Package org.dspace.content

Examples of org.dspace.content.Bitstream


        {
            if (myvalue.getLimitedDataTable() != null)
            {
                for (StatisticDatasBeanRow row : myvalue.getLimitedDataTable())
                {
                    Bitstream bitstream = Bitstream.find(context,
                            Integer.parseInt(row.getLabel()));

                    SolrQuery solrQuery = new SolrQuery();
                    solrQuery.setQuery(getFromField() +":"+ Constants.BITSTREAM + "-"+ bitstream.getID());
                    try
                    {
                        QueryResponse solrQueryResponse = crisSearchService.search(solrQuery);
                        for (SolrDocument doc : solrQueryResponse.getResults())
                        {
View Full Code Here


            AuthorizeException
    {
        boolean formatKnown = true;
        boolean fileOK = false;
        BitstreamFormat bf = null;
        Bitstream b = null;
        //NOTE: File should already be uploaded.
        //Manakin does this automatically via Cocoon.
        //For JSP-UI, the SubmissionController.uploadFiles() does the actual upload

        Enumeration attNames = request.getAttributeNames();
       
        //loop through our request attributes
        while(attNames.hasMoreElements())
        {
            String attr = (String) attNames.nextElement();
           
            //if this ends with "-path", this attribute
            //represents a newly uploaded file
            if(attr.endsWith("-path"))
            {
                //strip off the -path to get the actual parameter
                //that the file was uploaded as
                String param = attr.replace("-path", "");
               
                // Load the file's path and input stream and description
                String filePath = (String) request.getAttribute(param + "-path");
                InputStream fileInputStream = (InputStream) request
                                    .getAttribute(param + "-inputstream");
               
                //attempt to get description from attribute first, then direct from a parameter
                String fileDescription =  (String) request
                                    .getAttribute(param + "-description");
                if(fileDescription==null ||fileDescription.length()==0)
                    request.getParameter("description");
               
                // if information wasn't passed by User Interface, we had a problem
                // with the upload
                if (filePath == null || fileInputStream == null)
                    return STATUS_UPLOAD_ERROR;
               
                if (subInfo != null)
                {
                    // Create the bitstream
                    Item item = subInfo.getSubmissionItem().getItem();
       
                    // do we already have a bundle?
                    Bundle[] bundles = item.getBundles("ORIGINAL");
       
                    if (bundles.length < 1)
                    {
                        // set bundle's name to ORIGINAL
                        b = item.createSingleBitstream(fileInputStream, "ORIGINAL");
                    }
                    else
                    {
                        // we have a bundle already, just add bitstream
                        b = bundles[0].createBitstream(fileInputStream);
                    }
       
                    // Strip all but the last filename. It would be nice
                    // to know which OS the file came from.
                    String noPath = filePath;
       
                    while (noPath.indexOf('/') > -1)
                    {
                        noPath = noPath.substring(noPath.indexOf('/') + 1);
                    }
       
                    while (noPath.indexOf('\\') > -1)
                    {
                        noPath = noPath.substring(noPath.indexOf('\\') + 1);
                    }
       
                    b.setName(noPath);
                    b.setSource(filePath);
                    b.setDescription(fileDescription);
       
                    // Identify the format
                    bf = FormatIdentifier.guessFormat(context, b);
                    b.setFormat(bf);
       
                    // Update to DB
                    b.update();
                    item.update();
       
                    if (bf == null || !bf.isInternal())
                    {
                        fileOK = true;
                    }
                    else
                    {
                        log.warn("Attempt to upload file format marked as internal system use only");
                       
                        // remove bitstream from bundle..
                        // delete bundle if it's now empty
                        Bundle[] bnd = b.getBundles();

                        bnd[0].removeBitstream(b);

                        Bitstream[] bitstreams = bnd[0].getBitstreams();
View Full Code Here

    {
        if (license == null)
            license = collection.getLicense();
        InputStream lis = new ByteArrayInputStream(license.getBytes());
        Bundle lb = item.createBundle(Constants.LICENSE_BUNDLE_NAME);
        Bitstream lbs = lb.createBitstream(lis);
        lis.close();
        BitstreamFormat bf = BitstreamFormat.findByShortDescription(context, "License");
        if (bf == null)
            bf = FormatIdentifier.guessFormat(context, lbs);
        lbs.setFormat(bf);
        lbs.setName(Constants.LICENSE_BITSTREAM_NAME);
        lbs.setSource(Constants.LICENSE_BITSTREAM_NAME);
        lbs.update();
    }
View Full Code Here

        // get an input stream
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
                fullpath));

        Bitstream bs = null;
        String newBundleName = bundleName;

        if (bundleName == null)
        {
            // is it license.txt?
            if (fileName.equals("license.txt"))
            {
                newBundleName = "LICENSE";
            }
            else
            {
                // call it ORIGINAL
                newBundleName = "ORIGINAL";
            }
        }
       
        if (!isTest)
        {
            // find the bundle
            Bundle[] bundles = i.getBundles(newBundleName);
            Bundle targetBundle = null;

            if (bundles.length < 1)
            {
                // not found, create a new one
                targetBundle = i.createBundle(newBundleName);
            }
            else
            {
                // put bitstreams into first bundle
                targetBundle = bundles[0];
            }

            // now add the bitstream
            bs = targetBundle.createBitstream(bis);

            bs.setName(fileName);

            // Identify the format
            // FIXME - guessing format guesses license.txt incorrectly as a text
            // file format!
            BitstreamFormat bf = FormatIdentifier.guessFormat(c, bs);
            bs.setFormat(bf);

            // Is this a the primary bitstream?
            if (primary)
            {
                targetBundle.setPrimaryBitstreamID(bs.getID());
                targetBundle.update();
            }

            bs.update();
        }
    }
View Full Code Here

          throws SQLException, IOException, AuthorizeException
    {
        // TODO validate assetstore number
        // TODO make sure the bitstream is there

        Bitstream bs = null;
        String newBundleName = bundleName;
       
        if (bundleName == null)
        {
            // is it license.txt?
            if (bitstreamPath.endsWith("license.txt"))
            {
                newBundleName = "LICENSE";
            }
            else
            {
                // call it ORIGINAL
                newBundleName = "ORIGINAL";
            }
        }

        if(!isTest)
        {
          // find the bundle
          Bundle[] bundles = i.getBundles(newBundleName);
          Bundle targetBundle = null;
             
          if( bundles.length < 1 )
          {
              // not found, create a new one
              targetBundle = i.createBundle(newBundleName);
          }
          else
          {
              // put bitstreams into first bundle
              targetBundle = bundles[0];
          }
 
          // now add the bitstream
          bs = targetBundle.registerBitstream(assetstore, bitstreamPath);
 
          // set the name to just the filename
          int iLastSlash = bitstreamPath.lastIndexOf('/');
          bs.setName(bitstreamPath.substring(iLastSlash + 1));
 
          // Identify the format
          // FIXME - guessing format guesses license.txt incorrectly as a text file format!
          BitstreamFormat bf = FormatIdentifier.guessFormat(c, bs);
          bs.setFormat(bf);
 
          bs.update();
        }
    }
View Full Code Here

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

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

                                if ( filter == null ||
                                     t.getName().indexOf( filter ) != -1 )
                                {
                                    // is this a replace? delete policies first
                                    if (isReplace || clearOnly)
                                    {
                                            AuthorizeManager.removeAllPolicies(c, t);
View Full Code Here

                thisDescription = line.substring(
                        dMarkerIndex + descriptionMarker.length(), dEndIndex)
                        .trim();
            }

            Bitstream bs = null;
            boolean notfound = true;
            if (!isTest)
            {
                // find bitstream
                Bitstream[] bitstreams = myItem.getNonInternalBitstreams();
                for (int j = 0; j < bitstreams.length && notfound; j++)
                {
                    if (bitstreams[j].getName().equals(bitstreamName))
                    {
                        bs = bitstreams[j];
                        notfound = false;
                    }
                }
            }

            if (notfound && !isTest)
            {
                // this should never happen
                System.out.println("\tdefault permissions set for "
                        + bitstreamName);
            }
            else if (!isTest)
            {
                if (permissionsExist)
                {
                    if (myGroup == null)
                    {
                        System.out.println("\t" + groupName
                                + " not found, permissions set to default");
                    }
                    else if (actionID == -1)
                    {
                        System.out
                                .println("\tinvalid permissions flag, permissions set to default");
                    }
                    else
                    {
                        System.out.println("\tSetting special permissions for "
                                + bitstreamName);
                        setPermission(c, myGroup, actionID, bs);
                    }
                }

                if (descriptionExists)
                {
                    System.out.println("\tSetting description for "
                            + bitstreamName);
                    bs.setDescription(thisDescription);
                    bs.update();
                }
            }
        }
    }
View Full Code Here

    // Give it a unique name including the SID in case there are other
    // deposit license artifacts in the Item.
    private boolean addDepositLicense(Context context, Item item, AmdSec amdSec)
        throws SQLException, IOException, AuthorizeException, MetsException
    {
        Bitstream licenseBs = findDepositLicense(context, item);

        if (licenseBs == null)
            return false;
        else
        {
            String resource = "depositlicense_"+
                              String.valueOf(licenseBs.getSequenceID())+".txt";
            addRightsStream(licenseBs.retrieve(), resource, "text/plain",
                           DSPACE_DEPOSIT_LICENSE_MDTYPE, amdSec);
            return true;
        }
    }
View Full Code Here

    // if there's a CC RDF license, chuck it in external file.
    private boolean addCreativeCommons(Context context, Item item, AmdSec amdSec)
        throws SQLException, IOException, AuthorizeException, MetsException
    {
        // License as <rightsMD><mdWrap><binData>base64encoded</binData>...
        Bitstream cc;
       
        if ((cc = CreativeCommons.getLicenseRdfBitstream(item)) != null)
        {
            addRightsStream(cc.retrieve(),
                            (gensym("creativecommons") + ".rdf"),
                            "text/rdf",
                            CREATIVE_COMMONS_LICENSE_MDTYPE, amdSec);
        }
        else if ((cc = CreativeCommons.getLicenseTextBitstream(item)) != null)
        {
            addRightsStream(cc.retrieve(),
                            (gensym("creativecommons") + ".txt"),
                            "text/plain",
                            CREATIVE_COMMONS_LICENSE_MDTYPE, amdSec);
        }
        else
View Full Code Here

                                    .getName().equals("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.setOWNERID(bitstreamPID);
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.