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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
92
93
94
95
96 public String getIssn() {
97 return issn;
98 }
99
100
101
102
103
104
105
106 public void setIssn(String value) {
107 this.issn = value;
108 }
109
110
111
112
113
114
115
116 public String getIsbn() {
117 return isbn;
118 }
119
120
121
122
123
124
125
126 public void setIsbn(String value) {
127 this.isbn = value;
128 }
129
130
131
132
133
134
135
136 public String getSubject() {
137 return subject;
138 }
139
140
141
142
143
144
145
146 public void setSubject(String value) {
147 this.subject = value;
148 }
149
150
151
152
153
154
155
156 public String getEdition() {
157 return edition;
158 }
159
160
161
162
163
164
165
166 public void setEdition(String value) {
167 this.edition = value;
168 }
169
170
171
172
173
174
175
176 public String getPublicationDate() {
177 return publicationDate;
178 }
179
180
181
182
183
184
185
186 public void setPublicationDate(String value) {
187 this.publicationDate = value;
188 }
189
190
191
192
193
194
195
196 public String getPublisher() {
197 return publisher;
198 }
199
200
201
202
203
204
205
206 public void setPublisher(String value) {
207 this.publisher = value;
208 }
209
210
211
212
213
214
215
216 public String getAuthor() {
217 return author;
218 }
219
220
221
222
223
224
225
226 public void setAuthor(String value) {
227 this.author = value;
228 }
229
230
231
232
233
234
235
236 public String getTitle() {
237 return title;
238 }
239
240
241
242
243
244
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;
294 }
295
296 @Override
297 public String serializeContent(Object object) {
298 return null;
299 }
300 }