Class DigesterDefinitionsReader
- java.lang.Object
-
- org.apache.tiles.definition.digester.DigesterDefinitionsReader
-
- All Implemented Interfaces:
DefinitionsReader
- Direct Known Subclasses:
CompatibilityDigesterDefinitionsReader
public class DigesterDefinitionsReader extends java.lang.Object implements DefinitionsReader
ReadsDefinitionobjects from an XML InputStream using Digester.This
DefinitionsReaderimplementation expects the source to be passed as anInputStream. It parses XML data from the source and builds a Map of Definition objects.The Digester object can be configured by passing in initialization parameters. Currently the only parameter that is supported is the
validatingparameter. This value is set tofalseby default. To enable DTD validation for XML Definition files, give the init method a parameter with a key oforg.apache.tiles.definition.digester.DigesterDefinitionsReader.PARSER_VALIDATEand a value of"true".The Definition objects are stored internally in a Map. The Map is stored as an instance variable rather than a local variable in the
readmethod. This means that instances of this class are not thread-safe and access by multiple threads must be synchronized.- Version:
- $Rev: 990237 $ $Date: 2010-08-28 05:33:35 +1000 (Sat, 28 Aug 2010) $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classDigesterDefinitionsReader.AddNestedDefinitionRuleDigester rule to manage assignment of a nested definition in an attribute value.static classDigesterDefinitionsReader.FillAttributeRuleDigester rule to manage attribute filling.static classDigesterDefinitionsReader.FillDefinitionRuleDigester rule to manage definition filling.static classDigesterDefinitionsReader.PutAttributeRuleDigester rule to manage assignment of the attribute to the parent element.
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringDEFINITION_HANDLER_CLASSThe handler to create definitions.protected org.apache.commons.digester.DigesterdigesterDigesterobject used to read Definition data from the source.protected static java.lang.StringLIST_HANDLER_CLASSThe handler to create list attributes.static java.lang.StringPARSER_VALIDATE_PARAMETER_NAMEDigester validation parameter name.protected static java.lang.StringPUT_ATTRIBUTE_HANDLER_CLASSThe handler to create attributes.protected java.lang.String[]registrationsThe set of public identifiers, and corresponding resource names for the versions of the configuration file DTDs we know about.
-
Constructor Summary
Constructors Constructor Description DigesterDefinitionsReader()Creates a new instance of DigesterDefinitionsReader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDefinition(Definition definition)Adds a newDefinitionto the internal Map or replaces an existing one.protected java.lang.StringgetNextUniqueDefinitionName(java.util.Map<java.lang.String,Definition> definitions)Create a unique definition name usable to store anonymous definitions.protected java.lang.String[]getRegistrations()Returns the registrations for local DTDs.protected voidinitSyntax(org.apache.commons.digester.Digester digester)Initialised the syntax for reading XML files containing Tiles definitions.java.util.Map<java.lang.String,Definition>read(java.lang.Object source)Readsobjects from a source.DefinitionvoidsetValidating(boolean validating)Sets the validation of XML files.
-
-
-
Field Detail
-
PARSER_VALIDATE_PARAMETER_NAME
public static final java.lang.String PARSER_VALIDATE_PARAMETER_NAME
Digester validation parameter name.- See Also:
- Constant Field Values
-
DEFINITION_HANDLER_CLASS
protected static final java.lang.String DEFINITION_HANDLER_CLASS
The handler to create definitions.- Since:
- 2.1.0
-
PUT_ATTRIBUTE_HANDLER_CLASS
protected static final java.lang.String PUT_ATTRIBUTE_HANDLER_CLASS
The handler to create attributes.- Since:
- 2.1.0
-
LIST_HANDLER_CLASS
protected static final java.lang.String LIST_HANDLER_CLASS
The handler to create list attributes.- Since:
- 2.1.0
-
digester
protected org.apache.commons.digester.Digester digester
Digesterobject used to read Definition data from the source.
-
registrations
protected java.lang.String[] registrations
The set of public identifiers, and corresponding resource names for the versions of the configuration file DTDs we know about. There MUST be an even number of Strings in this list!
-
-
Method Detail
-
setValidating
public void setValidating(boolean validating)
Sets the validation of XML files.- Parameters:
validating-truemeans that XML validation is turned on.falseotherwise.- Since:
- 3.3.0
-
read
public java.util.Map<java.lang.String,Definition> read(java.lang.Object source)
Readsobjects from a source. Implementations should publish what type of source object is expected.Definition- Specified by:
readin interfaceDefinitionsReader- Parameters:
source- TheInputStreamsource from which definitions will be read.- Returns:
- a Map of
Definitionobjects read from the source. - Throws:
DefinitionsFactoryException- If the source is invalid or an error occurs when reading definitions.
-
initSyntax
protected void initSyntax(org.apache.commons.digester.Digester digester)
Initialised the syntax for reading XML files containing Tiles definitions.- Parameters:
digester- The digester to initialize.
-
addDefinition
public void addDefinition(Definition definition)
Adds a newDefinitionto the internal Map or replaces an existing one.- Parameters:
definition- The Definition object to be added.
-
getRegistrations
protected java.lang.String[] getRegistrations()
Returns the registrations for local DTDs.- Returns:
- An array containing the locations for registrations of local DTDs.
- Since:
- 2.1.0
-
getNextUniqueDefinitionName
protected java.lang.String getNextUniqueDefinitionName(java.util.Map<java.lang.String,Definition> definitions)
Create a unique definition name usable to store anonymous definitions.- Parameters:
definitions- The already created definitions.- Returns:
- The unique definition name to be used to store the definition.
- Since:
- 2.1.0
-
-