1 package org.kuali.ole.docstore.model.jaxb.config;
2
3 import org.kuali.ole.docstore.model.xmlpojo.config.DocumentConfig;
4 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory;
6
7 import javax.xml.bind.JAXBContext;
8 import javax.xml.bind.JAXBElement;
9 import javax.xml.bind.Marshaller;
10 import javax.xml.bind.Unmarshaller;
11 import javax.xml.transform.stream.StreamSource;
12 import java.io.ByteArrayInputStream;
13 import java.io.StringWriter;
14
15
16
17
18
19
20
21
22 public class DocumentConfigConverter {
23 public static final Logger LOG = LoggerFactory.getLogger(DocumentConfigConverter.class);
24
25 public DocumentConfig unmarshal(String docXml) {
26
27 JAXBElement<DocumentConfig> docElement = null;
28 try {
29 JAXBContext jaxbContext = JAXBContext.newInstance(DocumentConfig.class);
30 Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
31 ByteArrayInputStream input = new ByteArrayInputStream(docXml.getBytes("UTF-8"));
32 docElement = jaxbUnmarshaller.unmarshal(new StreamSource(input), DocumentConfig.class);
33 } catch (Exception e) {
34 LOG.info(e.getMessage(), e);
35 }
36 return docElement.getValue();
37 }
38
39 public String marshal(DocumentConfig docConfig) {
40
41 JAXBElement<DocumentConfig> docElement = null;
42 String result = null;
43 StringWriter sw = new StringWriter();
44 try {
45 JAXBContext jaxbContext = JAXBContext.newInstance(DocumentConfig.class);
46 Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
47 jaxbMarshaller.marshal(docConfig, sw);
48 result = sw.toString();
49 LOG.info("DocSearchConfig Xml is " + result);
50 } catch (Exception e) {
51 LOG.info(e.getMessage(), e);
52 }
53 return result;
54 }
55 }