Top Description Inners Fields Constructors Methods
org.eclipse.persistence.oxm.record

public Class FormattedOutputStreamRecord

extends OutputStreamRecord
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .UnsupportedEncodingException, org.eclipse.persistence.exceptions.XMLMarshalException, org.eclipse.persistence.internal.oxm.Constants, .NamespaceResolver, .XPathFragment, org.eclipse.persistence.internal.oxm.record.XMLFragmentReader, org.w3c.dom.Attr, .Node, org.xml.sax.Attributes, .SAXException

Use this type of MarshalRecord when the marshal target is an OutputStream and the XML should be formatted with carriage returns and indenting. This type is only used if the encoding of the OutputStream is UTF-8

XMLContext xmlContext = new XMLContext("session-name");
XMLMarshaller xmlMarshaller = xmlContext.createMarshaller();
FormattedOutputStreamRecord record = new FormattedOutputStreamRecord();
record.setOutputStream(myOutputStream);
xmlMarshaller.marshal(myObject, record);

If the marshal(OutputStream) and setFormattedOutput(true) method is called on XMLMarshaller and the encoding is UTF-8, then the OutputStream is automatically wrapped in a FormattedOutputStreamRecord.

XMLContext xmlContext = new XMLContext("session-name");
XMLMarshaller xmlMarshaller = xmlContext.createMarshaller();
xmlMarshaller xmlMarshaller.setFormattedOutput(true);
xmlMarshaller.marshal(myObject, myOutputStream);

See Also
org.eclipse.persistence.oxm.XMLMarshaller

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
FormattedOutputStreamRecord.FormattedOutputStreamRecordContentHandler

This class will typically be used in conjunction with an XMLFragmentReader.

Field Summary

Modifier and TypeField and Description
private boolean
private byte[]
private boolean
private int
private byte[]
Inherited from org.eclipse.persistence.oxm.record.OutputStreamRecord:
AMPCLOSE_ATTRIBUTE_VALUECLOSE_CDATACLOSE_COMMENTCLOSE_ELEMENTCLOSE_PIENCODINGGTisProcessingCDataisStartElementOpenLTOPEN_CDATAOPEN_COMMENTOPEN_ENCODING_ATTRIBUTEOPEN_START_ELEMENTOPEN_XML_PI_AND_VERSION_ATTRIBUTEoutputStreamQUOTSLASH_NSLASH_RSPACE

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
element(XPathFragment<XML_FIELD extends Field>
The XPathFragment of the element
frag
)

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.element.

INTERNAL:
public void
public void
endElement(XPathFragment<XML_FIELD extends Field>
The XPathFragment contains the name and prefix information about the XML element being ended.
xPathFragment
,
NamespaceResolver
The NamespaceResolver can be used to resolve the namespace URI for the namespace prefix held by the XPathFragment (if required).
namespaceResolver
)

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.endElement.

Implements org.eclipse.persistence.internal.oxm.record.MarshalRecord.endElement.

INTERNAL:
public void
node(Node
The Node to be added to the document
node
,
NamespaceResolver
The NamespaceResolver can be used to resolve the namespace URI/prefix of the node
namespaceResolver
,
String
replacement root name for the node
newNamespace
,
String
replacement root namespace for the node namespace URI/prefix of the node
newName
)

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.node.

Receive notification of a node.
public void
openStartElement(XPathFragment<XML_FIELD extends Field>
The XPathFragment contains the name and prefix information about the XML element being ended.
xPathFragment
,
NamespaceResolver
The NamespaceResolver can be used to resolve the namespace URI for the namespace prefix held by the XPathFragment (if required).
namespaceResolver
)

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.openStartElement.

Implements org.eclipse.persistence.internal.oxm.record.MarshalRecord.openStartElement.

INTERNAL:
private void
public void
startDocument(String
The XML document will be encoded using this encoding.
encoding
,
String
This specifies the version of XML.
version
)

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.startDocument.

