All Packages Class Hierarchy This Package Previous Next Index
Class com.openly.dt.JSText
com.openly.dt.EncodingDynamicTag | +----com.openly.dt.JSText
- public class JSText
- extends com.openly.dt.EncodingDynamicTag
JSText is sort of a light-weight version of JSP. Instances of this object load the page denoted by the URI parameter of the constructor. Notice the toString Method that takes a Param table as a parameter. To use this object,- you first have to make a JSText object initialized with a template. There are several ways to do this.
- pass a template name through the constructor. the name will be resolved considering templateRoot and root
- call loadTemplate(templateName) before use. the name will be resolved considering templateRoot and root
- call loadTemplateURI(templateURI) before use. the URI will be resolved without considering templateRoot and root
- call setTemplate(template) before use. the template will be set directly
- use the dynamic tag methods, getValue or writeValue. the param passed in these methods will be used as the template name. the name will be resolved considering templateRoot and root
- Pass a URI for the template through the constructor.
- Call the getValue method with a Params object which includes the incoming params
syntax of the JSText: - [[param]] gets substituted with the value of the param
- [[%param]] gets substituted with the URLEncoded value of the param
- [[¶m]] gets substituted with the XML escaped value of the param
- [[@classname(string)]] gets substituted with the value result of classname.getValue(string,the hashtable).classname must implement the DynamicTag interface. string may contain dynamic tags if properly nested.
- [[[[anything gets substituted with [[anything
- some commonly used dynamic tags have aliases:
[[@if(test param, value if true, value if false)]] is short for [[@com.openly.dt.ConditionalText(test param, value if true, value if false)]] [[@template(template URI)]] is short for [[@com.openly.dt.JSText(template URI)]] [[@comment(comment text)]] is short for [[@com.openly.dt.Comment(comment text)]] [[@repeat(comment text)]] is short for [[@com.openly.dt.Repeat(comment text)]]
WARNING JSText looks for templates in a place set using the static method setTemplateRoot. Since this is static, multiple programs using JSText on a machine must use the same root directory. To avoid this snag, use Params objects that implement Rooted
Changes
- 2000-10-5 when the template file can't be found, helpful text is now returned
- 2000-10-5 JSText now has a concept of a root directory for templates
- 2000-10-15 JSText can now be used by setting a template directly
- 2000-11-6 fixed bug when first character of templat is "["
- 2000-11-8 moved to com.openly.dt package; now looks for close paren from end; sb is now an OutputStream; getValue flushes
- 2000-12-6 added XML escaping
- 2001-1-26 no longer using StringBufferOutputStream out of concern for the extra memory needed to keep a stringbuffer around when streaming a result
- 2001-2-8 added aliases for commonly used dynamic tags
- 2001-2-16 added shortcut for comment; eliminated ready(); added setRoot and support for Rooted params; added flush()
- 2001-3-6 seems to work!
- 2001-3-12 documentation bug - "%" is the encoding switch, not "#".
- 2001-3-13 added protected method getTemplate
- 2001-3-21 fixed endless loop in writevalue
- 2001-5-2 because of a bug in Tomcat, changed append() to check for blank strings -mp
- 2001-6-19 nested tags now allowed;
- 2001-6-21 added alias for repeat;
- 2001-7-27 defaultTemplateRoot is no longer ignored in Rooted;
- 2001-9-18 defaultTemplateRoot is again ignored in Rooted;
- 2001-11-1 nested tags were being treated to a depth of only 1; new tag parsing code should work for arbitary depth
- 2002-2-18 this class now extends EncodingDynamicTag; to support encoding, Params are now passed to append() method
- 2002-3-12 it now works to encode or escape a dynamic tag call for example [[&@if(x,x)]] escapes the result of the if tag.
Check out Java and Linking related books at Openly.com! - See Also:
- com.openly.dt.DynamicTag, com.openly.dt.ConditionalText, com.openly.dt.Comment, com.openly.dt.Rooted, com.openly.dt.Repeat

-
CLOSE -
-
OPEN -
-
PARAMCLOSE -
-
PARAMOPEN -

-
JSText() -
-
JSText(String) -

-
flush() - flush templates in the cache
-
getValue(Params) -
-
loadTemplate(String) - decides on a URI of a template to open, then calls loadTemplateURI This is done as follows: if root is not null, then root is prepended to temp if root is null, and templateRoot is not null, then templateRoot is prepended to temp if both templateRoot and root are null temp is used as is
-
loadTemplate(String, Params) - this takes a file as param, opens,
-
loadTemplateURI(String) - this takes a file as param, opens,
-
main(String[]) -
-
setRoot(String) - controls where this JSText object looks for templates inside template root.
-
setTemplate(String) - Set the template with a String
-
setTemplateRoot(String) - controls where raw JSText objects look for templates if Root is not set.
-
toString(Params) - same as getValue(params)
-
writeValue(Params, OutputStream) - calls writeValue(params, writer)
-
writeValue(String, Params, OutputStream) - implements the DynamicTag interface! Use this method WHENEVER the result is expected to be large

OPEN public static final java.lang.String OPEN
CLOSE public static final java.lang.String CLOSE
PARAMOPEN public static final java.lang.String PARAMOPEN
PARAMCLOSE public static final java.lang.String PARAMCLOSE

JSText public JSText(java.lang.String templateLocation)
- Parameters:
- templateLocation - path relative to root to retrieve the template
JSText public JSText()

setRoot public void setRoot(java.lang.String root)
- controls where this JSText object looks for templates inside template root.
setTemplateRoot public static void setTemplateRoot(java.lang.String root)
- controls where raw JSText objects look for templates if Root is not set. it's really a default.
WARNINGcan only be set once; be careful about multiple projects using this.
setTemplate public void setTemplate(java.lang.String t)
- Set the template with a String
- Parameters:
- t - the template string
loadTemplateURI public void loadTemplateURI(java.lang.String tempURI)
- this takes a file as param, opens,
- Parameters:
- temp - file to open (as a string)
loadTemplate public void loadTemplate(java.lang.String temp)
- decides on a URI of a template to open, then calls loadTemplateURI This is done as follows: if root is not null, then root is prepended to temp if root is null, and templateRoot is not null, then templateRoot is prepended to temp if both templateRoot and root are null temp is used as is
- Parameters:
- temp - file name to open (as a string)
loadTemplate public void loadTemplate(java.lang.String temp, com.openly.util.Params params)
- this takes a file as param, opens,
- Parameters:
- temp - file to open (as a string)
- params - if it's a Rooted, sets root before calling loadTemplate
getValue public java.lang.String getValue(com.openly.util.Params params)
writeValue public void writeValue(java.lang.String temp, com.openly.util.Params values, java.io.OutputStream writer) throws java.io.IOException
- implements the DynamicTag interface! Use this method WHENEVER the result is expected to be large
- Overrides:
- writeValue in class com.openly.dt.EncodingDynamicTag
flush public void flush()
- flush templates in the cache
writeValue public void writeValue(com.openly.util.Params params, java.io.OutputStream writer) throws java.io.IOException
- calls writeValue(params, writer)
toString public java.lang.String toString(com.openly.util.Params values)
- same as getValue(params)
main public static void main(java.lang.String params[])
All Packages Class Hierarchy This Package Previous Next Index