|
deegree-core-3.0-pre-nightly (2010/03/05 00:01) - official | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.deegree.commons.xml.XMLAdapter
public class XMLAdapter
XMLAdapter
is the common base class of all hand-written (i.e. not automatically generated) XML parsers
and exporters in deegree. Classes that extend XMLAdapter
provide the binding between a certain type of
XML documents and their corresponding Java bean representation.
XMLAdapter
tries to make the process of writing custom XML parsers as painless as possible. It provides
the following functionality:
XMLParsingException
if the expression does not
have a result.int
, boolean
, ...) or common
Objects (QName
, SimpleLink
, ...). If the value can not be converted to the expected type,
an XMLParsingException
is thrown.
URL
, Reader
, InputStream
).
Technically, the XML handling is based on AXIOM (AXis Object Model).
Field Summary | |
---|---|
static String |
DEFAULT_URL
Use this URL as SystemID only if the document content cannot be pinpointed to a URL - in this case it may not use any relative references! |
protected static NamespaceContext |
nsContext
The context |
protected org.apache.axiom.om.OMElement |
rootElement
Root element of the XML contents. |
protected static String |
XLN_NS
the xlink namespace |
Constructor Summary | |
---|---|
XMLAdapter()
Creates a new XMLAdapter which is not bound to an XML element. |
|
XMLAdapter(File file)
Creates a new instance that loads its content from the given File . |
|
XMLAdapter(InputStream in)
Creates a new instance that loads its content from the given InputStream using the default url. |
|
XMLAdapter(InputStream in,
String systemId)
Creates a new instance that loads its content from the given InputStream . |
|
XMLAdapter(org.apache.axiom.om.OMDocument doc,
String systemId)
Creates a new instance that wraps the submitted XML document. |
|
XMLAdapter(org.apache.axiom.om.OMElement rootElement)
Creates a new XMLAdapter with the given OMElement as root element; |
|
XMLAdapter(org.apache.axiom.om.OMElement rootElement,
String systemId)
Creates a new instance that wraps the given XML element. |
|
XMLAdapter(Reader reader)
Creates a new instance that loads its content from the given Reader using the default url. |
|
XMLAdapter(Reader reader,
String systemId)
Creates a new instance that loads its content from the given Reader . |
|
XMLAdapter(URL url)
Creates a new instance that loads its content from the given URL . |
|
XMLAdapter(XMLStreamReader xmlStream)
|
Method Summary | |
---|---|
Object |
evaluateXPath(XPath xpath,
Object context)
|
org.apache.axiom.om.OMElement |
getElement(org.apache.axiom.om.OMElement context,
XPath xpath)
|
List<org.apache.axiom.om.OMElement> |
getElements(org.apache.axiom.om.OMElement context,
XPath xpath)
|
NamespaceContext |
getNamespaceContext(org.apache.axiom.om.OMElement element)
Constructs a NamespaceContext from all active namespace bindings available in the scope of the given
OMElement . |
Object |
getNode(org.apache.axiom.om.OMElement context,
XPath xpath)
|
boolean |
getNodeAsBoolean(org.apache.axiom.om.OMElement context,
XPath xpath,
boolean defaultValue)
|
double |
getNodeAsDouble(org.apache.axiom.om.OMElement context,
XPath xpath,
double defaultValue)
|
float |
getNodeAsFloat(org.apache.axiom.om.OMElement context,
XPath xpath,
float defaultValue)
|
int |
getNodeAsInt(org.apache.axiom.om.OMElement context,
XPath xpath,
int defaultValue)
|
QName |
getNodeAsQName(org.apache.axiom.om.OMElement context,
XPath xpath,
QName defaultValue)
|
String |
getNodeAsString(org.apache.axiom.om.OMElement context,
XPath xpath,
String defaultValue)
|
URL |
getNodeAsURL(org.apache.axiom.om.OMElement context,
XPath xpath,
URL defaultValue)
|
Version |
getNodeAsVersion(org.apache.axiom.om.OMElement context,
XPath xpath,
Version defaultValue)
|
List |
getNodes(org.apache.axiom.om.OMElement context,
XPath xpath)
|
QName[] |
getNodesAsQNames(org.apache.axiom.om.OMElement contextNode,
XPath xpath)
|
String[] |
getNodesAsStrings(org.apache.axiom.om.OMElement contextNode,
XPath xpath)
|
org.apache.axiom.om.OMElement |
getRequiredElement(org.apache.axiom.om.OMElement context,
XPath xpath)
|
List<org.apache.axiom.om.OMElement> |
getRequiredElements(org.apache.axiom.om.OMElement context,
XPath xpath)
|
Object |
getRequiredNode(org.apache.axiom.om.OMElement context,
XPath xpath)
|
boolean |
getRequiredNodeAsBoolean(org.apache.axiom.om.OMElement context,
XPath xpath)
|
double |
getRequiredNodeAsDouble(org.apache.axiom.om.OMElement context,
XPath xpath)
|
float |
getRequiredNodeAsFloat(org.apache.axiom.om.OMElement context,
XPath xpath)
|
int |
getRequiredNodeAsInteger(org.apache.axiom.om.OMElement context,
XPath xpath)
|
QName |
getRequiredNodeAsQName(org.apache.axiom.om.OMElement context,
XPath xpath)
|
String |
getRequiredNodeAsString(org.apache.axiom.om.OMElement context,
XPath xpath)
|
URL |
getRequiredNodeAsURL(org.apache.axiom.om.OMElement context,
XPath xpath)
|
Version |
getRequiredNodeAsVersion(org.apache.axiom.om.OMElement context,
XPath xpath)
|
List |
getRequiredNodes(org.apache.axiom.om.OMElement context,
XPath xpath)
|
org.apache.axiom.om.OMElement |
getRootElement()
Returns the root element, i.e. the XML element encapsulated by this XMLAdapter . |
Map<String,URL> |
getSchemas()
Determines the namespace URI s and the bound schema URL s from the 'xsi:schemaLocation'
attribute of the wrapped XML element. |
String |
getSystemId()
Returns the systemId (the physical location of the wrapped XML content). |
boolean |
hasSchemas()
Returns whether the wrapped XML element contains schema references. |
void |
load(InputStream resourceStream)
Initializes this XMLAdapter with the content from the given InputStream and sets the
system id to the DEFAULT_URL |
void |
load(InputStream istream,
String systemId)
Initializes this XMLAdapter with the content from the given InputStream . |
void |
load(Reader reader)
Initializes this XMLAdapter with the content from the given Reader and sets the system
id to the DEFAULT_URL |
void |
load(Reader reader,
String systemId)
Initializes this XMLAdapter with the content from the given Reader . |
void |
load(URL url)
Initializes this XMLAdapter with the content from the given URL . |
static void |
maybeWriteElement(XMLStreamWriter writer,
String name,
String text)
Writes an element without namespace, only if text not null |
static void |
maybeWriteElementNS(XMLStreamWriter writer,
String ns,
String name,
String text)
Writes an element with namespace, only if text not null |
boolean |
parseBoolean(String s)
Parses the given String as an xsd:boolean value. |
double |
parseDouble(String s)
Parses the given String as an xsd:double value. |
float |
parseFloat(String s)
Parses the given String as an xsd:float value. |
int |
parseInt(String s)
Parses the given String as an xsd:integer value. |
QName |
parseQName(String s,
org.apache.axiom.om.OMElement element)
Parses the given String as an xsd:QName value. |
SimpleLink |
parseSimpleLink(org.apache.axiom.om.OMElement element)
Parses the submitted XML element as a SimpleLink . |
URL |
parseURL(String s)
Parses the given String as an URL . |
URL |
resolve(String url)
Resolves the given URL (which may be relative) against the SystemID of this XMLAdapter into an
absolute URL . |
void |
setRootElement(org.apache.axiom.om.OMElement rootElement)
Sets the root element, i.e. the XML element encapsulated by this XMLAdapter . |
void |
setSystemId(String systemId)
Sets the systemId (the physical location of the wrapped XML content). |
String |
toString()
|
static void |
writeElement(XMLStreamWriter writer,
String name,
String text)
Writes an element without namespace, and with an (optional) text |
static void |
writeElement(XMLStreamWriter writer,
String namespace,
String elemName,
String value)
Write an element with simple text content into the XMLStream. |
static void |
writeElement(XMLStreamWriter writer,
String namespace,
String elemName,
String attrNS,
String attrName,
String attrValue)
Write an element with a single attribute into the XMLStream. |
static void |
writeElement(XMLStreamWriter writer,
String namespace,
String elemName,
String value,
String attrNS,
String attribPRE,
String attrName,
String attrValue)
Write an element with simple text content and an attribute into the XMLStream. |
static void |
writeElement(XMLStreamWriter writer,
XMLStreamReader inStream)
Copies an XML element (including all attributes and subnodes) from an XMLStreamReader into the given
XMLStreamWriter . |
static void |
writeOptionalAttribute(XMLStreamWriter writer,
String name,
String value)
Write an optional attribute at the current position of the writer. |
static void |
writeOptionalElement(XMLStreamWriter writer,
String namespace,
String elemName,
String value)
Write an optional element with simple text content into the XMLStream. |
static void |
writeOptionalNSAttribute(XMLStreamWriter writer,
String namespace,
String name,
String value)
Write an optional attribute at the current position of the writer. |
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 String XLN_NS
public static final String DEFAULT_URL
protected org.apache.axiom.om.OMElement rootElement
Constructor Detail |
---|
public XMLAdapter()
XMLAdapter
which is not bound to an XML element.
public XMLAdapter(org.apache.axiom.om.OMElement rootElement)
XMLAdapter
with the given OMElement as root element;
rootElement
- the root element of the xml adapterpublic XMLAdapter(URL url) throws XMLProcessingException
URL
.
url
- source of the xml content
XMLProcessingException
public XMLAdapter(File file) throws XMLProcessingException
File
.
file
- source of the xml content
XMLProcessingException
public XMLAdapter(Reader reader) throws XMLProcessingException
Reader
using the default url.
reader
- source of the xml content
XMLProcessingException
public XMLAdapter(Reader reader, String systemId) throws XMLProcessingException
Reader
.
reader
- source of the xml contentsystemId
- 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 XMLAdapter.DEFAULT_URL
XMLProcessingException
public XMLAdapter(InputStream in) throws XMLProcessingException
InputStream
using the default url.
in
- source of the xml content
XMLProcessingException
public XMLAdapter(InputStream in, String systemId) throws XMLProcessingException
InputStream
.
in
- source of the xml contentsystemId
- 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 XMLAdapter.DEFAULT_URL
XMLProcessingException
public XMLAdapter(org.apache.axiom.om.OMDocument doc, String systemId)
doc
- xml contentsystemId
- the 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_URLpublic XMLAdapter(org.apache.axiom.om.OMElement rootElement, String systemId)
rootElement
- xml contentsystemId
- the 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_URLpublic XMLAdapter(XMLStreamReader xmlStream)
Method Detail |
---|
public String getSystemId()
public void setSystemId(String systemId)
systemId
- systemId (physical location) to setpublic boolean hasSchemas()
public Map<String,URL> getSchemas() throws XMLProcessingException
URI
s and the bound schema URL
s from the 'xsi:schemaLocation'
attribute of the wrapped XML element.
XMLProcessingException
public void load(URL url) throws XMLProcessingException
XMLAdapter
with the content from the given URL
. Sets the SystemId,
too.
url
- source of the xml content
XMLProcessingException
public void load(InputStream istream, String systemId) throws XMLProcessingException
XMLAdapter
with the content from the given InputStream
. Sets the
SystemId, too.
istream
- source of the xml contentsystemId
- 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
XMLProcessingException
public void load(InputStream resourceStream) throws XMLProcessingException
XMLAdapter
with the content from the given InputStream
and sets the
system id to the DEFAULT_URL
resourceStream
- to load the xml from.
XMLProcessingException
public void load(Reader reader, String systemId) throws XMLProcessingException
XMLAdapter
with the content from the given Reader
. Sets the SystemId,
too.
reader
- source of the XML contentsystemId
- 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
XMLProcessingException
public void load(Reader reader) throws XMLProcessingException
XMLAdapter
with the content from the given Reader
and sets the system
id to the DEFAULT_URL
reader
- to load the xml from.
XMLProcessingException
public void setRootElement(org.apache.axiom.om.OMElement rootElement)
XMLAdapter
.
rootElement
- the root elementpublic org.apache.axiom.om.OMElement getRootElement()
XMLAdapter
.
public URL resolve(String url) throws MalformedURLException
XMLAdapter
into an
absolute URL
.
url
- URL
to be resolved (may be relative or absolute)
MalformedURLException
public Object evaluateXPath(XPath xpath, Object context) throws XMLProcessingException
XMLProcessingException
public SimpleLink parseSimpleLink(org.apache.axiom.om.OMElement element) throws XMLParsingException
SimpleLink
.
Possible escaping of the attributes "xlink:href", "xlink:role" and "xlink:arcrole" is performed automatically.
element
-
XMLParsingException
public boolean parseBoolean(String s) throws XMLParsingException
String
as an xsd:boolean
value.
s
- the String
to be parsed
XMLParsingException
- if the given String
is not a valid instance of xsd:boolean
public double parseDouble(String s) throws XMLParsingException
String
as an xsd:double
value.
s
- the String
to be parsed
XMLParsingException
- if the given String
is not a valid instance of xsd:double
public float parseFloat(String s) throws XMLParsingException
String
as an xsd:float
value.
s
- the String
to be parsed
XMLParsingException
- if the given String
is not a valid instance of xsd:float
public int parseInt(String s) throws XMLParsingException
String
as an xsd:integer
value.
s
- the String
to be parsed
XMLParsingException
- if the given String
is not a valid instance of xsd:integer
public URL parseURL(String s) throws XMLParsingException
String
as an URL
.
s
- the String
to be parsed
XMLParsingException
- if the given String
is not a valid URL
public QName parseQName(String s, org.apache.axiom.om.OMElement element) throws XMLParsingException
String
as an xsd:QName
value.
s
- the String
to be parsedelement
- element that provides the namespace context (used to resolve the namespace prefix)
XMLParsingException
- if the given String
is not a valid instance of xsd:QName
public org.apache.axiom.om.OMElement getElement(org.apache.axiom.om.OMElement context, XPath xpath) throws XMLParsingException
XMLParsingException
public List<org.apache.axiom.om.OMElement> getElements(org.apache.axiom.om.OMElement context, XPath xpath) throws XMLParsingException
XMLParsingException
public Object getNode(org.apache.axiom.om.OMElement context, XPath xpath) throws XMLParsingException
XMLParsingException
public boolean getNodeAsBoolean(org.apache.axiom.om.OMElement context, XPath xpath, boolean defaultValue) throws XMLParsingException
XMLParsingException
public double getNodeAsDouble(org.apache.axiom.om.OMElement context, XPath xpath, double defaultValue) throws XMLParsingException
XMLParsingException
public float getNodeAsFloat(org.apache.axiom.om.OMElement context, XPath xpath, float defaultValue) throws XMLParsingException
XMLParsingException
public int getNodeAsInt(org.apache.axiom.om.OMElement context, XPath xpath, int defaultValue) throws XMLParsingException
XMLParsingException
public URL getNodeAsURL(org.apache.axiom.om.OMElement context, XPath xpath, URL defaultValue) throws XMLParsingException
XMLParsingException
public QName getNodeAsQName(org.apache.axiom.om.OMElement context, XPath xpath, QName defaultValue) throws XMLParsingException
XMLParsingException
public String getNodeAsString(org.apache.axiom.om.OMElement context, XPath xpath, String defaultValue) throws XMLParsingException
XMLParsingException
public Version getNodeAsVersion(org.apache.axiom.om.OMElement context, XPath xpath, Version defaultValue) throws XMLParsingException
XMLParsingException
public List getNodes(org.apache.axiom.om.OMElement context, XPath xpath) throws XMLParsingException
XMLParsingException
public String[] getNodesAsStrings(org.apache.axiom.om.OMElement contextNode, XPath xpath)
public QName[] getNodesAsQNames(org.apache.axiom.om.OMElement contextNode, XPath xpath)
public org.apache.axiom.om.OMElement getRequiredElement(org.apache.axiom.om.OMElement context, XPath xpath) throws XMLParsingException
XMLParsingException
public List<org.apache.axiom.om.OMElement> getRequiredElements(org.apache.axiom.om.OMElement context, XPath xpath) throws XMLParsingException
XMLParsingException
public Object getRequiredNode(org.apache.axiom.om.OMElement context, XPath xpath) throws XMLParsingException
XMLParsingException
public boolean getRequiredNodeAsBoolean(org.apache.axiom.om.OMElement context, XPath xpath) throws XMLParsingException
XMLParsingException
public double getRequiredNodeAsDouble(org.apache.axiom.om.OMElement context, XPath xpath) throws XMLParsingException
XMLParsingException
public float getRequiredNodeAsFloat(org.apache.axiom.om.OMElement context, XPath xpath) throws XMLParsingException
XMLParsingException
public int getRequiredNodeAsInteger(org.apache.axiom.om.OMElement context, XPath xpath) throws XMLParsingException
XMLParsingException
public URL getRequiredNodeAsURL(org.apache.axiom.om.OMElement context, XPath xpath) throws XMLParsingException
XMLParsingException
public String getRequiredNodeAsString(org.apache.axiom.om.OMElement context, XPath xpath) throws XMLParsingException
XMLParsingException
public QName getRequiredNodeAsQName(org.apache.axiom.om.OMElement context, XPath xpath) throws XMLParsingException
XMLParsingException
public Version getRequiredNodeAsVersion(org.apache.axiom.om.OMElement context, XPath xpath) throws XMLParsingException
XMLParsingException
public List getRequiredNodes(org.apache.axiom.om.OMElement context, XPath xpath) throws XMLParsingException
XMLParsingException
public NamespaceContext getNamespaceContext(org.apache.axiom.om.OMElement element)
NamespaceContext
from all active namespace bindings available in the scope of the given
OMElement
.
element
- the given element
public static void writeElement(XMLStreamWriter writer, String namespace, String elemName, String value) throws XMLStreamException
Convenience method to write simple elements like:
<ogc:GeometryOperand>gml:Envelope</ogc:GeometryOperand> <gml:upperCorner>90 180</gml:upperCorner>
writer
- namespace
- the namespace of the elementelemName
- the element namevalue
- the text value of the element
XMLStreamException
public static void writeElement(XMLStreamWriter writer, String namespace, String elemName, String value, String attrNS, String attribPRE, String attrName, String attrValue) throws XMLStreamException
Convenience method to write simple elements like:
<ogc:GeometryOperand name="env">gml:Envelope</ogc:GeometryOperand> <gml:upperCorner>90 180</gml:upperCorner>
writer
- namespace
- the namespace of the elementelemName
- the element namevalue
- the text value of the elementattrNS
- the namespace of the attribute, null if the local namespace of the element should be usedattribPRE
- to use for the namespace bindingattrName
- the attribute nameattrValue
- the attribute value, if null
the attribute will not be written.
- Throws:
XMLStreamException
public static void writeOptionalAttribute(XMLStreamWriter writer, String name, String value) throws XMLStreamException
null
no
attribute will be written.
writer
- name
- value
-
XMLStreamException
public static void writeOptionalNSAttribute(XMLStreamWriter writer, String namespace, String name, String value) throws XMLStreamException
null
no
attribute will be written.
writer
- namespace
- of the attributename
- of the attributevalue
- of the attribute might be null
XMLStreamException
public static void writeElement(XMLStreamWriter writer, String namespace, String elemName, String attrNS, String attrName, String attrValue) throws XMLStreamException
Convenience method to write simple elements like:
<ows:Post xlink:href="http://localhost/" /> <ogc:TemporalOperator name="TM_Begins" />
writer
- namespace
- the namespace of the elementelemName
- the element nameattrNS
- the namespace of the attribute, null if the local namespace of the element should be usedattrName
- the attribute nameattrValue
- the attribute value
- Throws:
XMLStreamException
public static void writeOptionalElement(XMLStreamWriter writer, String namespace, String elemName, String value) throws XMLStreamException
null
, than
the element is omitted.
Convenience method to write simple elements like:
<ogc:GeometryOperand>gml:Envelope</ogc:GeometryOperand> <gml:upperCorner>10 -42</gml:upperCorner>
writer
- namespace
- the namespace of the elementelemName
- the element namevalue
- the text value of the element
XMLStreamException
public static void writeElement(XMLStreamWriter writer, XMLStreamReader inStream) throws XMLStreamException
XMLStreamReader
into the given
XMLStreamWriter
.
writer
- XMLStreamWriter
that the xml is appended toinStream
- cursor must point at a START_ELEMENT
event and points at the corresponding
END_ELEMENT
event afterwards
XMLStreamException
public static void writeElement(XMLStreamWriter writer, String name, String text) throws XMLStreamException
writer
- name
- text
-
XMLStreamException
public static void maybeWriteElement(XMLStreamWriter writer, String name, String text) throws XMLStreamException
writer
- name
- text
-
XMLStreamException
public static void maybeWriteElementNS(XMLStreamWriter writer, String ns, String name, String text) throws XMLStreamException
writer
- ns
- name
- text
-
XMLStreamException
public String toString()
toString
in class Object
|
deegree-core-3.0-pre-nightly (2010/03/05 00:01) - official | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |