org.apache.xalan.templates
Class ElemTemplateElement
java.lang.Object
|
+--org.apache.xml.utils.UnImplNode
|
+--org.apache.xalan.templates.ElemTemplateElement
- Direct Known Subclasses:
- DecimalFormatProperties, ElemApplyImport, ElemAttribute, ElemChoose, ElemComment, ElemCopyOf, ElemEmpty, ElemExtensionDecl, ElemExtensionScript, ElemFallback, ElemForEach, ElemIf, ElemMessage, ElemNumber, ElemOtherwise, ElemPI, ElemSort, ElemTemplate, ElemText, ElemTextLiteral, ElemUse, ElemValueOf, ElemVariable, ElemWhen, ElemWithParam, KeyDeclaration, NamespaceAlias, OutputProperties, Stylesheet
- public class ElemTemplateElement
- extends UnImplNode
- implements PrefixResolver, java.io.Serializable, SourceLocator, WhitespaceStrippingElementMatcher
**For advanced use only**
An instance of this class represents an element inside
an xsl:template class. It has a single "execute" method
which is expected to perform the given action on the
result tree.
This class acts like a Element node, and implements the
Element interface, but is not a full implementation
of that interface... it only implements enough for
basic traversal of the tree.
- See Also:
Stylesheet
, Serialized Form
Method Summary |
Node |
appendChild(Node newChild)
Add a child to the child list. |
boolean |
canStripWhiteSpace()
Get information about whether or not whitespace can be stripped. |
int |
compareTo(java.lang.Object o)
Compares this object with the specified object for precedence order. |
void |
compose()
This function is called after everything else has been
recomposed, and allows the template to set remaining
values that may be based on some other property that
depends on recomposition. |
boolean |
containsExcludeResultPrefix(java.lang.String prefix)
Get whether or not the passed URL is contained flagged by
the "extension-element-prefixes" property. |
void |
error(int msg,
java.lang.Object[] args)
Throw a template element runtime error. |
void |
execute(TransformerImpl transformer,
Node sourceNode,
QName mode)
Execute the element's primary function. |
java.lang.String |
getBaseIdentifier()
Return the base identifier. |
NodeList |
getChildNodes()
Return the nodelist (same reference). |
int |
getColumnNumber()
Return the column number where the current document event ends. |
java.util.Vector |
getDeclaredPrefixes()
Return a table that contains all prefixes available
within this element context. |
Node |
getDOMBackPointer()
If this stylesheet was created from a DOM, get the
DOM backpointer that this element originated from. |
Node |
getFirstChild()
Get the first child as a Node. |
ElemTemplateElement |
getFirstChildElem()
Get the first child as a ElemTemplateElement. |
Node |
getLastChild()
Get the last child. |
int |
getLength()
NodeList method: Count the immediate children of this node |
int |
getLineNumber()
Return the line number where the current document event ends. |
java.lang.String |
getNamespaceForPrefix(java.lang.String prefix)
Given a namespace, get the corrisponding prefix. |
java.lang.String |
getNamespaceForPrefix(java.lang.String prefix,
Node context)
Fullfill the PrefixResolver interface. |
Node |
getNextSibling()
Get the next sibling (as a Node) or return null. |
ElemTemplateElement |
getNextSiblingElem()
Get the next sibling (as a ElemTemplateElement) or return null. |
java.lang.String |
getNodeName()
Return the node name. |
short |
getNodeType()
Get the type of the node. |
Document |
getOwnerDocument()
Get the stylesheet owner. |
ElemTemplateElement |
getParentElem()
Get the parent as an ElemTemplateElement. |
Node |
getParentNode()
Get the parent as a Node. |
java.util.Vector |
getPrefixes()
Return a table that contains all prefixes available
within this element context. |
Node |
getPreviousSibling()
Get the previous sibling (as a Node) or return null. |
java.lang.String |
getPublicId()
Return the public identifier for the current document event. |
Stylesheet |
getStylesheet()
Get the owning stylesheet. |
StylesheetComposed |
getStylesheetComposed()
Get the owning "composed" stylesheet. |
StylesheetRoot |
getStylesheetRoot()
Get the owning root stylesheet. |
java.lang.String |
getSystemId()
Return the system identifier for the current document event. |
java.lang.String |
getTagName()
Return the element name. |
int |
getUid()
Get the UID (document order index). |
boolean |
getXmlSpace()
Get the "xml:space" attribute. |
int |
getXSLToken()
Get an integer representation of the element type. |
boolean |
hasChildNodes()
Tell if there are child nodes. |
boolean |
isCompiledTemplate()
Tell if this template is a compiled template. |
Node |
item(int index)
NodeList method: Return the Nth immediate child of this node, or
null if the index is out of bounds. |
void |
recompose(StylesheetRoot root)
This function is called during recomposition to
control how this element is composed. |
Node |
removeChild(ElemTemplateElement childETE)
Remove a child. |
Node |
replaceChild(Node newChild,
Node oldChild)
Replace the old child with a new child. |
void |
resolvePrefixTables()
Combine the parent's namespaces with this namespace
for fast processing, taking care to reference the
parent's namespace if this namespace adds nothing new. |
void |
runtimeInit(TransformerImpl transformer)
This function will be called on top-level elements
only, just before the transform begins. |
void |
setDOMBackPointer(Node n)
If this stylesheet was created from a DOM, set the
DOM backpointer that this element originated from. |
void |
setLocaterInfo(SourceLocator locator)
Set the location information for this element. |
void |
setPrefixes(NamespaceSupport nsSupport)
From the SAX2 helper class, set the namespace table for
this element. |
void |
setPrefixes(NamespaceSupport nsSupport,
boolean excludeXSLDecl)
Copy the namespace declarations from the NamespaceSupport object. |
void |
setUid(int i)
Set the UID (document order index). |
void |
setXmlSpace(int v)
Set the "xml:space" attribute. |
boolean |
shouldStripWhiteSpace(XPathContext support,
Element targetElement)
Get information about whether or not an element should strip whitespace. |
Methods inherited from class org.apache.xml.utils.UnImplNode |
appendData,
cloneNode,
createAttribute,
createAttributeNS,
createCDATASection,
createComment,
createDocumentFragment,
createElement,
createElementNS,
createEntityReference,
createProcessingInstruction,
createTextNode,
deleteData,
error,
getAttribute,
getAttributeNode,
getAttributeNodeNS,
getAttributeNS,
getAttributes,
getDoctype,
getDocumentElement,
getElementById,
getElementsByTagName,
getElementsByTagNameNS,
getImplementation,
getLocalName,
getNamespaceURI,
getNodeValue,
getOwnerElement,
getPrefix,
getSpecified,
hasAttribute,
hasAttributeNS,
hasAttributes,
importNode,
insertBefore,
insertData,
isSupported,
normalize,
removeAttribute,
removeAttributeNode,
removeAttributeNS,
removeChild,
replaceData,
setAttribute,
setAttributeNode,
setAttributeNodeNS,
setAttributeNS,
setData,
setNodeValue,
setPrefix,
setValue,
splitText,
substringData |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
ElemTemplateElement
public ElemTemplateElement()
- Construct a template element instance.
- Parameters:
transformer
- The XSLT TransformerFactory.stylesheetTree
- The owning stylesheet.name
- The name of the element.atts
- The element attributes.lineNumber
- The line in the XSLT file that the element occurs on.columnNumber
- The column index in the XSLT file that the element occurs on.
isCompiledTemplate
public boolean isCompiledTemplate()
- Tell if this template is a compiled template.
- Returns:
- Boolean flag indicating whether this is a compiled template
getXSLToken
public int getXSLToken()
- Get an integer representation of the element type.
- Returns:
- An integer representation of the element, defined in the
Constants class.
- See Also:
Constants
getNodeName
public java.lang.String getNodeName()
- Return the node name.
- Returns:
- An invalid node name
- Overrides:
- getNodeName in class UnImplNode
runtimeInit
public void runtimeInit(TransformerImpl transformer)
throws TransformerException
- This function will be called on top-level elements
only, just before the transform begins.
- Parameters:
transformer
- The XSLT TransformerFactory.- Throws:
- TransformerException -
execute
public void execute(TransformerImpl transformer,
Node sourceNode,
QName mode)
throws TransformerException
- Execute the element's primary function. Subclasses of this
function may recursivly execute down the element tree.
- Parameters:
transformer
- The XSLT TransformerFactory.sourceNode
- The current context node.mode
- The current mode.- Throws:
- TransformerException - if any checked exception occurs.
getStylesheetComposed
public StylesheetComposed getStylesheetComposed()
- Get the owning "composed" stylesheet. This looks up the
inheritance chain until it calls getStylesheetComposed
on a Stylesheet object, which will Get the owning
aggregated stylesheet, or that stylesheet if it is aggregated.
- Returns:
- the owning "composed" stylesheet.
getStylesheet
public Stylesheet getStylesheet()
- Get the owning stylesheet. This looks up the
inheritance chain until it calls getStylesheet
on a Stylesheet object, which will return itself.
- Returns:
- the owning stylesheet
getStylesheetRoot
public StylesheetRoot getStylesheetRoot()
- Get the owning root stylesheet. This looks up the
inheritance chain until it calls StylesheetRoot
on a Stylesheet object, which will return a reference
to the root stylesheet.
- Returns:
- the owning root stylesheet
recompose
public void recompose(StylesheetRoot root)
throws TransformerException
- This function is called during recomposition to
control how this element is composed.
compose
public void compose()
- This function is called after everything else has been
recomposed, and allows the template to set remaining
values that may be based on some other property that
depends on recomposition.
error
public void error(int msg,
java.lang.Object[] args)
- Throw a template element runtime error. (Note: should we throw a TransformerException instead?)
- Parameters:
msg
- Description of the error that occured.args
- Arguments to be used in the message- Overrides:
- error in class UnImplNode
appendChild
public Node appendChild(Node newChild)
throws DOMException
- Add a child to the child list.
NOTE: This presumes the child did not previously have a parent.
Making that assumption makes this a less expensive operation -- but
requires that if you *do* want to reparent a node, you use removeChild()
first to remove it from its previous context. Failing to do so will
damage the tree.
- Parameters:
newChild
- Child to be added to child list- Returns:
- Child just added to the child list
- Throws:
- DOMException -
- Overrides:
- appendChild in class UnImplNode
hasChildNodes
public boolean hasChildNodes()
- Tell if there are child nodes.
- Returns:
- True if there are child nodes
- Overrides:
- hasChildNodes in class UnImplNode
getNodeType
public short getNodeType()
- Get the type of the node.
- Returns:
- Constant for this node type
- Overrides:
- getNodeType in class UnImplNode
getChildNodes
public NodeList getChildNodes()
- Return the nodelist (same reference).
- Returns:
- The nodelist containing the child nodes (this)
- Overrides:
- getChildNodes in class UnImplNode
removeChild
public Node removeChild(ElemTemplateElement childETE)
throws DOMException
- Remove a child.
ADDED 9/8/200 to support compilation.
TODO: ***** Alternative is "removeMe() from my parent if any"
... which is less well checked, but more convenient in some cases.
Given that we assume only experts are calling this class, it might
be preferable. It's less DOMish, though.
- Parameters:
childETE
- The child to remove. This operation is a no-op
if oldChild is not a child of this node.- Returns:
- the removed child, or null if the specified
node was not a child of this element.
- Throws:
- DOMException -
replaceChild
public Node replaceChild(Node newChild,
Node oldChild)
throws DOMException
- Replace the old child with a new child.
- Parameters:
newChild
- New child to replace witholdChild
- Old child to be replaced- Returns:
- The new child
- Throws:
- DOMException -
- Overrides:
- replaceChild in class UnImplNode
getLength
public int getLength()
- NodeList method: Count the immediate children of this node
- Returns:
- The count of children of this node
- Overrides:
- getLength in class UnImplNode
item
public Node item(int index)
- NodeList method: Return the Nth immediate child of this node, or
null if the index is out of bounds.
- Parameters:
index
- Index of child to find- Returns:
- org.w3c.dom.Node: the child node at given index
- Overrides:
- item in class UnImplNode
getOwnerDocument
public Document getOwnerDocument()
- Get the stylesheet owner.
- Returns:
- The stylesheet owner
- Overrides:
- getOwnerDocument in class UnImplNode
getTagName
public java.lang.String getTagName()
- Return the element name.
- Returns:
- The element name
- Overrides:
- getTagName in class UnImplNode
getBaseIdentifier
public java.lang.String getBaseIdentifier()
- Return the base identifier.
- Specified by:
- getBaseIdentifier in interface PrefixResolver
- Returns:
- The base identifier
getLineNumber
public int getLineNumber()
- Return the line number where the current document event ends.
Note that this is the line position of the first character
after the text associated with the document event.
- Specified by:
- getLineNumber in interface SourceLocator
- Returns:
- The line number, or -1 if none is available.
- See Also:
getColumnNumber()
getColumnNumber
public int getColumnNumber()
- Return the column number where the current document event ends.
Note that this is the column number of the first
character after the text associated with the document
event. The first column in a line is position 1.
- Specified by:
- getColumnNumber in interface SourceLocator
- Returns:
- The column number, or -1 if none is available.
- See Also:
getLineNumber()
getPublicId
public java.lang.String getPublicId()
- Return the public identifier for the current document event.
This will be the public identifier
- Specified by:
- getPublicId in interface SourceLocator
- Returns:
- A string containing the public identifier, or
null if none is available.
- See Also:
getSystemId()
getSystemId
public java.lang.String getSystemId()
- Return the system identifier for the current document event.
If the system identifier is a URL, the parser must resolve it
fully before passing it to the application.
- Specified by:
- getSystemId in interface SourceLocator
- Returns:
- A string containing the system identifier, or null
if none is available.
- See Also:
getPublicId()
setLocaterInfo
public void setLocaterInfo(SourceLocator locator)
- Set the location information for this element.
- Parameters:
locator
- Source Locator with location information for this element
setXmlSpace
public void setXmlSpace(int v)
- Set the "xml:space" attribute.
A text node is preserved if an ancestor element of the text node
has an xml:space attribute with a value of preserve, and
no closer ancestor element has xml:space with a value of default.
- Parameters:
v
- Enumerated value, either Constants.ATTRVAL_PRESERVE
or Constants.ATTRVAL_STRIP.- See Also:
- strip in XSLT Specification,
section-Creating-Text in XSLT Specification
getXmlSpace
public boolean getXmlSpace()
- Get the "xml:space" attribute.
A text node is preserved if an ancestor element of the text node
has an xml:space attribute with a value of preserve, and
no closer ancestor element has xml:space with a value of default.
- Returns:
- The value of the xml:space attribute
- See Also:
- strip in XSLT Specification,
section-Creating-Text in XSLT Specification
getDeclaredPrefixes
public java.util.Vector getDeclaredPrefixes()
- Return a table that contains all prefixes available
within this element context.
- Returns:
- Vector containing the prefixes available within this
element context
setPrefixes
public void setPrefixes(NamespaceSupport nsSupport)
throws TransformerException
- From the SAX2 helper class, set the namespace table for
this element. Take care to call resolveInheritedNamespaceDecls.
after all namespace declarations have been added.
- Parameters:
nsSupport
- non-null reference to NamespaceSupport from
the ContentHandler.- Throws:
- TransformerException -
setPrefixes
public void setPrefixes(NamespaceSupport nsSupport,
boolean excludeXSLDecl)
throws TransformerException
- Copy the namespace declarations from the NamespaceSupport object.
Take care to call resolveInheritedNamespaceDecls.
after all namespace declarations have been added.
- Parameters:
nsSupport
- non-null reference to NamespaceSupport from
the ContentHandler.excludeXSLDecl
- true if XSLT namespaces should be ignored.- Throws:
- TransformerException -
getNamespaceForPrefix
public java.lang.String getNamespaceForPrefix(java.lang.String prefix,
Node context)
- Fullfill the PrefixResolver interface. Calling this for this class
will throw an error.
- Specified by:
- getNamespaceForPrefix in interface PrefixResolver
- Parameters:
prefix
- The prefix to look up, which may be an empty string ("")
for the default Namespace.context
- The node context from which to look up the URI.- Returns:
- null if the error listener does not choose to throw an exception.
getNamespaceForPrefix
public java.lang.String getNamespaceForPrefix(java.lang.String prefix)
- Given a namespace, get the corrisponding prefix.
9/15/00: This had been iteratively examining the m_declaredPrefixes
field for this node and its parents. That makes life difficult for
the compilation experiment, which doesn't have a static vector of
local declarations. Replaced a recursive solution, which permits
easier subclassing/overriding.
- Specified by:
- getNamespaceForPrefix in interface PrefixResolver
- Parameters:
prefix
- non-null reference to prefix string, which should map
to a namespace URL.- Returns:
- The namespace URL that the prefix maps to, or null if no
mapping can be found.
getPrefixes
public java.util.Vector getPrefixes()
- Return a table that contains all prefixes available
within this element context.
- Returns:
- reference to vector of
XMLNSDecl
s, which may be null.
containsExcludeResultPrefix
public boolean containsExcludeResultPrefix(java.lang.String prefix)
- Get whether or not the passed URL is contained flagged by
the "extension-element-prefixes" property. This method is overridden
by
ElemLiteralResult.containsExcludeResultPrefix(java.lang.String)
.
- Parameters:
prefix
- non-null reference to prefix that might be excluded.- Returns:
- true if the prefix should normally be excluded.
- See Also:
- extension-element in XSLT Specification
resolvePrefixTables
public void resolvePrefixTables()
throws TransformerException
- Combine the parent's namespaces with this namespace
for fast processing, taking care to reference the
parent's namespace if this namespace adds nothing new.
(Recursive method, walking the elements depth-first,
processing parents before children).
Note that this method builds m_prefixTable with aliased
namespaces, *not* the original namespaces.
- Throws:
- TransformerException -
setUid
public void setUid(int i)
- Set the UID (document order index).
- Parameters:
kIndex
- Index of this child.
getUid
public int getUid()
- Get the UID (document order index).
- Returns:
- Index of this child
getParentNode
public Node getParentNode()
- Get the parent as a Node.
- Returns:
- This node's parent node
- Overrides:
- getParentNode in class UnImplNode
getParentElem
public ElemTemplateElement getParentElem()
- Get the parent as an ElemTemplateElement.
- Returns:
- This node's parent as an ElemTemplateElement
getNextSibling
public Node getNextSibling()
- Get the next sibling (as a Node) or return null.
- Returns:
- this node's next sibling or null
- Overrides:
- getNextSibling in class UnImplNode
getPreviousSibling
public Node getPreviousSibling()
- Get the previous sibling (as a Node) or return null.
Note that this may be expensive if the parent has many kids;
we accept that price in exchange for avoiding the prev pointer
TODO: If we were sure parents and sibs are always ElemTemplateElements,
we could hit the fields directly rather than thru accessors.
- Returns:
- This node's previous sibling or null
- Overrides:
- getPreviousSibling in class UnImplNode
getNextSiblingElem
public ElemTemplateElement getNextSiblingElem()
- Get the next sibling (as a ElemTemplateElement) or return null.
- Returns:
- This node's next sibling (as a ElemTemplateElement) or null
getFirstChild
public Node getFirstChild()
- Get the first child as a Node.
- Returns:
- This node's first child or null
- Overrides:
- getFirstChild in class UnImplNode
getFirstChildElem
public ElemTemplateElement getFirstChildElem()
- Get the first child as a ElemTemplateElement.
- Returns:
- This node's first child (as a ElemTemplateElement) or null
getLastChild
public Node getLastChild()
- Get the last child.
- Returns:
- This node's last child
- Overrides:
- getLastChild in class UnImplNode
getDOMBackPointer
public Node getDOMBackPointer()
- If this stylesheet was created from a DOM, get the
DOM backpointer that this element originated from.
For tooling use.
- Returns:
- DOM backpointer that this element originated from or null.
setDOMBackPointer
public void setDOMBackPointer(Node n)
- If this stylesheet was created from a DOM, set the
DOM backpointer that this element originated from.
For tooling use.
- Parameters:
n
- DOM backpointer that this element originated from.
compareTo
public int compareTo(java.lang.Object o)
throws java.lang.ClassCastException
- Compares this object with the specified object for precedence order.
The order is determined by the getImportCountComposed() of the containing
composed stylesheet and the getUid() of this element.
Returns a negative integer, zero, or a positive integer as this
object is less than, equal to, or greater than the specified object.
- Parameters:
o
- The object to be compared to this object- Throws:
- java.lang.ClassCastException - if the specified object's
type prevents it from being compared to this Object.
shouldStripWhiteSpace
public boolean shouldStripWhiteSpace(XPathContext support,
Element targetElement)
throws TransformerException
- Get information about whether or not an element should strip whitespace.
- Specified by:
- shouldStripWhiteSpace in interface WhitespaceStrippingElementMatcher
- Parameters:
support
- The XPath runtime state.targetElement
- Element to check- Returns:
- true if the whitespace should be stripped.
- Throws:
- TransformerException -
- See Also:
- strip in XSLT Specification
canStripWhiteSpace
public boolean canStripWhiteSpace()
- Get information about whether or not whitespace can be stripped.
- Specified by:
- canStripWhiteSpace in interface WhitespaceStrippingElementMatcher
- Returns:
- true if the whitespace can be stripped.
- See Also:
- strip in XSLT Specification
Copyright � 2000 Apache XML Project. All Rights Reserved.