|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.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.
Supported types include:
Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Short
Singleton
Storable
String
int
, double
, char
, ...)
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 |
parseAttributes(Map<String,String> map)
This method parses a map of attribute, i.e. |
|
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"
- See Also:
parseAttributes(Map)
public static void appendObjectWithTags(StringBuffer xml, Object s, String tag)
Object
with the tags to the StringBuffer
xml
.
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 framedparseAttributes(Map)
,
appendObjectWithTagsAndAttributes(StringBuffer, Object, String, String, boolean)
public static void appendObjectWithTagsAndAttributes(StringBuffer xml, Object s, String tag, String attributes)
Object
with the tags and attributes to the StringBuffer
xml
.
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:
parseAttributes(Map)
,
appendObjectWithTagsAndAttributes(StringBuffer, Object, String, String, boolean)
public static void appendObjectWithTagsAndAttributes(StringBuffer xml, Object s, String tag, String attributes, boolean writeClassInfo)
Object
with the tags and attributes to the StringBuffer
xml
.
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:
parseAttributes(Map)
,
extractObjectAndAttributesForTags(StringBuffer, String, Map, Map, Class)
public static String parseAttributes(Map<String,String> map)
map
- the Map
of attribute names and values
String
representation of the attributesparseAttributes(String)
public static StringBuffer extractForTag(StringBuffer source, String tag) throws NonParsableException
source
between tag
start and end tags.
source
- the XML-code containing start and end tagtag
- the tag (without angle brackets)
StringBuffer
NonParsableException
- if start or end tag could not be foundpublic static StringBuffer extractForTag(StringBuffer source, String tag, Map<String,String> attributes, Map<String,String> filterAttributes) throws NonParsableException
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
.
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
StringBuffer
, if the XML does not contain such a tagged entry, the method returns null
NonParsableException
- if the XML is malformedpublic static boolean hasTag(StringBuffer source, String tag, Map<String,String> attributes, Map<String,String> filterAttributes) throws NonParsableException
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
true
if the XML contains such a tag, otherwise false
NonParsableException
- if the XML is malformedpublic static Object extractObjectForTags(StringBuffer xml, String tag) throws NonParsableException
xml
- the source StringBuffer
that should be decoded from XMLtag
- the tags between which the value shall be taken
NonParsableException
- if the value could not be parsedextractObjectAndAttributesForTags(StringBuffer, String, Map, Map, Class)
public static <T> T extractObjectForTags(StringBuffer xml, String tag, Class<T> k) throws NonParsableException
T
- the type of the parsed objectxml
- 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
NonParsableException
- if the value could not be parsedextractObjectAndAttributesForTags(StringBuffer, String, Map, Map, Class)
public static Object extractObjectAndAttributesForTags(StringBuffer xml, String tag, Map<String,String> attributes, Map<String,String> filterAttributes) throws NonParsableException
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
NonParsableException
- if the value could not be parsedextractObjectAndAttributesForTags(StringBuffer, String, Map, Map, Class)
public static <T> T extractObjectAndAttributesForTags(StringBuffer xml, String tag, Map<String,String> attributes, Map<String,String> filterAttributes, Class<T> k) throws NonParsableException
T
- the type of the parsed objectxml
- 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
NonParsableException
- if the value could not be parsedappendObjectWithTagsAndAttributes(StringBuffer, Object, String, String, boolean)
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
outerInstance
.
T
- the type of the parsed objectS
- the type of the outer objectxml
- 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
NonParsableException
- if the value could not be parsedappendObjectWithTagsAndAttributes(StringBuffer, Object, String, String, boolean)
public static String parseString(String original)
original
String
to null
if original
equals "null".
original
- the original String
null
or original
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |