public final class SMOutputContext extends Object
Usually the process of outputting XML content with StaxMate starts by
instantiating an SMOutputContext
. It can then be used to create
output fragments; all of which bind to that context. Context is thus
what "connects" various fragments when they are buffered (when there
may or may not be child/parent relationships yet defined).
Context is also used (in addition to storing output relevant settings and acting as a fragment factory) as the owner of various other objects, most notable namespaces. All local namespaces are owned by one and only one context.
Modifier and Type | Field and Description |
---|---|
protected boolean |
_cfgPreferDefaultNs
Configuration flag that specifies whether by default namespaces
should bind as the default namespaces for elements or not.
|
protected boolean |
_cfgRepairing |
protected SMNamespace |
_defaultNS
Currently active default namespace; one that is in effect within
current scope (inside currently open element, if any; if none,
within root level).
|
protected HashMap<String,SMNamespace> |
_localNsMap
Map that contains all local namespaces, that is, namespaces
that have been created for use with documents output using
this context.
|
protected String |
_nsPrefixPrefix
Prefix to use for creating automatic namespace prefixes.
|
protected int |
_nsPrefixSeqNr |
protected NamespaceContext |
_rootNsContext |
protected org.codehaus.stax2.XMLStreamWriter2 |
_streamWriter |
protected static int |
DEF_NS_STACK_SIZE |
protected static SMOTypedValue |
FALSE_VALUE |
protected static SMNamespace |
NS_EMPTY |
protected static SMNamespace |
NS_XML |
protected static SMNamespace |
NS_XMLNS |
protected static HashMap<String,SMNamespace> |
sGlobalNsMap |
protected static SMOTypedValue |
TRUE_VALUE |
Modifier | Constructor and Description |
---|---|
protected |
SMOutputContext(org.codehaus.stax2.XMLStreamWriter2 sw,
NamespaceContext rootNsCtxt) |
Modifier and Type | Method and Description |
---|---|
protected String |
_ensureBindingForAttribute(SMNamespace ns) |
void |
closeWriterCompletely()
Method that can be called to force full closing of the
underlying stream writer as well as output target it
uses (usually a
OutputStream or
Writer ). |
SMOutputtable |
createAttribute(SMNamespace ns,
String localName,
byte[] value) |
SMOutputtable |
createAttribute(SMNamespace ns,
String localName,
int value) |
SMOutputtable |
createAttribute(SMNamespace ns,
String localName,
String value) |
SMBufferedFragment |
createBufferedFragment() |
SMOutputtable |
createCData(char[] buf,
int offset,
int len) |
SMOutputtable |
createCData(String text) |
SMOutputtable |
createCharacters(char[] buf,
int offset,
int len) |
SMOutputtable |
createCharacters(String text) |
SMOutputtable |
createComment(String text) |
SMOutputDocument |
createDocument()
Method used to create a StaxMate output fragment that corresponds
to a single well-formed XML document.
|
SMOutputDocument |
createDocument(String version,
String encoding)
Method used to create a StaxMate output fragment that corresponds
to a single well-formed XML document.
|
SMOutputDocument |
createDocument(String version,
String encoding,
boolean standalone) |
SMOutputtable |
createEntityRef(String name) |
static SMOutputContext |
createInstance(org.codehaus.stax2.XMLStreamWriter2 sw) |
static SMOutputContext |
createInstance(org.codehaus.stax2.XMLStreamWriter2 sw,
NamespaceContext rootNsCtxt) |
SMOutputtable |
createNamespace(SMNamespace ns,
SMNamespace parentDefaultNS,
int parentNsCount)
Method called by
SMOutputElement to add buffered namespace
pre-declaration. |
SMOutputtable |
createNonSharedCData(char[] buf,
int offset,
int len)
Specialized alternative to {link #createCData(char[],int,int)}
that can count on the passed char array NOT being shared.
|
SMOutputtable |
createNonSharedCharacters(char[] buf,
int offset,
int len)
Specialized alternative to {link #createCharacters(char[],int,int)}
that can count on the passed char array NOT being shared.
|
SMOutputtable |
createProcessingInstruction(String target,
String data) |
SMRootFragment |
createRootFragment()
Method to use when outputting an XML sub-tree, in which case the
underlying stream writer may be (or has been) used for outputting
XML content in addition to content that is output using StaxMate.
|
SMOutputtable |
createValue(boolean value) |
SMOutputtable |
createValue(byte[] buffer) |
SMOutputtable |
createValue(byte[] buffer,
int offset,
int length) |
SMOutputtable |
createValue(double value) |
SMOutputtable |
createValue(int value) |
SMOutputtable |
createValue(long value) |
String |
findRootPrefix(SMNamespace ns) |
void |
flushWriter() |
String |
generateUnboundPrefix() |
static SMNamespace |
getEmptyNamespace() |
SMNamespace |
getNamespace(String uri) |
SMNamespace |
getNamespace(String uri,
String prefPrefix) |
org.codehaus.stax2.XMLStreamWriter2 |
getWriter() |
boolean |
isPrefixBound(String prefix) |
boolean |
isPrefixBoundLocally(String prefix,
int parentNsCount)
Similar to
isPrefixBound(java.lang.String) , but only considers bindings
added by the current start element. |
boolean |
isWriterRepairing() |
void |
predeclareNamespace(SMNamespace ns,
SMNamespace parentDefaultNS,
int parentNsCount)
Method called to try to pre-declare given namespace
|
void |
setIndentation(String indentStr,
int startOffset,
int step)
This method can be called to enable or disable heuristic indentation
for the output done using this output context.
|
void |
writeAttribute(SMNamespace ns,
String localName,
byte[] value) |
void |
writeAttribute(SMNamespace ns,
String localName,
int value) |
void |
writeAttribute(SMNamespace ns,
String localName,
String value) |
void |
writeCData(char[] buf,
int offset,
int len) |
void |
writeCData(String text) |
void |
writeCharacters(char[] buf,
int offset,
int len) |
void |
writeCharacters(String text) |
void |
writeComment(String text) |
void |
writeDoctypeDecl(String rootName,
String systemId,
String publicId,
String intSubset) |
void |
writeEndDocument() |
void |
writeEndElement(int parentNsCount,
SMNamespace parentDefNs) |
void |
writeEntityRef(String name) |
void |
writeProcessingInstruction(String target,
String data) |
void |
writeStartDocument() |
void |
writeStartDocument(String version,
String encoding) |
void |
writeStartDocument(String version,
String encoding,
boolean standalone) |
SMNamespace |
writeStartElement(SMNamespace ns,
String localName)
Method called by the element object when it is about to get written
out.
|
void |
writeValue(boolean v) |
void |
writeValue(byte[] data) |
void |
writeValue(byte[] data,
int offset,
int length) |
void |
writeValue(double d) |
void |
writeValue(int v) |
void |
writeValue(long v) |
protected static final int DEF_NS_STACK_SIZE
protected static final SMNamespace NS_EMPTY
protected static final SMNamespace NS_XML
protected static final SMNamespace NS_XMLNS
protected static final HashMap<String,SMNamespace> sGlobalNsMap
protected static final SMOTypedValue FALSE_VALUE
protected static final SMOTypedValue TRUE_VALUE
protected final org.codehaus.stax2.XMLStreamWriter2 _streamWriter
protected final NamespaceContext _rootNsContext
protected final boolean _cfgRepairing
protected String _nsPrefixPrefix
protected int _nsPrefixSeqNr
protected boolean _cfgPreferDefaultNs
protected HashMap<String,SMNamespace> _localNsMap
protected SMNamespace _defaultNS
protected SMOutputContext(org.codehaus.stax2.XMLStreamWriter2 sw, NamespaceContext rootNsCtxt)
public void setIndentation(String indentStr, int startOffset, int step)
Here are some example calls:
context.setIndentation("\n ", 1, 2); // indent by lf and 2 spaces per level context.setIndentation(null, 0, 0); // disable indentation context.setIndentation("\r\n\t\t\t\t\t\t\t\t", 2, 1); // indent by windows lf and 1 tab per level
indentStr
- String to use for indentation; if non-null, will
enable indentation, if null, will disable it. Used in conjunction
with the other argumentsstartOffset
- Initial character offset for the first level of
indentation (current context; usually root context): basically,
number of leading characters from indentStr
to
output.step
- Number of characters to add from the indentation
String for each new level (and to subtract when closing levels).public static SMOutputContext createInstance(org.codehaus.stax2.XMLStreamWriter2 sw, NamespaceContext rootNsCtxt) throws XMLStreamException
XMLStreamException
public static SMOutputContext createInstance(org.codehaus.stax2.XMLStreamWriter2 sw) throws XMLStreamException
XMLStreamException
public SMOutputDocument createDocument() throws XMLStreamException
This version of the method calls the matching no-arguments method in the stream writer.
XMLStreamException
public SMOutputDocument createDocument(String version, String encoding) throws XMLStreamException
This version of the method calls the matching stream writer method which takes full xml declaration information.
XMLStreamException
public SMOutputDocument createDocument(String version, String encoding, boolean standalone) throws XMLStreamException
XMLStreamException
public SMRootFragment createRootFragment() throws XMLStreamException
XMLStreamException
public SMBufferedFragment createBufferedFragment() throws XMLStreamException
XMLStreamException
public SMOutputtable createAttribute(SMNamespace ns, String localName, String value)
public SMOutputtable createAttribute(SMNamespace ns, String localName, int value)
public SMOutputtable createAttribute(SMNamespace ns, String localName, byte[] value)
public SMOutputtable createNamespace(SMNamespace ns, SMNamespace parentDefaultNS, int parentNsCount)
SMOutputElement
to add buffered namespace
pre-declaration.public SMOutputtable createCharacters(String text)
public SMOutputtable createCharacters(char[] buf, int offset, int len)
public SMOutputtable createNonSharedCharacters(char[] buf, int offset, int len)
public SMOutputtable createCData(String text)
public SMOutputtable createCData(char[] buf, int offset, int len)
public SMOutputtable createNonSharedCData(char[] buf, int offset, int len)
public SMOutputtable createComment(String text)
public SMOutputtable createEntityRef(String name)
public SMOutputtable createProcessingInstruction(String target, String data)
public SMOutputtable createValue(boolean value)
public SMOutputtable createValue(int value)
public SMOutputtable createValue(long value)
public SMOutputtable createValue(double value)
public SMOutputtable createValue(byte[] buffer)
public SMOutputtable createValue(byte[] buffer, int offset, int length)
public final SMNamespace getNamespace(String uri)
public final SMNamespace getNamespace(String uri, String prefPrefix)
public static final SMNamespace getEmptyNamespace()
public final org.codehaus.stax2.XMLStreamWriter2 getWriter()
public final boolean isWriterRepairing()
public void writeCharacters(String text) throws XMLStreamException
XMLStreamException
public void writeCharacters(char[] buf, int offset, int len) throws XMLStreamException
XMLStreamException
public void writeCData(String text) throws XMLStreamException
XMLStreamException
public void writeCData(char[] buf, int offset, int len) throws XMLStreamException
XMLStreamException
public void writeComment(String text) throws XMLStreamException
XMLStreamException
public void writeEntityRef(String name) throws XMLStreamException
XMLStreamException
public void writeProcessingInstruction(String target, String data) throws XMLStreamException
XMLStreamException
public void writeAttribute(SMNamespace ns, String localName, String value) throws XMLStreamException
XMLStreamException
public void writeAttribute(SMNamespace ns, String localName, int value) throws XMLStreamException
XMLStreamException
public void writeAttribute(SMNamespace ns, String localName, byte[] value) throws XMLStreamException
XMLStreamException
protected String _ensureBindingForAttribute(SMNamespace ns) throws XMLStreamException
XMLStreamException
public void predeclareNamespace(SMNamespace ns, SMNamespace parentDefaultNS, int parentNsCount) throws XMLStreamException
XMLStreamException
public SMNamespace writeStartElement(SMNamespace ns, String localName) throws XMLStreamException
XMLStreamException
public void writeEndElement(int parentNsCount, SMNamespace parentDefNs) throws XMLStreamException
XMLStreamException
public void writeStartDocument() throws XMLStreamException
XMLStreamException
public void writeStartDocument(String version, String encoding) throws XMLStreamException
XMLStreamException
public void writeStartDocument(String version, String encoding, boolean standalone) throws XMLStreamException
XMLStreamException
public void writeEndDocument() throws XMLStreamException
XMLStreamException
public void writeDoctypeDecl(String rootName, String systemId, String publicId, String intSubset) throws XMLStreamException
XMLStreamException
public void writeValue(boolean v) throws XMLStreamException
XMLStreamException
public void writeValue(int v) throws XMLStreamException
XMLStreamException
public void writeValue(long v) throws XMLStreamException
XMLStreamException
public void writeValue(double d) throws XMLStreamException
XMLStreamException
public void writeValue(byte[] data) throws XMLStreamException
XMLStreamException
public void writeValue(byte[] data, int offset, int length) throws XMLStreamException
XMLStreamException
public void flushWriter() throws XMLStreamException
XMLStreamException
public void closeWriterCompletely() throws XMLStreamException
OutputStream
or
Writer
). Latter is done by calling
XMLStreamWriter2.closeCompletely()
on stream writer.XMLStreamException
public String generateUnboundPrefix()
public boolean isPrefixBound(String prefix)
public boolean isPrefixBoundLocally(String prefix, int parentNsCount)
isPrefixBound(java.lang.String)
, but only considers bindings
added by the current start element.public String findRootPrefix(SMNamespace ns)
Copyright © 2013 FasterXML. All Rights Reserved.