EqxStringUtils.java
4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package th.co.ais.ssbsrfc.utils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringEscapeUtils;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import th.co.ais.ssbsrfc.instance.EC02Instance;
import ec02.af.data.EquinoxRawData;
import ec02.utils.AppLog;
public class EqxStringUtils {
public static Map <String, String> convertXMLtoHttpData(String rcvXMLData) throws Exception{
Map <String, String> rtnMapHttpData = new HashMap<String, String>();
if(rcvXMLData != null) {
Serializer serializer = new Persister();
rcvXMLData = "<HttpData>" + rcvXMLData + "</HttpData>";
HttpData httpData = serializer.read(HttpData.class, rcvXMLData);
if(httpData != null ) {
if(httpData.getErdData() != null
&& httpData.getErdData().getValue() != null) {
rtnMapHttpData.put("erddata_value", httpData.getErdData().getValue());
} else {
rtnMapHttpData.put("erddata_value", rcvXMLData);
}
ERDHeader eRDHeader = httpData.getErdHeader();
if(eRDHeader != null) {
List<Header> lsHeader = eRDHeader.getHeader();
if(lsHeader != null) {
for(int i = 0; i < lsHeader.size(); i++) {
Header header = lsHeader.get(i);
if(header.getName() != null) {
rtnMapHttpData.put(header.getName(), header.getValue());
}
}
}
}
}
}
return rtnMapHttpData;
}
public static String getMessage(EquinoxRawData equinoxRawData) {
String value = EqxStringUtils.getMessage(equinoxRawData, null);
return value;
}
public static String getMessage(EquinoxRawData equinoxRawData, EC02Instance ec02Instance) {
String value = EqxStringUtils.getMessage(equinoxRawData, ec02Instance, false);
return value;
}
public static String getMessage(EquinoxRawData equinoxRawData, EC02Instance ec02Instance, boolean isLog) {
String value = "";
try {
String ctype = equinoxRawData.getRawDataAttribute("ctype");
String val = equinoxRawData.getRawDataAttribute("val");
String message = equinoxRawData.getRawDataMessage();
if (ctype.equals("Specialized-Resource")) {
value = message;
if (isLog) {
AppLog.d("[GETMESSAGE(MESSAGE)]: " + value);
}
} else if (ctype.equals("text/xml")) {
if ((message == null || message.equals("")) && (val != null && !val.equals(""))) {
value = val;
if (isLog) {
AppLog.d("[GETMESSAGE(VAL)]: " + value);
}
} else if (message != null && !message.equals("")) {
value = EqxStringUtils.getERDData(message, ec02Instance);
if (isLog) {
AppLog.d("[GETMESSAGE(MESSAGE)]: " + value);
}
}
} else if (ctype.equals("filefeed")) {
value = message;
} else if (ctype.equals("unknown")) {
value = message;
} else {
if ((val == null || val.equals("")) && (message != null && !message.equals(""))) {
value = EqxStringUtils.getERDData(message, ec02Instance);
if (isLog) {
AppLog.d("[GETMESSAGE(MESSAGE)]: " + value);
}
} else {
value = val;
if (isLog) {
AppLog.d("[GETMESSAGE(VAL)]: " + value);
}
}
}
} catch (Exception e) {
AppLog.e("[ EXCEPTION GETMESSAGES ] : " + e);
}
return value;
}
public static String getERDData(String message, EC02Instance ec02Instance) {
String value = "";
try {
Map<String, String> mapHttpData = EqxStringUtils.convertXMLtoHttpData(message);
value = mapHttpData.get("erddata_value");
if (ec02Instance != null) {
ec02Instance.getAFInstance().setMapHttpData(mapHttpData);
}
} catch (Exception e) {
// AppLog.e("[ Exception convertXMLtoHttpData ] : " + e.getMessage());
// AppLog.d("## convertXMLtoHttpData: NOTMATH");
value = message;
}
return value;
}
public static String builMessageERDHeader(EC02Instance ec02Instance, String value) {
String buil = "\n\t\t<ERDHeader>\n";
Map<String, String> map = ec02Instance.getAFInstance().getMapHttpData();
if (map != null) {
for (Map.Entry<String, String> entry : map.entrySet())
{
String name = entry.getKey();
String data = entry.getValue();
if (!name.equals("Content-Type") && !name.equals("erddata_value") && !name.equals("Content-Length")) {
buil += "\t\t\t<Header name=\"" + name + "\" value=\"" + data + "\" />\n";
}
}
}
// buil += "<Header name=\"Content-Type\" value=\"application/json\" />\n";
buil += "\t\t</ERDHeader>\n";
buil += "\t\t<ERDData value=\"" + EqxStringUtils.escapePostdata(value) + "\" />";
return buil;
}
public static String escapePostdata(String rcvData) {
if(rcvData != null ) {
return StringEscapeUtils.escapeXml(rcvData);
} else {
return null;
}
}
public static String unescapePostdata(String rcvData) {
if(rcvData != null ) {
//return rcvData;
return StringEscapeUtils.unescapeXml(rcvData);
} else {
return null;
}
}
}