org.jrobin.core

Class XmlTemplate

public abstract class XmlTemplate extends Object

Class used as a base class for various XML template related classes. Class provides methods for XML source parsing and XML tree traversing. XML source may have unlimited number of placeholders (variables) in the format ${variable_name}. Methods are provided to specify variable values at runtime. Note that this class has limited functionality: XML source gets parsed, and variable values are collected. You have to extend this class to do something more useful.

Field Summary
protected Elementroot
Constructor Summary
protected XmlTemplate(InputSource xmlSource)
protected XmlTemplate(String xmlString)
protected XmlTemplate(File xmlFile)
Method Summary
voidclearValues()
Removes all placeholder-value mappings.
protected static Node[]getChildNodes(Node parentNode, String childName)
protected static Node[]getChildNodes(Node parentNode)
protected StringgetChildValue(Node parentNode, String childName)
protected StringgetChildValue(Node parentNode, String childName, boolean trim)
protected booleangetChildValueAsBoolean(Node parentNode, String childName)
protected doublegetChildValueAsDouble(Node parentNode, String childName)
protected intgetChildValueAsInt(Node parentNode, String childName)
protected longgetChildValueAsLong(Node parentNode, String childName)
protected static NodegetFirstChildNode(Node parentNode, String childName)
protected StringgetValue(Node parentNode)
protected StringgetValue(Node parentNode, boolean trim)
protected booleangetValueAsBoolean(Node parentNode)
protected PaintgetValueAsColor(Node parentNode)
protected doublegetValueAsDouble(Node parentNode)
protected intgetValueAsInt(Node parentNode)
protected longgetValueAsLong(Node parentNode)
String[]getVariables()
Returns the list of variables that should be set in this template.
protected booleanhasChildNode(Node parentNode, String childName)
booleanhasVariables()
Searches the XML template to see if there are variables in there that will need to be set.
protected booleanisEmptyNode(Node node)
voidsetVariable(String name, String value)
Sets value for a single XML template variable.
voidsetVariable(String name, int value)
Sets value for a single XML template variable.
voidsetVariable(String name, long value)
Sets value for a single XML template variable.
voidsetVariable(String name, double value)
Sets value for a single XML template variable.
voidsetVariable(String name, Color value)
Sets value for a single XML template variable.
voidsetVariable(String name, Date value)
Sets value for a single XML template variable.
voidsetVariable(String name, Calendar value)
Sets value for a single XML template variable.
voidsetVariable(String name, boolean value)
Sets value for a single XML template variable.
protected voidvalidateTagsOnlyOnce(Node parentNode, String[] allowedChildNames)

Field Detail

root

protected Element root

Constructor Detail

XmlTemplate

protected XmlTemplate(InputSource xmlSource)

XmlTemplate

protected XmlTemplate(String xmlString)

XmlTemplate

protected XmlTemplate(File xmlFile)

Method Detail

clearValues

public void clearValues()
Removes all placeholder-value mappings.

getChildNodes

protected static Node[] getChildNodes(Node parentNode, String childName)

getChildNodes

protected static Node[] getChildNodes(Node parentNode)

getChildValue

protected String getChildValue(Node parentNode, String childName)

getChildValue

protected String getChildValue(Node parentNode, String childName, boolean trim)

getChildValueAsBoolean

protected boolean getChildValueAsBoolean(Node parentNode, String childName)

getChildValueAsDouble

protected double getChildValueAsDouble(Node parentNode, String childName)

getChildValueAsInt

protected int getChildValueAsInt(Node parentNode, String childName)

getChildValueAsLong

protected long getChildValueAsLong(Node parentNode, String childName)

getFirstChildNode

protected static Node getFirstChildNode(Node parentNode, String childName)

getValue

protected String getValue(Node parentNode)

getValue

protected String getValue(Node parentNode, boolean trim)

getValueAsBoolean

protected boolean getValueAsBoolean(Node parentNode)

getValueAsColor

protected Paint getValueAsColor(Node parentNode)

getValueAsDouble

protected double getValueAsDouble(Node parentNode)

getValueAsInt

protected int getValueAsInt(Node parentNode)

getValueAsLong

protected long getValueAsLong(Node parentNode)

getVariables

public String[] getVariables()
Returns the list of variables that should be set in this template.

Returns: List of variable names as an array of strings.

hasChildNode

protected boolean hasChildNode(Node parentNode, String childName)

hasVariables

public boolean hasVariables()
Searches the XML template to see if there are variables in there that will need to be set.

Returns: True if variables were detected, false if not.

isEmptyNode

protected boolean isEmptyNode(Node node)

setVariable

public void setVariable(String name, String value)
Sets value for a single XML template variable. Variable name should be specified without leading '${' and ending '}' placeholder markers. For example, for a placeholder ${start}, specify start for the name parameter.

Parameters: name variable name value value to be set in the XML template

setVariable

public void setVariable(String name, int value)
Sets value for a single XML template variable. Variable name should be specified without leading '${' and ending '}' placeholder markers. For example, for a placeholder ${start}, specify start for the name parameter.

Parameters: name variable name value value to be set in the XML template

setVariable

public void setVariable(String name, long value)
Sets value for a single XML template variable. Variable name should be specified without leading '${' and ending '}' placeholder markers. For example, for a placeholder ${start}, specify start for the name parameter.

Parameters: name variable name value value to be set in the XML template

setVariable

public void setVariable(String name, double value)
Sets value for a single XML template variable. Variable name should be specified without leading '${' and ending '}' placeholder markers. For example, for a placeholder ${start}, specify start for the name parameter.

Parameters: name variable name value value to be set in the XML template

setVariable

public void setVariable(String name, Color value)
Sets value for a single XML template variable. Variable name should be specified without leading '${' and ending '}' placeholder markers. For example, for a placeholder ${start}, specify start for the name parameter.

Parameters: name variable name value value to be set in the XML template

setVariable

public void setVariable(String name, Date value)
Sets value for a single XML template variable. Variable name should be specified without leading '${' and ending '}' placeholder markers. For example, for a placeholder ${start}, specify start for the name parameter.

Parameters: name variable name value value to be set in the XML template

setVariable

public void setVariable(String name, Calendar value)
Sets value for a single XML template variable. Variable name should be specified without leading '${' and ending '}' placeholder markers. For example, for a placeholder ${start}, specify start for the name parameter.

Parameters: name variable name value value to be set in the XML template

setVariable

public void setVariable(String name, boolean value)
Sets value for a single XML template variable. Variable name should be specified without leading '${' and ending '}' placeholder markers. For example, for a placeholder ${start}, specify start for the name parameter.

Parameters: name variable name value value to be set in the XML template

validateTagsOnlyOnce

protected void validateTagsOnlyOnce(Node parentNode, String[] allowedChildNames)