View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole;
17  
18  import com.thoughtworks.xstream.XStream;
19  import com.thoughtworks.xstream.io.xml.DomDriver;
20  import com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer;
21  import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.DCValue;
22  import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.WorkBibDublinRecord;
23  import org.kuali.ole.docstore.model.xstream.work.bib.dublin.DCValueConverter;
24  import org.kuali.ole.docstore.model.xstream.work.bib.dublin.WorkBibDublinRecordConverter;
25  
26  /**
27   * Class to process Work Bib Dublin Records from and to XML.
28   *
29   * @author Rajesh Chowdary K
30   */
31  public class QualifiedDublinRecordHandler {
32      /**
33       * Method to covert xml content to QualifiedDublinRecord.
34       *
35       * @param fileContent
36       * @return
37       */
38      public WorkBibDublinRecord fromXML(String fileContent) {
39          //throws ParserConfigurationException, IOException, SAXException, XPathExpressionException {
40          XStream xStream = new XStream();
41          xStream.alias("dublin_core", WorkBibDublinRecord.class);
42          xStream.alias("dcvalue", DCValue.class);
43          xStream.addImplicitCollection(WorkBibDublinRecord.class, "dcValues", DCValue.class);
44          xStream.registerConverter(new WorkBibDublinRecordConverter());
45          xStream.registerConverter(new DCValueConverter());
46  
47          return (WorkBibDublinRecord) xStream.fromXML(fileContent);
48      }
49  
50      /**
51       * Method to covert QualifiedDublinRecord to XML Format.
52       *
53       * @param rec
54       * @return
55       */
56      public String toXml(WorkBibDublinRecord rec) {
57          XmlFriendlyReplacer replacer = new XmlFriendlyReplacer("ddd", "_");
58          XStream xStream = new XStream(new DomDriver("UTF-8", replacer));
59          xStream.alias("dublin_core", WorkBibDublinRecord.class);
60          xStream.alias("dcvalue", DCValue.class);
61          xStream.addImplicitCollection(WorkBibDublinRecord.class, "dcValues", DCValue.class);
62          xStream.registerConverter(new WorkBibDublinRecordConverter());
63          xStream.registerConverter(new DCValueConverter());
64          return xStream.toXML(rec);
65      }
66  
67  }