org.ditchnet.jsp.taglib.twod.handler
Class CanvasTag

java.lang.Object
  extended byjavax.servlet.jsp.tagext.SimpleTagSupport
      extended byorg.ditchnet.jsp.taglib.twod.handler.CanvasTag
All Implemented Interfaces:
javax.servlet.jsp.tagext.JspTag, javax.servlet.jsp.tagext.SimpleTag

public class CanvasTag
extends javax.servlet.jsp.tagext.SimpleTagSupport

Since:
0.1 TODO -- refactor this monolithic class into smaller classes with separate responsibilities.
Version:
0.1
Author:
Todd Ditchendorf

Constructor Summary
CanvasTag()
           
 
Method Summary
protected  void addJavaObjectsToJsRuntime(org.mozilla.javascript.Context ctx, org.mozilla.javascript.Scriptable scope)
          Add the graphics object and the app/session/request/page scope objects to the global scope of the Rhino JavaScript runtime.
protected  void assertImageTypeSupported()
          Assert that the given image format (e.g. jpg, png) is supported by this JVM.
protected  void createGraphics()
          Instantiate this object's BufferedImage and Graphics2D instance fields.
 void doTag()
          Retrieve the JavaScript code in this tag's body.
protected  void evalJs()
          Embed the Rhino JavaScript interpreter to evaluate the script body of this tag.
 java.lang.String getAlt()
           
 java.lang.String getBorder()
           
 java.lang.String getCache()
           
protected  java.lang.String getFileName()
          Determine the image's file name by concatinating this object's id property and the appropriate file extension.
 java.lang.String getHeight()
           
 java.lang.String getId()
           
protected  java.lang.String getImageDirPath()
          Get the string representation of the image dir's path.
 java.lang.String getImageFormat()
           
protected  java.lang.String getJsCode()
          Retrieve the JavaScript code in this tag's body.
 java.lang.String getStyle()
           
 java.lang.String getStyleClass()
           
 java.lang.String getWidth()
           
protected  boolean imageIsOutOfDate()
          Returns true if the JSP in which this tag handler was invoked has been edited since the last time it's associated image was generated.
 void setAlt(java.lang.String alt)
           
 void setBorder(java.lang.String border)
           
 void setCache(java.lang.String cache)
           
 void setHeight(java.lang.String height)
           
 void setId(java.lang.String id)
           
 void setImageFormat(java.lang.String imageFormat)
           
 void setStyle(java.lang.String style)
           
 void setStyleClass(java.lang.String styleClass)
           
 void setWidth(java.lang.String width)
           
protected  void writeFileToDir()
          Write the image to the image directory.
protected  void writeResponse()
          Render the XHTML response consisting of an <img> tag with the appropriate attributes.
 
Methods inherited from class javax.servlet.jsp.tagext.SimpleTagSupport
findAncestorWithClass, getJspBody, getJspContext, getParent, setJspBody, setJspContext, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CanvasTag

public CanvasTag()
Method Detail

getId

public java.lang.String getId()

setId

public void setId(java.lang.String id)

getCache

public java.lang.String getCache()

setCache

public void setCache(java.lang.String cache)

getBorder

public java.lang.String getBorder()

setBorder

public void setBorder(java.lang.String border)

getStyle

public java.lang.String getStyle()

setStyle

public void setStyle(java.lang.String style)

getStyleClass

public java.lang.String getStyleClass()

setStyleClass

public void setStyleClass(java.lang.String styleClass)

getAlt

public java.lang.String getAlt()

setAlt

public void setAlt(java.lang.String alt)

getWidth

public java.lang.String getWidth()

setWidth

public void setWidth(java.lang.String width)

getHeight

public java.lang.String getHeight()

setHeight

public void setHeight(java.lang.String height)

getImageFormat

public java.lang.String getImageFormat()

setImageFormat

public void setImageFormat(java.lang.String imageFormat)

getJsCode

protected java.lang.String getJsCode()
                              throws java.io.IOException,
                                     javax.servlet.jsp.JspException
Retrieve the JavaScript code in this tag's body.

Throws:
java.io.IOException
javax.servlet.jsp.JspException

createGraphics

protected void createGraphics()
Instantiate this object's BufferedImage and Graphics2D instance fields.


getImageDirPath

protected java.lang.String getImageDirPath()
Get the string representation of the image dir's path.


writeFileToDir

protected void writeFileToDir()
                       throws java.io.IOException
Write the image to the image directory.

Throws:
java.io.IOException

getFileName

protected java.lang.String getFileName()
Determine the image's file name by concatinating this object's id property and the appropriate file extension.


assertImageTypeSupported

protected void assertImageTypeSupported()
                                 throws javax.servlet.jsp.JspException
Assert that the given image format (e.g. jpg, png) is supported by this JVM.

Throws:
javax.servlet.jsp.JspException

doTag

public void doTag()
           throws java.io.IOException,
                  javax.servlet.jsp.JspException
Retrieve the JavaScript code in this tag's body.

Throws:
java.io.IOException
javax.servlet.jsp.JspException

imageIsOutOfDate

protected boolean imageIsOutOfDate()
Returns true if the JSP in which this tag handler was invoked has been edited since the last time it's associated image was generated. This allows caching of the image.


evalJs

protected void evalJs()
               throws javax.servlet.jsp.JspException
Embed the Rhino JavaScript interpreter to evaluate the script body of this tag. A (@link java.awt.Graphics2D} object will be available as a globally scoped variable named g.

Throws:
javax.servlet.jsp.JspException

addJavaObjectsToJsRuntime

protected void addJavaObjectsToJsRuntime(org.mozilla.javascript.Context ctx,
                                         org.mozilla.javascript.Scriptable scope)
Add the graphics object and the app/session/request/page scope objects to the global scope of the Rhino JavaScript runtime. This will allow their use in this tag's JS body.


writeResponse

protected void writeResponse()
                      throws java.io.IOException,
                             javax.servlet.jsp.JspException
Render the XHTML response consisting of an <img> tag with the appropriate attributes.

Throws:
java.io.IOException
javax.servlet.jsp.JspException