1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.docstore.model.xstream.ingest;
17
18 import com.thoughtworks.xstream.XStream;
19 import com.thoughtworks.xstream.core.util.QuickWriter;
20 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
21 import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
22 import com.thoughtworks.xstream.io.xml.XppDriver;
23 import org.kuali.ole.docstore.model.xmlpojo.ingest.AdditionalAttributes;
24 import org.kuali.ole.docstore.model.xmlpojo.ingest.Content;
25 import org.kuali.ole.docstore.model.xmlpojo.ingest.Response;
26 import org.kuali.ole.docstore.model.xmlpojo.ingest.ResponseDocument;
27
28 import java.io.Writer;
29
30
31
32
33
34
35
36
37 public class ResponseHandler {
38 public Response toObject(String requestXML) {
39 XStream xStream = new XStream();
40 xStream.registerConverter(new ResponseDocumentConverter());
41 xStream.alias("response", Response.class);
42 xStream.alias("document", ResponseDocument.class);
43 xStream.alias("content", Content.class);
44
45 Response response = (Response) xStream.fromXML(requestXML);
46 return response;
47 }
48
49 public String toXML(Response response) {
50 XStream xStream = new XStream(new XppDriver() {
51 public HierarchicalStreamWriter createWriter(Writer out) {
52 return new PrettyPrintWriter(out) {
53 protected void writeText(QuickWriter writer, String text) {
54 writer.write("<![CDATA[");
55 writer.write(text);
56 writer.write("]]>");
57 }
58 };
59 }
60 });
61 xStream.registerConverter(new ResponseDocumentConverter());
62 xStream.alias("response", Response.class);
63 xStream.alias("document", ResponseDocument.class);
64 xStream.alias("content", Content.class);
65
66 return xStream.toXML(response);
67 }
68 }