diff options
author | Stef Walter <stef@memberwebs.com> | 2004-08-03 00:56:29 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2004-08-03 00:56:29 +0000 |
commit | 81cc6acd5996cd30f4a246a610d0e5a9ef697b3d (patch) | |
tree | 4b7e68a962a3f8706977edb656d0f323b7a758b8 /src | |
parent | 740d8a6bcb6521e188361befa7f5636c880bf63b (diff) |
DOMC preliminary testing and work.
Diffstat (limited to 'src')
-rw-r--r-- | src/domcxx.h | 50 | ||||
-rw-r--r-- | src/xmlcomposehelpers.h | 2 | ||||
-rw-r--r-- | src/xmlcomposer.cpp | 11 | ||||
-rw-r--r-- | src/xmlfixups.cpp | 7 |
4 files changed, 39 insertions, 31 deletions
diff --git a/src/domcxx.h b/src/domcxx.h index bd96078..9ebc023 100644 --- a/src/domcxx.h +++ b/src/domcxx.h @@ -93,7 +93,7 @@ namespace DOM DOMException(int e) { ASSERT(e != 0); - code = (short)e; + m_code = e; } typedef enum @@ -110,20 +110,21 @@ namespace DOM INUSE_ATTRIBUTE_ERR = 10 } CODES; - int getCode() - { return code; } - char* getMessage() - { /* TODO: Get from the domc library */ return NULL; } - void getDetails(int* cde, char** message, - char** documentUri, int* fileLine) + short getCode() + { return (short)m_code; } + const char* getMessage() + { return msgno_msg(m_code); } + void getDetails(short* code, const char** message, + const char** documentUri, int* fileLine) { - *cde = code; - *message = NULL; // TODO: Get from domc library + *code = (short)m_code; + *message = msgno_msg(m_code); *documentUri = NULL; *fileLine = 0; } - short code; + protected: + int m_code; }; class NodeList; @@ -132,11 +133,17 @@ namespace DOM class Document; class DOMImplementation; + /* Checks whether an element is part of the tree */ + #define LOOSE_NODE(n) \ + ((n) && ((n)->nodeType == DOM_ATTRIBUTE_NODE ? \ + (n)->u.Attr.ownerElement == NULL : \ + (n)->parentNode == NULL)) \ + /* We only perform ref counting on nodes outside the tree */ #define INC_NODE_REF(n) \ - if((n).m_node != NULL && ((n).m_node)->parentNode == NULL) incref((n).m_node) + if(LOOSE_NODE(n)) incref(n) #define DEC_NODE_REF(n) \ - if((n).m_node != NULL && ((n).m_node)->parentNode == NULL) decref((n).m_node) + if(LOOSE_NODE(n)) decref(n) /** * Thin wrapper class for a DOM Node @@ -165,14 +172,14 @@ namespace DOM Node(const Node& node) { - INC_NODE_REF(node); + INC_NODE_REF(node.m_node); m_node = node.m_node; } Node& operator=(const Node& other) { - INC_NODE_REF(other); - DEC_NODE_REF(*this); + INC_NODE_REF(other.m_node); + DEC_NODE_REF(m_node); m_node = other.m_node; return *this; } @@ -180,13 +187,13 @@ namespace DOM Node& operator=(const void* null) { ASSERT(null == NULL); - DEC_NODE_REF(*this); + DEC_NODE_REF(m_node); m_node = NULL; return *this; } ~Node() - { DEC_NODE_REF(*this); } + { DEC_NODE_REF(m_node); } bool operator==(const Node& other) const { return m_node == other.m_node; } @@ -395,7 +402,7 @@ namespace DOM m_node->attributes->length > 0; } - void* setUserData(void* data) + void setUserData(void* data) throw(DOMException) { ASSERT_VALID(); @@ -416,7 +423,7 @@ namespace DOM Node(DOM_Node* node) { m_node = node; - INC_NODE_REF(*this); + INC_NODE_REF(m_node); } protected: @@ -437,8 +444,9 @@ namespace DOM --(node->rtfxRefCount); if(node->rtfxRefCount <= 0) { - ASSERT(node->ownerDocument); - DOM_Document_destroyNode(node->ownerDocument, node); + ASSERT(node->nodeType == DOM_DOCUMENT_NODE || node->ownerDocument); + DOM_Document_destroyNode(node->nodeType == DOM_DOCUMENT_NODE ? + node : node->ownerDocument, node); } } }; diff --git a/src/xmlcomposehelpers.h b/src/xmlcomposehelpers.h index 64e4723..8a15d91 100644 --- a/src/xmlcomposehelpers.h +++ b/src/xmlcomposehelpers.h @@ -60,7 +60,7 @@ public: // This is called when the Destination is first used virtual void initialize() {}; // Called when data arrives at destination - virtual void charData(string data) {}; + virtual void charData(const string& data) {}; // Called when the Destination goes out of scope virtual void done() {}; diff --git a/src/xmlcomposer.cpp b/src/xmlcomposer.cpp index e642acb..93bd8f3 100644 --- a/src/xmlcomposer.cpp +++ b/src/xmlcomposer.cpp @@ -72,8 +72,11 @@ XmlComposer::~XmlComposer() void XmlComposer::clear() { - m_document = NULL; LevelHandler::clear(); + + // Make sure not to release document until we're + // done with all the nodes + m_document = NULL; } @@ -114,12 +117,12 @@ void XmlComposer::endDocument() XmlFixups fix; // Pass 1: Block breakout - /* fix.breakTables(m_document); + fix.breakTables(m_document); fix.breakTags(m_document, kElTable, kElRow); fix.breakTags(m_document, kElRow, kElCell); fix.wrapTags(m_document, kElCell, kElDest); fix.breakBlocks(m_document); - fix.breakLists(m_document); */ + fix.breakLists(m_document); // Pass 2: Fixups fix.runPassTwo(m_document); @@ -1202,7 +1205,7 @@ ON_CHARDATA(Attribute) // Append data if(data.at(data.size() - 1) == L';') - cur.append(data.substr(data.size() - 1)); + cur.append(data.substr(0, data.size() - 1)); else cur.append(data); diff --git a/src/xmlfixups.cpp b/src/xmlfixups.cpp index d9bdb0a..eb6fcb7 100644 --- a/src/xmlfixups.cpp +++ b/src/xmlfixups.cpp @@ -503,10 +503,8 @@ void XmlFixups::runPassTwo(const DOM::Document& doc) continue; // Current element no longer valid } - continue; - // Change id attribute on fonts to name - /* else */ if(haveFonts && name == kElFont) + if(haveFonts && name == kElFont) { if(el.hasAttribute(kAtId)) { @@ -779,7 +777,6 @@ void XmlFixups::fixBlock(const DOM::Document& doc, DOM::Element& block) while(block.hasChildNodes()) el.appendChild(block.removeChild(block.getFirstChild())); - // parent.replaceChild(el, block); - parent.appendChild(el); + parent.replaceChild(el, block); } } |