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.DCValue;
22 import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.WorkBibDublinRecord;
23 import org.kuali.ole.docstore.model.xstream.work.bib.dublin.DCValueConverter;
24 import org.kuali.ole.docstore.model.xstream.work.bib.dublin.WorkBibDublinRecordConverter;
25
26
27
28
29
30
31 public class QualifiedDublinRecordHandler {
32
33
34
35
36
37
38 public WorkBibDublinRecord fromXML(String fileContent) {
39
40 XStream xStream = new XStream();
41 xStream.alias("dublin_core", WorkBibDublinRecord.class);
42 xStream.alias("dcvalue", DCValue.class);
43 xStream.addImplicitCollection(WorkBibDublinRecord.class, "dcValues", DCValue.class);
44 xStream.registerConverter(new WorkBibDublinRecordConverter());
45 xStream.registerConverter(new DCValueConverter());
46
47 return (WorkBibDublinRecord) xStream.fromXML(fileContent);
48 }
49
50
51
52
53
54
55
56 public String toXml(WorkBibDublinRecord rec) {
57 XmlFriendlyReplacer replacer = new XmlFriendlyReplacer("ddd", "_");
58 XStream xStream = new XStream(new DomDriver("UTF-8", replacer));
59 xStream.alias("dublin_core", WorkBibDublinRecord.class);
60 xStream.alias("dcvalue", DCValue.class);
61 xStream.addImplicitCollection(WorkBibDublinRecord.class, "dcValues", DCValue.class);
62 xStream.registerConverter(new WorkBibDublinRecordConverter());
63 xStream.registerConverter(new DCValueConverter());
64 return xStream.toXML(rec);
65 }
66
67 }