Class Attribute
- java.lang.Object
-
- org.jdom.Attribute
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
public class Attribute extends java.lang.Object implements java.io.Serializable, java.lang.CloneableAn XML attribute. Methods allow the user to obtain the value of the attribute as well as namespace and type information.- Version:
- $Revision: 1.56 $, $Date: 2007/11/10 05:28:58 $
- Author:
- Brett McLaughlin, Jason Hunter, Elliotte Rusty Harold, Wesley Biggs, Victor Toni
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intCDATA_TYPEAttribute type: the attribute value is a string.static intENTITIES_TYPEAttribute type: the attribute value is a list of entity names.static intENTITY_TYPEAttribute type: the attribute value is the name of an entity.static intENUMERATED_TYPEAttribute type: the attribute value is a name token from an enumeration.static intID_TYPEAttribute type: the attribute value is a unique identifier.static intIDREF_TYPEAttribute type: the attribute value is a reference to a unique identifier.static intIDREFS_TYPEAttribute type: the attribute value is a list of references to unique identifiers.protected java.lang.StringnameThe local name of theAttributeprotected NamespacenamespaceTheof theNamespaceAttributestatic intNMTOKEN_TYPEAttribute type: the attribute value is a name token.static intNMTOKENS_TYPEAttribute type: the attribute value is a list of name tokens.static intNOTATION_TYPEAttribute type: the attribute value is the name of a notation.protected ElementparentParent element, or null if noneprotected inttypeThe type of theAttributestatic intUNDECLARED_TYPEAttribute type: the attribute has not been declared or type is unknown.protected java.lang.StringvalueThe value of theAttribute
-
Constructor Summary
Constructors Modifier Constructor Description protectedAttribute()Default, no-args constructor for implementations to use if needed.Attribute(java.lang.String name, java.lang.String value)This will create a newAttributewith the specified (local) name and value, and does not place the attribute in a.NamespaceAttribute(java.lang.String name, java.lang.String value, int type)This will create a newAttributewith the specified (local) name, value and type, and does not place the attribute in a.NamespaceAttribute(java.lang.String name, java.lang.String value, int type, Namespace namespace)This will create a newAttributewith the specified (local) name, value, and type, and in the provided.NamespaceAttribute(java.lang.String name, java.lang.String value, Namespace namespace)This will create a newAttributewith the specified (local) name and value, and in the provided.Namespace
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()This will return a clone of thisAttribute.Attributedetach()This detaches theAttributefrom its parent, or does nothing if theAttributehas no parent.booleanequals(java.lang.Object ob)This tests for equality of thisAttributeto the suppliedObject.intgetAttributeType()This will return the actual declared type of thisAttribute.booleangetBooleanValue()This gets the effective boolean value of the attribute, or throws aif a conversion can't be performed.DataConversionExceptionDocumentgetDocument()doublegetDoubleValue()This gets the value of the attribute, indoubleform, and if no conversion can occur, throws aDataConversionExceptionfloatgetFloatValue()This gets the value of the attribute, infloatform, and if no conversion can occur, throws aDataConversionExceptionintgetIntValue()This gets the value of the attribute, inintform, and if no conversion can occur, throws aDataConversionExceptionlonggetLongValue()This gets the value of the attribute, inlongform, and if no conversion can occur, throws aDataConversionExceptionjava.lang.StringgetName()This will retrieve the local name of theAttribute.NamespacegetNamespace()This will return thisAttribute's.Namespacejava.lang.StringgetNamespacePrefix()This will retrieve the namespace prefix of theAttribute.java.lang.StringgetNamespaceURI()This returns the URI mapped to thisAttribute's prefix.ElementgetParent()This will return the parent of thisAttribute.java.lang.StringgetQualifiedName()This will retrieve the qualified name of theAttribute.java.lang.StringgetValue()This will return the actual textual value of thisAttribute.inthashCode()This returns the hash code for thisAttribute.AttributesetAttributeType(int type)This will set the type of theAttribute.AttributesetName(java.lang.String name)This sets the local name of theAttribute.AttributesetNamespace(Namespace namespace)This sets thisAttribute's.Namespaceprotected AttributesetParent(Element parent)This will set the parent of thisAttribute.AttributesetValue(java.lang.String value)This will set the value of theAttribute.java.lang.StringtoString()This returns aStringrepresentation of theAttribute, suitable for debugging.
-
-
-
Field Detail
-
UNDECLARED_TYPE
public static final int UNDECLARED_TYPE
Attribute type: the attribute has not been declared or type is unknown.- See Also:
getAttributeType(), Constant Field Values
-
CDATA_TYPE
public static final int CDATA_TYPE
Attribute type: the attribute value is a string.- See Also:
getAttributeType(), Constant Field Values
-
ID_TYPE
public static final int ID_TYPE
Attribute type: the attribute value is a unique identifier.- See Also:
getAttributeType(), Constant Field Values
-
IDREF_TYPE
public static final int IDREF_TYPE
Attribute type: the attribute value is a reference to a unique identifier.- See Also:
getAttributeType(), Constant Field Values
-
IDREFS_TYPE
public static final int IDREFS_TYPE
Attribute type: the attribute value is a list of references to unique identifiers.- See Also:
getAttributeType(), Constant Field Values
-
ENTITY_TYPE
public static final int ENTITY_TYPE
Attribute type: the attribute value is the name of an entity.- See Also:
getAttributeType(), Constant Field Values
-
ENTITIES_TYPE
public static final int ENTITIES_TYPE
Attribute type: the attribute value is a list of entity names.
- See Also:
getAttributeType(), Constant Field Values
-
NMTOKEN_TYPE
public static final int NMTOKEN_TYPE
Attribute type: the attribute value is a name token.According to SAX 2.0 specification, attributes of enumerated types should be reported as "NMTOKEN" by SAX parsers. But the major parsers (Xerces and Crimson) provide specific values that permit to recognize them as
ENUMERATED_TYPE.- See Also:
getAttributeType(), Constant Field Values
-
NMTOKENS_TYPE
public static final int NMTOKENS_TYPE
Attribute type: the attribute value is a list of name tokens.- See Also:
getAttributeType(), Constant Field Values
-
NOTATION_TYPE
public static final int NOTATION_TYPE
Attribute type: the attribute value is the name of a notation.- See Also:
getAttributeType(), Constant Field Values
-
ENUMERATED_TYPE
public static final int ENUMERATED_TYPE
Attribute type: the attribute value is a name token from an enumeration.- See Also:
getAttributeType(), Constant Field Values
-
name
protected java.lang.String name
The local name of theAttribute
-
value
protected java.lang.String value
The value of theAttribute
-
type
protected int type
The type of theAttribute
-
parent
protected Element parent
Parent element, or null if none
-
-
Constructor Detail
-
Attribute
protected Attribute()
Default, no-args constructor for implementations to use if needed.
-
Attribute
public Attribute(java.lang.String name, java.lang.String value, Namespace namespace)This will create a newAttributewith the specified (local) name and value, and in the provided.Namespace- Parameters:
name-Stringname ofAttribute.value-Stringvalue for new attribute.namespace-Namespacenamespace for new attribute.- Throws:
IllegalNameException- if the given name is illegal as an attribute name or if if the new namespace is the default namespace. Attributes cannot be in a default namespace.IllegalDataException- if the given attribute value is illegal character data (as determined byVerifier.checkCharacterData(java.lang.String)).
-
Attribute
public Attribute(java.lang.String name, java.lang.String value, int type, Namespace namespace)This will create a newAttributewith the specified (local) name, value, and type, and in the provided.Namespace- Parameters:
name-Stringname ofAttribute.value-Stringvalue for new attribute.type-inttype for new attribute.namespace-Namespacenamespace for new attribute.- Throws:
IllegalNameException- if the given name is illegal as an attribute name or if if the new namespace is the default namespace. Attributes cannot be in a default namespace.IllegalDataException- if the given attribute value is illegal character data (as determined byVerifier.checkCharacterData(java.lang.String)) or if the given attribute type is not one of the supported types.
-
Attribute
public Attribute(java.lang.String name, java.lang.String value)This will create a newAttributewith the specified (local) name and value, and does not place the attribute in a.NamespaceNote: This actually explicitly puts the
Attributein the "empty"Namespace().Namespace.NO_NAMESPACE- Parameters:
name-Stringname ofAttribute.value-Stringvalue for new attribute.- Throws:
IllegalNameException- if the given name is illegal as an attribute name.IllegalDataException- if the given attribute value is illegal character data (as determined byVerifier.checkCharacterData(java.lang.String)).
-
Attribute
public Attribute(java.lang.String name, java.lang.String value, int type)This will create a newAttributewith the specified (local) name, value and type, and does not place the attribute in a.NamespaceNote: This actually explicitly puts the
Attributein the "empty"Namespace().Namespace.NO_NAMESPACE- Parameters:
name-Stringname ofAttribute.value-Stringvalue for new attribute.type-inttype for new attribute.- Throws:
IllegalNameException- if the given name is illegal as an attribute name.IllegalDataException- if the given attribute value is illegal character data (as determined byVerifier.checkCharacterData(java.lang.String)) or if the given attribute type is not one of the supported types.
-
-
Method Detail
-
getParent
public Element getParent()
This will return the parent of thisAttribute. If there is no parent, then this returnsnull.- Returns:
- parent of this
Attribute
-
getDocument
public Document getDocument()
This retrieves the owningfor this Attribute, or null if not a currently a member of aDocument.Document- Returns:
Documentowning this Attribute, or null.
-
setParent
protected Attribute setParent(Element parent)
This will set the parent of thisAttribute.- Parameters:
parent-Elementto be new parent.- Returns:
- this
Attributemodified.
-
detach
public Attribute detach()
This detaches theAttributefrom its parent, or does nothing if theAttributehas no parent.- Returns:
Attribute- thisAttributemodified.
-
getName
public java.lang.String getName()
This will retrieve the local name of theAttribute. For any XML attribute which appears as[namespacePrefix]:[attributeName], the local name of the attribute would be[attributeName]. When the attribute has no namespace, the local name is simply the attribute name.To obtain the namespace prefix for this attribute, the
method should be used.getNamespacePrefix()- Returns:
String- name of this attribute, without any namespace prefix.
-
setName
public Attribute setName(java.lang.String name)
This sets the local name of theAttribute.- Parameters:
name- the new local name to set- Returns:
Attribute- the attribute modified.- Throws:
IllegalNameException- if the given name is illegal as an attribute name.
-
getQualifiedName
public java.lang.String getQualifiedName()
This will retrieve the qualified name of theAttribute. For any XML attribute whose name is[namespacePrefix]:[elementName], the qualified name of the attribute would be everything (both namespace prefix and element name). When the attribute has no namespace, the qualified name is simply the attribute's local name.To obtain the local name of the attribute, the
method should be used.getName()To obtain the namespace prefix for this attribute, the
method should be used.getNamespacePrefix()- Returns:
String- full name for this element.
-
getNamespacePrefix
public java.lang.String getNamespacePrefix()
This will retrieve the namespace prefix of theAttribute. For any XML attribute which appears as[namespacePrefix]:[attributeName], the namespace prefix of the attribute would be[namespacePrefix]. When the attribute has no namespace, an emptyStringis returned.- Returns:
String- namespace prefix of this attribute.
-
getNamespaceURI
public java.lang.String getNamespaceURI()
This returns the URI mapped to thisAttribute's prefix. If no mapping is found, an emptyStringis returned.- Returns:
String- namespace URI for thisAttribute.
-
getNamespace
public Namespace getNamespace()
This will return thisAttribute's.Namespace- Returns:
Namespace- Namespace object for thisAttribute
-
setNamespace
public Attribute setNamespace(Namespace namespace)
This sets thisAttribute's. If the provided namespace is null, the attribute will have no namespace. The namespace must have a prefix.Namespace- Parameters:
namespace- the new namespace- Returns:
Element- the element modified.- Throws:
IllegalNameException- if the new namespace is the default namespace. Attributes cannot be in a default namespace.
-
getValue
public java.lang.String getValue()
This will return the actual textual value of thisAttribute. This will include all text within the quotation marks.- Returns:
String- value for this attribute.
-
setValue
public Attribute setValue(java.lang.String value)
This will set the value of theAttribute.- Parameters:
value-Stringvalue for the attribute.- Returns:
Attribute- this Attribute modified.- Throws:
IllegalDataException- if the given attribute value is illegal character data (as determined byVerifier.checkCharacterData(java.lang.String)).
-
getAttributeType
public int getAttributeType()
This will return the actual declared type of thisAttribute.- Returns:
int- type for this attribute.
-
setAttributeType
public Attribute setAttributeType(int type)
This will set the type of theAttribute.- Parameters:
type-inttype for the attribute.- Returns:
Attribute- this Attribute modified.- Throws:
IllegalDataException- if the given attribute type is not one of the supported types.
-
toString
public java.lang.String toString()
This returns aStringrepresentation of theAttribute, suitable for debugging.- Overrides:
toStringin classjava.lang.Object- Returns:
String- information about theAttribute
-
equals
public final boolean equals(java.lang.Object ob)
This tests for equality of thisAttributeto the suppliedObject.- Overrides:
equalsin classjava.lang.Object- Parameters:
ob-Objectto compare to.- Returns:
boolean- whether theAttributeis equal to the suppliedObject.
-
hashCode
public final int hashCode()
This returns the hash code for thisAttribute.- Overrides:
hashCodein classjava.lang.Object- Returns:
int- hash code.
-
clone
public java.lang.Object clone()
This will return a clone of thisAttribute.- Overrides:
clonein classjava.lang.Object- Returns:
Object- clone of thisAttribute.
-
getIntValue
public int getIntValue() throws DataConversionExceptionThis gets the value of the attribute, inintform, and if no conversion can occur, throws aDataConversionException- Returns:
intvalue of attribute.- Throws:
DataConversionException- when conversion fails.
-
getLongValue
public long getLongValue() throws DataConversionExceptionThis gets the value of the attribute, inlongform, and if no conversion can occur, throws aDataConversionException- Returns:
longvalue of attribute.- Throws:
DataConversionException- when conversion fails.
-
getFloatValue
public float getFloatValue() throws DataConversionExceptionThis gets the value of the attribute, infloatform, and if no conversion can occur, throws aDataConversionException- Returns:
floatvalue of attribute.- Throws:
DataConversionException- when conversion fails.
-
getDoubleValue
public double getDoubleValue() throws DataConversionExceptionThis gets the value of the attribute, indoubleform, and if no conversion can occur, throws aDataConversionException- Returns:
doublevalue of attribute.- Throws:
DataConversionException- when conversion fails.
-
getBooleanValue
public boolean getBooleanValue() throws DataConversionExceptionThis gets the effective boolean value of the attribute, or throws aif a conversion can't be performed. True values are: "true", "on", "1", and "yes". False values are: "false", "off", "0", and "no". Values are trimmed before comparison. Values other than those listed here throw the exception.DataConversionException- Returns:
booleanvalue of attribute.- Throws:
DataConversionException- when conversion fails.
-
-