Cross-Platform C++

ot::sax
class AttributesImpl

#include "ot/sax/AttributesImpl.h"

ot::sax::Attributes ot::ManagedObject Default implementation of the SAX2 Attributes interface with the addition of manipulators so that the list can be modified or reused. There are two typical uses of this class:-
  1. to take a persistent snapshot of an Attributes object in a startElement event, or;
  2. to construct or modify an Attributes object in a SAX2 driver or filter.
This class differs slightly from the official SAX 2.0 distribution in that it omits certain methods or parameters that either deal with both local names and qualified names or that attempt to set the value of a local name in isolation. Local names are not well defined in SAX 2.0, which is confused further in this class because an AttributesImpl exists outside the scope of an XMLReader. For this reason the OpenTop designers decided to simplify matters by always avoiding conflicts between local and qualified names - which OpenTop treats as the same thing when XML namespace processing is disabled.

Since:
1.1



Constructor/Destructor Summary
AttributesImpl()
         Default constructor.
AttributesImpl(const Attributes& atts)
         Copies an existing Attributes object.

Method Summary
 void addAttribute(const String& uri, const String& qName, const String& type, const String& value)
         Add a new attribute to the end of the collection.
 void clear()
         Clear the attributes collection for reuse.
 virtual int getIndex(const String& qName) const
         Looks up an attribute's index by qualified (prefixed) name.
 virtual int getIndex(const String& uri, const String& localName) const
         Looks up an attribute's index by namespace uri and local name.
 virtual size_t getLength() const
         Returns the number of attributes in the collection.
 virtual String getLocalName(size_t index) const
         Returns the local name for the specified attribute.
 virtual String getQName(size_t index) const
         Returns the qualified (prefixed) name for the specified attribute.
 virtual String getType(size_t index) const
         Returns the type for the specified attribute.
 virtual String getType(const String& qName) const
         Returns the type for the specified attribute.
 virtual String getType(const String& uri, const String& localName) const
         Returns the type for the specified attribute.
 virtual String getURI(size_t index) const
         Returns the namespace URI for the specified attribute.
 virtual String getValue(size_t index) const
         Returns the value for the specified attribute.
 virtual String getValue(const String& qName) const
         Returns the value for the specified attribute.
 virtual String getValue(const String& uri, const String& localName) const
         Returns the value for the specified attribute.
 void removeAttribute(size_t index)
         Removes an attribute from the collection.
 void setAttribute(size_t index, const String& uri, const String& qName, const String& type, const String& value)
         Sets an attribute in the collection.
 void setAttributes(const Attributes& atts)
         Copies an Attributes collection.
 void setQName(size_t index, const String& qName)
         Sets the qualified name of a specified attribute.
 void setType(size_t index, const String& type)
         Sets the type of a specified attribute.
 void setURI(size_t index, const String& uri)
         Sets the namespace URI of a specified attribute.
 void setValue(size_t index, const String& value)
         Sets the value of a specified attribute.

Methods inherited from class ot::ManagedObject
addRef, getRefCount, onFinalRelease, operator=, release

Constructor/Destructor Detail

AttributesImpl

 AttributesImpl()
Default constructor.


AttributesImpl

 AttributesImpl(const Attributes& atts)
Copies an existing Attributes object.


Method Detail

addAttribute

void addAttribute(const String& uri,
                  const String& qName,
                  const String& type,
                  const String& value)
Add a new attribute to the end of the collection. For the sake of speed, this method does no checking for well-formedness: such checks are the responsibility of the application.

Note, for convenience to OpenTop users, this method differs from the standard SAX 2 distribution in two ways:-

  1. The method does not accepts a localName. The qName parameter should be used for the attribute name, regardless of whether or not namespace processing is enabled.
  2. An IllegalArgumentException is thrown if an attribute with the same name already exists in the collection.

Parameters:
uri - the namespace URI, or the empty string if none is available or namespace processing is not being performed.
qName - the qualified (prefixed) name of the attribute. The name is not required to contain a prefix, but if it does the uri parameter should also be provided when namespaces are in effect.
type - the attribute type as a string
value - the attribute value
Exceptions:
IllegalArgumentException - if the attribute already exists in the collection

clear

void clear()
Clear the attributes collection for reuse.


getIndex

virtual int getIndex(const String& qName) const
Looks up an attribute's index by qualified (prefixed) name.

Parameters:
qName - the qualified name to look for
Returns:
the attribute's index in the collection, or -1 if the qName was not found

getIndex

virtual int getIndex(const String& uri,
                     const String& localName) const
Looks up an attribute's index by namespace uri and local name.

Parameters:
uri - the uri for the attribute to search for
localName - the local name for the attribute to search for
Returns:
the attribute's index in the collection, or -1 if no matching attribute could be found

getLength

virtual size_t getLength() const
Returns the number of attributes in the collection.


getLocalName

