1 40 package org.dspace.app.oai; 41 42 import java.io.ByteArrayOutputStream ; 43 import java.util.Properties ; 44 45 import org.dspace.app.mets.METSExport; 46 import org.dspace.search.HarvestedItemInfo; 47 48 import ORG.oclc.oai.server.crosswalk.Crosswalk; 49 import ORG.oclc.oai.server.verb.CannotDisseminateFormatException; 50 51 59 public class METSCrosswalk extends Crosswalk 60 { 61 public METSCrosswalk(Properties properties) 62 { 63 super( 64 "http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd"); 65 } 66 67 public boolean isAvailableFor(Object nativeItem) 68 { 69 return true; 71 } 72 73 public String createMetadata(Object nativeItem) 74 throws CannotDisseminateFormatException 75 { 76 HarvestedItemInfo hii = (HarvestedItemInfo) nativeItem; 77 78 try 79 { 80 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 81 82 METSExport.writeMETS(hii.context, hii.item, baos, true); 83 84 String fullXML = baos.toString("UTF-8"); 88 String head = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n"; 89 int pos = fullXML.indexOf(head); 90 if (pos != -1) 91 { 92 fullXML = fullXML.substring(pos + head.length()); 93 } 94 95 return fullXML; 96 } 97 catch (Exception e) 98 { 99 e.printStackTrace(); 100 return null; 101 } 102 103 } 104 } 105 | Popular Tags |