📄 xmlelement.java
字号:
}
/**
* Enumerates the attribute names.
*
* <dl><dt><b>Postconditions:</b></dt><dd>
* <ul><li><code>result != null</code>
* </ul></dd></dl>
*
* @return enumeration of attribute names
* @see XMLElement#setDoubleAttribute(java.lang.String, double)
* setDoubleAttribute(String, double)
* @see XMLElement#setIntAttribute(java.lang.String, int)
* setIntAttribute(String, int)
* @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
* setAttribute(String, Object)
* @see XMLElement#removeAttribute(java.lang.String)
* removeAttribute(String)
* @see XMLElement#getAttribute(java.lang.String)
* getAttribute(String)
* @see XMLElement#getAttribute(java.lang.String, java.lang.Object)
* getAttribute(String, String)
* @see XMLElement#getAttribute(java.lang.String,
* java.util.Hashtable,
* java.lang.String, boolean)
* getAttribute(String, Hashtable, String, boolean)
* @see XMLElement#getStringAttribute(java.lang.String)
* getStringAttribute(String)
* @see XMLElement#getStringAttribute(java.lang.String,
* java.lang.String)
* getStringAttribute(String, String)
* @see XMLElement#getStringAttribute(java.lang.String,
* java.util.Hashtable,
* java.lang.String, boolean)
* getStringAttribute(String, Hashtable, String, boolean)
* @see XMLElement#getIntAttribute(java.lang.String)
* getIntAttribute(String)
* @see XMLElement#getIntAttribute(java.lang.String, int)
* getIntAttribute(String, int)
* @see XMLElement#getIntAttribute(java.lang.String,
* java.util.Hashtable,
* java.lang.String, boolean)
* getIntAttribute(String, Hashtable, String, boolean)
* @see XMLElement#getDoubleAttribute(java.lang.String)
* getDoubleAttribute(String)
* @see XMLElement#getDoubleAttribute(java.lang.String, double)
* getDoubleAttribute(String, double)
* @see XMLElement#getDoubleAttribute(java.lang.String,
* java.util.Hashtable,
* java.lang.String, boolean)
* getDoubleAttribute(String, Hashtable, String, boolean)
* @see XMLElement#getBooleanAttribute(java.lang.String,
* java.lang.String,
* java.lang.String, boolean)
* getBooleanAttribute(String, String, String, boolean)
*/
public Enumeration enumerateAttributeNames()
{
return this.attributes.keys();
}
/**
* Enumerates the attribute names.
*
* @return enumeration of attribute names
* @deprecated Use {@link #enumerateAttributeNames()
* enumerateAttributeNames} instead.
*/
public Enumeration enumeratePropertyNames()
{
return this.enumerateAttributeNames();
}
/**
* Enumerates the child elements.
*
* <dl><dt><b>Postconditions:</b></dt><dd>
* <ul><li><code>result != null</code>
* </ul></dd></dl>
*
* @return enumeration of child elements
* @see XMLElement#addChild(XMLElement)
* addChild(XMLElement)
* @see XMLElement#countChildren()
* @see XMLElement#getChildren()
* @see XMLElement#removeChild(XMLElement)
* removeChild(XMLElement)
*/
public Enumeration enumerateChildren()
{
return this.children.elements();
}
/**
* Returns the child elements as a Vector. It is safe to modify this
* Vector.
*
* <dl><dt><b>Postconditions:</b></dt><dd>
* <ul><li><code>result != null</code>
* </ul></dd></dl>
*
* @return vector of children
* @see XMLElement#addChild(XMLElement)
* addChild(XMLElement)
* @see XMLElement#countChildren()
* @see XMLElement#enumerateChildren()
* @see XMLElement#removeChild(XMLElement)
* removeChild(XMLElement)
*/
public Vector getChildren()
{
try {
return (Vector) this.children.clone();
} catch (Exception e) {
// this never happens, however, some Java compilers are so
// braindead that they require this exception clause
return null;
}
}
/**
* Returns the PCDATA content of the object. If there is no such content,
* <CODE>null</CODE> is returned.
*
* @return PCDATA content of element
* @deprecated Use {@link #getContent() getContent} instead.
*/
public String getContents()
{
return this.getContent();
}
/**
* Returns the PCDATA content of the object. If there is no such content,
* <CODE>null</CODE> is returned.
*
* @return PCDATA content of element
* @see XMLElement#setContent(java.lang.String)
* setContent(String)
*/
public String getContent()
{
return this.contents;
}
/**
* Returns the line nr in the source data on which the element is found.
* This method returns <code>0</code> there is no associated source data.
*
* <dl><dt><b>Postconditions:</b></dt><dd>
* <ul><li><code>result >= 0</code>
* </ul></dd></dl>
*
* @return line number in source of element
*/
public int getLineNr()
{
return this.lineNr;
}
/**
* Returns an attribute of the element.
* If the attribute doesn't exist, <code>null</code> is returned.
*
* @param name The name of the attribute.
*
* </dl><dl><dt><b>Preconditions:</b></dt><dd>
* <ul><li><code>name != null</code>
* <li><code>name</code> is a valid XML identifier
* </ul></dd></dl><dl>
*
* @return attribute
* @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
* setAttribute(String, Object)
* @see XMLElement#removeAttribute(java.lang.String)
* removeAttribute(String)
* @see XMLElement#enumerateAttributeNames()
* @see XMLElement#getAttribute(java.lang.String, java.lang.Object)
* getAttribute(String, Object)
* @see XMLElement#getAttribute(java.lang.String,
* java.util.Hashtable,
* java.lang.String, boolean)
* getAttribute(String, Hashtable, String, boolean)
*/
public Object getAttribute(String name)
{
return this.getAttribute(name, null);
}
/**
* Returns an attribute of the element.
* If the attribute doesn't exist, <code>defaultValue</code> is returned.
*
*
* </dl><dl><dt><b>Preconditions:</b></dt><dd>
* <ul><li><code>name != null</code>
* <li><code>name</code> is a valid XML identifier
* </ul></dd></dl><dl>
*
* @param name The name of the attribute.
* @param defaultValue Key to use if the attribute is missing.
* @return attribute
*
* @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
* setAttribute(String, Object)
* @see XMLElement#removeAttribute(java.lang.String)
* removeAttribute(String)
* @see XMLElement#enumerateAttributeNames()
* @see XMLElement#getAttribute(java.lang.String)
* getAttribute(String)
* @see XMLElement#getAttribute(java.lang.String,
* java.util.Hashtable,
* java.lang.String, boolean)
* getAttribute(String, Hashtable, String, boolean)
*/
public Object getAttribute(String name,
Object defaultValue)
{
if (this.ignoreCase) {
name = name.toUpperCase();
}
Object value = this.attributes.get(name);
if (value == null) {
value = defaultValue;
}
return value;
}
/**
* Returns an attribute by looking up a key in a hashtable.
* If the attribute doesn't exist, the value corresponding to defaultKey
* is returned.
* <P>
* As an example, if valueSet contains the mapping <code>"one" =>
* "1"</code>
* and the element contains the attribute <code>attr="one"</code>, then
* <code>getAttribute("attr", mapping, defaultKey, false)</code> returns
* <code>"1"</code>.
*
* @param name
* The name of the attribute.
* @param valueSet
* Hashtable mapping keys to values.
* @param defaultKey
* Key to use if the attribute is missing.
* @param allowLiterals
* <code>true</code> if literals are valid.
*
* </dl><dl><dt><b>Preconditions:</b></dt><dd>
* <ul><li><code>name != null</code>
* <li><code>name</code> is a valid XML identifier
* <li><code>valueSet</code> != null
* <li>the keys of <code>valueSet</code> are strings
* </ul></dd></dl><dl>
*
* @return attribute
* @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
* setAttribute(String, Object)
* @see XMLElement#removeAttribute(java.lang.String)
* removeAttribute(String)
* @see XMLElement#enumerateAttributeNames()
* @see XMLElement#getAttribute(java.lang.String)
* getAttribute(String)
* @see XMLElement#getAttribute(java.lang.String, java.lang.Object)
* getAttribute(String, Object)
*/
public Object getAttribute(String name,
Hashtable valueSet,
String defaultKey,
boolean allowLiterals)
{
if (this.ignoreCase) {
name = name.toUpperCase();
}
Object key = this.attributes.get(name);
Object result;
if (key == null) {
key = defaultKey;
}
result = valueSet.get(key);
if (result == null) {
if (allowLiterals) {
result = key;
} else {
throw this.invalidValue(name, (String) key);
}
}
return result;
}
/**
* Returns an attribute of the element.
* If the attribute doesn't exist, <code>null</code> is returned.
*
* @param name The name of the attribute.
*
* </dl><dl><dt><b>Preconditions:</b></dt><dd>
* <ul><li><code>name != null</code>
* <li><code>name</code> is a valid XML identifier
* </ul></dd></dl><dl>
*
* @return attribute
* @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
* setAttribute(String, Object)
* @see XMLElement#removeAttribute(java.lang.String)
* removeAttribute(String)
* @see XMLElement#enumerateAttributeNames()
* @see XMLElement#getStringAttribute(java.lang.String,
* java.lang.String)
* getStringAttribute(String, String)
* @see XMLElement#getStringAttribute(java.lang.String,
* java.util.Hashtable,
* java.lang.String, boolean)
* getStringAttribute(String, Hashtable, String, boolean)
*/
public String getStringAttribute(String name)
{
return this.getStringAttribute(name, null);
}
/**
* Returns an attribute of the element.
* If the attribute doesn't exist, <code>defaultValue</code> is returned.
*
* @param name The name of the attribute.
* @param defaultValue Key to use if the attribute is missing.
*
* </dl><dl><dt><b>Preconditions:</b></dt><dd>
* <ul><li><code>name != null</code>
* <li><code>name</code> is a valid XML identifier
* </ul></dd></dl><dl>
*
* @return attribute
* @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
* setAttribute(String, Object)
* @see XMLElement#removeAttribute(java.lang.String)
* removeAttribute(String)
* @see XMLElement#enumerateAttributeNames()
* @see XMLElement#getStringAttribute(java.lang.String)
* getStringAttribute(String)
* @see XMLElement#getStringAttribute(java.lang.String,
* java.util.Hashtable,
* java.lang.String, boolean)
* getStringAttribute(String, Hashtable, String, boolean)
*/
public String getStringAttribute(String name,
String defaultValue)
{
return (String) this.getAttribute(name, defaultValue);
}
/**
* Returns an attribute by looking up a key in a hashtable.
* If the attribute doesn't exist, the value corresponding to defaultKey
* is returned.
* <P>
* As an example, if valueSet contains the mapping <code>"one" =>
* "1"</code>
* and the element contains the attribute <code>attr="one"</code>, then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -