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