View Javadoc
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.DocType;
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.bind.annotation.XmlRootElement;
12  import javax.xml.transform.stream.StreamSource;
13  import java.io.ByteArrayInputStream;
14  import java.io.StringWriter;
15  
16  /**
17   * Created with IntelliJ IDEA.
18   * User: chenchulakshmig
19   * Date: 2/25/14
20   * Time: 2:59 PM
21   * To change this template use File | Settings | File Templates.
22   */
23  @XmlRootElement(name = "license")
24  public class LicenseAttachment extends License {
25  
26      private static final Logger LOG = Logger.getLogger(LicenseAttachment.class);
27  
28      private String fileName;
29      private String filePath;
30      private String documentTitle;
31      private String documentMimeType;
32      private String documentNote;
33      private String agreementType;
34      private String agreementNote;
35  
36      public String getFileName() {
37          return fileName;
38      }
39  
40      public void setFileName(String fileName) {
41          this.fileName = fileName;
42      }
43  
44      public String getFilePath() {
45          return filePath;
46      }
47  
48      public void setFilePath(String filePath) {
49          this.filePath = filePath;
50      }
51  
52      public String getDocumentTitle() {
53          return documentTitle;
54      }
55  
56      public void setDocumentTitle(String documentTitle) {
57          this.documentTitle = documentTitle;
58      }
59  
60      public String getDocumentMimeType() {
61          return documentMimeType;
62      }
63  
64      public void setDocumentMimeType(String documentMimeType) {
65          this.documentMimeType = documentMimeType;
66      }
67  
68      public String getDocumentNote() {
69          return documentNote;
70      }
71  
72      public void setDocumentNote(String documentNote) {
73          this.documentNote = documentNote;
74      }
75  
76      public LicenseAttachment() {
77          category = DocCategory.WORK.getCode();
78          type = DocType.LICENSE.getCode();
79      }
80  
81      public String getAgreementType() {
82          return agreementType;
83      }
84  
85      public void setAgreementType(String agreementType) {
86          this.agreementType = agreementType;
87      }
88  
89      public String getAgreementNote() {
90          return agreementNote;
91      }
92  
93      public void setAgreementNote(String agreementNote) {
94          this.agreementNote = agreementNote;
95      }
96  
97      @Override
98      public String serialize(Object object) {
99          String result = null;
100         StringWriter sw = new StringWriter();
101         LicenseAttachment licenseAttachment = (LicenseAttachment) object;
102         try {
103             JAXBContext jaxbContext = JAXBContext.newInstance(LicenseAttachment.class);
104             Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
105             jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
106             jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
107             jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
108             jaxbMarshaller.marshal(licenseAttachment, sw);
109             result = sw.toString();
110         } catch (Exception e) {
111             LOG.error("Exception :", e);
112         }
113         return result;
114     }
115 
116     @Override
117     public Object deserialize(String content) {
118         JAXBElement<LicenseAttachment> licenseAttachmentElement = null;
119         try {
120             JAXBContext jaxbContext = JAXBContext.newInstance(LicenseAttachment.class);
121             Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
122             ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
123             licenseAttachmentElement = jaxbUnmarshaller.unmarshal(new StreamSource(input), LicenseAttachment.class);
124         } catch (Exception e) {
125             LOG.error("Exception :", e);
126         }
127         return licenseAttachmentElement.getValue();
128     }
129 }