Package org.dspace.content

Examples of org.dspace.content.Bundle


                if (mdRef != null)
                {
                    Bitstream bs = callback.getBitstreamForMdRef(mdRef);
                    if (bs != null)
                    {
                        Bundle parent[] = bs.getBundles();
                        if (parent.length > 0)
                        {
                            parent[0].removeBitstream(bs);
                            parent[0].update();
                        }
View Full Code Here


       
        // get bitstream filename, calculate destination filename
        String newName = formatFilter.getFilteredName(source.getName());

        Bitstream existingBitstream = null; // is there an existing rendition?
        Bundle targetBundle = null; // bundle we're modifying

        Bundle[] bundles = item.getBundles(formatFilter.getBundleName());

        // check if destination bitstream exists
        if (bundles.length > 0)
        {
            // only finds the last match (FIXME?)
            for (int i = 0; i < bundles.length; i++)
            {
                Bitstream[] bitstreams = bundles[i].getBitstreams();

                for (int j = 0; j < bitstreams.length; j++)
                {
                    if (bitstreams[j].getName().equals(newName))
                    {
                        targetBundle = bundles[i];
                        existingBitstream = bitstreams[j];
                    }
                }
            }
        }

        // if exists and overwrite = false, exit
        if (!overWrite && (existingBitstream != null))
        {
            if (!isQuiet)
            System.out.println("SKIPPED: bitstream " + source.getID()
                    + " (item: " + item.getHandle() + ") because '" + newName + "' already exists");

            return false;
        }
       
        InputStream destStream = formatFilter.getDestinationStream(source.retrieve());
        if (destStream == null)
        {
            if (!isQuiet)
            System.out.println("SKIPPED: bitstream " + source.getID()
                    + " (item: " + item.getHandle() + ") because filtering was unsuccessful");

            return false;
        }

        // create new bundle if needed
        if (bundles.length < 1)
        {
            targetBundle = item.createBundle(formatFilter.getBundleName());
        }
        else
        {
            // take the first match
            targetBundle = bundles[0];
        }

        Bitstream b = targetBundle.createBitstream(destStream);

        // Now set the format and name of the bitstream
        b.setName(newName);
        b.setSource("Written by FormatFilter " + formatFilter.getClass().getName() +
              " on " + DCDate.getCurrent() + " (GMT).");
        b.setDescription(formatFilter.getDescription());

        // Find the proper format
        BitstreamFormat bf = BitstreamFormat.findByShortDescription(c,
                formatFilter.getFormatString());
        b.setFormat(bf);
        b.update();
       
        //Inherit policies from the source bitstream
        //(first remove any existing policies)
        AuthorizeManager.removeAllPolicies(c, b);
        AuthorizeManager.inheritPolicies(c, source, b);

        // fixme - set date?
        // we are overwriting, so remove old bitstream
        if (existingBitstream != null)
        {
            targetBundle.removeBitstream(existingBitstream);
        }

        if (!isQuiet)
        System.out.println("FILTERED: bitstream " + source.getID()
                + " (item: " + item.getHandle() + ") and created '" + newName + "'");
View Full Code Here

               AuthorizeException, SQLException, IOException
    {
        InputStream bis = null;
        COSDocument cos = null;
        boolean success = false;
        Bundle original = null;
        Bitstream bs = null;
        WorkspaceItem wi = null;

        /** XXX comment out for now
          // XXX for debugging of parameter handling
          if (params != null)
          {
              Enumeration pe = params.propertyNames();
              while (pe.hasMoreElements())
              {
                  String name = (String)pe.nextElement();
                  String v[] = params.getProperties(name);
                  StringBuffer msg = new StringBuffer("PackageParam: ");
                  msg.append(name).append(" = ");
                  for (int i = 0; i < v.length; ++i)
                  {
                      if (i > 0)
                          msg.append(", ");
                      msg.append(v[i]);
                  }
                  log.debug(msg);
              }
          }
        **/
          
        try
        {
            // Save the PDF in a bitstream first, since the parser
            // has to read it as well, and we cannot "rewind" it after that.
            wi = WorkspaceItem.create(context, collection, false);
            Item myitem = wi.getItem();
            original = myitem.createBundle("ORIGINAL");
            bs = original.createBitstream(pkg);
            pkg.close();
            bs.setName("package.pdf");
            setFormatToMIMEType(context, bs, "application/pdf");
            bs.update();
            log.debug("Created bitstream ID="+String.valueOf(bs.getID())+", parsing...");

            crosswalkPDF(context, myitem, bs.retrieve());

            wi.update();
            context.commit();
            success = true;
            log.info(LogManager.getHeader(context, "ingest",
                "Created new Item, db ID="+String.valueOf(myitem.getID())+
                ", WorkspaceItem ID="+String.valueOf(wi.getID())));
            return wi;
        }
        finally
        {
            try
            {
                // Close bitstream input stream and PDF file.
                if (bis != null)
                    bis.close();
                if (cos != null)
                    cos.close();
            }
            catch (IOException ie)
            { }

            // get rid of bitstream and item if ingest fails
            if (!success)
            {
                if (original != null && bs != null)
                    original.removeBitstream(bs);
                if (wi != null)
                    wi.deleteAll();
            }
            context.commit();
        }
View Full Code Here

                    Utils.copy((InputStream)extraFiles.get(fname), zip);
                    zip.closeEntry();
                }

                // copy all non-meta bitstreams into zip
                Bundle bundles[] = item.getBundles();
                for (int i = 0; i < bundles.length; i++)
                {
                    if (!PackageUtils.isMetaInfoBundle(bundles[i]))
                    {
                        // unauthorized bundle?
View Full Code Here

            bundleName = "ORIGINAL";
          }
         
          // Bundle names are not unique, so we just pick the first one if there's more than one.
          Bundle[] targetBundles = item.getBundles(bundleName);
          Bundle targetBundle;
         
          // if null, create the new bundle and add it in
          if (targetBundles.length == 0) {
            targetBundle = item.createBundle(bundleName);
            item.addBundle(targetBundle);
          }
          else {
            targetBundle = targetBundles[0];
          }
         
          URL ARurl = null;
          InputStream in = null;
          if (href != null) {
            try {
              // Make sure the url string escapes all the oddball characters
              String processedURL = URLencode(href);
              // Generate a requeset for the aggregated resource
              ARurl = new URL(processedURL);
              in = ARurl.openStream();
            }
            catch(FileNotFoundException fe) {
                log.error("The provided URI failed to return a resource: " + href);
              }
            catch(ConnectException fe) {
                log.error("The provided URI was invalid: " + href);
              }
          }
          else {
            throw new CrosswalkException("Entry did not contain link to resource: " + entryId);
          }
         
          // ingest and update
          if (in != null) {
            Bitstream newBitstream = targetBundle.createBitstream(in);
           
            String bsName = resource.getAttributeValue("title");
            newBitstream.setName(bsName);
           
              // Identify the format
            String mimeString = resource.getAttributeValue("type");
            BitstreamFormat bsFormat = BitstreamFormat.findByMIMEType(context, mimeString);
            if (bsFormat == null) {
              bsFormat = FormatIdentifier.guessFormat(context, newBitstream);
            }
            newBitstream.setFormat(bsFormat);
              newBitstream.update();
             
              targetBundle.addBitstream(newBitstream);
            targetBundle.update();
          }
          else {
            throw new CrosswalkException("Could not retrieve bitstream: " + entryId);
          }
         
View Full Code Here

                validityKey.append(dcv.value);
            }
        }
        else if (dso instanceof Bundle)
        {
            Bundle bundle = (Bundle) dso;
           
            validityKey.append("Bundle:");
            validityKey.append(bundle.getID());
            validityKey.append(bundle.getName());
            validityKey.append(bundle.getPrimaryBitstreamID());
           
            for(Bitstream bitstream : bundle.getBitstreams())
            {
                this.add(bitstream);
            }
        }
        else if (dso instanceof Bitstream)
View Full Code Here

          dso = bundles[0];
        }
       
        if (dso instanceof Bundle)
        {
          Bundle bundle = (Bundle) dso;
          Item[] items = bundle.getItems();
         
          dso = items[0];
        }
       
        if (dso instanceof Item)
View Full Code Here

      }
     
      // Now create the special ORE bundle and drop the ORE document in it
    if (harvestRow.getHarvestType() == 2 || harvestRow.getHarvestType() == 3)
    {
      Bundle OREBundle = item.createBundle("ORE");
     
      XMLOutputter outputter = new XMLOutputter();
      String OREString = outputter.outputString(oreREM);
      ByteArrayInputStream OREStream = new ByteArrayInputStream(OREString.getBytes());
     
      Bitstream OREBitstream = OREBundle.createBitstream(OREStream);
      OREBitstream.setName("ORE.xml");

      BitstreamFormat bf = FormatIdentifier.guessFormat(ourContext, OREBitstream);
      OREBitstream.setFormat(bf);
      OREBitstream.update();
     
      OREBundle.addBitstream(OREBitstream);
      OREBundle.update();
    }
   
    //item.setHarvestDate(new Date());
    hi.setHarvestDate(new Date());
View Full Code Here

     *             if a db error occur
     */
    public static void authorizeManageBitstreamPolicy(Context context,
            Bitstream bitstream) throws AuthorizeException, SQLException
    {
        Bundle bundle = bitstream.getBundles()[0];
        authorizeManageBundlePolicy(context, bundle);
    }
View Full Code Here

     * @throws IOException Signals that an I/O exception has occurred.
     */
    private String getLicenseAsString() throws SQLException,
            AuthorizeException, IOException
    {
        Bundle lb[] = this.item.getBundles(Constants.LICENSE_BUNDLE_NAME);
        for (Bundle element : lb)
        {
            Bitstream lbs = element.getBitstreamByName("license.txt");
            if (lbs != null)
            {
View Full Code Here

TOP

Related Classes of org.dspace.content.Bundle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.