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.DocFormat;
6   import org.kuali.ole.docstore.common.document.content.enums.DocType;
7   import org.kuali.ole.docstore.common.exception.DocstoreDeserializeException;
8   import org.kuali.ole.docstore.common.exception.DocstoreResources;
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.XmlAccessType;
15  import javax.xml.bind.annotation.XmlAccessorType;
16  import javax.xml.bind.annotation.XmlRootElement;
17  import javax.xml.bind.annotation.XmlType;
18  import javax.xml.transform.stream.StreamSource;
19  import java.io.ByteArrayInputStream;
20  import java.io.StringWriter;
21  
22  
23  /**
24   * <p>Java class for bib complex type.
25   * <p/>
26   * <p>The following schema fragment specifies the expected content contained within this class.
27   * <p/>
28   * <pre>
29   * &lt;complexType name="bib">
30   *   &lt;complexContent>
31   *     &lt;extension base="{}docstoreDocument">
32   *       &lt;sequence>
33   *         &lt;element name="issn" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
34   *         &lt;element name="isbn" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
35   *         &lt;element name="subject" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
36   *         &lt;element name="edition" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
37   *         &lt;element name="publicationDate" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
38   *         &lt;element name="publisher" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
39   *         &lt;element name="author" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
40   *         &lt;element name="title" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
41   *       &lt;/sequence>
42   *     &lt;/extension>
43   *   &lt;/complexContent>
44   * &lt;/complexType>
45   * </pre>
46   */
47  @XmlAccessorType(XmlAccessType.FIELD)
48  @XmlType(name = "bibDoc", propOrder = {
49          "issn",
50          "isbn",
51          "subject",
52          "edition",
53          "publicationDate",
54          "publisher",
55          "author",
56          "title"
57  })
58  @XmlRootElement(name = "bibDoc")
59  public class Bib
60          extends DocstoreDocument {
61  
62      private static final Logger LOG = Logger.getLogger(Bib.class);
63      public static final String TITLE = "TITLE";
64      public static final String AUTHOR = "AUTHOR";
65      public static final String ISBN = "ISBN";
66      public static final String ISSN = "ISSN";
67      public static final String SUBJECT = "SUBJECT";
68      public static final String PUBLISHER = "PUBLISHER";
69      public static final String PUBLICATIONDATE = "PUBLICATIONDATE";
70      public static final String EDITION = "EDITION";
71      public static final String DESCRIPTION = "DESCRIPTION";
72      public static final String FORMAT = "FORMAT";
73      public static final String LANGUAGE = "LANGUAGE";
74      public static final String BIBIDENTIFIER = "BIBIDENTIFIER";
75      protected String issn;
76      protected String isbn;
77      protected String subject;
78      protected String edition;
79      protected String publicationDate;
80      protected String publisher;
81      protected String author;
82      protected String title;
83  
84      public Bib() {
85          category=DocCategory.WORK.getCode();
86          type=DocType.BIB.getCode();
87          format=DocFormat.MARC.getCode();
88      }
89  
90      /**
91       * Gets the value of the issn property.
92       *
93       * @return possible object is
94       *         {@link String }
95       */
96      public String getIssn() {
97          return issn;
98      }
99  
100     /**
101      * Sets the value of the issn property.
102      *
103      * @param value allowed object is
104      *              {@link String }
105      */
106     public void setIssn(String value) {
107         this.issn = value;
108     }
109 
110     /**
111      * Gets the value of the isbn property.
112      *
113      * @return possible object is
114      *         {@link String }
115      */
116     public String getIsbn() {
117         return isbn;
118     }
119 
120     /**
121      * Sets the value of the isbn property.
122      *
123      * @param value allowed object is
124      *              {@link String }
125      */
126     public void setIsbn(String value) {
127         this.isbn = value;
128     }
129 
130     /**
131      * Gets the value of the subject property.
132      *
133      * @return possible object is
134      *         {@link String }
135      */
136     public String getSubject() {
137         return subject;
138     }
139 
140     /**
141      * Sets the value of the subject property.
142      *
143      * @param value allowed object is
144      *              {@link String }
145      */
146     public void setSubject(String value) {
147         this.subject = value;
148     }
149 
150     /**
151      * Gets the value of the edition property.
152      *
153      * @return possible object is
154      *         {@link String }
155      */
156     public String getEdition() {
157         return edition;
158     }
159 
160     /**
161      * Sets the value of the edition property.
162      *
163      * @param value allowed object is
164      *              {@link String }
165      */
166     public void setEdition(String value) {
167         this.edition = value;
168     }
169 
170     /**
171      * Gets the value of the publicationDate property.
172      *
173      * @return possible object is
174      *         {@link String }
175      */
176     public String getPublicationDate() {
177         return publicationDate;
178     }
179 
180     /**
181      * Sets the value of the publicationDate property.
182      *
183      * @param value allowed object is
184      *              {@link String }
185      */
186     public void setPublicationDate(String value) {
187         this.publicationDate = value;
188     }
189 
190     /**
191      * Gets the value of the publisher property.
192      *
193      * @return possible object is
194      *         {@link String }
195      */
196     public String getPublisher() {
197         return publisher;
198     }
199 
200     /**
201      * Sets the value of the publisher property.
202      *
203      * @param value allowed object is
204      *              {@link String }
205      */
206     public void setPublisher(String value) {
207         this.publisher = value;
208     }
209 
210     /**
211      * Gets the value of the author property.
212      *
213      * @return possible object is
214      *         {@link String }
215      */
216     public String getAuthor() {
217         return author;
218     }
219 
220     /**
221      * Sets the value of the author property.
222      *
223      * @param value allowed object is
224      *              {@link String }
225      */
226     public void setAuthor(String value) {
227         this.author = value;
228     }
229 
230     /**
231      * Gets the value of the title property.
232      *
233      * @return possible object is
234      *         {@link String }
235      */
236     public String getTitle() {
237         return title;
238     }
239 
240     /**
241      * Sets the value of the title property.
242      *
243      * @param value allowed object is
244      *              {@link String }
245      */
246     public void setTitle(String value) {
247         this.title = value;
248     }
249 
250     @Override
251     public String serialize(Object object) {
252         String result = null;
253         StringWriter sw = new StringWriter();
254         Bib bib = (Bib) object;
255         try {
256             JAXBContext jaxbContext = JAXBContext.newInstance(Bib.class);
257             Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
258             jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
259             jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
260             jaxbMarshaller.marshal(bib, sw);
261             result = sw.toString();
262         } catch (Exception e) {
263             LOG.error("Exception :", e);
264         }
265         return result;
266     }
267 
268     @Override
269     public Object deserialize(String content) {
270 
271         JAXBElement<Bib> bibElement = null;
272         try {
273             JAXBContext jaxbContext = JAXBContext.newInstance(Bib.class);
274             Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
275             ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
276             bibElement = jaxbUnmarshaller.unmarshal(new StreamSource(input), Bib.class);
277         } catch (Exception e) {
278             LOG.error("Exception :", e);
279             throw new DocstoreDeserializeException(DocstoreResources.BIB_CREATION_FAILED,DocstoreResources.BIB_CREATION_FAILED);
280         }
281         return bibElement.getValue();
282     }
283 
284     @Override
285     public Object deserializeContent(Object object) {
286         Bib bib = (Bib) object;
287         BibMarcMapping bibMarcMapping = new BibMarcMapping();
288         return bibMarcMapping.getDocument(bib);
289     }
290 
291     @Override
292     public Object deserializeContent(String content) {
293         return null;  //To change body of implemented methods use File | Settings | File Templates.
294     }
295 
296     @Override
297     public String serializeContent(Object object) {
298         return null;  //To change body of implemented methods use File | Settings | File Templates.
299     }
300 }