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 public class UnQualifiedDublinRecordHandler {
37
38
39
40
41
42
43
44
45
46
47
48
49 public UnQualifiedDublinRecord fromXML(String fileContent) throws ParserConfigurationException, IOException, SAXException, XPathExpressionException {
50 Object object = getXstream().fromXML(fileContent);
51 return (UnQualifiedDublinRecord) object;
52 }
53
54
55
56
57
58
59
60 public String toXml(UnQualifiedDublinRecord rec) {
61 String xml = getXstream().toXML(rec);
62 return xml;
63 }
64
65 private XStream getXstream() {
66 XmlFriendlyReplacer replacer = new XmlFriendlyReplacer("ddd", "_");
67 XStream xStream = new XStream(new DomDriver("UTF-8", replacer));
68 xStream.alias("OAI-PMH", UnQualifiedDublinRecord.class);
69 xStream.alias("responseDate", String.class);
70 xStream.alias("request", String.class);
71 xStream.alias("ListRecords", ListRecords.class);
72 xStream.alias("record", Record.class);
73 xStream.alias("header", Header.class);
74 xStream.alias("metadata", MetaData.class);
75 xStream.alias("oai_dc:dc", OaiDcDoc.class);
76 xStream.addImplicitCollection(ListRecords.class, "recordsList", Record.class);
77 xStream.addImplicitCollection(MetaData.class, "oaiDcDocs", OaiDcDoc.class);
78 xStream.registerConverter(new HeaderConverter());
79 xStream.registerConverter(new OaiDcDocConverter());
80 return xStream;
81 }
82 }