javawebparts.taglib.jstags
Class JSDigesterTag

java.lang.Object
  |
  +--javax.servlet.jsp.tagext.TagSupport
        |
        +--javawebparts.taglib.jstags.JSDigesterTag
All Implemented Interfaces:
javax.servlet.jsp.tagext.IterationTag, java.io.Serializable, javax.servlet.jsp.tagext.Tag

public class JSDigesterTag
extends javax.servlet.jsp.tagext.TagSupport

This class is a custom tag that renders the JSDigester. This is a client-side implementation of the Commons Digester component, quite a bit trimmed down though (i.e., only a few of the most common rules are implemented).

JSDigester uses the SAXParser code from the Mozilla JSLib library. It is included here for convenience, with some minor changes required to work for JSDigester, and also to save some space.

The implemented rules are CreateObject, SetProperties, BeanPropertySetter and SetNext. Here is a usage example:

function testJSDigester() {   sampleXML = "<movies numMovies=\"2\">\n";
  sampleXML += " <movie>\n";
  sampleXML += " <title>Star Wars</title>\n";
  sampleXML += " <actor gender=\"male\">Harrison Ford< /actor>\n";
  sampleXML += " <actor gender=\"female\"> Carrie Fisher</actor>\n";
  sampleXML += " </movie>\n";
  sampleXML += " <movie>\n";
  sampleXML += " <title>Real Genius</title>\n";
  sampleXML += " <actor gender=\"male\">Val Kilmer< /actor>\n";
  sampleXML += " </movie>\n";
  sampleXML += "</movies>";
  jsDigester = new JSDigester();
  jsDigester.addObjectCreate("movies", "Movies");
  jsDigester.addSetProperties("movies");
  jsDigester.addObjectCreate("movies/movie", "Movie");
  jsDigester.addBeanPropertySetter("movies/movie/title", "setTitle");
  jsDigester.addObjectCreate("movies/movie/actor", "Actor");
  jsDigester.addSetProperties("movies/movie/actor");
  jsDigester.addBeanPropertySetter("movies/movie/actor", "setName");
  jsDigester.addSetNext("movies/movie/actor", "addActor");
  jsDigester.addSetNext("movies/movie", "addMovie");
  myMovies = jsDigester.parse(sampleXML);
}


(This is directly from the sample app. This makes use of some custom Javascript "classes", so please see the sample app for full details)

Because the rendered code is considerably bigger than most of the other tags in the JSTags library, it is not shown here.

Author:
Frank W. Zammetti.
See Also:
Serialized Form

Field Summary
private static org.apache.commons.logging.Log log
          Log instance.
private  java.lang.String renderScriptTags
          Whether to render the opening and closing script tags around the emitted Javascript.
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
JSDigesterTag()
           
 
Method Summary
 int doStartTag()
          Render the results of the tag.
private  void renderJSDigester(java.lang.StringBuffer sb)
          Renders the JSDigester class code.
private  void renderRules(java.lang.StringBuffer sb)
          Renders the Digester rule classes.
private  void renderSAXParser(java.lang.StringBuffer sb)
          Renders the SAXParser handler class code.
 void setRenderScriptTags(java.lang.String inRenderScriptTags)
          renderScriptTags mutator.
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
doAfterBody, doEndTag, findAncestorWithClass, getId, getParent, getValue, getValues, release, removeValue, setId, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Log instance.


renderScriptTags

private java.lang.String renderScriptTags
Whether to render the opening and closing script tags around the emitted Javascript.

Constructor Detail

JSDigesterTag

public JSDigesterTag()
Method Detail

setRenderScriptTags

public void setRenderScriptTags(java.lang.String inRenderScriptTags)
renderScriptTags mutator.

Parameters:
inRenderScriptTags - renderScriptTags.

doStartTag

public int doStartTag()
               throws javax.servlet.jsp.JspException
Render the results of the tag.

Specified by:
doStartTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doStartTag in class javax.servlet.jsp.tagext.TagSupport
Returns:
Return code.
Throws:
javax.servlet.jsp.JspException - If anything goes wrong

renderSAXParser

private void renderSAXParser(java.lang.StringBuffer sb)
Renders the SAXParser handler class code.

Parameters:
sb - StringBuffer the output is being built up in.

renderJSDigester

private void renderJSDigester(java.lang.StringBuffer sb)
Renders the JSDigester class code.

Parameters:
sb - StringBuffer the output is being built up in.

renderRules

private void renderRules(java.lang.StringBuffer sb)
Renders the Digester rule classes.

Parameters:
sb - StringBuffer the output is being built up in.


Copyright © 2005 Frank W. Zammetti