|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.xpresso.xml.XmlContent
org.xpresso.xml.Document
public class Document
The main class, used to generate the XML document. It contains a stack containing Elements
.
Content is added to the upper Element on the stack. Document provides methods to stack and unstack elements,
adding content
and returning the resulting XML.
Document is itself a XmlContent, so a Document can be added at a chosen place of another Document. Header information (XML header,
DTD declaration) are in this case discarded.
This code is under the LGPL v3 licence.
Field Summary | |
---|---|
protected java.lang.StringBuilder |
header
Contains the header: XML declaration and DTD reference |
protected boolean |
open
Content can only be added to the Document if this boolean is true. |
protected java.util.Deque<Element> |
stack
This stack is used to know the depth in the document tree |
Fields inherited from class org.xpresso.xml.XmlContent |
---|
content |
Constructor Summary | |
---|---|
protected |
Document()
Constructor creating a new Document without content. |
protected |
Document(Element root)
Constructor creating a new Document with only a root Element . |
protected |
Document(java.lang.String xmlVersion,
Element root)
Constructor creating a new Document with a xml version and a root Element . |
protected |
Document(java.lang.String xmlVersion,
Element root,
java.lang.String dtdName,
java.lang.String dtdFile)
Constructor creating a new Document with a xml version, a root Element and a DOCTYPE statement. |
protected |
Document(java.lang.String xmlVersion,
java.lang.String encoding,
Element root)
Constructor creating a new Document with a xml version, the character set encoding and a root Element . |
protected |
Document(java.lang.String xmlVersion,
java.lang.String encoding,
Element root,
boolean standalone)
Constructor creating a new Document with a xml version, the character set encoding, the standalone setting and a root Element . |
protected |
Document(java.lang.String xmlVersion,
java.lang.String encoding,
Element root,
boolean standalone,
java.lang.String dtdName,
java.lang.String dtdFile)
Constructor creating a new Document with a xml version, the character set encoding, the standalone setting a root Element and a DOCTYPE statement. |
protected |
Document(java.lang.String xmlVersion,
java.lang.String encoding,
Element root,
java.lang.String dtdName,
java.lang.String dtdFile)
Constructor creating a new Document with a xml version, the character set encoding, a root Element and a DOCTYPE statement. |
Method Summary | |
---|---|
void |
add(XmlContent xmlContent)
Add an XmlContent to the uppest Element of the stack. |
char |
charAt(int index)
Required for implementing CharSequence |
Document |
clone()
Returns a deep clone of the Document, regardless its current state. |
static CDATA |
createCdata(java.lang.String text)
Returns a new CDATA |
static Comment |
createComment(java.lang.String text)
Returns a new Comment |
static Document |
createDocument(Element root)
Creates a new Document with only a root Element . |
static Document |
createDocument(java.lang.String xmlVersion,
Element root)
Creates a new Document with a xml version and a root Element . |
static Document |
createDocument(java.lang.String xmlVersion,
Element root,
java.lang.String dtdName,
java.lang.String dtdFile)
Creates a new Document with a xml version, a root Element and a DOCTYPE statement. |
static Document |
createDocument(java.lang.String xmlVersion,
java.lang.String encoding,
Element root)
Creates a new Document with a xml version, the character set encoding and a root Element . |
static Document |
createDocument(java.lang.String xmlVersion,
java.lang.String encoding,
Element root,
boolean standalone)
Creates a new Document with a xml version, the character set encoding, the standalone setting and a root Element . |
static Document |
createDocument(java.lang.String xmlVersion,
java.lang.String encoding,
Element root,
boolean standalone,
java.lang.String dtdName,
java.lang.String dtdFile)
Creates a new Document with a xml version, the character set encoding, the standalone setting a root Element and a DOCTYPE statement. |
static Document |
createDocument(java.lang.String xmlVersion,
java.lang.String encoding,
Element root,
java.lang.String dtdName,
java.lang.String dtdFile)
a new Document with a xml version, the character set encoding, a root Element and a DOCTYPE statement. |
static Element |
createElement(java.lang.String label)
Creates a new Element |
static ProcessingInstruction |
createProcessingInstruction(java.lang.String text)
Returns a new ProcessingInstruction |
static Text |
createText(java.lang.String text)
Returns a new XML Text |
void |
finish()
Unstack all Elements , which means the document is closed. |
java.io.StringReader |
getStringReader()
Returns a StringReader containing the XML. |
java.lang.String |
getText()
Return the Document as a String which can be added to another Document, which means it has to be closed and that the header informations are discarded. |
java.lang.String |
getXmlText()
Return the Document in its current state of completion. |
int |
length()
Required for implementing CharSequence |
static void |
main(java.lang.String[] args)
For test purpose only ! |
void |
stackElement(Element element)
Adds a level of depth to the current branch of the document. |
java.lang.CharSequence |
subSequence(int start,
int end)
Required for implementing CharSequence |
void |
unstackElement()
Unstack a level of depth from the current branch of the document. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.lang.CharSequence |
---|
toString |
Field Detail |
---|
protected java.lang.StringBuilder header
protected java.util.Deque<Element> stack
protected boolean open
finish()
method or whenElement
is unstacked byunstackElement()
method.
Constructor Detail |
---|
protected Document(Element root)
Element
.
root
- Root Element
of the documentprotected Document(java.lang.String xmlVersion, Element root)
Element
.
xmlVersion
- XML version in the header of the Documentroot
- Root Element
of the documentprotected Document(java.lang.String xmlVersion, Element root, java.lang.String dtdName, java.lang.String dtdFile)
Element
xmlVersion
- XML version in the header of the Documentroot
- Root Element
of the documentdtdName
- Reference name to give to the DTD with the XML documentdtdFile
- DTD Fileprotected Document(java.lang.String xmlVersion, java.lang.String encoding, Element root)
Element
.
xmlVersion
- XML version in the header of the Documentencoding
- Character set encodingroot
- Root Element
of the documentprotected Document(java.lang.String xmlVersion, java.lang.String encoding, Element root, java.lang.String dtdName, java.lang.String dtdFile)
Element
and a DOCTYPE statement.
xmlVersion
- XML version in the header of the Documentencoding
- Character set encodingroot
- Root Element
of the documentdtdName
- Reference name to give to the DTD with the XML documentdtdFile
- DTD Fileprotected Document(java.lang.String xmlVersion, java.lang.String encoding, Element root, boolean standalone)
Element
.
xmlVersion
- XML version in the header of the Documentencoding
- Character set encodingroot
- Root Element
of the documentstandalone
- Is the document standalone, which means does it refer to a DTD or not. Values are "true" or "false"protected Document(java.lang.String xmlVersion, java.lang.String encoding, Element root, boolean standalone, java.lang.String dtdName, java.lang.String dtdFile)
Element
and a DOCTYPE statement.
xmlVersion
- XML version in the header of the Documentencoding
- Character set encodingroot
- Root Element
of the documentstandalone
- Is the document standalone, which means does it refer to a DTD or not. Values are "true" or "false"dtdName
- Reference name to give to the DTD with the XML documentdtdFile
- DTD Fileprotected Document()
Method Detail |
---|
public static Document createDocument(Element root)
Element
.
root
- Root Element
of the document
public static Document createDocument(java.lang.String xmlVersion, Element root)
Element
.
xmlVersion
- XML version in the header of the Documentroot
- Root Element
of the document
public static Document createDocument(java.lang.String xmlVersion, Element root, java.lang.String dtdName, java.lang.String dtdFile)
Element
xmlVersion
- XML version in the header of the Documentroot
- Root Element
of the documentdtdName
- Reference name to give to the DTD with the XML documentdtdFile
- DTD File
public static Document createDocument(java.lang.String xmlVersion, java.lang.String encoding, Element root)
Element
.
xmlVersion
- XML version in the header of the Documentencoding
- Character set encodingroot
- Root Element
of the document
public static Document createDocument(java.lang.String xmlVersion, java.lang.String encoding, Element root, java.lang.String dtdName, java.lang.String dtdFile)
Element
and a DOCTYPE statement.
xmlVersion
- XML version in the header of the Documentencoding
- Character set encodingroot
- Root Element
of the documentdtdName
- Reference name to give to the DTD with the XML documentdtdFile
- DTD File
public static Document createDocument(java.lang.String xmlVersion, java.lang.String encoding, Element root, boolean standalone)
Element
.
xmlVersion
- XML version in the header of the Documentencoding
- Character set encodingroot
- Root Element
of the documentstandalone
- Is the document standalone, which means does it refer to a DTD or not. Values are "true" or "false"
public static Document createDocument(java.lang.String xmlVersion, java.lang.String encoding, Element root, boolean standalone, java.lang.String dtdName, java.lang.String dtdFile)
Element
and a DOCTYPE statement.
xmlVersion
- XML version in the header of the Documentencoding
- Character set encodingroot
- Root Element
of the documentstandalone
- Is the document standalone, which means does it refer to a DTD or not. Values are "true" or "false"dtdName
- Reference name to give to the DTD with the XML documentdtdFile
- DTD File
public void stackElement(Element element) throws ClosedDocumentException
Element
.
element
- The new Element to be stacked
ClosedDocumentException
- Thrown if the method is added after the document was closedpublic void unstackElement() throws ClosedDocumentException
XmlContent
Element
just below the one unstacked. If this one is the last in
ClosedDocumentException
- Thrown if the method is added after the document was closedpublic void add(XmlContent xmlContent) throws ClosedDocumentException
XmlContent
to the uppest Element
of the stack.
xmlContent
- Content to be added
ClosedDocumentException
- Thrown if the method is added after the document was closedpublic void finish()
Elements
, which means the document is closed.
public java.lang.String getXmlText()
Elements
are left on the stack,
public java.io.StringReader getStringReader()
public java.lang.String getText() throws IllegalContentException
getText
in class XmlContent
IllegalContentException
- Thrown if the Document is not closedpublic char charAt(int index)
charAt
in interface java.lang.CharSequence
public int length()
length
in interface java.lang.CharSequence
public java.lang.CharSequence subSequence(int start, int end)
subSequence
in interface java.lang.CharSequence
public Document clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public static Element createElement(java.lang.String label)
label
- label of the new Element
public static CDATA createCdata(java.lang.String text)
text
- Content of the CDATA
public static Comment createComment(java.lang.String text)
text
- Content of the Comment
public static ProcessingInstruction createProcessingInstruction(java.lang.String text)
text
- Text of the Processing Instruction
public static Text createText(java.lang.String text)
text
- Content of the Text
public static void main(java.lang.String[] args)
args
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |