Package org.dspace.content

Examples of org.dspace.content.Bitstream


        }
          StringBuffer thumbFrag = new StringBuffer();

          if (linkToBitstream)
          {
            Bitstream original = thumbnail.getOriginal();
            String link = hrq.getContextPath() + "/bitstream/" + item.getHandle() + "/" + original.getSequenceID() + "/" +
                    UIUtil.encodeBitstreamName(original.getName(), Constants.DEFAULT_ENCODING);
            thumbFrag.append("<a target=\"_blank\" href=\"" + link + "\" />");
          }
          else
          {
            String link = hrq.getContextPath() + "/handle/" + item.getHandle();
            thumbFrag.append("<a href=\"" + link + "\" />");
          }

          Bitstream thumb = thumbnail.getThumb();
          String img = hrq.getContextPath() + "/retrieve/" + thumb.getID() + "/" +
                UIUtil.encodeBitstreamName(thumb.getName(), Constants.DEFAULT_ENCODING);
          String alt = thumb.getName();
            String scAttr = getScalingAttr(hrq, thumb);
            thumbFrag.append("<img src=\"")
                     .append(img)
                     .append("\" alt=\"")
                     .append(alt + "\" ")
View Full Code Here


            }
            StringBuffer thumbFrag = new StringBuffer();

            if (linkToBitstream)
            {
                Bitstream original = thumbnail.getOriginal();
                String link = hrq.getContextPath() + "/bitstream/" + item.getHandle() + "/" + original.getSequenceID() + "/" +
                                UIUtil.encodeBitstreamName(original.getName(), Constants.DEFAULT_ENCODING);
                thumbFrag.append("<a target=\"_blank\" href=\"" + link + "\" />");
            }
            else
            {
                String link = hrq.getContextPath() + "/handle/" + item.getHandle();
                thumbFrag.append("<a href=\"" + link + "\" />");
            }

            Bitstream thumb = thumbnail.getThumb();
            String img = hrq.getContextPath() + "/retrieve/" + thumb.getID() + "/" +
                        UIUtil.encodeBitstreamName(thumb.getName(), Constants.DEFAULT_ENCODING);
            String alt = thumb.getName();
            String scAttr = getScalingAttr(hrq, thumb);
            thumbFrag.append("<img src=\"")
                     .append(img)
                     .append("\" alt=\"")
                     .append(alt + "\" ")
View Full Code Here

            {
                if (i + 1 < pathElt.length)
                {
                    if (pathElt[i + 1].startsWith("bitstream_"))
                    {
                        Bitstream bs = DAVBitstream.findBitstream(context,
                                (Item) dso, pathElt[i + 1]);
                        if (bs == null)
                        {
                            throw new DAVStatusException(
                                    HttpServletResponse.SC_NOT_FOUND,
View Full Code Here

        {
            // get rid of extension, if any, e.g. ".pdf"
            int dot = pathElt.indexOf('.');
            String strId = (dot >= 0) ? pathElt.substring(0, dot) : new String(
                    pathElt);
            Bitstream result = null;

            if (strId.startsWith("bitstream_"))
            {
                strId = strId.substring(10);
                result = getBitstreamBySequenceID(item, Integer.parseInt(strId));
View Full Code Here

         * Collection is a loose bitstream not connected to any Item, so it can
         * only be identified by a direct database-ID reference. Ugh.
         */
        if (pathElt[0].startsWith("retrieve_"))
        {
            Bitstream bs = findBitstream(context, null, pathElt[0]);
            return new DAVBitstream(context, request, response, pathElt, bs);
        }
        return null;
    }
View Full Code Here

            String name = par.getParameter("name", null);
       
            this.isSpider = par.getParameter("userAgent", "").equals("spider");

            // Resolve the bitstream
            Bitstream bitstream = null;
            DSpaceObject dso = null;
           
            if (bitstreamID > -1)
            {
                // Direct reference to the individual bitstream ID.
                bitstream = Bitstream.find(context, bitstreamID);
            }
            else if (itemID > -1)
            {
                // Referenced by internal itemID
                item = Item.find(context, itemID);
               
                if (sequence > -1)
                {
                        bitstream = findBitstreamBySequence(item, sequence);
                }
                else if (name != null)
                {
                        bitstream = findBitstreamByName(item, name);
                }
            }
            else if (handle != null)
            {
                // Reference by an item's handle.
                dso = HandleManager.resolveToObject(context,handle);

                if (dso instanceof Item)
                {
                    item = (Item)dso;

                    if (sequence > -1)
                    {
                        bitstream = findBitstreamBySequence(item,sequence);
                    }
                    else if (name != null)
                    {
                        bitstream = findBitstreamByName(item,name);
                    }
                }
            }

            // if initial search was by sequence number and found nothing,
            // then try to find bitstream by name (assuming we have a file name)
            if((sequence > -1 && bitstream==null) && name!=null)
            {
                bitstream = findBitstreamByName(item,name);

                // if we found bitstream by name, send a redirect to its new sequence number location
                if(bitstream!=null)
                {
                    String redirectURL = "";

                    // build redirect URL based on whether item has a handle assigned yet
                    if(item.getHandle()!=null && item.getHandle().length()>0)
                    {
                        redirectURL = request.getContextPath() + "/bitstream/handle/" + item.getHandle();
                    }
                    else
                    {
                        redirectURL = request.getContextPath() + "/bitstream/item/" + item.getID();
                    }

                        redirectURL += "/" + name + "?sequence=" + bitstream.getSequenceID();

                        HttpServletResponse httpResponse = (HttpServletResponse)
                        objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
                        httpResponse.sendRedirect(redirectURL);
                        return;
                }
            }

            // Was a bitstream found?
            if (bitstream == null)
            {
                throw new ResourceNotFoundException("Unable to locate bitstream");
            }

            // Is there a User logged in and does the user have access to read it?
            boolean isAuthorized = AuthorizeManager.authorizeActionBoolean(context, bitstream, Constants.READ);
            if (item != null && item.isWithdrawn() && !AuthorizeManager.isAdmin(context))
            {
                isAuthorized = false;
                log.info(LogManager.getHeader(context, "view_bitstream", "handle=" + item.getHandle() + ",withdrawn=true"));
            }
            // It item-request is enabled to all request we redirect to restricted-resource immediately without login request 
            String requestItemType = ConfigurationManager.getProperty("request.item.type");
            if (!isAuthorized)
            {
                if(context.getCurrentUser() != null || StringUtils.equalsIgnoreCase("all", requestItemType)){
                        // A user is logged in, but they are not authorized to read this bitstream,
                        // instead of asking them to login again we'll point them to a friendly error
                        // message that tells them the bitstream is restricted.
                        String redictURL = request.getContextPath() + "/handle/";
                        if (item!=null){
                                redictURL += item.getHandle();
                        }
                        else if(dso!=null){
                                redictURL += dso.getHandle();
                        }
                        redictURL += "/restricted-resource?bitstreamId=" + bitstream.getID();

                        HttpServletResponse httpResponse = (HttpServletResponse)
                        objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
                        httpResponse.sendRedirect(redictURL);
                        return;
                }
                else{
                  if(ConfigurationManager.getProperty("request.item.type")==null||
                                            ConfigurationManager.getProperty("request.item.type").equalsIgnoreCase("logged")){
                        // The user does not have read access to this bitstream. Interrupt this current request
                        // and then forward them to the login page so that they can be authenticated. Once that is
                        // successful, their request will be resumed.
                        AuthenticationUtil.interruptRequest(objectModel, AUTH_REQUIRED_HEADER, AUTH_REQUIRED_MESSAGE, null);

                        // Redirect
                        String redictURL = request.getContextPath() + "/login";

                        HttpServletResponse httpResponse = (HttpServletResponse)
                        objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
                        httpResponse.sendRedirect(redictURL);
                        return;
                  }
                }
            }

            // Success, bitstream found and the user has access to read it.
            // Store these for later retrieval:

            // Intercepting views to the original bitstream to instead show a citation altered version of the object
            // We need to check if this resource falls under the "show watermarked alternative" umbrella.
            // At which time we will not return the "bitstream", but will instead on-the-fly generate the citation rendition.

            // What will trigger a redirect/intercept?
            // 1) Intercepting Enabled
            // 2) This User is not an admin
            // 3) This object is citation-able
            if (CitationDocument.isCitationEnabledForBitstream(bitstream, context)) {
                // on-the-fly citation generator
                log.info(item.getHandle() + " - " + bitstream.getName() + " is citable.");

                FileInputStream fileInputStream = null;
                CitationDocument citationDocument = new CitationDocument();

                try {
                    //Create the cited document
                    tempFile = citationDocument.makeCitedDocument(bitstream);
                    if(tempFile == null) {
                        log.error("CitedDocument was null");
                    } else {
                        log.info("CitedDocument was ok," + tempFile.getAbsolutePath());
                    }


                    fileInputStream = new FileInputStream(tempFile);
                    if(fileInputStream == null) {
                        log.error("Error opening fileInputStream: ");
                    }

                    this.bitstreamInputStream = fileInputStream;
                    this.bitstreamSize = tempFile.length();

                } catch (Exception e) {
                    log.error("Caught an error with intercepting the citation document:" + e.getMessage());
                }

                //End of CitationDocument
            } else {
                this.bitstreamInputStream = bitstream.retrieve();
                this.bitstreamSize = bitstream.getSize();
            }

            this.bitstreamMimeType = bitstream.getFormat().getMIMEType();
            this.bitstreamName = bitstream.getName();
            if (context.getCurrentUser() == null)
            {
                this.isAnonymouslyReadable = true;
            }
            else
View Full Code Here

      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();
    }
View Full Code Here

        try
        {
            // get rid of extension, if any, e.g. ".pdf"
            int dot = pathElt.indexOf('.');
            String strId = (dot >= 0) ? pathElt.substring(0, dot) : pathElt;
            Bitstream result = null;

            if (strId.startsWith("bitstream_"))
            {
                strId = strId.substring(10);
                result = getBitstreamBySequenceID(item, Integer.parseInt(strId));
View Full Code Here

         * Collection is a loose bitstream not connected to any Item, so it can
         * only be identified by a direct database-ID reference. Ugh.
         */
        if (pathElt[0].startsWith("retrieve_"))
        {
            Bitstream bs = findBitstream(context, null, pathElt[0]);
            return new DAVBitstream(context, request, response, pathElt, bs);
        }
        return null;
    }
View Full Code Here

    public void consumeBitstream(Context ctx, Event event) throws SQLException
    {
        if (event.getEventType() == Event.MODIFY
                || event.getEventType() == Event.MODIFY_METADATA)
        {
            Bitstream bitstream = Bitstream.find(ctx, event.getSubjectID());
            if (bitstream == null)
            {
                log.warn("Cannot find bitstream " + event.getSubjectID() + "! "
                        + "Ignoring, as it is likely it was deleted "
                        + "and we'll cover it by a REMOVE event on its bundle.");
                return;
            }
            Bundle[] bundles = bitstream.getBundles();
            for (Bundle b : bundles)
            {
                Item[] items = b.getItems();
                for (Item i : items)
                {
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.