org.zkoss.idom
Interface Attributable

All Known Implementing Classes:
Element

public interface Attributable

Represents a class that has attributes. It is usually implemented by a class that also implements Item or Group. Currently, only Element implements it.

Design consideration: Be as similar to Group as possible.

Author:
tomyeh
See Also:
Item, Attribute

Method Summary
 int getAttributeIndex(int indexFrom, java.lang.String tname)
          Gets the index of the attribute with the giving local name.
 int getAttributeIndex(int indexFrom, java.lang.String namespace, java.lang.String name, int mode)
          Gets the index of the first attribute that matches the specified criteria.
 Attribute getAttributeItem(java.lang.String tname)
          Gets the attribute with the tag name.
 Attribute getAttributeItem(java.lang.String namespace, java.lang.String name, int mode)
          Gets the first attribute that matches the specified criteria.
 java.util.List<Attribute> getAttributeItems()
          Returns all attributes of this object.
 java.util.List<Attribute> getAttributes(java.lang.String namespace, java.lang.String name, int mode)
          Gets a list of attributes of the specified criteria.
 java.lang.String getAttributeValue(java.lang.String tname)
          Returns the value of the attribute of the specified tag name, or null if not specified.
 java.lang.String getAttributeValue(java.lang.String namespace, java.lang.String name, int mode)
          Gets the value of the first attribute that matches the giving criteria, or null if not found.
 Attribute setAttribute(Attribute attr)
          Adds the giving attribute.
 Attribute setAttributeValue(java.lang.String tname, java.lang.String value)
          Sets the value of the attribute with the giving tag name.
 

Method Detail

getAttributeItems

java.util.List<Attribute> getAttributeItems()
Returns all attributes of this object.

The returned list is "live". Any modification to it affects the object that owns the attributes.

If the new added attribute has the same tag name as that of any existent attribute, DOMException is thrown. Thus, it is, sometimes, more convenient to ue setAttribute.

Naming reason: we don't call it getAttributes() to avoid the name conflict with Node.getAttributes().

Returns:
an empty list if no attribute at all

getAttributeIndex

int getAttributeIndex(int indexFrom,
                      java.lang.String namespace,
                      java.lang.String name,
                      int mode)
Gets the index of the first attribute that matches the specified criteria.

Parameters:
indexFrom - the index to start searching from; 0 for beginning
namespace - the namespace URI if FIND_BY_PREFIX is not specified; the namespace prefix if FIND_BY_PREFIX specified; null to ignore
name - the local name if FIND_BY_TAGNAME is not specified; the tag name if FIND_BY_TAGNAME specified; null to ignore
mode - the search mode; zero or any combination of Item.FIND_xxx
Returns:
the index if found; -1 if not found

getAttributeIndex

int getAttributeIndex(int indexFrom,
                      java.lang.String tname)
Gets the index of the attribute with the giving local name.

Parameters:
indexFrom - the index to start searching from; 0 for beginning
tname - the tag name (i.e., Attribute.getName()) -- consists of the prefix and the local name
Returns:
the index if found; -1 if not found

getAttributeValue

java.lang.String getAttributeValue(java.lang.String namespace,
                                   java.lang.String name,
                                   int mode)
Gets the value of the first attribute that matches the giving criteria, or null if not found.

According to Section 3.3.3 of XML 1.0 spec, the value is normalized, including trimmed.

Parameters:
namespace - the namespace URI if FIND_BY_PREFIX is not specified; the namespace prefix if FIND_BY_PREFIX specified; null to ignore
name - the local name if FIND_BY_TAGNAME is not specified; the tag name if FIND_BY_TAGNAME specified; null to ignore
Returns:
the value of the attribute; null if not found

getAttributeValue

java.lang.String getAttributeValue(java.lang.String tname)
Returns the value of the attribute of the specified tag name, or null if not specified.

Note: unlike W3C's getAttribute, which returns empty if not specified, this method returns null if not specified.


getAttributeItem

Attribute getAttributeItem(java.lang.String namespace,
                           java.lang.String name,
                           int mode)
Gets the first attribute that matches the specified criteria.

The name is a bit strange because we have to avoid name conflicts with org.w3c.dom.Node.

Parameters:
namespace - the namespace URI if FIND_BY_PREFIX is not specified; the namespace prefix if FIND_BY_PREFIX specified; null to ignore
name - the local name if FIND_BY_TAGNAME is not specified; the tag name if FIND_BY_TAGNAME specified; null to ignore
mode - the search mode; zero or any combination of Item.FIND_xxx
Returns:
the index if found; -1 if not found

getAttributeItem

Attribute getAttributeItem(java.lang.String tname)
Gets the attribute with the tag name.

The name is a bit strange because we have to avoid name conflicts with org.w3c.dom.Node.

Parameters:
tname - the tag name (i.e., Attribute.getName()) -- consists of the prefix and the local name
Returns:
null if not found

getAttributes

java.util.List<Attribute> getAttributes(java.lang.String namespace,
                                        java.lang.String name,
                                        int mode)
Gets a list of attributes of the specified criteria.

Parameters:
namespace - the namespace URI if FIND_BY_PREFIX is not specified; the namespace prefix if FIND_BY_PREFIX specified; null to ignore
name - the local name if FIND_BY_TAGNAME is not specified; the tag name if FIND_BY_TAGNAME specified; null to ignore
mode - the search mode; zero or any combination of Item.FIND_xxx
Returns:
null if not found

setAttribute

Attribute setAttribute(Attribute attr)
Adds the giving attribute. If there is any existent one with the same tag name, it will be replaced. If not, the new attribute will be appended.

Parameters:
attr - the new attribute to add
Returns:
the attribute being replaced; null if no one is replaced

setAttributeValue

Attribute setAttributeValue(java.lang.String tname,
                            java.lang.String value)
Sets the value of the attribute with the giving tag name. If the attribute doesn't exist, a new attribute will be created and added.

Note: it looks similar to Attribute(String, String), but this method requires the tag name.

Parameters:
tname - the tag name (i.e., Attribute.getName)
value - the new value.
Returns:
the attribute being replaced; null if no one is replaced


Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo