|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.jstacs.io.XMLParser
public final class XMLParser
Class for parsing standard data types and arrays in and out of an XML
File
. The methods with prefix append
or
add
are for encoding, while methods with prefix
extract
are for decoding.
Constructor Summary | |
---|---|
XMLParser()
|
Method Summary | ||
---|---|---|
static void |
addTags(StringBuffer source,
String tag)
Frames the StringBuffer source with equal tags
"< tag >" and "</tag
>". |
|
static void |
addTagsAndAttributes(StringBuffer source,
String tag,
String attributes)
Frames the StringBuffer source with "<
tag attributes >" and "</tag
>". |
|
static void |
appendObjectWithTags(StringBuffer xml,
Object s,
String tag)
Appends an Object with the tags to the StringBuffer xml . |
|
static void |
appendObjectWithTagsAndAttributes(StringBuffer xml,
Object s,
String tag,
String attributes)
Appends an Object with the tags and attributes to the StringBuffer xml . |
|
static void |
appendObjectWithTagsAndAttributes(StringBuffer xml,
Object s,
String tag,
String attributes,
boolean writeClassInfo)
Appends an Object with the tags and attributes to the StringBuffer xml . |
|
static StringBuffer |
extractForTag(StringBuffer source,
String tag)
Extracts the contents of source between tag start and end tags. |
|
static StringBuffer |
extractForTag(StringBuffer source,
String tag,
Map<String,String> attributes,
Map<String,String> filterAttributes)
Extracts the contents of source between tag start and end tags. |
|
static Object |
extractObjectAndAttributesForTags(StringBuffer xml,
String tag,
Map<String,String> attributes,
Map<String,String> filterAttributes)
Returns the parsed value between the tags. |
|
static
|
extractObjectAndAttributesForTags(StringBuffer xml,
String tag,
Map<String,String> attributes,
Map<String,String> filterAttributes,
Class<T> k)
Returns the parsed value between the tags. |
|
static
|
extractObjectAndAttributesForTags(StringBuffer xml,
String tag,
Map<String,String> attributes,
Map<String,String> filterAttributes,
Class<T> k,
Class<S> outerClass,
S outerInstance)
Returns the parsed value between the tags as an inner instance of the object outerInstance . |
|
static Object |
extractObjectForTags(StringBuffer xml,
String tag)
Returns the parsed value between the tags. |
|
static
|
extractObjectForTags(StringBuffer xml,
String tag,
Class<T> k)
Returns the parsed value between the tags. |
|
static boolean |
hasTag(StringBuffer source,
String tag,
Map<String,String> attributes,
Map<String,String> filterAttributes)
This method allows to check whether an XML contains a tagged entry. |
|
static String |
parseString(String original)
This method parses the original String to null if original equals "null". |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XMLParser()
Method Detail |
---|
public static void addTags(StringBuffer source, String tag)
StringBuffer
source
with equal tags
"< tag
>" and "</tag
>".
source
- the source StringBuffer
that should be encoded in XMLtag
- the tags by which the StringBuffer
should be framedaddTagsAndAttributes(StringBuffer, String, String)
public static void addTagsAndAttributes(StringBuffer source, String tag, String attributes)
StringBuffer
source
with "<
tag attributes
>" and "</tag
>".
source
- the source StringBuffer
that should be encoded in XMLtag
- the tags by which the StringBuffer
should be framedattributes
- null or some attributes, i.e. value="100" confidence="0"
appendObjectWithTags
public static void appendObjectWithTags(StringBuffer xml,
Object s,
String tag)
- Appends an
Object
with the tags to the StringBuffer
xml
.
- Parameters:
xml
- the source StringBuffer
that should be encoded in XMLs
- the object that should be framed by the tags and appended to the source,
s
might be null
, Storable
, String
, primitive type,
wrapper class of a primitive type, or any array thereoftag
- the tags by which the value should be framed- See Also:
appendObjectWithTagsAndAttributes(StringBuffer, Object, String, String, boolean)
appendObjectWithTagsAndAttributes
public static void appendObjectWithTagsAndAttributes(StringBuffer xml,
Object s,
String tag,
String attributes)
- Appends an
Object
with the tags and attributes to the StringBuffer
xml
.
- Parameters:
xml
- the source StringBuffer
that should be encoded in XMLs
- the object that should be framed by the tags and appended to the source,
s
might be null
, Storable
, String
, primitive type,
wrapper class of a primitive type, or any array thereoftag
- the tags by which the value should be framedattributes
- null or some attributes, e.g., value="100" confidence="0"
See Also:
appendObjectWithTagsAndAttributes(StringBuffer, Object, String, String, boolean)
appendObjectWithTagsAndAttributes
public static void appendObjectWithTagsAndAttributes(StringBuffer xml,
Object s,
String tag,
String attributes,
boolean writeClassInfo)
- Appends an
Object
with the tags and attributes to the StringBuffer
xml
.
- Parameters:
xml
- the source StringBuffer
that should be encoded in XMLs
- the object that should be framed by the tags and appended to the source,
s
might be null
, Storable
, String
, primitive type,
wrapper class of a primitive type, or any array thereoftag
- the tags by which the value should be framedattributes
- null or some attributes, e.g., value="100" confidence="0"
writeClassInfo
- a boolean to enable to write class information (e.g. Class.getSimpleName()
) of the Object
s
into the XML.
See Also:
extractObjectAndAttributesForTags(StringBuffer, String, Map, Map, Class)
extractForTag
public static StringBuffer extractForTag(StringBuffer source,
String tag)
throws NonParsableException
- Extracts the contents of
source
between tag
start and end tags.
- Parameters:
source
- the XML-code containing start and end tagtag
- the tag (without angle brackets)
- Returns:
- the contents of start and end tags, without these tags, as a
StringBuffer
- Throws:
NonParsableException
- if start or end tag could not be found
extractForTag
public static StringBuffer extractForTag(StringBuffer source,
String tag,
Map<String,String> attributes,
Map<String,String> filterAttributes)
throws NonParsableException
- Extracts the contents of
source
between tag
start and end tags.
If attributes
is not null
, the attributes of the start tag are added to this Map
.
If filterAttributes
is not null
, the start tag is accepted only if its attributes and associated values contain those defined in filterAttributed
.
- Parameters:
source
- the XML-code containing start and end tagtag
- the tag (without angle brackets)attributes
- a Map
for attributes and values, or null
if no attributes should be parsed.filterAttributes
- a Map
of attributes and associated values, which must be present in the attributes of the start tag, or null
for no filtering
- Returns:
- the contents of start and end tags, without these tags, as a
StringBuffer
, if the XML does not contain such a tagged entry, the method returns null
- Throws:
NonParsableException
- if the XML is malformed
hasTag
public static boolean hasTag(StringBuffer source,
String tag,
Map<String,String> attributes,
Map<String,String> filterAttributes)
throws NonParsableException
- This method allows to check whether an XML contains a tagged entry.
- Parameters:
source
- the XML-code containing start and end tagtag
- the tag (without angle brackets)attributes
- a Map
for attributes and values, or null
if no attributes should be parsed.filterAttributes
- a Map
of attributes and associated values, which must be present in the attributes of the start tag, or null
for no filtering
- Returns:
true
if the XML contains such a tag, otherwise false
- Throws:
NonParsableException
- if the XML is malformed
extractObjectForTags
public static Object extractObjectForTags(StringBuffer xml,
String tag)
throws NonParsableException
- Returns the parsed value between the tags.
- Parameters:
xml
- the source StringBuffer
that should be decoded from XMLtag
- the tags between which the value shall be taken
- Returns:
- the value between the tags
- Throws:
NonParsableException
- if the value could not be parsed- See Also:
extractObjectAndAttributesForTags(StringBuffer, String, Map, Map, Class)
extractObjectForTags
public static <T> T extractObjectForTags(StringBuffer xml,
String tag,
Class<T> k)
throws NonParsableException
- Returns the parsed value between the tags.
- Type Parameters:
T
- the type of the parsed object- Parameters:
xml
- the source StringBuffer
that should be decoded from XMLtag
- the tags between which the value shall be takenk
- the class used to parse the value between the tag, if null
the class will be inferred from the XML
- Returns:
- the value between the tags
- Throws:
NonParsableException
- if the value could not be parsed- See Also:
extractObjectAndAttributesForTags(StringBuffer, String, Map, Map, Class)
extractObjectAndAttributesForTags
public static Object extractObjectAndAttributesForTags(StringBuffer xml,
String tag,
Map<String,String> attributes,
Map<String,String> filterAttributes)
throws NonParsableException
- Returns the parsed value between the tags.
- Parameters:
xml
- the source StringBuffer
that should be decoded from XMLtag
- the tags between which the value shall be takenattributes
- a Map
which can be used to obtain the attribute of the tagfilterAttributes
- a Map
which defines a filter for the tags
- Returns:
- the value between the tags
- Throws:
NonParsableException
- if the value could not be parsed- See Also:
extractObjectAndAttributesForTags(StringBuffer, String, Map, Map, Class)
extractObjectAndAttributesForTags
public static <T> T extractObjectAndAttributesForTags(StringBuffer xml,
String tag,
Map<String,String> attributes,
Map<String,String> filterAttributes,
Class<T> k)
throws NonParsableException
- Returns the parsed value between the tags.
- Type Parameters:
T
- the type of the parsed object- Parameters:
xml
- the source StringBuffer
that should be decoded from XMLtag
- the tags between which the value shall be takenattributes
- a Map
which can be used to obtain the attribute of the tagfilterAttributes
- a Map
which defines a filter for the tagsk
- the class used to parse the value between the tag, if null
the class will be inferred from the XML
- Returns:
- the value between the tags
- Throws:
NonParsableException
- if the value could not be parsed- See Also:
appendObjectWithTagsAndAttributes(StringBuffer, Object, String, String, boolean)
extractObjectAndAttributesForTags
public static <T,S> T extractObjectAndAttributesForTags(StringBuffer xml,
String tag,
Map<String,String> attributes,
Map<String,String> filterAttributes,
Class<T> k,
Class<S> outerClass,
S outerInstance)
throws NonParsableException
- Returns the parsed value between the tags as an inner instance of the object
outerInstance
.
- Type Parameters:
T
- the type of the parsed objectS
- the type of the outer object- Parameters:
xml
- the source StringBuffer
that should be decoded from XMLtag
- the tags between which the value shall be takenattributes
- a Map
which can be used to obtain the attribute of the tagfilterAttributes
- a Map
which defines a filter for the tagsk
- the class used to parse the value between the tag, if null
the class will be inferred from the XMLouterClass
- the class of the outer instance of the parsed objectouterInstance
- the outer instance of the parsed object
- Returns:
- the value between the tags
- Throws:
NonParsableException
- if the value could not be parsed- See Also:
appendObjectWithTagsAndAttributes(StringBuffer, Object, String, String, boolean)
parseString
public static String parseString(String original)
- This method parses the
original
String
to null
if original
equals "null".
- Parameters:
original
- the original String
- Returns:
null
or original
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD