|
deegree 2.1 (2007/11/08 09:57 build-328-official) | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.deegree.framework.xml.XMLFragment
public class XMLFragment
An instance of XMLFragment
encapsulates an underlying Element
which acts
as the root element of the document (which may be a fragment or a whole document).
Basically, XMLFragment
provides easy loading and proper saving (automatically
generated CDATA-elements for text nodes that need to be escaped) and acts as base class for all
XML parsers in deegree.
TODO: automatically generated CDATA-elements are not implemented yet
Additionally, XMLFragment
tries to make the handling of relative paths inside the
document's content as painless as possible. This means that after initialization of the
XMLFragment
with the correct SystemID (i.e. the URL of the document):
XMLFragment
can resolve relative
URLs during parsing by calling the resolve()
method
XMLTools
,
Serialized FormField Summary | |
---|---|
static String |
DEFAULT_URL
Use this URL as SystemID only if an XMLFragment cannot be pinpointed to a URL -
in this case it may not use any relative references! |
protected static ILogger |
LOG
|
protected static NamespaceContext |
nsContext
|
protected static URI |
XLNNS
|
Constructor Summary | |
---|---|
XMLFragment()
Creates a new XMLFragment which is not initialized. |
|
XMLFragment(Document doc,
String systemId)
Creates a new XMLFragment instance based on the submitted
Document . |
|
XMLFragment(Element element)
Creates a new XMLFragment instance based on the submitted Element . |
|
XMLFragment(File file)
Creates a new XMLFragment which is loaded from the given File . |
|
XMLFragment(QualifiedName elementName)
Constructs an empty document with the given QualifiedName as root node. |
|
XMLFragment(Reader reader,
String systemId)
Creates a new XMLFragment which is loaded from the given Reader . |
|
XMLFragment(URL url)
Creates a new XMLFragment which is loaded from the given URL . |
Method Summary | |
---|---|
String |
getAsPrettyString()
Returns a string representation of the XML Document, pretty printed. |
String |
getAsString()
Returns a string representation of the XML Document |
Map<URI,URL> |
getAttachedSchemas()
Determines the namespace URI s and the bound schema URL s from
the 'xsi:schemaLocation' attribute of the document element. |
protected QualifiedName |
getQualifiedName(Element element)
Returns the qualified name of the given element. |
Element |
getRootElement()
|
URL |
getSystemId()
Returns the systemId (the URL of the XMLFragment ). |
boolean |
hasSchema()
Returns whether the document has a schema reference. |
void |
load(InputStream istream,
String systemId)
Initializes the XMLFragment with the content from the given
InputStream . |
void |
load(Reader reader,
String systemId)
Initializes the XMLFragment with the content from the given
Reader . |
void |
load(URL url)
Initializes the XMLFragment with the content from the given URL . |
static QualifiedName |
parseQualifiedName(Node node)
Parses the value of the submitted Node as a QualifiedName . |
protected SimpleLink |
parseSimpleLink(Element element)
Parses the submitted Element as a SimpleLink . |
void |
prettyPrint(OutputStream os)
Writes the XMLFragment instance to the given OutputStream using
indentation so it may be read easily. |
void |
prettyPrint(Writer writer)
Writes the XMLFragment instance to the given Writer using
indentation so it may be read easily. |
URL |
resolve(String url)
Resolves the given URL (which may be relative) against the SystemID of the XMLFragment into a URL (which is always absolute). |
void |
setRootElement(Element rootElement)
|
void |
setSystemId(String systemId)
|
void |
setSystemId(URL systemId)
|
String |
toString()
Returns a string representation of the object. |
void |
write(OutputStream os)
Writes the XMLFragment instance to the given OutputStream using
the default system encoding and adding CDATA-sections in for text-nodes where needed. |
void |
write(OutputStream os,
Properties outputProperties)
Writes the XMLFragment instance to the given OutputStream using
the specified OutputKeys which allow complete control of the generated output. |
void |
write(Writer writer)
Writes the XMLFragment instance to the given Writer using the
default system encoding and adding CDATA-sections in for text-nodes where needed. |
void |
write(Writer writer,
Properties outputProperties)
Writes the XMLFragment instance to the given Writer using the
specified OutputKeys . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static NamespaceContext nsContext
protected static final URI XLNNS
protected static final ILogger LOG
public static final String DEFAULT_URL
XMLFragment
cannot be pinpointed to a URL -
in this case it may not use any relative references!
Constructor Detail |
---|
public XMLFragment()
XMLFragment
which is not initialized.
public XMLFragment(URL url) throws IOException, SAXException
XMLFragment
which is loaded from the given URL
.
url
-
IOException
SAXException
public XMLFragment(File file) throws MalformedURLException, IOException, SAXException
XMLFragment
which is loaded from the given File
.
file
- the file to load from
SAXException
- if the document could not be parsed
IOException
- if the document could not be read
MalformedURLException
- if the file cannot be transposed to a valid urlpublic XMLFragment(Reader reader, String systemId) throws SAXException, IOException
XMLFragment
which is loaded from the given Reader
.
reader
- systemId
- this string should represent a URL that is related to the passed reader. If this
URL is not available or unknown, the string should contain the value of
XMLFragment.DEFAULT_URL
SAXException
IOException
public XMLFragment(Document doc, String systemId) throws MalformedURLException
XMLFragment
instance based on the submitted
Document
.
doc
- systemId
- this string should represent a URL that is the source of the passed doc. If this
URL is not available or unknown, the string should contain the value of
XMLFragment.DEFAULT_URL
MalformedURLException
- if systemId is no valid and absolute URL
public XMLFragment(Element element)
XMLFragment
instance based on the submitted Element
.
element
- public XMLFragment(QualifiedName elementName)
QualifiedName
as root node.
elementName
- if the name's namespace is set, the prefix should be set as well.Method Detail |
---|
public URL getSystemId()
XMLFragment
).
public void setSystemId(String systemId) throws MalformedURLException
systemId
- The systemId (physical location) to set (may be null).
MalformedURLException
public void setSystemId(URL systemId)
systemId
- The systemId (physical location) to set.public boolean hasSchema()
public Map<URI,URL> getAttachedSchemas() throws XMLParsingException
URI
s and the bound schema URL
s from
the 'xsi:schemaLocation' attribute of the document element.
XMLParsingException
public void load(URL url) throws IOException, SAXException
XMLFragment
with the content from the given URL
.
Sets the SystemId, too.
url
-
IOException
SAXException
public void load(InputStream istream, String systemId) throws SAXException, IOException, XMLException
XMLFragment
with the content from the given
InputStream
. Sets the SystemId, too.
istream
- systemId
- cannot be null. This string should represent a URL that is related to the passed
istream. If this URL is not available or unknown, the string should contain the
value of XMLFragment.DEFAULT_URL
SAXException
IOException
XMLException
NullPointerException
public void load(Reader reader, String systemId) throws SAXException, IOException
XMLFragment
with the content from the given
Reader
. Sets the SystemId, too.
reader
- systemId
- can not be null. This string should represent a URL that is related to the passed
reader. If this URL is not available or unknown, the string should contain the
value of XMLFragment.DEFAULT_URL
SAXException
IOException
NullPointerException
public void setRootElement(Element rootElement)
rootElement
- public Element getRootElement()
public URL resolve(String url) throws MalformedURLException
XMLFragment
into a URL
(which is always absolute).
url
-
MalformedURLException
public void write(Writer writer)
XMLFragment
instance to the given Writer
using the
default system encoding and adding CDATA-sections in for text-nodes where needed.
TODO: Add code for CDATA safety.
writer
- public void write(Writer writer, Properties outputProperties)
XMLFragment
instance to the given Writer
using the
specified OutputKeys
.
writer
- cannot be nulloutputProperties
- output properties for the Transformer
that is used to serialize the
document
see javax.xml.OutputKeyspublic void write(OutputStream os)
XMLFragment
instance to the given OutputStream
using
the default system encoding and adding CDATA-sections in for text-nodes where needed.
TODO: Add code for CDATA safety.
os
- public void write(OutputStream os, Properties outputProperties)
XMLFragment
instance to the given OutputStream
using
the specified OutputKeys
which allow complete control of the generated output.
os
- cannot be nulloutputProperties
- output properties for the Transformer
used to serialize the
documentOutputKeys
public void prettyPrint(OutputStream os) throws TransformerException
XMLFragment
instance to the given OutputStream
using
indentation so it may be read easily.
os
-
TransformerException
public void prettyPrint(Writer writer) throws TransformerException
XMLFragment
instance to the given Writer
using
indentation so it may be read easily.
writer
-
TransformerException
protected SimpleLink parseSimpleLink(Element element) throws XMLParsingException
Element
as a SimpleLink
.
Possible escaping of the attributes "xlink:href", "xlink:role" and "xlink:arcrole" is performed automatically.
element
-
XMLParsingException
public static QualifiedName parseQualifiedName(Node node) throws XMLParsingException
Node
as a QualifiedName
.
To parse the text contents of an Element
node, the actual text node must be
given, not the Element
node itself.
node
-
XMLParsingException
protected QualifiedName getQualifiedName(Element element) throws XMLParsingException
element
-
XMLParsingException
public String getAsString()
public String getAsPrettyString()
public String toString()
toString
in class Object
|
deegree 2.1 (2007/11/08 09:57 build-328-official) | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://deegree.sourceforge.net