001/* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.ole; 017 018import com.thoughtworks.xstream.XStream; 019import com.thoughtworks.xstream.io.xml.DomDriver; 020import com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer; 021import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.DCValue; 022import org.kuali.ole.docstore.model.xmlpojo.work.bib.dublin.WorkBibDublinRecord; 023import org.kuali.ole.docstore.model.xstream.work.bib.dublin.DCValueConverter; 024import org.kuali.ole.docstore.model.xstream.work.bib.dublin.WorkBibDublinRecordConverter; 025 026/** 027 * Class to process Work Bib Dublin Records from and to XML. 028 * 029 * @author Rajesh Chowdary K 030 */ 031public class QualifiedDublinRecordHandler { 032 /** 033 * Method to covert xml content to QualifiedDublinRecord. 034 * 035 * @param fileContent 036 * @return 037 */ 038 public WorkBibDublinRecord fromXML(String fileContent) { 039 //throws ParserConfigurationException, IOException, SAXException, XPathExpressionException { 040 XStream xStream = new XStream(); 041 xStream.alias("dublin_core", WorkBibDublinRecord.class); 042 xStream.alias("dcvalue", DCValue.class); 043 xStream.addImplicitCollection(WorkBibDublinRecord.class, "dcValues", DCValue.class); 044 xStream.registerConverter(new WorkBibDublinRecordConverter()); 045 xStream.registerConverter(new DCValueConverter()); 046 047 return (WorkBibDublinRecord) xStream.fromXML(fileContent); 048 } 049 050 /** 051 * Method to covert QualifiedDublinRecord to XML Format. 052 * 053 * @param rec 054 * @return 055 */ 056 public String toXml(WorkBibDublinRecord rec) { 057 XmlFriendlyReplacer replacer = new XmlFriendlyReplacer("ddd", "_"); 058 XStream xStream = new XStream(new DomDriver("UTF-8", replacer)); 059 xStream.alias("dublin_core", WorkBibDublinRecord.class); 060 xStream.alias("dcvalue", DCValue.class); 061 xStream.addImplicitCollection(WorkBibDublinRecord.class, "dcValues", DCValue.class); 062 xStream.registerConverter(new WorkBibDublinRecordConverter()); 063 xStream.registerConverter(new DCValueConverter()); 064 return xStream.toXML(rec); 065 } 066 067}