jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject cvs commit: jakarta-taglibs-sandbox/image/doc/web/images splash-new-gray.jpg
Date Mon, 03 May 2004 15:47:42 GMT
abey        2004/05/03 08:47:42

  Modified:    image/xml intro.xml image.xml
               image/src/org/apache/taglibs/image TransparencyTag.java
                        ResizeTag.java TextTag.java ImageTag.java
               image/examples/conf web.xml
               image/examples/web index.jsp
               image/doc/web/images splash-new-gray.jpg
  Removed:     image/examples/web/WEB-INF/lib pmiw.jar
               image/lib pmiw.jar
  Log:
  update including bestfit resize, transparency, etc - Abey
  
  Revision  Changes    Path
  1.3       +2 -3      jakarta-taglibs-sandbox/image/xml/intro.xml
  
  Index: intro.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs-sandbox/image/xml/intro.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- intro.xml	19 Apr 2004 14:33:19 -0000	1.2
  +++ intro.xml	3 May 2004 15:47:42 -0000	1.3
  @@ -34,8 +34,7 @@
     
       <news>
         <newsitem date="16/04/2004">
  -      	Added a new tag to add Transparency to images. This is useful before
  -      	overlaying images.       
  +      	Added Transparency tag, bestfit option for Resize tag, etc.
         </newsitem>    
         <newsitem date="10/03/2003">
         	The Image taglib is now available in the sandbox for testing 
  @@ -113,7 +112,7 @@
       <p>List of contributors:</p>
   
       <ul>
  -      <li>Abey Mullassery</li>
  +      <li><a href="http://www.mullassery.com">Abey Mullassery</a></li>
       </ul>
   
     </section>
  
  
  
  1.4       +69 -35    jakarta-taglibs-sandbox/image/xml/image.xml
  
  Index: image.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs-sandbox/image/xml/image.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- image.xml	19 Apr 2004 14:33:19 -0000	1.3
  +++ image.xml	3 May 2004 15:47:42 -0000	1.4
  @@ -96,7 +96,8 @@
   		  for the <code>refresh</code> attribute is "<code>false</code>".
The <code>dir</code> 
   		  attribute lets you specify a directory to save the generated images. The generated

   		  images are saved into a default "<code>gen-images</code>" directory or
the one 
  -		  specified by the <code>dir</code> attribute.</blockquote>
  +		  specified by the <code>dir</code> attribute. The quality of the final image
can be specified
  +		  as a float (0.0 to 1.0 - default 0.6) by the <code>quality</code> attribute.</blockquote>
   
   		<b>Encoding, HTML generation and access of the images</b>
   		  <blockquote>
  @@ -120,7 +121,7 @@
   		<ul>
   		  <li> <code>resize</code> -- <code>scale</code> the image
by a percentage or 
   		    to a specified <code>width</code> and <code>height</code>.
Thus it supports 
  -		    differential scaling (i.e., scaleX != scaleY) </li>
  +		    differential scaling (i.e., scaleX != scaleY). It also has a bestfit option.</li>
   		  <li> <code>grayscale</code> -- convert a color image to grayscale.
</li>
   		  <li> <code>rotate</code> -- rotate the image by some degrees and
enlarges it 
   		    to still accommodate the full image. </li>
  @@ -135,6 +136,7 @@
   		    with the <code>color</code> will be considered as transparent. </li>
   		  <li> <code>text</code> -- writes a string/ text on the image in the
<code>color</code> 
   		    and <code>font</code> at a given point. </li>
  +		  <li> <code>transparency</code> -- adds transparency to the image.
</li>
   		</ul>
   		  These tags can be combined and used in any order to get the desired effect. 
   		  The overlay is useful to add tags like "SOLD", "NEW", etc., to a product image. 
  @@ -154,18 +156,19 @@
   &lt;img:image src=&quot;/images/splash.jpg&quot;
           dir=&quot;generated&quot;
           name=&quot;splash-new-gray.jpg&quot;
  -        refresh=&quot;true&quot;&gt;
  +        refresh=&quot;true&quot;
  +        attributes=&quot;border='0' alt='a sample dynamic image'&quot;&gt;
       &lt;img:grayscale/&gt;
  -    &lt;img:overlay x=&quot;5%&quot; y=&quot;60%&quot;&gt;
  +    &lt;img:overlay x=&quot;55%&quot; y=&quot;60%&quot;&gt;
           &lt;img:image src=&quot;/images/new.gif&quot; &gt;
               &lt;img:rotate degrees=&quot;-30&quot; /&gt;
               &lt;img:resize scale=&quot;80%&quot; /&gt;
               &lt;img:transparency level=&quot;125&quot; /&gt;          
 
           &lt;/img:image&gt;        
       &lt;/img:overlay&gt;
  -    &lt;img:resize scale=&quot;75%&quot; /&gt;
       &lt;img:border width=&quot;5&quot; height=&quot;3&quot; 
               color=&quot;0x005d00&quot;/&gt;
  +    &lt;img:resize bestfit=&quot;true&quot; width=&quot;200&quot; height=&quot;400&quot;/&gt;
   &lt;/img:image&gt;
   		</pre>
   		<b>The output image of the tag given above:</b><br/>
  @@ -184,14 +187,14 @@
   		    	<li>The image is rotated by &quot;-30&quot; degrees</li>
   		    	<li>The resulting image is resize/scaled to its &quot;80%&quot;</li>
   		    </ol>
  -		  <li>The whole image is resized/ scaled to &quot;75%&quot; its current
