1 40 41 package org.dspace.content.packager; 42 43 import java.io.IOException ; 44 import java.sql.SQLException ; 45 import java.util.Set ; 46 47 import org.apache.log4j.Logger; 48 import org.dspace.authorize.AuthorizeException; 49 import org.dspace.content.Bitstream; 50 import org.dspace.content.Bundle; 51 import org.dspace.content.Collection; 52 import org.dspace.content.Item; 53 import org.dspace.content.crosswalk.CrosswalkException; 54 import org.dspace.content.crosswalk.MetadataValidationException; 55 import org.dspace.core.Context; 56 import org.dspace.license.CreativeCommons; 57 import org.jdom.Element; 58 59 74 public class DSpaceMETSIngester 75 extends AbstractMETSIngester 76 { 77 78 private static Logger log = Logger.getLogger(DSpaceMETSIngester.class); 79 80 private final static String PROFILE_START = "DSpace METS SIP Profile"; 82 83 void checkManifest(METSManifest manifest) 85 throws MetadataValidationException 86 { 87 String profile = manifest.getProfile(); 88 if (profile == null) 89 throw new MetadataValidationException("Cannot accept METS with no PROFILE attribute!"); 90 else if (!profile.startsWith(PROFILE_START)) 91 throw new MetadataValidationException("METS has unacceptable PROFILE value, profile="+profile); 92 } 93 94 public void checkPackageFiles(Set packageFiles, Set missingFiles, 96 METSManifest manifest) 97 throws PackageValidationException, CrosswalkException 98 { 99 } 102 103 104 113 public void chooseItemDmd(Context context, Item item, 114 METSManifest manifest, 115 AbstractMETSIngester.MdrefManager callback, 116 Element dmds[]) 117 throws CrosswalkException, 118 AuthorizeException, SQLException , IOException 119 { 120 int found = -1; 121 122 for (int i = 0; i < dmds.length; ++i) 124 if ("MODS".equals(manifest.getMdType(dmds[i]))) 125 found = i; 126 127 if (found == -1) 129 { 130 for (int i = 0; i < dmds.length; ++i) 131 if ("DC".equals(manifest.getMdType(dmds[i]))) 132 found = i; 133 } 134 135 String groupID = null; 136 if (found >= 0) 137 { 138 manifest.crosswalkItem(context, item, dmds[found], callback); 139 groupID = dmds[found].getAttributeValue("GROUPID"); 140 141 if (groupID != null) 142 { 143 for (int i = 0; i < dmds.length; ++i) 144 { 145 String g = dmds[i].getAttributeValue("GROUPID"); 146 if (g != null && !g.equals(groupID)) 147 manifest.crosswalkItem(context, item, dmds[i], callback); 148 } 149 } 150 } 151 152 else 155 { 156 if (dmds.length > 0) 157 manifest.crosswalkItem(context, item, dmds[0], callback); 158 } 159 } 160 161 162 168 public void addLicense(Context context, Collection collection, 169 Item item, METSManifest manifest, 170 AbstractMETSIngester.MdrefManager callback, 171 String license) 172 throws PackageValidationException, CrosswalkException, 173 AuthorizeException, SQLException , IOException 174 { 175 PackageUtils.addDepositLicense(context, license, item, collection); 176 177 Element rmds[] = manifest.getItemRightsMD(); 179 for (int i = 0; i < rmds.length; ++i) 180 { 181 String type = manifest.getMdType(rmds[i]); 182 if (type != null && type.equals("Creative Commons")) 183 { 184 log.debug("Got Creative Commons license in rightsMD"); 185 CreativeCommons.setLicense(context, item, 186 manifest.getMdContentAsStream(rmds[i], callback), 187 manifest.getMdContentMimeType(rmds[i])); 188 189 Element mdRef = rmds[i].getChild("mdRef", METSManifest.metsNS); 192 if (mdRef != null) 193 { 194 Bitstream bs = callback.getBitstreamForMdRef(mdRef); 195 if (bs != null) 196 { 197 Bundle parent[] = bs.getBundles(); 198 if (parent.length > 0) 199 { 200 parent[0].removeBitstream(bs); 201 parent[0].update(); 202 } 203 } 204 } 205 } 206 } 207 } 208 209 public void finishItem(Context context, Item item) 211 throws PackageValidationException, CrosswalkException, 212 AuthorizeException, SQLException , IOException 213 { 214 } 216 } 217 | Popular Tags |