atg.taglib.json
Class JsonBaseTag

java.lang.Object
  extended by javax.servlet.jsp.tagext.SimpleTagSupport
      extended by atg.taglib.json.JsonBaseTag
All Implemented Interfaces:
javax.servlet.jsp.tagext.JspTag, javax.servlet.jsp.tagext.SimpleTag
Direct Known Subclasses:
JsonArrayTag, JsonObjectTag, JsonPropertyTag

public abstract class JsonBaseTag
extends javax.servlet.jsp.tagext.SimpleTagSupport

Abstract base class for all JSON tags

Version:
$Id$
Author:
James Wiltshire

Field Summary
protected  java.lang.Boolean mEscapeXmlOriginalValue
           
protected  boolean mEscapeXmlValueSet
           
protected  java.lang.String mName
           
protected  boolean mNewStackCreated
           
protected  boolean mTrim
           
protected static int PRETTY_PRINT_INDENT
           
 
Constructor Summary
JsonBaseTag()
           
 
Method Summary
protected  java.util.Stack createEntityStack()
          Create a new entity stack and set it in pageContext
protected  boolean entityStackExists()
          Does an entity stack exist?
protected  JsonEntity getCurrentEntity()
          Get the topmost JSONObject or JSONArray from the stack
protected  java.lang.Object getDefaultValue(java.lang.String pParamKey, java.lang.Object pDefaultConstant)
          Get the default value for a parameter.
protected  java.util.Stack getEntityStack()
          Get the JSON object stack.
 boolean getEscapeXml()
          Gets the value of the EscapeXml flag.
 java.lang.Boolean getEscapeXmlDefault()
          Get the default value of the escapeXml property
 java.lang.String getName()
          Gets the Name
 int getPrettyPrintIndentFactor()
          Get the number of spaces that should be used to indent the pretty-printed output, or 0 if no pretty-printing should be used
 boolean getTrim()
          Gets the Trim
protected  boolean isRootTag()
          Is this tag the root json: tag?
protected  void processTagEnd(JsonEntity pNewEntity)
          Process the end of a tag.
protected  void removeEntityStack()
          Remove the entity stack object from page context
protected  void resetEscapeXmlValue()
          Replace the escapeXml value with the original value if this tag modified it
 void setEscapeXml(boolean pEscapeXml)
          Sets the EscapeXml flag.
 void setName(java.lang.String pName)
          Sets the Name
 void setPrettyPrint(boolean pPrettyPrint)
          Sets the PrettyPrint flag.
 void setTrim(boolean pTrim)
          Sets the Trim
protected  java.lang.Object trimAndEscapeValue(java.lang.Object pValue)
          Trim and EscapeXml chars in the value depending on whether the trim and escapeXml attributes have been set
 
Methods inherited from class javax.servlet.jsp.tagext.SimpleTagSupport
doTag, 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
 

Field Detail

PRETTY_PRINT_INDENT

protected static final int PRETTY_PRINT_INDENT
See Also:
Constant Field Values

mName

protected java.lang.String mName

mTrim

protected boolean mTrim

mNewStackCreated

protected boolean mNewStackCreated

mEscapeXmlOriginalValue

protected java.lang.Boolean mEscapeXmlOriginalValue

mEscapeXmlValueSet

protected boolean mEscapeXmlValueSet
Constructor Detail

JsonBaseTag

public JsonBaseTag()
Method Detail

getName

public java.lang.String getName()
Gets the Name

Returns:
the Name

setName

public void setName(java.lang.String pName)
Sets the Name

Parameters:
pName - The Name to set

getTrim

public boolean getTrim()
Gets the Trim

Returns:
the Trim

setTrim

public void setTrim(boolean pTrim)
Sets the Trim

Parameters:
pTrim - The Trim to set

setPrettyPrint

public void setPrettyPrint(boolean pPrettyPrint)
Sets the PrettyPrint flag. If set, then any JSON output should be nicely formatted

Parameters:
pPrettyPrint - The PrettyPrint to set

getPrettyPrintIndentFactor

public int getPrettyPrintIndentFactor()
Get the number of spaces that should be used to indent the pretty-printed output, or 0 if no pretty-printing should be used

Returns:
The number of spaces to indent when pretty printing

getEscapeXml

public boolean getEscapeXml()
Gets the value of the EscapeXml flag. This can be set on any tag by setting the escapeXml attribute to true, or it can be set by setting a page attribute atg.taglib.json.escapeXml. When set on a tag it will recursively apply to all sub-tags, but may be overriden by any sub-tag.
Defaults to true

Returns:
the EscapeXml flag value

setEscapeXml

public void setEscapeXml(boolean pEscapeXml)
Sets the EscapeXml flag. If set, then any output will be xml-escaped

Parameters:
pEscapeXml - The EscapeXml to set

getEscapeXmlDefault

public java.lang.Boolean getEscapeXmlDefault()
Get the default value of the escapeXml property

Returns:
the default escapeXml value

resetEscapeXmlValue

protected void resetEscapeXmlValue()
Replace the escapeXml value with the original value if this tag modified it


getEntityStack

protected java.util.Stack getEntityStack()
                                  throws javax.servlet.jsp.JspException
Get the JSON object stack. This is stored as an attribute in the page context. Request scope is used so that jsp:include can be used to nest json: tags in included pages.

If an entity stack does not exists, then this method will create a new one

Returns:
The JSON Entity Stack
Throws:
javax.servlet.jsp.JspException - If there is a problem creating a new entity stack

createEntityStack

protected java.util.Stack createEntityStack()
                                     throws javax.servlet.jsp.JspException
Create a new entity stack and set it in pageContext

Returns:
The newly created JSON entity statck
Throws:
javax.servlet.jsp.JspException

removeEntityStack

protected void removeEntityStack()
Remove the entity stack object from page context


getCurrentEntity

protected JsonEntity getCurrentEntity()
                               throws javax.servlet.jsp.JspException
Get the topmost JSONObject or JSONArray from the stack

Returns:
the topmost JsonEntity on the stack
Throws:
javax.servlet.jsp.JspException - if unable to get the object stack

entityStackExists

protected boolean entityStackExists()
Does an entity stack exist?

Returns:
true if an entity stack is found in pageContext, false otherwise

isRootTag

protected boolean isRootTag()
Is this tag the root json: tag?

Returns:
true if this tag instance is the root tag, false otherwise

getDefaultValue

protected java.lang.Object getDefaultValue(java.lang.String pParamKey,
                                           java.lang.Object pDefaultConstant)
Get the default value for a parameter. This will search each of the following locations in order, returning the first value that it finds.
  1. page/request/session/application attributes. Uses findAttribute to try and find the attribute
  2. Servlet Context initParams - as set in a web.xml context-param
  3. The Default Constant value passed in to this method

Parameters:
pParamKey - The key of the param.
Returns:

trimAndEscapeValue

protected java.lang.Object trimAndEscapeValue(java.lang.Object pValue)
Trim and EscapeXml chars in the value depending on whether the trim and escapeXml attributes have been set

Parameters:
pValue - The value to trim and xml-escape
Returns:
The processed value

processTagEnd

protected void processTagEnd(JsonEntity pNewEntity)
                      throws javax.servlet.jsp.JspException,
                             JSONException
Process the end of a tag. Check to see if this is the top level tag that created the entity stack, and if so, render the JSON data to the output stream.

Parameters:
pNewEntity - The entity that has just been created by this tag
Throws:
javax.servlet.jsp.JspException
JSONException


Copyright © 2008 Art Technology Group, Inc. (ATG). All Rights Reserved.