com.arsdigita.acs
Class TemplateTranslator

java.lang.Object
  |
  +--com.arsdigita.acs.TemplateTranslator

public class TemplateTranslator
extends java.lang.Object

Translates ATS templates (aka "Karl's Templates") into JSP code. Performs a series of transforms on @...@ substitution, multiple, grid, etc. Handles translation of conditionals (if). handles master/slave, include.


Inner Class Summary
static class TemplateTranslator.IncludeHandler
          Helper class to perform the function of an include tag
static class TemplateTranslator.MasterHandler
          Helper class instantiated to perform the task involved with a master tag.
 
Field Summary
static java.lang.String cvsId
           
static java.lang.String SLAVE_ATTR
          Convenience field; short for "com.arsdigita.acs.TemplateTranslator.slave"
 
Constructor Summary
TemplateTranslator()
          Dummy no-arg public constructor
TemplateTranslator(java.lang.String s, java.lang.String docRoot)
          Creates a new TemplateTranslator with a default global master template.
 
Method Summary
static java.lang.String emptyIfNull(java.lang.Object o)
          A filter used by the translated template JSP.
static java.lang.String getTemplate(javax.servlet.jsp.PageContext pageContext)
          Returns the URL for the .adp template that should be served by the current request.
static void main(java.lang.String[] args)
          Translates the specified template.
 java.lang.String mungeName(java.lang.String baseName)
          Generates a template URL for a translated JSP, given the base name for the template .adp file being translated
 java.lang.String translate(java.io.File inputFile, java.lang.String relativePath)
          Translates the specified template .adp file to a .template.jsp file.
static SeekableSelection vectorToSeekableSelection(java.util.Vector list)
          Wraps an incoming Vector as a SeekableSelection so it looks like a one-column table with the column named "item." This removes some of the asymmetries between <multiple> and <list>.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cvsId

public static final java.lang.String cvsId

SLAVE_ATTR

public static final java.lang.String SLAVE_ATTR
Convenience field; short for "com.arsdigita.acs.TemplateTranslator.slave"
Constructor Detail

TemplateTranslator

public TemplateTranslator()
Dummy no-arg public constructor

TemplateTranslator

public TemplateTranslator(java.lang.String s,
                          java.lang.String docRoot)
Creates a new TemplateTranslator with a default global master template.
Parameters:
s - the default global master template
docRoot - the document root, that is, the directory in the file system where the acs-java-4 webapp is rooted. In Tomcat this will probably be something like /tomcat/webapps/acs-java-4.
Method Detail

getTemplate

public static java.lang.String getTemplate(javax.servlet.jsp.PageContext pageContext)
                                    throws javax.servlet.jsp.JspException
Returns the URL for the .adp template that should be served by the current request.
Parameters:
pageContext - The page context of the calling JSP page. The caller's URL should have already been resolved.

translate

public final java.lang.String translate(java.io.File inputFile,
                                        java.lang.String relativePath)
                                 throws java.io.IOException,
                                        ACSException
Translates the specified template .adp file to a .template.jsp file. See the templating system documentation for more details.
Parameters:
inputFile - the input .adp file to translate
relativePath - the pathname string of the input file, relative to the webapp root (e.g., /packages/key/www/foo.adp). This cannot be determined reliably given only a pathname to an input file and the webapp root separately because of symlinks.
Returns:
the body of the translated jsp file as a String.

main

public static final void main(java.lang.String[] args)
                       throws java.lang.Exception
Translates the specified template. Prints to standard out if only one filename is supplied. If more than one filename is supplied, assumes the first name is the base template target directory without a trailing slash (i.e. $ACS_JAVA/templates) and the rest are templates, and generates output templates in the target directory.

emptyIfNull

public static java.lang.String emptyIfNull(java.lang.Object o)
A filter used by the translated template JSP. Functions as a pass-through before printing objects out, but replaces null objects with an empty string instead of the word "null."
Returns:
An empty string if the parameter is null; or the parameter if not null.

mungeName

public java.lang.String mungeName(java.lang.String baseName)
Generates a template URL for a translated JSP, given the base name for the template .adp file being translated

Example: /path/to/page.jsp or /path/to/page.adp --> /templates/path/to/page.template.jsp

Parameters:
baseName - the resolved template URL to munge, which is a path relative to the webapp root
Returns:
the URL for the translated template

vectorToSeekableSelection

public static SeekableSelection vectorToSeekableSelection(java.util.Vector list)
Wraps an incoming Vector as a SeekableSelection so it looks like a one-column table with the column named "item." This removes some of the asymmetries between <multiple> and <list>. Preserves the incoming ordering.
Parameters:
list - the incoming list
Returns:
the converted SeekableSelection