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.select.service.impl; 17 18 import org.kuali.ole.select.businessobject.BibInfoBean; 19 import org.kuali.ole.select.service.BibMarcXMLGenerationService; 20 21 import java.util.HashMap; 22 23 public class BibMarcXMLGenerationServiceImpl implements BibMarcXMLGenerationService { 24 private static BibMarcXMLGenerationServiceImpl bibMarcXMLGenerationServiceImpl; 25 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BibMarcXMLGenerationServiceImpl.class); 26 27 28 private String buildXmlString(BibInfoBean bibInfoBean, HashMap dataMap) throws Exception { 29 //StringBuffer xmlString = new StringBuffer(); 30 StringBuilder xmlString = new StringBuilder(); 31 //xmlString.append("<?xml version=\"1.0\"?>"); 32 xmlString.append("<collection>"); 33 xmlString.append("<record>"); 34 xmlString.append("<leader>" + bibInfoBean.getLeader() + "</leader>"); 35 xmlString.append("<controlfield tag=\"001\"></controlfield>"); 36 xmlString.append("<controlfield tag=\"008\">" + bibInfoBean.getControlField() + "</controlfield>"); 37 if (bibInfoBean.getStandardNumber() != null && !bibInfoBean.getStandardNumber().isEmpty()) { 38 xmlString.append("<datafield tag=\"020\" >"); 39 xmlString.append("<subfield code=\"a\">").append(bibInfoBean.getStandardNumber()).append("</subfield>"); 40 xmlString.append("</datafield>"); 41 } 42 if (bibInfoBean.getAuthor() != null && !bibInfoBean.getAuthor().isEmpty()) { 43 xmlString.append("<datafield tag=\"100\" >"); 44 xmlString.append("<subfield code=\"a\">").append(bibInfoBean.getAuthor()).append("</subfield>"); 45 xmlString.append("</datafield>"); 46 } 47 if (bibInfoBean.getTitle() != null && !bibInfoBean.getTitle().isEmpty()) { 48 xmlString.append("<datafield tag=\"245\" >"); 49 xmlString.append("<subfield code=\"a\">").append(bibInfoBean.getTitle()).append("</subfield>"); 50 xmlString.append("</datafield>"); 51 } 52 if (bibInfoBean.getEdition() != null && !bibInfoBean.getEdition().isEmpty()) { 53 xmlString.append("<datafield tag=\"250\" >"); 54 xmlString.append("<subfield code=\"a\">").append(bibInfoBean.getEdition()).append("</subfield>"); 55 xmlString.append("</datafield>"); 56 } 57 if ((bibInfoBean.getPlaceOfPublication() != null && !bibInfoBean.getPlaceOfPublication().isEmpty()) || (bibInfoBean.getPublisher() != null && !bibInfoBean.getPublisher().isEmpty()) || (bibInfoBean.getYearOfPublication() != null && !bibInfoBean.getYearOfPublication().isEmpty())) { 58 xmlString.append("<datafield tag=\"260\" >"); 59 //if (bibInfoBean.getPlaceOfPublication() != null) 60 xmlString.append("<subfield code=\"a\">").append(bibInfoBean.getPlaceOfPublication()).append("</subfield>"); 61 //if (bibInfoBean.getPublisher() != null) 62 xmlString.append("<subfield code=\"b\">").append(bibInfoBean.getPublisher()).append("</subfield>"); 63 //if (bibInfoBean.getYearOfPublication() != null) 64 xmlString.append("<subfield code=\"c\">").append(bibInfoBean.getYearOfPublication()).append("</subfield>"); 65 xmlString.append("</datafield>"); 66 } 67 if (bibInfoBean.getSeriesOfStatement() != null && !bibInfoBean.getSeriesOfStatement().isEmpty()) { 68 xmlString.append("<datafield tag=\"490\" >"); 69 xmlString.append("<subfield code=\"a\">").append(bibInfoBean.getSeriesOfStatement()).append("</subfield>"); 70 xmlString.append("</datafield>"); 71 } 72 /*if ((bibInfoBean.getFundCode() != null && !bibInfoBean.getFundCode().isEmpty()) || ((bibInfoBean.getLocation() != null)&& !bibInfoBean.getLocation().isEmpty())) { 73 xmlString.append("<datafield tag=\"960\" >"); 74 //if (bibInfoBean.getFundCode() != null) 75 xmlString.append("<subfield code=\"a\">").append(bibInfoBean.getFundCode()).append("</subfield>"); 76 //if (bibInfoBean.getLocation() != null) 77 xmlString.append("<subfield code=\"h\">").append(bibInfoBean.getLocation()).append("</subfield>"); 78 xmlString.append("</datafield>"); 79 } 80 if (bibInfoBean.getRequestersNotes() != null && !bibInfoBean.getRequestersNotes().isEmpty() ) { 81 xmlString.append("<datafield tag=\"961\" >"); 82 xmlString.append("<subfield code=\"d\">").append(bibInfoBean.getRequestersNotes()).append("</subfield>"); 83 xmlString.append("</datafield>"); 84 } 85 if (dataMap.containsKey("unitPrice") || dataMap.containsKey("itemQuantity")) { 86 xmlString.append("<datafield tag=\"980\" >"); 87 //if (dataMap.containsKey("unitPrice")) 88 xmlString.append("<subfield code=\"b\">").append(dataMap.get("unitPrice")).append("</subfield>"); 89 //if (dataMap.containsKey("itemQuantity")) 90 xmlString.append("<subfield code=\"q\">").append(dataMap.get("itemQuantity")).append("</subfield>"); 91 xmlString.append("</datafield>"); 92 } 93 if (dataMap.containsKey("ybpOrderKey") || dataMap.containsKey("subAccountNo") || dataMap.containsKey("binding") || dataMap.containsKey("initials")) { 94 xmlString.append("<datafield tag=\"982\" >"); 95 //if (dataMap.containsKey("ybpOrderKey")) 96 xmlString.append("<subfield code=\"a\">").append(dataMap.get("ybpOrderKey")).append("</subfield>"); 97 //if (dataMap.containsKey("subAccountNo")) 98 xmlString.append("<subfield code=\"b\">").append(dataMap.get("subAccountNo")).append("</subfield>"); 99 //if (dataMap.containsKey("binding")) 100 xmlString.append("<subfield code=\"d\">").append(dataMap.get("binding")).append("</subfield>"); 101 //if (dataMap.containsKey("initials")) 102 xmlString.append("<subfield code=\"f\">").append(dataMap.get("initials")).append("</subfield>"); 103 xmlString.append("</datafield>"); 104 } 105 if (dataMap.containsKey("dateOrdered") || dataMap.containsKey("vendorCode")) { 106 xmlString.append("<datafield tag=\"984\" >"); 107 //if (dataMap.containsKey("dateOrdered")) 108 if ((bibInfoBean.getFundCode() != null && !bibInfoBean.getFundCode().isEmpty()) || ((bibInfoBean.getLocation() != null)&& !bibInfoBean.getLocation().isEmpty())) { 109 xmlString.append("<datafield tag=\"960\" >"); 110 //if (bibInfoBean.getFundCode() != null) 111 xmlString.append("<subfield code=\"a\">").append(bibInfoBean.getFundCode()).append("</subfield>"); 112 //if (bibInfoBean.getLocation() != null) 113 xmlString.append("<subfield code=\"h\">").append(bibInfoBean.getLocation()).append("</subfield>"); 114 xmlString.append("</datafield>"); 115 } 116 if (bibInfoBean.getRequestersNotes() != null && !bibInfoBean.getRequestersNotes().isEmpty() ) { 117 xmlString.append("<datafield tag=\"961\" >"); 118 xmlString.append("<subfield code=\"d\">").append(bibInfoBean.getRequestersNotes()).append("</subfield>"); 119 xmlString.append("</datafield>"); 120 } 121 if (dataMap.containsKey("unitPrice") || dataMap.containsKey("itemQuantity")) { 122 xmlString.append("<datafield tag=\"980\" >"); 123 //if (dataMap.containsKey("unitPrice")) 124 xmlString.append("<subfield code=\"b\">").append(dataMap.get("unitPrice")).append("</subfield>"); 125 //if (dataMap.containsKey("itemQuantity")) 126 xmlString.append("<subfield code=\"q\">").append(dataMap.get("itemQuantity")).append("</subfield>"); 127 xmlString.append("</datafield>"); 128 } 129 if (dataMap.containsKey("ybpOrderKey") || dataMap.containsKey("subAccountNo") || dataMap.containsKey("binding") || dataMap.containsKey("initials")) { 130 xmlString.append("<datafield tag=\"982\" >"); 131 //if (dataMap.containsKey("ybpOrderKey")) 132 xmlString.append("<subfield code=\"a\">").append(dataMap.get("ybpOrderKey")).append("</subfield>"); 133 //if (dataMap.containsKey("subAccountNo")) 134 xmlString.append("<subfield code=\"b\">").append(dataMap.get("subAccountNo")).append("</subfield>"); 135 //if (dataMap.containsKey("binding")) 136 xmlString.append("<subfield code=\"d\">").append(dataMap.get("binding")).append("</subfield>"); 137 //if (dataMap.containsKey("initials")) 138 xmlString.append("<subfield code=\"f\">").append(dataMap.get("initials")).append("</subfield>"); 139 xmlString.append("</datafield>"); 140 } 141 if (dataMap.containsKey("dateOrdered") || dataMap.containsKey("vendorCode")) { 142 xmlString.append("<datafield tag=\"984\" >"); 143 //if (dataMap.containsKey("dateOrdered")) 144 xmlString.append("<subfield code=\"a\">").append(dataMap.get("dateOrdered")).append("</subfield>"); 145 //if (dataMap.containsKey("vendorCode")) 146 xmlString.append("<subfield code=\"c\">").append(dataMap.get("vendorCode")).append("</subfield>"); 147 xmlString.append("</datafield>"); 148 } 149 if (dataMap.containsKey("ybpUID")) { 150 xmlString.append("<datafield tag=\"987\" >"); 151 xmlString.append("<subfield code=\"a\">").append(dataMap.get("ybpUID")).append("</subfield>"); 152 xmlString.append("</datafield>"); 153 } 154 if (bibInfoBean.getSeries() != null && !bibInfoBean.getSeries().isEmpty()) { 155 xmlString.append("<datafield tag=\"993\" >"); 156 xmlString.append("<subfield code=\"a\">").append(bibInfoBean.getSeries()).append("</subfield>"); 157 xmlString.append("</datafield>"); 158 } xmlString.append("<subfield code=\"a\">").append(dataMap.get("dateOrdered")).append("</subfield>"); 159 //if (dataMap.containsKey("vendorCode")) 160 xmlString.append("<subfield code=\"c\">").append(dataMap.get("vendorCode")).append("</subfield>"); 161 xmlString.append("</datafield>"); 162 } 163 if (dataMap.containsKey("ybpUID")) { 164 xmlString.append("<datafield tag=\"987\" >"); 165 xmlString.append("<subfield code=\"a\">").append(dataMap.get("ybpUID")).append("</subfield>"); 166 xmlString.append("</datafield>"); 167 } 168 if (bibInfoBean.getSeries() != null && !bibInfoBean.getSeries().isEmpty()) { 169 xmlString.append("<datafield tag=\"993\" >"); 170 xmlString.append("<subfield code=\"a\">").append(bibInfoBean.getSeries()).append("</subfield>"); 171 xmlString.append("</datafield>"); 172 }*/ 173 xmlString.append("</record>"); 174 xmlString.append("</collection>"); 175 if (LOG.isDebugEnabled()) 176 LOG.debug("xmlString----------->" + xmlString.toString()); 177 return xmlString.toString(); 178 } 179 180 public String getMarcXML(BibInfoBean bibInfoBean, HashMap dataMap) throws Exception { 181 return buildXmlString(bibInfoBean, dataMap); 182 } 183 184 /* public static void main(String args[]){ 185 try{ 186 writeToXMLFile(); 187 }catch(Exception e){ 188 e.printStackTrace(); 189 } 190 }*/ 191 }