#ifndef JEZUK_DOM_DOCUMENT_H #define JEZUK_DOM_DOCUMENT_H //////////////////////////// // C++ DOM definition //////////////////////////// #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace Arabica { namespace DOM { namespace Events { template class DocumentEvent; } // namespace Events template class Document_impl; template > class Document : public Node { typedef Node NodeT; public: Document() : Node() { } Document(Document_impl* impl) : Node(impl) { } Document(const Document& rhs) : Node(rhs) { } explicit Document(const Node& rhs) : Node(rhs) { if(NodeT::impl_ == 0) // null nodes can always be cast return; if(rhs.getNodeType() != Node::DOCUMENT_NODE) throw DOMBadCast("Document"); } // Document ~Document() { } Document& operator=(const Document& rhs) { Node::operator=(rhs); return *this; } // operator DocumentType getDoctype() const { return dImpl()->getDoctype(); } DOMImplementation getImplementation() const { return DOMImplementation(dImpl()->getImplementation()); } Element getDocumentElement() const { return Element(dImpl()->getDocumentElement()); } Element createElement(const stringT& tagName) const { return Element(dImpl()->createElement(tagName)); } DocumentFragment createDocumentFragment() const { return DocumentFragment(dImpl()->createDocumentFragment()); } Text createTextNode(const stringT& data) const { return Text(dImpl()->createTextNode(data)); } Comment createComment(const stringT& data) const { return Comment(dImpl()->createComment(data)); } CDATASection createCDATASection(const stringT& data) const { return CDATASection(dImpl()->createCDATASection(data)); } ProcessingInstruction createProcessingInstruction(const stringT& target, const stringT& data) const { return ProcessingInstruction(dImpl()->createProcessingInstruction(target, data)); } // createProcessingInstruction Attr createAttribute(const stringT& name) const { return Attr(dImpl()->createAttribute(name)); } EntityReference createEntityReference(const stringT& name) const { return EntityReference(dImpl()->createEntityReference(name)); } NodeList getElementsByTagName(const stringT& tagname) const { return NodeList(dImpl()->getElementsByTagName(tagname)); } Node importNode(const Node& importedNode, bool deep) const { return Node(dImpl()->importNode(*importedNode.impl_, deep)); } Element createElementNS(const stringT& namespaceURI, const stringT& qualifiedName) const { return Element(dImpl()->createElementNS(namespaceURI, qualifiedName)); } // createElementNS Attr createAttributeNS(const stringT& namespaceURI, const stringT& qualifiedName) const { return Attr(dImpl()->createAttributeNS(namespaceURI, qualifiedName)); } // createAttributeNS NodeList getElementsByTagNameNS(const stringT& namespaceURI, const stringT& localName) const { return NodeList(dImpl()->getElementsByTagNameNS(namespaceURI, localName)); } // getElementsByTagNameNS Element getElementById(const stringT& elementId) const { return Element(dImpl()->getElementById(elementId)); } // getElementById Traversal::DocumentTraversal createDocumentTraversal() { Traversal::DocumentTraversal docTraversal(new Traversal::DocumentTraversalImpl()); return docTraversal; } // createDocumentTraversal private: Document_impl* dImpl() const { return dynamic_cast*>(*NodeT::impl_); } typedef class Traversal::DocumentTraversal DocumentTraversalT; friend class Traversal::DocumentTraversal; typedef class Events::DocumentEvent DocumentEventT; friend class Events::DocumentEvent; }; // class Document ////////////////////////////////////////////////////////// template class DocumentType_impl; template class DOMImplementation_impl; template class Element_impl; template class DocumentFragment_impl; template class Text_impl; template class Comment_impl; template class CDATASection_impl; template class ProcessingInstruction_impl; template class Attr_impl; template class EntityReference_impl; template class NodeList_impl; template class Document_impl : virtual public Node_impl { public: virtual ~Document_impl() { } virtual DocumentType_impl* getDoctype() const = 0; virtual DOMImplementation getImplementation() const = 0; virtual Element_impl* getDocumentElement() const = 0; virtual Element_impl* createElement(const stringT& tagName) const = 0; virtual DocumentFragment_impl* createDocumentFragment() const = 0; virtual Text_impl* createTextNode(const stringT& data) const = 0; virtual Comment_impl* createComment(const stringT& data) const = 0; virtual CDATASection_impl* createCDATASection(const stringT& data) const = 0; virtual ProcessingInstruction_impl* createProcessingInstruction(const stringT& target, const stringT& data) const = 0; virtual Attr_impl* createAttribute(const stringT& name) const = 0; virtual EntityReference_impl* createEntityReference(const stringT& name) const = 0; virtual NodeList_impl* getElementsByTagName(const stringT& tagname) const = 0; virtual Node_impl* importNode(Node_impl* importedNode, bool deep) const = 0; virtual Element_impl* createElementNS(const stringT& namespaceURI, const stringT& qualifiedName) const = 0; virtual Attr_impl* createAttributeNS(const stringT& namespaceURI, const stringT& qualifiedName) const = 0; virtual NodeList_impl* getElementsByTagNameNS(const stringT& namespaceURI, const stringT& localName) const = 0; virtual Element_impl* getElementById(const stringT& elementId) const = 0; }; // class Document_impl } // namespace DOM } // namespace Arabica #endif