001package org.kuali.ole.docstore.common.document; 002 003import org.apache.log4j.Logger; 004import org.kuali.ole.docstore.common.document.content.enums.DocCategory; 005import org.kuali.ole.docstore.common.document.content.enums.DocType; 006 007import javax.xml.bind.JAXBContext; 008import javax.xml.bind.JAXBElement; 009import javax.xml.bind.Marshaller; 010import javax.xml.bind.Unmarshaller; 011import javax.xml.bind.annotation.XmlRootElement; 012import javax.xml.transform.stream.StreamSource; 013import java.io.ByteArrayInputStream; 014import java.io.StringWriter; 015 016/** 017 * Created with IntelliJ IDEA. 018 * User: chenchulakshmig 019 * Date: 2/25/14 020 * Time: 2:59 PM 021 * To change this template use File | Settings | File Templates. 022 */ 023@XmlRootElement(name = "license") 024public class LicenseAttachment extends License { 025 026 private static final Logger LOG = Logger.getLogger(LicenseAttachment.class); 027 028 private String fileName; 029 private String filePath; 030 private String documentTitle; 031 private String documentMimeType; 032 private String documentNote; 033 private String agreementType; 034 private String agreementNote; 035 036 public String getFileName() { 037 return fileName; 038 } 039 040 public void setFileName(String fileName) { 041 this.fileName = fileName; 042 } 043 044 public String getFilePath() { 045 return filePath; 046 } 047 048 public void setFilePath(String filePath) { 049 this.filePath = filePath; 050 } 051 052 public String getDocumentTitle() { 053 return documentTitle; 054 } 055 056 public void setDocumentTitle(String documentTitle) { 057 this.documentTitle = documentTitle; 058 } 059 060 public String getDocumentMimeType() { 061 return documentMimeType; 062 } 063 064 public void setDocumentMimeType(String documentMimeType) { 065 this.documentMimeType = documentMimeType; 066 } 067 068 public String getDocumentNote() { 069 return documentNote; 070 } 071 072 public void setDocumentNote(String documentNote) { 073 this.documentNote = documentNote; 074 } 075 076 public LicenseAttachment() { 077 category = DocCategory.WORK.getCode(); 078 type = DocType.LICENSE.getCode(); 079 } 080 081 public String getAgreementType() { 082 return agreementType; 083 } 084 085 public void setAgreementType(String agreementType) { 086 this.agreementType = agreementType; 087 } 088 089 public String getAgreementNote() { 090 return agreementNote; 091 } 092 093 public void setAgreementNote(String agreementNote) { 094 this.agreementNote = agreementNote; 095 } 096 097 @Override 098 public String serialize(Object object) { 099 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}