1 40 41 package org.dspace.content.crosswalk; 42 43 import java.io.OutputStream ; 44 import java.io.IOException ; 45 import java.util.ArrayList ; 46 import java.util.List ; 47 48 import java.sql.SQLException ; 49 50 import org.dspace.core.Context; 51 import org.dspace.core.Constants; 52 import org.dspace.content.Item; 53 import org.dspace.content.DSpaceObject; 54 import org.dspace.content.DCValue; 55 import org.dspace.core.SelfNamedPlugin; 56 import org.dspace.authorize.AuthorizeException; 57 58 import org.jdom.*; 59 62 71 public class SimpleDCDisseminationCrosswalk extends SelfNamedPlugin 72 implements DisseminationCrosswalk 73 { 74 76 78 private static final Namespace DC_NS = 79 Namespace.getNamespace("dc", "http://purl.org/dc/elements/1.1/"); 80 81 private static final String DC_XSD = 83 "http://dublincore.org/schemas/xmls/simpledc20021212.xsd"; 84 86 private static final String schemaLocation = 87 DC_NS.getURI()+" "+DC_XSD; 88 89 private static final Namespace namespaces[] = 90 { DC_NS, XSI_NS }; 91 92 private final static String aliases[] = { "SimpleDC", "DC" }; 93 94 public static String [] getPluginNames() 95 { 96 return aliases; 97 } 98 99 public Element disseminateElement(DSpaceObject dso) 100 throws CrosswalkException, 101 IOException , SQLException , AuthorizeException 102 { 103 Element root = new Element("simpledc", DC_NS); 104 root.setAttribute("schemaLocation", schemaLocation, XSI_NS); 105 root.addContent(disseminateListInternal(dso, false)); 106 return root; 107 } 108 109 114 public List disseminateList(DSpaceObject dso) 115 throws CrosswalkException, 116 IOException , SQLException , AuthorizeException 117 { 118 return disseminateListInternal(dso, true); 119 } 120 121 public List disseminateListInternal(DSpaceObject dso, boolean addSchema) 122 throws CrosswalkException, 123 IOException , SQLException , AuthorizeException 124 { 125 if (dso.getType() != Constants.ITEM) 126 throw new CrosswalkObjectNotSupported("SimpleDCDisseminationCrosswalk can only crosswalk an Item."); 127 128 Item item = (Item)dso; 129 DCValue[] allDC = item.getDC(Item.ANY, Item.ANY, Item.ANY); 130 131 List dcl = new ArrayList (allDC.length); 132 133 for (int i = 0; i < allDC.length; i++) 134 { 135 if (!(allDC[i].element.equals("description") && 137 (allDC[i].qualifier != null && allDC[i].qualifier.equals("provenance")))) 138 { 139 String element; 140 141 if (allDC[i].element.equals("contributor") 143 && (allDC[i].qualifier != null) 144 && allDC[i].qualifier.equals("author")) 145 element = "creator"; 146 else 147 element = allDC[i].element; 148 Element field = new Element(element, DC_NS); 149 field.addContent(allDC[i].value); 150 if (addSchema) 151 field.setAttribute("schemaLocation", schemaLocation, XSI_NS); 152 dcl.add(field); 153 } 154 } 155 return dcl; 156 } 157 158 public Namespace[] getNamespaces() 159 { 160 return namespaces; 161 } 162 163 public String getSchemaLocation() 164 { 165 return schemaLocation; 166 } 167 168 public boolean canDisseminate(DSpaceObject dso) 169 { 170 return dso.getType() == Constants.ITEM; 171 } 172 173 public boolean preferList() 174 { 175 return true; 176 } 177 } 178 | Popular Tags |