Class XStreamDOM
- java.lang.Object
-
- jenkins.util.xstream.XStreamDOM
-
public class XStreamDOM extends Object
XML DOM like structure to preserve a portion of XStream data as-is, so that you can process it later in a separate XStream call.This object captures a subset of XML infoset that XStream understands. Namely, no XML namespace, no mixed content.
You use it as a field in your class (that itself participates in an XStream persistence), and have it receive the portion of that XML. Then later you can use
unmarshal(XStream)
to convert this sub-tree to an object with a possibly separate XStream instance.The reverse operation is
from(XStream, Object)
method, which marshals an object intoXStreamDOM
.You can also use this class to parse an entire XML document into a DOM like tree with
from(HierarchicalStreamReader)
andwriteTo(HierarchicalStreamWriter)
. These two methods support variants that accept other forms.Whereas the above methods read from and write to
HierarchicalStreamReader
and,HierarchicalStreamWriter
, we can also createHierarchicalStreamReader
that read from DOM andHierarchicalStreamWriter
that writes to DOM. SeenewReader()
andnewWriter()
for those operations.XStreamDOM as a field of another XStream-enabled class:
XStreamDOM
can be used as a type of a field of another class that's itself XStream-enabled, such as this:class Foo { XStreamDOM bar; }
With the following XML:<foo> <bar> <payload> ... </payload> </bar> </foo>
The
XStreamDOM
object in the bar field will have the "payload" element in its tag name (which means the bar element cannot have multiple children.)XStream and name escaping: Because XStream wants to use letters like '$' that's not legal as a name char in XML, the XML data model that it thinks of (unescaped) is actually translated into the actual XML-compliant infoset via
XmlFriendlyReplacer
. This translation is done byHierarchicalStreamReader
andHierarchicalStreamWriter
, transparently fromConverter
s. InXStreamDOM
, we'd like to hold the XML infoset (escaped form, in XStream speak), so in ourXStreamDOM.ConverterImpl
we go out of the way to cancel out this effect.- Since:
- 1.473
- Author:
- Kohsuke Kawaguchi
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
XStreamDOM.ConverterImpl
static class
XStreamDOM.WriterImpl
-
Field Summary
Fields Modifier and Type Field Description static com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer
REPLACER
-
Constructor Summary
Constructors Constructor Description XStreamDOM(String tagName, Map<String,String> attributes, String value)
XStreamDOM(String tagName, Map<String,String> attributes, List<XStreamDOM> children)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description XStreamDOM
expandMacro(VariableResolver<String> vars)
Recursively expands the variables in text and attribute values and return the new DOM.static XStreamDOM
from(com.thoughtworks.xstream.io.HierarchicalStreamReader in)
static XStreamDOM
from(com.thoughtworks.xstream.XStream xs, Object obj)
Marshals the given object with the given XStream intoXStreamDOM
and return it.static XStreamDOM
from(InputStream in)
static XStreamDOM
from(Reader in)
String
getAttribute(int index)
String
getAttribute(String name)
int
getAttributeCount()
Map<String,String>
getAttributeMap()
List<XStreamDOM>
getChildren()
String
getTagName()
String
getValue()
com.thoughtworks.xstream.io.HierarchicalStreamReader
newReader()
Returns a newHierarchicalStreamReader
that reads a sub-tree rooted at this node.static XStreamDOM.WriterImpl
newWriter()
Returns a newHierarchicalStreamWriter
for marshalling objects intoXStreamDOM
.<T> T
unmarshal(com.thoughtworks.xstream.XStream xs)
Unmarshals this DOM into an object via the given XStream.<T> T
unmarshal(com.thoughtworks.xstream.XStream xs, T root)
void
writeTo(com.thoughtworks.xstream.io.HierarchicalStreamWriter w)
void
writeTo(OutputStream os)
Writes thisXStreamDOM
intoOutputStream
.void
writeTo(Writer w)
-
-
-
Field Detail
-
REPLACER
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) @RestrictedSince("2.301") public static final com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer REPLACER
-
-
Method Detail
-
getTagName
public String getTagName()
-
unmarshal
public <T> T unmarshal(com.thoughtworks.xstream.XStream xs)
Unmarshals this DOM into an object via the given XStream.
-
unmarshal
public <T> T unmarshal(com.thoughtworks.xstream.XStream xs, T root)
-
expandMacro
public XStreamDOM expandMacro(VariableResolver<String> vars)
Recursively expands the variables in text and attribute values and return the new DOM. The expansion usesUtil.replaceMacro(String, VariableResolver)
, so any unresolved references will be left as-is.
-
getAttributeCount
public int getAttributeCount()
-
getAttribute
public String getAttribute(int index)
-
getValue
public String getValue()
-
getChildren
public List<XStreamDOM> getChildren()
-
newReader
public com.thoughtworks.xstream.io.HierarchicalStreamReader newReader()
Returns a newHierarchicalStreamReader
that reads a sub-tree rooted at this node.
-
newWriter
public static XStreamDOM.WriterImpl newWriter()
Returns a newHierarchicalStreamWriter
for marshalling objects intoXStreamDOM
. After the writer receives the calls, callXStreamDOM.WriterImpl.getOutput()
to obtain the populated tree.
-
writeTo
public void writeTo(OutputStream os)
Writes thisXStreamDOM
intoOutputStream
.
-
writeTo
public void writeTo(Writer w)
-
writeTo
public void writeTo(com.thoughtworks.xstream.io.HierarchicalStreamWriter w)
-
from
public static XStreamDOM from(com.thoughtworks.xstream.XStream xs, Object obj)
Marshals the given object with the given XStream intoXStreamDOM
and return it.
-
from
public static XStreamDOM from(InputStream in)
-
from
public static XStreamDOM from(Reader in)
-
from
public static XStreamDOM from(com.thoughtworks.xstream.io.HierarchicalStreamReader in)
-
-