Bitstream[] bits = bunds[0].getBitstreams(); for (int i = 0; i < bits.length && !html; i++) { if (bits[i].getID() == bunds[0].getPrimaryBitstreamID()) { html = bits[i].getFormat().getMIMEType().equals("text/html"); primaryBitstream = bits[i]; } }
if (bits[i].getID() == bunds[0].getPrimaryBitstreamID()) { html = bits[i].getFormat().getMIMEType().equals("text/html"); primaryBitstream = bits[i]; }
    private void listBitstreams()    throws IOException    {        JspWriter out = pageContext.getOut();        HttpServletRequest request =            (HttpServletRequest) pageContext.getRequest();                out.print("<table align=center class=\"miscTable\"><tr>");        out.println("<td class=evenRowEvenCol><P><strong>Files in This Item:</strong></P>");                Bundle[] bundles = item.getBundles("ORIGINAL");                if (bundles.length == 0)        {            out.println("<P>There are no files associated with this item.</P>");        }        else        {               boolean html = false;            String handle = item.getHandle();            Bitstream primaryBitstream = null;                        Bundle[] bunds = item.getBundles("ORIGINAL");            // if item contains multiple bitstreams, display bitstream description            boolean multiFile = bunds[0].getBitstreams().length > 1;            Bundle[] thumbs= item.getBundles("THUMBNAIL");                        // check if primary bitstream is html            if (bunds[0] != null)            {                Bitstream[] bits = bunds[0].getBitstreams();                for (int i = 0; i < bits.length && !html; i++)                {                    if (bits[i].getID() == bunds[0].getPrimaryBitstreamID())                    {                        html = bits[i].getFormat().getMIMEType().equals("text/html");                        primaryBitstream = bits[i];                    }                }            }                        out.println("<table cellpadding=6><tr><th class=\"standard\">File</th>");            if (multiFile)            {                out.println("<th class=\"standard\">Description</th>");            }            out.println("<th class=\"standard\">Size</th class=\"standard\"><th class=\"standard\">Format</th></tr>");                        // if primary bitstream is html, display a link for only that one to HTMLServlet            if (html)            {                // If no real Handle yet (e.g. because Item is in workflow)                // we use the 'fake' Handle db-id/1234 where 1234 is the                // database ID of the item.                if (handle == null)                {                    handle = "db-id/" + item.getID();                }                                out.print("<tr><td class=\"standard\">");                out.print(primaryBitstream.getName());                if (multiFile)                {                    out.print("</td><td class=\"standard\">");                    String desc = primaryBitstream.getDescription();                    out.print(desc != null ? desc : "");                }                out.print("</td><td class=\"standard\">");                out.print(primaryBitstream.getSize() / 1024);                out.print("Kb</td><td class=\"standard\">");                out.print(primaryBitstream.getFormatDescription());                out.print("</td><td class=\"standard\"><A TARGET=_blank HREF=\"");                out.print(request.getContextPath());                out.print("/html/");                out.print(handle + "/");                out.print(URLEncoder.encode(primaryBitstream.getName()));                out.print("\">View/Open</A></td></tr>");            }            else            {                for (int i = 0; i < bundles.length; i++)                {                    Bitstream[] bitstreams = bundles[i].getBitstreams();                                        for (int k = 0; k < bitstreams.length ; k++)                    {                        // Skip internal types                        if (!bitstreams[k].getFormat().isInternal())                        {                            out.print("<tr><td class=\"standard\">");                            out.print(bitstreams[k].getName());                            if (multiFile)                            {                                out.print("</td><td class=\"standard\">");                                String desc = bitstreams[k].getDescription();                                out.print(desc != null ? desc : "");                            }                            out.print("</td><td class=\"standard\">");                            out.print(bitstreams[k].getSize() / 1024);                            out.print("Kb</td><td class=\"standard\">");                            out.print(bitstreams[k].getFormatDescription());                            out.print("</td><td class=\"standard\" align=\"center\">");                                                        // Work out what the bitstream link should be (persistent ID if item has Handle)                            String bsLink = "<A TARGET=_blank HREF=\"" + request.getContextPath();                                                        if (handle != null && bitstreams[k].getSequenceID() > 0)                            {                                bsLink = bsLink + "/bitstream/" + item.getHandle() + "/" +                                bitstreams[k].getSequenceID() + "/";                            }                            else                            {                                bsLink = bsLink + "/retrieve/" + bitstreams[k].getID() + "/";                            }                                                        bsLink = bsLink + URLEncoder.encode(bitstreams[k].getName()) + "\">";                                                        // is there a thumbnail bundle?                            if(thumbs.length > 0 && showThumbs)                            {                                String tName = bitstreams[k].getName()+".jpg";                                Bitstream tb = thumbs[0].getBitstreamByName(tName);                                                                if( tb != null )                                {                                    String myPath = request.getContextPath() + "/retrieve/" + tb.getID()                                    + "/" + URLEncoder.encode(tb.getName());                                                                        out.print(bsLink);                                        out.print("<img src=\""+ myPath + "\" ");                                    out.print("alt=\"" + tName + "\"></A><BR>");                                }                            }                                                        out.print(bsLink + "View/Open</A></td></tr>");                        }                    }                }            }            out.println("</table>");        }                out.println("</td></tr></table>");    }