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.*;
24
25 import java.io.Writer;
26
27
28
29
30
31
32
33
34 public class RequestHandler {
35 public Request toObject(String requestXML) {
36 XStream xStream = new XStream();
37 xStream.registerConverter(new RequestDocumentConverter());
38 xStream.alias("request", Request.class);
39 xStream.alias("ingestDocument", RequestDocument.class);
40 xStream.alias("linkedIngestDocument", RequestDocument.class);
41 xStream.alias("content", Content.class);
42 xStream.alias("additionalAttributes", AdditionalAttributes.class);
43 Request request = (Request) xStream.fromXML(requestXML);
44 return request;
45 }
46
47 public String toXML(Request request) {
48 XStream xStream = new XStream(
49 new XppDriver() {
50 public HierarchicalStreamWriter createWriter(Writer out) {
51 return new PrettyPrintWriter(out) {
52 protected void writeText(QuickWriter writer, String text) {
53 writer.write("<![CDATA[");
54 if (text == null) {
55 text = "";
56 }
57 writer.write(text);
58 writer.write("]]>");
59 }
60 };
61 }
62 }
63 );
64 xStream.registerConverter(new RequestDocumentConverter());
65 xStream.alias("request", Request.class);
66 xStream.alias("ingestDocument", RequestDocument.class);
67 String xml = xStream.toXML(request);
68 return xml;
69 }
70 }