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.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 Bib bib = (Bib) object;
254 try {
255 StringWriter sw = new StringWriter();
256 Marshaller jaxbMarshaller = JAXBContextFactory.getInstance().getMarshaller(Bib.class);
257 jaxbMarshaller.marshal(bib, sw);
258 result = sw.toString();
259 } catch (Exception e) {
260 LOG.error("Exception :", e);
261 }
262 return result;
263 }
264
265 @Override
266 public Object deserialize(String content) {
267 Bib bib = new Bib();
268 try {
269 Unmarshaller unmarshaller = JAXBContextFactory.getInstance().getUnMarshaller(Bib.class);
270 ByteArrayInputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
271 JAXBElement<Bib> bibElement = unmarshaller.unmarshal(new StreamSource(input), Bib.class);
272 bib = bibElement.getValue();
273 } catch (Exception e) {
274 LOG.error("Exception :", e);
275 throw new DocstoreDeserializeException(DocstoreResources.BIB_CREATION_FAILED,DocstoreResources.BIB_CREATION_FAILED);
276 }
277 return bib;
278 }
279
280 @Override
281 public Object deserializeContent(Object object) {
282 Bib bib = (Bib) object;
283 BibMarcMapping bibMarcMapping = new BibMarcMapping();
284 return bibMarcMapping.getDocument(bib);
285 }
286
287 @Override
288 public Object deserializeContent(String content) {
289 return null;
290 }
291
292 @Override
293 public String serializeContent(Object object) {
294 return null;
295 }
296 }