cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1573201 - in /cocoon/branches/BRANCH_2_1_X/src: blocks/captcha/java/org/apache/cocoon/reading/CaptchaReader.java blocks/captcha/samples/sitemap.xmap java/org/apache/cocoon/reading/ImageReader.java
Date Sat, 01 Mar 2014 17:26:20 GMT
Author: ilgrosso
Date: Sat Mar  1 17:26:19 2014
New Revision: 1573201

URL: http://svn.apache.org/r1573201
Log:
[COCOON-2341] Applying provided patches

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/captcha/java/org/apache/cocoon/reading/CaptchaReader.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/captcha/samples/sitemap.xmap
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/reading/ImageReader.java

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/captcha/java/org/apache/cocoon/reading/CaptchaReader.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/captcha/java/org/apache/cocoon/reading/CaptchaReader.java?rev=1573201&r1=1573200&r2=1573201&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/captcha/java/org/apache/cocoon/reading/CaptchaReader.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/captcha/java/org/apache/cocoon/reading/CaptchaReader.java
Sat Mar  1 17:26:19 2014
@@ -25,14 +25,15 @@ import java.awt.RenderingHints;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
 import java.awt.image.WritableRaster;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.lang.reflect.Field;
+import java.util.Iterator;
 import java.util.Random;
 
-import com.sun.image.codec.jpeg.JPEGCodec;
-import com.sun.image.codec.jpeg.JPEGEncodeParam;
-import com.sun.image.codec.jpeg.JPEGImageEncoder;
+import javax.imageio.ImageIO;
+import javax.imageio.ImageWriteParam;
+import javax.imageio.ImageWriter;
+import javax.imageio.stream.ImageOutputStream;
 
 /**
  * <p>The {@link CaptchaReader} is a simple tool generating JPEG images for the text
@@ -297,14 +298,16 @@ public class CaptchaReader extends Abstr
         warped = null;
 
         /* Write the processed image as a JPEG image */
-        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(buffer);
-        JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(result);
-        param.setQuality(quality, true);
-        encoder.encode(result, param);
-        buffer.flush();
-        buffer.close();
-        this.out.write(buffer.toByteArray());
+        Iterator writers = ImageIO.getImageWritersByFormatName("jpeg");
+        ImageOutputStream ios = ImageIO.createImageOutputStream(out);
+        ImageWriter writer = (ImageWriter) writers.next();
+        writer.setOutput(ios);
+        ImageWriteParam p = writer.getDefaultWriteParam();
+        p.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
+        p.setCompressionQuality(quality);
+        writer.write(result);
+        
+        ios.flush();
         this.out.flush();
     }
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/captcha/samples/sitemap.xmap
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/captcha/samples/sitemap.xmap?rev=1573201&r1=1573200&r2=1573201&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/captcha/samples/sitemap.xmap (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/captcha/samples/sitemap.xmap Sat Mar  1 17:26:19
2014
@@ -30,7 +30,9 @@
     </map:generators>
   </map:components>
   
-  <map:flow language="javascript" />
+  <map:flow language="javascript">
+    <map:script src="flow/captcha.js"/>
+  </map:flow>
 
   <map:pipelines>
     <map:pipeline type="caching">

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/reading/ImageReader.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/reading/ImageReader.java?rev=1573201&r1=1573200&r2=1573201&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/reading/ImageReader.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/reading/ImageReader.java Sat Mar
 1 17:26:19 2014
@@ -27,20 +27,20 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Serializable;
+import java.util.Iterator;
 import java.util.Map;
+
+import javax.imageio.ImageIO;
+import javax.imageio.ImageWriteParam;
+import javax.imageio.ImageWriter;
+import javax.imageio.stream.ImageOutputStream;
 import javax.swing.ImageIcon;
 
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.environment.SourceResolver;
-import org.apache.commons.lang.SystemUtils;
 import org.xml.sax.SAXException;
 
-import com.sun.image.codec.jpeg.ImageFormatException;
-import com.sun.image.codec.jpeg.JPEGCodec;
-import com.sun.image.codec.jpeg.JPEGEncodeParam;
-import com.sun.image.codec.jpeg.JPEGImageEncoder;
-
 /**
  * The <code>ImageReader</code> component is used to serve binary image data
  * in a sitemap pipeline. It makes use of HTTP Headers to determine if
@@ -97,9 +97,6 @@ final public class ImageReader extends R
     private static final boolean ENLARGE_DEFAULT = true;
     private static final boolean FIT_DEFAULT = false;
 
-    /* See http://developer.java.sun.com/developer/bugParade/bugs/4502892.html */
-    private static final boolean JVMBugFixed = SystemUtils.isJavaVersionAtLeast(1.4f);
-
     private int width;
     private int height;
     private float[] scaleColor = new float[3];
@@ -263,28 +260,6 @@ final public class ImageReader extends R
                                   + " expires: " + expires);
             }
 
-            /*
-             * NOTE (SM):
-             * Due to Bug Id 4502892 (which is found in *all* JVM implementations from
-             * 1.2.x and 1.3.x on all OS!), we must buffer the JPEG generation to avoid
-             * that connection resetting by the peer (user pressing the stop button,
-             * for example) crashes the entire JVM (yes, dude, the bug is *that* nasty
-             * since it happens in JPEG routines which are native!)
-             * I'm perfectly aware of the huge memory problems that this causes (almost
-             * doubling memory consumption for each image and making the GC work twice
-             * as hard) but it's *far* better than restarting the JVM every 2 minutes
-             * (since this is the average experience for image-intensive web application
-             * such as an image gallery).
-             * Please, go to the <a href="http://developer.java.sun.com/developer/bugParade/bugs/4502892.html">Sun
Developers Connection</a>
-             * and vote this BUG as the one you would like fixed sooner rather than
-             * later and all this hack will automagically go away.
-             * Many deep thanks to Michael Hartle <mhartle@hartle-klug.com> for tracking
-             * this down and suggesting the workaround.
-             *
-             * UPDATE (SM):
-             * This appears to be fixed on JDK 1.4
-             */
-
             try {
                 byte content[] = readFully(inputStream);
                 ImageIcon icon = new ImageIcon(content);
@@ -321,25 +296,17 @@ final public class ImageReader extends R
                     colorFilter.filter(currentImage, currentImage);
                 }
 
-                // JVM Bug handling
-                if (JVMBugFixed) {
-                    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
-                    JPEGEncodeParam p = encoder.getDefaultJPEGEncodeParam(currentImage);
-                    p.setQuality(this.quality[0], true);
-                    encoder.setJPEGEncodeParam(p);
-                    encoder.encode(currentImage);
-                } else {
-                    ByteArrayOutputStream bstream = new ByteArrayOutputStream();
-                    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bstream);
-                    JPEGEncodeParam p = encoder.getDefaultJPEGEncodeParam(currentImage);
-                    p.setQuality(this.quality[0], true);
-                    encoder.setJPEGEncodeParam(p);
-                    encoder.encode(currentImage);
-                    out.write(bstream.toByteArray());
-                }
+                Iterator writers = ImageIO.getImageWritersByFormatName("jpeg");
+                ImageOutputStream ios = ImageIO.createImageOutputStream(out);
+                ImageWriter writer = (ImageWriter) writers.next();
+                writer.setOutput(ios);
+                ImageWriteParam p = writer.getDefaultWriteParam();
+                p.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
+                p.setCompressionQuality(this.quality[0]);
+                writer.write(currentImage);
 
-                out.flush();
-            } catch (ImageFormatException e) {
+                ios.flush();
+            } catch (IOException e) {
                 throw new ProcessingException("Error reading the image. " +
                                               "Note that only JPEG images are currently supported.");
             } finally {



Mime
View raw message