Package org.codehaus.staxmate.out
Class SMOutputElement
java.lang.Object
org.codehaus.staxmate.out.SMOutputtable
org.codehaus.staxmate.out.SMOutputContainer
org.codehaus.staxmate.out.SMOutputElement
- Direct Known Subclasses:
SMBufferedElement
Output class that models an outputtable XML element.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final String
Local name of the element, name without preceding prefix or colon (in namespace mode).protected final SMNamespace
Namespace of this element.protected int
protected SMNamespace
Namespace that was bound as the default namespace in the context where this element gets output.protected int
Number of explicitly bound namespaces parent element has (or for root elements 0).protected static final int
protected static final int
protected static final int
protected static final int
Fields inherited from class org.codehaus.staxmate.out.SMOutputContainer
_context, _firstChild, _lastChild, _parent
Fields inherited from class org.codehaus.staxmate.out.SMOutputtable
_next
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
SMOutputElement
(SMOutputContext ctxt, String localName, SMNamespace ns) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Method called to figure out if we can just output a newly added child, without any buffering.protected void
_childReleased
(SMOutputtable child) Method called by a child, when it is released and neither is or contains any buffered entities.protected void
_forceOutput
(SMOutputContext ctxt) Method similar toSMOutputtable._output(org.codehaus.staxmate.out.SMOutputContext, boolean)
, except that this method will always succeed in doing the output.protected boolean
_output
(SMOutputContext ctxt, boolean canClose) Method called to request that the entity output itself; either as much as it can without closing, or as much as it can if it is to get closed.protected void
Method for indicating illegal call to add attributes, when the underlying stream state prevents addition.protected void
addAttribute
(String localName, byte[] value) Typed Access write method to use for adding attribute with base64-encoded binary value using appropriate default variant (MIME, no linefeeds)final void
addAttribute
(String localName, String value) Convenience method for attributes that do not belong to a namespace (no prefix)void
addAttribute
(SMNamespace ns, String localName, boolean value) Typed Access write method to use for adding attribute with boolean value.addAttribute
(SMNamespace ns, String localName, byte[] value) Typed Access write method to use for adding attribute with base64-encoded binary value using appropriate default variant (MIME, no linefeeds)void
addAttribute
(SMNamespace ns, String localName, int value) Typed Access write method to use for adding attribute with integer value.void
addAttribute
(SMNamespace ns, String localName, long value) Typed Access write method to use for adding attribute with long value.void
addAttribute
(SMNamespace ns, String localName, String value) Method for adding an attribute to this element.protected void
protected void
Method that can be used to get the local name of this elementMethod that can be used to get the namespace of the element.void
getPath
(StringBuilder sb) Method that can be called to get an XPath like description of the relative location of this output node, starting from root.void
linkParent
(SMOutputContainer parent, boolean blocked) void
Method that can be (but never has to) called to force declaration of given namespace for this element, if that is possible (i.e.Methods inherited from class org.codehaus.staxmate.out.SMOutputContainer
_closeAllButLastChild, _closeAndOutputChildren, _forceChildOutput, _linkNewChild, _throwClosed, _throwRelinking, _verifyNamespaceArg, addAndReleaseBuffered, addBuffered, addCData, addCData, addCharacters, addCharacters, addComment, addElement, addElement, addElementWithCharacters, addEntityRef, addProcessingInstruction, addValue, addValue, addValue, addValue, addValue, addValue, createBufferedElement, createBufferedFragment, getContext, getNamespace, getNamespace, getParent, getPath, setIndentation
Methods inherited from class org.codehaus.staxmate.out.SMOutputtable
_linkNext, getNext
-
Field Details
-
OUTPUT_NONE
protected static final int OUTPUT_NONE- See Also:
-
OUTPUT_ATTRS
protected static final int OUTPUT_ATTRS- See Also:
-
OUTPUT_CHILDREN
protected static final int OUTPUT_CHILDREN- See Also:
-
OUTPUT_CLOSED
protected static final int OUTPUT_CLOSED- See Also:
-
_localName
Local name of the element, name without preceding prefix or colon (in namespace mode). In non-namespace mode fully-qualified name. -
_namespace
Namespace of this element.Note: can never be null -- event the default (empty) namespace is presented by a global shared namespace instance.
-
_outputState
protected int _outputState -
_parentDefaultNs
Namespace that was bound as the default namespace in the context where this element gets output. This is generally just stored here to be able to write the end element matching start element, since it'sSMOutputContext
that handles actual namespace binding for output. This is either the default declared namespace of an ancestor element, or if none exists, the default namespace of the root (either the empty namespace, or one found viaNamespaceContext
.Note: can never be null -- event the default (empty) namespace is presented by a global shared namespace instance.
-
_parentNsCount
protected int _parentNsCountNumber of explicitly bound namespaces parent element has (or for root elements 0). Stored forSMOutputContext
during time element is open; needed for closing namespace scopes appropriately.
-
-
Constructor Details
-
SMOutputElement
-
-
Method Details
-
linkParent
- Throws:
XMLStreamException
-
getLocalName
Method that can be used to get the local name of this element -
getNamespace
Method that can be used to get the namespace of the element. Note that the returned value is never null; if no namespace was passed during construction, "no namespace" (SMOutputContext.getEmptyNamespace()
) is used instead.- Returns:
- Namespace of this element.
-
addAttribute
Method for adding an attribute to this element. For regular (non-buffered) output elements, attribute is written right away; for buffered variants output will be postponed until buffered element is completely released (including its ancestors if they are unreleased buffered elements)- Throws:
XMLStreamException
-
addAttribute
Convenience method for attributes that do not belong to a namespace (no prefix)- Throws:
XMLStreamException
-
addAttribute
Typed Access write method to use for adding attribute with boolean value.- Throws:
XMLStreamException
-
addAttribute
Typed Access write method to use for adding attribute with integer value.- Throws:
XMLStreamException
-
addAttribute
Typed Access write method to use for adding attribute with long value.- Throws:
XMLStreamException
-
addAttribute
public SMOutputElement addAttribute(SMNamespace ns, String localName, byte[] value) throws XMLStreamException Typed Access write method to use for adding attribute with base64-encoded binary value using appropriate default variant (MIME, no linefeeds)- Returns:
- This element, to allow call chaining
- Throws:
XMLStreamException
- Since:
- 2.0
-
addAttribute
Typed Access write method to use for adding attribute with base64-encoded binary value using appropriate default variant (MIME, no linefeeds)- Returns:
- This element, to allow call chaining
- Throws:
XMLStreamException
- Since:
- 2.0
-
predeclareNamespace
Method that can be (but never has to) called to force declaration of given namespace for this element, if that is possible (i.e. no binding has been added for the preferred prefix of given namespace). This is usually done as a minor optimization or cosmetic improvement so that child elements need not declare the namespace. Since namespace declarations are otherwise output automatically when and as needed, this method never has to be called (from correctness standpoint), but it may produce more aestethically pleasing and compact output when properly used.Default namespace can often not be pre-declared using this method, because that would change namespace of the element itself if it has no prefix, so method is most often called for namespaces with explicit prefix.
Note: in cases where the given namespace can not be bound to preferred URI, exact behavior is undefined: two possible outcomes are that no namespace declaration is added, or that one with different prefix (but given namespace URI) is added. No error is reported at any rate.
- Throws:
XMLStreamException
- Since:
- 2.0.0
-
_childReleased
Description copied from class:SMOutputContainer
Method called by a child, when it is released and neither is or contains any buffered entities. This should indicate that it can be output unless one of its parents or preceding siblings is buffered. Container is expected to update its own state, and then inform its own parent (if necesary) about release; this may cascade output from parents up the container stack.- Specified by:
_childReleased
in classSMOutputContainer
- Parameters:
child
- Child node that now neither is nor contains any buffered nodes.- Throws:
XMLStreamException
-
_output
Description copied from class:SMOutputtable
Method called to request that the entity output itself; either as much as it can without closing, or as much as it can if it is to get closed. In both cases output can fail or be only a partial one: buffered nodes will not be output at all, and nodes with buffered children can only be partially output.- Specified by:
_output
in classSMOutputContainer
- Parameters:
ctxt
- Output context to use for outputting this node (and its contents)canClose
- If true, indicates that the node can (and should) be fully closed if possible. This (passing true) is usually done when a new sibling is added after a node (element/fragment); if so, current one should be recursively closed. If false, should only try to output as much as can be done without forcing closures.- Returns:
- True if the whole node could be output, ie. neither it nor its children are buffered.
- Throws:
XMLStreamException
-
_forceOutput
Description copied from class:SMOutputtable
Method similar toSMOutputtable._output(org.codehaus.staxmate.out.SMOutputContext, boolean)
, except that this method will always succeed in doing the output. Specifically, it will force all buffered nodes to be unbuffered, and then output.- Specified by:
_forceOutput
in classSMOutputContainer
- Throws:
XMLStreamException
-
_canOutputNewChild
Description copied from class:SMOutputContainer
Method called to figure out if we can just output a newly added child, without any buffering. It will request container to close and output all non-buffered children it has, if any; and indicate whether it was fully succesful or not.- Specified by:
_canOutputNewChild
in classSMOutputContainer
- Returns:
- True if all children (if any) were completely output; false if there was at least one buffered child that couldn't be output.
- Throws:
XMLStreamException
-
getPath
Description copied from class:SMOutputContainer
Method that can be called to get an XPath like description of the relative location of this output node, starting from root. Path will be appended to given StringBuilder.- Specified by:
getPath
in classSMOutputContainer
-
doWriteStartElement
- Throws:
XMLStreamException
-
doWriteEndElement
- Throws:
XMLStreamException
-
_throwClosedForAttrs
protected void _throwClosedForAttrs()Method for indicating illegal call to add attributes, when the underlying stream state prevents addition. -
_throwClosedForNsDecls
protected void _throwClosedForNsDecls()
-