|
EchoPoint 1.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object echopoint.layout.AbstractLayoutManager echopoint.layout.HtmlTemplateLayoutManager
The HtmlTemplateLayoutManager
class can be used as a layout manager
that will use an HTML template as a basis to render other Components within it.
The generalised form of the template looks something like the following :
<HTML><BODY> Name : <COMPONENT NAME="PERSON"><COMPONENT><BR> Address: <COMPONENT NAME="ADDRESS" ICON="address.gif"><COMPONENT><BR> Phone : <COMPONENT NAME="PHONE"><COMPONENT><BR> </BODY></HTML>
The COMPONENT tags will be subsituted with the real components that has been previously added via the addLayoutComponent() method. The components are matched via the constraint name and the templated attribute name="x".
templateLayout.addLayoutComponent(new TextField("Name"), "PERSON"); templateLayout.addLayoutComponent(new TextField("Address"), "ADDRESS"); templateLayout.addLayoutComponent(new TextField("Phone"), "PHONE");
Note : Components will NOT be created if they have NOT been added to the HtmlTemplateLayoutManager. The template will, by design, fail to render them, but will instead insert garish HTML noting their absence.
You can turn this dire warning off via the setLoudErrorsUsed(false);
Parsing is done via a two pass process. The first pass runs through all the template content and marks the positions of the handled tags.
The second pass will then copy static content up until each remembered tag position. It will then invoke the tag handler that allows the component to generate is content. Then the rest of the static content is copied until another active tag position is reached and so on.
All DataSources have their last modified time checked. If they are up to date then only the second pass parse will be performed, and hence rendering time is reduced.
The content of Files and URLs are cached internally if they are smaller than getFileCacheSizeLimit() and hence will execute very fast the next time they are rendered.
The attributes within the HTML tags are then applied to the Component before it is displayed,
if there is a PropertyManager
available that understands the tag attributes and
they have not already been set.
These attributes are only applied to the contained Components once for a given DataSource. If you use the same DataSource on another HtmlTemplateLayoutManager, then the tag attributes will be set into the components that the new layout manager contains. However a compilation of the DataSource will not occur unless it is out of date.
You can force a explcit compilation to occur before the template is displayed by adding
all components and then calling the compileDataSource
method.
The current list of tags parsed and handled by PropertyManagers are as follows:
All tags have the following attributes which can be used to control the appearance of the Components :
For a full list of attributes handled, see the various PropertyManager class descriptions.
HtmlTemplateLayoutManager supports setting properties of the component via a CSS like style setting :
<component name="comp1" style="background : #ff0000; font : verdana,bold,9; foreground : yellow">
This uses the EchoPoint CSS support to each of the component properties via entries in the style attribute.
It also supports a standalone <stylesheet> tag for setting style sheet information. This might look like this :
<stylesheet> nextapp.echo.Button { font : font(verdana,plain,8); background : #ffddcc; } </stylesheet>
The <stylesheet> trags will be applied before any <component name=".." style="..." /> attributes are performed. This way the most least specific attributes are set first followed by the more specific style="..." values.
For more information on EchoPoint CSS style sheets see :
and @see echopoint.stylesheet.CssStyleSheet.
Radio buttons are handled in a special way, in that their contraint names are
matched using the tag name and value attribute. So if you had a tag :
<input type=radio name="radioB" value="1">
<input type=radio name="radioB" value="2">
Would be matched if you added components such as:
templateLayout.add(new RadionButton("Button Title X"), "radioB1");
templateLayout.add(new RadionButton("Button Title Y"), "radioB2");
ListBox and SelectFields also have special handling. If the OPTION tag
is present within the SELECT tag, then if the ListBox or SelectField does
not contain any options, the the model of the ListBox or SelectField will
be replaced with a default one and the OPTION values will be added to
this new model.
For example :
<SELECT name="list1" >
<OPTION value="Volvo" >
<OPTION value="Ford" >
<OPTION value="Fiat" selected >
</SELECT>
...
templateLayout.add(new ListBox(), "list1");
...
would cause the model of the listbox to be replaced with one
with the values Volvo, Ford and Fiat where Fiat is the selected
value, IF the listbox was created with no options within it.
Whereas the code :
<SELECT name="list1" > </SELECT>
...
or
...
<COMPONENT name="list1" > </COMPONENT>
...
would not replace the model of the ListBox or SelectField.
There is also a "text substitution" facility available. This allows "TEXT" tag
markers to be substituted with varibale values. This will allow dynamic changes
within the template without the "expense" of "Label" component.
So any TEXT tags that look like :
<TEXT name="variableName" > </TEXT>
will be substituted with strings returned from a an object that implements
TextSubstitution
. The provided SimpleTextSubstitution
class implements a simple HashMap mapping of strings to names.
You can of course derived your own TextSubstitution
implementation.
,
Serialized FormField Summary |
Fields inherited from class echopoint.layout.AbstractLayoutManager |
componentMap, layoutManageableWR |
Constructor Summary | |
HtmlTemplateLayoutManager()
Constructs an empty HtmlTemplatePanel with an empty StringDataSource. |
|
HtmlTemplateLayoutManager(java.io.File tmplFile)
Creates a TemplatePanel that reads its template from a File.
|
|
HtmlTemplateLayoutManager(java.io.File tmplFile,
java.lang.String encoding)
Creates a TemplatePanel that reads its template from a File
with the provided character encoding.
|
|
HtmlTemplateLayoutManager(java.lang.String stringTemplate)
Creates a TemplatePanel that reads its template from
the String stringTemplate. |
|
HtmlTemplateLayoutManager(java.net.URL url)
Creates a TemplatePanel that reads its template from an URL.
|
|
HtmlTemplateLayoutManager(java.net.URL url,
java.lang.String encoding)
Creates a TemplatePanel that reads its template from an URL with
the provideded character encoding.
|
Method Summary | |
static void |
addPropertyManager(PropertyManager p)
Adds a PropertyManager to the list of available PropertyManagers. |
CompilationUnit |
compileDataSource()
Compiles a DataSource and returns a CompilationUnit representing the compiled output. |
CompilationContext |
getCompilationContext()
Returns the CompilationContext in use by this HtmlTemplateLayoutManager for the current DataSource. |
nextapp.echo.Component |
getComponent(java.lang.String constraintName)
Retrivews a component based on the contraint name |
DataSource |
getDataSource()
|
int |
getFileCacheSizeLimit()
Returns the maximum size of a cache entry, after which template files will not be internally cached. |
PropertyManager |
getPropertyManager(java.lang.Class clazz)
Called to get a ProperyManagerfor a given clazz of Component |
TextSubstitution |
getTextSubstitution()
Returns the TextSubstitution object used to substitute TEXT tags. |
boolean |
isLoudErrorsUsed()
This returns true if "loud" error messages are to be used during template compilation. |
boolean |
isPropertiesUsed()
Returns whether component properties will be set from the template HTML tag attributes. |
void |
setFileCacheSizeLimit(int newFileCacheSizeLimit)
Sets the maximum size of a cache entry, after which template files will not be internally cached. |
void |
setLoudErrorsUsed(boolean b)
Controls whether loud error messages are to be used during template compilation. |
void |
setPropertiesUsed(boolean flag)
Sets whether component properties will be set from the template HTML tag attributes. |
void |
setTemplate(DataSource source)
Sets the template from the DataSource. |
void |
setTemplate(java.io.File templateFile)
Set the template to the template stored in the given file with the default character encoding. |
void |
setTemplate(java.io.File templateFile,
java.lang.String encoding)
Set the template to the template stored in the given file with the provided character encoding. |
void |
setTemplate(java.lang.String templateString)
Set the template via the string contents of templateString |
void |
setTemplate(java.net.URL templateURL)
Set the template to the template which can be retrieved from the given URL with the default character encoding |
void |
setTemplate(java.net.URL templateURL,
java.lang.String encoding)
Set the template to the template which can be retrieved from the given URL with the provided character encoding |
void |
setTextSubstitution(TextSubstitution newTextSubstitution)
Sets the TextSubstitution object used to substitute TEXT tags. |
Methods inherited from class echopoint.layout.AbstractLayoutManager |
addLayoutComponent, getComponent, getComponentMap, getContraints, getLayoutManageable, invalidateLayout, removeLayoutComponent, setLayoutManageable |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public HtmlTemplateLayoutManager()
HtmlTemplatePanel
with an empty StringDataSource.
public HtmlTemplateLayoutManager(java.io.File tmplFile) throws java.io.IOException
TemplatePanel
that reads its template from a File.
The contents are read once into a cache.
java.io.IOException
public HtmlTemplateLayoutManager(java.io.File tmplFile, java.lang.String encoding) throws java.io.IOException
TemplatePanel
that reads its template from a File
with the provided character encoding.
The contents are read once into a cache.
java.io.IOException
public HtmlTemplateLayoutManager(java.lang.String stringTemplate)
TemplatePanel
that reads its template from
the String stringTemplate.
public HtmlTemplateLayoutManager(java.net.URL url) throws java.io.IOException
TemplatePanel
that reads its template from an URL.
The contents are read once into a cache.
java.io.IOException
public HtmlTemplateLayoutManager(java.net.URL url, java.lang.String encoding) throws java.io.IOException
TemplatePanel
that reads its template from an URL with
the provideded character encoding.
The contents are read once into a cache.
java.io.IOException
Method Detail |
public CompilationUnit compileDataSource() throws java.io.IOException
java.io.IOException
public nextapp.echo.Component getComponent(java.lang.String constraintName)
getComponent
in interface ComponentMapper
public DataSource getDataSource()
public int getFileCacheSizeLimit()
public PropertyManager getPropertyManager(java.lang.Class clazz)
getPropertyManager
in interface PropertyManagerOwner
public TextSubstitution getTextSubstitution()
public boolean isPropertiesUsed()
public void setPropertiesUsed(boolean flag)
flag
- booleanpublic void setFileCacheSizeLimit(int newFileCacheSizeLimit)
newFileCacheSizeLimit
- intpublic void setTemplate(DataSource source)
public void setTemplate(java.io.File templateFile) throws java.io.IOException
java.io.IOException
public void setTemplate(java.io.File templateFile, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public void setTemplate(java.lang.String templateString)
templateString
- public void setTemplate(java.net.URL templateURL) throws java.io.IOException
java.io.IOException
public void setTemplate(java.net.URL templateURL, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public void setTextSubstitution(TextSubstitution newTextSubstitution)
newTextSubstitution
- echopoint.template.TextSubstitutionpublic static final void addPropertyManager(PropertyManager p)
public CompilationContext getCompilationContext()
This method is intended for use between the template compiling mechanism and hence is not for general consumption
public boolean isLoudErrorsUsed()
public void setLoudErrorsUsed(boolean b)
|
EchoPoint 1.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |