Qt 4.8
Public Types | Public Functions | Private Types | Properties | List of all members
QPatternist::NamespaceSupport Class Reference

A helper class for handling nested namespace declarations. More...

#include <qnamespacesupport_p.h>

Public Types

enum  NameType { AttributeName, ElementName }
 

Public Functions

QList< QXmlNamenamespaceBindings () const
 
 NamespaceSupport ()
 
 NamespaceSupport (NamePool &namePool)
 
void popContext ()
 
QXmlName::PrefixCode prefix (const QXmlName::NamespaceCode code) const
 
bool processName (const QString &qualifiedName, NameType type, QXmlName &name) const
 
void pushContext ()
 
void setPrefix (const QXmlName::PrefixCode prefixCode, const QXmlName::NamespaceCode namespaceCode)
 
void setPrefixes (const QXmlStreamNamespaceDeclarations &declarations)
 
void setTargetNamespace (const QXmlName::NamespaceCode code)
 
QXmlName::NamespaceCode uri (const QXmlName::PrefixCode code) const
 

Private Types

typedef QHash< QXmlName::PrefixCode, QXmlName::NamespaceCodeNamespaceHash
 

Properties

NamePoolm_namePool
 
NamespaceHash m_ns
 
QStack< NamespaceHashm_nsStack
 

Detailed Description

A helper class for handling nested namespace declarations.

This class is mostly an adaption of QXmlNamespaceSupport to the NamePool mechanism used in XmlPatterns.

Author
Tobias Koenig tobia.nosp@m.s.ko.nosp@m.enig@.nosp@m.noki.nosp@m.a.com

Definition at line 78 of file qnamespacesupport_p.h.

Typedefs

◆ NamespaceHash

Definition at line 161 of file qnamespacesupport_p.h.

Enumerations

◆ NameType

Describes whether the name to process is an attribute or element.

Enumerator
AttributeName 

An attribute name to process.

ElementName 

An element name to process.

Definition at line 84 of file qnamespacesupport_p.h.

85  {
88  };

Constructors and Destructors

◆ NamespaceSupport() [1/2]

NamespaceSupport::NamespaceSupport ( )

Creates an empty namespace support object.

Definition at line 58 of file qnamespacesupport.cpp.

59 {
60 }

◆ NamespaceSupport() [2/2]

NamespaceSupport::NamespaceSupport ( NamePool namePool)

Creates a new namespace support object.

Parameters
namePoolThe name pool where all processed names are stored in.

Definition at line 62 of file qnamespacesupport.cpp.

63  : m_namePool(&namePool)
64 {
65  // the XML namespace
67 }
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753

Functions

◆ namespaceBindings()

QList< QXmlName > NamespaceSupport::namespaceBindings ( ) const

Returns the list of namespace bindings.

Definition at line 147 of file qnamespacesupport.cpp.

Referenced by QPatternist::XsdSchemaParser::readXPathAttribute(), and QPatternist::XsdSchemaParser::readXPathExpression().

148 {
149  QList<QXmlName> bindings;
150 
151  QHashIterator<QXmlName::PrefixCode, QXmlName::NamespaceCode> it(m_ns);
152  while (it.hasNext()) {
153  it.next();
154  bindings.append(QXmlName(it.value(), StandardLocalNames::empty, it.key()));
155  }
156 
157  return bindings;
158 }
#define it(className, varName)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58

◆ popContext()

void NamespaceSupport::popContext ( )

Pops the current namespace mapping from the stack.

Definition at line 140 of file qnamespacesupport.cpp.

Referenced by QPatternist::XsdSchemaParser::parseUnknown(), QPatternist::XsdSchemaParser::parseUnknownDocumentation(), and QPatternist::ElementNamespaceHandler::~ElementNamespaceHandler().

141 {
142  m_ns.clear();
143  if(!m_nsStack.isEmpty())
144  m_ns = m_nsStack.pop();
145 }
void clear()
Removes all items from the hash.
Definition: qhash.h:574
QStack< NamespaceHash > m_nsStack

◆ prefix()

QXmlName::PrefixCode NamespaceSupport::prefix ( const QXmlName::NamespaceCode  code) const

Returns the prefix code for the given namespace code.

Definition at line 90 of file qnamespacesupport.cpp.

91 {
93  while ((itc=it) != m_ns.constEnd()) {
94  ++it;
95  if (*itc == namespaceCode)
96  return itc.key();
97  }
98  return 0;
99 }
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469

◆ processName()

bool NamespaceSupport::processName ( const QString qualifiedName,
NameType  type,
QXmlName name 
) const

Converts the given qualifiedName to a resolved QXmlName name according to the current namespace mapping.

Parameters
qualifiedNameThe full qualified name.
typeThe type of name processing.
nameThe resolved QXmlName.
Returns
true if the name could be processed correctly or false if the namespace prefix is unknown.

Definition at line 106 of file qnamespacesupport.cpp.

Referenced by QPatternist::XsdSchemaParser::convertName().

