Package org.xmlpull.v1.wrapper.classic
Class StaticXmlSerializerWrapper
- java.lang.Object
-
- org.xmlpull.v1.wrapper.classic.XmlSerializerDelegate
-
- org.xmlpull.v1.wrapper.classic.StaticXmlSerializerWrapper
-
- All Implemented Interfaces:
XmlSerializerWrapper,XmlSerializer
public class StaticXmlSerializerWrapper extends XmlSerializerDelegate implements XmlSerializerWrapper
This class seemlesly extends exisiting serialzier implementation by adding new methods (provided by XmlPullUtil) and delegating exisiting methods to parser implementation.- Author:
- Aleksander Slominski, Naresh Bhatia
-
-
Field Summary
Fields Modifier and Type Field Description protected StringcurrentNsprotected XmlPullParserWrapperfragmentParserprotected int[]namespaceDepthprotected intnamespaceEndprotected String[]namespacePrefixprotected String[]namespaceUriprotected XmlPullWrapperFactorywf-
Fields inherited from class org.xmlpull.v1.wrapper.classic.XmlSerializerDelegate
xs
-
Fields inherited from interface org.xmlpull.v1.wrapper.XmlSerializerWrapper
NO_NAMESPACE, XSD_NS, XSI_NS
-
-
Constructor Summary
Constructors Constructor Description StaticXmlSerializerWrapper(XmlSerializer xs, XmlPullWrapperFactory wf)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description XmlSerializerWrapperattribute(String name, String value)Write an attribute without namespace.XmlSerializerWrapperelement(String elementName, String elementText)Write simple text element in current namespaceXmlSerializerWrapperelement(String namespace, String elementName, String elementText)Writes a simple element such as <username>johndoe</username>.XmlSerializerWrapperendTag(String name)Write end tag in current namespace with name given as argument.StringescapeAttributeValue(String value)StringescapeText(String text)voidevent(XmlPullParser pp)Serializer current event form pull parservoidfragment(String xmlFragment)Write XML fragment using currently set namespace prefixesStringgetCurrentNamespaceForElements()Get namespace that is used as default when no namespace parameter is used for startTag(), endTag() and element()StringsetCurrentNamespaceForElements(String value)Set namespace to use in startTag(), endTag() and element() when methods called are those without namespace parameter.voidsetPrefix(String prefix, String namespace)Binds the given prefix to the given namespace.XmlSerializerWrapperstartTag(String name)Write start tag in current namespace with name given as argument.voidwriteDouble(double d)voidwriteDoubleElement(String namespace, String name, double d)voidwriteFloat(float f)voidwriteFloatElement(String namespace, String name, float f)voidwriteInt(int i)voidwriteIntElement(String namespace, String name, int i)voidwriteString(String s)voidwriteStringElement(String namespace, String name, String s)-
Methods inherited from class org.xmlpull.v1.wrapper.classic.XmlSerializerDelegate
attribute, cdsect, comment, docdecl, endDocument, endTag, entityRef, flush, getDepth, getFeature, getName, getNamespace, getPrefix, getProperty, ignorableWhitespace, processingInstruction, setFeature, setOutput, setOutput, setProperty, startDocument, startTag, text, text
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.xmlpull.v1.XmlSerializer
attribute, cdsect, comment, docdecl, endDocument, endTag, entityRef, flush, getDepth, getFeature, getName, getNamespace, getPrefix, getProperty, ignorableWhitespace, processingInstruction, setFeature, setOutput, setOutput, setProperty, startDocument, startTag, text, text
-
-
-
-
Field Detail
-
currentNs
protected String currentNs
-
wf
protected XmlPullWrapperFactory wf
-
fragmentParser
protected XmlPullParserWrapper fragmentParser
-
namespaceEnd
protected int namespaceEnd
-
namespacePrefix
protected String[] namespacePrefix
-
namespaceUri
protected String[] namespaceUri
-
namespaceDepth
protected int[] namespaceDepth
-
-
Constructor Detail
-
StaticXmlSerializerWrapper
public StaticXmlSerializerWrapper(XmlSerializer xs, XmlPullWrapperFactory wf)
-
-
Method Detail
-
getCurrentNamespaceForElements
public String getCurrentNamespaceForElements()
Description copied from interface:XmlSerializerWrapperGet namespace that is used as default when no namespace parameter is used for startTag(), endTag() and element()- Specified by:
getCurrentNamespaceForElementsin interfaceXmlSerializerWrapper
-
setCurrentNamespaceForElements
public String setCurrentNamespaceForElements(String value)
Description copied from interface:XmlSerializerWrapperSet namespace to use in startTag(), endTag() and element() when methods called are those without namespace parameter.- Specified by:
setCurrentNamespaceForElementsin interfaceXmlSerializerWrapper
-
attribute
public XmlSerializerWrapper attribute(String name, String value) throws IOException, IllegalArgumentException, IllegalStateException
Description copied from interface:XmlSerializerWrapperWrite an attribute without namespace. Calls to attribute() MUST follow a call to startTag() immediately. If there is no prefix defined for the given namespace, a prefix will be defined automatically. NOTE: current element namespace is not used attribute and attributre has no namespace.- Specified by:
attributein interfaceXmlSerializerWrapper- Throws:
IOExceptionIllegalArgumentExceptionIllegalStateException
-
startTag
public XmlSerializerWrapper startTag(String name) throws IOException, IllegalArgumentException, IllegalStateException
Description copied from interface:XmlSerializerWrapperWrite start tag in current namespace with name given as argument.- Specified by:
startTagin interfaceXmlSerializerWrapper- Throws:
IOExceptionIllegalArgumentExceptionIllegalStateException
-
endTag
public XmlSerializerWrapper endTag(String name) throws IOException, IllegalArgumentException, IllegalStateException
Description copied from interface:XmlSerializerWrapperWrite end tag in current namespace with name given as argument.- Specified by:
endTagin interfaceXmlSerializerWrapper- Throws:
IOExceptionIllegalArgumentExceptionIllegalStateException
-
element
public XmlSerializerWrapper element(String elementName, String elementText) throws IOException, XmlPullParserException
Write simple text element in current namespace- Specified by:
elementin interfaceXmlSerializerWrapper- Throws:
IOExceptionXmlPullParserException
-
element
public XmlSerializerWrapper element(String namespace, String elementName, String elementText) throws IOException, XmlPullParserException
Description copied from interface:XmlSerializerWrapperWrites a simple element such as <username>johndoe</username>. The namespace and elementText are allowed to be null. If elementText is null, an xsi:nil="true" will be added as an attribute.- Specified by:
elementin interfaceXmlSerializerWrapper- Throws:
IOExceptionXmlPullParserException
-
setPrefix
public void setPrefix(String prefix, String namespace) throws IOException, IllegalArgumentException, IllegalStateException
Description copied from interface:XmlSerializerBinds the given prefix to the given namespace. This call is valid for the next element including child elements. The prefix and namespace MUST be always declared even if prefix is not used in element (startTag() or attribute()) - for XML 1.0 it must result in declaringxmlns:prefix='namespace'(orxmlns:prefix="namespace"depending what character is used to quote attribute value).NOTE: this method MUST be called directly before startTag() and if anything but startTag() or setPrefix() is called next there will be exception.
NOTE: prefixes "xml" and "xmlns" are already bound and can not be redefined see: Namespaces in XML Errata.
NOTE: to set default namespace use as prefix empty string.
- Specified by:
setPrefixin interfaceXmlSerializer- Overrides:
setPrefixin classXmlSerializerDelegate- Parameters:
prefix- must be not null (or IllegalArgumentException is thrown)namespace- must be not null- Throws:
IOExceptionIllegalArgumentExceptionIllegalStateException
-
fragment
public void fragment(String xmlFragment) throws IOException, IllegalArgumentException, IllegalStateException, XmlPullParserException
Description copied from interface:XmlSerializerWrapperWrite XML fragment using currently set namespace prefixes- Specified by:
fragmentin interfaceXmlSerializerWrapper- Throws:
IOExceptionIllegalArgumentExceptionIllegalStateExceptionXmlPullParserException
-
event
public void event(XmlPullParser pp) throws XmlPullParserException, IOException
Description copied from interface:XmlSerializerWrapperSerializer current event form pull parser- Specified by:
eventin interfaceXmlSerializerWrapper- Throws:
XmlPullParserExceptionIOException
-
escapeAttributeValue
public String escapeAttributeValue(String value)
- Specified by:
escapeAttributeValuein interfaceXmlSerializerWrapper
-
escapeText
public String escapeText(String text)
- Specified by:
escapeTextin interfaceXmlSerializerWrapper
-
writeDouble
public void writeDouble(double d) throws XmlPullParserException, IOException, IllegalArgumentException
-
writeFloat
public void writeFloat(float f) throws XmlPullParserException, IOException, IllegalArgumentException
-
writeInt
public void writeInt(int i) throws XmlPullParserException, IOException, IllegalArgumentException
-
writeString
public void writeString(String s) throws XmlPullParserException, IOException, IllegalArgumentException
-
writeDoubleElement
public void writeDoubleElement(String namespace, String name, double d) throws XmlPullParserException, IOException, IllegalArgumentException
-
writeFloatElement
public void writeFloatElement(String namespace, String name, float f) throws XmlPullParserException, IOException, IllegalArgumentException
-
writeIntElement
public void writeIntElement(String namespace, String name, int i) throws XmlPullParserException, IOException, IllegalArgumentException
-
writeStringElement
public void writeStringElement(String namespace, String name, String s) throws XmlPullParserException, IOException, IllegalArgumentException
-
-