org.apache.shale.clay.config
Class ClayTemplateParser

java.lang.Object
  extended by org.apache.shale.clay.config.ClayTemplateParser
All Implemented Interfaces:
ClayConfigParser

public class ClayTemplateParser
extends Object
implements ClayConfigParser

This class is responsible for loading an HTML template into a graph of ComponentBean's that represents a JSF component tree. It is used by TemplateConfigBean, a subclass of ComponentConfigBean.


Constructor Summary
ClayTemplateParser()
           
 
Method Summary
protected  ComponentBean generateElement(URL templateURL, String templateName)
           Loads the template file and parses it into a composition of metadata that's used by the Clay component.
 Builder getBuilder(Node node)
          Returns the Builder that is assigned the task of converting the html node to a corresponding component metadata used to construct a JSF resource.
 String getCharacterEncoding(URL templateURL)
          Returns the encoding type used to open the templateURL.
 ConfigBean getConfig()
           Returns an object pool for HTML template configuration files.
 void loadConfigFile(URL templateURL, String templateName)
           Loads the templateURL identified by the templateName into a graph of ComponentBean's.
 StringBuffer loadTemplate(URL templateURL)
          Loads the template file respecting the encoding type.
 void setConfig(ConfigBean config)
           Sets an object pool for HTML template configuration files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClayTemplateParser

public ClayTemplateParser()
Method Detail

setConfig

public void setConfig(ConfigBean config)

Sets an object pool for HTML template configuration files.

Specified by:
setConfig in interface ClayConfigParser
Parameters:
config - handler

getConfig

public ConfigBean getConfig()

Returns an object pool for HTML template configuration files.

Specified by:
getConfig in interface ClayConfigParser
Returns:
config handler

loadConfigFile

public void loadConfigFile(URL templateURL,
                           String templateName)
                    throws IOException,
                           SAXException

Loads the templateURL identified by the templateName into a graph of ComponentBean's.

Specified by:
loadConfigFile in interface ClayConfigParser
Parameters:
templateURL - template file
templateName - jsfid
Throws:
SAXException - XML parse error
IOException - XML parse error

generateElement

protected ComponentBean generateElement(URL templateURL,
                                        String templateName)
                                 throws IOException

Loads the template file and parses it into a composition of metadata that's used by the Clay component. This metadata is used to construct a JSF subtree within target view.

Parameters:
templateURL - template file
templateName - jsfid
Returns:
config bean graph holding the template file
Throws:
IOException - loading template file

loadTemplate

public StringBuffer loadTemplate(URL templateURL)
                          throws IOException

Loads the template file respecting the encoding type. The file encoding type is determined by calling the getCharacterEncoding() method.

Parameters:
templateURL - target template to load
Returns:
content of the template
Throws:
IOException - error loading the template

getCharacterEncoding

public String getCharacterEncoding(URL templateURL)
                            throws IOException

Returns the encoding type used to open the templateURL. The template encoding type is resolved using three overrides. The first step is to look in the target template for a comment token that defines the charset. The first 512 chars of the templateURL are read and scanned for a special comment token.

For example: <-- ### clay:page charset="UTF-8" /### -->

If the Clay page directive is not found, the next override is an initialization parameter in the web.xml. The value of this parameter is a global override for all templates.

For example:
<context-param>
  <param-name>org.apache.shale.clay.HTML_TEMPLATE_CHARSET </param-name>
  <param-value>UTF-8</param-value>
</context-param>

Otherwise, the defaut is the VM's "file.encoding" system parameter.

Parameters:
templateURL - template URL
Returns:
charset encoding used to read the template
Throws:
IOException - unable to read the template document

getBuilder

public Builder getBuilder(Node node)

Returns the Builder that is assigned the task of converting the html node to a corresponding component metadata used to construct a JSF resource.

Parameters:
node - markup node
Returns:
builder that maps markup to config beans


Copyright © 2004-2007 Apache Software Foundation. All Rights Reserved.