1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole;
17
18 import com.thoughtworks.xstream.XStream;
19 import com.thoughtworks.xstream.io.xml.DomDriver;
20 import com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer;
21 import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.unqualified.*;
22 import org.kuali.ole.docstore.model.xstream.work.bib.dublin.unqualified.HeaderConverter;
23 import org.kuali.ole.docstore.model.xstream.work.bib.dublin.unqualified.OaiDcDocConverter;
24 import org.kuali.ole.pojo.dublin.unqualified.UnQualifiedDublinRecord;
25 import org.xml.sax.SAXException;
26
27 import javax.xml.parsers.ParserConfigurationException;
28 import javax.xml.xpath.XPathExpressionException;
29 import java.io.IOException;
30
31
32
33
34
35
36
37 public class UnQualifiedDublinRecordHandler {
38
39
40
41
42
43
44
45
46
47
48 public UnQualifiedDublinRecord fromXML(String fileContent) throws ParserConfigurationException, IOException, SAXException, XPathExpressionException {
49 Object object = getXstream().fromXML(fileContent);
50 return (UnQualifiedDublinRecord) object;
51 }
52
53
54
55
56
57
58
59 public String toXml(UnQualifiedDublinRecord rec) {
60 String xml = getXstream().toXML(rec);
61 return xml;
62 }
63
64 private XStream getXstream() {
65 XmlFriendlyReplacer replacer = new XmlFriendlyReplacer("ddd", "_");
66 XStream xStream = new XStream(new DomDriver("UTF-8", replacer));
67 xStream.alias("OAI-PMH", UnQualifiedDublinRecord.class);
68 xStream.alias("responseDate", String.class);
69 xStream.alias("request", String.class);
70 xStream.alias("ListRecords", ListRecords.class);
71 xStream.alias("record", Record.class);
72 xStream.alias("header", Header.class);
73 xStream.alias("metadata", MetaData.class);
74 xStream.alias("oai_dc:dc", OaiDcDoc.class);
75 xStream.addImplicitCollection(ListRecords.class, "recordsList", Record.class);
76 xStream.addImplicitCollection(MetaData.class, "oaiDcDocs", OaiDcDoc.class);
77 xStream.registerConverter(new HeaderConverter());
78 xStream.registerConverter(new OaiDcDocConverter());
79 return xStream;
80 }
81 }