Class Attribute
- All Implemented Interfaces:
Serializable, Cloneable, NamespaceAware
JDOM 1.x Compatibility Note:
The Attribute class in JDOM 1.x had a number of int Constants declared to
represent different Attribute Types. JDOM2 has introduced an AttributeType
enumeration instead. To facilitate compatibility and to simplify JDOM 1.x
migrations, the replacement AttributeType enums are referenced still using
the JDOM 1.x constant names. In JDOM 1.x these names referenced constant
int values. In JDOM2 these names reference Enum constants.
- Author:
- Brett McLaughlin, Jason Hunter, Elliotte Rusty Harold, Wesley Biggs, Victor Toni, Rolf Lear
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final AttributeTypeJDOM 1.x compatible reference toAttributeType.CDATAstatic final AttributeTypeJDOM 1.x compatible reference toAttributeType.ENTITIESstatic final AttributeTypeJDOM 1.x compatible reference toAttributeType.ENTITYstatic final AttributeTypeJDOM 1.x compatible reference toAttributeType.ENUMERATIONstatic final AttributeTypeJDOM 1.x compatible reference toAttributeType.IDstatic final AttributeTypeJDOM 1.x compatible reference toAttributeType.IDREFstatic final AttributeTypeJDOM 1.x compatible reference toAttributeType.IDREFSprotected StringThe local name of theAttributeprotected NamespaceTheof theNamespaceAttributestatic final AttributeTypeJDOM 1.x compatible reference toAttributeType.NMTOKENstatic final AttributeTypeJDOM 1.x compatible reference toAttributeType.NMTOKENSstatic final AttributeTypeJDOM 1.x compatible reference toAttributeType.NOTATIONprotected ElementThe parent to which this Attribute belongs.protected booleanSpecified attributes are part of the XML, unspecified attributes are 'defaulted' from a DTD.protected AttributeTypeThe type of theAttributestatic final AttributeTypeJDOM 1.x compatible reference toAttributeType.UNDECLAREDprotected StringThe value of theAttribute -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefault, no-args constructor for implementations to use if needed.This will create a newAttributewith the specified (local) name and value, and does not place the attribute in a.NamespaceDeprecated.Deprecated.Attribute(String name, String value, AttributeType type) This will create a newAttributewith the specified (local) name, value and type, and does not place the attribute in a.NamespaceAttribute(String name, String value, AttributeType type, Namespace namespace) This will create a newAttributewith the specified (local) name, value, and type, and in the provided.NamespaceThis will create a newAttributewith the specified (local) name and value, and in the provided.Namespace -
Method Summary
Modifier and TypeMethodDescriptionclone()Return a deep clone of this instance.detach()Detach this Attribute from its parent.This will return the declared type of thisAttribute.booleanThis gets the effective boolean value of the attribute, or throws aif a conversion can't be performed.DataConversionExceptionGet this Attribute's Document.doubleThis gets the value of the attribute, indoubleform, and if no conversion can occur, throws aDataConversionExceptionfloatThis gets the value of the attribute, infloatform, and if no conversion can occur, throws aDataConversionExceptionintThis gets the value of the attribute, inintform, and if no conversion can occur, throws aDataConversionExceptionlongThis gets the value of the attribute, inlongform, and if no conversion can occur, throws aDataConversionExceptiongetName()This will retrieve the local name of theAttribute.This will return thisAttribute's.NamespaceThis will retrieve the namespace prefix of theAttribute.Obtain a list of all namespaces that are in scope for this content, but were not introduced by this content.Get the namespaces that are in-scope on this Attribute.Obtain a list of all namespaces that are introduced to the XML tree by this node.This returns the URI mapped to thisAttribute's prefix.This will return the parent of thisAttribute.This will retrieve the qualified name of theAttribute.getValue()This will return the actual textual value of thisAttribute.booleanGet the 'specified' flag.setAttributeType(int type) Deprecated.This will set the type of theAttribute.This sets the local name of theAttribute.setNamespace(Namespace namespace) This sets thisAttribute's.Namespaceprotected AttributeSet this Attribute's parent.voidsetSpecified(boolean specified) Change the specified flag to the given value.This will set the value of theAttribute.toString()This returns aStringrepresentation of theAttribute, suitable for debugging.
-
Field Details
-
UNDECLARED_TYPE
JDOM 1.x compatible reference toAttributeType.UNDECLARED -
CDATA_TYPE
JDOM 1.x compatible reference toAttributeType.CDATA -
ID_TYPE
JDOM 1.x compatible reference toAttributeType.ID -
IDREF_TYPE
JDOM 1.x compatible reference toAttributeType.IDREF -
IDREFS_TYPE
JDOM 1.x compatible reference toAttributeType.IDREFS -
ENTITY_TYPE
JDOM 1.x compatible reference toAttributeType.ENTITY -
ENTITIES_TYPE
JDOM 1.x compatible reference toAttributeType.ENTITIES -
NMTOKEN_TYPE
JDOM 1.x compatible reference toAttributeType.NMTOKEN -
NMTOKENS_TYPE
JDOM 1.x compatible reference toAttributeType.NMTOKENS -
NOTATION_TYPE
JDOM 1.x compatible reference toAttributeType.NOTATION -
ENUMERATED_TYPE
JDOM 1.x compatible reference toAttributeType.ENUMERATION -
name
The local name of theAttribute -
namespace
-
value
The value of theAttribute -
type
The type of theAttribute -
specified
protected boolean specifiedSpecified attributes are part of the XML, unspecified attributes are 'defaulted' from a DTD. -
parent
The parent to which this Attribute belongs. Change it withsetParent(Element)
-
-
Constructor Details
-
Attribute
protected Attribute()Default, no-args constructor for implementations to use if needed. -
Attribute
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(String)).
-
Attribute
Deprecated.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(String)) or if the given attribute type is not one of the supported types.
-
Attribute
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-AttributeTypefor 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(String)) or if the given attribute type is not one of the supported types.
-
Attribute
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(String)).
-
Attribute
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-AttributeTypefor 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(String)) or if the given attribute type is not one of the supported types.
-
Attribute
Deprecated.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(String)) or if the given attribute type is not one of the supported types.
-
-
Method Details
-
getParent
This will return the parent of thisAttribute. If there is no parent, then this returnsnull. Use return-type covariance to override Content's getParent() method to return an Element, not just a Parent- Returns:
- parent of this
Attribute
-
getDocument
Get this Attribute's Document.- Returns:
- The document to which this Attribute is associated, may be null.
-
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
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
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
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
This returns the URI mapped to thisAttribute's prefix. If no mapping is found, an emptyStringis returned.- Returns:
String- namespace URI for thisAttribute.
-
getNamespace
-
setNamespace
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
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
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(String)).
-
getAttributeType
This will return the declared type of thisAttribute.- Returns:
AttributeType- type for this attribute.
-
setAttributeType
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.
-
setAttributeType
Deprecated.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.
-
isSpecified
public boolean isSpecified()Get the 'specified' flag. True values indicate this attribute was part of an XML document, false indicates it was defaulted from a DTD.- Returns:
- the specified flag.
- Since:
- JDOM2
-
setSpecified
public void setSpecified(boolean specified) Change the specified flag to the given value.- Parameters:
specified- The value to set the specified flag to.- Since:
- JDOM2
-
toString
-
clone
Return a deep clone of this instance. Even if this instance has a parent, the returned clone will not.All JDOM core classes are Cloneable, and never throw CloneNotSupportedException. Additionally all Cloneable JDOM classes return the correct type of instance from this method and there is no need to cast the result (co-variant return value).
Subclasses of this should still call super.clone() in their clone method.
-
detach
Detach this Attribute from its parent.- Returns:
- this Attribute (detached).
-
setParent
-
getIntValue
This 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
This 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
This 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
This 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
This 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.
-
getNamespacesInScope
Get the namespaces that are in-scope on this Attribute.Attribute has peculiarities that affect the in-scope Namespaces because there are conditions in which the Attribute's scope is different to its parent Element's scope. Specifically, if the parent Element is in a 'default' Namespace that is not the empty Namespace (e.g. xmlns="someurl") and this Attribute is also in the default Namespace (has no prefix - but for Attributes that means the Namespace URL is ""), then this Attribute has a different namespace scope from its parent Element because it does not include the 'someurl' Namespace.
In the above conditions (no-prefix Attribute in an Element with a non-empty no-prefix Namespace) this Attribute effectively re-binds the "" prefix to the "" URL, thus the Attribute 'introduces' the Namespace. It follows then that the getNamespacesIntroduced() will return a list with the single member
Namespace.NO_NAMESPACE.Note that the Attribute's Namespace will always be reported first.
Description copied from
NamespaceAware.getNamespacesInScope():Obtain a list of all namespaces that are in scope for the current content.
The contents of this list will always be the combination of getNamespacesIntroduced() and getNamespacesInherited().
See
NamespaceAwaredocumentation for details on what the order of the Namespaces will be in the returned list.- Specified by:
getNamespacesInScopein interfaceNamespaceAware- Returns:
- a read-only list of Namespaces.
-
getNamespacesIntroduced
Description copied from interface:NamespaceAwareObtain a list of all namespaces that are introduced to the XML tree by this node. Only Elements and Attributes can introduce namespaces, so all other Content types will return an empty list.The contents of this list will always be a subset (but in the same order) of getNamespacesInScope(), and will never intersect getNamspacesInherited()
- Specified by:
getNamespacesIntroducedin interfaceNamespaceAware- Returns:
- a read-only list of Namespaces.
-
getNamespacesInherited
Description copied from interface:NamespaceAwareObtain a list of all namespaces that are in scope for this content, but were not introduced by this content.The contents of this list will always be a subset (but in the same order) of getNamespacesInScope(), and will never intersect getNamspacesIntroduced()
- Specified by:
getNamespacesInheritedin interfaceNamespaceAware- Returns:
- a read-only list of Namespaces.
-
Attribute(String, String, AttributeType)