INTERNAL:
private byte[]
tab()

public void
Inherited from org.eclipse.persistence.oxm.record.OutputStreamRecord:
attributeattributecloseStartElementflushgetOutputStreamoutputStreamWriteoutputStreamWriteoutputStreamWriteoutputStreamWritesetOutputStreamstartPrefixMappingswriteValuewriteValue

Field Detail

complexTypeback to summary
private boolean complexType
crback to summary
private byte[] cr
isLastEventTextback to summary
private boolean isLastEventText
numberOfTabsback to summary
private int numberOfTabs
tabback to summary
private byte[] tab

Constructor Detail

FormattedOutputStreamRecordback to summary
public FormattedOutputStreamRecord()

Method Detail

cdataback to summary
public void cdata(String value)

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.cdata.

Implements org.eclipse.persistence.internal.oxm.record.MarshalRecord.cdata.

INTERNAL:

Parameters
value:String

Doc from org.eclipse.persistence.oxm.record.MarshalRecord.cdata.

This is the value of the text to be wrapped

Annotations
@Override
charactersback to summary
public void characters(String value)

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.characters.

Implements org.eclipse.persistence.internal.oxm.record.MarshalRecord.characters.

INTERNAL:

Parameters
value:String

Doc from org.eclipse.persistence.oxm.record.MarshalRecord.characters.

This is the entire value of the text node.

Annotations
@Override
elementback to summary
public void element(XPathFragment<XML_FIELD extends Field> frag)

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.element.

INTERNAL:

Parameters
frag:XPathFragment<XML_FIELD extends Field>

Doc from org.eclipse.persistence.oxm.record.MarshalRecord.element.

The XPathFragment of the element

Annotations
@Override
endDocumentback to summary
public void endDocument()

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.endDocument.

INTERNAL:

Annotations
@Override
endElementback to summary
public void endElement(XPathFragment<XML_FIELD extends Field> xPathFragment, NamespaceResolver namespaceResolver)

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.endElement.

Implements org.eclipse.persistence.internal.oxm.record.MarshalRecord.endElement.

INTERNAL:

Parameters
xPathFragment:XPathFragment<XML_FIELD extends Field>

Doc from org.eclipse.persistence.oxm.record.MarshalRecord.endElement.

The XPathFragment contains the name and prefix information about the XML element being ended.

namespaceResolver:NamespaceResolver

Doc from org.eclipse.persistence.oxm.record.MarshalRecord.endElement.

The NamespaceResolver can be used to resolve the namespace URI for the namespace prefix held by the XPathFragment (if required).

Annotations
@Override
nodeback to summary
public void node(Node node, NamespaceResolver namespaceResolver, String newNamespace, String newName)

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.node.

Receive notification of a node.

Parameters
node:Node

The Node to be added to the document

namespaceResolver:NamespaceResolver

The NamespaceResolver can be used to resolve the namespace URI/prefix of the node

newNamespace:String

Doc from org.eclipse.persistence.oxm.record.MarshalRecord.node.

replacement root name for the node

newName:String

Doc from org.eclipse.persistence.oxm.record.MarshalRecord.node.

replacement root namespace for the node namespace URI/prefix of the node

Annotations
@Override
openStartElementback to summary
public void openStartElement(XPathFragment<XML_FIELD extends Field> xPathFragment, NamespaceResolver namespaceResolver)

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.openStartElement.

Implements org.eclipse.persistence.internal.oxm.record.MarshalRecord.openStartElement.

INTERNAL:

Parameters
xPathFragment:XPathFragment<XML_FIELD extends Field>

Doc from org.eclipse.persistence.oxm.record.MarshalRecord.openStartElement.

The XPathFragment contains the name and prefix information about the XML element being ended.

namespaceResolver:NamespaceResolver

Doc from org.eclipse.persistence.oxm.record.MarshalRecord.openStartElement.

The NamespaceResolver can be used to resolve the namespace URI for the namespace prefix held by the XPathFragment (if required).

