1 package org.kuali.ole.handler;
2
3 import com.thoughtworks.xstream.XStream;
4 import org.kuali.ole.bo.cql.CQLModifiers;
5 import org.kuali.ole.bo.cql.CQLPrefixes;
6 import org.kuali.ole.bo.cql.CQLResponseBO;
7 import org.kuali.ole.bo.cql.CQLSearchClauseTag;
8
9 import java.io.IOException;
10 import java.net.URISyntaxException;
11
12 public class OleCQLResponseHandler {
13
14
15
16
17
18
19
20
21
22 public CQLResponseBO fromXML(String fileContent) throws URISyntaxException, IOException {
23
24 XStream xStream = new XStream();
25 xStream.alias("triple", CQLResponseBO.class);
26 xStream.alias("modifier", CQLModifiers.class);
27 xStream.alias("prefix", CQLPrefixes.class);
28 xStream.aliasField("boolean", CQLResponseBO.class, "booleanTagValue");
29 xStream.aliasField("value", CQLResponseBO.class, "booleanTagValue");
30 xStream.aliasField("leftOperand", CQLResponseBO.class, "leftOperand");
31 xStream.aliasField("rightOperand", CQLResponseBO.class, "rightOperand");
32 xStream.aliasField("searchClause", CQLResponseBO.class, "searchClauseTag");
33 xStream.aliasField("relation", CQLSearchClauseTag.class, "relationTag");
34 Object object = xStream.fromXML(fileContent);
35 return (CQLResponseBO) object;
36 }
37
38
39
40
41
42
43
44
45
46 public CQLSearchClauseTag fromCQLXML(String fileContent) throws URISyntaxException, IOException {
47
48 XStream xStream = new XStream();
49 xStream.alias("searchClause", CQLSearchClauseTag.class);
50 xStream.alias("modifier", CQLModifiers.class);
51 xStream.alias("prefix", CQLPrefixes.class);
52 xStream.aliasField("relation", CQLSearchClauseTag.class, "relationTag");
53 Object object = xStream.fromXML(fileContent);
54 return (CQLSearchClauseTag) object;
55 }
56
57 public String toXML(CQLResponseBO cqlResponseBO) {
58
59 StringBuffer stringBuffer = new StringBuffer();
60 stringBuffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
61 XStream xStream = new XStream();
62 xStream.alias("triple", CQLResponseBO.class);
63 xStream.alias("modifier", CQLModifiers.class);
64 xStream.alias("prefix", CQLPrefixes.class);
65 xStream.aliasField("boolean", CQLResponseBO.class, "booleanTagValue");
66 xStream.aliasField("leftOperand", CQLResponseBO.class, "leftOperand");
67 xStream.aliasField("rightOperand", CQLResponseBO.class, "rightOperand");
68 xStream.aliasField("searchClause", CQLResponseBO.class, "searchClauseTag");
69 xStream.aliasField("relation", CQLSearchClauseTag.class, "relationTag");
70 String xml = xStream.toXML(cqlResponseBO);
71 System.out.println("XML :: " + xml);
72 stringBuffer.append(xml);
73 return stringBuffer.toString();
74 }
75
76
77 }