size. </li>
   		  <li>A colored border with &quot;5&quot; pixels thickness at the sides
and &quot;3&quot; pixels at the top
  -		   and bottom is added. </li>		  
  +		   and bottom is added. </li>	
  +		  <li>The whole image is resized/ scaled to fit within a &quot;200&quot;
x &quot;400&quot; rectangle. </li>  
   		  <li>The image is saved as &quot;splash-new-gray.jpg&quot; in the &quot;generated&quot;

   		  directory. </li>
  -		  <li>An <code>&lt;img&gt;</code> tag similar to <code>&lt;img
src=&quot;/generated/splash-new-gray.jpg&quot; 
  -		    width=&quot;300&quot; height=&quot;200&quot;&gt;</code>
is written. The &quot;width&quot; 
  -		    and &quot;height&quot; are that of the resulting image.</li>
  +		  <li>An <code>&lt;img&gt;</code> tag similar to <code>&lt;img
border='0' alt='a sample dynamic image' 
  +                src=&quot;/generated/splash-new-gray.jpg&quot; width=&quot;200&quot;
height=&quot;132&quot;&gt;</code> 
  +                is written. The &quot;width&quot; and &quot;height&quot;
are that of the resulting image.</li>
   		</ol>
   		</blockquote>
   	</p>
  @@ -204,16 +207,14 @@
   		    <li>Loading Scalable Vector Graphics (SVG) files using Batik.</li>
   		    <li>Shape overlay and transformation operations such as "ShapeOverlay", "Circle",

   		      &quot;Rectangle&quot;, etc. </li>
  -		    <li>Image kernel operations such as "Brightness", "Contrast", "Threshold",

  -		      &quot;Blur&quot;, &quot;Posterize&quot;, etc. </li>
  +		    <li>Operations such as "Brightness", "Contrast", "Threshold", &quot;Posterize&quot;,
etc. </li>
   		    <li>Special operations such as &quot;Tile", &quot;Bevel border&quot;,
etc. 
   		    </li>
   		    <li>The various ways of deleting the image files need to be implemented such

   		      as <code>deleteOnExit</code>, <code>deleteAfterRequest</code>,
<code>deleteAferSession</code>, 
   		      etc. </li>
  -		    <li>Implementations based on Standard Windowing Toolkit (SWT) or similar library

  -		      that might not have "headless" issues. </li>
  -		    <li>Support for GIF file writing using ACME or similar libraries. </li>
  +		    <li>Implementations based on Standard Windowing Toolkit (SWT).</li>
  +		    <li>Improve the WebColorFilter in GIF encoding.</li>
   			<li>Logging support.</li>			    
   		  </ul>
   		</blockquote>
  @@ -263,10 +264,13 @@
               <type>String</type>
           	<description>
           		The file name for the output image. The format/ encoding of the output
  -        		image is decided from the extension on this name. The tag searches
  -        		for an image file with this name and loads it if it exists UNLESS
  -        		the refresh attribute is set to true. Just the output filename  
  -        		without the path is expected.
  +        		image is decided from the extension on this name. The extention can be
  +        		jpeg, jpg, png, gif, etc. The default is the same as the src image. 
  +        		Java2d supports only jpeg. JAI supports jpeg, png, tiff, bmp, etc. but 
  +        		not gif. For gif encoding pja-tools.jar must be included in the 
  +        		classpath. The tag searches for an image file with this name and loads 
  +        		it if it exists UNLESS the refresh attribute is set to true. Just the 
  +        		output filename without the path is expected.
           	</description>
           	<availability>1.0</availability>            
           </attribute>
  @@ -288,9 +292,9 @@
               <rtexprvalue>true</rtexprvalue>
               <type>boolean</type>
           	<description>
  -        		The output file is generated in and reloaded from this directory. 
  -        		This is expected relative to the context path. The default value 
  -        		is &quot;gen-images&quot;.
  +        		If this value is set to true, the image is generated on every access.
  +        		If it is set to false (default) the dynamic image is generated only
  +        		when the output image (already generated) is absent (first access).
           	</description>
           	<availability>1.0</availability>            
           </attribute>
  @@ -324,12 +328,23 @@
               <rtexprvalue>true</rtexprvalue>
               <type>String</type>
           	<description>
  -        		The output file is generated in and reloaded from this directory. 
  -        		This is expected relative to the context path. The default value 
  -        		is &quot;gen-images&quot;.
  +        		The imaging library used is specified by this attribute. It could be
  +        		JAVA2D or JAI. By default it will look for JAI and if those classes are
  +        		not available it will load Java2D imaging support. 
           	</description>
           	<availability>1.0</availability>            
  -        </attribute>        
  +        </attribute>      
  +        <attribute>
  +            <name>quality</name>
  +            <required>false</required>
  +            <rtexprvalue>true</rtexprvalue>
  +            <type>float</type>
  +        	<description>
  +        		The quality of the output image file. The value must be between 
  +        		0.0 and 1.0. The default is 0.6.
  +        	</description>
  +        	<availability>1.0</availability>            
  +        </attribute>          
   	    <example>
   		    <usage>
   			    <comment>
  @@ -347,7 +362,8 @@
   	dir="generated" 
   	name="splash-new.jpg" 
   	attributes="alt='A sample image'"
  -	refresh="false">
  +	refresh="false"
  +	quality="0.8">
   </img:image>			    	
   					]]> 
   			    </code>
  @@ -414,7 +430,19 @@
           		However if the scale attribute is specified, this attribute is ignored.
           	</description>
           	<availability>1.0</availability>            
  -        </attribute>                
  +        </attribute>   
  +        <attribute>
  +            <name>bestfit</name>
  +            <required>false</required>
  +            <rtexprvalue>true</rtexprvalue>
  +            <type>boolean</type>
  +        	<description>
  +        		The image is scaled within the rectangled specified by the width and height
  +        		keeping the aspect ratio of the original image if this option is true. The
  +        		width and height MUST be specified if this option is set true.
  +        	</description>
  +        	<availability>1.0</availability>            
  +        </attribute>                     
   	    <example>
   		    <usage>
   			    <comment>
  @@ -871,7 +899,7 @@
       <tag>
           <name>text</name>
           <tag-class>org.apache.taglibs.image.TextTag</tag-class>
  -        <body-content>empty</body-content>
  +        <body-content>JSP</body-content>
           <display-name>Text</display-name>
           <description>
   	    	This nested/ child tag of the <code>&lt;image&gt;</code> tag
can add a line of text
  @@ -912,11 +940,12 @@
           </attribute>
           <attribute>
               <name>text</name>
  -            <required>true</required>
  +            <required>false</required>
               <rtexprvalue>true</rtexprvalue>
               <type>String</type>
           	<description>
  -        		The String value that should be written/painted on the image.
  +        		The String value that should be written/painted on the image. This may also be

  +        		specified in the body. If the text attribute is specified the body is ignored.
           	</description>
           	<availability>1.0</availability>            
           </attribute>
  @@ -948,8 +977,8 @@
               <rtexprvalue>true</rtexprvalue>
               <type>String</type>
           	<description>
  -        		The color of the font in which the text has to appear. The default color value
is 
  -        		&quot;<code>0x000000</code>&quot; (black)
  +        		The color of the font (as an RGB integer) in which the text has to appear. The
default 
  +        		color value is &quot;<code>0x000000</code>&quot; (black)
           	</description>
           	<availability>1.0</availability>            
           </attribute>
  @@ -1035,13 +1064,18 @@
   
   <revision release="Development" date="16/04/2004">
     <description>
  -    The Image tag library is in development,
  -    changes are fast and furious.
  +    More changes based on user feedback.
     </description>
     <section name="New Features">
       <item>
         New Tag to add transparency to an image.
       </item>
  +    <item>
  +      Bestfit feature in Resize tag
  +    </item>    
  +    <item>
  +      Support for accessing contexts within a security-constraint
  +    </item>    
     </section>
     <section name="Bugs Fixed">
       <item>
  
  
  
  1.3       +6 -3      jakarta-taglibs-sandbox/image/src/org/apache/taglibs/image/TransparencyTag.java
  
  Index: TransparencyTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs-sandbox/image/src/org/apache/taglibs/image/TransparencyTag.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TransparencyTag.java	21 Apr 2004 05:02:57 -0000	1.2
  +++ TransparencyTag.java	3 May 2004 15:47:42 -0000	1.3
  @@ -68,18 +68,21 @@
    */
   public class TransparencyTag extends TagSupport {
   
  -    private int level;
  +    private int level = 125;
   
       public int doEndTag() throws JspException {
           Tag pTag = getParent();
           if (pTag == null || !(pTag instanceof ImageHolder))
                   throw new JspException(
                           "Transparency must be a nested tag of Image Tag!");
  +        if (!(level > 0 && level <= 255))
  +            throw new JspException(
  +                    "Transparency \"level\" must be between 0 and 255");
  +        
           ImageHolder par = (ImageHolder) getParent();
           BufferedImage image = par.getImage();
   
  -        //just to make the build succeed
  -        //par.setImage(par.getImaging().addTransparency(image, level));
  +        par.setImage(par.getImaging().addTransparency(image, level));
           return EVAL_PAGE;
       }
   
  
  
  
  1.5       +3 -12     jakarta-taglibs-sandbox/image/src/org/apache/taglibs/image/ResizeTag.java
  
  Index: ResizeTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs-sandbox/image/src/org/apache/taglibs/image/ResizeTag.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ResizeTag.java	21 Apr 2004 13:40:38 -0000	1.4
  +++ ResizeTag.java	3 May 2004 15:47:42 -0000	1.5
  @@ -106,16 +106,8 @@
           ImageHolder par = (ImageHolder) getParent();
   
           if (bestfit) {// width and height is specified
  -            float ht = Float.parseFloat(height);
  -            float wt = Float.parseFloat(width);
  -            float wScale = (wt / par.getImage().getWidth());
  -            float hScale = (ht / par.getImage().getHeight());
  -
  -            if (wScale <= hScale) {
  -                par.setImage(par.getImaging().scale(par.getImage(), wScale));
  -            } else {
  -                par.setImage(par.getImaging().scale(par.getImage(), hScale));
  -            }
  +            par.setImage(par.getImaging().resize(par.getImage(),
  +                    Integer.parseInt(width), Integer.parseInt(height), true));
           } else if (scale != null && scale.length() != 0) {
               par.setImage(par.getImaging().scale(par.getImage(),
                       Util.convertToFraction(scale, 1)));
  @@ -133,8 +125,7 @@
                                           .getWidth())));
               }
           } else {
  -            par
  -                    .setImage(par.getImaging().scale(
  +            par.setImage(par.getImaging().scale(
                               par.getImage(),
                               Util.convertToFraction(width, par.getImage()
                                       .getWidth()),
  
  
  
  1.3       +83 -69    jakarta-taglibs-sandbox/image/src/org/apache/taglibs/image/TextTag.java
  
  Index: TextTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs-sandbox/image/src/org/apache/taglibs/image/TextTag.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TextTag.java	7 Oct 2003 06:33:54 -0000	1.2
  +++ TextTag.java	3 May 2004 15:47:42 -0000	1.3
  @@ -52,88 +52,102 @@
    * <http://www.apache.org/>.
    *
    */
  - 
  +
   package org.apache.taglibs.image;
   
   import java.awt.Font;
   import java.awt.image.BufferedImage;
   
   import javax.servlet.jsp.JspException;
  +import javax.servlet.jsp.tagext.BodyTagSupport;
   import javax.servlet.jsp.tagext.Tag;
  -import javax.servlet.jsp.tagext.TagSupport;
   
   import com.mullassery.imaging.util.Util;
   
   /**
  - * <p>Adds a line of text onto an image.</p>
  - *
  - * @author Abey Mullassery
  + * <p>
  + * Adds a line of text onto an image.
  + * </p>
    * 
  + * @author Abey Mullassery
  + *  
    */
  -public class TextTag extends TagSupport {
  +public class TextTag extends BodyTagSupport {
  +
  +    private String x = "2";
  +
  +    private String y = "98%";
  +
  +    private String text;
   
  -	private String x = "2";
  -	private String y = "98%";
  -	private String text;
  -	private String font;
  -	private String color = "0x000000";
  -	private int size = 10;
  -	private boolean italic;
  -	private boolean bold;
  -
  -	public int doEndTag() throws JspException {
  -		Tag pTag = getParent();
  -		if (pTag == null || !(pTag instanceof ImageHolder))
  -			throw new JspException("Text must be a nested tag of Image Tag!");
  -		ImageHolder par = (ImageHolder)getParent();
  -		BufferedImage image = par.getImage();
  -
  -		int _x = (int)Util.convertToWhole(x, image.getWidth());
  -		int _y = (int)Util.convertToWhole(y, image.getHeight());
  -		Font f = Font.getFont("SansSerif");
  -		if (font != null) {
  -			int style = 0;
  -			style = italic ? style | Font.ITALIC : style;
  -			style = bold ? style | Font.BOLD : style;			
  -			try {
  -				f = new Font(font, style, size);
  -			} catch (RuntimeException e) {
  -			}
  -		}
  -
  -		par.setImage(par.getImaging().textOverlay(image, text, _x, _y, f, Util.getColor(color)));
  -		return EVAL_PAGE;
  -	}
  -	public void setFont(String font) {
  -		this.font = font;
  -	}
  -
  -	public void setItalic(boolean italic) {
  -		this.italic = italic;
  -	}
  -
  -	public void setSize(int size) {
  -		this.size = size;
  -	}
  -
  -	public void setText(String text) {
  -		this.text = text;
  -	}
  -
  -	public void setX(String x) {
  -		this.x = x;
  -	}
  -
  -	public void setY(String y) {
  -		this.y = y;
  -	}
  -
  -	public void setBold(boolean bold) {
  -		this.bold = bold;
  -	}
  -
  -	public void setColor(String color) {
  -		this.color = color;
  -	}
  +    private String font;
  +
  +    private String color = "0x000000";
  +
  +    private int size = 10;
  +
  +    private boolean italic;
  +
  +    private boolean bold;
  +
  +    public int doEndTag() throws JspException {
  +        Tag pTag = getParent();
  +        if (pTag == null || !(pTag instanceof ImageHolder))
  +                throw new JspException(
  +                        "Text must be a nested tag of Image Tag!");
  +        ImageHolder par = (ImageHolder) getParent();
  +        BufferedImage image = par.getImage();
  +
  +        int _x = (int) Util.convertToWhole(x, image.getWidth());
  +        int _y = (int) Util.convertToWhole(y, image.getHeight());
  +        Font f = Font.getFont("SansSerif");
  +        if (font != null) {
  +            int style = 0;
  +            style = italic ? style | Font.ITALIC : style;
  +            style = bold ? style | Font.BOLD : style;
  +            try {
  +                f = new Font(font, style, size);
  +            } catch (RuntimeException e) {
  +            }
  +        }
  +        if (text == null) {
  +            text = bodyContent.getString();
  +        }
  +        par.setImage(par.getImaging().textOverlay(image, text, _x, _y, f,
  +                Util.getColor(color)));
  +        return EVAL_PAGE;
  +    }
  +
  +    public void setFont(String font) {
  +        this.font = font;
  +    }
  +
  +    public void setItalic(boolean italic) {
  +        this.italic = italic;
  +    }
  +
  +    public void setSize(int size) {
  +        this.size = size;
  +    }
  +
  +    public void setText(String text) {
  +        this.text = text;
  +    }
  +
  +    public void setX(String x) {
  +        this.x = x;
  +    }
  +
  +    public void setY(String y) {
  +        this.y = y;
  +    }
  +
  +    public void setBold(boolean bold) {
  +        this.bold = bold;
  +    }
  +
  +    public void setColor(String color) {
  +        this.color = color;
  +    }
   
   }
  
  
  
  1.5       +147 -103  jakarta-taglibs-sandbox/image/src/org/apache/taglibs/image/ImageTag.java
  
  Index: ImageTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs-sandbox/image/src/org/apache/taglibs/image/ImageTag.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ImageTag.java	21 Apr 2004 13:41:23 -0000	1.4
  +++ ImageTag.java	3 May 2004 15:47:42 -0000	1.5
  @@ -58,8 +58,10 @@
   import java.awt.image.BufferedImage;
   import java.io.File;
   import java.io.IOException;
  +import java.io.InputStream;
   import java.net.MalformedURLException;
   import java.net.URL;
  +import java.net.URLConnection;
   
   import javax.servlet.ServletContext;
   import javax.servlet.http.HttpServletRequest;
  @@ -93,44 +95,117 @@
   
       public static final String GEN_IMAGES_DIR = "gen-images";
   
  -    private String src;
  +    protected String src;
   
  -    private String attributes;
  +    protected String attributes;
   
  -    private String name;
  +    protected String name;
   
  -    private boolean deleteOnExit = false;
  +    protected boolean deleteOnExit = false;
   
  -    private boolean refresh = false;
  +    protected boolean refresh = false;
   
  -    private boolean display = true;
  +    protected boolean display = true;
   
  -    private String dir = GEN_IMAGES_DIR;
  +    protected String dir = GEN_IMAGES_DIR;
   
  -    private BufferedImage image;
  +    protected BufferedImage image;
   
  -    private File img;
  +    protected File img;
   
  -    private Imaging imaging;
  +    protected float quality = 0.6f;
   
  -    private ServletContext context;
  +    protected Imaging imaging;
   
  -    private HttpServletRequest hr; //should this be ServletRequest?
  +    protected ServletContext context;
   
  -    private String baseUrl;
  +    protected HttpServletRequest hreq;
   
  -    private String imagingType;
  +    protected HttpServletResponse hres;
   
  -    private ImageHolder par;
  +    protected String baseUrl;
  +
  +    protected String imagingType;
  +
  +    protected ImageHolder par;
   
       public int doStartTag() throws JspException {
  +        initialize();
  +        doChecks();
  +
  +        try {
  +            getLocalImageFile();
  +            createImaging();
  +            fetchImage();
  +        } catch (Throwable e) {
  +            // don't throw exceptions for image errors like the <img> tag
  +            refresh = false; //keep quiet; no errors
  +            context.log("ImageTag error: Cannot get " + src);
  +            context.log("The exception was:-", e);
  +        }
  +
  +        if (refresh)
  +            return EVAL_BODY_BUFFERED;
  +        else
  +            return SKIP_BODY;
  +    }
  +
  +    public int doAfterBody() throws JspException {
  +        bodyContent.clearBody();
  +        return SKIP_BODY;
  +    }
  +
  +    public int doEndTag() throws JspException {
  +        if (image == null) return EVAL_PAGE;
  +
  +        //serving as a nested Tag to the Overlay tag?
  +        if (par != null) {
  +            //just pass the image; no need to write/save
  +            par.setImage(image);
  +            return EVAL_PAGE;
  +        }
  +
  +        saveImageIfRequired();
  +
  +        //if the image is to be displayed
  +        if (display) {
  +            try {
  +                pageContext.getOut().println(createImageSrcUrlString());
  +            } catch (IOException e) {
  +                context.log("Error creating <img> tag-html: ", e);
  +                throw new JspException(e);
  +            }
  +        }
  +        this.image = null;
  +        return EVAL_PAGE;
  +    }
  +
  +    public void release() {
  +        this.image = null;
  +        super.release();
  +        System.gc();
  +    }
  +
  +    private void initialize() throws JspException {
           context = pageContext.getServletContext();
  -        hr = (HttpServletRequest) (pageContext.getRequest());
  -        String reqUrl = hr.getRequestURL().toString();
  -        baseUrl = reqUrl.substring(0, reqUrl.indexOf(hr.getRequestURI()));
  +        hreq = (HttpServletRequest) (pageContext.getRequest());
  +        hres = (HttpServletResponse) (pageContext.getResponse());
  +        String reqUrl = hreq.getRequestURL().toString();
  +        URL base;
  +        try {
  +            base = new URL(hreq.getScheme(), hreq.getServerName(), hreq
  +                    .getServerPort(), "");
  +        } catch (MalformedURLException e) {
  +            throw new JspException(e);
  +        }
  +        baseUrl = base.toString();
  +
  +    }
   
  +    private void doChecks() throws JspException {
           if (refresh && src == null) { throw new JspException(
                   "Image \"src\" should be specified to refresh forcefully"); }
  +
           //serving as a nested Tag to the Overlay tag?
           Tag pTag = getParent();
           if (pTag != null && (pTag instanceof ImageHolder)) {
  @@ -143,32 +218,38 @@
                       "Image \"src\" should be specified"); }
           }
   
  -        //don't throw exceptions for image errors like the <img> tag
  -        try {
  -            //if the name is not specified the src will be specified
  -            if (name == null) {
  -                URL url = getUrl(src);
  -                name = url.getFile().substring(
  -                        url.getFile().lastIndexOf('/') + 1);
  -            }
  -            String imgFile = Util.extractFileName(name);
  -            img = new File(context.getRealPath("/") + dir, imgFile);
  +        if (!(quality > 0.0 && quality <= 1.0))
  +                throw new JspException(
  +                        "Image \"quality\" must be between 0.0 and 1.0");
  +    }
   
  -            createImaging();
  -            if (refresh || !img.exists()) {
  -                refresh = true;
  -                image = imaging.read(getUrl(src));
  -            } else {
  -                image = imaging.read(img);
  -            }
  -        } catch (Throwable e) {
  -            refresh = false; //keep quiet; no errors
  +    private void getLocalImageFile() throws JspException {
  +        //if the name is not specified the src will be specified
  +        if (name == null) {
  +            URL url = getUrl(src);
  +            name = url.getFile().substring(url.getFile().lastIndexOf('/') + 1);
           }
  +        String imgFile = Util.extractFileName(name);
  +        img = new File(context.getRealPath("/") + dir, imgFile);
  +    }
   
  -        if (refresh)
  -            return EVAL_BODY_BUFFERED;
  -        else
  -            return SKIP_BODY;
  +    private void fetchImage() throws JspException, IOException {
  +        if (refresh || !img.exists()) {
  +            refresh = true;
  +            image = imaging.read(getImageStream());
  +        } else {
  +            image = imaging.read(img);
  +        }
  +    }
  +
  +    protected InputStream getImageStream() throws JspException, IOException {
  +        URLConnection connection = getUrl(src).openConnection();
  +        //TODO: Auth only if it is the same server
  +        String auth = hreq.getHeader("Authorization");
  +        if (auth != null && auth.length() > 0) {
  +            connection.setRequestProperty("Authorization", auth);
  +        }
  +        return connection.getInputStream();
       }
   
       private void createImaging() throws JspException {
  @@ -195,36 +276,7 @@
           // false
       }
   
  -    public int doAfterBody() throws JspException {
  -        bodyContent.clearBody();
  -        return SKIP_BODY;
  -    }
  -
  -    public int doEndTag() throws JspException {
  -        if (image == null) return EVAL_PAGE;
  -
  -        //serving as a nested Tag to the Overlay tag?
  -        if (par != null) {
  -            //just pass the image; no need to write/save
  -            par.setImage(image);
  -            return EVAL_PAGE;
  -        }
  -
  -        if (refresh) {
  -            File f = img.getParentFile();
  -            if (!f.exists()) f.mkdirs();
  -            if (deleteOnExit) {
  -                img.deleteOnExit();
  -                f.deleteOnExit();
  -            }
  -            saveImage();
  -        }
  -        //if the image need not be displayed
  -        if (!display) {
  -            this.image = null;
  -            return EVAL_PAGE;
  -        }
  -
  +    private String createImageSrcUrlString() throws JspException {
           StringBuffer html = new StringBuffer("<img ");
           if (attributes != null && attributes.length() != 0) {
               html.append(attributes);
  @@ -234,44 +286,32 @@
           //checking if the user has already specified the attributes.
           String al = attributes.toLowerCase();
           if (al.indexOf(" src") == -1) {
  -            HttpServletResponse response = (HttpServletResponse) pageContext
  -                    .getResponse();
  -            String encodedUrl = response.encodeURL(getUrl(
  -                    '/' + dir + '/' + img.getName()).toString());
  -            html.append(" src=" + '"' + encodedUrl + '"');
  +            html.append(" src=" + '"' + getUrl('/' + dir + '/' + img.getName())
  +                    + '"');
           }
           if (al.indexOf("width") == -1 && al.indexOf("height") == -1) {
               html.append(" width=\"" + image.getWidth() + "\" height=\""
                       + image.getHeight() + "\"");
           }
           html.append(" />");
  -        try {
  -            pageContext.getOut().println(html.toString());
  -        } catch (IOException e) {
  -            context.log("Error writing <img> tag-html " + html, e);
  -            throw new JspException(e);
  -        }
  -        this.image = null;
  -        return EVAL_PAGE;
  +        return html.toString();
       }
   
  -    public void release() {
  -        this.image = null;
  -        super.release();
  -        System.gc();
  -    }
  +    //TODO: Add quality setting to the save
  +    public void saveImageIfRequired() {
  +        if (!refresh) return;
  +
  +        File f = img.getParentFile();
  +        if (!f.exists()) f.mkdirs();
  +        if (deleteOnExit) {
  +            img.deleteOnExit();
  +            f.deleteOnExit();
  +        }
   
  -    public void saveImage() {
           String type = Util.getExtentionType(img);
  -        if (type.equalsIgnoreCase("gif")) { //till GIF is supported
  -            type = "JPEG";
  -            String imgName = img.getAbsolutePath();
  -            int ind_dot = imgName.indexOf('.');
  -            imgName = imgName.substring(0, ind_dot + 1) + "jpg";
  -        }
           try {
               com.mullassery.imaging.util.Util.saveImage(imaging, image, type,
  -                    img);
  +                    img, quality);
           } catch (IOException e) {
               new JspException(e);
           }
  @@ -280,17 +320,17 @@
       public URL getUrl(String srcStr) throws JspException {
           if (srcStr.startsWith("./")) //will just act like one without it
                   srcStr = srcStr.substring(2);
  -        String contextUrl = baseUrl + hr.getContextPath();
  +        String contextUrl = baseUrl + hreq.getContextPath();
   
  -        if (!srcStr.startsWith(hr.getScheme())) {
  +        if (!srcStr.startsWith(hreq.getScheme())) {
               if (srcStr.startsWith("/")) {
  -                if (srcStr.startsWith(hr.getContextPath() + '/'))
  +                if (srcStr.startsWith(hreq.getContextPath() + '/'))
                       srcStr = baseUrl + srcStr;
                   else
                       srcStr = contextUrl + srcStr;
               } else {
  -                String parUrl = hr.getRequestURL().toString(); // can be
  -                                                               // /xyz?a=b
  +                String parUrl = hreq.getRequestURL().toString(); // can be
  +                // /xyz?a=b
                   // if like "/some/path.html" trim till "/"
                   if (parUrl.indexOf(".") != -1) {
                       parUrl = parUrl.substring(0, parUrl.lastIndexOf("/"));
  @@ -309,7 +349,7 @@
           }
           URL url = null;
           try {
  -            url = new URL(srcStr);
  +            url = new URL(hres.encodeURL(srcStr));
           } catch (MalformedURLException e) {
               context.log("Not a proper URL: " + srcStr, e);
               throw new JspException(e);
  @@ -361,4 +401,8 @@
           this.imagingType = imagingType;
       }
   
  +    public void setQuality(float quality) {
  +        this.quality = quality;
  +
  +    }
   }
  
  
  
  1.2       +1 -1      jakarta-taglibs-sandbox/image/examples/conf/web.xml
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs-sandbox/image/examples/conf/web.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- web.xml	6 Oct 2003 16:46:30 -0000	1.1
  +++ web.xml	3 May 2004 15:47:42 -0000	1.2
  @@ -32,7 +32,7 @@
   
   	<taglib>
   	  <taglib-uri>http://jakarta.apache.org/taglibs/image-1.0</taglib-uri>
  -	  <taglib-location>/WEB-INF/image.tld</taglib-location>
  +	  <taglib-location>/WEB-INF/taglibs-image.tld</taglib-location>
   	</taglib>
   
   </web-app>
  
  
  
  1.4       +19 -17    jakarta-taglibs-sandbox/image/examples/web/index.jsp
  
  Index: index.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs-sandbox/image/examples/web/index.jsp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- index.jsp	19 Apr 2004 14:33:19 -0000	1.3
  +++ index.jsp	3 May 2004 15:47:42 -0000	1.4
  @@ -11,7 +11,7 @@
   <h1 align="center">Image Tag examples</h1>
   <table width="100%" border="0" cellpadding="2">
     <tr align="center"> 
  -    <td colspan="3">A Tag example (lots more will be added soon)</td>
  +    <td colspan="3">A Tag example.</td>
     </tr>
     <tr> 
       <td>&nbsp;</td>
  @@ -20,20 +20,21 @@
   <img:image src="/images/splash.jpg"
           dir="generated"
           name="splash-new-gray.jpg"
  -        refresh="true">
  +        refresh="true"
  +	  attributes="border='0' alt='a sample dynamic image'">
       <img:grayscale/>
  -    <img:overlay x="5%" y="50%">
  +    <img:overlay x="55%" y="50%">
           <img:image src="/images/new.gif" >
               <img:rotate degrees="-30" />
               <img:resize scale="80%" />
               <img:transparency level="125" />
           </img:image>        
       </img:overlay>
  -    <img:resize scale="75%" />
       <img:border width="5" height="3" 
               color="0x005d00"/>
  +    <img:resize bestfit="true" width="200" height="400"/>
   </img:image>    
  -    
  +  
       </td>
       <td>&nbsp;</td>
     </tr>
  @@ -49,18 +50,19 @@
   &lt;img:image src=&quot;/images/splash.jpg&quot;
           dir=&quot;generated&quot;
           name=&quot;splash-new-gray.jpg&quot;
  -        refresh=&quot;true&quot;&gt;
  +        refresh=&quot;true&quot;
  +        attributes=&quot;border='0' alt='a sample dynamic image'&quot;&gt;
       &lt;img:grayscale/&gt;
  -    &lt;img:overlay x=&quot;5%&quot; y=&quot;60%&quot;&gt;
  +    &lt;img:overlay x=&quot;55%&quot; y=&quot;60%&quot;&gt;
           &lt;img:image src=&quot;/images/new.gif&quot; &gt;
               &lt;img:rotate degrees=&quot;-30&quot; /&gt;
               &lt;img:resize scale=&quot;80%&quot; /&gt;
               &lt;img:transparency level=&quot;125&quot; /&gt;          
 
           &lt;/img:image&gt;        
       &lt;/img:overlay&gt;
  -    &lt;img:resize scale=&quot;75%&quot; /&gt;
       &lt;img:border width=&quot;5&quot; height=&quot;3&quot; 
               color=&quot;0x005d00&quot;/&gt;
  +    &lt;img:resize bestfit=&quot;true&quot; width=&quot;200&quot; height=&quot;400&quot;/&gt;
   &lt;/img:image&gt;
   		</pre>		
   		The sequence of operations to generate the output image: -
  @@ -77,14 +79,14 @@
   		    	<li>The image is rotated by &quot;-30&quot; degrees</li>
   		    	<li>The resulting image is resize/scaled to its &quot;80%&quot;</li>
   		    </ol>
  -		  <li>The whole image is resized/ scaled to &quot;75%&quot; its current
size. </li>
   		  <li>A colored border with &quot;5&quot; pixels thickness at the sides
and &quot;3&quot; pixels at the top
  -		   and bottom is added. </li>		  
  +		   and bottom is added. </li>	
  +		  <li>The whole image is resized/ scaled to fit within a &quot;200&quot;
x &quot;400&quot; rectangle. </li>  
   		  <li>The image is saved as &quot;splash-new-gray.jpg&quot; in the &quot;generated&quot;

   		  directory. </li>
  -		  <li>An <code>&lt;img&gt;</code> tag similar to <code>&lt;img
src=&quot;/generated/splash-new-gray.jpg&quot; 
  -		    width=&quot;300&quot; height=&quot;200&quot;&gt;</code>
is written. The &quot;width&quot; 
  -		    and &quot;height&quot; are that of the resulting image.</li>
  +		  <li>An <code>&lt;img&gt;</code> tag similar to <code>&lt;img
border='0' alt='a sample dynamic image' 
  +                src=&quot;/generated/splash-new-gray.jpg&quot; width=&quot;200&quot;
height=&quot;132&quot;&gt;</code> 
  +                is written. The &quot;width&quot; and &quot;height&quot;
are that of the resulting image.</li>
   		</ol>
   		</blockquote>	
   
  @@ -93,9 +95,9 @@
     </tr>
   </table>
   <p align="center">
  -	<b>Source Images used in the above example.</b>
  -	<img src="/images/splash.jpg" /><br/><br/>
  -	<img src="/images/new.gif" />
  +	<b>Source Images used in the above example:-</b><br/>
  +	<img src="images/splash.jpg" /><br/><br/>
  +	<img src="images/new.gif" />
   </p>
   </body>
  -</html>
  +</html>
  \ No newline at end of file
  
  
  
  1.3       +24 -38    jakarta-taglibs-sandbox/image/doc/web/images/splash-new-gray.jpg
  
  	<<Binary file>>
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org


Mime
View raw message