107 {
108  int len = qname.size();
109  const QChar *data = qname.constData();
110  for (int pos = 0; pos < len; ++pos) {
111  if (data[pos] == QLatin1Char(':')) {
112  const QXmlName::PrefixCode prefixCode = m_namePool->allocatePrefix(qname.left(pos));
113  if (!m_ns.contains(prefixCode))
114  return false;
115  const QXmlName::NamespaceCode namespaceCode = uri(prefixCode);
116  const QXmlName::LocalNameCode localNameCode = m_namePool->allocateLocalName(qname.mid(pos + 1));
117  name = QXmlName(namespaceCode, localNameCode, prefixCode);
118  return true;
119  }
120  }
121 
122  // there was no ':'
123  QXmlName::NamespaceCode namespaceCode = 0;
124  // attributes don't take default namespace
125  if (type == ElementName && !m_ns.isEmpty()) {
126  namespaceCode = m_ns.value(0); // get default namespace
127  }
128 
129  const QXmlName::LocalNameCode localNameCode = m_namePool->allocateLocalName(qname);
130  name = QXmlName(namespaceCode, localNameCode, 0);
131 
132  return true;
133 }
int type
Definition: qmetatype.cpp:239
NamespaceCode LocalNameCode
Definition: qxmlname.h:84
qint16 NamespaceCode
Definition: qxmlname.h:82
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QXmlName::PrefixCode allocatePrefix(const QString &prefix)
Definition: qnamepool_p.h:214
QXmlName::LocalNameCode allocateLocalName(const QString &ln)
Definition: qnamepool_p.h:208
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297
static const char * data(const QByteArray &arr)
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QXmlName::NamespaceCode uri(const QXmlName::PrefixCode code) const
NamespaceCode PrefixCode
Definition: qxmlname.h:83

◆ pushContext()

void NamespaceSupport::pushContext ( )

◆ setPrefix()

void NamespaceSupport::setPrefix ( const QXmlName::PrefixCode  prefixCode,
const QXmlName::NamespaceCode  namespaceCode 
)

Adds a new prefix-to-namespace binding.

Parameters
prefixCodeThe name pool code for the prefix.
namespaceCodeThe name pool code for the namespace.

Definition at line 69 of file qnamespacesupport.cpp.

70 {
71  m_ns.insert(prefixCode, namespaceCode);
72 }
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753

◆ setPrefixes()

void NamespaceSupport::setPrefixes ( const QXmlStreamNamespaceDeclarations declarations)

Adds the prefix-to-namespace bindings from declarations to the namespace support.

Definition at line 74 of file qnamespacesupport.cpp.

Referenced by QPatternist::ElementNamespaceHandler::ElementNamespaceHandler(), QPatternist::XsdSchemaParser::parseUnknown(), and QPatternist::XsdSchemaParser::parseUnknownDocumentation().

75 {
76  for (int i = 0; i < declarations.count(); i++) {
77  const QXmlStreamNamespaceDeclaration declaration = declarations.at(i);
78 
79  const QXmlName::PrefixCode prefixCode = m_namePool->allocatePrefix(declaration.prefix().toString());
80  const QXmlName::NamespaceCode namespaceCode = m_namePool->allocateNamespace(declaration.namespaceUri().toString());
81  m_ns.insert(prefixCode, namespaceCode);
82  }
83 }
QString toString() const
Returns a copy of the string reference as a QString object.
Definition: qstring.cpp:8653
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
qint16 NamespaceCode
Definition: qxmlname.h:82
QXmlName::NamespaceCode allocateNamespace(const QString &uri)
Definition: qnamepool_p.h:202
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
QXmlName::PrefixCode allocatePrefix(const QString &prefix)
Definition: qnamepool_p.h:214
QStringRef namespaceUri() const
Returns the namespaceUri.
Definition: qxmlstream.h:216
QStringRef prefix() const
Returns the prefix.
Definition: qxmlstream.h:215
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QXmlStreamNamespaceDeclaration class represents a namespace declaration.
Definition: qxmlstream.h:204
NamespaceCode PrefixCode
Definition: qxmlname.h:83

◆ setTargetNamespace()

void NamespaceSupport::setTargetNamespace ( const QXmlName::NamespaceCode  code)

Sets the name pool code of the target namespace of the schema the namespace support works on.

Definition at line 85 of file qnamespacesupport.cpp.

Referenced by QPatternist::XsdSchemaParser::setTargetNamespaceExtended().

86 {
87  m_ns.insert(0, namespaceCode);
88 }
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753

◆ uri()

QXmlName::NamespaceCode NamespaceSupport::uri ( const QXmlName::PrefixCode  code) const

Returns the namespace code for the given prefix code.

Definition at line 101 of file qnamespacesupport.cpp.

Referenced by processName().

102 {
103  return m_ns.value(prefixCode);
104 }
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606

Properties

◆ m_namePool

NamePool* QPatternist::NamespaceSupport::m_namePool
private

Definition at line 163 of file qnamespacesupport_p.h.

Referenced by processName(), and setPrefixes().

◆ m_ns

NamespaceHash QPatternist::NamespaceSupport::m_ns
private

◆ m_nsStack

QStack<NamespaceHash> QPatternist::NamespaceSupport::m_nsStack
private

Definition at line 164 of file qnamespacesupport_p.h.

Referenced by popContext(), and pushContext().


The documentation for this class was generated from the following files: