org.formaria.template
Class XmlTemplateProcessor

java.lang.Object
  extended by org.formaria.template.TemplateProcessor
      extended by org.formaria.template.XmlTemplateProcessor

public class XmlTemplateProcessor
extends TemplateProcessor

A template processor for parameterized XML files.

Individual elements can be excludes/included in the copy of the template file by adding the 'te_include' attribute to those elements. The attribute value is then used to query the template engine's includes method. The method's return value dictates whether or not the element is included.

A <Repeat> element can be included so that elements can be repeated. The element is repeated while the while attribute evaluates to true. The same evaluation mechansim as is used within Aria's page is employed and the TemplateEngine's subclasses can implement the callback methods. As each item is included the loop counter is processed and this value can be used with expressoions as the value {N}. Each attribute is evaluated so that the necessary substitutions can be made. This a field name by be coded as name="addressEdit{N}" such that the name is different for each element included.

Copyright (c) Formaria Ltd., 2008, This software is licensed under the GNU Public License (GPL), please see license.txt for more details. If you make commercial use of this software you must purchase a commercial license from formaria.

$Revision: 1.6 $


Field Summary
 
Fields inherited from class org.formaria.template.TemplateProcessor
APPLY_RESOURCE, COPY_FILE, currentProject, engine, PROCESSING_INSTRUCTION, RENAME_ELEMENT, RENAME_FILE, sourceFile, sourceFileName, targetFile, targetFileName
 
Constructor Summary
XmlTemplateProcessor(Project proj, TemplateEngine te)
           
 
Method Summary
protected  boolean copyResources(XmlElement xe)
          Attempt to copy the resources specified in XML template
protected  boolean excludeElements(XmlElement xe)
          Exclude those elements that are marked as being optional.
protected  boolean includeElements(XmlElement xe)
          Include the xml fragements referenced by the include elements
protected  boolean insertAttribute(XmlElement xe)
          Sustitute any content, field values etc described in the template
protected  boolean loadFile()
          Read the XML template
 boolean process(java.lang.String sourceName, java.lang.String targetName, int processingType)
           
protected  boolean repeatElements(XmlElement parent, XmlElement xe)
          Repeat those elements that are within a repeat element.
protected  boolean saveFile()
          Save the XML template
 
Methods inherited from class org.formaria.template.TemplateProcessor
copyFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlTemplateProcessor

public XmlTemplateProcessor(Project proj,
                            TemplateEngine te)
Method Detail

process

public boolean process(java.lang.String sourceName,
                       java.lang.String targetName,
                       int processingType)
Overrides:
process in class TemplateProcessor

loadFile

protected boolean loadFile()
Read the XML template

Returns:
true if the processing completed successfully, otherwise false is returned

saveFile

protected boolean saveFile()
Save the XML template

Returns:
true if the processing completed successfully, otherwise false is returned

includeElements

protected boolean includeElements(XmlElement xe)
Include the xml fragements referenced by the include elements

Parameters:
xe - the element being processed
Returns:
true if the processing completed successfully, otherwise false is returned

excludeElements

protected boolean excludeElements(XmlElement xe)
Exclude those elements that are marked as being optional. Calls back to the isIncluded method of the template engine

Parameters:
xe - the element being processed
Returns:
true if the processing completed successfully, otherwise false is returned

repeatElements

protected boolean repeatElements(XmlElement parent,
                                 XmlElement xe)
Repeat those elements that are within a repeat element. The while clause of the repeat element is used to determine the number of times the element is repeated. When done, the repeat element is removed.

Parameters:
parent - the parent of the element being processed
xe - the element being processed
Returns:
true if the processing completed successfully, otherwise false is returned

insertAttribute

protected boolean insertAttribute(XmlElement xe)
Sustitute any content, field values etc described in the template

Parameters:
xe - the element being processed
Returns:
true if the processing completed successfully, otherwise false is returned

copyResources

protected boolean copyResources(XmlElement xe)
Attempt to copy the resources specified in XML template

Parameters:
xe - the element being processed
Returns:
true if the processing completed successfully, otherwise false is returned