1 package org.kuali.ole.docstore.common.document;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.docstore.common.document.content.bib.dc.unqualified.*;
5 import org.kuali.ole.docstore.common.document.content.bib.dc.unqualified.xstream.BibDublinUnQualifiedRecordProcessor;
6 import org.kuali.ole.docstore.common.document.content.enums.DocCategory;
7 import org.kuali.ole.docstore.common.document.content.enums.DocFormat;
8 import org.kuali.ole.docstore.common.document.content.enums.DocType;
9
10 import javax.xml.bind.JAXBContext;
11 import javax.xml.bind.JAXBElement;
12 import javax.xml.bind.Marshaller;
13 import javax.xml.bind.Unmarshaller;
14 import javax.xml.bind.annotation.XmlRootElement;
15 import javax.xml.transform.stream.StreamSource;
16 import java.io.ByteArrayInputStream;
17 import java.io.StringWriter;
18
19
20
21
22
23
24
25
26 @XmlRootElement(name = "bibDoc")
27
28 public class BibDcUnqualified extends Bib {
29
30 private static final Logger LOG = Logger.getLogger(BibDcUnqualified.class);
31 public BibDcUnqualified () {
32 category=DocCategory.WORK.getCode();
33 type=DocType.BIB.getCode();
34 format=DocFormat.DUBLIN_UNQUALIFIED.getCode();
35 }
36
37 @Override
38 public String serialize(Object object) {
39 String result = null;
40 StringWriter sw = new StringWriter();
41 BibDcUnqualified bib = (BibDcUnqualified) object;
42 try {
43 JAXBContext jaxbContext = JAXBContext.newInstance(BibDcUnqualified.class);
44 Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
45 jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
46 jaxbMarshaller.marshal(bib, sw);
47 result = sw.toString();
48 } catch (Exception e) {
49 LOG.error("Exception :", e);
50 }
51 return result;
52 }
53
54 @Override
55 public Object deserialize(String content) {
56
57 JAXBElement<BibDcUnqualified> bibElement = null;
58 try {
59 JAXBContext jaxbContext = JAXBContext.newInstance(BibDcUnqualified.class);
60 Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
61 ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
62 bibElement = jaxbUnmarshaller.unmarshal(new StreamSource(input), BibDcUnqualified.class);
63 } catch (Exception e) {
64 LOG.error("Exception :", e);
65 }
66 return bibElement.getValue();
67 }
68 @Override
69 public Object deserializeContent(Object object) {
70 BibDcUnqualified bibDcUnqualified= (BibDcUnqualified)object;
71 BibDublinUnQualifiedRecordProcessor bibDublinUnQualifiedRecordProcessor=new BibDublinUnQualifiedRecordProcessor();
72 BibDublinUnQualifiedRecord bibDcUnqualifiedRecord=bibDublinUnQualifiedRecordProcessor.fromXML(bibDcUnqualified.getContent());
73 ListRecords listRecords=bibDcUnqualifiedRecord.getListRecords();
74 for(Record recordlist:listRecords.getRecords()){
75 MetaData metaData=recordlist.getMetadata();
76 for(OaiDcDoc oaiDcDoc:metaData.getOaiDcDocs()){
77 for (Tag tag:oaiDcDoc.getAllTags()){
78 if(tag.getName().equalsIgnoreCase("dc:title")){
79 bibDcUnqualified.setTitle(tag.getValue());
80 }
81 }
82 }
83 }
84 return bibDcUnqualified;
85 }
86 }