| Constructor and Description |
|---|
XMLParser() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addTags(StringBuffer source,
String tag)
|
static void |
addTagsAndAttributes(StringBuffer source,
String tag,
String attributes)
|
static void |
appendObjectWithTags(StringBuffer xml,
Object s,
String tag)
|
static void |
appendObjectWithTagsAndAttributes(StringBuffer xml,
Object s,
String tag,
String attributes)
|
static void |
appendObjectWithTagsAndAttributes(StringBuffer xml,
Object s,
String tag,
String attributes,
boolean writeClassInfo)
|
static void |
appendSequencesWithTags(StringBuffer xml,
String tag,
Sequence... seqs)
|
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 <T> T |
extractObjectAndAttributesForTags(StringBuffer xml,
String tag,
Map<String,String> attributes,
Map<String,String> filterAttributes,
Class<T> k)
Returns the parsed value between the tags.
|
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)
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 <T> T |
extractObjectForTags(StringBuffer xml,
String tag,
Class<T> k)
Returns the parsed value between the tags.
|
static Sequence[] |
extractSequencesWithTags(StringBuffer xml,
String tag)
Extracts a set of sequences from their XML representation.
|
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)
|
public static void addTags(StringBuffer source, String 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)
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)
-
appendObjectWithTags
public static void appendObjectWithTags(StringBuffer xml,
Object s,
String tag)
- 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:
parseAttributes(Map),
appendObjectWithTagsAndAttributes(StringBuffer, Object, String, String, boolean)
-
appendObjectWithTagsAndAttributes
public static void appendObjectWithTagsAndAttributes(StringBuffer xml,
Object s,
String tag,
String attributes)
- 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:parseAttributes(Map),
appendObjectWithTagsAndAttributes(StringBuffer, Object, String, String, boolean)
-
appendObjectWithTagsAndAttributes
public static void appendObjectWithTagsAndAttributes(StringBuffer xml,
Object s,
String tag,
String attributes,
boolean writeClassInfo)
- 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:parseAttributes(Map),
extractObjectAndAttributesForTags(StringBuffer, String, Map, Map, Class)
-
parseAttributes
public static String parseAttributes(Map<String,String> map)
This method parses a map of attribute, i.e. key-value-pairs, to a String representation that is used
for encoding XML.
- Parameters:
map - the Map of attribute names and values
- Returns:
- the
String representation of the attributes - See Also:
parseAttributes(String)
-
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)
-
appendSequencesWithTags
public static void appendSequencesWithTags(StringBuffer xml,
String tag,
Sequence... seqs)
Stores a set of Sequences to XML, although Sequence does not implement Storable.
Use for general data storage is discouraged and should be limited to those cases, where a Sequence needs
to the stored within another object implementing Storable.
- Parameters:
xml - the XML buffertag - the tagseqs - the sequences
-
extractSequencesWithTags
public static Sequence[] extractSequencesWithTags(StringBuffer xml,
String tag)
throws NonParsableException,
WrongAlphabetException
Extracts a set of sequences from their XML representation.
Use for general data storage is discouraged and should be limited to those cases, where a Sequence needs
to the stored within another object implementing Storable.
- Parameters:
xml - the XML buffertag - the tag
- Returns:
- the sequences
- Throws:
NonParsableException - if the XML could not be parsed
WrongAlphabetException - if the alphabet does not fit the sequence information