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.DocFormat; 006import org.kuali.ole.docstore.common.document.content.enums.DocType; 007import org.kuali.ole.docstore.common.document.factory.JAXBContextFactory; 008import org.kuali.ole.docstore.common.exception.DocstoreDeserializeException; 009import org.kuali.ole.docstore.common.exception.DocstoreResources; 010 011import javax.xml.bind.Marshaller; 012import javax.xml.bind.Unmarshaller; 013import javax.xml.bind.annotation.XmlAccessType; 014import javax.xml.bind.annotation.XmlAccessorType; 015import javax.xml.bind.annotation.XmlRootElement; 016import javax.xml.bind.annotation.XmlType; 017import javax.xml.transform.stream.StreamSource; 018import java.io.ByteArrayInputStream; 019import java.io.StringWriter; 020 021 022/** 023 * <p>Java class for bib complex type. 024 * <p/> 025 * <p>The following schema fragment specifies the expected content contained within this class. 026 * <p/> 027 * <pre> 028 * <complexType name="bib"> 029 * <complexContent> 030 * <extension base="{}docstoreDocument"> 031 * <sequence> 032 * <element name="issn" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 033 * <element name="isbn" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 034 * <element name="subject" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 035 * <element name="edition" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 036 * <element name="publicationDate" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 037 * <element name="publisher" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 038 * <element name="author" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 039 * <element name="title" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> 040 * </sequence> 041 * </extension> 042 * </complexContent> 043 * </complexType> 044 * </pre> 045 */ 046@XmlAccessorType(XmlAccessType.FIELD) 047@XmlType(name = "bibDoc", propOrder = { 048 "issn", 049 "isbn", 050 "subject", 051 "edition", 052 "publicationDate", 053 "publisher", 054 "author", 055 "title" 056}) 057@XmlRootElement(name = "bibDoc") 058public class Bib 059 extends DocstoreDocument { 060 061 private static final Logger LOG = Logger.getLogger(Bib.class); 062 public static final String TITLE = "TITLE"; 063 public static final String AUTHOR = "AUTHOR"; 064 public static final String ISBN = "ISBN"; 065 public static final String ISSN = "ISSN"; 066 public static final String SUBJECT = "SUBJECT"; 067 public static final String PUBLISHER = "PUBLISHER"; 068 public static final String PUBLICATIONDATE = "PUBLICATIONDATE"; 069 public static final String EDITION = "EDITION"; 070 public static final String DESCRIPTION = "DESCRIPTION"; 071 public static final String FORMAT = "FORMAT"; 072 public static final String LANGUAGE = "LANGUAGE"; 073 public static final String BIBIDENTIFIER = "BIBIDENTIFIER"; 074 protected String issn; 075 protected String isbn; 076 protected String subject; 077 protected String edition; 078 protected String publicationDate; 079 protected String publisher; 080 protected String author; 081 protected String title; 082 083 public Bib() { 084 category = DocCategory.WORK.getCode(); 085 type = DocType.BIB.getCode(); 086 format = DocFormat.MARC.getCode(); 087 } 088 089 /** 090 * Gets the value of the issn property. 091 * 092 * @return possible object is 093 * {@link String } 094 */ 095 public String getIssn() { 096 return issn; 097 } 098 099 /** 100 * Sets the value of the issn property. 101 * 102 * @param value allowed object is 103 * {@link String } 104 */ 105 public void setIssn(String value) { 106 this.issn = value; 107 } 108 109 /** 110 * Gets the value of the isbn property. 111 * 112 * @return possible object is 113 * {@link String } 114 */ 115 public String getIsbn() { 116 return isbn; 117 } 118 119 /** 120 * Sets the value of the isbn property. 121 * 122 * @param value allowed object is 123 * {@link String } 124 */ 125 public void setIsbn(String value) { 126 this.isbn = value; 127 } 128 129 /** 130 * Gets the value of the subject property. 131 * 132 * @return possible object is 133 * {@link String } 134 */ 135 public String getSubject() { 136 return subject; 137 } 138 139 /** 140 * Sets the value of the subject property. 141 * 142 * @param value allowed object is 143 * {@link String } 144 */ 145 public void setSubject(String value) { 146 this.subject = value; 147 } 148 149 /** 150 * Gets the value of the edition property. 151 * 152 * @return possible object is 153 * {@link String } 154 */ 155 public String getEdition() { 156 return edition; 157 } 158 159 /** 160 * Sets the value of the edition property. 161 * 162 * @param value allowed object is 163 * {@link String } 164 */ 165 public void setEdition(String value) { 166 this.edition = value; 167 } 168 169 /** 170 * Gets the value of the publicationDate property. 171 * 172 * @return possible object is 173 * {@link String } 174 */ 175 public String getPublicationDate() { 176 return publicationDate; 177 } 178 179 /** 180 * Sets the value of the publicationDate property. 181 * 182 * @param value allowed object is 183 * {@link String } 184 */ 185 public void setPublicationDate(String value) { 186 this.publicationDate = value; 187 } 188 189 /** 190 * Gets the value of the publisher property. 191 * 192 * @return possible object is 193 * {@link String } 194 */ 195 public String getPublisher() { 196 return publisher; 197 } 198 199 /** 200 * Sets the value of the publisher property. 201 * 202 * @param value allowed object is 203 * {@link String } 204 */ 205 public void setPublisher(String value) { 206 this.publisher = value; 207 } 208 209 /** 210 * Gets the value of the author property. 211 * 212 * @return possible object is 213 * {@link String } 214 */ 215 public String getAuthor() { 216 return author; 217 } 218 219 /** 220 * Sets the value of the author property. 221 * 222 * @param value allowed object is 223 * {@link String } 224 */ 225 public void setAuthor(String value) { 226 this.author = value; 227 } 228 229 /** 230 * Gets the value of the title property. 231 * 232 * @return possible object is 233 * {@link String } 234 */ 235 public String getTitle() { 236 return title; 237 } 238 239 /** 240 * Sets the value of the title property. 241 * 242 * @param value allowed object is 243 * {@link String } 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; //To change body of implemented methods use File | Settings | File Templates. 295 } 296 297 @Override 298 public String serializeContent(Object object) { 299 return null; //To change body of implemented methods use File | Settings | File Templates. 300 } 301}