Annotations
@Override
outputStreamWriteTabback to summary
private void outputStreamWriteTab()
startDocumentback to summary
public void startDocument(String encoding, String version)

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.startDocument.

INTERNAL:

Parameters
encoding:String

Doc from org.eclipse.persistence.oxm.record.MarshalRecord.startDocument.

The XML document will be encoded using this encoding.

version:String

Doc from org.eclipse.persistence.oxm.record.MarshalRecord.startDocument.

This specifies the version of XML.

Annotations
@Override
tabback to summary
private byte[] tab()
writeHeaderback to summary
public void writeHeader()

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.writeHeader.

INTERNAL

Annotations
@Override
org.eclipse.persistence.oxm.record back to summary

private Class FormattedOutputStreamRecord.FormattedOutputStreamRecordContentHandler

extends OutputStreamRecordContentHandler
Class Inheritance

This class will typically be used in conjunction with an XMLFragmentReader. The XMLFragmentReader will walk a given XMLFragment node and report events to this class - the event's data is then written to the enclosing class' writer.
See Also
org.eclipse.persistence.internal.oxm.record.XMLFragmentReader, org.eclipse.persistence.oxm.record.WriterRecord.WriterRecordContentHandler

Field Summary

Inherited from org.eclipse.persistence.oxm.record.OutputStreamRecord.OutputStreamRecordContentHandler:
prefixMappings

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
characters(char[]
the characters from the XML document
ch
,
int
the start position in the array
start
,
int
the number of characters to read from the array
length
)

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.OutputStreamRecordContentHandler.characters.

Implements org.xml.sax.ContentHandler.characters.

Receive notification of character data.
public void
comment(char[]
An array holding the characters in the comment.
ch
,
int
The starting position in the array.
start
,
int
The number of characters to use from the array.
length
)

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.OutputStreamRecordContentHandler.comment.

Implements org.xml.sax.ext.LexicalHandler.comment.

Report an XML comment anywhere in the document.
public void
endElement(String
the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed
namespaceURI
,
String
the local name (without prefix), or the empty string if Namespace processing is not being performed
localName
,
String
the qualified XML name (with prefix), or the empty string if qualified names are not available
qName
)

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.OutputStreamRecordContentHandler.endElement.

Implements org.xml.sax.ContentHandler.endElement.

Receive notification of the end of an element.
public void
startElement(String
the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed
namespaceURI
,
String
the local name (without prefix), or the empty string if Namespace processing is not being performed
localName
,
String
the qualified name (with prefix), or the empty string if qualified names are not available
qName
,
Attributes
the attributes attached to the element. If there are no attributes, it shall be an empty Attributes object. The value of this object after startElement returns is undefined
atts
)

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.OutputStreamRecordContentHandler.startElement.

Implements org.xml.sax.ContentHandler.startElement.

Receive notification of the beginning of an element.
Inherited from org.eclipse.persistence.oxm.record.OutputStreamRecord.OutputStreamRecordContentHandler:
charactersendCDATAendDocumentendDTDendEntityendPrefixMappinghandleAttributesignorableWhitespaceprocessingInstructionsetDocumentLocatorsetNilskippedEntitystartCDATAstartDocumentstartDTDstartEntitystartPrefixMappingwriteCharacterswriteCommentwritePrefixMappings

Constructor Detail

FormattedOutputStreamRecordContentHandlerback to summary
private FormattedOutputStreamRecordContentHandler()

Method Detail

charactersback to summary
public void characters(char[] ch, int start, int length) throws SAXException

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.OutputStreamRecordContentHandler.characters.

Implements org.xml.sax.ContentHandler.characters.

Doc from org.xml.sax.ContentHandler.characters.

Receive notification of character data.

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.

The application must not attempt to read from the array outside of the specified range.

