public class Attribute extends java.lang.Object implements NamespaceAware, java.io.Serializable, java.lang.Cloneable
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.
Modifier and Type | Field and Description |
---|---|
static AttributeType |
CDATA_TYPE
JDOM 1.x compatible reference to
AttributeType.CDATA |
static AttributeType |
ENTITIES_TYPE
JDOM 1.x compatible reference to
AttributeType.ENTITIES |
static AttributeType |
ENTITY_TYPE
JDOM 1.x compatible reference to
AttributeType.ENTITY |
static AttributeType |
ENUMERATED_TYPE
JDOM 1.x compatible reference to
AttributeType.ENUMERATION |
static AttributeType |
ID_TYPE
JDOM 1.x compatible reference to
AttributeType.ID |
static AttributeType |
IDREF_TYPE
JDOM 1.x compatible reference to
AttributeType.IDREF |
static AttributeType |
IDREFS_TYPE
JDOM 1.x compatible reference to
AttributeType.IDREFS |
protected java.lang.String |
name
The local name of the
Attribute |
protected Namespace |
namespace
The
of the Attribute |
static AttributeType |
NMTOKEN_TYPE
JDOM 1.x compatible reference to
AttributeType.NMTOKEN |
static AttributeType |
NMTOKENS_TYPE
JDOM 1.x compatible reference to
AttributeType.NMTOKENS |
static AttributeType |
NOTATION_TYPE
JDOM 1.x compatible reference to
AttributeType.NOTATION |
protected Element |
parent
The parent to which this Attribute belongs.
|
protected boolean |
specified
Specified attributes are part of the XML,
unspecified attributes are 'defaulted' from a DTD.
|
protected AttributeType |
type
The type of the
Attribute |
static AttributeType |
UNDECLARED_TYPE
JDOM 1.x compatible reference to
AttributeType.UNDECLARED |
protected java.lang.String |
value
The value of the
Attribute |
Modifier | Constructor and Description |
---|---|
protected |
Attribute()
Default, no-args constructor for implementations to use if needed.
|
|
Attribute(java.lang.String name,
java.lang.String value)
This will create a new
Attribute with the
specified (local) name and value, and does not place
the attribute in a . |
|
Attribute(java.lang.String name,
java.lang.String value,
AttributeType type)
This will create a new
Attribute with the
specified (local) name, value and type, and does not place
the attribute in a . |
|
Attribute(java.lang.String name,
java.lang.String value,
AttributeType type,
Namespace namespace)
This will create a new
Attribute with the
specified (local) name, value, and type, and in the provided
. |
|
Attribute(java.lang.String name,
java.lang.String value,
int type)
Deprecated.
|
|
Attribute(java.lang.String name,
java.lang.String value,
int type,
Namespace namespace)
Deprecated.
|
|
Attribute(java.lang.String name,
java.lang.String value,
Namespace namespace)
This will create a new
Attribute with the
specified (local) name and value, and in the provided
. |
Modifier and Type | Method and Description |
---|---|
Attribute |
clone()
Return a deep clone of this instance.
|
Attribute |
detach()
Detach this Attribute from its parent.
|
AttributeType |
getAttributeType()
This will return the declared type of this
Attribute . |
boolean |
getBooleanValue()
This gets the effective boolean value of the attribute, or throws a
if a conversion can't be
performed. |
Document |
getDocument()
Get this Attribute's Document.
|
double |
getDoubleValue()
This gets the value of the attribute, in
double form, and if no conversion
can occur, throws a
|
float |
getFloatValue()
This gets the value of the attribute, in
float form, and if no conversion
can occur, throws a
|
int |
getIntValue()
This gets the value of the attribute, in
int form, and if no conversion
can occur, throws a
|
long |
getLongValue()
This gets the value of the attribute, in
long form, and if no conversion
can occur, throws a
|
java.lang.String |
getName()
This will retrieve the local name of the
Attribute . |
Namespace |
getNamespace()
This will return this
Attribute 's
. |
java.lang.String |
getNamespacePrefix()
This will retrieve the namespace prefix of the
Attribute . |
java.util.List<Namespace> |
getNamespacesInherited()
Obtain a list of all namespaces that are in scope for this content, but
were not introduced by this content.
|
java.util.List<Namespace> |
getNamespacesInScope()
Get the namespaces that are in-scope on this Attribute.
|
java.util.List<Namespace> |
getNamespacesIntroduced()
Obtain a list of all namespaces that are introduced to the XML tree by
this node.
|
java.lang.String |
getNamespaceURI()
This returns the URI mapped to this
Attribute 's
prefix. |
Element |
getParent()
This will return the parent of this
Attribute . |
java.lang.String |
getQualifiedName()
This will retrieve the qualified name of the
Attribute . |
java.lang.String |
getValue()
This will return the actual textual value of this
Attribute . |
boolean |
isSpecified()
Get the 'specified' flag.
|
Attribute |
setAttributeType(AttributeType type)
This will set the type of the
Attribute . |
Attribute |
setAttributeType(int type)
Deprecated.
|
Attribute |
setName(java.lang.String name)
This sets the local name of the
Attribute . |
Attribute |
setNamespace(Namespace namespace)
This sets this
Attribute 's . |
protected Attribute |
setParent(Element parent)
Set this Attribute's parent.
|
void |
setSpecified(boolean specified)
Change the specified flag to the given value.
|
Attribute |
setValue(java.lang.String value)
This will set the value of the
Attribute . |
java.lang.String |
toString()
This returns a
String representation of the
Attribute , suitable for debugging. |
public static final AttributeType UNDECLARED_TYPE
AttributeType.UNDECLARED
public static final AttributeType CDATA_TYPE
AttributeType.CDATA
public static final AttributeType ID_TYPE
AttributeType.ID
public static final AttributeType IDREF_TYPE
AttributeType.IDREF
public static final AttributeType IDREFS_TYPE
AttributeType.IDREFS
public static final AttributeType ENTITY_TYPE
AttributeType.ENTITY
public static final AttributeType ENTITIES_TYPE
AttributeType.ENTITIES
public static final AttributeType NMTOKEN_TYPE
AttributeType.NMTOKEN
public static final AttributeType NMTOKENS_TYPE
AttributeType.NMTOKENS
public static final AttributeType NOTATION_TYPE
AttributeType.NOTATION
public static final AttributeType ENUMERATED_TYPE
AttributeType.ENUMERATION
protected java.lang.String name
Attribute
protected java.lang.String value
Attribute
protected AttributeType type
Attribute
protected boolean specified
protected transient Element parent
setParent(Element)
protected Attribute()
public Attribute(java.lang.String name, java.lang.String value, Namespace namespace)
Attribute
with the
specified (local) name and value, and in the provided
Namespace
.name
- String
name of Attribute
.value
- String
value for new attribute.namespace
- Namespace
namespace for new attribute.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 by
Verifier.checkCharacterData(java.lang.String)
).@Deprecated public Attribute(java.lang.String name, java.lang.String value, int type, Namespace namespace)
Attribute(String, String, AttributeType, Namespace)
.Attribute
with the
specified (local) name, value, and type, and in the provided
Namespace
.name
- String
name of Attribute
.value
- String
value for new attribute.type
- int
type for new attribute.namespace
- Namespace
namespace for new attribute.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 by
Verifier.checkCharacterData(java.lang.String)
) or
if the given attribute type is not one of the
supported types.public Attribute(java.lang.String name, java.lang.String value, AttributeType type, Namespace namespace)
Attribute
with the
specified (local) name, value, and type, and in the provided
Namespace
.name
- String
name of Attribute
.value
- String
value for new attribute.type
- AttributeType
for new attribute.namespace
- Namespace
namespace for new attribute.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 by
Verifier.checkCharacterData(java.lang.String)
) or
if the given attribute type is not one of the
supported types.public Attribute(java.lang.String name, java.lang.String value)
Attribute
with the
specified (local) name and value, and does not place
the attribute in a Namespace
.
Note: This actually explicitly puts the
Attribute
in the "empty" Namespace
(
).Namespace.NO_NAMESPACE
name
- String
name of Attribute
.value
- String
value for new attribute.IllegalNameException
- if the given name is illegal as an
attribute name.IllegalDataException
- if the given attribute value is
illegal character data (as determined by
Verifier.checkCharacterData(java.lang.String)
).public Attribute(java.lang.String name, java.lang.String value, AttributeType type)
Attribute
with the
specified (local) name, value and type, and does not place
the attribute in a Namespace
.
Note: This actually explicitly puts the
Attribute
in the "empty" Namespace
(
).Namespace.NO_NAMESPACE
name
- String
name of Attribute
.value
- String
value for new attribute.type
- AttributeType
for new attribute.IllegalNameException
- if the given name is illegal as an
attribute name.IllegalDataException
- if the given attribute value is
illegal character data (as determined by
Verifier.checkCharacterData(java.lang.String)
) or
if the given attribute type is not one of the
supported types.@Deprecated public Attribute(java.lang.String name, java.lang.String value, int type)
Attribute(String, String, AttributeType)
Attribute
with the
specified (local) name, value and type, and does not place
the attribute in a Namespace
.
Note: This actually explicitly puts the
Attribute
in the "empty" Namespace
(
).Namespace.NO_NAMESPACE
name
- String
name of Attribute
.value
- String
value for new attribute.type
- int
type for new attribute.IllegalNameException
- if the given name is illegal as an
attribute name.IllegalDataException
- if the given attribute value is
illegal character data (as determined by
Verifier.checkCharacterData(java.lang.String)
) or
if the given attribute type is not one of the
supported types.public Element getParent()
Attribute
.
If there is no parent, then this returns null
.
Use return-type covariance to override Content's getParent() method
to return an Element, not just a ParentAttribute
public Document getDocument()
public java.lang.String getName()
Attribute
. 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()
String
- name of this attribute,
without any namespace prefix.public Attribute setName(java.lang.String name)
Attribute
.name
- the new local name to setAttribute
- the attribute modified.IllegalNameException
- if the given name is illegal as an
attribute name.public java.lang.String getQualifiedName()
Attribute
.
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()
String
- full name for this element.public java.lang.String getNamespacePrefix()
Attribute
. 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 empty String
is returned.String
- namespace prefix of this
attribute.public java.lang.String getNamespaceURI()
Attribute
's
prefix. If no mapping is found, an empty String
is
returned.String
- namespace URI for this Attribute
.public Namespace getNamespace()
Attribute
's
Namespace
.Namespace
- Namespace object for this Attribute
public Attribute setNamespace(Namespace namespace)
Attribute
's Namespace
.
If the provided namespace is null, the attribute will have no namespace.
The namespace must have a prefix.namespace
- the new namespaceElement
- the element modified.IllegalNameException
- if the new namespace is the default
namespace. Attributes cannot be in a default namespace.public java.lang.String getValue()
Attribute
. This will include all text
within the quotation marks.String
- value for this attribute.public Attribute setValue(java.lang.String value)
Attribute
.value
- String
value for the attribute.Attribute
- this Attribute modified.IllegalDataException
- if the given attribute value is
illegal character data (as determined by
Verifier.checkCharacterData(java.lang.String)
).public AttributeType getAttributeType()
Attribute
.AttributeType
- type for this attribute.public Attribute setAttributeType(AttributeType type)
Attribute
.type
- int
type for the attribute.Attribute
- this Attribute modified.IllegalDataException
- if the given attribute type is
not one of the supported types.@Deprecated public Attribute setAttributeType(int type)
setAttributeType(AttributeType)
Attribute
.type
- int
type for the attribute.Attribute
- this Attribute modified.IllegalDataException
- if the given attribute type is
not one of the supported types.public boolean isSpecified()
public void setSpecified(boolean specified)
specified
- The value to set the specified flag to.public java.lang.String toString()
String
representation of the
Attribute
, suitable for debugging.toString
in class java.lang.Object
String
- information about the
Attribute
public Attribute clone()
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.
public Attribute detach()
protected Attribute setParent(Element parent)
parent
- The parent to setpublic int getIntValue() throws DataConversionException
int
form, and if no conversion
can occur, throws a
DataConversionException
int
value of attribute.DataConversionException
- when conversion fails.public long getLongValue() throws DataConversionException
long
form, and if no conversion
can occur, throws a
DataConversionException
long
value of attribute.DataConversionException
- when conversion fails.public float getFloatValue() throws DataConversionException
float
form, and if no conversion
can occur, throws a
DataConversionException
float
value of attribute.DataConversionException
- when conversion fails.public double getDoubleValue() throws DataConversionException
double
form, and if no conversion
can occur, throws a
DataConversionException
double
value of attribute.DataConversionException
- when conversion fails.public boolean getBooleanValue() throws DataConversionException
DataConversionException
if 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.boolean
value of attribute.DataConversionException
- when conversion fails.public java.util.List<Namespace> getNamespacesInScope()
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 NamespaceAware
documentation for details on what the order of the
Namespaces will be in the returned list.
getNamespacesInScope
in interface NamespaceAware
public java.util.List<Namespace> getNamespacesIntroduced()
NamespaceAware
The contents of this list will always be a subset (but in the same order) of getNamespacesInScope(), and will never intersect getNamspacesInherited()
getNamespacesIntroduced
in interface NamespaceAware
public java.util.List<Namespace> getNamespacesInherited()
NamespaceAware
The contents of this list will always be a subset (but in the same order) of getNamespacesInScope(), and will never intersect getNamspacesIntroduced()
getNamespacesInherited
in interface NamespaceAware
Copyright © 2021 Jason Hunter, Brett McLaughlin. All Rights Reserved.