1 40 package org.dspace.app.oai; 41 42 import java.util.Properties ; 43 import java.io.StringWriter ; 44 import java.io.PrintWriter ; 45 46 import org.dspace.content.Item; 47 import org.dspace.core.PluginManager; 48 import org.dspace.search.HarvestedItemInfo; 49 import org.dspace.content.crosswalk.DisseminationCrosswalk; 50 51 import org.apache.log4j.Logger; 52 53 import ORG.oclc.oai.server.crosswalk.Crosswalk; 54 import ORG.oclc.oai.server.verb.CannotDisseminateFormatException; 55 56 import org.jdom.*; 57 import org.jdom.output.XMLOutputter; 58 import org.jdom.output.Format; 59 60 97 public class PluginCrosswalk extends Crosswalk 98 { 99 100 private static Logger log = Logger.getLogger(PluginCrosswalk.class); 101 102 private DisseminationCrosswalk xwalk = null; 103 104 private String schemaLabel = null; 106 107 private static XMLOutputter outputUgly = new XMLOutputter(); 108 109 119 private static String makeSchemaLocation(String schemaLabel) 120 { 121 DisseminationCrosswalk xwalk = (DisseminationCrosswalk) 122 PluginManager.getNamedPlugin(DisseminationCrosswalk.class, 123 schemaLabel); 124 if (xwalk != null) 125 { 126 String schemaLoc = xwalk.getSchemaLocation(); 127 128 if (schemaLoc != null) 131 { 132 log.debug("Initialized schemaLabel="+schemaLabel+" with schemaLocation = \""+schemaLoc+"\""); 133 return schemaLoc; 134 } 135 log.error("makeSchemaLocation: crosswalk cannot provide schemaLocation, label="+schemaLabel); 136 return "Error No-schemaLocation-for-"+schemaLabel; 137 } 138 log.error("No crosswalk found, makeSchemaLocation giving up, label="+schemaLabel); 139 return "Error No-crosswalk-for-"+schemaLabel; 140 } 141 142 154 public PluginCrosswalk(String schemaLabel, Properties properties) 155 { 156 super(makeSchemaLocation(schemaLabel)); 157 xwalk = (DisseminationCrosswalk)PluginManager.getNamedPlugin( 158 DisseminationCrosswalk.class, schemaLabel); 159 this.schemaLabel = schemaLabel; 160 } 161 162 165 public boolean isAvailableFor(Object nativeItem) 166 { 167 Item item = ((HarvestedItemInfo) nativeItem).item; 168 return xwalk.canDisseminate(item); 169 } 170 171 174 public String createMetadata(Object nativeItem) 175 throws CannotDisseminateFormatException 176 { 177 Item item = ((HarvestedItemInfo) nativeItem).item; 178 try 179 { 180 log.debug("OAI plugin, schema="+schemaLabel+", preferList="+String.valueOf(xwalk.preferList())); 181 if (xwalk.preferList()) 182 return outputUgly.outputString(xwalk.disseminateList(item)); 183 else 184 return outputUgly.outputString(xwalk.disseminateElement(item)); 185 } 186 catch (Exception e) 187 { 188 log.error(this.getClass().getName()+ 189 ": hiding exception in CannotDisseminateFormatException:"+ 190 e.toString()); 191 192 StringWriter sw = new StringWriter (); 193 e.printStackTrace(new PrintWriter (sw)); 194 log.error("*** Stack trace follows:"); 195 log.error(sw.toString()); 196 197 throw new CannotDisseminateFormatException(schemaLabel); 198 } 199 } 200 } 201 | Popular Tags |