virtual String getLocalName(size_t index) const
Returns the local name for the specified attribute.

Parameters:
index - the 0-based index of the attribute whose local name is required
Returns:
the local name of the specified attribute or the empty string if none is available or if the index is out of range

getQName

virtual String getQName(size_t index) const
Returns the qualified (prefixed) name for the specified attribute.

Parameters:
index - the 0-based index of the attribute whose qualified name is required
Returns:
the qualified name of the specified attribute or the empty string if none is available or if the index is out of range

getType

virtual String getType(size_t index) const
Returns the type for the specified attribute.

Parameters:
index - the 0-based index of the attribute whose type is required
Returns:
the type of the specified attribute, "CDATA" if the type is unknown or the empty string if the index is out of range

getType

virtual String getType(const String& qName) const
Returns the type for the specified attribute.

Parameters:
qName - the qualified name of the attribute whose type is required
Returns:
the type of the specified attribute, "CDATA" if the type is unknown of the empty string if the attribute could not be found.

getType

virtual String getType(const String& uri,
                       const String& localName) const
Returns the type for the specified attribute.

Parameters:
uri - The attribute's Namespace URI, or the empty string if none is available.
localName - The attribute's local name
Returns:
the type of the specified attribute, "CDATA" if the type is unknown of the empty string if the attribute could not be found.

getURI

virtual String getURI(size_t index) const
Returns the namespace URI for the specified attribute.

Parameters:
index - the 0-based index of the attribute whose URI is required
Returns:
the URI of the specified attribute, or the empty string if none is available or if the index is out of range

getValue

virtual String getValue(size_t index) const
Returns the value for the specified attribute.

Parameters:
index - the 0-based index of the attribute whose value is required
Returns:
the value of the specified attribute, or the empty string if none is available or if the index is out of range

getValue

virtual String getValue(const String& qName) const
Returns the value for the specified attribute.

Parameters:
qName - the qualified name of the attribute whose value is required
Returns:
the value of the specified attribute, or the empty string if none is available or if the attribute could not be found

getValue

virtual String getValue(const String& uri,
                        const String& localName) const
Returns the value for the specified attribute.

Parameters:
uri - The attribute's Namespace URI, or the empty string if none is available.
localName - The attribute's local name
Returns:
the value of the specified attribute or the empty string if the attribute could not be found.

removeAttribute

void removeAttribute(size_t index)
Removes an attribute from the collection.

Parameters:
index - the 0-based index of the attribute to be removed
Exceptions:
IllegalArgumentException - if index specifies an attribute which is not in the collection

setAttribute

void setAttribute(size_t index,
                  const String& uri,
                  const String& qName,
                  const String& type,
                  const String& value)
Sets an attribute in the collection.

For the sake of speed, this method does no checking for name conflicts or well-formedness: such checks are the responsibility of the application.

Note, for convenience to OpenTop users, this method differs from the standard SAX 2 distribution in that it does not accepts a localName. The qName parameter should be used for the attribute name, regardless of whether or not namespace processing is enabled.

Parameters:
index - the 0-based index of the item to be modified
uri - the namespace URI, or the empty string if none is available or namespace processing is not being performed.
qName - the qualified (prefixed) name of the attribute. The name is not required to contain a prefix, but if it does the uri parameter should also be provided when namespaces are in effect.
type - the attribute type as a string
value - the attribute value
Exceptions:
IllegalArgumentException - if index is larger than the number of entries in the collection.

setAttributes

void setAttributes(const Attributes& atts)
Copies an Attributes collection.

Parameters:
atts - the attributes to copy
Exceptions:
IllegalArgumentException - if the passed collection contains a duplicate attribute.

setQName

void setQName(size_t index,
              const String& qName)
Sets the qualified name of a specified attribute.

Parameters:
index - the 0-based index of the attribute to be modified
qName - the new qualified name for the attribute
Exceptions:
IllegalArgumentException - if index is larger than the number of entries in the collection.

setType

void setType(size_t index,
             const String& type)
Sets the type of a specified attribute.

Parameters:
index - the 0-based index of the attribute to be modified
type - the new type for the attribute
Exceptions:
IllegalArgumentException - if index is larger than the number of entries in the collection.

setURI

void setURI(size_t index,
            const String& uri)
Sets the namespace URI of a specified attribute.

Parameters:
index - the 0-based index of the attribute to be modified
uri - the new uri for the attribute
Exceptions:
IllegalArgumentException - if index is larger than the number of entries in the collection.

setValue

void setValue(size_t index,
              const String& value)
Sets the value of a specified attribute.

Parameters:
index - the 0-based index of the attribute to be modified
value - the new value for the attribute
Exceptions:
IllegalArgumentException - if index is larger than the number of entries in the collection.


Cross-Platform C++

Found a bug or missing feature? Please email us at support@elcel.com

Copyright © 2000-2003 ElCel Technology   Trademark Acknowledgements