Package org.dspace.content

Examples of org.dspace.content.Bundle


     * the CC bundle, with the given bitstream name
     */
    private static Bitstream getBitstream(Item item, String bitstream_name)
            throws SQLException, IOException, AuthorizeException
    {
        Bundle cc_bundle = null;

        // look for the CC bundle
        try
        {
            Bundle[] bundles = item.getBundles(CC_BUNDLE_NAME);

            if ((bundles != null) && (bundles.length > 0))
            {
                cc_bundle = bundles[0];
            }
            else
            {
                return null;
            }
        }
        catch (Exception exc)
        {
            // this exception catching is a bit generic,
            // but basically it happens if there is no CC bundle
            return null;
        }

        return cc_bundle.getBitstreamByName(bitstream_name);
    }
View Full Code Here


            Item item = (Item)dso;

            //get last modified time
            long lmTime = ((Item)dso).getLastModified().getTime();

            Bundle bundles[] = item.getBundles();
            for (int i = 0; i < bundles.length; i++)
            {
                if (includeBundle(bundles[i]))
                {
                    // unauthorized bundle?
View Full Code Here

        if(mdRef.getMDTYPE()!=null && mdRef.getMDTYPE()==Mdtype.OTHER &&
           mdRef.getOTHERMDTYPE()!=null && mdRef.getOTHERMDTYPE().equals("DSpaceDepositLicense"))
        {
            //Locate the LICENSE bundle
            Item i = (Item)dso;
            Bundle license[] = i.getBundles(Constants.LICENSE_BUNDLE_NAME);

            //Are we already including the LICENSE bundle's bitstreams in this package?
            if(license!=null && license.length>0 && includeBundle(license[0]))
            {
                //Since we are including the LICENSE bitstreams, lets find our LICENSE bitstream path & link to it.
                Bitstream licenseBs = PackageUtils.findDepositLicense(context, (Item)dso);
                mdRef.setXlinkHref(makeBitstreamURL(licenseBs, params));
            }
        }
        //If this <mdRef> is a reference to a Creative Commons Textual License
        else if(mdRef.getMDTYPE() != null && mdRef.getMDTYPE() == Mdtype.OTHER &&
                mdRef.getOTHERMDTYPE()!=null && mdRef.getOTHERMDTYPE().equals("CreativeCommonsText"))
        {
            //Locate the CC-LICENSE bundle
            Item i = (Item)dso;
            Bundle license[] = i.getBundles(CreativeCommons.CC_BUNDLE_NAME);

            //Are we already including the CC-LICENSE bundle's bitstreams in this package?
            if(license!=null && license.length>0 && includeBundle(license[0]))
            {
                //Since we are including the CC-LICENSE bitstreams, lets find our CC-LICENSE (textual) bitstream path & link to it.
                Bitstream ccText = CreativeCommons.getLicenseTextBitstream(i);
                mdRef.setXlinkHref(makeBitstreamURL(ccText, params));
            }
        }
        //If this <mdRef> is a reference to a Creative Commons RDF License
        else if(mdRef.getMDTYPE() != null && mdRef.getMDTYPE() == Mdtype.OTHER &&
                mdRef.getOTHERMDTYPE()!=null && mdRef.getOTHERMDTYPE().equals("CreativeCommonsRDF"))
        {
            //Locate the CC-LICENSE bundle
            Item i = (Item)dso;
            Bundle license[] = i.getBundles(CreativeCommons.CC_BUNDLE_NAME);

            //Are we already including the CC-LICENSE bundle's bitstreams in this package?
            if(license!=null && license.length>0 && includeBundle(license[0]))
            {
                //Since we are including the CC-LICENSE bitstreams, lets find our CC-LICENSE (RDF) bitstream path & link to it.
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

                                String license)
        throws PackageValidationException, CrosswalkException,
               AuthorizeException, SQLException, IOException
    {
        boolean success = false;
        Bundle original = null;
        Bitstream bs = null;
        WorkspaceItem wi = null;

        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)parent, false);
            Item myitem = wi.getItem();
            original = myitem.createBundle("ORIGINAL");

            InputStream fileStream = null;
            try
            {
                fileStream = new FileInputStream(pkgFile);
                bs = original.createBitstream(fileStream);
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.close();
                }
            }

            bs.setName("package.pdf");
            setFormatToMIMEType(context, bs, "application/pdf");
            bs.update();
            if (log.isDebugEnabled())
            {
                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())));

            myitem = PackageUtils.finishCreateItem(context, wi, null, params);
            return myitem;
        }
        finally
        {
            // get rid of bitstream and item if ingest fails
            if (!success)
            {
                if (original != null && bs != null)
                {
                    original.removeBitstream(bs);
                }
                if (wi != null)
                {
                    wi.deleteAll();
                }
View Full Code Here

          aDso = bundles[0];
        }

        if (aDso instanceof Bundle)
        {
          Bundle bundle = (Bundle) aDso;
          Item[] items = bundle.getItems();

          aDso = items[0];
        }

        if (aDso instanceof Item)
View Full Code Here

        {
            license = collection.getLicense();
        }
        InputStream lis = new ByteArrayInputStream(license.getBytes());

        Bundle lb;
        //If LICENSE bundle is missing, create it
        Bundle[] bundles = item.getBundles(Constants.LICENSE_BUNDLE_NAME);
        if(bundles==null || bundles.length==0)
        {
            lb = item.createBundle(Constants.LICENSE_BUNDLE_NAME);
        }
        else
        {
            lb = bundles[0];
        }

        //Create the License bitstream
        Bitstream lbs = lb.createBitstream(lis);
        lis.close();
        BitstreamFormat bf = BitstreamFormat.findByShortDescription(context, "License");
        if (bf == null)
        {
            bf = FormatIdentifier.guessFormat(context, lbs);
View Full Code Here

            // retrieve bundle name from manifest
            String bundleName = METSManifest.getBundleName(mfile);

            // Find or create the bundle where bitstream should be attached
            Bundle bundle;
            Bundle bns[] = item.getBundles(bundleName);
            if (bns != null && bns.length > 0)
            {
                bundle = bns[0];
            }
            else
            {
                bundle = item.createBundle(bundleName);
            }

            // Create the bitstream in the bundle & initialize its name
            Bitstream bitstream = bundle.createBitstream(fileStream);
            bitstream.setName(path);

             // Set bitstream sequence id, if known
            String seqID = mfile.getAttributeValue("SEQ");
            if(seqID!=null && !seqID.isEmpty())
                bitstream.setSequenceID(Integer.parseInt(seqID));
           
            // crosswalk this bitstream's administrative metadata located in
            // METS manifest (or referenced externally)
            manifest.crosswalkBitstream(context, params, bitstream, mfileID,
                    mdRefCallback);

            // is this the primary bitstream?
            if (primaryID != null && mfileID.equals(primaryID))
            {
                bundle.setPrimaryBitstreamID(bitstream.getID());
                bundle.update();
                setPrimaryBitstream = true;
            }

            // Run any finishing activities -- this allows subclasses to
            // change default bitstream information
            finishBitstream(context, bitstream, mfile, manifest, params);

            // Last-ditch attempt to divine the format, if crosswalk failed to
            // set it:
            // 1. attempt to guess from MIME type
            // 2. if that fails, guess from "name" extension.
            if (bitstream.getFormat().equals(unknownFormat))
            {
                if (log.isDebugEnabled())
                {
                    log.debug("Guessing format of Bitstream left un-set: "
                            + bitstream.toString());
                }
                String mimeType = mfile.getAttributeValue("MIMETYPE");
                BitstreamFormat bf = (mimeType == null) ? null
                        : BitstreamFormat.findByMIMEType(context, mimeType);
                if (bf == null)
                {
                    bf = FormatIdentifier.guessFormat(context, bitstream);
                }
                bitstream.setFormat(bf);
            }
            bitstream.update();
        }// end for each manifest file

        for (Iterator<Element> mi = manifestBundleFiles.iterator(); mi
                .hasNext();)
        {
            Element mfile = mi.next();

            String bundleName = METSManifest.getBundleName(mfile, false);

            Bundle bundle;
            Bundle bns[] = item.getBundles(bundleName);
            if (bns != null && bns.length > 0)
            {
                bundle = bns[0];
            }
            else
View Full Code Here

    protected void addManifestBitstream(Context context, Item item,
            METSManifest manifest) throws IOException, SQLException,
            AuthorizeException, PackageValidationException
    {
        // We'll save the METS Manifest as part of the METADATA bundle.
        Bundle mdBundle = item.createBundle(Constants.METADATA_BUNDLE_NAME);

        // Create a Bitstream from the METS Manifest's content
        Bitstream manifestBitstream = mdBundle.createBitstream(manifest
                .getMetsAsStream());
        manifestBitstream.setName(METSManifest.MANIFEST_FILE);
        manifestBitstream.setSource(METSManifest.MANIFEST_FILE);
        manifestBitstream.update();
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 = encodeForURL(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

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.