Individual characters may consist of more than one Java char value. There are two important cases where this happens, because characters can't be represented in just sixteen bits. In one case, characters are represented in a Surrogate Pair, using two special Unicode values. Such characters are in the so-called "Astral Planes", with a code point above U+FFFF. A second case involves composite characters, such as a base character combining with one or more accent characters.

Your code should not assume that algorithms using char-at-a-time idioms will be working in character units; in some cases they will split characters. This is relevant wherever XML permits arbitrary characters, such as attribute values, processing instruction data, and comments as well as in data reported from this method. It's also generally relevant whenever Java code manipulates internationalized text; the issue isn't unique to XML.

Note that some parsers will report whitespace in element content using the ignorableWhitespace method rather than this one (validating parsers must do so).

Parameters
ch:char[]

the characters from the XML document

start:int

the start position in the array

length:int

the number of characters to read from the array

Annotations
@Override
Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
commentback to summary
public void comment(char[] ch, int start, int length) throws SAXException

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.OutputStreamRecordContentHandler.comment.

Implements org.xml.sax.ext.LexicalHandler.comment.

Doc from org.xml.sax.ext.LexicalHandler.comment.

Report an XML comment anywhere in the document.

This callback will be used for comments inside or outside the document element, including comments in the external DTD subset (if read). Comments in the DTD must be properly nested inside start/endDTD and start/endEntity events (if used).

Parameters
ch:char[]

An array holding the characters in the comment.

start:int

The starting position in the array.

length:int

The number of characters to use from the array.

Annotations
@Override
Exceptions
SAXException:
The application may raise an exception.
endElementback to summary
public void endElement(String namespaceURI, String localName, String qName) throws SAXException

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.OutputStreamRecordContentHandler.endElement.

Implements org.xml.sax.ContentHandler.endElement.

Doc from org.xml.sax.ContentHandler.endElement.

Receive notification of the end of an element.

The SAX parser will invoke this method at the end of every element in the XML document; there will be a corresponding startElement event for every endElement event (even when the element is empty).

For information on the names, see startElement.

Parameters
namespaceURI:String

the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed

localName:String

the local name (without prefix), or the empty string if Namespace processing is not being performed

qName:String

the qualified XML name (with prefix), or the empty string if qualified names are not available

Annotations
@Override
Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
startElementback to summary
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException

Overrides org.eclipse.persistence.oxm.record.OutputStreamRecord.OutputStreamRecordContentHandler.startElement.

Implements org.xml.sax.ContentHandler.startElement.

Doc from org.xml.sax.ContentHandler.startElement.

Receive notification of the beginning of an element.

The Parser will invoke this method at the beginning of every element in the XML document; there will be a corresponding endElement event for every startElement event (even when the element is empty). All of the element's content will be reported, in order, before the corresponding endElement event.

This event allows up to three name components for each element:

  1. the Namespace URI;
  2. the local name; and
  3. the qualified (prefixed) name.

Any or all of these may be provided, depending on the values of the http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixes properties:

  • the Namespace URI and local name are required when the namespaces property is true (the default), and are optional when the namespaces property is false (if one is specified, both must be);
  • the qualified name is required when the namespace-prefixes property is true, and is optional when the namespace-prefixes property is false (the default).

Note that the attribute list provided will contain only attributes with explicit values (specified or defaulted): #IMPLIED attributes will be omitted. The attribute list will contain attributes used for Namespace declarations (xmlns* attributes) only if the http://xml.org/sax/features/namespace-prefixes property is true (it is false by default, and support for a true value is optional).

Like characters(), attribute values may have characters that need more than one char value.

Parameters
namespaceURI:String

the Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed

localName:String

the local name (without prefix), or the empty string if Namespace processing is not being performed

qName:String

the qualified name (with prefix), or the empty string if qualified names are not available

atts:Attributes

the attributes attached to the element. If there are no attributes, it shall be an empty Attributes object. The value of this object after startElement returns is undefined

Annotations
@Override
Exceptions
SAXException:
any SAX exception, possibly wrapping another exception