[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui ...

Christian Bauer christian at hibernate.org
Tue Jun 12 13:51:00 EDT 2007


  User: cbauer  
  Date: 07/06/12 13:51:00

  Modified:    examples/wiki/src/main/org/jboss/seam/wiki/core/ui   
                        FileServlet.java FileMetaMap.java
                        UIWikiFormattedText.java
  Log:
  Pre-generate thumbnails
  
  Revision  Changes    Path
  1.8       +26 -51    jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/FileServlet.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: FileServlet.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/FileServlet.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- FileServlet.java	4 Jun 2007 08:06:36 -0000	1.7
  +++ FileServlet.java	12 Jun 2007 17:51:00 -0000	1.8
  @@ -2,17 +2,13 @@
   
   import org.jboss.seam.wiki.core.model.File;
   
  -import javax.imageio.ImageIO;
   import javax.persistence.EntityManager;
   import javax.persistence.NoResultException;
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServlet;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
  -import javax.swing.*;
   import javax.transaction.UserTransaction;
  -import java.awt.*;
  -import java.awt.image.BufferedImage;
   import java.io.ByteArrayOutputStream;
   import java.io.IOException;
   import java.io.InputStream;
  @@ -21,12 +17,7 @@
   
       private static final String DOWNLOAD_PATH = "/download.seam";
   
  -    /**
  -     * The maximum width allowed for image rescaling
  -     */
  -    private static final int MAX_IMAGE_WIDTH = 3000;
  -
  -    private byte[] noImage;
  +    private byte[] fileNotFoundImage;
   
       public FileServlet() {
           InputStream in = getClass().getResourceAsStream("/img/filenotfound.png");
  @@ -40,7 +31,7 @@
                       read = in.read(buffer);
                   }
   
  -                noImage = out.toByteArray();
  +                fileNotFoundImage = out.toByteArray();
               }
               catch (IOException e) {
               }
  @@ -94,54 +85,38 @@
               String contentType = null;
               byte[] data = null;
   
  +            String thumbnail = request.getParameter("thumbnail");
  +
  +            if (file != null
  +                && thumbnail != null
  +                && Boolean.valueOf(thumbnail)
  +                && file.getImageMetaInfo() != null
  +                && file.getImageMetaInfo().getThumbnailData() != null
  +                && file.getImageMetaInfo().getThumbnailData().length >0) {
  +
  +                // Render thumbnail picture
  +                contentType = file.getContentType();
  +                data = file.getImageMetaInfo().getThumbnailData();
  +
  +            } else if (file != null
  +                       && file.getData() != null
  +                       && file.getData().length > 0) {
   
  -            if (file != null && file.getData() != null && file.getData().length > 0) {
  +                // Render file regularly
                   contentType = file.getContentType();
                   data = file.getData();
  -            } else if (noImage != null) {
  +
  +            } else if (fileNotFoundImage != null) {
  +
                   contentType = "image/png";
  -                data = noImage;
  +                data = fileNotFoundImage;
  +
               }
   
  -            if (file != null && data != null) {
  +            if (data != null) {
                   response.setContentType(contentType);
  -
  -                boolean rescale = false;
  -                int width = 0;
  -                ImageIcon icon = null;
  -
  -                // Check if the image needs to be rescaled (and if the file is an image)
  -                if (request.getParameter("width") != null && file.getImageMetaInfo() != null) {
  -                    width = Math.min(MAX_IMAGE_WIDTH, Integer.parseInt(request.getParameter("width")));
  -                    icon = new ImageIcon(data);
  -                    if (width > 0 && width != icon.getIconWidth())
  -                        rescale = true;
  -                }
  -
  -                // Rescale the image if required
  -                if (rescale) {
  -                    double ratio = (double) width / icon.getIconWidth();
  -                    int height = (int) (icon.getIconHeight() * ratio);
  -
  -                    int imageType = "image/png".equals(contentType) ?
  -                            BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
  -                    BufferedImage bImg = new BufferedImage(width, height, imageType);
  -                    Graphics2D g2d = bImg.createGraphics();
  -                    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
  -                    g2d.drawImage(icon.getImage(), 0, 0, width, height, null);
  -                    g2d.dispose();
  -
  -                    String formatName = "";
  -                    if ("image/png".equals(contentType))
  -                        formatName = "png";
  -                    else if ("image/jpeg".equals(contentType))
  -                        formatName = "jpeg";
  -
  -                    ImageIO.write(bImg, formatName, response.getOutputStream());
  -                } else {
                       response.getOutputStream().write(data);
                   }
  -            }
   
               response.getOutputStream().flush();
           }
  
  
  
  1.2       +0 -1      jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/FileMetaMap.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: FileMetaMap.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/FileMetaMap.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- FileMetaMap.java	7 Mar 2007 18:37:39 -0000	1.1
  +++ FileMetaMap.java	12 Jun 2007 17:51:00 -0000	1.2
  @@ -17,7 +17,6 @@
           {
               put("image/jpg",                    new FileMetaInfo("icon.fileimg.gif", true));
               put("image/jpeg",                   new FileMetaInfo("icon.fileimg.gif", true));
  -            put("image/gif",                    new FileMetaInfo("icon.fileimg.gif", true));
               put("image/png",                    new FileMetaInfo("icon.fileimg.gif", true));
               put("text/plain",                   new FileMetaInfo("icon.filetxt.gif", false));
               put("application/pdf",              new FileMetaInfo("icon.filepdf.gif", false));
  
  
  
  1.23      +1 -19     jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/UIWikiFormattedText.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UIWikiFormattedText.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/UIWikiFormattedText.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -b -r1.22 -r1.23
  --- UIWikiFormattedText.java	7 May 2007 11:42:33 -0000	1.22
  +++ UIWikiFormattedText.java	12 Jun 2007 17:51:00 -0000	1.23
  @@ -97,28 +97,10 @@
                   } else {
                       // Thumbnail with link display
   
  -                    int thumbnailWidth;
  -                    // TODO: We could make these sizes customizable, maybe as attributes
  -                    // of the JSF tag
  -                    switch (file.getImageMetaInfo().getThumbnail()) {
  -                        case'S':
  -                            thumbnailWidth = 80;
  -                            break;
  -                        case'M':
  -                            thumbnailWidth = 160;
  -                            break;
  -                        case'L':
  -                            thumbnailWidth = 320;
  -                            break;
  -                        default:
  -                            thumbnailWidth = file.getImageMetaInfo().getSizeX();
  -                    }
  -
                       // I have no idea why this needs HTML entities for the & symbol -
                       // Firefox complains about invalid XML if an & is in an attribute
                       // value!
  -                    String thumbnailUrl = WikiUtil.renderURL(inlineLink.getNode()) + "&width="
  -                            + thumbnailWidth + "&cid=" + conversation.getId();
  +                    String thumbnailUrl = WikiUtil.renderURL(inlineLink.getNode()) + "&thumbnail=true&cid=" + conversation.getId();
   
                       return "<a href=\""
                               + (inlineLink.isBroken() ? inlineLink.getUrl() : WikiUtil.renderURL(inlineLink
  
  
  



More information about the jboss-cvs-commits mailing list