2002-06-21 13:16:28 +02:00
|
|
|
#ifndef JEZUK_SimpleDOM_ELEMENTNSIMPL_H
|
|
|
|
#define JEZUK_SimpleDOM_ELEMENTNSIMPL_H
|
|
|
|
|
|
|
|
#include <DOM/Simple/ElementImpl.h>
|
|
|
|
#include <DOM/Simple/Helpers.h>
|
|
|
|
|
|
|
|
namespace SimpleDOM
|
|
|
|
{
|
|
|
|
|
|
|
|
template<class stringT, class string_adaptorT>
|
|
|
|
class ElementNSImpl : public ElementImpl<stringT, string_adaptorT>
|
|
|
|
{
|
2004-09-14 22:51:36 +02:00
|
|
|
typedef typename stringT::size_type size_type;
|
|
|
|
typedef ElementImpl<stringT, string_adaptorT> ElementImplT;
|
2002-06-21 13:16:28 +02:00
|
|
|
public:
|
|
|
|
ElementNSImpl(DocumentImpl<stringT, string_adaptorT>* ownerDoc,
|
|
|
|
const stringT& namespaceURI,
|
|
|
|
bool hasNamespaceURI,
|
|
|
|
const stringT& qualifiedName) :
|
|
|
|
ElementImpl<stringT, string_adaptorT>(ownerDoc, qualifiedName),
|
|
|
|
hasNamespaceURI_(false)
|
|
|
|
{
|
|
|
|
string_adaptorT SA;
|
|
|
|
bool hasPrefix = false;
|
|
|
|
stringT prefix;
|
|
|
|
size_type index = qualifiedName.find(SA.makeStringT(":"));
|
|
|
|
|
|
|
|
if(index == stringT::npos)
|
2004-09-18 01:17:51 +02:00
|
|
|
{ //qualifiedName contains no ':'
|
|
|
|
localName_ = qualifiedName;
|
2002-06-21 13:16:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hasPrefix = true;
|
2004-09-18 01:17:51 +02:00
|
|
|
prefix = qualifiedName.substr(0, index);
|
|
|
|
localName_ = qualifiedName.substr(index+1);
|
2002-06-21 13:16:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<bool, stringT> mappedURI =
|
|
|
|
checkPrefixAndNamespace<stringT, string_adaptorT>(hasPrefix, prefix, hasNamespaceURI, namespaceURI, DOM::Node<stringT>::ELEMENT_NODE);
|
|
|
|
|
|
|
|
hasNamespaceURI_ = mappedURI.first;
|
|
|
|
namespaceURI_ = mappedURI.second;
|
|
|
|
} // ElementImpl
|
|
|
|
|
|
|
|
virtual ~ElementNSImpl() { }
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
// DOM::Node methods
|
|
|
|
virtual DOM::Node_impl<stringT>* cloneNode(bool deep) const
|
|
|
|
{
|
2004-09-18 01:17:51 +02:00
|
|
|
ElementNSImpl* clone = dynamic_cast<ElementNSImpl*>(ElementImplT::ownerDoc_->createElementNS(namespaceURI_, ElementImplT::tagName_));
|
2004-10-12 22:49:30 +02:00
|
|
|
ElementImplT::cloneChildren(clone, deep);
|
2002-06-21 13:16:28 +02:00
|
|
|
return clone;
|
|
|
|
} // cloneNode
|
|
|
|
|
|
|
|
virtual stringT getNamespaceURI() const
|
|
|
|
{
|
|
|
|
return namespaceURI_;
|
|
|
|
} // getNamespaceURI
|
|
|
|
|
|
|
|
virtual stringT getPrefix() const
|
|
|
|
{
|
|
|
|
string_adaptorT SA;
|
2004-09-18 01:17:51 +02:00
|
|
|
size_type index = ElementImplT::tagName_.find(SA.makeStringT(":"));
|
|
|
|
return (index != stringT::npos) ? ElementImplT::tagName_.substr(0, index) : stringT();
|
2002-06-21 13:16:28 +02:00
|
|
|
} // getPrefix
|
|
|
|
|
|
|
|
virtual void setPrefix(const stringT& prefix)
|
|
|
|
{
|
2004-09-18 01:17:51 +02:00
|
|
|
ElementImplT::throwIfReadOnly();
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
if(hasNamespaceURI_ == false)
|
|
|
|
throw DOM::DOMException(DOM::DOMException::NAMESPACE_ERR);
|
|
|
|
|
|
|
|
if(prefix.empty())
|
|
|
|
{
|
2004-09-18 01:17:51 +02:00
|
|
|
ElementImplT::tagName_ = localName_;
|
2002-06-21 13:16:28 +02:00
|
|
|
return;
|
|
|
|
} // empty prefix
|
|
|
|
|
|
|
|
checkPrefixAndNamespace<stringT, string_adaptorT>(true, prefix, true, namespaceURI_, DOM::Node<stringT>::ELEMENT_NODE);
|
|
|
|
|
|
|
|
string_adaptorT SA;
|
2004-09-18 01:17:51 +02:00
|
|
|
ElementImplT::tagName_ = prefix + SA.makeStringT(":") + localName_;
|
2002-06-21 13:16:28 +02:00
|
|
|
} // setPrefix
|
|
|
|
|
|
|
|
virtual stringT getLocalName() const
|
|
|
|
{
|
|
|
|
return localName_;
|
|
|
|
} // 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
|
|
|
|
{
|
|
|
|
string_adaptorT SA;
|
2004-09-18 01:17:51 +02:00
|
|
|
return (ElementImplT::tagName_.find(SA.makeStringT(":")) != stringT::npos);
|
2002-06-21 13:16:28 +02:00
|
|
|
} // hasPrefix
|
|
|
|
|
|
|
|
private:
|
|
|
|
stringT namespaceURI_;
|
|
|
|
stringT localName_;
|
|
|
|
bool hasNamespaceURI_;
|
|
|
|
}; // class ElementImpl
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace SAX2DOM
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|