Package org.dspace.content

Examples of org.dspace.content.Bitstream


     *         no errors occurred!)
     */
    protected int processRemoveFile(Context context, Item item, int bitstreamID)
            throws IOException, SQLException, AuthorizeException
    {
        Bitstream bitstream;

        // Try to find bitstream
        try
        {
            bitstream = Bitstream.find(context, bitstreamID);
        }
        catch (NumberFormatException nfe)
        {
            bitstream = null;
        }

        if (bitstream == null)
        {
            // Invalid or mangled bitstream ID
            // throw an error and return immediately
            return STATUS_INTEGRITY_ERROR;
        }

        // remove bitstream from bundle..
        // delete bundle if it's now empty
        Bundle[] bundles = bitstream.getBundles();

        bundles[0].removeBitstream(bitstream);

        Bitstream[] bitstreams = bundles[0].getBitstreams();

View Full Code Here


                String bundleName = bundles[j].getName();

                for (int k = 0; k < bitstreams.length; k++)
                {
                    Bitstream b = bitstreams[k];

                    String myName = b.getName();
                    String oldName = myName;

                    String description = b.getDescription();
                    if ((description != null) && (!description.equals("")))
                    {
                        description = "\tdescription:" + description;
                    } else
                    {
                        description = "";
                    }

                    String primary = "";
                    if (bundles[j].getPrimaryBitstreamID() == b.getID()) {
                        primary = "\tprimary:true ";
                    }

                    int myPrefix = 1; // only used with name conflict

                    InputStream is = b.retrieve();

                    boolean isDone = false; // done when bitstream is finally
                    // written

                    while (!isDone)
                    {
                        if (myName.contains(File.separator))
                        {
                            String dirs = myName.substring(0, myName
                                    .lastIndexOf(File.separator));
                            File fdirs = new File(destDir + File.separator
                                    + dirs);
                            fdirs.mkdirs();
                        }

                        File fout = new File(destDir, myName);

                        if (fout.createNewFile())
                        {
                            FileOutputStream fos = new FileOutputStream(fout);
                            Utils.bufferedCopy(is, fos);
                            // close streams
                            is.close();
                            fos.close();

                            // write the manifest file entry
                            if (b.isRegisteredBitstream())
                            {
                                out.println("-r -s " + b.getStoreNumber()
                                        + " -f " + myName +
                                        "\tbundle:" + bundleName +
                                        primary + description);
                            }
                            else
View Full Code Here

                // if there was a bitstream, get rid of it, since
                // it's just an artifact now that the CC license is installed.
                Element mdRef = rmds[i].getChild("mdRef", METSManifest.metsNS);
                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

      boolean overWrite = MediaFilterManager.isForce;
       
        // 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);
View Full Code Here

    {
        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",
View Full Code Here

        {
            BitstreamFormat pdff = BitstreamFormat.findByShortDescription(context,
                                    BITSTREAM_FORMAT_NAME);
            if (pdff == null)
                throw new PackageValidationException("Cannot find BitstreamFormat \""+BITSTREAM_FORMAT_NAME+"\"");
            Bitstream pkgBs = PackageUtils.getBitstreamByFormat(item, pdff, Constants.DEFAULT_BUNDLE_NAME);
            if (pkgBs == null)
                throw new PackageValidationException("Cannot find Bitstream with format \""+BITSTREAM_FORMAT_NAME+"\"");
            Utils.copy(pkgBs.retrieve(), out);
        }
            finally {}
    }
View Full Code Here

        if (bundles == null || bundles.length == 0)
            return;

        Bundle bundle = bundles[0];

        Bitstream bitstream = bundle.getBitstreamByName("license_rdf");

        String license_rdf = new String(copy(bitstream));

        /* quickly fix xml by ripping out offensive parts */
        license_rdf = license_rdf.replaceFirst("<license", "");
        license_rdf = license_rdf.replaceFirst("</license>", "");

        StringWriter result = new StringWriter();

        try
        {
            templates.newTransformer().transform(
                    new StreamSource(new ByteArrayInputStream(license_rdf
                            .getBytes())), new StreamResult(result));
        }
        catch (TransformerException e)
        {
            throw new RuntimeException(e.getMessage(), e);
        }

        StringBuffer buffer = result.getBuffer();

        Bitstream newBitstream = bundle
                .createBitstream(new ByteArrayInputStream(buffer.toString()
                        .getBytes()));

        newBitstream.setName(bitstream.getName());
        newBitstream.setDescription(bitstream.getDescription());
        newBitstream.setFormat(bitstream.getFormat());
        newBitstream.setSource(bitstream.getSource());
        newBitstream.setUserFormatDescription(bitstream
                .getUserFormatDescription());
        newBitstream.update();

        bundle.removeBitstream(bitstream);

        bundle.update();

View Full Code Here

                            && (bundles[i].getName().equals("THUMBNAIL") ||
                                bundles[i].getName().startsWith("TEXT")))
                    {
                        // Try and find the original bitstream, and chuck the
                        // derived bitstream in the same group
                        Bitstream original = findOriginalBitstream(item,
                                bitstreams[bits]);
        
                        if (original != null)
                        {
                            groupID = "GROUP_" + xmlIDstart
                                    + original.getSequenceID();
                        }
                    }
        
                    file.setGROUPID(groupID);
                    file.setMIMETYPE(bitstreams[bits].getFormat().getMIMEType());
View Full Code Here

            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 {
View Full Code Here

            // Generate a second group id for any extra metadata added.
            String groupID2 = getGenericID("group_dmd_");

            Bundle[] bundles = item.getBundles("METADATA");
            for (Bundle bundle : bundles) {
                Bitstream bitstream = bundle.getBitstreamByName("MODS.xml");

                if (bitstream == null) {
                    continue;
                }


                String dmdID = getGenericID("dmd_");


                ////////////////////////////////
                // Start a metadata wrapper
                attributes = new AttributeMap();
                attributes.put("ID", dmdID);
                attributes.put("GROUPID", groupID2);
                startElement(METS, "dmdSec", attributes);

                ////////////////////////////////
                // Start a metadata wrapper
                attributes = new AttributeMap();
                attributes.put("MDTYPE", "MODS");
                startElement(METS, "mdWrap", attributes);

                // ////////////////////////////////
                // Start the xml data
                startElement(METS, "xmlData");


                // ///////////////////////////////
                // Send the actual XML content

                SAXFilter filter = new SAXFilter(contentHandler, lexicalHandler, namespaces);
                // Allow the basics for XML
                filter.allowElements().allowIgnorableWhitespace().allowCharacters().allowCDATA().allowPrefixMappings();

                XMLReader reader = XMLReaderFactory.createXMLReader();
                reader.setContentHandler(filter);
                reader.setProperty("http://xml.org/sax/properties/lexical-handler", filter);
                try {
                    InputStream is = bitstream.retrieve();
                    reader.parse(new InputSource(is));
                } catch (AuthorizeException ae) {
                    // just ignore the authorize exception and continue on with
                    //out parsing the xml document.
                }
View Full Code Here

TOP

Related Classes of org.dspace.content.Bitstream

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.