1 package org.kuali.ole.docstore.common.document;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.docstore.common.document.content.enums.DocCategory;
5 import org.kuali.ole.docstore.common.document.content.enums.DocFormat;
6 import org.kuali.ole.docstore.common.document.content.enums.DocType;
7
8 import javax.xml.bind.JAXBContext;
9 import javax.xml.bind.JAXBElement;
10 import javax.xml.bind.Marshaller;
11 import javax.xml.bind.Unmarshaller;
12 import javax.xml.bind.annotation.XmlRootElement;
13 import javax.xml.transform.stream.StreamSource;
14 import java.io.ByteArrayInputStream;
15 import java.io.StringWriter;
16
17
18
19
20
21
22
23
24 @XmlRootElement(name = "bibDoc")
25 public class BibDc extends Bib {
26
27 private static final Logger LOG = Logger.getLogger(BibDc.class);
28 public BibDc() {
29 category=DocCategory.WORK.getCode();
30 type=DocType.BIB.getCode();
31 format=DocFormat.DUBLIN_CORE.getCode();
32 }
33
34 @Override
35 public String serialize(Object object) {
36 String result = null;
37 StringWriter sw = new StringWriter();
38 BibDc bib = (BibDc) object;
39 try {
40 JAXBContext jaxbContext = JAXBContext.newInstance(BibDc.class);
41 Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
42 jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
43 jaxbMarshaller.marshal(bib, sw);
44 result = sw.toString();
45 } catch (Exception e) {
46 LOG.error("Exception :", e);
47 }
48 return result;
49 }
50
51 @Override
52 public Object deserialize(String content) {
53
54 JAXBElement<BibDc> bibElement = null;
55 try {
56 JAXBContext jaxbContext = JAXBContext.newInstance(BibDc.class);
57 Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
58 ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
59 bibElement = jaxbUnmarshaller.unmarshal(new StreamSource(input), BibDc.class);
60 } catch (Exception e) {
61 LOG.error("Exception :", e);
62 }
63 return bibElement.getValue();
64 }
65 }