2002-06-21 13:16:28 +02:00
|
|
|
#ifndef JEZUK_SimpleDOM_ATTRNSIMPL_H
|
|
|
|
#define JEZUK_SimpleDOM_ATTRNSIMPL_H
|
|
|
|
|
2007-09-05 00:55:47 +02:00
|
|
|
#include <DOM/Simple/AttrImpl.hpp>
|
|
|
|
#include <DOM/Simple/Helpers.hpp>
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2007-09-05 13:47:13 +02:00
|
|
|
namespace Arabica
|
|
|
|
{
|
2002-06-21 13:16:28 +02:00
|
|
|
namespace SimpleDOM
|
|
|
|
{
|
|
|
|
|
|
|
|
template<class stringT, class string_adaptorT>
|
|
|
|
class AttrNSImpl : public AttrImpl<stringT, string_adaptorT>
|
|
|
|
{
|
2005-09-08 23:43:21 +02:00
|
|
|
typedef typename string_adaptorT::size_type size_type;
|
2004-09-14 22:51:36 +02:00
|
|
|
typedef AttrImpl<stringT, string_adaptorT> AttrT;
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
AttrNSImpl(DocumentImpl<stringT, string_adaptorT>* ownerDoc,
|
|
|
|
const stringT& namespaceURI,
|
|
|
|
bool hasNamespaceURI,
|
|
|
|
const stringT& qualifiedName) :
|
|
|
|
AttrImpl<stringT, string_adaptorT>(ownerDoc, qualifiedName),
|
2005-12-16 20:08:46 +01:00
|
|
|
prefix_(&ownerDoc->empty_string()),
|
|
|
|
hasNamespaceURI_(false)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
bool hasPrefix = false;
|
2005-12-09 16:20:08 +01:00
|
|
|
stringT const* prefix_for_checking = (&ownerDoc->empty_string());
|
2005-09-30 23:36:11 +02:00
|
|
|
size_type index = string_adaptorT::find(qualifiedName, string_adaptorT::construct_from_utf8(":"));
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2006-06-08 11:51:18 +02:00
|
|
|
if(index == string_adaptorT::npos())
|
2002-06-21 13:16:28 +02:00
|
|
|
{ //qualifiedName contains no ':'
|
2005-12-09 12:49:03 +01:00
|
|
|
localName_ = AttrT::ownerDoc_->stringPool(qualifiedName);
|
|
|
|
if(*localName_ == string_adaptorT::construct_from_utf8("xmlns"))
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
|
|
|
hasPrefix = true;
|
2005-12-09 16:20:08 +01:00
|
|
|
prefix_for_checking = localName_;
|
2005-09-30 23:36:11 +02:00
|
|
|
} // if ...
|
2002-06-21 13:16:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hasPrefix = true;
|
2005-12-09 16:20:08 +01:00
|
|
|
prefix_ = AttrT::ownerDoc_->stringPool(string_adaptorT::substr(qualifiedName, 0, index));
|
2005-12-09 12:49:03 +01:00
|
|
|
localName_ = AttrT::ownerDoc_->stringPool(string_adaptorT::substr(qualifiedName, index+1));
|
2005-12-09 16:20:08 +01:00
|
|
|
prefix_for_checking = prefix_;
|
2005-09-30 23:36:11 +02:00
|
|
|
} // if(index == string_adaptorT::npos)
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
std::pair<bool, stringT> mappedURI =
|
2005-12-09 16:20:08 +01:00
|
|
|
checkPrefixAndNamespace<stringT, string_adaptorT>(hasPrefix, *prefix_for_checking, hasNamespaceURI, namespaceURI, DOM::Node<stringT>::ATTRIBUTE_NODE);
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
hasNamespaceURI_ = mappedURI.first;
|
2005-12-09 12:49:03 +01:00
|
|
|
namespaceURI_ = AttrT::ownerDoc_->stringPool(mappedURI.second);
|
2002-06-21 13:16:28 +02:00
|
|
|
} // AttrImpl
|
|
|
|
|
|
|
|
virtual ~AttrNSImpl() { }
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
// DOM::Node methods
|
|
|
|
virtual DOM::Node_impl<stringT>* cloneNode(bool deep) const
|
|
|
|
{
|
2005-12-09 12:49:03 +01:00
|
|
|
AttrNSImpl* clone = dynamic_cast<AttrNSImpl*>(AttrT::ownerDoc_->createAttributeNS(*namespaceURI_, *AttrT::name_));
|
2004-10-12 22:49:30 +02:00
|
|
|
AttrT::cloneChildren(clone);
|
2004-09-18 01:17:51 +02:00
|
|
|
clone->setSpecified(AttrT::getSpecified());
|
2002-06-21 13:16:28 +02:00
|
|
|
return clone;
|
|
|
|
} // cloneNode
|
|
|
|
|
2005-12-09 16:20:08 +01:00
|
|
|
virtual const stringT& getNamespaceURI() const
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
2005-12-09 12:49:03 +01:00
|
|
|
return *namespaceURI_;
|
2002-06-21 13:16:28 +02:00
|
|
|
} // getNamespaceURI
|
|
|
|
|
2005-12-09 16:20:08 +01:00
|
|
|
virtual const stringT& getPrefix() const
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
2005-12-09 16:20:08 +01:00
|
|
|
return *prefix_;
|
2002-06-21 13:16:28 +02:00
|
|
|
} // getPrefix
|
|
|
|
|
|
|
|
virtual void setPrefix(const stringT& prefix)
|
|
|
|
{
|
|
|
|
if(hasNamespaceURI_ == false)
|
|
|
|
throw DOM::DOMException(DOM::DOMException::NAMESPACE_ERR);
|
|
|
|
|
2005-09-08 23:43:21 +02:00
|
|
|
if(string_adaptorT::empty(prefix))
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
2004-09-18 01:17:51 +02:00
|
|
|
AttrT::name_ = localName_;
|
2005-12-09 16:20:08 +01:00
|
|
|
prefix_ = &AttrT::ownerDoc_->empty_string();
|
2002-06-21 13:16:28 +02:00
|
|
|
return;
|
|
|
|
} // empty prefix
|
|
|
|
|
2005-12-09 12:49:03 +01:00
|
|
|
checkPrefixAndNamespace<stringT, string_adaptorT>(true, prefix, true, *namespaceURI_, DOM::Node<stringT>::ATTRIBUTE_NODE);
|
2002-06-21 13:16:28 +02:00
|
|
|
|
2005-12-09 12:49:03 +01:00
|
|
|
stringT newName = prefix;
|
|
|
|
string_adaptorT::append(newName, string_adaptorT::construct_from_utf8(":"));
|
|
|
|
string_adaptorT::append(newName, *localName_);
|
2005-12-09 16:20:08 +01:00
|
|
|
|
|
|
|
prefix_ = AttrT::ownerDoc_->stringPool(prefix);
|
2005-12-09 12:49:03 +01:00
|
|
|
AttrT::name_ = AttrT::ownerDoc_->stringPool(newName);
|
2002-06-21 13:16:28 +02:00
|
|
|
} // setPrefix
|
|
|
|
|
2005-12-09 16:20:08 +01:00
|
|
|
virtual const stringT& getLocalName() const
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
2005-12-09 12:49:03 +01:00
|
|
|
return *localName_;
|
2002-06-21 13:16:28 +02:00
|
|
|
} // getLocalName
|
|
|
|
|
|
|
|
// additional three methods - since C++ std::string (and by implication
|
|
|
|
// stringT) don't differenciate between a null string and an empty string,
|
|
|
|
// but the DOM recommendation does, I have to introduce these three methods
|
|
|
|
// to disambiguate. If they return false, the corresponding attribute should be
|
|
|
|
// considered null. If they return true, the attribute has been set EVEN IF
|
|
|
|
// it has been set to the empty string
|
|
|
|
virtual bool hasNamespaceURI() const
|
|
|
|
{
|
|
|
|
return hasNamespaceURI_;
|
|
|
|
} // hasNamespaceURI
|
|
|
|
|
|
|
|
virtual bool hasPrefix() const
|
|
|
|
{
|
2005-12-09 16:20:08 +01:00
|
|
|
return !(*prefix_ == AttrT::ownerDoc_->empty_string());
|
2002-06-21 13:16:28 +02:00
|
|
|
} // hasPrefix
|
|
|
|
|
|
|
|
private:
|
2005-12-09 12:49:03 +01:00
|
|
|
stringT const* namespaceURI_;
|
2005-12-09 16:20:08 +01:00
|
|
|
stringT const* prefix_;
|
2005-12-09 12:49:03 +01:00
|
|
|
stringT const* localName_;
|
2002-06-21 13:16:28 +02:00
|
|
|
bool hasNamespaceURI_;
|
|
|
|
}; // class AttrNSImpl
|
|
|
|
|
|
|
|
} // namespace SAX2DOM
|
2007-09-05 13:47:13 +02:00
|
|
|
} // namespace Arabica
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|