public class DomVariableExpander extends IdentityForwardingSaxHandler
Usage:
try {
Map<String, String> variables = new Map<>() {{ put("foo", "value"); }};
// for example <element attr="${foo}">${foo}</element>
Element elementWithVariables = ...
Document elementExpanded = DomVariableExpander.expand(
variableStyle, variables, elementWithVariables);
}
catch (VariableNotFoundException e) { .. }
For the syntax of variables, see the DomVariableExpander.VariableSyntax enum.
Variables in the Map passed to the expand method should not have the dollar prefix.
Variable names may contain a-z, A-Z, 0-9, hypen and underscore and are case sensitive.
This class is XML namespace aware.
| Modifier and Type | Class and Description |
|---|---|
static class |
DomVariableExpander.VariableNotFoundException |
static class |
DomVariableExpander.VariableSyntax |
| Modifier and Type | Field and Description |
|---|---|
protected DomVariableExpander.VariableSyntax |
syntax |
protected Map<String,String> |
variables |
destinationHandler| Constructor and Description |
|---|
DomVariableExpander(DomVariableExpander.VariableSyntax syntax,
Map<String,String> variables,
TransformerHandler outputHandler) |
| Modifier and Type | Method and Description |
|---|---|
void |
characters(char[] ch,
int start,
int length) |
static Document |
expand(DomVariableExpander.VariableSyntax syntax,
Map<String,String> variables,
Node prototypeElement) |
void |
startElement(String uri,
String localName,
String el,
Attributes templateAttributes) |
endDocument, endElement, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMappingprotected final DomVariableExpander.VariableSyntax syntax
public DomVariableExpander(DomVariableExpander.VariableSyntax syntax, Map<String,String> variables, TransformerHandler outputHandler)
public void startElement(String uri, String localName, String el, Attributes templateAttributes) throws SAXException
startElement in interface ContentHandlerstartElement in class IdentityForwardingSaxHandlerSAXExceptionpublic void characters(char[] ch,
int start,
int length)
throws SAXException
characters in interface ContentHandlercharacters in class IdentityForwardingSaxHandlerSAXExceptionpublic static Document expand(DomVariableExpander.VariableSyntax syntax, Map<String,String> variables, Node prototypeElement) throws DomVariableExpander.VariableNotFoundException
Copyright © 2003–2018. All rights reserved.