net.sf.saxon.event

Class StartTagBuffer

public class StartTagBuffer extends ProxyReceiver implements NamespaceResolver

StartTagBuffer is a ProxyReceiver that buffers attributes and namespace events within a start tag. It maintains details of the namespace context, and a full set of attribute information, on behalf of other filters that need access to namespace information or need to process attributes in arbitrary order.

StartTagBuffer also implements namespace fixup (the process of creating namespace nodes|bindings on behalf of constructed element and attribute nodes). Although this would be done anyway, further down the pipeline, it has to be done early in the case of a validating pipeline, because the namespace bindings must be created before any namespace-sensitive attribute content is validated.

The StartTagBuffer also allows error conditions to be buffered. This is because the XSIAttributeHandler validates attributes such as xsi:type and xsi:nil before attempting to match its parent element against a particle of its containing type. It is possible that the parent element will match a wildcard particle with processContents="skip", in which case an invalid xsi:type or xsi:nil attribute is not an error.

Field Summary
AttributeCollectionImplbufferedAttributes
intelementLocationId
intelementNameCode
intelementProperties
intelementTypeCode
LocationProviderinputLocationProvider
Method Summary
voidattribute(int nameCode, int typeCode, CharSequence value, int locationId, int properties)
Notify an attribute.
protected voiddeclareAllNamespaces()
protected voiddeclareNamespacesForStartElement()
voidendDocument()
Notify the end of a document node
voidendElement()
endElement: Discard the namespaces declared on this element.
AttributeCollectiongetAllAttributes()
Get all the attributes on the current element start tag
StringgetAttribute(int nameCode)
Get the value of the current attribute with a given nameCode
intgetElementNameCode()
Get the name of the current element
NodeInfogetElementNode()
Get an element node representing the element whose start tag this is, as required for implementing conditional type assignment
int[]getLocalNamespaces()
protected shortgetURICode(short prefixCode)
Get the URI code corresponding to a given prefix code, by searching the in-scope namespaces.
StringgetURIForPrefix(String prefix, boolean useDefault)
Get the namespace URI corresponding to a given prefix.
booleanhasAttributes()
Determine if the current element has any attributes
IteratoriteratePrefixes()
Get an iterator over all the prefixes declared in this namespace context.
voidnamespace(int namespaceCode, int properties)
voidsetPipelineConfiguration(PipelineConfiguration pipe)
Set the pipeline configuration
voidstartContent()
startContent: Add any namespace undeclarations needed to stop namespaces being inherited from parent elements
voidstartDocument(int properties)
Start of a document node.
voidstartElement(int nameCode, int typeCode, int locationId, int properties)
startElement
protected voidundeclareNamespacesForElement()

Field Detail

bufferedAttributes

AttributeCollectionImpl bufferedAttributes

elementLocationId

int elementLocationId

elementNameCode

int elementNameCode

elementProperties

int elementProperties

elementTypeCode

int elementTypeCode

inputLocationProvider

LocationProvider inputLocationProvider

Method Detail

attribute

public void attribute(int nameCode, int typeCode, CharSequence value, int locationId, int properties)
Notify an attribute. Attributes are notified after the startElement event, and before any children. Namespaces and attributes may be intermingled.

Parameters: nameCode The name of the attribute, as held in the name pool typeCode The type of the attribute, as held in the name pool properties Bit significant value. The following bits are defined:

DISABLE_ESCAPING
Disable escaping for this attribute
NO_SPECIAL_CHARACTERS
Attribute value contains no special characters

Throws: IllegalStateException: attempt to output an attribute when there is no open element start tag

declareAllNamespaces

protected void declareAllNamespaces()

declareNamespacesForStartElement

protected void declareNamespacesForStartElement()

endDocument

public void endDocument()
Notify the end of a document node

endElement

public void endElement()
endElement: Discard the namespaces declared on this element.

getAllAttributes

public AttributeCollection getAllAttributes()
Get all the attributes on the current element start tag

Returns: an AttributeCollection containing all the attributes

getAttribute

public String getAttribute(int nameCode)
Get the value of the current attribute with a given nameCode

Parameters: nameCode the name of the required attribute

Returns: the attribute value, or null if the attribute is not present

getElementNameCode

public int getElementNameCode()
Get the name of the current element

Returns: the namepool namecode of the element

getElementNode

public NodeInfo getElementNode()
Get an element node representing the element whose start tag this is, as required for implementing conditional type assignment

Returns: an element node. This contains all the required namespaces and attributes, and has no children; it is untyped, as are the attributes.

getLocalNamespaces

public int[] getLocalNamespaces()

getURICode

protected short getURICode(short prefixCode)
Get the URI code corresponding to a given prefix code, by searching the in-scope namespaces. This is a service provided to subclasses.

Parameters: prefixCode the 16-bit prefix code required

Returns: the 16-bit URI code, or -1 if the prefix is not bound to any namespace

getURIForPrefix

public String getURIForPrefix(String prefix, boolean useDefault)
Get the namespace URI corresponding to a given prefix. Return null if the prefix is not in scope.

Parameters: prefix the namespace prefix useDefault true if the default namespace is to be used when the prefix is ""

Returns: the uri for the namespace, or null if the prefix is not in scope

hasAttributes

public boolean hasAttributes()
Determine if the current element has any attributes

Returns: true if the element has one or more attributes

iteratePrefixes

public Iterator iteratePrefixes()
Get an iterator over all the prefixes declared in this namespace context. This will include the default namespace (prefix="") and the XML namespace where appropriate

namespace

public void namespace(int namespaceCode, int properties)

setPipelineConfiguration

public void setPipelineConfiguration(PipelineConfiguration pipe)
Set the pipeline configuration

Parameters: pipe the pipeline configuration

startContent

public void startContent()
startContent: Add any namespace undeclarations needed to stop namespaces being inherited from parent elements

startDocument

public void startDocument(int properties)
Start of a document node.

startElement

public void startElement(int nameCode, int typeCode, int locationId, int properties)
startElement

undeclareNamespacesForElement

protected void undeclareNamespacesForElement()