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.document.factory.JAXBContextFactory;
8 import org.kuali.ole.docstore.common.exception.DocstoreDeserializeException;
9 import org.kuali.ole.docstore.common.exception.DocstoreResources;
10
11 import javax.xml.bind.Marshaller;
12 import javax.xml.bind.Unmarshaller;
13 import javax.xml.bind.annotation.XmlAccessType;
14 import javax.xml.bind.annotation.XmlAccessorType;
15 import javax.xml.bind.annotation.XmlRootElement;
16 import javax.xml.bind.annotation.XmlType;
17 import javax.xml.transform.stream.StreamSource;
18 import java.io.ByteArrayInputStream;
19 import java.io.StringWriter;
20
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 @XmlAccessorType(XmlAccessType.FIELD)
47 @XmlType(name = "bibDoc", propOrder = {
48 "issn",
49 "isbn",
50 "subject",
51 "edition",
52 "publicationDate",
53 "publisher",
54 "author",
55 "title"
56 })
57 @XmlRootElement(name = "bibDoc")
58 public class Bib
59 extends DocstoreDocument {
60
61 private static final Logger LOG = Logger.getLogger(Bib.class);
62 public static final String TITLE = "TITLE";
63 public static final String AUTHOR = "AUTHOR";
64 public static final String ISBN = "ISBN";
65 public static final String ISSN = "ISSN";
66 public static final String SUBJECT = "SUBJECT";
67 public static final String PUBLISHER = "PUBLISHER";
68 public static final String PUBLICATIONDATE = "PUBLICATIONDATE";
69 public static final String EDITION = "EDITION";
70 public static final String DESCRIPTION = "DESCRIPTION";
71 public static final String FORMAT = "FORMAT";
72 public static final String LANGUAGE = "LANGUAGE";
73 public static final String BIBIDENTIFIER = "BIBIDENTIFIER";
74 protected String issn;
75 protected String isbn;
76 protected String subject;
77 protected String edition;
78 protected String publicationDate;
79 protected String publisher;
80 protected String author;
81 protected String title;
82
83 public Bib() {
84 category = DocCategory.WORK.getCode();
85 type = DocType.BIB.getCode();
86 format = DocFormat.MARC.getCode();
87 }
88
89
90
91
92
93
94
95 public String getIssn() {
96 return issn;
97 }
98
99
100
101
102
103
104
105 public void setIssn(String value) {
106 this.issn = value;
107 }
108
109
110
111
112
113
114
115 public String getIsbn() {
116 return isbn;
117 }
118
119
120
121
122
123
124
125 public void setIsbn(String value) {
126 this.isbn = value;
127 }
128
129
130
131
132
133
134
135 public String getSubject() {
136 return subject;
137 }
138
139
140
141
142
143
144
145 public void setSubject(String value) {
146 this.subject = value;
147 }
148
149
150
151
152
153
154
155 public String getEdition() {
156 return edition;
157 }
158
159
160
161
162
163
164
165 public void setEdition(String value) {
166 this.edition = value;
167 }
168
169
170
171
172
173
174
175 public String getPublicationDate() {
176 return publicationDate;
177 }
178
179
180
181
182
183
184
185 public void setPublicationDate(String value) {
186 this.publicationDate = value;
187 }
188
189
190
191
192
193
194
195 public String getPublisher() {
196 return publisher;
197 }
198
199
200
201
202
203
204
205 public void setPublisher(String value) {
206 this.publisher = value;
207 }
208
209
210
211
212
213
214
215 public String getAuthor() {
216 return author;
217 }
218
219
220
221
222
223
224
225 public void setAuthor(String value) {
226 this.author = value;
227 }
228
229
230
231
232
233
234
235 public String getTitle() {
236 return title;
237 }
238
239
240
241
242
243
244
245 public void setTitle(String value) {
246 this.title = value;
247 }
248
249 @Override
250 public String serialize(Object object) {
251 String result = null;
252 Bib bib = (Bib) object;
253 try {
254 StringWriter sw = new StringWriter();
255 JAXBContextFactory jaxbContextFactory = JAXBContextFactory.getInstance();
256 Marshaller jaxbMarshaller = jaxbContextFactory.getMarshaller(Bib.class);
257 synchronized (jaxbMarshaller) {
258 jaxbMarshaller.marshal(bib, sw);
259 }
260
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 Bib bib = new Bib();
271 try {
272 Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(Bib.class);
273 ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
274 synchronized (unmarshaller) {
275 bib = unmarshaller.unmarshal(new StreamSource(input), Bib.class).getValue();
276 }
277
278 } catch (Exception e) {
279 LOG.error("Exception :", e);
280 throw new DocstoreDeserializeException(DocstoreResources.BIB_CREATION_FAILED,DocstoreResources.BIB_CREATION_FAILED);
281 }
282 return bib;
283 }
284
285 @Override
286 public Object deserializeContent(Object object) {
287 Bib bib = (Bib) object;
288 BibMarcMapping bibMarcMapping = new BibMarcMapping();
289 return bibMarcMapping.getDocument(bib);
290 }
291
292 @Override
293 public Object deserializeContent(String content) {
294 return null;
295 }
296
297 @Override
298 public String serializeContent(Object object) {
299 return null;
300 }
301 }