1 40 package org.dspace.app.oai; 41 42 import java.util.Properties ; 43 44 import org.dspace.content.DCValue; 45 import org.dspace.content.Item; 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 58 public class OAIDCCrosswalk extends Crosswalk 59 { 60 public OAIDCCrosswalk(Properties properties) 61 { 62 super( 63 "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"); 64 } 65 66 public boolean isAvailableFor(Object nativeItem) 67 { 68 return true; 70 } 71 72 public String createMetadata(Object nativeItem) 73 throws CannotDisseminateFormatException 74 { 75 Item item = ((HarvestedItemInfo) nativeItem).item; 76 77 DCValue[] allDC = item.getDC(Item.ANY, Item.ANY, Item.ANY); 79 80 StringBuffer metadata = new StringBuffer (); 81 82 metadata 83 .append( 84 "<oai_dc:dc xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\" ") 85 .append("xmlns:dc=\"http://purl.org/dc/elements/1.1/\" ") 86 .append( 87 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ") 88 .append( 89 "xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd\">"); 90 91 for (int i = 0; i < allDC.length; i++) 92 { 93 boolean description = allDC[i].element.equals("description"); 95 boolean provenance = (allDC[i].qualifier != null) 96 && allDC[i].qualifier.equals("provenance"); 97 98 if (!(description && provenance)) 99 { 100 String element = allDC[i].element; 101 102 if (allDC[i].element.equals("contributor") 104 && (allDC[i].qualifier != null) 105 && allDC[i].qualifier.equals("author")) 106 { 107 element = "creator"; 108 } 109 110 String value = allDC[i].value; 112 113 int c = -1; 116 117 while ((c = value.indexOf("&", c + 1)) > -1) 118 { 119 value = value.substring(0, c) + "&" 120 + value.substring(c + 1); 121 } 122 123 while ((c = value.indexOf("<")) > -1) 124 { 125 value = value.substring(0, c) + "<" 126 + value.substring(c + 1); 127 } 128 129 while ((c = value.indexOf(">")) > -1) 130 { 131 value = value.substring(0, c) + ">" 132 + value.substring(c + 1); 133 } 134 135 metadata.append("<dc:").append(element).append(">").append( 136 value).append("</dc:").append(element).append(">"); 137 } 138 } 139 140 metadata.append("</oai_dc:dc>"); 141 142 return metadata.toString(); 143 } 144 } 145 | Popular Tags |