Package com.l2fprod.contrib.nanoxml
Class XMLElement
- java.lang.Object
-
- com.l2fprod.contrib.nanoxml.XMLElement
-
- All Implemented Interfaces:
java.io.Serializable
public class XMLElement extends java.lang.Object implements java.io.SerializableXMLElement is a representation of an XML object. The object is able to parse XML code.Note that NanoXML is not 100% XML 1.0 compliant:
- The parser is non-validating.
- The DTD is fully ignored, including
<!ENTITY...>. - There is no support for mixed content (elements containing both subelements and CDATA elements)
You can opt to use a SAX compatible API, by including both
nanoxml.jarandnanoxml-sax.jarin your classpath and setting the propertyorg.xml.sax.parsertonanoxml.sax.SAXParser$Revision: 1.3 $
$Date: 2005/11/19 09:15:30 $- Version:
- 1.6
- Author:
- Marc De Scheemaecker < Marc.DeScheemaecker@advalvas.be >
- See Also:
XMLParseException, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intNANOXML_MAJOR_VERSIONMajor version of NanoXML.static intNANOXML_MINOR_VERSIONMinor version of NanoXML.
-
Constructor Summary
Constructors Modifier Constructor Description XMLElement()Creates a new XML element.XMLElement(boolean skipLeadingWhitespace)Creates a new XML element.XMLElement(java.util.Properties conversionTable)Creates a new XML element.XMLElement(java.util.Properties conversionTable, boolean skipLeadingWhitespace)Creates a new XML element.XMLElement(java.util.Properties conversionTable, boolean skipLeadingWhitespace, boolean ignoreCase)Creates a new XML element.protectedXMLElement(java.util.Properties conversionTable, boolean skipLeadingWhitespace, boolean fillBasicConversionTable, boolean ignoreCase)Creates a new XML element.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(XMLElement child)Adds a subobject.voidaddProperty(java.lang.String key, double value)Adds a property.voidaddProperty(java.lang.String key, int value)Adds a property.voidaddProperty(java.lang.String key, java.lang.Object value)Adds a property.intcountChildren()Returns the number of subobjects of the object.protected XMLElementcreateAnotherElement()Creates a new XML element.protected java.lang.StringdecodeString(java.lang.String s, int lineNr)Converts &...; sequences to "normal" chars.java.util.EnumerationenumerateChildren()Enumerates the subobjects of the object.java.util.EnumerationenumeratePropertyNames()Enumerates the attribute names.java.util.VectorgetChildren()Returns the subobjects of the object.java.lang.StringgetContents()Returns the #PCDATA content of the object.intgetIntProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)Returns a property by looking up a key in a hashtable.intgetLineNr()Returns the line nr on which the element is found.java.lang.StringgetProperty(java.lang.String key)Returns a property of the object.doublegetProperty(java.lang.String key, double defaultValue)Returns a floating point property of the object.intgetProperty(java.lang.String key, int defaultValue)Returns an integer property of the object.java.lang.StringgetProperty(java.lang.String key, java.lang.String defaultValue)Returns a property of the object.booleangetProperty(java.lang.String key, java.lang.String trueValue, java.lang.String falseValue, boolean defaultValue)Returns a boolean property of the object.java.lang.ObjectgetProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)Returns a property by looking up a key in the hashtable valueSet If the property doesn't exist, the value corresponding to defaultValue is returned.doublegetSpecialDoubleProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)Returns a property by looking up a key in the hashtable valueSet .intgetSpecialIntProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)Returns a property by looking up a key in the hashtable valueSet .java.lang.StringgetStringProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)Returns a property by looking up a key in the hashtable valueSet .java.lang.StringgetTagName()Returns the class (i.e.intparseCharArray(char[] input, int offset, int end)Parses an XML definition starting at offset .intparseCharArray(char[] input, int offset, int end, int startingLineNr)Parses an XML definition starting at offset .voidparseFromReader(java.io.Reader reader)Reads an XML definition from a java.io.Reader and parses it.voidparseFromReader(java.io.Reader reader, int startingLineNr)Reads an XML definition from a java.io.Reader and parses it.voidparseString(java.lang.String string)Parses an XML definition.intparseString(java.lang.String string, int offset)Parses an XML definition starting at offset .intparseString(java.lang.String string, int offset, int end)Parses an XML definition starting at offset .intparseString(java.lang.String string, int offset, int end, int startingLineNr)Parses an XML definition starting at offset .voidremoveChild(XMLElement child)Removes a child object.voidremoveChild(java.lang.String key)Removes an attribute.protected voidscanChildren(char[] input, int contentOffset, int contentSize, int contentLineNr)!!! Searches the content for child objects.voidsetContent(java.lang.String content)Changes the content string.voidsetTagName(java.lang.String tagName)Changes the tag name.protected intskipBogusTag(char[] input, int offset, int end, int[] lineNr)Skips a tag that don't contain any useful data: <?...?>, <!...> and comments.java.lang.StringtoString()Writes the XML element to a string.voidwrite(java.io.Writer writer)Writes the XML element to a writer.voidwrite(java.io.Writer writer, int indent)Writes the XML element to a writer.protected voidwriteEncoded(java.io.PrintWriter out, java.lang.String str)Writes a string encoded to a writer.
-
-
-
Field Detail
-
NANOXML_MAJOR_VERSION
public static final int NANOXML_MAJOR_VERSION
Major version of NanoXML.- See Also:
- Constant Field Values
-
NANOXML_MINOR_VERSION
public static final int NANOXML_MINOR_VERSION
Minor version of NanoXML.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XMLElement
public XMLElement()
Creates a new XML element. The following settings are used:- Conversion table
- Minimal XML conversions:
& < > ' " - Skip whitespace in contents
-
false - Ignore Case
-
true
-
XMLElement
public XMLElement(java.util.Properties conversionTable)
Creates a new XML element. The following settings are used:- Conversion table
- conversionTable combined with the minimal XML conversions:
& < > ' " - Skip whitespace in contents
-
false - Ignore Case
-
true
- Parameters:
conversionTable- Description of Parameter- See Also:
XMLElement(),XMLElement(boolean),XMLElement(java.util.Properties,boolean)
-
XMLElement
public XMLElement(boolean skipLeadingWhitespace)
Creates a new XML element. The following settings are used:- Conversion table
- Minimal XML conversions:
& < > ' " - Skip whitespace in contents
- skipLeadingWhitespace
- Ignore Case
-
true
- Parameters:
skipLeadingWhitespace- Description of Parameter- See Also:
XMLElement(),XMLElement(java.util.Properties),XMLElement(java.util.Properties,boolean)
-
XMLElement
public XMLElement(java.util.Properties conversionTable, boolean skipLeadingWhitespace)Creates a new XML element. The following settings are used:- Conversion table
- conversionTable combined with the minimal XML conversions:
& < > ' " - Skip whitespace in contents
- skipLeadingWhitespace
- Ignore Case
-
true
- Parameters:
conversionTable- Description of ParameterskipLeadingWhitespace- Description of Parameter- See Also:
XMLElement(),XMLElement(boolean),XMLElement(java.util.Properties)
-
XMLElement
public XMLElement(java.util.Properties conversionTable, boolean skipLeadingWhitespace, boolean ignoreCase)Creates a new XML element. The following settings are used:- Conversion table
- conversionTable , eventually combined with the minimal XML
conversions:
& < > ' "(depending on fillBasicConversionTable ) - Skip whitespace in contents
- skipLeadingWhitespace
- Ignore Case
- ignoreCase
This constructor should only be called from XMLElement itself to create child elements.
- Parameters:
conversionTable- Description of ParameterskipLeadingWhitespace- Description of ParameterignoreCase- Description of Parameter- See Also:
XMLElement(),XMLElement(boolean),XMLElement(java.util.Properties),XMLElement(java.util.Properties,boolean)
-
XMLElement
protected XMLElement(java.util.Properties conversionTable, boolean skipLeadingWhitespace, boolean fillBasicConversionTable, boolean ignoreCase)Creates a new XML element. The following settings are used:- Conversion table
- conversionTable , eventually combined with the minimal XML
conversions:
& < > ' "(depending on fillBasicConversionTable ) - Skip whitespace in contents
- skipLeadingWhitespace
- Ignore Case
- ignoreCase
This constructor should only be called from XMLElement itself to create child elements.
- Parameters:
conversionTable- Description of ParameterskipLeadingWhitespace- Description of ParameterfillBasicConversionTable- Description of ParameterignoreCase- Description of Parameter- See Also:
XMLElement(),XMLElement(boolean),XMLElement(java.util.Properties),XMLElement(java.util.Properties,boolean)
-
-
Method Detail
-
setContent
public void setContent(java.lang.String content)
Changes the content string.- Parameters:
content- The new content string.
-
setTagName
public void setTagName(java.lang.String tagName)
Changes the tag name.- Parameters:
tagName- The new tag name.
-
getChildren
public java.util.Vector getChildren()
Returns the subobjects of the object.- Returns:
- The Children value
-
getContents
public java.lang.String getContents()
Returns the #PCDATA content of the object. If there is no such content,nullis returned.- Returns:
- The Contents value
-
getLineNr
public int getLineNr()
Returns the line nr on which the element is found.- Returns:
- The LineNr value
-
getIntProperty
public int getIntProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)Returns a property by looking up a key in a hashtable. If the property doesn't exist, the value corresponding to defaultValue is returned.- Parameters:
key- Description of ParametervalueSet- Description of ParameterdefaultValue- Description of Parameter- Returns:
- The IntProperty value
-
getProperty
public java.lang.String getProperty(java.lang.String key)
Returns a property of the object. If there is no such property, this method returnsnull.- Parameters:
key- Description of Parameter- Returns:
- The Property value
-
getProperty
public java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)Returns a property of the object. If the property doesn't exist, defaultValue is returned.- Parameters:
key- Description of ParameterdefaultValue- Description of Parameter- Returns:
- The Property value
-
getProperty
public int getProperty(java.lang.String key, int defaultValue)Returns an integer property of the object. If the property doesn't exist, defaultValue is returned.- Parameters:
key- Description of ParameterdefaultValue- Description of Parameter- Returns:
- The Property value
-
getProperty
public double getProperty(java.lang.String key, double defaultValue)Returns a floating point property of the object. If the property doesn't exist, defaultValue is returned.- Parameters:
key- Description of ParameterdefaultValue- Description of Parameter- Returns:
- The Property value
-
getProperty
public boolean getProperty(java.lang.String key, java.lang.String trueValue, java.lang.String falseValue, boolean defaultValue)Returns a boolean property of the object. If the property is missing, defaultValue is returned.- Parameters:
key- Description of ParametertrueValue- Description of ParameterfalseValue- Description of ParameterdefaultValue- Description of Parameter- Returns:
- The Property value
-
getProperty
public java.lang.Object getProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)Returns a property by looking up a key in the hashtable valueSet If the property doesn't exist, the value corresponding to defaultValue is returned.- Parameters:
key- Description of ParametervalueSet- Description of ParameterdefaultValue- Description of Parameter- Returns:
- The Property value
-
getStringProperty
public java.lang.String getStringProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)Returns a property by looking up a key in the hashtable valueSet . If the property doesn't exist, the value corresponding to defaultValue is returned.- Parameters:
key- Description of ParametervalueSet- Description of ParameterdefaultValue- Description of Parameter- Returns:
- The StringProperty value
-
getSpecialIntProperty
public int getSpecialIntProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)Returns a property by looking up a key in the hashtable valueSet . If the value is not defined in the hashtable, the value is considered to be an integer. If the property doesn't exist, the value corresponding to defaultValue is returned.- Parameters:
key- Description of ParametervalueSet- Description of ParameterdefaultValue- Description of Parameter- Returns:
- The SpecialIntProperty value
-
getSpecialDoubleProperty
public double getSpecialDoubleProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)Returns a property by looking up a key in the hashtable valueSet . If the value is not defined in the hashtable, the value is considered to be a floating point number. If the property doesn't exist, the value corresponding to defaultValue is returned.- Parameters:
key- Description of ParametervalueSet- Description of ParameterdefaultValue- Description of Parameter- Returns:
- The SpecialDoubleProperty value
-
getTagName
public java.lang.String getTagName()
Returns the class (i.e. the name indicated in the tag) of the object.- Returns:
- The TagName value
-
addChild
public void addChild(XMLElement child)
Adds a subobject.- Parameters:
child- The feature to be added to the Child attribute
-
addProperty
public void addProperty(java.lang.String key, java.lang.Object value)Adds a property. If the element is case insensitive, the property name is capitalized.- Parameters:
key- The feature to be added to the Property attributevalue- The feature to be added to the Property attribute
-
addProperty
public void addProperty(java.lang.String key, int value)Adds a property. If the element is case insensitive, the property name is capitalized.- Parameters:
key- The feature to be added to the Property attributevalue- The feature to be added to the Property attribute
-
addProperty
public void addProperty(java.lang.String key, double value)Adds a property. If the element is case insensitive, the property name is capitalized.- Parameters:
key- The feature to be added to the Property attributevalue- The feature to be added to the Property attribute
-
countChildren
public int countChildren()
Returns the number of subobjects of the object.- Returns:
- Description of the Returned Value
-
enumeratePropertyNames
public java.util.Enumeration enumeratePropertyNames()
Enumerates the attribute names.- Returns:
- Description of the Returned Value
-
enumerateChildren
public java.util.Enumeration enumerateChildren()
Enumerates the subobjects of the object.- Returns:
- Description of the Returned Value
-
parseFromReader
public void parseFromReader(java.io.Reader reader) throws java.io.IOException, XMLParseExceptionReads an XML definition from a java.io.Reader and parses it.- Parameters:
reader- Description of Parameter- Throws:
java.io.IOException- Description of ExceptionXMLParseException- Description of Exception
-
parseFromReader
public void parseFromReader(java.io.Reader reader, int startingLineNr) throws java.io.IOException, XMLParseExceptionReads an XML definition from a java.io.Reader and parses it.- Parameters:
reader- Description of ParameterstartingLineNr- Description of Parameter- Throws:
java.io.IOException- Description of ExceptionXMLParseException- Description of Exception
-
parseString
public void parseString(java.lang.String string) throws XMLParseExceptionParses an XML definition.- Parameters:
string- Description of Parameter- Throws:
XMLParseException- Description of Exception
-
parseString
public int parseString(java.lang.String string, int offset) throws XMLParseExceptionParses an XML definition starting at offset .- Parameters:
string- Description of Parameteroffset- Description of Parameter- Returns:
- the offset of the string following the XML data
- Throws:
XMLParseException- Description of Exception
-
parseString
public int parseString(java.lang.String string, int offset, int end) throws XMLParseExceptionParses an XML definition starting at offset .- Parameters:
string- Description of Parameteroffset- Description of Parameterend- Description of Parameter- Returns:
- the offset of the string following the XML data (<= end)
- Throws:
XMLParseException- Description of Exception
-
parseString
public int parseString(java.lang.String string, int offset, int end, int startingLineNr) throws XMLParseExceptionParses an XML definition starting at offset .- Parameters:
string- Description of Parameteroffset- Description of Parameterend- Description of ParameterstartingLineNr- Description of Parameter- Returns:
- the offset of the string following the XML data (<= end)
- Throws:
XMLParseException- Description of Exception
-
parseCharArray
public int parseCharArray(char[] input, int offset, int end) throws XMLParseExceptionParses an XML definition starting at offset .- Parameters:
input- Description of Parameteroffset- Description of Parameterend- Description of Parameter- Returns:
- the offset of the array following the XML data (<= end)
- Throws:
XMLParseException- Description of Exception
-
parseCharArray
public int parseCharArray(char[] input, int offset, int end, int startingLineNr) throws XMLParseExceptionParses an XML definition starting at offset .- Parameters:
input- Description of Parameteroffset- Description of Parameterend- Description of ParameterstartingLineNr- Description of Parameter- Returns:
- the offset of the array following the XML data (<= end)
- Throws:
XMLParseException- Description of Exception
-
removeChild
public void removeChild(XMLElement child)
Removes a child object. If the object is not a child, nothing happens.- Parameters:
child- Description of Parameter
-
removeChild
public void removeChild(java.lang.String key)
Removes an attribute.- Parameters:
key- Description of Parameter
-
toString
public java.lang.String toString()
Writes the XML element to a string.- Overrides:
toStringin classjava.lang.Object- Returns:
- Description of the Returned Value
-
write
public void write(java.io.Writer writer)
Writes the XML element to a writer.- Parameters:
writer- Description of Parameter
-
write
public void write(java.io.Writer writer, int indent)Writes the XML element to a writer.- Parameters:
writer- Description of Parameterindent- Description of Parameter
-
scanChildren
protected void scanChildren(char[] input, int contentOffset, int contentSize, int contentLineNr) throws XMLParseException!!! Searches the content for child objects. If such objects exist, the content is reduced tonull.- Parameters:
input- Description of ParametercontentOffset- Description of ParametercontentSize- Description of ParametercontentLineNr- Description of Parameter- Throws:
XMLParseException- Description of Exception- See Also:
parseCharArray(char[], int, int, int[])
-
createAnotherElement
protected XMLElement createAnotherElement()
Creates a new XML element.- Returns:
- Description of the Returned Value
-
skipBogusTag
protected int skipBogusTag(char[] input, int offset, int end, int[] lineNr)Skips a tag that don't contain any useful data: <?...?>, <!...> and comments.- Parameters:
input- Description of Parameteroffset- Description of Parameterend- Description of ParameterlineNr- Description of Parameter- Returns:
- the position after the tag
-
decodeString
protected java.lang.String decodeString(java.lang.String s, int lineNr)Converts &...; sequences to "normal" chars.- Parameters:
s- Description of ParameterlineNr- Description of Parameter- Returns:
- Description of the Returned Value
-
writeEncoded
protected void writeEncoded(java.io.PrintWriter out, java.lang.String str)Writes a string encoded to a writer.- Parameters:
out- Description of Parameterstr- Description of Parameter
-
-