1 package org.kuali.common.util.xml.jaxb.adapter;
2
3 import javax.xml.bind.annotation.adapters.XmlAdapter;
4
5 import org.kuali.common.util.Assert;
6 import org.kuali.common.util.Str;
7
8 public final class FlattenStringAdapter extends XmlAdapter<String, String> {
9
10 public FlattenStringAdapter() {
11 this(FlattenConstants.DEFAULT_CR_REPLACEMENT, FlattenConstants.DEFAULT_LF_REPLACEMENT);
12 }
13
14 public FlattenStringAdapter(String carriageReturnReplacement, String linefeedReplacement) {
15
16 Assert.noBlanks(carriageReturnReplacement, linefeedReplacement);
17 this.carriageReturnReplacement = carriageReturnReplacement;
18 this.linefeedReplacement = linefeedReplacement;
19 }
20
21 private final String carriageReturnReplacement;
22 private final String linefeedReplacement;
23
24 @Override
25 public String marshal(String string) {
26 if (string != null) {
27 return Str.flatten(string, carriageReturnReplacement, linefeedReplacement);
28 } else {
29 return null;
30 }
31 }
32
33 @Override
34 public String unmarshal(String value) {
35 if (value == null) {
36 return null;
37 } else {
38 return Str.inflate(value, carriageReturnReplacement, linefeedReplacement);
39 }
40 }
41
42 public String getCarriageReturnReplacement() {
43 return carriageReturnReplacement;
44 }
45
46 public String getLinefeedReplacement() {
47 return linefeedReplacement;
48 }
49
50 }