1 40 41 package org.dspace.content.packager; 42 43 import java.io.IOException ; 44 import java.io.InputStream ; 45 import java.sql.SQLException ; 46 47 import org.apache.log4j.Logger; 48 import org.dspace.authorize.AuthorizeException; 49 import org.dspace.content.Bitstream; 50 import org.dspace.content.BitstreamFormat; 51 import org.dspace.content.Bundle; 52 import org.dspace.content.Item; 53 import org.dspace.core.Constants; 54 import org.dspace.core.Context; 55 import org.dspace.license.CreativeCommons; 56 57 import edu.harvard.hul.ois.mets.AmdSec; 58 import edu.harvard.hul.ois.mets.BinData; 59 import edu.harvard.hul.ois.mets.Loctype; 60 import edu.harvard.hul.ois.mets.MdRef; 61 import edu.harvard.hul.ois.mets.MdWrap; 62 import edu.harvard.hul.ois.mets.Mdtype; 63 import edu.harvard.hul.ois.mets.Mets; 64 import edu.harvard.hul.ois.mets.RightsMD; 65 import edu.harvard.hul.ois.mets.helper.Base64; 66 import edu.harvard.hul.ois.mets.helper.MetsException; 67 68 86 public class DSpaceMETSDisseminator 87 extends AbstractMETSDisseminator 88 { 89 90 private static Logger log = Logger.getLogger(DSpaceMETSDisseminator.class); 91 92 97 private final static String PROFILE_LABEL = "DSpace METS SIP Profile 1.0"; 98 99 private final static String DSPACE_DEPOSIT_LICENSE_MDTYPE = 101 "DSpace Deposit License"; 102 103 private final static String CREATIVE_COMMONS_LICENSE_MDTYPE = 105 "Creative Commons"; 106 107 112 public String getProfile() 113 { 114 return PROFILE_LABEL; 115 } 116 117 125 public String bundleToFileGrp(String bname) 126 { 127 if (bname.equals("ORIGINAL")) 128 return "CONTENT"; 129 else 130 return bname; 131 } 132 133 140 public String [] getDmdTypes(PackageParameters params) 141 throws SQLException , IOException , AuthorizeException 142 { 143 144 146 String result[] = null; 147 if (params != null) 148 result = params.getProperties("dmd"); 149 if (result == null || result.length == 0) 150 { 151 result = new String [1]; 152 result[0] = "MODS"; 153 } 154 return result; 155 } 156 157 162 public String getTechMdType(PackageParameters params) 163 throws SQLException , IOException , AuthorizeException 164 { 165 return "PREMIS"; 166 } 167 168 172 public void addRightsMd(Context context, Item item, AmdSec amdSec) 173 throws SQLException , IOException , AuthorizeException, MetsException 174 { 175 addDepositLicense(context, item, amdSec); 176 addCreativeCommons(context, item, amdSec); 177 } 178 179 private boolean addDepositLicense(Context context, Item item, AmdSec amdSec) 183 throws SQLException , IOException , AuthorizeException, MetsException 184 { 185 Bitstream licenseBs = findDepositLicense(context, item); 186 187 if (licenseBs == null) 188 return false; 189 else 190 { 191 String resource = "depositlicense_"+ 192 String.valueOf(licenseBs.getSequenceID())+".txt"; 193 addRightsStream(licenseBs.retrieve(), resource, "text/plain", 194 DSPACE_DEPOSIT_LICENSE_MDTYPE, amdSec); 195 return true; 196 } 197 } 198 199 private boolean addCreativeCommons(Context context, Item item, AmdSec amdSec) 201 throws SQLException , IOException , AuthorizeException, MetsException 202 { 203 Bitstream cc; 205 206 if ((cc = CreativeCommons.getLicenseRdfBitstream(item)) != null) 207 { 208 addRightsStream(cc.retrieve(), 209 (gensym("creativecommons") + ".rdf"), 210 "text/rdf", 211 CREATIVE_COMMONS_LICENSE_MDTYPE, amdSec); 212 } 213 else if ((cc = CreativeCommons.getLicenseTextBitstream(item)) != null) 214 { 215 addRightsStream(cc.retrieve(), 216 (gensym("creativecommons") + ".txt"), 217 "text/plain", 218 CREATIVE_COMMONS_LICENSE_MDTYPE, amdSec); 219 } 220 else 221 return false; 222 return true; 223 } 224 225 private void addRightsStream(InputStream is , String resourceName, 228 String mimeType, String mdType, AmdSec amdSec) 229 throws IOException , MetsException 230 { 231 RightsMD rightsMD = new RightsMD(); 232 rightsMD.setID(gensym("rights")); 233 if (extraFiles == null) 234 { 235 MdWrap rightsMDWrap = new MdWrap(); 236 rightsMDWrap.setMIMETYPE(mimeType); 237 rightsMDWrap.setMDTYPE(Mdtype.OTHER); 238 rightsMDWrap.setOTHERMDTYPE(mdType); 239 BinData bin = new BinData(); 240 bin.getContent().add(new Base64(is)); 241 rightsMDWrap.getContent().add(bin); 242 rightsMD.getContent().add(rightsMDWrap); 243 } 244 else 245 { 246 extraFiles.put(resourceName, is); 247 MdRef rightsMDRef = new MdRef(); 248 rightsMDRef.setMIMETYPE(mimeType); 249 rightsMDRef.setMDTYPE(Mdtype.OTHER); 250 rightsMDRef.setOTHERMDTYPE(mdType); 251 rightsMDRef.setLOCTYPE(Loctype.URL); 252 rightsMDRef.setXlinkHref(resourceName); 253 rightsMD.getContent().add(rightsMDRef); 254 } 255 amdSec.getContent().add(rightsMD); 256 } 257 258 270 private static Bitstream findDepositLicense(Context context, Item item) 271 throws SQLException , IOException , AuthorizeException 272 { 273 int licenseFormatId = -1; 275 BitstreamFormat bf = BitstreamFormat.findByShortDescription(context, 276 "License"); 277 if (bf != null) 278 licenseFormatId = bf.getID(); 279 280 Bundle[] bundles = item.getBundles(Constants.LICENSE_BUNDLE_NAME); 281 for (int i = 0; i < bundles.length; i++) 282 { 283 Bitstream[] bitstreams = bundles[i].getBitstreams(); 285 286 if (bitstreams[0].getFormat().getID() == licenseFormatId) 287 { 288 return bitstreams[0]; 289 } 290 } 291 292 return null; 294 } 295 296 public void addStructMap(Context context, Item item, 298 PackageParameters params, Mets mets) 299 throws SQLException , IOException , AuthorizeException, MetsException 300 { 301 } 302 } 303 | Popular Tags |