|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.org.blankaspect.nlf.Chunk
uk.org.blankaspect.nlf.Attributes
public class Attributes
This class implements an attributes chunk. An attributes chunk is a special chunk in
a Nested List File. A chunk list may contain one attributes chunk, which has the
reserved identifier $ATTR
and consists of a list of name-value pairs, analogous to the attributes
of an element in an XML document. The names of the attributes in an attributes list must be unique. In
a Nested List File, the name and value of an attribute are each encoded as two size bytes followed by a
UTF-8 sequence. The byte order of the size bytes is determined by the byte-order flag in the header of
the Nested List File document
to which the chunk belongs. The maximum size of a name or
value is 65535 bytes.
To allow the conversion of a Nested List File to XML, an attribute name must be valid unprefixed name (ie, a name that doesn't contain a ':') under XML 1.1. Note that XML 1.1 names are less restrictive than those of XML 1.0, so that a name that is valid under XML 1.1 might not be valid under XML 1.0.
When an attributes chunk is constructed, its chunk writer is set to a default writer, which is suitable
for use by Document.write(java.io.File)
. The default writer may be
replaced, using Chunk.setWriter(Chunk.Writer)
, if it is unsuitable
for a particular purpose. The rewrite
flag, which is accessed with isRewrite()
and setRewrite(boolean)
, is used by the default writer to
indicate to the document writer whether the attributes chunk
should be rewritten on the second pass (for example, if an attribute value can be set only after
subsequent chunks have been written).
Chunk
,
ChunkList
Nested Class Summary | |
---|---|
static class |
Attributes.Attr
This class implements an attribute name-value pair. |
Nested classes/interfaces inherited from class uk.org.blankaspect.nlf.Chunk |
---|
Chunk.Base64Encoder, Chunk.Encoder, Chunk.Processor, Chunk.Reader |
Field Summary | |
---|---|
static Id |
ATTRIBUTES_ID
|
static int |
MAX_NAME_SIZE
|
static int |
MAX_VALUE_SIZE
|
static int |
MIN_NAME_SIZE
|
static int |
MIN_VALUE_SIZE
|
protected static int |
NAME_SIZE_MASK
|
static int |
NAME_SIZE_SIZE
|
protected static int |
VALUE_SIZE_MASK
|
static int |
VALUE_SIZE_SIZE
|
Fields inherited from class uk.org.blankaspect.nlf.Chunk |
---|
document, encoder, id, MAX_SIZE, MIN_SIZE, parent, reader, size, SIZE_SIZE, writer |
Constructor Summary | |
---|---|
protected |
Attributes(Document document)
Constructs an attributes chunk. |
Method Summary | |
---|---|
boolean |
equals(java.lang.Object obj)
Compares this attributes chunk with a specified object. |
Attributes.Attr |
getAttribute(int index)
Returns the attribute at the specified index in the attributes list. |
int |
getNumAttributes()
Returns the number of attributes in this chunk's attributes list. |
boolean |
hasAttributes()
Returns true if this chunk contains at least one attribute. |
int |
hashCode()
Returns the hash code for this object. |
int |
indexOf(java.lang.String name)
Returns the index of the attribute with the specified name in this chunk's attributes list, or -1 if the list does not contain an attribute with the specified name. |
boolean |
isRewrite()
Returns true if the attributes will be rewritten on the second pass of the document writer. |
static boolean |
isValidName(java.lang.String str)
Tests whether the specified string is a valid attribute name. |
Attributes.Attr |
removeAttribute(int index)
Removes the attribute at the specified index from this chunk's attributes list, and returns the attribute that was removed. |
void |
setAttribute(Attributes.Attr attribute)
Sets the specified attribute in this chunk's attributes list. |
void |
setRewrite(boolean rewrite)
Sets the flag that indicates whether the attributes will be rewritten on the second pass of the document writer. |
java.lang.String |
toString()
Returns a string representation of the attributes chunk. |
protected void |
toXml(org.w3c.dom.Element element)
Sets the attributes in this chunk's attributes list as attributes of the specified XML element. |
Methods inherited from class uk.org.blankaspect.nlf.Chunk |
---|
compareTo, getDocument, getEncoder, getHeaderSize, getId, getName, getNamespaceName, getParent, getPathname, getReader, getSize, getSizeBytes, getWriter, isAttributes, isList, setEncoder, setParent, setReader, setSize, setWriter, toXml, updateSize, writeHeader |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final Id ATTRIBUTES_ID
public static final int NAME_SIZE_SIZE
public static final int MIN_NAME_SIZE
public static final int MAX_NAME_SIZE
protected static final int NAME_SIZE_MASK
public static final int VALUE_SIZE_SIZE
public static final int MIN_VALUE_SIZE
public static final int MAX_VALUE_SIZE
protected static final int VALUE_SIZE_MASK
Constructor Detail |
---|
protected Attributes(Document document)
The chunk writer for this chunk is set to a default chunk writer when an Attributes
object is
constructed. The default writer may be replaced by the base-class method Chunk.setWriter(Chunk.Writer)
.
document
- the document to which this chunk is to belong.Method Detail |
---|
public static boolean isValidName(java.lang.String str)
str
- the string that is to be tested.
true
if the specified string is a valid attribute name; false
otherwise.public boolean equals(java.lang.Object obj)
true
if and only if
obj
is an Attributes
object that contains the same attributes as this object, though
not necessarily in the same order.
equals
in class java.lang.Object
obj
- the object with which the comparison is to be made.
true
if obj
is an Attributes
object that contains the same attributes
as this object, though not necessarily in the same order; false
otherwise.public int hashCode()
hashCode
in class java.lang.Object
equals(Object)
public java.lang.String toString()
toString
in class java.lang.Object
Attributes.Attr.toString()
public boolean isRewrite()
true
if the attributes will be rewritten on the second pass of the document writer.
true
if the attributes will be rewritten on the second pass of the document writer;
false
otherwise.setRewrite(boolean)
public boolean hasAttributes()
true
if this chunk contains at least one attribute.
true
if this chunk contains at least one attribute; false
otherwise.getNumAttributes()
public int getNumAttributes()
hasAttributes()
public Attributes.Attr getAttribute(int index) throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException
- if (index < 0)
or (index >=
getNumAttributes()
)
.getNumAttributes()
public void setRewrite(boolean rewrite)
Attributes
object's default writer, can be
tested by a replacement writer with isRewrite()
.
rewrite
- true
if the attributes should be rewritten on the second pass of the document
writer; false
otherwise.isRewrite()
public int indexOf(java.lang.String name) throws java.lang.IllegalArgumentException
-1
if the list does not contain an attribute with the specified name. As the attributes in the list
must have unique names, any occurrence in the list of an attribute with a given name will be the only
occurrence.
name
- the name of the attribute whose index is to be determined.
-1
if the
list does not contain an attribute with the specified name.
java.lang.IllegalArgumentException
- if name
is null
.public void setAttribute(Attributes.Attr attribute) throws java.lang.IllegalArgumentException
attribute
- the attribute that is to be set in or added to the list of attributes.
java.lang.IllegalArgumentException
- if attribute
is null
.removeAttribute(int)
public Attributes.Attr removeAttribute(int index) throws java.lang.IndexOutOfBoundsException
index
- the index of the attribute that is to be removed from the list of attributes.
java.lang.IndexOutOfBoundsException
- if (index < 0)
or (index >=
getNumAttributes()
)
.setAttribute(Attr)
,
getNumAttributes()
,
indexOf(java.lang.String)
protected void toXml(org.w3c.dom.Element element) throws org.w3c.dom.DOMException
element
- the XML element on which the attributes are to be set.
org.w3c.dom.DOMException
- if an attribute name is not valid for the XML version of the document to which element
belongs.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |