summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author(no author) <(no author)>2003-11-26 02:12:18 +0000
committer(no author) <(no author)@f4007aff-3deb-0310-84d5-95a897f41757>2003-11-26 02:12:18 +0000
commit507524b97ef3bedb42f6c15ec93eedff8ee4b150 (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /src
parent38a93ec51b23826a8f0f2b91fbaea5956ea5bda4 (diff)
New repository initialized by cvs2svn.
Diffstat (limited to 'src')
-rw-r--r--src/.cvsignore4
-rw-r--r--src/Makefile.am14
-rw-r--r--src/domhelpers.cpp370
-rw-r--r--src/domhelpers.h165
-rw-r--r--src/levelhandler.cpp134
-rw-r--r--src/levelhandler.h88
-rw-r--r--src/reference.h157
-rw-r--r--src/rtfformatting.h190
-rw-r--r--src/rtfparser.cpp442
-rw-r--r--src/rtfparser.h143
-rw-r--r--src/rtfx.173
-rw-r--r--src/rtfx.cpp140
-rw-r--r--src/sablo.h2173
-rw-r--r--src/sablotr.cpp137
-rw-r--r--src/tags.h120
-rw-r--r--src/usuals.h69
-rw-r--r--src/xmlcomposehelpers.cpp159
-rw-r--r--src/xmlcomposehelpers.h167
-rw-r--r--src/xmlcomposer.cpp1245
-rw-r--r--src/xmlcomposer.h311
-rw-r--r--src/xmlfixups.cpp794
-rw-r--r--src/xmlfixups.h155
22 files changed, 0 insertions, 7250 deletions
diff --git a/src/.cvsignore b/src/.cvsignore
deleted file mode 100644
index 52605a3..0000000
--- a/src/.cvsignore
+++ /dev/null
@@ -1,4 +0,0 @@
-.deps
-Makefile
-Makefile.in
-rtfx
diff --git a/src/Makefile.am b/src/Makefile.am
deleted file mode 100644
index 317aa41..0000000
--- a/src/Makefile.am
+++ /dev/null
@@ -1,14 +0,0 @@
-
-bin_PROGRAMS = rtfx
-
-rtfx_SOURCES = rtfx.cpp levelhandler.cpp levelhandler.h \
- reference.h xmlcomposer.cpp xmlcomposer.h xmlcomposehelpers.cpp rtfformatting.h \
- xmlcomposehelpers.h rtfparser.cpp rtfparser.h sablo.h sablotr.cpp usuals.h \
- xmlfixups.h xmlfixups.cpp domhelpers.h domhelpers.cpp tags.h
-rtfx_LDADD = -lsablot -lexpat $(LIB_ICONV)
-rtfx_CFLAGS = -O0 -I${top_srcdir} -I/usr/local/include
-rtfx_LDFLAGS = -L/usr/local/lib
-man_MANS = rtfx.1
-
-EXTRA_DIST = $(man_MANS)
-
diff --git a/src/domhelpers.cpp b/src/domhelpers.cpp
deleted file mode 100644
index 9a9cfd2..0000000
--- a/src/domhelpers.cpp
+++ /dev/null
@@ -1,370 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-#include "usuals.h"
-#include "domhelpers.h"
-#include "tags.h"
-
-using std::make_pair;
-
-bool DOMHelpers::isElement(const DOM::Node& node, const string& name)
-{
- return node != NULL && node.getNodeType() == DOM::Node::ELEMENT_NODE &&
- node.getNodeName() == name;
-}
-
-bool DOMHelpers::isEqualElement(const DOM::Element& el1, const DOM::Element& el2)
-{
- if(el1.getNodeName() != el2.getNodeName())
- return false;
-
- // Compare attributes
- DOM::NamedNodeMap at1 = el1.getAttributes();
- DOM::NamedNodeMap at2 = el2.getAttributes();
-
- if(at1 == NULL && at2 == NULL)
- return true;
-
- if(at1 == NULL || at2 == NULL ||
- at1->getLength() != at2->getLength())
- return false;
-
- for(int i = 0; i < at1->getLength(); i++)
- {
- DOM::Attr attr1 = (const DOM::Attr&)at1->item(0);
- if(attr1 == NULL)
- return false;
-
- DOM::Attr attr2 = (const DOM::Attr&)at2->getNamedItem(attr1.getNodeName());
- if(attr2 == NULL)
- return false;
-
- if(attr1.getNodeValue() != attr2.getNodeValue())
- return false;
- }
-
- return true;
-}
-
-DOM::Element DOMHelpers::getContainingElement(const DOM::Node& node, const string& name)
-{
- DOM::Node n = node;
-
- while(true)
- {
- n = n.getParentNode();
- if(n == NULL)
- break;
-
- // Match parent to given name
- if(isElement(n, name))
- return (DOM::Element&)n;
- }
-
- return DOM::Element();
-}
-
-bool isNsAttr(const string& name)
-{
- // Check if this attribute is a xmlns: attribute
- return strncmp(name.c_str(), kNSPrefix, strlen(kNSPrefix)) ? false : true;
-}
-
-void DOMHelpers::copyAttributes(const DOM::Element& src, DOM::Element& dest,
- const char** hideList)
-{
- // Get both sets of attributes
- DOM::NamedNodeMap srcMap = src.getAttributes();
- DOM::NamedNodeMap destMap = dest.getAttributes();
-
- if(srcMap == NULL || destMap == NULL)
- return;
-
- // And copy them from one to the other
- for(int j = 0; j < srcMap->getLength(); j++)
- {
- DOM::Node attr = srcMap->item(j);
- if(attr != NULL)
- {
- string name = attr.getNodeName();
-
- if(hideList)
- {
- for(const char** t = hideList; *t != NULL; t++)
- {
- if(name == *t)
- name.erase();
- }
- }
-
- // BUG: Sablotron seems to have a bug in it's
- // setAttributeNode implementation. It always
- // adds a blank namespace
- //
- // attr = attr.cloneNode(false);
- // if(attr != NULL)
- // destMap.setNamedItem(attr);
-
- // We never copy xmlns: attributes
- if(name.length() > 0 && !isNsAttr(name))
- dest.setAttribute(attr.getNodeName(), attr.getNodeValue());
- }
- }
-}
-
-DOM::Element DOMHelpers::getPriorElement(const DOM::Node& node, const string& name)
-{
- DOM::Node n = node;
-
- while(n != NULL)
- {
- // Note that we return ourselves if it matches
- if(isElement(n, name))
- return (DOM::Element&)n;
-
- n = n.getPreviousSibling();
- }
-
- DOM::Node parent = node.getParentNode();
-
- if(parent == NULL)
- return DOM::Element();
- else
- return getPriorElement(parent, name);
-}
-
-void DOMHelpers::insertAfter(DOM::Node& parent, const DOM::Node& node,
- const DOM::Node& ref)
-{
- DOM::Node sibling = ref.getNextSibling();
-
- if(sibling == NULL)
- parent.appendChild(node);
- else
- parent.insertBefore(node, sibling);
-}
-
-DOM::Element DOMHelpers::findChildElement(const DOM::Node& parent, const string& name)
-{
- DOM::Node child = parent.getFirstChild();
- while(child != NULL)
- {
- if(isElement(child, name))
- return (DOM::Element&)child;
- }
-
- return DOM::Element();
-}
-
-bool DOMHelpers::hasAncestor(const DOM::Node& ancestor, const DOM::Node& node)
-{
- DOM::Node n = node;
-
- while(n != NULL)
- {
- if(n == ancestor)
- return true;
-
- n = n.getParentNode();
- }
-
- return false;
-}
-
-
-/* ----------------------------------------------------------------------------------
- * ElementTable
- */
-
-void ElementTable::load(const DOM::Node& parent, const string& name)
-{
- clear();
-
- DOM::Node child = parent.getFirstChild();
- while(child != NULL)
- {
- if(DOMHelpers::isElement(child, name))
- {
- DOM::Element& el = (DOM::Element&)child;
- wstring id = el.getAttribute(kAtId);
-
- if(!id.empty())
- insert(make_pair(id, el));
- }
-
- child = child.getNextSibling();
- }
-}
-
-DOM::Element ElementTable::get(const wstring& id) const
-{
- const_iterator it = find(id);
- return it == end() ? DOM::Element() : it->second;
-}
-
-void ElementTable::removeIds()
-{
- iterator it = begin();
- iterator e = end();
-
- for( ; it != e; it++)
- it->second.removeAttribute(kAtId);
-}
-
-/* ----------------------------------------------------------------------------------
- * ElementIterator
- */
-
-void ElementIterator::next()
-{
- if(m_flags == AFTER_LAST)
- return;
-
- if(m_flags == BEFORE_FIRST)
- m_current = m_top;
-
- ASSERT(m_current != NULL);
-
- DOM::Node n;
-
- // Always descend into children first
- if(m_current.hasChildNodes())
- {
- n = nextel(m_current.getFirstChild());
- if(n != NULL)
- {
- m_current = n;
- m_flags = ITERATING;
- return;
- }
- }
-
- // Look for siblings along the current level
- n = nextel(m_current.getNextSibling());
- if(n != NULL)
- {
- m_current = n;
- m_flags = ITERATING;
- return;
- }
-
- for(;;)
- {
- // Go back up to parent, and get it's next sibling
- m_current = m_current.getParentNode();
- if(m_current == NULL || m_current == m_top)
- break;
-
- n = nextel(m_current.getNextSibling());
- if(n != NULL)
- {
- m_current = n;
- m_flags = ITERATING;
- return;
- }
- }
-
- m_flags = AFTER_LAST;
- m_current = NULL;
-}
-
-DOM::Element ElementIterator::nextel(DOM::Node node)
-{
- while(node != NULL)
- {
- if(node.getNodeType() == DOM::Element::ELEMENT_NODE)
- return (DOM::Element&)node;
-
- node = node.getNextSibling();
- }
-
- return DOM::Element();
-}
-
-void ElementIterator::prev()
-{
- if(m_flags == BEFORE_FIRST)
- return;
-
- DOM::Node n;
-
- if(m_flags == AFTER_LAST)
- n = m_top;
- else
- n = prevel(m_current.getPreviousSibling());
-
- while(n != NULL)
- {
- m_current = n;
-
- n = n.hasChildNodes() ?
- prevel(m_current.getLastChild()) : DOM::Node();
-
- if(n == NULL)
- {
- m_flags = ITERATING;
- return;
- }
- }
-
- // Go back up to parent
- m_current = m_current.getParentNode();
-
- if(m_current == NULL || m_current == m_top)
- {
- m_flags = BEFORE_FIRST;
- m_current = NULL;
- return;
- }
-
-
-}
-
-
-DOM::Element ElementIterator::prevel(DOM::Node node)
-{
- while(node != NULL)
- {
- if(node.getNodeType() == DOM::Element::ELEMENT_NODE)
- return (DOM::Element&)node;
-
- node = node.getPreviousSibling();
- }
-
- return DOM::Element();
-}
diff --git a/src/domhelpers.h b/src/domhelpers.h
deleted file mode 100644
index 8b14e2b..0000000
--- a/src/domhelpers.h
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-#ifndef __DOMHELPERS_H__
-#define __DOMHELPERS_H__
-
-#include "sablo.h"
-#include <map>
-#include <stack>
-#include <set>
-
-/*
- * DOMHelpers
- *
- * A collection of functions for doing some things with an XML DOM.
- * Used mainly by XMLComposer.
- */
-class DOMHelpers
-{
-public:
-
- // Check if given node is an element with a certain name
- static bool isElement(const DOM::Node& node, const string& name);
-
- // Check if two elements have the same name and attributes
- static bool isEqualElement(const DOM::Element& el1, const DOM::Element& el2);
-
- // Copy attributes from one element to another optionaly ignoring some
- static void copyAttributes(const DOM::Element& src, DOM::Element& dest, const char** hideList);
-
- // Insert a child node after a given reference node
- static void insertAfter(DOM::Node& parent, const DOM::Node& node, const DOM::Node& ref);
-
- // Get containing element of a given name
- static DOM::Element getContainingElement(const DOM::Node& node, const string& name);
-
- // Get previous element (in XML flow) of a given name
- static DOM::Element getPriorElement(const DOM::Node& node, const string& name);
-
- // Get first child element of a given name
- static DOM::Element findChildElement(const DOM::Node& parent, const string& name);
-
- // Check if a given element is anothers ancestor
- static bool hasAncestor(const DOM::Node& ancestor, const DOM::Node& node);
-};
-
-/*
- * ElementTable
- *
- * A table of elements matched to their ids for quick access while applying
- * things like fonts, styles, lists from their definitions.
- */
-class ElementTable :
- public std::map<wstring, DOM::Element>
-{
-public:
- void load(const DOM::Node& parent, const string& name);
-
- DOM::Element get(const wstring& id) const;
-
- bool has(const wstring& id) const
- { return find(id) != end(); }
-
- void removeIds();
-};
-
-// Some other handy types
-typedef std::set<string> StringSet;
-typedef std::stack<DOM::Node> NodeStack;
-
-/*
- * ElementIterator
- *
- * For iterating through the elements in a document.
- */
-class ElementIterator
- : public std::iterator<std::input_iterator_tag, DOM::Element, ptrdiff_t>
-{
-public:
- ElementIterator()
- { m_flags = AFTER_LAST; }
- ElementIterator(const DOM::Element& top)
- { m_top = top; m_flags = BEFORE_FIRST; next(); }
- ElementIterator(const ElementIterator& x)
- { m_top = x.m_top; m_current = x.m_current; m_flags = x.m_flags; }
-
- const DOM::Element& operator*() const
- { return m_current; }
- const DOM::Element* operator->() const
- { return (&**this); }
- const ElementIterator& operator++()
- { next(); return (*this); }
- const ElementIterator& operator--()
- { prev(); return (*this); }
-
- // Friend comparision functions
- friend bool operator==(const ElementIterator& x, const ElementIterator& y);
- friend bool operator!=(const ElementIterator& x, const ElementIterator& y);
-
-// Implementation
-protected:
-
- void next();
- DOM::Element nextel(DOM::Node node);
-
- void prev();
- DOM::Element prevel(DOM::Node node);
-
-// Data
-protected:
-
- enum
- {
- ITERATING,
- BEFORE_FIRST,
- AFTER_LAST
- };
-
- DOM::Element m_top;
- DOM::Element m_current;
- int m_flags;
-};
-
-// friend functions
-inline bool operator==(const ElementIterator& x, const ElementIterator& y)
- { return y.m_current == x.m_current && y.m_flags == x.m_flags; }
-inline bool operator!=(const ElementIterator& x, const ElementIterator& y)
- { return (!(x == y)); }
-
-#endif // __DOMHELPERS_H__
diff --git a/src/levelhandler.cpp b/src/levelhandler.cpp
deleted file mode 100644
index 20751b2..0000000
--- a/src/levelhandler.cpp
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-#include "usuals.h"
-#include "levelhandler.h"
-
-/* ----------------------------------------------------------------------------------
- * CONSTRUCTION
- */
-LevelHandler::LevelHandler()
-{
- m_parser = NULL;
-}
-
-LevelHandler::~LevelHandler()
-{
- clear();
-}
-
-void LevelHandler::clear()
-{
- m_curLevel.release();
- m_topLevel.release();
-
- m_parser = NULL;
-}
-
-/* ----------------------------------------------------------------------------------
- * OVERRIDES
- */
-
-void LevelHandler::startDocument(RtfParser* parser)
-{
- clear();
-
- m_parser = parser;
-
- m_topLevel = new Level;
- m_curLevel = m_topLevel;
-}
-
-void LevelHandler::endDocument()
-{
-
-}
-
-void LevelHandler::groupStart()
-{
- ASSERT(m_curLevel);
- pushLevel();
-}
-
-void LevelHandler::groupEnd()
-{
- ASSERT(m_curLevel);
- popLevel();
-}
-
-/* ----------------------------------------------------------------------------------
- * OPERATIONS
- */
-
-DOM::Element LevelHandler::getElement()
-{
- ASSERT(m_curLevel);
- return m_curLevel->getElement();
-}
-
-void LevelHandler::pushLevel()
-{
- // Push a level on the stack
- m_curLevel = m_curLevel->pushLevel();
-}
-
-void LevelHandler::popLevel()
-{
- // Pull a level off the stack
- LevelPtr level = m_curLevel->getPrevious();
-
- if(level)
- m_curLevel = level;
-}
-
-void LevelHandler::rewindLevel(LevelPtr ptr)
-{
- ASSERT(ptr != NULL);
-
- LevelPtr prev = ptr->getPrevious();
-
- if(prev != NULL)
- m_curLevel = prev;
- else
- m_curLevel = ptr;
-}
-
-LevelPtr LevelHandler::getLevel()
-{
- return m_curLevel;
-}
diff --git a/src/levelhandler.h b/src/levelhandler.h
deleted file mode 100644
index 8a183f2..0000000
--- a/src/levelhandler.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-#ifndef __LEVELHANDLER_H__
-#define __LEVELHANDLER_H__
-
-#include "rtfparser.h"
-#include "reference.h"
-#include "xmlcomposehelpers.h"
-
-/*
- * LevelHandler
- *
- * A base class that manages a set of Levels (see xmlcomposehelpers.cpp)
- * based on the RTF groups seen.
- */
-class LevelHandler
- : public RtfHandler
-{
-public:
- LevelHandler();
- virtual ~LevelHandler();
-
- // Overrides
- virtual void startDocument(RtfParser* parser);
- virtual void endDocument();
- virtual void groupStart();
- virtual void groupEnd();
-
- // Convenience function to get XML element from current level
- virtual DOM::Element getElement();
-
- // Create a new level on top of stack
- void pushLevel();
-
- // Pop top level and discard
- void popLevel();
-
- // Back out all the way past a given level
- void rewindLevel(LevelPtr ptr);
-
- // Get the current level
- LevelPtr getLevel();
-
-protected:
- virtual void clear();
-
- LevelPtr m_topLevel; // First level
- LevelPtr m_curLevel; // The current level
- RtfParser* m_parser; // The parser we're listening to
-};
-
-#endif // __LEVELHANDLER_H__
diff --git a/src/reference.h b/src/reference.h
deleted file mode 100644
index 1a78d4c..0000000
--- a/src/reference.h
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-#ifndef __REFERENCE_H__
-#define __REFERENCE_H__
-
-/*
- * Reference
- *
- * A basic reference counting pointer
- */
-template<typename C>
-class Reference
-{
-public:
- Reference()
- { m_ptr = NULL; }
-
- Reference(C* ptr)
- {
- m_ptr = ptr;
- addref();
- }
-
- Reference(C* ptr, bool addref)
- {
- m_ptr = ptr;
- if(addref)
- addref();
- }
-
- ~Reference()
- { release(); }
-
- Reference(const Reference& orig)
- {
- m_ptr = orig.m_ptr;
- addref();
- }
-
- Reference& operator=(const C* ptr)
- {
- C* old = m_ptr;
- m_ptr = (C*)ptr;
- addref();
- if(old)
- old->release();
- return *this;
- }
-
- Reference& operator=(const Reference& orig)
- { return operator=(orig.m_ptr); }
-
- void attach(C* ptr)
- {
- release();
- m_ptr = ptr;
- }
-
- C* detach()
- {
- C* ptr = m_ptr;
- m_ptr = NULL;
- return ptr;
- }
-
- operator C*() const
- { return m_ptr; }
-
- C* operator->() const
- { return m_ptr; }
-
-#if 0
- operator bool() const
- {
- return m_ptr != NULL;
- }
-#endif
-
- void release()
- {
- if(m_ptr)
- m_ptr->release();
- m_ptr = NULL;
- }
-
- void addref()
- {
- if(m_ptr)
- m_ptr->addRef();
- }
-
-private:
- C* m_ptr;
-};
-
-/*
- * Instance
- *
- * A basic reference counted object.
- */
-class Instance
-{
-public:
- Instance()
- { m_x = 0; }
- virtual ~Instance()
- { }
- void addRef()
- { m_x++; }
- void release()
- {
- if((--m_x) <= 0)
- delete this;
- }
-
-private:
- // The reference count
- int m_x;
-};
-
-#endif //__REFERENCE_H__
diff --git a/src/rtfformatting.h b/src/rtfformatting.h
deleted file mode 100644
index aa5ac58..0000000
--- a/src/rtfformatting.h
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-#ifndef __RTFFORMATTING_H__
-#define __RTFFORMATTING_H__
-
-/*
- * RtfFormatting
- *
- * For keeping track of all the various transient formatting options
- * within a given Rtf group. Any supported text options (not block)
- * should be added here.
- */
-class RtfFormatting
-{
-public:
- RtfFormatting()
- {
- resetText();
- resetPara();
- }
-
- RtfFormatting(const RtfFormatting& format)
- {
- copy(format);
- }
-
- bool textEquals(const RtfFormatting& format) const
- {
- return m_bold == format.m_bold &&
- m_italic == format.m_italic &&
- m_strike == format.m_italic &&
- m_hidden == format.m_hidden &&
- m_underline == format.m_underline &&
- m_color == format.m_color &&
- m_suscript == format.m_suscript &&
- m_font == format.m_font &&
- m_fsize == format.m_fsize;
- }
-
- bool paraEquals(RtfFormatting& format) const
- {
- return m_style == format.m_style &&
- m_list == format.m_list &&
- m_inTbl == format.m_inTbl;
- }
-
- void copy(const RtfFormatting& format)
- {
- m_bold = format.m_bold;
- m_italic = format.m_italic;
- m_strike = format.m_italic;
- m_hidden = format.m_hidden;
- m_underline = format.m_underline;
- m_color = format.m_color;
- m_suscript = format.m_suscript;
- m_font = format.m_font;
- m_fsize = format.m_fsize;
-
- m_style = format.m_style;
- m_list = format.m_list;
- m_inTbl = format.m_inTbl;
- }
-
- void resetText()
- {
- m_bold = m_italic = m_strike =
- m_underline = m_hidden = false;
- m_color = -1;
- m_suscript = 0;
- m_fsize = -1;
- m_font = -1;
- }
-
- void resetPara()
- {
- m_style = m_list = -1;
- m_inTbl = false;
- }
-
- bool textIsBold() const
- { return m_bold; }
- bool textIsItalic() const
- { return m_italic; }
- bool textIsStrike() const
- { return m_strike; }
- bool textIsUnderline() const
- { return m_underline; }
- bool textIsHidden() const
- { return m_hidden; }
- int textColor() const
- { return m_color; }
- int textSuScript() const
- { return m_suscript; }
- int textFont() const
- { return m_font; }
- int textFontSize() const
- { return m_fsize; }
- int paraStyle() const
- { return m_style; }
- int paraList() const
- { return m_list; }
- bool paraInTable() const
- { return m_inTbl; }
-
- void textSetBold(bool bold)
- { m_bold = bold; }
- void textSetItalic(bool italic)
- { m_italic = italic; }
- void textSetStrike(bool strike)
- { m_strike = strike; }
- void textSetUnderline(bool underline)
- { m_underline = underline; }
- void textSetHidden(bool hidden)
- { m_hidden = hidden; }
- void textSetColor(int color)
- { m_color = color; }
- void textSetSuScript(int suscript)
- { m_suscript = suscript; }
- void textSetFont(int font)
- { m_font = font; }
- void textSetFontSize(int fsize)
- { m_fsize = fsize == 24 ? -1 : fsize; } // default font size is always 24
- void paraSetStyle(int style)
- { m_style = style; }
- void paraSetList(int list)
- { m_list = list; }
- void paraSetTable(bool inTable)
- { m_inTbl = inTable; }
-
- enum
- {
- SUPERSCRIPT = 1,
- SUBSCRIPT
- };
-
-protected:
- bool m_bold;
- bool m_italic;
- bool m_strike;
- bool m_underline;
- bool m_hidden;
- int m_suscript;
- int m_color;
- int m_font;
- int m_fsize;
-
- int m_style;
- int m_list;
- bool m_inTbl;
-
- // TODO: Character styles
-};
-
-#endif // __RTFFORMATTING_H__
diff --git a/src/rtfparser.cpp b/src/rtfparser.cpp
deleted file mode 100644
index c136e95..0000000
--- a/src/rtfparser.cpp
+++ /dev/null
@@ -1,442 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-#include "usuals.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include "rtfparser.h"
-
-
-/* ----------------------------------------------------------------------------------
- * CONSTRUCTION
- */
-
-RtfParser::RtfParser()
-{
- m_handler = NULL;
- m_depth = 0;
- m_parseHex = true;
- m_parseUnicode = false;
- m_uniEat = 0;
- m_uniEatStack.push(0);
-}
-
-RtfParser::~RtfParser()
-{
-
-}
-
-
-/* ----------------------------------------------------------------------------------
- * PUBLIC METHODS
- */
-
-bool RtfParser::parse(string fileName)
-{
- FILE* file = fopen(fileName.c_str(), "r");
- if(!file)
- return false;
-
- bool ret = parse(file);
-
- fclose(file);
-
- return ret;
-}
-
-bool RtfParser::parse(FILE* file)
-{
- int ch = 0;
- bool isData = false;
-
- m_depth = 0;
- m_parseErrors = "";
- m_file = file;
-
- if(m_handler)
- m_handler->startDocument(this);
-
- while(1)
- {
- ch = fgetc(file);
- if(ch == EOF)
- goto done;
-
- switch(ch)
- {
-
- // Starting a control word
- case '\\':
- if(!parseControlWord())
- goto done;
- break;
-
- // Starting an RTF group
- case '{':
- {
- // Send all previous data
- flushData();
-
- // Handle any unicode destinations properly
- m_uniEatStack.push(m_uniEatStack.top());
-
- if(m_handler)
- m_handler->groupStart();
-
- m_depth++;
- }
- break;
-
- case '}':
- {
- // Send all previous data
- flushData();
-
- if(m_handler)
- m_handler->groupEnd();
-
- // Handle any unicode destinations properly
- if(!m_uniEatStack.empty())
- m_uniEatStack.pop();
-
- m_depth--;
- }
- break;
-
- default:
- isData = true;
- break;
- }
-
- if(isData)
- {
- // We translate tabs into the appropriate control word
- if(ch == '\t')
- sendControlWord("tab", 0, -1);
-
- // line endings aren't used
- else if(!strchr("\r\n", ch))
- sendData(ch);
-
- isData = false;
- }
- }
-
-
-done:
-
- if(m_depth != 0)
- m_parseErrors.append("unmatched braces\n");
-
- if(m_handler)
- m_handler->endDocument();
-
- m_file = NULL;
- m_dataBuffer.resize(0);
-
- // If any parse errors return failure
- return m_parseErrors.empty();
-}
-
-
-/* ----------------------------------------------------------------------------------
- * HANDLER CALLS
- */
-
-void RtfParser::flushData()
-{
- if(!m_dataBuffer.empty())
- {
- if(m_handler)
- m_handler->charData(m_dataBuffer);
-
- m_dataBuffer.resize(0);
- }
-}
-
-void RtfParser::sendData(wchar_t ch)
-{
- // Skip unicode chars we've been asked to
- if(m_uniEat > 0)
- m_uniEat--;
-
- else
- m_dataBuffer.append(1, ch);
-}
-
-void RtfParser::sendData(wstring data)
-{
- // Skip any unicode chars we've been asked to
- if(m_uniEat > 0)
- {
- int len = data.size();
- if(len > m_uniEat)
- len = m_uniEat;
-
- m_dataBuffer.append(data.substr(len));
- m_uniEat -= len;
- }
- else
- {
- m_dataBuffer.append(data);
- }
-}
-
-void RtfParser::sendControlWord(string cw, int flags, int param)
-{
- flushData();
-
- if(m_handler)
- m_handler->controlWord(cw, flags, param);
-}
-
-
-/* ----------------------------------------------------------------------------------
- * PARSE HELPERS
- */
-
-bool RtfParser::parseHexChar(int num)
-{
- string data;
-
- // Get num chars and put them in the string
- for(int i = 0; i < num; i++)
- {
- char ch = fgetc(m_file);
-
- if(ch == -1)
- return false;
-
- if((ch >= 'A' && ch <= 'F') ||
- (ch >= 'a' && ch <= 'f') ||
- (ch >= '0' && ch <= '9'))
- {
- data.append(1, ch);
- }
- else
- {
- m_parseErrors.append((string)"invalid hex char: " + ch + "\n");
- }
- }
-
- // If parsing hex, then convert to appropriate unicode
- if(m_parseHex)
- {
- char* end = NULL;
- int val = strtol(data.c_str(), &end, 16);
- if(end == data.c_str() + data.size() && m_parseHex)
- sendData(val);
- else
- m_parseErrors.append("invalid hex char: " + data + "\n");
- }
-
- // TODO: Why would we ever want to do this?
- // Otherwise just send as a hex control word
- else
- {
- sendControlWord(data, RtfHandler::kIsEncoded, -1);
- }
-
- return true;
-}
-
-bool RtfParser::parseControlWord()
-{
- bool isAsterisk = false;
- string controlword;
- string param;
-
- while(1)
- {
- int ch = fgetc(m_file);
- if(ch == WEOF)
- return false;
-
- bool empty = controlword.empty();
-
- // Part of the name of a control word
- // NOTE: Although the RTF specification prohibits uppercase
- // control words, MS Word uses them :-/
- if(ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')
- controlword.append(1, (char)ch);
-
- // Part of the parameter of a control word
- else if(ch >= '0' && ch <= '9')
- param.append(1, (char)ch);
-
- // Now handle escapes and other special types of
- // control words. These are all only valid at beginning
- // of the "control word"
-
- // hex spelled out character
- else if(empty && ch == '\'')
- {
- parseHexChar(2);
- break;
- }
-
- // Asterisk type destination
- else if(empty && ch == '*')
- {
- isAsterisk = true;
-
- ch = fgetc(m_file);
- while(strchr("\r\n", ch))
- ch = fgetc(m_file);
-
- if(ch != '\\')
- ungetc(ch, m_file);
- }
-
- // Escaped backslash
- else if(empty && ch == '\\')
- {
- sendData(L'\\');
- break;
- }
-
- // Escaped braces
- else if(empty && ch == '{')
- {
- sendData(L'{');
- }
-
- else if(empty && ch == '}')
- {
- sendData(L'}');
- }
-
- // Non breaking space
- else if(empty && ch == '~')
- {
- sendData(0x00A0);
- break;
- }
-
- // Optional hyphen
- else if(empty && ch == '-')
- {
- sendData(0x00AD);
- break;
- }
-
- // a hyphen right after control word is part of number
- else if(!empty && param.empty() && ch == '-')
- {
- param.append(1, (char)ch);
- }
-
- // Space at end a rtf code (it gets eaten)
- else if(strchr(" ", ch))
- break;
-
- // Anything else (including a backslash ends a control word)
- else
- {
- ungetc(ch, m_file);
- break;
- }
- }
-
- // Empty out the control word buffers
- if(!controlword.empty())
- {
- int flags = isAsterisk ? RtfHandler::kAsterisk : 0;
- int numPar = -1;
-
- if(!param.empty())
- {
- char* end = NULL;
- numPar = strtol(param.c_str(), &end, 10);
- if(end == param.c_str() + param.size())
- flags += RtfHandler::kHasParam;
- }
-
- // Here we check for common characters
- if(controlword == "emdash")
- sendData(0x2014);
- else if(controlword == "endash")
- sendData(0x2013);
- else if(controlword == "emspace")
- sendData(0x2003);
- else if(controlword == "enspace")
- sendData(0x2002);
- else if(controlword == "bullet")
- sendData(0x2022);
- else if(controlword == "lquote")
- sendData(0x2018);
- else if(controlword == "rquote")
- sendData(0x2019);
- else if(controlword == "ldblquote")
- sendData(0x201C);
- else if(controlword == "rdblquote")
- sendData(0x201D);
-
- // Unicode values get sent through
- else if(m_parseUnicode && flags & RtfHandler::kHasParam &&
- controlword == "u" )
- {
- sendData(numPar);
- m_uniEat = m_uniEatStack.top();
- }
-
- // Unicode destination
- else if(m_parseUnicode && controlword == "ud")
- {
-
- }
-
- // Skip value for unicode characters
- else if(m_parseUnicode && controlword == "uc")
- {
- m_uniEatStack.pop();
- m_uniEatStack.push(numPar);
- }
-
- // Otherwise we send the control word
- else
- {
- if(m_handler)
- sendControlWord(controlword, flags, numPar);
- }
- }
-
- return true;
-}
-
diff --git a/src/rtfparser.h b/src/rtfparser.h
deleted file mode 100644
index 9509a35..0000000
--- a/src/rtfparser.h
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-#ifndef __RTFPARSER_H__
-#define __RTFPARSER_H__
-
-#include "usuals.h"
-#include <stack>
-#include <stdio.h>
-
-class RtfHandler;
-
-/*
- * RtfParser
- *
- * A class that parses the RTF into it's tags and groups etc... It feeds its
- * parsed data into into a handler interface (see below) for processing.
- *
- * Performs some basic conversion and sanity checking (unicode chars etc...)
- * as well.
- */
-class RtfParser
-{
-public:
- RtfParser();
- virtual ~RtfParser();
-
- bool parse(string fileName);
- bool parse(FILE* file);
-
- void setHandler(RtfHandler* handler)
- { m_handler = handler; }
- string getParseErrors() const
- { return m_parseErrors; }
- int getDepth() const
- { return m_depth; }
- void setHexParse(bool parse)
- { m_parseHex = parse; }
- void setUnicode(bool unicode);
-
-protected:
- RtfHandler* m_handler; // The current handler
- int m_depth; // To keep track of group depth
- bool m_parseHex; // Whether to parse hex chars or not
- string m_parseErrors; // A list of all the RTF parsing errors
-
- // TODO: Look at exactly what this is doing
- // Unicode char handling
- bool m_parseUnicode;
- typedef std::stack<int> StackInt;
- StackInt m_uniEatStack;
- int m_uniEat;
-
- FILE* m_file; // The file we're currently parsing
- wstring m_dataBuffer; // The block of data we're caching to send
-
-private:
-
- // Parse helpers
- bool parseControlWord();
- bool parseHexChar(int num);
-
- // Convenience functions for calling the handler
- void sendControlWord(string cw, int flags, int param);
- void sendData(wchar_t ch);
- void sendData(wstring data);
- void flushData();
-};
-
-/*
- * RtfHandler
- *
- * An interface called by RtfParser with tags and groups etc... parsed from
- * an RTF file.
- */
-class RtfHandler
-{
-public:
-
- // Called at the beginning of the document
- virtual void startDocument(RtfParser* reader) = 0;
-
- // Called at the end of the document
- virtual void endDocument() = 0;
-
- // Called when an RTF control word is hit. Flags below.
- // If control word has no param then param is -1
- virtual void controlWord(const string& cw, int flags, int param) = 0;
-
- // Called when an RTF group opened
- virtual void groupStart() = 0;
-
- // Called when an RTF group is closed
- virtual void groupEnd() = 0;
-
- // A block of character data encountered
- virtual void charData(wstring data) = 0;
-
- // Flags for controlWord
- enum
- {
- kAsterisk = 0x00000001,
- kHasParam = 0x00000002,
- kIsEncoded = 0x00000004
- };
-};
-
-#endif // __RTFPARSER_H__
diff --git a/src/rtfx.1 b/src/rtfx.1
deleted file mode 100644
index 6119ef8..0000000
--- a/src/rtfx.1
+++ /dev/null
@@ -1,73 +0,0 @@
-.\"
-.\" Copyright (c) 2004, Nate Nielsen
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\"
-.\" * Redistributions of source code must retain the above
-.\" copyright notice, this list of conditions and the
-.\" following disclaimer.
-.\" * Redistributions in binary form must reproduce the
-.\" above copyright notice, this list of conditions and
-.\" the following disclaimer in the documentation and/or
-.\" other materials provided with the distribution.
-.\" * The names of contributors to this software may not be
-.\" used to endorse or promote products derived from this
-.\" software without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-.\" COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
-.\" OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
-.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
-.\" THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
-.\" DAMAGE.
-.\"
-.\"
-.\" CONTRIBUTORS
-.\" Nate Nielsen <nielsen@memberwebs.com>
-.\"
-.Dd July, 2004
-.Dt rtfx 1
-.Os rtfx
-.Sh NAME
-.Nm rtfx
-.Nd converts RTF to a generic XML format
-.Sh SYNOPSIS
-.Nm
-.Op Fl p
-.Ar inrtf
-.Ar outxml
-.Sh DESCRIPTION
-.Nm
-converts RTF files into a generic XML format. It majors on keeping meta data like style
-names, etc... rather than every bit of formatting. This makes it handy for converting
-RTF documents into a custom XML format (using XSL or an additional processing step).
-.Pp
-The output format is documented on the rtfx website (below). There are two slight
-variations of output format. The normal mode contains structure type data with
-formatting that has relevance on the context (such as bold or underline). The
-presentation format adds some more formatting tags (such as fonts or colors).
-.Sh OPTIONS
-The options are as follows:
-.Bl -tag -width Fl
-.It Fl p
-Puts
-.Nm
-into 'presentation' output mode.
-.El
-.Sh WEBSITE
-http://memberwebs.com/software/rtfx/
-.Sh BUGS
-Doesn't handle crummy RTF files nicely. Needs some speed improvements.
-.Sh SEE ALSO
-.Xr sablot 3
-.Sh AUTHOR
-.An Nate Nielsen Aq nielsen@memberwebs.com
diff --git a/src/rtfx.cpp b/src/rtfx.cpp
deleted file mode 100644
index 541432e..0000000
--- a/src/rtfx.cpp
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-#include "usuals.h"
-#include <stdlib.h>
-#include <stdio.h>
-#include <errno.h>
-
-#include "rtfparser.h"
-#include "xmlcomposer.h"
-
-int usage()
-{
- fprintf(stderr, "usage: rtfx [-p] <inrtf> <outxml>\n");
- exit(2);
-}
-
-int main(int argc, char* argv[])
-{
- XmlComposerOptions options;
-
- while(argc > 1)
- {
- argc--;
- argv++;
-
- char* arg = argv[0];
- if(*arg != '-')
- break;
-
- while(arg && *(++arg))
- {
- switch(*arg)
- {
- case 'p':
- options.extras = true;
- break;
-
- case '-':
- arg = NULL;
- break;
-
- case '?':
- default:
- usage();
- }
- }
-
- if(arg == NULL)
- break;
- }
-
- if(argc < 2)
- usage();
-
- try
- {
- // The input file
- FILE* file = fopen(argv[0], "rb");
-
- if(!file)
- {
- fprintf(stderr, "rtfx: couldn't open rtf file: %s: %s\n", argv[0], strerror(errno));
- return 1;
- }
-
- // Reads RTF tags and blocks
- RtfParser rtf;
-
- // Interprets tags and blocks from RTFParser
- XmlComposer composer(options);
- rtf.setHandler(&composer);
-
- bool ret = rtf.parse(file);
- fclose(file);
-
- if(!ret)
- {
- fprintf(stderr, "rtfx: rtf parse failed: %s\n", rtf.getParseErrors().c_str());
- return 1;
- }
-
- // TODO: This is disgusting. We need to bug the sablotron guys
- // for a better way to serialize a document.
- DOM::Document doc = composer.getDocument();
- string xml = doc.serialize();
-
- FILE* out = fopen(argv[1], "wb");
- if(!out)
- {
- fprintf(stderr, "rtfx: couldn't open file: %s: %s\n", argv[1], strerror(errno));
- return 1;
- }
-
- fwrite(xml.c_str(), 1, xml.length(), out);
- fclose(out);
- return 0;
- }
- catch(DOM::DOMException& e)
- {
- fprintf(stderr, "rtfx: xml dom error: %s\n", e.getMessage());
- }
-
- return 1;
-}
diff --git a/src/sablo.h b/src/sablo.h
deleted file mode 100644
index 196b70b..0000000
--- a/src/sablo.h
+++ /dev/null
@@ -1,2173 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-// SABLOTRON C++ WRAPPER
-//
-// This wrapper tries to emulate the W3C DOM as much as possible.
-// Objects returned can be copied liberally. When copied they still
-// refer to the original Sablotron classes.
-// Almost all classes are "light" wrappers, and shouldn't be more
-// than 4 to 8 bytes a piece, with no additional memory allocation.
-// Certain objects (NodeList, NamedNodeMap implementations) are
-// heavier, and are reference counted.
-//
-// Salbotron uses UTF8 exclusively internally. This wrapper
-// supports on the fly conversions from UTF16. Define the following
-// constants to enable conversions:
-//
-// USE_UTF16
-// Convert all data values from UTF16 to UTF8.
-//
-// DOM_UTF16
-// Convert all DOM names from UTF16 to UTF8.
-//
-// If either of the above two constants are enabled you must include
-// salbotr.cpp in your build.
-//
-// Everything is in the DOM namespace.
-//
-// Objects of type Document and DOMImplementation must be manually
-// freed with their 'release' member function.
-//
-//
-
-#ifndef __SABLO_H__
-#define __SABLO_H__
-
-#define USE_UTF16
-// #define DOM_UTF16
-
-#include <stdio.h>
-#include <wchar.h>
-#include <exception>
-#include <string>
-
-namespace DOM
-{
- namespace S
- {
- extern "C"
- {
- #include <sablot.h>
- #include <sdom.h>
- }
- };
-
- bool transcode16to8(const std::basic_string<wchar_t>& data,
- std::basic_string<char>& ret);
- bool transcode8to16(const std::basic_string<char>& data,
- std::basic_string<wchar_t>& ret);
-
- namespace INT
- {
- typedef std::basic_string<char> _8str;
- typedef std::basic_string<wchar_t> _16str;
- }
-
-#ifdef ASSERT
- #define DOM_ASSERT ASSERT
-#else
- #include <assert.h>
- #define ASSERT assert
-#endif
-
-#ifdef USE_UTF16
- #ifdef DOM_UTF16
- typedef INT::_16str data_str;
- typedef INT::_16str dom_str;
- #define FROM_V(v) _16to8(v)
- #define FROM_D(v) _16to8(v)
- #define TO_V(v) _8to16(v)
- #define TO_D(v) _8to16(v)
- #else
- typedef INT::_16str data_str;
- typedef INT::_8str dom_str;
- #define FROM_V(v) _16to8(v)
- #define FROM_D(v) v
- #define TO_V(v) _8to16(v)
- #define TO_D(v) v
- #endif
-#else
- typedef INT::_8str data_str;
- typedef INT::_8str dom_str;
- #define FROM_V(v) v
- #define FROM_D(v) v
- #define TO_V(v) v
- #define TO_D(v) v
-#endif
-
- namespace INT
- {
- template<typename C>
- class Ref
- {
- public:
- Ref()
- { m_ptr = NULL; }
-
- Ref(C* ptr)
- {
- m_ptr = ptr;
- addref();
- }
-
- Ref(C* ptr, bool addref)
- {
- m_ptr = ptr;
- if(addref)
- addref();
- }
-
- ~Ref()
- {
- release();
- }
-
- Ref(const Ref& orig)
- {
- m_ptr = orig.m_ptr;
- addref();
- }
-
- Ref& operator=(const C* ptr)
- {
- C* old = m_ptr;
- m_ptr = (C*)ptr;
- addref();
- if(old)
- old->release();
- return *this;
- }
-
- Ref& operator=(const Ref& orig)
- { return operator=(orig.m_ptr); }
-
-#ifdef COMPARE_REF
- bool operator==(const C* ptr)
- {
- if(m_ptr == NULL && ptr == NULL)
- return true;
- else if(m_ptr == NULL || ptr == NULL)
- return false;
-
- return *ptr == *m_ptr;
- }
-
- bool operator==(const Ref& orig)
- { return operator==(orig.m_ptr); }
-#else
- bool operator==(const C* ptr)
- {
- ASSERT(ptr == NULL);
- return m_ptr == NULL;
- }
-#endif
- operator C*() const
- { return m_ptr; }
-
- operator C&() const
- { return &m_ptr; }
-
- C* operator->() const
- { return m_ptr; }
-
- protected:
- void release()
- {
- if(m_ptr)
- m_ptr->release();
- m_ptr = NULL;
- }
-
- void addref()
- {
- if(m_ptr)
- m_ptr->addref();
- }
-
- private:
- C* m_ptr;
- };
-
- class Inst
- {
- public:
- Inst()
- { m_x = 0; }
- virtual ~Inst()
- { }
- void addref()
- { m_x++; }
- void release()
- {
- if((--m_x) <= 0)
- delete this;
- }
-
- private:
- int m_x;
- };
-
- class Base;
- };
-
- #define ASSERT_VALID() \
- ASSERT(isValid());
- #define ASSERT_VALID_NODE(node) \
- ASSERT(node.isValid());
- #define ASSERT_TYPE(t) \
- ASSERT(getNodeType() == t)
- #define ASSERT_NODE_TYPE(n, t) \
- ASSERT(n.getNodeType() == t)
-
- class DOMException
- {
- public:
- typedef enum
- {
- INDEX_SIZE_ERR = S::SDOM_INDEX_SIZE_ERR,
- DOMSTRING_SIZE_ERR = S::SDOM_DOMSTRING_SIZE_ERR,
- HIERARCHY_REQUEST_ERR = S::SDOM_HIERARCHY_REQUEST_ERR,
- WRONG_DOCUMENT_ERR = S::SDOM_WRONG_DOCUMENT_ERR,
- INVALID_CHARACTER_ERR = S::SDOM_INVALID_CHARACTER_ERR,
- NO_DATA_ALLOWED_ERR = S::SDOM_NO_DATA_ALLOWED_ERR,
- NO_MODIFICATION_ALLOWED_ERR = S::SDOM_NO_MODIFICATION_ALLOWED_ERR,
- NOT_FOUND_ERR = S::SDOM_NOT_FOUND_ERR,
- NOT_SUPPORTED_ERR = S::SDOM_NOT_SUPPORTED_ERR,
- INUSE_ATTRIBUTE_ERR = S::SDOM_INUSE_ATTRIBUTE_ERR,
- INVALID_STATE_ERR = S::SDOM_INVALID_STATE_ERR,
- SYNTAX_ERR = S::SDOM_SYNTAX_ERR,
- INVALID_MODIFICATION_ERR = S::SDOM_INVALID_MODIFICATION_ERR,
- NAMESPACE_ERR = S::SDOM_NAMESPACE_ERR,
- INVALID_ACCESS_ERR = S::SDOM_INVALID_ACCESS_ERR,
- /* not in spec below this point: */
- INVALID_NODE_TYPE = S::SDOM_INVALID_NODE_TYPE,
- QUERY_PARSE_ERR = S::SDOM_QUERY_PARSE_ERR,
- QUERY_EXECUTION_ERR = S::SDOM_QUERY_EXECUTION_ERR,
- NOT_OK = S::SDOM_NOT_OK
- } CODES;
-
- int getCode()
- { return code; }
- char* getMessage()
- { return S::SDOM_getExceptionMessage(m_sit); }
- void getDetails(int* code, char** message,
- char** documentUri, int* fileLine)
- { S::SDOM_getExceptionDetails(m_sit, code, message, documentUri, fileLine); }
-
- short code;
-
- protected:
- DOMException(S::SDOM_Exception e, S::SablotSituation s)
- {
- code = e;
- m_sit = s;
- }
-
- S::SablotSituation m_sit;
-
- friend class INT::Base;
- };
-
- namespace INT
- {
- /**
- * The base class that keeps references to sablo
- */
- class Base
- {
- public:
- bool operator==(const Base& other) const
- { return m_sit == other.m_sit; }
- bool operator==(const void* null) const
- { ASSERT(null == NULL); return m_sit == NULL; };
- bool operator!=(const Base& other) const
- { return !operator==(other); }
- bool operator!=(const void* null) const
- { return !operator==(null); }
-
- protected:
- Base(S::SablotSituation sit)
- { m_sit = sit; }
- Base(const Base& base)
- { m_sit = base.m_sit; }
- Base& operator=(const Base& other)
- { m_sit = other.m_sit; return *this; }
- Base& operator=(const void* null)
- { ASSERT(null == NULL); m_sit = NULL; return *this; }
- inline bool isValid() const
- { return m_sit != NULL; }
-
- inline S::SDOM_Exception _try_(S::SDOM_Exception e) const
- throw(DOMException)
- {
- if(e != S::SDOM_OK)
- throw DOMException(e, m_sit);
- return e;
- }
-
-#ifdef USE_UTF16
- inline _16str _8to16(const _8str& d) const
- throw(DOMException)
- {
- _16str s;
- if(!transcode8to16(d, s))
- throw DOMException(S::SDOM_INVALID_CHARACTER_ERR, m_sit);
- return s;
- }
-
- inline _8str _16to8(const _16str& d) const
- throw(DOMException)
- {
- _8str s;
- if(!transcode16to8(d, s))
- throw DOMException(S::SDOM_INVALID_CHARACTER_ERR, m_sit);
- return s;
- }
-#endif
-
- S::SablotSituation m_sit;
- };
-
- class NamedNodeMap;
- class NodeList;
- class ChildNodeList;
- class AttrNodeList;
- class DOMNodeList;
- class AttrNamedNodeMap;
- }
-
- class Element;
- class Document;
- class DOMImplementation;
-
- typedef INT::Ref<INT::NamedNodeMap> NamedNodeMap;
- typedef INT::Ref<INT::NodeList> NodeList;
-
- /**
- * Thin wrapper class for a DOM Node
- */
- class Node :
- public INT::Base
- {
- public:
- enum TYPES
- {
- ELEMENT_NODE = S::SDOM_ELEMENT_NODE,
- ATTRIBUTE_NODE = S::SDOM_ATTRIBUTE_NODE,
- TEXT_NODE = S::SDOM_TEXT_NODE,
- CDATA_SECTION_NODE = S::SDOM_CDATA_SECTION_NODE,
- ENTITY_REFERENCE_NODE = S::SDOM_ENTITY_REFERENCE_NODE,
- ENTITY_NODE = S::SDOM_ENTITY_NODE,
- PROCESSING_INSTRUCTION_NODE = S::SDOM_PROCESSING_INSTRUCTION_NODE,
- COMMENT_NODE = S::SDOM_COMMENT_NODE,
- DOCUMENT_NODE = S::SDOM_DOCUMENT_NODE,
- DOCUMENT_TYPE_NODE = S::SDOM_DOCUMENT_TYPE_NODE,
- DOCUMENT_FRAGMENT_NODE = S::SDOM_DOCUMENT_FRAGMENT_NODE,
- NOTATION_NODE = S::SDOM_NOTATION_NODE
- };
-
- Node() : INT::Base(NULL)
- {
- m_node = NULL;
- }
-
- Node(const Node& node)
- : INT::Base(node)
- {
- m_node = node.m_node;
- }
-
- Node& operator=(const Node& other)
- {
- Base::operator=(other);
- m_node = other.m_node;
- return *this;
- }
-
- Node& operator=(const void* null)
- {
- ASSERT(null == NULL);
- Base::operator=(null);
- m_node = NULL;
- return *this;
- }
-
- bool operator==(const Node& other) const
- {
- return Base::operator==(other) &&
- m_node == other.m_node;
- }
-
- bool operator==(const void* null) const
- {
- ASSERT(null == NULL);
- return Base::operator==(null) ||
- m_node == NULL;
- }
-
- bool operator!=(const Node& other) const
- { return !operator==(other); }
-
- bool operator!=(const void* null) const
- { return !operator==(null); }
-
- const Node* operator->() const
- { return (const Node*)this; }
- Node* operator->()
- { return this; }
-
- dom_str getNodeName() const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_char* name;
- _try_(S::SDOM_getNodeName(m_sit, m_node, &name));
- return TO_D(INT::_8str(name));
- }
-
- data_str getNodeValue() const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_char* value;
- _try_(S::SDOM_getNodeValue(m_sit, m_node, &value));
- return TO_V(INT::_8str(value));
- }
-
- void setNodeValue(const data_str& value)
- throw(DOMException)
- {
- ASSERT_VALID();
- _try_(S::SDOM_setNodeValue(m_sit, m_node, FROM_V(value).c_str()));
- }
-
- short getNodeType() const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_NodeType type;
- _try_(S::SDOM_getNodeType(m_sit, m_node, &type));
- return (short)type;
- }
-
- Node getParentNode() const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_Node parent;
- _try_(S::SDOM_getParentNode(m_sit, m_node, &parent));
- return Node(m_sit, parent);
- }
-
- NodeList getChildNodes() const
- throw(DOMException);
-
- Node getFirstChild() const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_Node child;
- _try_(S::SDOM_getFirstChild(m_sit, m_node, &child));
- return Node(m_sit, child);
- }
-
- Node getLastChild() const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_Node child;
- _try_(S::SDOM_getLastChild(m_sit, m_node, &child));
- return Node(m_sit, child);
- }
-
- Node getPreviousSibling() const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_Node sib;
- _try_(S::SDOM_getPreviousSibling(m_sit, m_node, &sib));
- return Node(m_sit, sib);
- }
-
- Node getNextSibling() const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_Node sib;
- _try_(S::SDOM_getNextSibling(m_sit, m_node, &sib));
- return Node(m_sit, sib);
- }
-
- NamedNodeMap getAttributes() const
- throw(DOMException);
-
- Document getOwnerDocument() const
- throw(DOMException);
-
- Node insertBefore(const Node& newChild, const Node& refChild)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_VALID_NODE(newChild);
- ASSERT_VALID_NODE(refChild);
- _try_(S::SDOM_insertBefore(m_sit, m_node, newChild.m_node, refChild.m_node));
- return newChild;
- }
-
- Node replaceChild(const Node& newChild, const Node& refChild)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_VALID_NODE(newChild);
- ASSERT_VALID_NODE(refChild);
- _try_(S::SDOM_replaceChild(m_sit, m_node, newChild.m_node, refChild.m_node));
- return newChild;
- }
-
- Node removeChild(const Node& oldChild)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_VALID_NODE(oldChild);
- _try_(S::SDOM_removeChild(m_sit, m_node, oldChild.m_node));
- return oldChild;
- }
-
- Node appendChild(const Node& newChild)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_VALID_NODE(newChild);
- _try_(S::SDOM_appendChild(m_sit, m_node, newChild.m_node));
- return newChild;
- }
-
- bool hasChildNodes() const
- throw(DOMException)
- {
- ASSERT_VALID();
- int count = 0;
- _try_(S::SDOM_getChildNodeCount(m_sit, m_node, &count));
- return count != 0;
- }
-
- Node cloneNode(bool deep) const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_Node node;
- _try_(S::SDOM_cloneNode(m_sit, m_node, deep ? 1 : 0, &node));
- return Node(m_sit, node);
- }
-
- void normalize()
- throw(DOMException)
- {
- ASSERT_VALID();
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- }
-
- bool isSupported(const dom_str& feature,
- const dom_str& version) const
- {
- ASSERT_VALID();
- return false;
- }
-
- dom_str getNamespaceURI() const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_char* uri;
- _try_(S::SDOM_getNodeNSUri(m_sit, m_node, &uri));
- return TO_D(INT::_8str(uri));
- }
-
- dom_str getPrefix() const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_char* prefix;
- _try_(S::SDOM_getNodePrefix(m_sit, m_node, &prefix));
- return TO_D(INT::_8str(prefix));
- }
-
- void setPrefix(const dom_str& prefix)
- throw(DOMException)
- {
- ASSERT_VALID();
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- }
-
- dom_str getLocalName() const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_char* name;
- _try_(S::SDOM_getNodeLocalName(m_sit, m_node, &name));
- return TO_D(INT::_8str(name));
- }
-
- bool hasAttributes() const
- throw (DOMException)
- {
- ASSERT_VALID();
-
- if(getNodeType() != ELEMENT_NODE)
- return false;
-
- int count = 0;
- _try_(S::SDOM_getAttributeNodeCount(m_sit, m_node, &count));
- return count != 0;
- }
-
- void* setUserData(void* data)
- throw(DOMException)
- {
- ASSERT_VALID();
- void* old = S::SDOM_getNodeInstanceData(m_node);
- S::SDOM_setNodeInstanceData(m_node, data);
- return old;
- }
-
- void* getUserData() const
- throw(DOMException)
- {
- ASSERT_VALID();
- return S::SDOM_getNodeInstanceData(m_node);
- }
-
- std::string serialize() const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_Document doc;
- _try_(S::SDOM_getOwnerDocument(m_sit, m_node, &doc));
- S::SDOM_char* serialized;
- _try_(S::SDOM_nodeToString(m_sit, doc, m_node, &serialized));
- std::string ret(serialized);
- S::SablotFree(serialized);
- return ret;
- }
-
- bool isValid() const
- {
- return Base::isValid() &&
- m_node != NULL;
- }
-
- protected:
- Node(S::SablotSituation sit, S::SDOM_Node node) :
- INT::Base(sit) { m_node = node; }
-
- protected:
- S::SDOM_Node m_node;
-
- friend class Document;
- friend class INT::ChildNodeList;
- friend class INT::AttrNodeList;
- friend class INT::DOMNodeList;
- friend class INT::AttrNamedNodeMap;
- };
-
- class Attr :
- public Node
- {
- public:
- Attr() { }
- Attr(const Attr& node) :
- Node(node) { }
-
- Attr& operator=(const Attr& other)
- { Node::operator=(other); return *this; }
- Attr& operator=(const void* null)
- { Node::operator=(null); return *this; }
- const Attr* operator->() const
- { return (const Attr*)this; }
- Attr* operator->()
- { return this; }
-
- dom_str getName() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ATTRIBUTE_NODE);
- return getNodeName();
- }
-
- Element getOwnerElement() const
- throw(DOMException);
-
- bool getSpecified() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ATTRIBUTE_NODE);
- return true;
- }
-
- data_str getValue() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ATTRIBUTE_NODE);
- return getNodeValue();
- }
-
- void setValue(const data_str& value)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ATTRIBUTE_NODE);
- setNodeValue(value);
- }
-
- protected:
- Attr(S::SablotSituation sit, S::SDOM_Node node) :
- Node(sit, node) { }
-
- friend class Element;
- friend class Document;
- };
-
- /**
- * This wrapper class for an element
- */
- class Element :
- public Node
- {
- public:
- Element() { }
- Element(const Element& node) :
- Node(node) {}
-
- Element& operator=(const Node& other)
- { Node::operator=(other); return *this; }
- Element& operator=(const Element& other)
- { Node::operator=(other); return *this; }
- Element& operator=(const void* null)
- { Node::operator=(null); return *this; }
- const Element* operator->() const
- { return (const Element*)this; }
- Element* operator->()
- { return this; }
-
- dom_str getTagName() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ELEMENT_NODE);
- return getNodeName();
- }
-
- data_str getAttribute(const dom_str& name) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ELEMENT_NODE);
- S::SDOM_char* value;
- _try_(S::SDOM_getAttribute(m_sit, m_node, FROM_D(name).c_str(), &value));
- return TO_V(INT::_8str(value));
- }
-
- void setAttribute(const dom_str& name, const data_str& value)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ELEMENT_NODE);
- _try_(S::SDOM_setAttribute(m_sit, m_node, FROM_D(name).c_str(),
- FROM_V(value).c_str()));
- }
-
- void removeAttribute(const dom_str& name)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ELEMENT_NODE);
- _try_(S::SDOM_removeAttribute(m_sit, m_node, FROM_D(name).c_str()));
- }
-
- Attr getAttributeNode(const dom_str& name) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ELEMENT_NODE);
- S::SDOM_Node attr;
- _try_(S::SDOM_getAttributeNode(m_sit, m_node, FROM_D(name).c_str(), &attr));
- return Attr(m_sit, attr);
- }
-
- Attr setAttributeNode(const Attr& attr)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_VALID_NODE(attr);
- ASSERT_TYPE(ELEMENT_NODE);
- S::SDOM_Node repl;
- _try_(S::SDOM_setAttributeNode(m_sit, m_node, attr.m_node, &repl));
- return Attr(m_sit, repl);
- }
-
- Attr removeAttributeNode(const Attr& attr)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_VALID_NODE(attr);
- ASSERT_TYPE(ELEMENT_NODE);
- S::SDOM_Node rem;
- _try_(S::SDOM_removeAttributeNode(m_sit, m_node, attr.m_node, &rem));
- return Attr(m_sit, rem);
- }
-
- NodeList getElementsByTagName(const dom_str& name) const
- throw(DOMException);
-
- data_str getAttributeNS(const dom_str& uri, const dom_str& name) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ELEMENT_NODE);
- S::SDOM_char* value;
- _try_(S::SDOM_getAttributeNS(m_sit, m_node, (char*)FROM_D(uri).c_str(),
- (char*)FROM_D(name).c_str(), &value));
- return TO_V(INT::_8str(value));
- }
-
- void setAttributeNS(const dom_str& uri, const dom_str& name,
- const data_str& value)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ELEMENT_NODE);
- _try_(S::SDOM_setAttributeNS(m_sit, m_node, FROM_D(uri).c_str(),
- FROM_D(name).c_str(), FROM_V(value).c_str()));
- }
-
- void removeAttributeNS(const dom_str& uri, const dom_str& name)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ELEMENT_NODE);
- DOM::Attr attr = getAttributeNodeNS(uri, name);
- if(attr != NULL)
- removeAttributeNode(attr);
- }
-
- Attr getAttributeNodeNS(const dom_str& uri, const dom_str& name) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ELEMENT_NODE);
- S::SDOM_Node attr;
- _try_(S::SDOM_getAttributeNodeNS(m_sit, m_node, (char*)FROM_D(uri).c_str(),
- (char*)FROM_D(name).c_str(), &attr));
- return Attr(m_sit, attr);
- }
-
- Attr setAttributeNodeNS(const Attr& attr)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_VALID_NODE(attr);
- ASSERT_TYPE(ELEMENT_NODE);
- S::SDOM_Node repl;
- _try_(S::SDOM_setAttributeNodeNS(m_sit, m_node, attr.m_node, &repl));
- return Attr(m_sit, repl);
- }
-
- NodeList getElementsByTagNameNS(const dom_str& uri,
- const dom_str& name) const
- throw(DOMException);
-
- bool hasAttribute(const dom_str& name) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ELEMENT_NODE);
- return getAttributeNode(name) != NULL;
- }
-
- bool hasAttributeNS(const dom_str& uri, const dom_str& name) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ELEMENT_NODE);
- return getAttributeNodeNS(uri, name) != NULL;
- }
-
- protected:
- Element(S::SablotSituation sit, S::SDOM_Node node) :
- Node(sit, node) { }
-
- friend class Attr;
- friend class Document;
- };
-
-
- class CharacterData :
- public Node
- {
- public:
- CharacterData() { }
- CharacterData(const Node& node) :
- Node(node) { }
-
- CharacterData& operator=(const Node& other)
- { Node::operator=(other); return *this; }
- CharacterData& operator=(const CharacterData& other)
- { Node::operator=(other); return *this; }
- CharacterData& operator=(const void* null)
- { Node::operator=(null); return *this; }
- const CharacterData* operator->() const
- { return (const CharacterData*)this; }
- CharacterData* operator->()
- { return this; }
-
- void appendData(const data_str& data)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT(getNodeType() == TEXT_NODE ||
- getNodeType() == CDATA_SECTION_NODE ||
- getNodeType() == COMMENT_NODE);
- data_str val = getNodeValue();
- val.append(data);
- setNodeValue(val);
- }
-
- void deleteData(int offset, int count)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT(getNodeType() == TEXT_NODE ||
- getNodeType() == CDATA_SECTION_NODE ||
- getNodeType() == COMMENT_NODE);
- data_str val = getNodeValue();
- val.erase(offset, count);
- setNodeValue(val);
- }
-
- data_str getData() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT(getNodeType() == TEXT_NODE ||
- getNodeType() == CDATA_SECTION_NODE ||
- getNodeType() == COMMENT_NODE);
- return getNodeValue();
- }
-
- int getLength() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT(getNodeType() == TEXT_NODE ||
- getNodeType() == CDATA_SECTION_NODE ||
- getNodeType() == COMMENT_NODE);
- return getNodeValue().size();
- }
-
- void insertData(int offset, const data_str& data)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT(getNodeType() == TEXT_NODE ||
- getNodeType() == CDATA_SECTION_NODE ||
- getNodeType() == COMMENT_NODE);
- data_str val = getNodeValue();
- val.insert(offset, data);
- setNodeValue(val);
- }
-
- void replaceData(int offset, int count, const data_str& arg)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT(getNodeType() == TEXT_NODE ||
- getNodeType() == CDATA_SECTION_NODE ||
- getNodeType() == COMMENT_NODE);
- data_str val = getNodeValue();
- val.erase(offset, count);
- val.insert(offset, arg);
- setNodeValue(val);
- }
-
- void setData(const data_str& data)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT(getNodeType() == TEXT_NODE ||
- getNodeType() == CDATA_SECTION_NODE ||
- getNodeType() == COMMENT_NODE);
- setNodeValue(data);
- }
-
- data_str substringData(int offset, int count) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT(getNodeType() == TEXT_NODE ||
- getNodeType() == CDATA_SECTION_NODE ||
- getNodeType() == COMMENT_NODE);
- data_str val = getNodeValue();
- return val.substr(offset, count);
- }
-
- protected:
- CharacterData(S::SablotSituation sit, S::SDOM_Node node) :
- Node(sit, node) { }
- };
-
- class Text :
- public CharacterData
- {
- public:
- Text() { }
- Text(const Node& node) :
- CharacterData(node) { }
-
- Text& operator=(const Text& other)
- { CharacterData::operator=(other); return *this; }
- Text& operator=(const void* null)
- { CharacterData::operator=(null); return *this; }
- const Text* operator->() const
- { return (const Text*)this; }
- Text* operator->()
- { return this; }
-
- Text splitText(int offset)
- throw(DOMException);
-
- protected:
- Text(S::SablotSituation sit, S::SDOM_Node node) :
- CharacterData(sit, node) { }
-
- friend class Document;
- };
-
- class CDATASection :
- public Text
- {
- public:
- CDATASection() { }
- CDATASection(const CDATASection& node) :
- Text(node) { }
-
- CDATASection& operator=(const CDATASection& other)
- { Text::operator=(other); return *this; }
- CDATASection& operator=(void* null)
- { Text::operator=(null); return *this; }
- const CDATASection* operator->() const
- { return (const CDATASection*)this; }
- CDATASection* operator->()
- { return this; }
-
- protected:
- CDATASection(S::SablotSituation sit, S::SDOM_Node node) :
- Text(sit, node) { }
-
- friend class Document;
- };
-
- class Comment :
- public CharacterData
- {
- public:
- Comment() { }
- Comment(const Comment& node) :
- CharacterData(node) { }
-
- Comment& operator=(const Node& other)
- { Node::operator=(other); return *this; }
- Comment& operator=(const Comment& other)
- { CharacterData::operator=(other); return *this; }
- Comment& operator=(void* null)
- { CharacterData::operator=(null); return *this; }
- const Comment* operator->() const
- { return (const Comment*)this; }
- Comment* operator->()
- { return this; }
-
- protected:
- Comment(S::SablotSituation sit, S::SDOM_Node node) :
- CharacterData(sit, node) { }
-
- friend class Document;
- };
-
- class ProcessingInstruction :
- public Node
- {
- public:
- ProcessingInstruction() { }
- ProcessingInstruction(const ProcessingInstruction& node) :
- Node(node) { }
-
- ProcessingInstruction& operator=(const Node& other)
- { Node::operator=(other); return *this; }
- ProcessingInstruction& operator=(const ProcessingInstruction& other)
- { Node::operator=(other); return *this; }
- ProcessingInstruction& operator=(void* null)
- { Node::operator=(null); return *this; }
- const ProcessingInstruction* operator->() const
- { return (const ProcessingInstruction*)this; }
- ProcessingInstruction* operator->()
- { return this; }
-
- data_str getData() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(PROCESSING_INSTRUCTION_NODE);
- return getNodeValue();
- }
-
- dom_str getTarget() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(PROCESSING_INSTRUCTION_NODE);
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return dom_str();
- }
-
- void setData(const data_str& data)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(PROCESSING_INSTRUCTION_NODE);
- setNodeValue(data);
- }
-
- protected:
- ProcessingInstruction(S::SablotSituation sit, S::SDOM_Node node) :
- Node(sit, node) { }
-
- friend class Document;
- };
-
- class DocumentFragment :
- public Node
- {
- public:
- DocumentFragment() { }
- DocumentFragment(const DocumentFragment& node) :
- Node(node) { }
-
- DocumentFragment& operator=(const Node& other)
- { Node::operator=(other); return *this; }
- DocumentFragment& operator=(const DocumentFragment& other)
- { Node::operator=(other); return *this; }
- DocumentFragment& operator=(void* null)
- { Node::operator=(null); return *this; }
- const DocumentFragment* operator->() const
- { return (const DocumentFragment*)this; }
- DocumentFragment* operator->()
- { return this; }
- };
-
- class Entity :
- public Node
- {
- public:
- Entity() { }
- Entity(const Entity& node) :
- Node(node) { }
-
- Entity& operator=(const Node& other)
- { Node::operator=(other); return *this; }
- Entity& operator=(const Entity& other)
- { Node::operator=(other); return *this; }
- Entity& operator=(void* null)
- { Node::operator=(null); return *this; }
- const Entity* operator->() const
- { return (const Entity*)this; }
- Entity* operator->()
- { return this; }
-
- dom_str getNotationName() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ENTITY_NODE);
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return dom_str();
- }
-
- dom_str getPublicId() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ENTITY_NODE);
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return dom_str();
- }
-
- dom_str getSystemId() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ENTITY_NODE);
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return dom_str();
- }
- };
-
- class EntityReference :
- public Node
- {
- public:
- EntityReference() { }
- EntityReference(const EntityReference& node) :
- Node(node) { }
-
- EntityReference& operator=(const Node& other)
- { Node::operator=(other); return *this; }
- EntityReference& operator=(const EntityReference& other)
- { Node::operator=(other); return *this; }
- EntityReference& operator=(void* null)
- { Node::operator=(null); return *this; }
- const EntityReference* operator->() const
- { return (const EntityReference*)this; }
- EntityReference* operator->()
- { return this; }
- };
-
- class Notation :
- public Node
- {
- public:
- Notation() { }
- Notation(const Notation& node) :
- Node(node) { }
-
- Notation& operator=(const Node& other)
- { Node::operator=(other); return *this; }
- Notation& operator=(const Notation& other)
- { Node::operator=(other); return *this; }
- Notation& operator=(void* null)
- { Node::operator=(null); return *this; }
- const Notation* operator->() const
- { return (const Notation*)this; }
- Notation* operator->()
- { return this; }
-
- dom_str getPublicId() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(NOTATION_NODE);
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return dom_str();
- }
-
- dom_str getSystemId() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(NOTATION_NODE);
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return dom_str();
- }
- };
-
- class DocumentType :
- public Node
- {
- public:
- DocumentType() { }
- DocumentType(const DocumentType& node) :
- Node(node) { }
-
- DocumentType& operator=(const Node& other)
- { Node::operator=(other); return *this; }
- DocumentType& operator=(const DocumentType& other)
- { Node::operator=(other); return *this; }
- DocumentType& operator=(void* null)
- { Node::operator=(null); return *this; }
- const DocumentType* operator->() const
- { return (const DocumentType*)this; }
- DocumentType* operator->()
- { return this; }
-
- NamedNodeMap getEntities() const
- throw(DOMException);
-
- dom_str getInternalSubset() const
- throw(DOMException)
- {
- ASSERT_VALID();
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return dom_str();
- }
-
- dom_str getName() const
- throw(DOMException)
- {
- ASSERT_VALID();
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return dom_str();
- }
-
- NamedNodeMap getNotations() const
- throw(DOMException);
- };
-
-
- class Document :
- public Node
- {
- public:
- Document() { }
- Document(const Document& doc) :
- Node(doc) { }
- Document(S::SablotSituation sit, S::SDOM_Document doc) :
- Node(sit, NULL) { m_node = doc; }
-
- Document& operator=(const Document& other)
- { Node::operator=(other); return *this; }
- Document& operator=(void* null)
- { Node::operator=(null); return *this; }
- const Document* operator->() const
- { return (const Document*)this; }
- Document* operator->()
- { return this; }
-
- DocumentType getDocType() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- return DocumentType();
- }
-
- DOMImplementation getImplementation() const
- throw(DOMException);
-
- Element getDocumentElement() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- S::SDOM_Node child;
- _try_(S::SDOM_getFirstChild(m_sit, m_node, &child));
- return Element(m_sit, child);
- }
-
- Element createElement(const dom_str& tag) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- S::SDOM_Node el;
- _try_(S::SDOM_createElement(m_sit, (S::SDOM_Document)m_node,
- &el, FROM_D(tag).c_str()));
- return Element(m_sit, el);
- }
-
- DocumentFragment createDocumentFragment() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return DocumentFragment();
- }
-
- Text createTextNode(const data_str& data) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- S::SDOM_Node text;
- _try_(S::SDOM_createTextNode(m_sit, (S::SDOM_Document)m_node,
- &text, FROM_V(data).c_str()));
- return Text(m_sit, text);
- }
-
- Comment createComment(const data_str& data) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- S::SDOM_Node comment;
- _try_(S::SDOM_createComment(m_sit, (S::SDOM_Document)m_node,
- &comment, FROM_V(data).c_str()));
- return Comment(m_sit, comment);
- }
-
- CDATASection createCDATASection(const data_str& data) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- S::SDOM_Node cdata;
- _try_(S::SDOM_createCDATASection(m_sit, (S::SDOM_Document)m_node,
- &cdata, FROM_V(data).c_str()));
- return CDATASection(m_sit, cdata);
- }
-
- ProcessingInstruction createProcessingInstruction(const dom_str& targ,
- const data_str& data) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- S::SDOM_Node pi;
- _try_(S::SDOM_createProcessingInstruction(m_sit,
- (S::SDOM_Document)m_node,
- &pi, FROM_D(targ).c_str(),
- FROM_V(data).c_str()));
- return ProcessingInstruction(m_sit, pi);
- }
-
- Attr createAttribute(const dom_str& name) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- S::SDOM_Node attr;
- _try_(S::SDOM_createAttribute(m_sit, (S::SDOM_Document)m_node,
- &attr, FROM_D(name).c_str()));
- return Attr(m_sit, attr);
- }
-
- EntityReference createEntityReference()
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return EntityReference();
- }
-
- NodeList getElementsByTagName(const dom_str& name) const
- throw(DOMException);
-
- Node importNode(const Node& import, bool deep) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- ASSERT_VALID_NODE(import);
- S::SDOM_Node imported;
- _try_(S::SDOM_cloneForeignNode(m_sit, (S::SDOM_Document)m_node,
- import.m_node, deep ? 1 : 0, &imported));
- return Node(m_sit, imported);
- }
-
- Element createElementNS(const dom_str& uri, const dom_str& tag) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- S::SDOM_Node el;
- _try_(S::SDOM_createElementNS(m_sit, (S::SDOM_Document)m_node,
- &el, FROM_D(uri).c_str(), FROM_D(tag).c_str()));
- return Element(m_sit, el);
- }
-
- Attr createAttributeNS(const dom_str& uri, const dom_str& name) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- S::SDOM_Node attr;
- _try_(S::SDOM_createAttributeNS(m_sit, (S::SDOM_Document)m_node,
- &attr, FROM_D(uri).c_str(), FROM_D(name).c_str()));
- return Attr(m_sit, attr);
- }
-
- NodeList getElementsByTagNameNS(const dom_str& uri,
- const dom_str& name) const
- throw(DOMException);
-
- Element getElementById(const dom_str& id) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- dom_str query = "//*[id('" + id + "')]";
- S::SDOM_NodeList result;
- _try_(S::SDOM_xql(m_sit, FROM_D(query).c_str(), m_node, &result));
-
- int length;
- _try_(S::SDOM_getNodeListLength(m_sit, result, &length));
-
- Element ret;
- if(length != 1)
- {
- ret = Element();
- }
- else
- {
- S::SDOM_Node el;
- _try_(S::SDOM_getNodeListItem(m_sit, result, 0, &el));
- ret = Element(m_sit, el);
- }
-
- S::SDOM_disposeNodeList(m_sit, result);
- return ret;
- }
-
- std::string serialize() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- S::SDOM_char* serialized;
- _try_(S::SDOM_docToString(m_sit, (S::SDOM_Document)m_node, &serialized));
- std::string ret(serialized);
- S::SablotFree(serialized);
- return ret;
- }
-
- void release()
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- S::SDOM_tmpListDump((S::SDOM_Document)m_node, 0);
- if(S::SablotDestroyDocument(m_sit, (S::SDOM_Document)m_node))
- _try_(S::SDOM_NOT_OK);
- *this = NULL;
- }
-
- protected:
-
- friend class Node;
- friend class DOMImplementation;
- };
-
-
- class DOMImplementation :
- public INT::Base
- {
- public:
- DOMImplementation()
- throw(DOMException) : INT::Base(NULL)
- {
- if(S::SablotCreateSituation(&m_sit))
- _try_(S::SDOM_NOT_OK);
- }
- DOMImplementation(S::SablotSituation sit)
- throw(DOMException) : INT::Base(sit) { }
- DOMImplementation(const DOMImplementation& impl) :
- INT::Base(impl) { }
-
- DOMImplementation& operator=(const DOMImplementation& other)
- { Base::operator=(other); return *this; }
- DOMImplementation& operator=(void* null)
- { Base::operator=(null); return *this; }
- const DOMImplementation* operator->() const
- { return (const DOMImplementation*)this; }
- DOMImplementation* operator->()
- { return this; }
-
- Document createDocument(const dom_str& uri, const dom_str& qname,
- const DocumentType& type) const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_Document doc;
- if(S::SablotCreateDocument(m_sit, &doc))
- _try_(S::SDOM_NOT_OK);
-
- Document document(m_sit, doc);
-
- if(!qname.empty())
- {
- if(!uri.empty())
- document.appendChild(document.createElementNS(uri, qname));
- else
- document.appendChild(document.createElement(qname));
- }
-
- return document;
- }
-
- DocumentType createDocumentType(const dom_str& qname,
- const dom_str& publicId,
- const dom_str& systemId) const
- throw(DOMException)
- {
- ASSERT_VALID();
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return DocumentType();
- }
-
- bool hasFeature(const dom_str& feature, const dom_str& version) const
- throw(DOMException)
- {
- ASSERT_VALID();
- return false;
- }
-
- void release()
- throw(DOMException)
- {
- ASSERT_VALID();
- if(S::SablotDestroySituation(m_sit))
- _try_(S::SDOM_NOT_OK);
- }
- };
-
- namespace INT
- {
- class NodeList :
- public INT::Base,
- public INT::Inst
- {
- public:
-#ifdef COMPARE_REF
- virtual bool operator==(const NodeList& other) const
- { return Base::operator==(other); }
-#endif
- virtual int getLength() const
- throw(DOMException)
- {
- ASSERT_VALID();
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return 0;
- }
-
- virtual Node item(int index) const
- throw(DOMException)
- {
- ASSERT_VALID();
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return Node();
- }
-
- protected:
- NodeList(S::SablotSituation sit) :
- INT::Base(sit) { }
-
- virtual bool isValid() const
- {
- return false;
- }
-
- private:
- NodeList(const NodeList& list) : INT::Base(list) { }
- };
-
- class ChildNodeList :
- public NodeList
- {
- public:
-#ifdef COMPARE_REF
- virtual bool operator==(const NodeList& other) const
- { return m_el == ((ChildNodeList)other).m_el; }
-#endif
- virtual int getLength() const
- throw(DOMException)
- {
- ASSERT_VALID();
- int length;
- _try_(S::SDOM_getChildNodeCount(m_sit, m_el, &length));
- return length;
- }
-
- virtual Node item(int index) const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_Node attr;
- _try_(S::SDOM_getChildNodeIndex(m_sit, m_el, index, &attr));
- return Node(m_sit, attr);
- }
-
- protected:
- ChildNodeList(S::SablotSituation sit, S::SDOM_Node node) :
- NodeList(sit) { m_el = node; }
-
- virtual bool isValid() const
- {
- return m_el != NULL;
- }
-
- protected:
- S::SDOM_Node m_el;
-
- friend class Node;
- };
-
- class AttrNodeList :
- public NodeList
- {
- public:
-#ifdef COMPARE_REF
- virtual bool operator==(const NodeList& other) const
- { return m_el == ((AttrNodeList)other).m_el; }
-#endif
- virtual int getLength() const
- throw(DOMException)
- {
- ASSERT_VALID();
- int length;
- _try_(S::SDOM_getAttributeNodeCount(m_sit, m_el, &length));
- return length;
- }
-
- virtual Node item(int index) const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_Node attr;
- _try_(S::SDOM_getAttributeNodeIndex(m_sit, m_el, index, &attr));
- return Node(m_sit, attr);
- }
-
- protected:
- AttrNodeList(S::SablotSituation sit, S::SDOM_Node el) :
- NodeList(sit) { m_el = el; }
-
- virtual bool isValid() const
- {
- return m_el != NULL;
- }
-
- protected:
- S::SDOM_Node m_el;
- };
-
-
- class DOMNodeList :
- public NodeList
- {
- public:
-#ifdef COMPARE_REF
- virtual bool operator==(const NodeList& other) const
- { return m_list == ((DOMNodeList&)other).m_list; }
-#endif
- virtual int getLength() const
- throw(DOMException)
- {
- ASSERT_VALID();
- int length;
- _try_(S::SDOM_getNodeListLength(m_sit, m_list, &length));
- return length;
- }
-
- virtual Node item(int index) const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_Node it;
- _try_(S::SDOM_getNodeListItem(m_sit, m_list, index, &it));
- return Node(m_sit, it);
- }
-
- protected:
- DOMNodeList(S::SablotSituation sit, S::SDOM_NodeList list) :
- NodeList(sit)
- {
- m_list = list;
- }
-
- ~DOMNodeList()
- {
- if(m_list != NULL)
- S::SDOM_disposeNodeList(m_sit, m_list);
- m_list = NULL;
- }
-
- virtual bool isValid() const
- {
- return m_list != NULL;
- }
-
- protected:
- S::SDOM_NodeList m_list;
-
- friend class Element;
- friend class Document;
- };
-
-
- class NamedNodeMap :
- public INT::Base,
- public INT::Inst
- {
- public:
-#ifdef COMPARE_REF
- virtual bool operator==(const NamedNodeMap& other) const
- { Base::operator==(other); }
-#endif
- virtual int getLength() const
- throw(DOMException)
- {
- ASSERT_VALID();
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return 0;
- }
-
- virtual Node getNamedItem(const dom_str& name) const
- throw(DOMException)
- {
- ASSERT_VALID();
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return Node();
- }
-
- virtual Node getNamedItemNS(const dom_str& uri, const dom_str& name) const
- throw(DOMException)
- {
- ASSERT_VALID();
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return Node();
- }
-
- virtual Node item(int index) const
- throw(DOMException)
- {
- ASSERT_VALID();
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return Node();
- }
-
- virtual Node removeNamedItem(const dom_str& name)
- throw(DOMException)
- {
- ASSERT_VALID();
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return Node();
- }
-
- virtual Node removeNamedItemNS(const dom_str& uri, const dom_str& name)
- throw(DOMException)
- {
- ASSERT_VALID();
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return Node();
- }
-
- virtual Node setNamedItem(const Node& arg)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_VALID_NODE(arg);
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return Node();
- }
-
- virtual Node setNamedItemNS(const Node& arg)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_VALID_NODE(arg);
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return Node();
- }
-
- protected:
- NamedNodeMap(S::SablotSituation sit) :
- INT::Base(sit) { }
-
- virtual bool isValid() const
- {
- return false;
- }
-
- private:
- NamedNodeMap(const NamedNodeMap& map) : INT::Base(map) { }
- };
-
- class AttrNamedNodeMap :
- public NamedNodeMap
- {
- public:
-#ifdef COMPARE_REF
- virtual bool operator==(const NamedNodeMap& other) const
- { return m_el == ((AttrNamedNodeMap)other).m_el; }
-#endif
- virtual int getLength() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_VALID_NODE(m_el);
- int length;
- _try_(S::SDOM_getAttributeNodeCount(m_sit, m_el.m_node, &length));
- return length;
- }
-
- virtual Node getNamedItem(const dom_str& name) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_VALID_NODE(m_el);
- return m_el.getAttributeNode(name);
- }
-
- virtual Node getNamedItemNS(const dom_str& uri, const dom_str& name) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_VALID_NODE(m_el);
- return m_el.getAttributeNodeNS(uri, name);
- }
-
- virtual Node item(int index) const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_Node attr;
- _try_(S::SDOM_getAttributeNodeIndex(m_sit, m_el.m_node, index, &attr));
- return Node(m_sit, attr);
- }
-
- virtual Node removeNamedItem(const dom_str& name)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_VALID_NODE(m_el);
- Node node = getNamedItem(name);
- if(node != NULL)
- m_el.removeAttributeNode((Attr&)node);
- return node;
- }
-
- virtual Node removeNamedItemNS(const dom_str& uri, const dom_str& name)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_VALID_NODE(m_el);
- Node node = getNamedItemNS(uri, name);
- if(node != NULL)
- m_el.removeAttributeNode((Attr&)node);
- return node;
- }
-
- virtual Node setNamedItem(const Node& arg)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_VALID_NODE(m_el);
- return m_el.setAttributeNode((Attr&)arg);
- }
-
- virtual Node setNamedItemNS(const Node& arg)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_VALID_NODE(m_el);
- return m_el.setAttributeNodeNS((Attr&)arg);
- }
-
- protected:
- AttrNamedNodeMap(S::SablotSituation sit, const Node& el) :
- NamedNodeMap(sit)
- {
- ASSERT_VALID_NODE(el);
- ASSERT_NODE_TYPE(el, Node::ELEMENT_NODE);
- m_el = (Element&)el;
- }
-
- virtual bool isValid() const
- {
- return m_el.isValid();
- }
-
-
- protected:
- Element m_el;
-
- friend class Node;
- };
- };
-
-
- inline NodeList Node::getChildNodes() const
- throw(DOMException)
- {
- ASSERT_VALID();
- return NodeList(new INT::ChildNodeList(m_sit, m_node));
- }
-
- inline NamedNodeMap Node::getAttributes() const
- throw(DOMException)
- {
- ASSERT_VALID();
- if(getNodeType() != ELEMENT_NODE)
- return NamedNodeMap(NULL);
-
- return NamedNodeMap(new INT::AttrNamedNodeMap(m_sit, *this));
- }
-
- inline Document Node::getOwnerDocument() const
- throw(DOMException)
- {
- ASSERT_VALID();
- S::SDOM_Document doc;
- _try_(S::SDOM_getOwnerDocument(m_sit, m_node, &doc));
- return Document(m_sit, doc);
- }
-
- inline Element Attr::getOwnerElement() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ATTRIBUTE_NODE);
- S::SDOM_Node el;
- _try_(S::SDOM_getAttributeElement(m_sit, m_node, &el));
- return Element(m_sit, el);
- }
-
- inline NodeList Element::getElementsByTagName(const dom_str& name) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ELEMENT_NODE);
- dom_str query = "descendant::" + name;
- S::SDOM_NodeList result;
- _try_(S::SDOM_xql(m_sit, FROM_D(query).c_str(), m_node, &result));
- return NodeList(new INT::DOMNodeList(m_sit, result));
- }
-
- inline NodeList Element::getElementsByTagNameNS(const dom_str& uri,
- const dom_str& name) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(ELEMENT_NODE);
- dom_str query = "descendant::*[namespace-uri()='" + uri + "'";
- if(name != "*")
- query += " and local-name()='" + name + "']";
- S::SDOM_NodeList result;
- _try_(S::SDOM_xql(m_sit, FROM_D(query).c_str(), m_node, &result));
- return NodeList(new INT::DOMNodeList(m_sit, result));
- }
-
- inline NodeList Document::getElementsByTagName(const dom_str& name) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- dom_str query = "descendant::" + name;
- S::SDOM_NodeList result;
- _try_(S::SDOM_xql(m_sit, FROM_D(query).c_str(), m_node, &result));
- return NodeList(new INT::DOMNodeList(m_sit, result));
- }
-
- inline NodeList Document::getElementsByTagNameNS(const dom_str& uri,
- const dom_str& name) const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- dom_str query = "descendant::*[namespace-uri()='" + uri + "'";
- if(name != "*")
- query += " and local-name()='" + name + "']";
- S::SDOM_NodeList result;
- _try_(S::SDOM_xql(m_sit, FROM_D(query).c_str(), m_node, &result));
- return NodeList(new INT::DOMNodeList(m_sit, result));
- }
-
- inline DOMImplementation Document::getImplementation() const
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT_TYPE(DOCUMENT_NODE);
- return DOMImplementation(m_sit);
- }
-
- inline Text Text::splitText(int offset)
- throw(DOMException)
- {
- ASSERT_VALID();
- ASSERT(getNodeType() == TEXT_NODE ||
- getNodeType() == CDATA_SECTION_NODE);
-
- data_str val = getNodeValue();
- setNodeValue(val.substr(0, offset));
-
- Document doc = getOwnerDocument();
- ASSERT(doc != NULL);
-
- Text split(m_sit, NULL);
- val = val.substr(0, offset);
-
- switch(getNodeType())
- {
- case TEXT_NODE:
- split = doc.createTextNode(val);
- break;
-
- case CDATA_SECTION_NODE:
- split = doc.createCDATASection(val);
- break;
-
- default:
- ASSERT(false);
- };
-
- Node parent = getParentNode();
- if(parent != NULL)
- {
- Node next = getNextSibling();
- if(next != NULL)
- parent.insertBefore(split, next);
- else
- parent.appendChild(split);
- }
-
- return split;
- }
-
- inline NamedNodeMap DocumentType::getEntities() const
- throw(DOMException)
- {
- ASSERT_VALID();
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return NamedNodeMap(NULL);
- }
-
- inline NamedNodeMap DocumentType::getNotations() const
- throw(DOMException)
- {
- ASSERT_VALID();
- _try_(S::SDOM_NOT_SUPPORTED_ERR);
- return NamedNodeMap(NULL);
- }
-
-}; // namespace DOM
-
-
-#endif //__SABLO_H__
diff --git a/src/sablotr.cpp b/src/sablotr.cpp
deleted file mode 100644
index 47853cc..0000000
--- a/src/sablotr.cpp
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-// SABLOTRON C++ WRAPPER CONVERSION FUNCTIONS
-//
-
-#include <wchar.h>
-#include "sablo.h"
-
-bool DOM::transcode16to8(const std::basic_string<wchar_t>& data,
- std::basic_string<char>& ret)
-{
- ret.resize(0);
- ret.reserve(data.length() + (data.length() / 2));
-
- // basic_string.c_str doesn't work properly everywhere
- // most notably not in the g++ std library
-
- const wchar_t* c = data.length() ? data.data() : L"";
- const wchar_t* e = c + data.length();
-
- for( ; c < e; c++)
- {
- if(*c <= 0x007F)
- {
- ret.append(1, (char)*c);
- }
- else if(*c <= 0x07FF)
- {
- ret.append(1, (char)(192 | (*c >> 6)));
- ret.append(1, (char)(128 | (*c & 63)));
- }
- else
- {
- ret.append(1, (char)(224 | (*c >> 12)));
- ret.append(1, (char)(128 | ((*c >> 6) & 63)));
- ret.append(1, (char)(128 | (*c & 63)) );
- }
- }
-
- return true;
-}
-
-bool DOM::transcode8to16(const std::basic_string<char>& data,
- std::basic_string<wchar_t>& ret)
-{
- ret.resize(0);
- ret.reserve(data.length());
-
- // basic_string.c_str doesn't work properly everywhere
- // most notably not in the g++ std library
-
- const char* c = data.length() ? data.data() : "";
- const char* e = c + data.length();
-
- for( ; c < e; c++)
- {
- // First 4 bits set
- if((c[0] & 0xF8) == 0xF0 &&
- (c[1] & 0xC0) == 0x80 &&
- (c[2] & 0xC0) == 0x80 &&
- (c[3] & 0xC0) == 0x80)
- {
- ret.append(1, (wchar_t)(((wchar_t)c[0] & 7) << 18 |
- ((wchar_t)c[1] & 63) << 12 |
- ((wchar_t)c[2] & 63) << 6 |
- ((wchar_t)c[3] & 63)));
- c += 3;
- }
-
- // First 3 bits set
- else if((c[0] & 0xF0) == 0xE0 &&
- (c[1] & 0xC0) == 0x80 &&
- (c[2] & 0xC0) == 0x80)
- {
- ret.append(1, (wchar_t)(((wchar_t)c[0] & 15) << 12 |
- ((wchar_t)c[1] & 63) << 6 |
- ((wchar_t)c[2] & 63)));
- c += 2;
- }
-
- // First 2 bits set
- else if((c[0] & 0xE0) == 0xC0 &&
- (c[1] & 0xC0) == 0x80)
- {
- ret.append(1, (wchar_t)(((wchar_t)c[0] & 31) << 6 |
- ((wchar_t)c[1] & 63)));
- c += 1;
- }
-
- // First bit set
- else if(!(c[0] & 0x80))
- {
- ret.append(1, (wchar_t)c[0]);
- }
-
- else
- return false;
- }
-
- return true;
-}
diff --git a/src/tags.h b/src/tags.h
deleted file mode 100644
index 98787d9..0000000
--- a/src/tags.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-#ifndef __TAGS_H__
-#define __TAGS_H__
-
-/*
- * IMPORTANT: When adding tags, attributes or values here make sure to update
- * the XSL Schema for the output formats.
- */
-
-static const char* kNSPrefix = "xmlns";
-static const wchar_t* kNSRtfx = L"http://memberwebs.com/ns/rtfx/";
-
-// Tags used internally
-static const char* kElDest = "i_dest";
-static const char* kElBlock = "i_block";
-static const char* kElListtable = "i_listtable";
-static const char* kElListdef = "i_listdef";
-static const char* kElFontTable = "i_fonttable";
-static const char* kElFontDef = "i_fontdef";
-static const char* kAtFix = "i_fix";
-static const char* kAtCell = "i_cell";
-static const char* kAtList = "i_list";
-
-// All the main tags
-static const char* kElPara = "para";
-static const char* kElDoc = "document";
-static const char* kElTab = "tab";
-static const char* kElSect = "sect";
-static const char* kElPage = "page";
-static const char* kElStyle = "style";
-static const char* kElLine = "line";
-static const char* kElList = "list";
-static const char* kElStylesheet = "stylesheet";
-static const char* kElInfo = "info";
-static const char* kElTitle = "title";
-static const char* kElAuthor = "author";
-static const char* kElOperator = "operator";
-static const char* kElB = "b";
-static const char* kElHide = "hide";
-static const char* kElI = "i";
-static const char* kElStrike = "strike";
-static const char* kElU = "u";
-static const char* kElSuper = "super";
-static const char* kElSub = "sub";
-static const char* kElCell = "cell";
-static const char* kElRow = "row";
-static const char* kElTable = "table";
-static const char* kElFootNote = "footnote";
-static const char* kElRef = "ref";
-static const char* kElFont = "font";
-static const char* kElOptions = "options";
-
-// Attributes
-static const char* kAtName = "name";
-static const char* kAtBold = "bold";
-static const char* kAtHidden = "hide";
-static const char* kAtItalic = "italic";
-static const char* kAtStrike = "strike";
-static const char* kAtUnderline = "underline";
-static const char* kAtColor = "color";
-static const char* kAtType = "type";
-static const char* kAtOrdered = "ordered";
-static const char* kAtStart = "start";
-static const char* kAtId = "id";
-static const char* kAtTo = "to";
-static const char* kAtSize = "size";
-
-// Values
-static const wchar_t* kValDisc = L"disc";
-static const wchar_t* kValLowerAlpha = L"lower-alpha";
-static const wchar_t* kValUpperAlpha = L"upper-alpha";
-static const wchar_t* kValLowerRoman = L"lower-roman";
-static const wchar_t* kValUpperRoman = L"upper-roman";
-static const wchar_t* kValArabic = L"arabic";
-static const wchar_t* kValNull = L"";
-static const wchar_t* kValFootNote = L"footnote";
-static const wchar_t* kValList = L"list";
-static const wchar_t* kValPara = L"para";
-static const wchar_t* kValTable = L"table";
-static const wchar_t* kValTrue = L"true";
-static const wchar_t* kValZero = L"0";
-
-#endif // __TAGS_H__
diff --git a/src/usuals.h b/src/usuals.h
deleted file mode 100644
index eeb13b1..0000000
--- a/src/usuals.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-#ifndef __USUALS_H__
-#define __USUALS_H__
-
-#ifndef NULL
-#define NULL 0
-#endif
-
-#ifdef _WIN32
-/* Suppress stupid errors */
-#pragma warning( disable : 4786 )
-#endif
-
-#ifdef _WIN32
-#include "config.win32.h"
-#else
-#include "config.h"
-#endif
-
-#include <stdlib.h>
-#include <assert.h>
-
-#include <wchar.h>
-#include <string>
-using std::string;
-
-#if HAVE_WSTRING
-using std::wstring;
-#else
-typedef std::basic_string<wchar_t> wstring;
-#endif
-
-#endif // __USUALS_H__
diff --git a/src/xmlcomposehelpers.cpp b/src/xmlcomposehelpers.cpp
deleted file mode 100644
index 74eb9c1..0000000
--- a/src/xmlcomposehelpers.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-#include "usuals.h"
-#include "xmlcomposehelpers.h"
-
-/* ----------------------------------------------------------------------------------
- * CONSTRUCTION
- */
-
-Level::Level()
-{
- m_previous = NULL;
- m_element = NULL;
- m_destination = NULL;
- m_analyser = NULL;
-}
-
-Level::Level(const Level& level) :
- m_text(level.m_text)
-{
- m_element = NULL;
- m_destination = NULL;
- m_analyser = NULL;
- m_previous = &level;
-}
-
-Level::~Level()
-{
- if(m_analyser)
- m_analyser->done();
- if(m_destination)
- m_destination->done();
-}
-
-/* ----------------------------------------------------------------------------------
- * LEVEL OPERATIONS
- */
-
-LevelPtr Level::pushLevel()
-{
- LevelPtr level = new Level(*this);
- return level;
-}
-
-LevelPtr Level::getPrevious()
-{
- return m_previous;
-}
-
-DOM::Element Level::getElement(bool deep)
-{
- if(m_element != NULL)
- return m_element;
- else if(deep && m_previous)
- return m_previous->getElement();
- else
- return DOM::Element();
-}
-
-void Level::setElement(DOM::Element element, bool deep)
-{
- if(deep && m_previous && m_element == NULL)
- m_previous->setElement(element, deep);
- else
- m_element = element;
-}
-
-AnalyserPtr Level::getAnalyser(bool deep)
-{
- if(m_analyser)
- return m_analyser;
- else if(deep && m_previous)
- return m_previous->getAnalyser();
- else
- return NULL;
-}
-
-void Level::setAnalyser(AnalyserPtr analyser, bool deep)
-{
- if(deep && m_previous && !m_analyser)
- m_previous->setAnalyser(analyser, deep);
-
- else
- {
- if(m_analyser != NULL)
- m_analyser->done();
-
- m_analyser = analyser;
- }
-}
-
-DestinationPtr Level::getDestination(bool deep)
-{
- if(m_destination)
- return m_destination;
- else if(deep && m_previous)
- return m_previous->getDestination();
- else
- return NULL;
-}
-
-void Level::setDestination(DestinationPtr destination, bool deep)
-{
- if(deep && m_previous && !m_destination)
- m_previous->setDestination(destination, deep);
- else
- {
- if(m_destination != NULL)
- m_destination->done();
-
- m_destination = destination;
- }
-}
-
-RtfFormatting& Level::getFormatting()
-{
- return m_text;
-}
-
-void Level::setTextProperties(RtfFormatting& formatting)
-{
- m_text.copy(formatting);
-}
diff --git a/src/xmlcomposehelpers.h b/src/xmlcomposehelpers.h
deleted file mode 100644
index aa8a52d..0000000
--- a/src/xmlcomposehelpers.h
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-#ifndef __XMLCOMPOSEHELPERS_H__
-#define __XMLCOMPOSEHELPERS_H__
-
-#include "usuals.h"
-#include "reference.h"
-#include "sablo.h"
-#include "rtfformatting.h"
-
-class XmlComposer;
-
-/*
- * Destination
- *
- * A destination is a small class that handles the character data found
- * in the RTF document. Depending on the current context in the RTF
- * different destinations are used.
- */
-class Destination :
- public Instance
-{
-public:
- // This is called when the Destination is first used
- virtual void initialize() {};
- // Called when data arrives at destination
- virtual void charData(wstring data) {};
- // Called when the Destination goes out of scope
- virtual void done() {};
-
-protected:
- XmlComposer* m_composer;
- friend class XmlComposer;
-};
-
-/*
- * Analyser
- *
- * An analyser is a small class that handles the RTF control words.
- * Depending on the current context in the RTF different analysers
- * are used.
- */
-class Analyser :
- public Instance
-{
-public:
- // This is called when the Analyser is first used
- virtual void initialize() {};
- // Called when a control word is seen
- virtual void controlWord(const string& cw, int flags, int param) {};
- // Called when a group is seen within this scope
- virtual void groupStart() {};
- // Called when a group ends within this scope
- virtual void groupEnd() {};
- // Called when when this analyser goes out of scope
- virtual void done() {};
-
-protected:
- XmlComposer* m_composer;
- friend class XmlComposer;
-};
-
-class Level;
-
-// Reference counted pointers
-typedef Reference<Destination> DestinationPtr;
-typedef Reference<Analyser> AnalyserPtr;
-typedef Reference<Level> LevelPtr;
-
-/*
- * Level
- *
- * A level is a combination of a Destination, Analyser, XML Element and
- * some other options. They're used in a stack to push and pop these as
- * RTF groups are found.
- *
- * About the stack:
- * Not each level has it's own options. If a certain option isn't found
- * in the current level the previous one is looked up. That's what all
- * the 'deep' stuff is about below:
- *
- * get* methods:
- * When 'deep' is set look to previous levels for the given object if not
- * found at the current level. When not set returns object in current level
- * or null when none exists here.
- *
- * set* methods:
- * When 'deep' is set then replace the object currently being used at it's
- * own level. So if get* would return an object from a previous level, with
- * deep set to true it would replace that object in the given level. When
- * not set, then the object is set in the current level.
- */
-class Level :
- public Instance
-{
-public:
- Level();
- virtual ~Level();
-
- LevelPtr getPrevious();
- LevelPtr pushLevel();
-
- // The current XML Element
- DOM::Element getElement(bool deep = true);
- void setElement(DOM::Element element, bool deep = false);
-
- // The current Analyser
- AnalyserPtr getAnalyser(bool deep = true);
- void setAnalyser(AnalyserPtr analyser, bool deep = false);
-
- // The current Destination
- DestinationPtr getDestination(bool deep = true);
- void setDestination(DestinationPtr destination, bool deep = false);
-
- // The current formatting options
- RtfFormatting& getFormatting();
- void setTextProperties(RtfFormatting& textProperties);
-
-protected:
-
- // Constructor for stacking levels
- Level(const Level& level);
-
- LevelPtr m_previous; // The previous level
- DOM::Element m_element; // XML Element for this level
- RtfFormatting m_text; // Formatting options for this level
- DestinationPtr m_destination; // Destination for this level
- AnalyserPtr m_analyser; // Analyser for this level
-};
-
-#endif //__XMLCOMPOSEHELPERS_H__
diff --git a/src/xmlcomposer.cpp b/src/xmlcomposer.cpp
deleted file mode 100644
index 6f41b29..0000000
--- a/src/xmlcomposer.cpp
+++ /dev/null
@@ -1,1245 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-#include "usuals.h"
-#include "xmlcomposer.h"
-#include "xmlfixups.h"
-#include "domhelpers.h"
-#include "tags.h"
-
-
-wstring formatInt(int num)
-{
- char buff[16];
-
- // Certain OSs don't support swprintf :(
- sprintf(buff, "%d", num);
-
- wstring n;
- for(char* s = buff; *s; s++)
- n.append(1, *s);
-
- return n;
-}
-
-/* ----------------------------------------------------------------------------------
- * CONSTRUCTION
- */
-
-XmlComposer::XmlComposer(const XmlComposerOptions& options)
-{
- m_document = NULL;
- memcpy(&m_options, &options, sizeof(options));
-
- // All autocounters start at 1
- for(int i = 0; i < AUTOCOUNT_MAX; i++)
- m_autocount[i] = 1;
-}
-
-XmlComposer::~XmlComposer()
-{
- clear();
-
- if(m_impl != NULL)
- m_impl.release();
-}
-
-void XmlComposer::clear()
-{
- if(m_document != NULL)
- {
- try
- {
- m_document.release();
- }
- catch(...) { }
-
- m_document = NULL;
- }
- LevelHandler::clear();
-}
-
-
-/* ----------------------------------------------------------------------------------
- * HANDLER OVERRIDES
- */
-
-void XmlComposer::startDocument(RtfParser* reader)
-{
- LevelHandler::startDocument(reader);
- ASSERT(m_curLevel != NULL);
-
- // Create a new document
- m_document = m_impl.createDocument("", kElDoc, DOM::DocumentType());
-
- // TODO: Throw error if document is null
- ASSERT(m_document != NULL);
-
- // Hook up the top level element
- DOM::Element top = m_document.getDocumentElement();
- m_curLevel->setElement(top, true);
-
- // Set the attributes on the top level
- setAnalyser(AnalyserPtr(new Root));
- setDestination(DestinationPtr(new Content));
- getTextFormatting().resetPara();
- getTextFormatting().resetText();
-
- // Create the options element
- m_docOptions = m_document.createElement(kElOptions);
- top.appendChild(m_docOptions);
-}
-
-void XmlComposer::endDocument()
-{
- LevelHandler::endDocument();
-
- XmlFixups fix;
-
- // Pass 0: Cleanup the tree
- // XmlFixups::combineDuplicates(m_document);
- // XmlFixups::consolidateStartTags(m_document);
- // XmlFixups::consolidateEndTags(m_document);
-
- // Pass 1: Block breakout
- 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);
-
- // Pass 2: Fixups
- fix.runPassTwo(m_document);
-
- // XmlFixups::fixLists(m_document);
- // XmlFixups::fixStyles(m_document);
- // XmlFixups::fixBlocks(m_document);
- // XmlFixups::removeTags(m_document);
- // XmlFixups::breakBreak(m_document, kElDoc, kElPage);
- // XmlFixups::breakBreak(m_document, kElDoc, kElSect);
-
- // Pass 3: Final cleanup
- // XmlFixups::combineDuplicates(m_document);
-
- DOM::Element top = m_document.getDocumentElement();
- ASSERT(top != NULL);
- top.setAttribute(kNSPrefix, kNSRtfx);
-
- return;
-}
-
-void XmlComposer::charData(wstring data)
-{
- ASSERT(m_curLevel != NULL);
- DestinationPtr destination = m_curLevel->getDestination();
-
- if(!destination)
- {
- destination = DestinationPtr(new Content);
- setDestination(destination);
- }
-
- destination->charData(data);
-}
-
-void XmlComposer::controlWord(const string& cw, int flags, int param)
-{
- ASSERT(m_curLevel != NULL);
- AnalyserPtr analyser = m_curLevel->getAnalyser();
- if(analyser)
- analyser->controlWord(cw, flags, param);
-}
-
-void XmlComposer::groupStart()
-{
- LevelHandler::groupStart();
-
- ASSERT(m_curLevel != NULL);
- AnalyserPtr analyser = m_curLevel->getAnalyser();
- if(analyser)
- analyser->groupStart();
-}
-
-void XmlComposer::groupEnd()
-{
- LevelHandler::groupEnd();
-
- ASSERT(m_curLevel != NULL);
- AnalyserPtr analyser = m_curLevel->getAnalyser();
- if(analyser)
- analyser->groupEnd();
-}
-
-
-/* ----------------------------------------------------------------------------------
- * HELPER FUNCTIONS
- */
-
-DOM::Element XmlComposer::createElement(const string& name)
-{
- ASSERT(name.length() > 0);
- return m_document.createElement(name);
-}
-
-void XmlComposer::replaceElement(const DOM::Element& element)
-{
- ASSERT(m_curLevel != NULL);
- m_curLevel->setElement(element, true);
-}
-
-void XmlComposer::pushElement(const DOM::Element& element)
-{
- ASSERT(m_curLevel != NULL);
- getElement().appendChild(element);
- m_curLevel->setElement(element);
-}
-
-void XmlComposer::pushTopElement(const DOM::Element& element)
-{
- ASSERT(m_curLevel != NULL);
- DOM::Element top = m_document.getDocumentElement();
- if(top.hasChildNodes())
- top.insertBefore(element, top.getFirstChild());
- else
- top.appendChild(element);
-
- m_curLevel->setElement(element);
-}
-
-DOM::Element XmlComposer::popElement()
-{
- DOM::Element element = getElement();
- ASSERT(m_curLevel != NULL);
-
- DOM::Node parent = element.getParentNode();
- ASSERT(parent != NULL && parent.getNodeType() == DOM::Node::ELEMENT_NODE);
-
- // Set it deep so it replaces the current element
- m_curLevel->setElement((DOM::Element&)parent, true);
- return element;
-}
-
-void XmlComposer::setAttribute(const string& name, const wstring& value, DOM::Element el)
-{
- ASSERT(name.length() > 0);
- if(el == NULL)
- el = getElement();
- el.setAttribute(name, value);
-}
-
-void XmlComposer::setAttribute(const string& name, int value, DOM::Element el)
-{
- ASSERT(name.length() > 0);
- if(el == NULL)
- el = getElement();
- el.setAttribute(name, formatInt(value));
-}
-
-void XmlComposer::setDestination(DestinationPtr dest)
-{
- ASSERT(m_curLevel);
-
- m_curLevel->setDestination(dest);
- dest->m_composer = this;
- dest->initialize();
-}
-
-DestinationPtr XmlComposer::replaceDestination(DestinationPtr dest)
-{
- ASSERT(m_curLevel);
-
- DestinationPtr old = m_curLevel->getDestination();
- m_curLevel->setDestination(dest, true);
- dest->m_composer = this;
- dest->initialize();
-
- return old;
-}
-
-
-void XmlComposer::setAnalyser(AnalyserPtr analy)
-{
- ASSERT(m_curLevel);
- ASSERT(analy != NULL);
-
- analy->m_composer = this;
- m_curLevel->setAnalyser(analy);
- analy->initialize();
-}
-
-AnalyserPtr XmlComposer::getAnalyser()
-{
- ASSERT(m_curLevel);
- return m_curLevel->getAnalyser();
-}
-
-DestinationPtr XmlComposer::getDestination()
-{
- ASSERT(m_curLevel);
- return m_curLevel->getDestination();
-}
-
-RtfFormatting& XmlComposer::getTextFormatting()
-{
- ASSERT(m_curLevel);
- return m_curLevel->getFormatting();
-}
-
-int XmlComposer::getAutoCount(int type)
-{
- ASSERT(type < AUTOCOUNT_MAX);
- return m_autocount[type];
-}
-
-void XmlComposer::incrementAutoCount(int type)
-{
- ASSERT(type < AUTOCOUNT_MAX);
- m_autocount[type]++;
-}
-
-void XmlComposer::addDocumentOption(DOM::Element& option)
-{
- ASSERT(m_docOptions != NULL);
- m_docOptions.appendChild(option);
-}
-
-
-/* ----------------------------------------------------------------------------------
- * CONVENIENCE MACROS USED BELOW
- */
-
-#define AN_ELEMENT(name) \
- m_composer->pushElement(m_composer->createElement(name))
-#define AN_TOP_ELEMENT(name) \
- m_composer->pushTopElement(m_composer->createElement(name))
-#define AN_POP_ELEMENT() \
- m_composer->popElement()
-#define AN_ATTRIBUTE(name, value) \
- m_composer->setAttribute(name, value)
-#define AN_DESTINATION_ATTR(name) \
- m_composer->setDestination(new Attribute(name))
-#define AN_DESTINATION(cls) \
- m_composer->setDestination(new cls)
-#define AN_ANALYSER(cls) \
- m_composer->setAnalyser(AnalyserPtr(new cls))
-#define AN_SET_ANALYSER(cls) \
- m_composer->setAnalyser(AnalyserPtr(cls))
-#define HAS_PARAM (flags & kHasParam)
-#define DEFAULT_CONTROLWORD processDefault(cw, flags, param)
-#define DUMMY 1 == 1
-#define NUM_ATTR(x) formatInt(x)
-#define DO_EXTRAS() (m_composer->getOptions().extras)
-
-/* ----------------------------------------------------------------------------------
- * BASE ANALYSER
- */
-
-bool XmlComposer::BaseAnalyser::processDefault(const string& cw, int flags, int param)
-{
- // Unicode blocks go to a special analyser
- if(cw == "upr")
- {
- AnalyserPtr analy = m_composer->getAnalyser();
- ASSERT(analy != NULL);
- AN_SET_ANALYSER(new Upr(analy));
- return true;
- }
-
- return false;
-}
-
-void XmlComposer::BaseAnalyser::applyParaFormatting(RtfFormatting* format,
- DOM::Element& el)
-{
- if(format == NULL)
- format = &(m_composer->getTextFormatting());
-
- wstring fix = kValPara;
-
- // Is it a list?
- int list = format->paraList();
- if(list != -1)
- el.setAttribute(kAtList, NUM_ATTR(list));
- else
- el.removeAttribute(kAtList);
-
- // Is it a cell?
- if(format->paraInTable())
- el.setAttribute(kAtCell, L"1");
- else
- el.removeAttribute(kAtCell);
-
- // Paragraph styles
- int style = format->paraStyle();
- if(style != -1)
- el.setAttribute(kElStyle, NUM_ATTR(style));
- else
- el.removeAttribute(kElStyle);
-
- // These fix elements are later picked up in XmlFixups::fixBlocks
- el.setAttribute(kAtFix, fix);
-}
-
-DOM::Element XmlComposer::BaseAnalyser::getCurrentBlock()
-{
- DOM::Node node = m_composer->getElement();
-
- if(node.hasChildNodes())
- node = node.getLastChild();
-
- return DOMHelpers::getPriorElement(node, kElBlock);
-}
-
-bool XmlComposer::BaseAnalyser::processTextContent(const string& cw, int flags, int param)
-{
- DOM::Element el;
- bool process = false;
-
- RtfFormatting& format = m_composer->getTextFormatting();
-
- // New paragraph
- if(cw == "par")
- {
- el = getCurrentBlock();
- if(el != NULL)
- applyParaFormatting(&format, el);
-
- el = m_composer->createElement(kElBlock);
- applyParaFormatting(&format, el);
- }
-
- // Cells (used later in applyParaFormatting)
- else if(cw == "intbl")
- format.paraSetTable(true);
-
- // Start of a cell
- else if(cw == "cell")
- {
- el = getCurrentBlock();
- if(el != NULL)
- applyParaFormatting(&format, el);
-
- el = m_composer->createElement(kElCell);
- m_composer->pushElement(el);
- m_composer->popElement();
- el = m_composer->createElement(kElBlock);
- applyParaFormatting(&format, el);
- }
-
- // Start of a row
- else if(cw == "trowd")
- el = m_composer->createElement(kElRow);
-
- // A tab
- else if(cw == "tab")
- el = m_composer->createElement(kElTab);
-
- // A section break
- else if(cw == "sect")
- el = m_composer->createElement(kElSect);
-
- // A page break
- else if(cw == "page")
- el = m_composer->createElement(kElPage);
-
- // A paragraph style
- else if(cw == "s" && HAS_PARAM)
- format.paraSetStyle(param);
-
- // A line break
- else if(cw == "line")
- el = m_composer->createElement(kElLine);
-
- // A page header (not implemented)
- else if(cw == "header")
- AN_ANALYSER(Skip);
-
- // A page footer (not implemented)
- else if(cw == "footer")
- AN_ANALYSER(Skip);
-
- // A bookmark (not implemented)
- else if(cw == "bkmkstart")
- AN_ANALYSER(Skip);
-
- // List text (not implemented)
- else if(cw == "listtext")
- AN_ANALYSER(Skip);
-
- // Set list style (used in applyFormatting)
- else if(cw == "ls" && HAS_PARAM)
- format.paraSetList(param);
-
- if(el != NULL)
- {
- // This ensures that our content destination is open and ready
- DestinationPtr dest = m_composer->getDestination();
- ASSERT(dest != NULL);
- dest->charData(kValNull);
-
- m_composer->pushElement(el);
- m_composer->popElement();
- }
-
- return (el != NULL) || process;
-}
-
-bool XmlComposer::BaseAnalyser::processTextFormatting(const string& cw, int flags,
- int param, RtfFormatting& format)
-{
- bool on = true;
- if(flags & HAS_PARAM && param == 0)
- on = false;
-
- // Clears all paragraph formatting
- if(cw == "pard")
- {
- format.resetPara();
- // applyParaFormatting();
- }
-
- // Rest are pretty much self-explanatory
- else if(cw == "plain")
- format.resetText();
- else if(cw == "b")
- format.textSetBold(on);
- else if(cw == "i")
- format.textSetItalic(on);
- else if(cw == "v")
- format.textSetHidden(on);
- else if(cw == "ul")
- format.textSetUnderline(on);
- else if(cw == "super")
- format.textSetSuScript(RtfFormatting::SUPERSCRIPT);
- else if(cw == "sub")
- format.textSetSuScript(RtfFormatting::SUBSCRIPT);
- else if(cw == "cf" && HAS_PARAM)
- format.textSetColor(param);
- else if(cw == "f" && HAS_PARAM)
- format.textSetFont(param);
- else if(cw == "fs" && HAS_PARAM)
- format.textSetFontSize(param);
- else
- return false;
-
- return true;
-}
-
-bool XmlComposer::BaseAnalyser::processTextFormatting(const string& cw, int flags, int param)
-{
- return processTextFormatting(cw, flags, param, m_composer->getTextFormatting());
-}
-
-bool XmlComposer::BaseAnalyser::processTextAutoContent(const string& cw, int flags, int param)
-{
- DestinationPtr dest = m_composer->getDestination();
- ASSERT(dest != NULL);
- dest->charData(kValNull);
-
- // Auto generated content
-
- if(cw == "chftn")
- {
- // Footnote auto numbering
- int ac = m_composer->getAutoCount(AUTOCOUNT_FOOTNOTE);
-
- AN_ELEMENT(kElRef);
- AN_ATTRIBUTE(kAtType, kValFootNote);
- AN_ATTRIBUTE(kAtTo, ac);
-
- // Only output the actual link text in this case
- if(DO_EXTRAS())
- dest->charData(formatInt(ac));
-
- AN_POP_ELEMENT();
- return true;
- }
-
- return false;
-}
-
-/* ----------------------------------------------------------------------------------
- * ANALYSER/DESTINATION DEFINITIONS
- */
-
-#define ON_INITIALIZE(cls) \
- void XmlComposer::cls::initialize()
-#define ON_CONTROLWORD(cls) \
- void XmlComposer::cls::controlWord(const string& cw, int flags, int param)
-#define ON_CHARDATA(cls) \
- void XmlComposer::cls::charData(wstring data)
-#define ON_GROUPSTART(cls) \
- void XmlComposer::cls::groupStart()
-#define ON_GROUPEND(cls) \
- void XmlComposer::cls::groupEnd()
-#define ON_DONE(cls) \
- void XmlComposer::cls::done()
-
-
-// Skip Analyser --------------------------------------------------------------------
-
-ON_INITIALIZE(Skip)
- { AN_DESTINATION(Null); }
-
-ON_GROUPSTART(Skip)
- { AN_ANALYSER(Skip); }
-
-
-// Upr Analyser ---------------------------------------------------------------------
-
-XmlComposer::Upr::Upr(AnalyserPtr prv)
-{
- ASSERT(prv);
- prev = prv;
-}
-
-ON_GROUPSTART(Upr)
-{
- AN_ANALYSER(Skip);
-}
-
-ON_GROUPEND(Upr)
-{
- ASSERT(prev);
- m_composer->setAnalyser(prev);
- prev = NULL;
-}
-
-
-// Stylesheet Analyser --------------------------------------------------------------
-
-ON_INITIALIZE(Stylesheet)
-{
- AN_TOP_ELEMENT(kElStylesheet);
-}
-
-ON_GROUPSTART(Stylesheet)
-{
- // Each group should be a style
- AN_ANALYSER(Style);
-
- // Without any character data
- AN_DESTINATION(Null);
-}
-
-
-// Stylesheet Style Analyser --------------------------------------------------------
-
-ON_INITIALIZE(Style)
-{
- // Were not sure if this element is really something
- // so we can't always create
- haveStyle = false;
-}
-
-ON_CONTROLWORD(Style)
-{
- // Get the style id
- if(flags & kAsterisk)
- {
- AN_ANALYSER(Skip);
- return;
- }
-
- // Create the style tag if necessary
- if(!haveStyle)
- {
- AN_ELEMENT(kElStyle);
- AN_DESTINATION_ATTR(kAtName);
- haveStyle = true;
- }
-
- // The style id
- if(cw == "s" && flags & kHasParam)
- {
- AN_ATTRIBUTE(kAtId, param);
- }
-
- // Otherwise get as much formatting out of the tag as possible
- else if(processTextFormatting(cw, flags, param))
- DUMMY;
-
- else
- DEFAULT_CONTROLWORD;
-}
-
-ON_GROUPSTART(Style)
-{
- AN_ANALYSER(Skip);
-}
-
-ON_GROUPEND(Style)
-{
- RtfFormatting& props = m_composer->getTextFormatting();
-
- // Dig out all the formatting attributes
- if(props.textIsBold())
- AN_ATTRIBUTE(kAtBold, kValTrue);
- if(props.textIsHidden())
- AN_ATTRIBUTE(kAtHidden, kValTrue);
- if(props.textIsItalic())
- AN_ATTRIBUTE(kAtItalic, kValTrue);
- if(props.textIsStrike())
- AN_ATTRIBUTE(kAtStrike, kValTrue);
- if(props.textIsUnderline())
- AN_ATTRIBUTE(kAtUnderline, kValTrue);
-
- // TODO: Do fonts and colors here
-}
-
-
-// Font Table Analyser --------------------------------------------------------------
-
-ON_INITIALIZE(FontTable)
-{
- AN_TOP_ELEMENT(kElFontTable);
- AN_DESTINATION(Null);
-}
-
-ON_GROUPSTART(FontTable)
-{
- // Each group should be a font
- AN_ANALYSER(Font);
-}
-
-ON_DONE(FontTable)
-{
- DOM::Element deffont = m_composer->createElement(kElFont);
-
- // Default font is always the first in the list
- deffont->setAttribute(kAtId, kValZero);
-
- // Default size is always 12 pt
- deffont->setAttribute(kAtSize, L"12");
-
- // TODO: Is this correct?
- deffont->setAttribute(kAtColor, kValZero);
-
- m_composer->addDocumentOption(deffont);
-}
-
-// Font Analyser --------------------------------------------------------------------
-
-ON_INITIALIZE(Font)
-{
- AN_ELEMENT(kElFontDef);
- AN_DESTINATION_ATTR(kAtName);
-}
-
-ON_CONTROLWORD(Font)
-{
- // The font id
- if(cw == "f" && flags & kHasParam)
- AN_ATTRIBUTE(kAtId, param);
-
- else
- DEFAULT_CONTROLWORD;
-}
-
-ON_GROUPSTART(Font)
-{
- AN_ANALYSER(Skip);
-}
-
-
-// List Table Analyser --------------------------------------------------------------
-
-ON_INITIALIZE(ListTable)
-{
- AN_TOP_ELEMENT(kElListtable);
-}
-
-ON_GROUPSTART(ListTable)
-{
- // Everything in here should be a list
- AN_ANALYSER(List);
-
- // Content doesn't matter
- AN_DESTINATION(Null);
-}
-
-
-// List (in List Table) Analyser ----------------------------------------------------
-
-ON_INITIALIZE(List)
-{
- // Create a default element
- AN_ELEMENT(kElListdef);
-
- if(DO_EXTRAS())
- AN_ATTRIBUTE(kAtType, kValDisc);
-
- AN_ATTRIBUTE(kAtOrdered, L"0");
- levelsSeen = 0;
-}
-
-ON_CONTROLWORD(List)
-{
- // The name
- if(cw == "listname")
- AN_DESTINATION_ATTR(kAtName);
-
- // The list id
- else if(cw == "listid" && HAS_PARAM)
- AN_ATTRIBUTE(kAtId, param);
-
- // We let listlevel in here too
- else if(cw == "levelstartat" && HAS_PARAM)
- AN_ATTRIBUTE(kAtStart, param);
-
- // The list type
- else if(cw == "levelnfc" && HAS_PARAM)
- {
- if(DO_EXTRAS())
- {
- switch(param)
- {
- case 0: // 1, 2, 3
- case 5: // 1st, 2nd, 3rd
- case 6: // One, Two, Three
- case 7: // First, Second, Third
- case 22: // 01, 02, 03
- AN_ATTRIBUTE(kAtType, kValArabic);
- break;
- case 1: // I, II, III
- AN_ATTRIBUTE(kAtType, kValUpperRoman);
- break;
- case 2: // i, ii, iii
- AN_ATTRIBUTE(kAtType, kValLowerRoman);
- break;
- case 3: // A, B, C
- AN_ATTRIBUTE(kAtType, kValUpperAlpha);
- break;
- case 4: // a, b, c
- AN_ATTRIBUTE(kAtType, kValLowerAlpha);
- break;
- default:
- AN_ATTRIBUTE(kAtType, kValDisc);
- break;
- }
- }
-
- switch(param)
- {
- case 0: case 5: case 6: case 7: case 22:
- case 1: case 2: case 3: case 4:
- AN_ATTRIBUTE(kAtOrdered, L"1");
- break;
- default:
- AN_ATTRIBUTE(kAtOrdered, L"0");
- }
- }
-
- else
- DEFAULT_CONTROLWORD;
-}
-
-ON_GROUPSTART(List)
-{
- // Skip internal groups and content
-
- if(levelsSeen > 0)
- AN_ANALYSER(Skip);
-
- levelsSeen++;
-}
-
-
-// The List Override Table ----------------------------------------------------------
-
-ON_INITIALIZE(ListOverrideTable)
-{
- // Get all of the current lists
- DOM::Document document = m_composer->getDocument();
- lists = document.getElementsByTagName(kElListdef);
- curList = NULL;
- lsId = -1;
-}
-
-ON_GROUPSTART(ListOverrideTable)
-{
- // Content doesn't matter
- AN_DESTINATION(Null);
-}
-
-ON_CONTROLWORD(ListOverrideTable)
-{
- // New list override clear
- if(cw == "listoverride")
- curList = NULL;
-
- // List id for current listoverride
- else if(cw == "listid" && HAS_PARAM)
- {
- wstring id = formatInt(param);
-
- if(lists != NULL)
- {
- // Find the list in question
- for(int i = 0; i < lists->getLength(); i++)
- {
- DOM::Node node = lists->item(i);
- if(node != NULL && node.getNodeType() == DOM::Node::ELEMENT_NODE)
- {
- DOM::Element element = (DOM::Element&)node;
- if(element.getAttribute(kAtId) == id)
- {
- curList = element;
- break;
- }
- }
- }
- }
- }
-
- // The actual list code
- else if(cw == "ls" && HAS_PARAM)
- lsId = param;
-
- // Override the starting level for the node
- else if(cw == "levelstartat" && HAS_PARAM)
- {
- if(curList != NULL)
- curList.setAttribute(kAtStart, NUM_ATTR(param));
- }
-
- else
- DEFAULT_CONTROLWORD;
-
-
- // Okay before any overrides take effect we need to duplicate
- // the list node for overriding, using the 'listid' and 'ls' we gathered
- if(curList != NULL && lsId != -1)
- {
- DOM::Element parent = (const DOM::Element&)curList.getParentNode();
- if(parent != NULL)
- {
- curList = (const DOM::Element&)curList.cloneNode(true);
- if(curList != NULL)
- {
- parent.appendChild(curList);
- curList.setAttribute(kAtId, NUM_ATTR(lsId));
- }
- }
-
- lsId = -1;
- }
-
-}
-
-
-// Info Block Analyser --------------------------------------------------------------
-
-ON_INITIALIZE(Info)
-{
- // Create a new element
- AN_TOP_ELEMENT(kElInfo);
- AN_DESTINATION(Null);
-}
-
-ON_CONTROLWORD(Info)
-{
- if(cw == "title")
- {
- AN_ELEMENT(kElTitle);
- AN_DESTINATION(Raw);
- }
-
- else if(cw == "author")
- {
- AN_ELEMENT(kElAuthor);
- AN_DESTINATION(Raw);
- }
-
- else if(cw == "operator")
- {
- AN_ELEMENT(kElOperator);
- AN_DESTINATION(Raw);
- }
-
- else if(flags & kAsterisk)
- AN_ANALYSER(Skip);
-
- else
- DEFAULT_CONTROLWORD;
-}
-
-
-// Root Analyser --------------------------------------------------------------------
-
-ON_INITIALIZE(Root)
-{
-
-}
-
-ON_CONTROLWORD(Root)
-{
- // All the main RTF sections
- if(cw == "stylesheet")
- AN_ANALYSER(Stylesheet);
- else if(cw == "listtable")
- AN_ANALYSER(ListTable);
- else if(cw == "listoverridetable")
- AN_ANALYSER(ListOverrideTable);
- else if(cw == "info")
- AN_ANALYSER(Info);
- else if(cw == "fonttbl")
- {
- if(DO_EXTRAS())
- AN_ANALYSER(FontTable);
- else
- AN_ANALYSER(Skip);
- }
- else if(cw == "colortbl")
- AN_ANALYSER(Skip);
- else if(cw == "footnote")
- AN_ANALYSER(FootNote);
- else if(cw == "pict")
- {
- AN_ANALYSER(Skip);
- AN_DESTINATION(Null);
- }
- else if(flags & kAsterisk)
- AN_ANALYSER(Skip);
- else if(processTextContent(cw, flags, param))
- DUMMY;
- else if(processTextAutoContent(cw, flags, param))
- DUMMY;
- else if(processTextFormatting(cw, flags, param))
- DUMMY;
- else
- DEFAULT_CONTROLWORD;
-}
-
-
-// Content Destination --------------------------------------------------------------
-
-ON_INITIALIZE(Content)
-{
- parent = m_composer->getElement();
- created = false;
-}
-
-ON_CHARDATA(Content)
-{
- // Create the first time we get content
- if(!created)
- {
- DOM::Element dest = m_composer->createElement(kElDest);
- parent.appendChild(dest);
- m_composer->replaceElement(dest);
-
- DOM::Element el = m_composer->createElement(kElBlock);
- m_composer->pushElement(el);
- m_composer->popElement();
-
- created = true;
- }
-
- if(data.length() == 0)
- return;
-
- int elements = 0;
- RtfFormatting& format = m_composer->getTextFormatting();
-
- // Extra elements written out here are consolidated in
- // XmlFixups::combineDuplicates
-
- // Handle fonts etc...
- if(DO_EXTRAS())
- {
- int font = format.textFont();
- int fontsize = format.textFontSize();
-
- if(font != -1 || fontsize != -1)
- {
- AN_ELEMENT(kElFont);
-
- if(font != -1)
- AN_ATTRIBUTE(kAtName, font);
-
- if(fontsize != -1)
- {
- // Little hack for half point sizes
- wstring size = NUM_ATTR(fontsize / 2);
- if(fontsize % 2)
- size.append(L".5");
-
- AN_ATTRIBUTE(kAtSize, size);
- }
-
- if(format.textColor() != -1)
- AN_ATTRIBUTE(kAtColor, format.textColor());
-
- elements++;
- }
- }
-
- // Now do text Properties if necessary
-
- if(format.textIsBold())
- {
- AN_ELEMENT(kElB);
- elements++;
- }
-
- if(format.textIsHidden())
- {
- AN_ELEMENT(kElHide);
- elements++;
- }
-
- if(format.textIsItalic())
- {
- AN_ELEMENT(kElI);
- elements++;
- }
-
- if(format.textIsStrike())
- {
- AN_ELEMENT(kElStrike);
- elements++;
- }
-
- if(format.textIsUnderline())
- {
- AN_ELEMENT(kElU);
- elements++;
- }
-
- if(format.textSuScript() == RtfFormatting::SUPERSCRIPT)
- {
- AN_ELEMENT(kElSuper);
- elements++;
- }
-
- if(format.textSuScript() == RtfFormatting::SUBSCRIPT)
- {
- AN_ELEMENT(kElSub);
- elements++;
- }
-
- // Write the data to the element
- m_composer->getElement().appendChild(
- m_composer->getDocument().createTextNode(data));
-
- // Now drop out of all the above formatting
- while(elements-- > 0)
- AN_POP_ELEMENT();
-}
-
-
-// FootNote Analyser ----------------------------------------------------------------
-
-ON_INITIALIZE(FootNote)
-{
- int ac = m_composer->getAutoCount(AUTOCOUNT_FOOTNOTE);
-
- AN_ELEMENT(kElFootNote);
- AN_ATTRIBUTE(kAtId, ac);
- AN_DESTINATION(Content);
-}
-
-ON_CONTROLWORD(FootNote)
-{
- // Inside foot notes there's no link to the foot note
- if(cw == "chftn")
- {
- // Only put actual text when in extras mode
- if(DO_EXTRAS())
- {
- DestinationPtr dest = m_composer->getDestination();
- ASSERT(dest != NULL);
- int ac = m_composer->getAutoCount(AUTOCOUNT_FOOTNOTE);
- dest->charData(formatInt(ac));
- }
-
- return;
- }
-
- // Process text content in the foot note
- else if(processTextContent(cw, flags, param))
- DUMMY;
- else if(processTextAutoContent(cw, flags, param))
- DUMMY;
- else if(processTextFormatting(cw, flags, param))
- DUMMY;
- else
- DEFAULT_CONTROLWORD;
-}
-
-ON_DONE(FootNote)
-{
- m_composer->incrementAutoCount(AUTOCOUNT_FOOTNOTE);
-}
-
-
-// Raw Destination ------------------------------------------------------------------
-
-ON_CHARDATA(Raw)
-{
- // Write the data to the element
- m_composer->getElement().appendChild(
- m_composer->getDocument().createTextNode(data));
-}
-
-
-// Attribute Destination ------------------------------------------------------------
-
-ON_INITIALIZE(Attribute)
-{
- element = m_composer->getElement();
- ASSERT(element != NULL);
-}
-
-ON_CHARDATA(Attribute)
-{
- // Get the current value
- wstring cur = element.getAttribute(name);
-
- if(data.at(data.size() - 1) == L';')
- data.resize(data.size() - 1);
-
- // Append data
- cur.append(data);
-
- // Write it back
- element.setAttribute(name, cur);
-}
-
diff --git a/src/xmlcomposer.h b/src/xmlcomposer.h
deleted file mode 100644
index 41aad0e..0000000
--- a/src/xmlcomposer.h
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-#ifndef __XMLCOMPOSER_H__
-#define __XMLCOMPOSER_H__
-
-#include "levelhandler.h"
-
-struct XmlComposerOptions
-{
- XmlComposerOptions()
- { memset(this, 0, sizeof(*this)); }
-
- bool extras;
-};
-
-/*
- * XmlComposer
- *
- * This is where the RTF gets initially converted to XML. RtfParser sends
- * notifications to this class's RtfHandler interface. It forwards them to
- * the current analysers and destinations which produce XML content.
- * (see xmlcomposehelpers.h)
- *
- * Not all conversion is completed here. Because RTF is so very wierd we
- * have to run lots of fixups are run in endDocument (see rtffixups.h)
- */
-class XmlComposer :
- public LevelHandler
-{
-public:
- XmlComposer(const XmlComposerOptions& options);
- virtual ~XmlComposer();
-
- // Handler Overrides
- virtual void startDocument(RtfParser* reader);
- virtual void endDocument();
- virtual void controlWord(const string& cw, int flags, int param);
- virtual void groupStart();
- virtual void groupEnd();
- virtual void charData(wstring data);
-
- // Create an XML element with given name
- DOM::Element createElement(const string& name);
-
- // Push an XML element on the current level
- void pushElement(const DOM::Element& element);
-
- // Push an element at the top of the document
- void pushTopElement(const DOM::Element& element);
-
- // Replace current XML element with given element
- void replaceElement(const DOM::Element& element);
-
- // Move up one XML element level without changing RTF level
- DOM::Element popElement();
-
- // Set attributes on the current XML Element
- void setAttribute(const string& name, const wstring& value, DOM::Element el = DOM::Element());
- void setAttribute(const string& name, int value, DOM::Element el = DOM::Element());
-
- // The current analyser in use
- AnalyserPtr getAnalyser();
- void setAnalyser(AnalyserPtr analy);
-
- // The current destination in use
- DestinationPtr getDestination();
- void setDestination(DestinationPtr dest);
-
- // Replace the current destination (sets level deep)
- DestinationPtr replaceDestination(DestinationPtr dest);
-
-
- // The types of auto numbering
- enum
- {
- AUTOCOUNT_FOOTNOTE,
- AUTOCOUNT_MAX
- };
-
- // Functions for RTF auto numbering
- int getAutoCount(int type);
- void incrementAutoCount(int type);
-
- // Add a document option to the option block
- void addDocumentOption(DOM::Element& option);
-
- // Get the current formatting options
- RtfFormatting& getTextFormatting();
-
- DOM::Document getDocument()
- { return m_document; }
-
- const XmlComposerOptions& getOptions()
- { return m_options; }
-
-
-// LevelHandler override
-protected:
- virtual void clear();
-
-
-// Data
-protected:
- DOM::DOMImplementation m_impl; // For creating the document
- DOM::Document m_document; // The current document
- XmlComposerOptions m_options; // Configurable options for parsing
- int m_autocount[AUTOCOUNT_MAX]; // Auto counters for the document
- DOM::Element m_docOptions; // For storing document options
-
-// Sub classes
-protected:
-
- #define DESTINATION(cls) class cls : public Destination { public:
- #define END_DESTINATION };
- #define ANALYSER(cls) class cls : public BaseAnalyser { public:
- #define END_ANALYSER };
- #define DATA_PORTION protected:
- #define INITIALIZE virtual void initialize();
- #define CHARDATA virtual void charData(wstring data);
- #define CONTROLWORD virtual void controlWord(const string& cw, int flags, int param);
- #define GROUPSTART virtual void groupStart();
- #define GROUPEND virtual void groupEnd();
- #define DONE virtual void done();
-
- // Main destination for document character content
- DESTINATION(Content)
- INITIALIZE
- CHARDATA
- DATA_PORTION
- bool created;
- DOM::Element parent;
- END_DESTINATION
-
- // Discards character data
- DESTINATION(Null)
- END_DESTINATION
-
- // Copies raw character data to output
- DESTINATION(Raw)
- CHARDATA
- END_DESTINATION
-
- // Copies character data to an XML attribute
- DESTINATION(Attribute)
- Attribute(const string& nm) : name(nm) {}
- INITIALIZE
- CHARDATA
- DATA_PORTION
- string name;
- DOM::Element element;
- END_DESTINATION
-
-
- // Base class for analysers with some helper functions
- class BaseAnalyser :
- public Analyser
- {
- public:
- virtual void controlWord(const string& cw, int flags, int param)
- { processDefault(cw, flags, param); }
-
- protected:
- // Process a standard set of tags that can be found anywhere
- bool processDefault(const string& cw, int flags, int param);
-
- // Process text formatting tags
- bool processTextFormatting(const string& cw, int flags, int param, RtfFormatting& format);
- bool processTextFormatting(const string& cw, int flags, int param);
-
- // Creates 'fix' tags for paragraph formatting in element
- void applyParaFormatting(RtfFormatting* format, DOM::Element& el);
-
- // Process tags that are either text content, or change context
- bool processTextContent(const string& cw, int flags, int param);
-
- // Process tags that generate text content (like auto-numbering, fields)
- bool processTextAutoContent(const string& cw, int flags, int param);
-
- // Convenience function
- DOM::Element getCurrentBlock();
- };
-
-
- // Skip tags and groups
- ANALYSER(Skip)
- INITIALIZE
- GROUPSTART
- END_ANALYSER
-
- // Unicode block analyser
- ANALYSER(Upr)
- Upr(AnalyserPtr prv);
- GROUPSTART
- GROUPEND
- DATA_PORTION
- AnalyserPtr prev;
- END_ANALYSER
-
- // Handle Stylesheets
- ANALYSER(Stylesheet)
- INITIALIZE
- GROUPSTART
- END_ANALYSER
-
- // Handle a style in a stylesheet
- ANALYSER(Style)
- INITIALIZE
- CONTROLWORD
- GROUPSTART
- GROUPEND
- DATA_PORTION
- bool haveStyle;
- END_ANALYSER
-
- // Handle the Font Table
- ANALYSER(FontTable)
- INITIALIZE
- GROUPSTART
- DONE
- END_ANALYSER
-
- // Handle a Font in the Table
- ANALYSER(Font)
- INITIALIZE
- CONTROLWORD
- GROUPSTART
- END_ANALYSER
-
- // Handle the list definitions
- ANALYSER(ListTable)
- INITIALIZE
- GROUPSTART
- END_ANALYSER
-
- // Handle a list in the list definitions
- ANALYSER(List)
- INITIALIZE
- CONTROLWORD
- GROUPSTART
- DATA_PORTION
- int levelsSeen;
- END_ANALYSER
-
- // Handle list overrides
- ANALYSER(ListOverrideTable)
- INITIALIZE
- CONTROLWORD
- GROUPSTART
- DATA_PORTION
- DOM::NodeList lists;
- int lsId;
- DOM::Element curList;
- END_ANALYSER
-
- // Creates the info block
- ANALYSER(Info)
- INITIALIZE
- CONTROLWORD
- END_ANALYSER
-
- // The main root analyser
- ANALYSER(Root)
- INITIALIZE
- CONTROLWORD
- END_ANALYSER
-
- // Handles footnotes
- ANALYSER(FootNote)
- INITIALIZE
- CONTROLWORD
- DONE
- END_ANALYSER
-};
-
-#endif // __XMLCOMPOSER_H__
diff --git a/src/xmlfixups.cpp b/src/xmlfixups.cpp
deleted file mode 100644
index 3b56f6b..0000000
--- a/src/xmlfixups.cpp
+++ /dev/null
@@ -1,794 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-#include "usuals.h"
-#include "xmlfixups.h"
-#include "domhelpers.h"
-#include "tags.h"
-
-static const char* kNoDuplicates[] =
- { kElB, kElU, kElI, kElFont, kElHide, kElSuper, kElSub, NULL };
-
-static const char* kRequireAttrs[] =
- { kElFont, NULL };
-
-static const char* kRemoveTags[] =
- { kElDest, kElListdef, kElListtable, kElFontTable, kElFontDef, NULL };
-
-static const char* kRemoveEmpty[] =
- { kElOptions, kElList, NULL };
-
-static const char* kBlockTags[] =
- { kElTable, kElPara, NULL };
-
-static const char* kHideList[] =
- { kAtId, kAtList, NULL };
-
-static const char* kConsolidateEnd[] =
- { kElFootNote, NULL };
-
-static const char* kConsolidateStart[] =
- { kElStylesheet, kElInfo, NULL };
-
-void loadStringSet(StringSet& set, const char** strings)
-{
- while(*strings)
- set.insert(string(*(strings++)));
-}
-
-XmlFixups::XmlFixups()
-{
- loadStringSet(m_duplicates, kNoDuplicates);
- loadStringSet(m_removes, kRemoveTags);
- loadStringSet(m_removeEmpty, kRemoveEmpty);
- loadStringSet(m_requireAttrs, kRequireAttrs);
- loadStringSet(m_consolidateStart, kConsolidateStart);
- loadStringSet(m_consolidateEnd, kConsolidateEnd);
-}
-
-bool XmlFixups::breakElement(const DOM::Element& el, const string& contain)
-{
- ASSERT(el != NULL);
-
- DOM::Element parent = (const DOM::Element&)el.getParentNode();
- DOM::Element grandparent;
-
- string s = el.getNodeName();
- s = parent.getNodeName();
-
- // Get the parent node
- if(parent != NULL)
- grandparent = (const DOM::Element&)parent.getParentNode();
-
- // Make sure we have something to work with before continuing
- if(grandparent == NULL || parent == NULL ||
- DOMHelpers::isElement(parent, contain))
- return true;
-
- DOM::Node e;
-
- // Check to see if this is the first node in the parent.
- // If so then just move out to before
- if(el.getPreviousSibling() == NULL)
- {
- e = grandparent.insertBefore(parent.removeChild(el), parent);
- }
-
-
- // Check to see if this is the last node in the parent.
- // If so then just move out to after the parent
- else if(el.getNextSibling() == NULL)
- {
- DOM::Node next = parent.getNextSibling();
- if(next == NULL)
- e = grandparent.appendChild(parent.removeChild(el));
- else
- e = grandparent.insertBefore(parent.removeChild(el), next);
- }
-
-
- // Otherwise it's in the middle so split the parent
- // element etc...
- else
- {
- // Clone it but not deep
- DOM::Element parent2 = (const DOM::Element&)parent.cloneNode(false);
-
- if(parent2 == NULL)
- return false;
-
- // Flag that tells us whether we moved anything up to parent
- bool moved = false;
-
- // Now move all nodes after this one to the second parent.
- while((e = el.getNextSibling()) != NULL)
- {
- parent2.appendChild(parent.removeChild(e));
- moved = true;
- }
-
- // Remove the element from it's parent
- e = parent.removeChild(el);
-
- // Okay now we move the paragraph up to the parent
- DOMHelpers::insertAfter(grandparent, e, parent);
- if(moved)
- DOMHelpers::insertAfter(grandparent, parent2, e);
- }
-
- // Now call it again with the paragraph in the new position
- // until everything's cut through!
- return breakElement((DOM::Element&)e, contain);
-}
-
-void XmlFixups::breakBlocks(DOM::Document& document)
-{
- // First break out all the paragraphs to the destination level
- DOM::NodeList blocks = document.getElementsByTagName(kElBlock);
- if(blocks != NULL)
- {
- for(int i = 0; i < blocks->getLength(); i++)
- {
- DOM::Element block = (const DOM::Element&)blocks->item(i);
-
- // If it's the single closed style para then break it
- if(block != NULL && !block.hasChildNodes())
- breakElement(block, kElDest);
- }
- }
-
-
- // Now group stuff in destinations into paras or other blocks
- DOM::NodeList destinations = document.getElementsByTagName(kElDest);
- if(destinations != NULL)
- {
- for(int i = 0; i < destinations->getLength(); i++)
- {
- DOM::Element dest = (const DOM::Element&)destinations->item(i);
-
- // Sanity Check
- if(dest == NULL || !dest.hasChildNodes())
- continue;
-
- // Go through the children of this destination
- DOM::Node child = dest.getFirstChild();
-
- DOM::Element block;
-
- while(child != NULL)
- {
- // If it's a block
- if(DOMHelpers::isElement(child, kElBlock))
- {
- block = (DOM::Element&)child;
- child = child.getNextSibling();
- continue;
- }
-
- // If it's already a real block element
- for(const char** t = kBlockTags; *t != NULL; t++)
- {
- if(DOMHelpers::isElement(child, *t))
- {
- block = NULL;
- break;
- }
- }
-
- // If there's a block then add to it
- if(block != NULL)
- {
- block.appendChild(dest.removeChild(child));
- child = block;
- }
-
- child = child.getNextSibling();
- }
- }
- }
-}
-
-void XmlFixups::wrapTags(DOM::Document& doc, const string& tagName,
- const string& wrapName)
-{
- DOM::NodeList tags = doc.getElementsByTagName(tagName);
- if(tags != NULL)
- {
- for(int i = 0; i < tags->getLength(); i++)
- {
- DOM::Element tag = (const DOM::Element&)tags->item(i);
-
- DOM::Element wrap = doc.createElement(wrapName);
- while(tag.hasChildNodes())
- wrap.appendChild(tag.removeChild(tag.getFirstChild()));
-
- tag.appendChild(wrap);
- }
- }
-}
-
-void XmlFixups::breakTags(DOM::Document& doc, const string& parentName,
- const string& tagName)
-{
- DOM::NodeList parents = doc.getElementsByTagName(parentName);
- if(parents != NULL)
- {
- for(int i = 0; i < parents->getLength(); i++)
- {
- DOM::Element parent = (const DOM::Element&)parents->item(i);
-
- if(!parent.hasChildNodes())
- continue;
-
- // First perform the breaks
- DOM::NodeList tags = parent.getElementsByTagName(tagName);
- if(tags != NULL)
- {
- for(int i = 0; i < tags->getLength(); i++)
- breakElement((const DOM::Element&)tags->item(i), parentName);
- }
-
- DOM::Node tag = doc.createElement(tagName);
- parent.insertBefore(tag, parent.getFirstChild());
-
- DOM::Node child = tag;
-
- while(child != NULL && (child = child.getNextSibling()) != NULL)
- {
- if(DOMHelpers::isElement(child, kElBlock))
- {
- DOM::Node next = child.getNextSibling();
- if(next == NULL)
- {
- parent.removeChild(child);
- continue;
- }
-
- if(DOMHelpers::isElement(next, tagName))
- {
- DOM::Node twodown = next.getNextSibling();
- if(!DOMHelpers::isElement(twodown, kElBlock))
- {
- child = parent.insertBefore(parent.removeChild(next), child);
- }
- else
- {
- parent.removeChild(child);
- child = next;
- }
- }
- }
-
- if(DOMHelpers::isElement(child, tagName))
- {
- if(!tag.hasChildNodes())
- parent.removeChild(tag);
- tag = child;
- }
- else
- {
- tag.appendChild(parent.removeChild(child));
- child = tag;
- }
- }
-
- if(!tag.hasChildNodes())
- parent.removeChild(tag);
- }
- }
-
- DOM::NodeList tags = doc.getElementsByTagName(tagName);
- if(tags != NULL)
- {
- for(int i = 0; i < tags->getLength(); i++)
- {
- DOM::Element tag = (const DOM::Element&)tags->item(i);
- DOM::Node parent = tag.getParentNode();
-
- if(parent != NULL && !DOMHelpers::isElement(parent, parentName))
- parent.removeChild(tag);
- }
- }
-}
-
-void XmlFixups::breakLists(DOM::Document& doc)
-{
- DOM::NodeList destinations = doc.getElementsByTagName(kElDest);
- if(destinations != NULL)
- {
- for(int i = 0; i < destinations->getLength(); i++)
- {
- DOM::Element dest = (const DOM::Element&)destinations->item(i);
-
- // Sanity Check
- if(dest == NULL)
- continue;
-
- // Go through the children of this destination
- DOM::Node child = dest.getFirstChild();
-
- DOM::Element list;
- DOM::Element e;
-
- wstring previd;
-
- while(child != NULL)
- {
- // If it's a block ...
- if(DOMHelpers::isElement(child, kElBlock))
- {
- e = (DOM::Element&)child;
-
- // ... and has a list attribute
- wstring listid = e.getAttribute(kAtList);
- if(listid.length() > 0)
- {
- e.removeAttribute(kAtList);
-
- if(list == NULL || previd != listid)
- {
- list = doc.createElement(kElList);
- list.setAttribute(kAtList, listid);
- dest.insertBefore(list, child);
- previd = listid;
- }
- }
- else
- {
- list = NULL;
- previd.erase();
- }
- }
-
- // It's not a block
- if(list != NULL)
- {
- list.appendChild(dest.removeChild(child));
- child = list;
- }
-
- child = child.getNextSibling();
- }
- }
- }
-}
-
-void XmlFixups::runPassTwo(const DOM::Document& doc)
-{
- /*
- * Okay, this function is complicated and long. It was all broken up into
- * shorter functions previously but that sucked for efficiency. Basically
- * we want to iterate over the document as few times as possible and because
- * of that we combine all of that here.
- *
- * In this pass:
- * o Fix:
- * - font names
- * - style names
- * - list attributes
- * - block elements
- * o Consolidate certain tags to end of doc
- * o Consolidate certain tags to start of doc
- * o Combine duplicates of certain tags
- * o Remove certain tags
- * o Break out pages and sections
- */
-
- bool haveStyles = false;
- ElementTable styles;
-
- bool haveFonts = false;
- ElementTable fonts;
-
- bool haveLists = false;
- ElementTable lists;
-
- DOM::Element top = doc.getDocumentElement();
-
- NodeStack toStart; // Nodes that get moved to beginning of document
- NodeStack toEnd; // Nodes that get moved to the end of the document
-
- ElementIterator it(top);
- ElementIterator end;
-
- DOM::Element el;
-
- for( ; it != end; ++it)
- {
- el = *it;
-
- // Mark each node as we've seen it so we don't
- // do a given element twice
- if((int)el.getUserData() == PASS_TWO)
- continue;
-
- el.setUserData((void*)PASS_TWO);
- string name = el.getNodeName();
-
- // Get stylesheet block
- if(name == kElStylesheet)
- {
- // Load the styles into a id mapped table
- styles.load(el, kElStyle);
-
- if(!styles.empty())
- {
- styles.removeIds();
- haveStyles = true;
- }
- }
-
- // The Font Table
- else if(name == kElFontTable)
- {
- // Load the fonts into an id mapped table
- fonts.load(el, kElFontDef);
-
- if(!fonts.empty())
- {
- fonts.removeIds();
- haveFonts = true;
- }
- }
-
- // Get the list definition block
- else if(name == kElListtable)
- {
- // Load the lists into an id mapped table
- lists.load(el, kElListdef);
-
- if(!lists.empty())
- {
- lists.removeIds();
- haveLists = true;
- }
- }
-
- else if(name == kElBlock)
- {
- // Change style attribute on blocks to name
- if(haveStyles && el.hasAttribute(kElStyle))
- {
- DOM::Element style = styles.get(el.getAttribute(kElStyle));
- if(style != NULL)
- el.setAttribute(kElStyle, style.getAttribute(kAtName));
- }
-
- /*
- * The below function call replaces the current element with another
- * new element. The new element still needs to be processed, so we
- * just backup one, and then short circuit the loop below.
- */
- --it;
-
- // Now fix the block itself
- fixBlock(doc, el);
-
- continue; // Current element no longer valid
- }
-
- // Change id attribute on fonts to name
- else if(haveFonts && name == kElFont)
- {
- if(el.hasAttribute(kAtId))
- {
- DOM::Element font = fonts.get(el.getAttribute(kAtId));
- if(font != NULL)
- el.setAttribute(kAtName, font.getAttribute(kAtName));
-
- el.removeAttribute(kAtId);
- }
- }
-
- // Copy list attributes onto the lists
- else if(haveLists && name == kElList)
- {
- if(el.hasAttribute(kAtList))
- {
- DOM::Element list = lists.get(el.getAttribute(kAtList));
- if(list != NULL)
- {
- // And copy all the attributes from the list definition to the list
- DOMHelpers::copyAttributes(list, el, kHideList);
- el.removeAttribute(kAtList);
- }
- }
- }
-
- // Break out pages and sections all the way to document
- if(name == kElPage || name == kElSect)
- {
- breakElement(el, kElDoc);
-
- /*
- * NOTE: The flow of the document is changed here. But the current
- * element is still in a valid place for iterating over the document
- * so we don't have to worry about it.
- */
- }
-
- // Tags that get removed but contents preserved. Also here are
- // tags that get removed if they have no attributes
- if(m_removes.find(name) != m_removes.end() ||
- (m_requireAttrs.find(name) != m_requireAttrs.end() && !el.hasAttributes()))
- {
- DOM::Node parent = el->getParentNode();
-
- if(parent != NULL)
- {
- /*
- * After the element is removed, the current element is no longer
- * valid for iterating over the document. In addition we insert
- * all the child nodes of the current element before it. We need
- * to be sure to iterate over these elements, and to do so we
- * decrement the iterator.
- */
- --it;
-
- while(el.hasChildNodes())
- parent.insertBefore(el.removeChild(el.getFirstChild()), el);
-
- parent.removeChild(el);
- continue; /* Current element doesn't need any more processing */
- }
- }
-
- // Tags that get removed when no child nodes exist
- if(m_removeEmpty.find(name) != m_removeEmpty.end() && !el.hasChildNodes())
- {
- DOM::Node parent = el->getParentNode();
-
- if(parent != NULL)
- {
- /*
- * After the element is removed, the current element is no longer
- * valid for iterating over the document. In addition we insert
- * all the child nodes of the current element before it. We need
- * to be sure to iterate over these elements, and to do so we
- * decrement the iterator.
- */
- --it;
-
- parent.removeChild(el);
- continue; /* Current element doesn't need any more processing */
- }
- }
-
- // Tags that need to get consolidated to start
- if(m_consolidateStart.find(name) != m_consolidateStart.end())
- toStart.push(el);
-
- // Tags that need to get consolidated to end
- else if(m_consolidateEnd.find(name) != m_consolidateEnd.end())
- toEnd.push(el);
-
-
- // Tags for which duplicates need to be combined
- if(m_duplicates.find(name) != m_duplicates.end())
- {
- DOM::Element parent = (const DOM::Element&)el.getParentNode();
- if(parent != NULL)
- {
- // Loop till we find no more of the same
- for(;;)
- {
- DOM::Node next = el.getNextSibling();
-
- if(next == NULL || next.getNodeType() != DOM::Node::ELEMENT_NODE)
- break;
-
- // If it's the same type of element ...
- if(!DOMHelpers::isEqualElement((DOM::Element&)next, el))
- break;
-
- // NOTE: Notice we do nothing with attributes. Currently
- // all elements in the duplicates list don't need that.
-
- while(next.hasChildNodes())
- el.appendChild(next.removeChild(next.getFirstChild()));
-
- // Remove duplicate node
- parent.removeChild(next);
- }
- }
- }
- }
-
- // Complete consolidation to front
- while(!toStart.empty())
- {
- DOM::Node node = toStart.top();
- DOM::Node parent = node.getParentNode();
- if(parent != NULL && DOMHelpers::hasAncestor(top, node))
- {
- // Remove it from it's child
- parent.removeChild(node);
-
- // And put at start of the document of the document
- top.insertBefore(node, top.getFirstChild());
- }
-
- toStart.pop();
- }
-
- // Complete consolidation to end
- while(!toEnd.empty())
- {
- DOM::Node node = toEnd.top();
- DOM::Node parent = node.getParentNode();
- if(parent != NULL && DOMHelpers::hasAncestor(top, node))
- {
- // Remove it from it's child
- parent.removeChild(node);
-
- // And put at end of the document of the document
- top.appendChild(node);
- }
-
- toEnd.pop();
- }
-
-}
-
-void XmlFixups::breakTables(DOM::Document& doc)
-{
- // Break rows out to destinations
- DOM::NodeList rows = doc.getElementsByTagName(kElRow);
- if(rows != NULL)
- {
- for(int i = 0; i < rows->getLength(); i++)
- {
- DOM::Element row = (const DOM::Element&)rows->item(i);
- DOM::Node parent = row.getParentNode();
-
- if(parent == NULL)
- continue;
-
- if(DOMHelpers::isElement(parent, kElBlock))
- {
- DOM::Node grandparent = parent.getParentNode();
-
- if(grandparent != NULL && !row.hasChildNodes())
- {
- if(row.getPreviousSibling() == NULL)
- grandparent.insertBefore(parent.removeChild(row), parent);
- else if(row.getNextSibling() == NULL)
- DOMHelpers::insertAfter(grandparent, parent.removeChild(row), parent);
- }
- }
-
- breakElement(row, kElDest);
- }
- }
-
- // Now group stuff in destinations into tables
- DOM::NodeList destinations = doc.getElementsByTagName(kElDest);
- if(destinations != NULL)
- {
- for(int i = 0; i < destinations->getLength(); i++)
- {
- DOM::Element dest = (const DOM::Element&)destinations->item(i);
-
- // Sanity Check
- if(dest == NULL)
- continue;
-
- // Go through the children of this destination
- DOM::Node child = dest.getFirstChild();
-
- DOM::Element table;
- DOM::Element e;
-
- while(child != NULL)
- {
- // If it's a block and has a cell attribute
- if(DOMHelpers::isElement(child, kElBlock))
- {
- e = (DOM::Element&)child;
-
- // if it has a cell attribute
- if(e.getAttribute(kAtCell).length() > 0)
- {
- e.removeAttribute(kAtCell);
-
- if(table == NULL)
- {
- table = doc.createElement(kElTable);
- dest.insertBefore(table, child);
- }
- }
- else
- {
- table = NULL;
- }
- }
-
- // It's not a block
- if(table != NULL)
- {
- table.appendChild(dest.removeChild(child));
- child = table;
- }
-
- child = child.getNextSibling();
- }
- }
- }
-}
-
-
-void XmlFixups::fixBlock(const DOM::Document& doc, DOM::Element& block)
-{
- // Okay now change blocks to whatever element they're supposed to be
- string fix;
- wstring val;
-
- DOM::Node parent = block.getParentNode();
-
- if(parent != NULL)
- {
- // Figure out what kind of element they want block fixed to
- val = block.getAttribute(kAtFix);
- if(val.length() > 0)
- block.removeAttribute(kAtFix);
-
- // BUG: Sablotron bug work around
- if(val.length() == 0)
- {
- val = block.getAttributeNS("", kAtFix);
- if(val.length() > 0)
- block.removeAttributeNS("", kAtFix);
- }
-
- if(val.length() > 0)
- DOM::transcode16to8(val, fix);
-
- if(fix.length() == 0)
- fix = kElPara;
-
- // Create duplicate of the 'fix' element
- DOM::Element el = doc.createElement(fix);
- DOMHelpers::copyAttributes(block, el, NULL);
-
- // Replace block with the given 'fix' element
- while(block.hasChildNodes())
- el.appendChild(block.removeChild(block.getFirstChild()));
-
- parent.replaceChild(el, block);
- }
-}
diff --git a/src/xmlfixups.h b/src/xmlfixups.h
deleted file mode 100644
index 99fe876..0000000
--- a/src/xmlfixups.h
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (c) 2004, Nate Nielsen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- *
- * CONTRIBUTORS
- * Nate Nielsen <nielsen@memberwebs.com>
- *
- */
-
-#ifndef __XMLFIXUPS_H__
-#define __XMLFIXUPS_H__
-
-#include "sablo.h"
-#include "domhelpers.h"
-
-/*
- * XmlFixups
- *
- * Because RTF is so 'different' (read: brain dead) we need to do all sorts
- * of antics to get it into a nice XML format. Some of the XML Composition
- * is done in XmlComposer, but whatever can't be done there as we're parsing
- * gets done here after the fact.
- *
- * These functions are called from XmlComposer::endDocument and massage the
- * resulting XML DOM into shape.
- */
-class XmlFixups
-{
-public:
- XmlFixups();
-
- /*
- * Breaks a paragraph up through a previous level. Calls itself
- * recursively to break paragraphs totally free up to containing
- * destination.
- *
- * For example:
- *
- * <dest>
- * This is <b> a <block fix="para"/>
- * test of </b> your concentration.
- * </dest>
- *
- * Becomes:
- *
- * <dest>
- * This is <b> a </b><block fix="para"/>
- * <b>test of </b> your concentration.
- * </dest>
- */
- bool breakElement(const DOM::Element& el, const string& contain);
-
- // Break all tags of a given type to a previous level (see above)
- void breakBreak(DOM::Document& doc, const string& contain, const string& tag);
-
- // Used to break tables cells and rows into blocks (but more complicated)
- void breakTags(DOM::Document& doc, const string& parentName, const string& tagName);
-
- // Fixes and combines list elements with the same id
- void breakLists(DOM::Document& document);
-
- // Used to find and create tables and perform initial break out
- void breakTables(DOM::Document& document);
-
-
- /*
- * Changes from a marker based paragraph system to a contained
- * paragraph system. Also applies paragraph attributes to the
- * appropriate paragraph.
- *
- * For example:
- *
- * <dest>
- * This <blockattr style="10"> is <b> a <block fix="para"/>
- * test of </b> your concentration.
- * </dest>
- *
- * Becomes:
- *
- * <para style="10"> This is <b> a </b></para>
- * <para><b>test of </b> your concentration.</para>
- */
- void breakBlocks(DOM::Document& document);
-
- // Wrap certain tags in a wrapper tag of given name
- void wrapTags(DOM::Document& document, const string& tagName, const string& wrapName);
-
- // Remove certain tags from document
- void removeTags(const DOM::Document& doc);
-
- // Combines certain adjacent duplicate tags
- void combineDuplicates(const DOM::Document& doc);
-
- // Consolidates a certain tag types at the beginning of the document
- void consolidateStartTags(DOM::Document& doc);
-
- // Consolidates a certain tag types at the end of the document
- void consolidateEndTags(DOM::Document& doc);
-
-
- // The main pass 2 function
- void runPassTwo(const DOM::Document& doc);
-
- // Replace blocks with 'fix' elements like paragraphs
- void fixBlock(const DOM::Document& doc, DOM::Element& block);
-
-
-protected:
-
- enum
- {
- PASS_0,
- PASS_1,
- PASS_TWO
- };
-
- // Our tables cached for efficiency
- StringSet m_duplicates;
- StringSet m_removes;
- StringSet m_removeEmpty;
- StringSet m_consolidateStart;
- StringSet m_consolidateEnd;
- StringSet m_requireAttrs;
-};
-
-#endif // __XMLFIXUPS_H__