📄 xmlelement.java
字号:
*/ public double getProperty(String key, double defaultValue) { if (this.ignoreCase) { key = key.toUpperCase(); } String val = this.attributes.getProperty(key); if (val == null) { return defaultValue; } else { try { return Double.valueOf(val).doubleValue(); } catch (NumberFormatException e) { throw this.invalidValue(key, val, this.lineNr); } } } /** * Returns a boolean property of the object. If the property is missing, <I> * defaultValue</I> is returned. * * @param key Description of Parameter * @param trueValue Description of Parameter * @param falseValue Description of Parameter * @param defaultValue Description of Parameter * @return The Property value */ public boolean getProperty(String key, String trueValue, String falseValue, boolean defaultValue) { if (this.ignoreCase) { key = key.toUpperCase(); } String val = this.attributes.getProperty(key); if (val == null) { return defaultValue; } else if (val.equals(trueValue)) { return true; } else if (val.equals(falseValue)) { return false; } else { throw this.invalidValue(key, val, this.lineNr); } } /** * Returns a property by looking up a key in the hashtable <I>valueSet</I> If * the property doesn't exist, the value corresponding to <I>defaultValue</I> * is returned. * * @param key Description of Parameter * @param valueSet Description of Parameter * @param defaultValue Description of Parameter * @return The Property value */ public Object getProperty(String key, Hashtable valueSet, String defaultValue) { if (this.ignoreCase) { key = key.toUpperCase(); } String val = this.attributes.getProperty(key); if (val == null) { val = defaultValue; } Object result = valueSet.get(val); if (result == null) { throw this.invalidValue(key, val, this.lineNr); } return result; } /** * Returns a property by looking up a key in the hashtable <I>valueSet</I> . * If the property doesn't exist, the value corresponding to <I>defaultValue * </I> is returned. * * @param key Description of Parameter * @param valueSet Description of Parameter * @param defaultValue Description of Parameter * @return The StringProperty value */ public String getStringProperty(String key, Hashtable valueSet, String defaultValue) { if (this.ignoreCase) { key = key.toUpperCase(); } String val = this.attributes.getProperty(key); String result; if (val == null) { val = defaultValue; } try { result = (String) (valueSet.get(val)); } catch (ClassCastException e) { throw this.invalidValueSet(key); } if (result == null) { throw this.invalidValue(key, val, this.lineNr); } return result; } /** * Returns a property by looking up a key in the hashtable <I>valueSet</I> . * 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 <I> * defaultValue</I> is returned. * * @param key Description of Parameter * @param valueSet Description of Parameter * @param defaultValue Description of Parameter * @return The SpecialIntProperty value */ public int getSpecialIntProperty(String key, Hashtable valueSet, String defaultValue) { if (this.ignoreCase) { key = key.toUpperCase(); } String val = this.attributes.getProperty(key); Integer result; if (val == null) { val = defaultValue; } try { result = (Integer) (valueSet.get(val)); } catch (ClassCastException e) { throw this.invalidValueSet(key); } if (result == null) { try { return Integer.parseInt(val); } catch (NumberFormatException e) { throw this.invalidValue(key, val, this.lineNr); } } return result.intValue(); } /** * Returns a property by looking up a key in the hashtable <I>valueSet</I> . * 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 <I>defaultValue</I> is returned. * * @param key Description of Parameter * @param valueSet Description of Parameter * @param defaultValue Description of Parameter * @return The SpecialDoubleProperty value */ public double getSpecialDoubleProperty(String key, Hashtable valueSet, String defaultValue) { if (this.ignoreCase) { key = key.toUpperCase(); } String val = this.attributes.getProperty(key); Double result; if (val == null) { val = defaultValue; } try { result = (Double) (valueSet.get(val)); } catch (ClassCastException e) { throw this.invalidValueSet(key); } if (result == null) { try { result = Double.valueOf(val); } catch (NumberFormatException e) { throw this.invalidValue(key, val, this.lineNr); } } return result.doubleValue(); } /** * Returns the class (i.e. the name indicated in the tag) of the object. * * @return The TagName value */ public String getTagName() { return this.tagName; } /** * Adds a subobject. * * @param child The feature to be added to the Child attribute */ public void addChild(XMLElement child) { this.children.addElement(child); } /** * Adds a property. If the element is case insensitive, the property name is * capitalized. * * @param key The feature to be added to the Property attribute * @param value The feature to be added to the Property attribute */ public void addProperty(String key, Object value) { if (this.ignoreCase) { key = key.toUpperCase(); } this.attributes.put(key, value.toString()); } /** * Adds a property. If the element is case insensitive, the property name is * capitalized. * * @param key The feature to be added to the Property attribute * @param value The feature to be added to the Property attribute */ public void addProperty(String key, int value) { if (this.ignoreCase) { key = key.toUpperCase(); } this.attributes.put(key, Integer.toString(value)); } /** * Adds a property. If the element is case insensitive, the property name is * capitalized. * * @param key The feature to be added to the Property attribute * @param value The feature to be added to the Property attribute */ public void addProperty(String key, double value) { if (this.ignoreCase) { key = key.toUpperCase(); } this.attributes.put(key, Double.toString(value)); } /** * Returns the number of subobjects of the object. * * @return Description of the Returned Value */ public int countChildren() { return this.children.size(); } /** * Enumerates the attribute names. * * @return Description of the Returned Value */ public Enumeration enumeratePropertyNames() { return this.attributes.keys(); } /** * Enumerates the subobjects of the object. * * @return Description of the Returned Value */ public Enumeration enumerateChildren() { return this.children.elements(); } /** * Reads an XML definition from a java.io.Reader and parses it. * * @param reader Description of Parameter * @exception IOException Description of Exception * @exception XMLParseException Description of Exception */ public void parseFromReader(Reader reader) throws IOException, XMLParseException { this.parseFromReader(reader, 1); } /** * Reads an XML definition from a java.io.Reader and parses it. * * @param reader Description of Parameter * @param startingLineNr Description of Parameter * @exception IOException Description of Exception * @exception XMLParseException Description of Exception */ public void parseFromReader(Reader reader, int startingLineNr) throws IOException, XMLParseException { int blockSize = 4096; char[] input = null; int size = 0; for (; ; ) { if (input == null) { input = new char[blockSize]; } else { char[] oldInput = input; input = new char[input.length + blockSize]; System.arraycopy(oldInput, 0, input, 0, oldInput.length); } int charsRead = reader.read(input, size, blockSize); if (charsRead < 0) { break; } size += charsRead; } this.parseCharArray(input, 0, size, startingLineNr); } /** * Parses an XML definition. * * @param string Description of Parameter * @exception XMLParseException Description of Exception */ public void parseString(String string) throws XMLParseException { this.parseCharArray(string.toCharArray(), 0, string.length(), 1); } /** * Parses an XML definition starting at <I>offset</I> . * * @param string Description of Parameter * @param offset Description of Parameter * @return the offset of the string following * the XML data * @exception XMLParseException Description of Exception */ public int parseString(String string, int offset) throws XMLParseException { return this.parseCharArray(string.toCharArray(), offset, string.length(), 1); } /** * Parses an XML definition starting at <I>offset</I> . * * @param string Description of Parameter * @param offset Description of Parameter * @param end Description of Parameter * @return the offset of the string following * the XML data (<= end) * @exception XMLParseException Description of Exception */ public int parseString(String string, int offset, int end) throws XMLParseException { return this.parseCharArray(string.toCharArray(), offset, end, 1); } /** * Parses an XML definition starting at <I>offset</I> . * * @param string Description of Parameter * @param offset Description of Parameter * @param end Description of Parameter * @param startingLineNr Description of Parameter * @return the offset of the string following * the XML data (<= end) * @exception XMLParseException Description of Exception */ public int parseString(String string, int offset, int end, int startingLineNr) throws XMLParseException { return this.parseCharArray(string.toCharArray(), offset, end, startingLineNr); } /** * Parses an XML definition starting at <I>offset</I> . * * @param input Description of Parameter * @param offset Description of Parameter * @param end Description of Parameter * @return the offset of the array following the * XML data (<= end) * @exception XMLParseException Description of Exception */ public int parseCharArray(char[] input, int offset, int end) throws XMLParseException { return this.parseCharArray(input, offset, end, 1); } /** * Parses an XML definition starting at <I>offset</I> . * * @param input Description of Parameter * @param offset Description of Parameter * @param end Description of Parameter * @param startingLineNr Description of Parameter * @return the offset of the array following the * XML data (<= end) * @exception XMLParseException Description of Exception */ public int parseCharArray(char[] input, int offset, int end, int startingLineNr) throws XMLParseException { int[] lineNr = new int[1]; lineNr[0] = startingLineNr; return this.parseCharArray(input, offset, end, lineNr); } /** * Removes a child object. If the object is not a child, nothing happens. * * @param child Description of Parameter */ public void removeChild(XMLElement child) { this.children.removeElement(child); } /** * Removes an attribute. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -