|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.util.XmlHelper
public class XmlHelper
a helper class that allows to easily handle some aspects of an xml source element
and also provides some convenient utility functions.
Note that this implementation is not synchronized as all operations work on the element
that could easily itself be altered outside this instance in another thread
- which should be avoided, of course.
The only method that will actually change the identity of the embedded element itself
is importXML(InputStream).
setBuilderFactory(Class),
DatatypeConverter,
Serialized Form| Constructor Summary | |
|---|---|
XmlHelper(DocumentBuilder builder,
InputSource source)
|
|
XmlHelper(Element element)
|
|
XmlHelper(InputSource source)
|
|
XmlHelper(String sourceXml)
|
|
XmlHelper(URL url)
|
|
| Method Summary | ||
|---|---|---|
void |
addBinaryElement(String tagName,
InputStream in)
|
|
Element |
addElement(String tagName,
String value)
adds the generated element (which is also returned) to the given element |
|
Node |
append(Element node,
XMLSerializable xs)
|
|
static Node |
append(Element node,
XMLSerializable xs,
DocumentBuilder builder)
|
|
Node |
append(XMLSerializable xs)
|
|
Node |
append(XMLSerializable xs,
DocumentBuilder builder)
|
|
boolean |
containsTag(String name)
|
|
int |
countTags(String tagName)
|
|
static XmlHelper |
createDocument(String documentElementName)
|
|
static Element |
createElement(InputSource source)
used by the constructor to generate the element stored internally |
|
static Element |
createElement(String source)
used by the constructor to generate the element stored internally |
|
static
|
deserializeXML(String xml)
|
|
static
|
deserializeXML(String xml,
boolean throwExceptions)
|
|
void |
exportXML(OutputStream out)
exports the entire object as XML and writes it to the given Writer, so that the object can be reconstructed with importXML(InputSource). |
|
String[] |
getAllTagText(String tagName)
|
|
byte[] |
getBinaryTagData(String tagName)
|
|
ArrayList<Element> |
getChildElements(boolean all)
if all is false, only direct child elements are returned |
|
ArrayList<Element> |
getChildElements(String tagName,
boolean all)
if all is false, only direct child elements are returned |
|
static DocumentBuilder |
getDocumentBuilder()
|
|
Element |
getElement()
|
|
Element |
getFirstChild(String tagName,
boolean all)
if all is false, only a direct child element is returned |
|
InputSource |
getInputSource()
|
|
InputStream |
getInputStream()
|
|
XmlHelper |
getParent()
|
|
static Hashtable<Class<?>,PersistenceDelegate> |
getPersistenceDelegates()
allows to register PersistenceDelegate instances for customizing the XML serialization |
|
String |
getTagText(String tagName)
returns the text for the first tag found with the given name |
|
String |
getTagText(String tag,
String defaultValue)
|
|
static PersistenceDelegate |
getToStringDelegator()
very useful to provide PersistenceDelegate instances for
classes, that can be best created by passing their toString()-value
to the constructor. |
|
void |
importXML(InputStream source)
The object is fully reinitialized with the XML data contained in the given ImputSource, so that the object has the same state as it had during export. |
|
static void |
readIntoXMLSerializable(Element node,
XMLSerializable xs)
|
|
boolean |
removeFirstTag(String tagName)
|
|
int |
removeTags(String tagName,
boolean all)
if all is false, only those elements that have the root as the parent are removed |
|
static String |
serializeXML(Object object)
calls serializeXML(Object, boolean) with the option true |
|
static String |
serializeXML(Object object,
boolean throwExceptions)
first uses serializeXML(XMLSerializable) if applicable and then
takes the delegates configured in getPersistenceDelegates() to call. |
|
static String |
serializeXML(Object object,
Map<Class<?>,PersistenceDelegate> delegates)
|
|
static String |
serializeXML(Object object,
Map<Class<?>,PersistenceDelegate> delegates,
boolean throwExceptions)
|
|
static String |
serializeXML(XMLSerializable object)
|
|
static void |
setBuilderFactory(Class<?> factoryClass)
|
|
void |
setTagText(String tagName,
String value)
|
|
void |
storeTo(OutputStream out)
stores the xml as reformatted xml in utf8 (including flushing/closing) |
|
String |
toDetailedString()
returns the reformatted xml in utf8 encoding |
|
static String |
toXmlString(XMLSerializable xs)
|
|
Element |
unwrap()
returns the embedded instance that this wrapper encloses |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public XmlHelper(URL url)
throws SAXException,
IOException,
ParserConfigurationException
SAXException
IOException
ParserConfigurationException
public XmlHelper(String sourceXml)
throws SAXException,
IOException,
ParserConfigurationException
SAXException
IOException
ParserConfigurationException
public XmlHelper(InputSource source)
throws SAXException,
IOException,
ParserConfigurationException
SAXException
IOException
ParserConfigurationException
public XmlHelper(DocumentBuilder builder,
InputSource source)
throws SAXException,
IOException,
ParserConfigurationException
SAXException
IOException
ParserConfigurationExceptionpublic XmlHelper(Element element)
| Method Detail |
|---|
public static void setBuilderFactory(Class<?> factoryClass)
com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl,
DocumentBuilderFactory.newInstance()
public static DocumentBuilder getDocumentBuilder()
throws ParserConfigurationException
ParserConfigurationException
public static Element createElement(String source)
throws SAXException,
IOException,
ParserConfigurationException
SAXException
IOException
ParserConfigurationException
public static Element createElement(InputSource source)
throws SAXException,
IOException,
ParserConfigurationException
SAXException
IOException
ParserConfigurationException
public static XmlHelper createDocument(String documentElementName)
throws ParserConfigurationException
ParserConfigurationExceptionpublic XmlHelper getParent()
public ArrayList<Element> getChildElements(boolean all)
public ArrayList<Element> getChildElements(String tagName,
boolean all)
public Element getFirstChild(String tagName,
boolean all)
public String[] getAllTagText(String tagName)
public String getTagText(String tagName)
public String getTagText(String tag,
String defaultValue)
public void setTagText(String tagName,
String value)
public void addBinaryElement(String tagName,
InputStream in)
throws IOException
IOException
public byte[] getBinaryTagData(String tagName)
throws IOException
IOException
public Element addElement(String tagName,
String value)
public Node append(XMLSerializable xs)
throws IOException,
SAXException,
ParserConfigurationException
IOException
SAXException
ParserConfigurationException
public Node append(XMLSerializable xs,
DocumentBuilder builder)
throws IOException,
SAXException
IOException
SAXException
public Node append(Element node,
XMLSerializable xs)
throws IOException,
SAXException,
ParserConfigurationException
IOException
SAXException
ParserConfigurationException
public static Node append(Element node,
XMLSerializable xs,
DocumentBuilder builder)
throws IOException,
SAXException
IOException
SAXException
public static void readIntoXMLSerializable(Element node,
XMLSerializable xs)
throws IOException,
ClassCastException,
SAXException
IOException
ClassCastException
SAXException
public static String toXmlString(XMLSerializable xs)
throws IOException
IOExceptionpublic int countTags(String tagName)
public boolean removeFirstTag(String tagName)
public int removeTags(String tagName,
boolean all)
public boolean containsTag(String name)
public InputSource getInputSource()
public String toDetailedString()
toDetailedString in interface DetailedStringpublic InputStream getInputStream()
public void storeTo(OutputStream out)
throws IOException
IOExceptionpublic final Element getElement()
public final Element unwrap()
Wrapped
unwrap in interface Wrapped<Element>
public void exportXML(OutputStream out)
throws IOException
XMLSerializableimportXML(InputSource).
The given stream is neither flushed nor closed, so that other data may be
effectively written to the InputSource after the method returned.
exportXML in interface XMLSerializableIOExceptionXMLSerializable.importXML(InputStream)
public void importXML(InputStream source)
throws SAXException,
IOException
XMLSerializable
importXML in interface XMLSerializableSAXException
IOExceptionXMLSerializable.exportXML(OutputStream)public static PersistenceDelegate getToStringDelegator()
PersistenceDelegate instances for
classes, that can be best created by passing their toString()-value
to the constructor.
URL,
BigDecimalpublic static Hashtable<Class<?>,PersistenceDelegate> getPersistenceDelegates()
serializeXML(Object, boolean)public static String serializeXML(Object object)
serializeXML(Object, boolean) with the option true
public static String serializeXML(Object object,
boolean throwExceptions)
serializeXML(XMLSerializable) if applicable and then
takes the delegates configured in getPersistenceDelegates() to call.
throwExceptions - will be ignored if the object parameter is XMLSerializable
serializeXML(Object, Map, boolean)public static String serializeXML(XMLSerializable object)
public static String serializeXML(Object object,
Map<Class<?>,PersistenceDelegate> delegates)
public static String serializeXML(Object object,
Map<Class<?>,PersistenceDelegate> delegates,
boolean throwExceptions)
public static <T> T deserializeXML(String xml)
deserializeXML(String, boolean)
@Warning(value="the return value may be unsavely casted if generics are involved")
public static <T> T deserializeXML(String xml,
boolean throwExceptions)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||