summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorHenning Brinkmann <hbrinkm@openoffice.org>2011-01-05 13:41:21 +0100
committerHenning Brinkmann <hbrinkm@openoffice.org>2011-01-05 13:41:21 +0100
commitf1896f1247ff93549a9e52dde90df8ade994daed (patch)
tree1bcac0dd1e9f6cb7d53fb483a3660c78845eba1a /writerfilter
parent94fae542b504dcde605cfa311ce997094ad9b553 (diff)
new: XPathLogger
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/inc/resourcemodel/XPathLogger.hxx65
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.cxx8
-rw-r--r--writerfilter/source/ooxml/OOXMLParserState.cxx5
-rw-r--r--writerfilter/source/ooxml/OOXMLParserState.hxx5
-rw-r--r--writerfilter/source/resourcemodel/XPathLogger.cxx89
-rw-r--r--writerfilter/source/resourcemodel/makefile.mk1
6 files changed, 172 insertions, 1 deletions
diff --git a/writerfilter/inc/resourcemodel/XPathLogger.hxx b/writerfilter/inc/resourcemodel/XPathLogger.hxx
new file mode 100644
index 000000000000..22e50fc15bb9
--- /dev/null
+++ b/writerfilter/inc/resourcemodel/XPathLogger.hxx
@@ -0,0 +1,65 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+#ifndef INCLUDED_XPATH_LOGGER_HXX
+#define INCLUDED_XPATH_LOGGER_HXX
+
+#include <hash_map>
+#include <stack>
+#include <string>
+#include <vector>
+#include <boost/shared_ptr.hpp>
+#include <WriterFilterDllApi.hxx>
+
+namespace writerfilter
+{
+using ::std::hash_map;
+using ::std::stack;
+using ::std::string;
+using ::std::vector;
+
+class WRITERFILTER_DLLPUBLIC XPathLogger
+{
+ typedef hash_map<string, unsigned int> TokenMap_t;
+ typedef boost::shared_ptr<TokenMap_t> TokenMapPointer_t;
+
+ TokenMapPointer_t mp_tokenMap;
+ stack<TokenMapPointer_t> m_tokenMapStack;
+ vector<string> m_path;
+ string m_currentPath;
+
+ void updateCurrentPath();
+
+public:
+ explicit XPathLogger();
+ virtual ~XPathLogger();
+
+ string getXPath() const;
+ void startElement(string _token);
+ void endElement();
+};
+}
+#endif // INCLUDED_XPATH_LOGGER_HXX
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index 1f5181e03055..5e4d5604527f 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -31,6 +31,7 @@
#include <rtl/uuid.h>
#include <com/sun/star/drawing/XShapes.hpp>
#include <resourcemodel/QNameToString.hxx>
+#include <resourcemodel/XPathLogger.hxx>
#include <resourcemodel/util.hxx>
#include <ooxml/resourceids.hxx>
#include <doctok/sprmids.hxx>
@@ -191,8 +192,10 @@ void SAL_CALL OOXMLFastContextHandler::startFastElement
#ifdef DEBUG_CONTEXT_HANDLER
debug_logger->startElement("contexthandler.element");
string sToken = fastTokenToId(Element);
+ mpParserState->getXPathLogger().startElement(sToken);
debug_logger->attribute("token", sToken);
- debug_logger->attribute("type",getType());
+ debug_logger->attribute("type", getType());
+ debug_logger->attribute("xpath", mpParserState->getXPathLogger().getXPath());
debug_logger->startElement("at-start");
debug_logger->addTag(toTag());
debug_logger->endElement("at-start");
@@ -210,6 +213,7 @@ throw (uno::RuntimeException, xml::sax::SAXException)
debug_logger->startElement("contexthandler.unknown-element");
debug_logger->attribute("namespace", Namespace);
debug_logger->attribute("name", Name);
+ mpParserState->getXPathLogger().startElement("unknown");
#else
(void) Namespace;
(void) Name;
@@ -231,6 +235,7 @@ throw (uno::RuntimeException, xml::sax::SAXException)
debug_logger->addTag(toTag());
debug_logger->endElement("at-end");
debug_logger->endElement("contexthandler.element");
+ mpParserState->getXPathLogger().endElement();
#endif
}
@@ -255,6 +260,7 @@ throw (uno::RuntimeException, xml::sax::SAXException)
{
#ifdef DEBUG_CONTEXT_HANDLER
debug_logger->endElement("contexthandler.unknown-element");
+ mpParserState->getXPathLogger().endElement();
#endif
}
diff --git a/writerfilter/source/ooxml/OOXMLParserState.cxx b/writerfilter/source/ooxml/OOXMLParserState.cxx
index fb347d02048e..41a3738ee7ab 100644
--- a/writerfilter/source/ooxml/OOXMLParserState.cxx
+++ b/writerfilter/source/ooxml/OOXMLParserState.cxx
@@ -320,6 +320,11 @@ XMLTag::Pointer_t OOXMLParserState::toTag() const
return pTag;
}
+
+XPathLogger & OOXMLParserState::getXPathLogger()
+{
+ return m_xPathLogger;
+}
#endif
}}
diff --git a/writerfilter/source/ooxml/OOXMLParserState.hxx b/writerfilter/source/ooxml/OOXMLParserState.hxx
index 2dd118a5b96b..12a9876ce6eb 100644
--- a/writerfilter/source/ooxml/OOXMLParserState.hxx
+++ b/writerfilter/source/ooxml/OOXMLParserState.hxx
@@ -33,6 +33,7 @@
#ifdef DEBUG
#include <resourcemodel/TagLogger.hxx>
+#include <resourcemodel/XPathLogger.hxx>
#endif
namespace writerfilter {
@@ -57,6 +58,9 @@ class OOXMLParserState
stack<OOXMLPropertySet::Pointer_t> mCellProps;
stack<OOXMLPropertySet::Pointer_t> mRowProps;
stack<OOXMLPropertySet::Pointer_t> mTableProps;
+#ifdef DEBUG
+ XPathLogger m_xPathLogger;
+#endif
public:
typedef boost::shared_ptr<OOXMLParserState> Pointer_t;
@@ -109,6 +113,7 @@ public:
unsigned int getContextCount() const;
string toString() const;
XMLTag::Pointer_t toTag() const;
+ XPathLogger & getXPathLogger();
#endif
};
diff --git a/writerfilter/source/resourcemodel/XPathLogger.cxx b/writerfilter/source/resourcemodel/XPathLogger.cxx
new file mode 100644
index 000000000000..6e8ec701bc4a
--- /dev/null
+++ b/writerfilter/source/resourcemodel/XPathLogger.cxx
@@ -0,0 +1,89 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <resourcemodel/XPathLogger.hxx>
+
+namespace writerfilter
+{
+XPathLogger::XPathLogger()
+: mp_tokenMap(new TokenMap_t)
+{
+}
+
+XPathLogger::~XPathLogger()
+{
+}
+
+string XPathLogger::getXPath() const
+{
+ return m_currentPath;
+}
+
+void XPathLogger::updateCurrentPath()
+{
+ m_currentPath = "";
+
+ for (vector<string>::const_iterator aIt = m_path.begin();
+ aIt != m_path.end();
+ aIt++)
+ {
+ if (m_currentPath.size() > 0)
+ m_currentPath += "/";
+
+ m_currentPath += *aIt;
+ }
+}
+
+void XPathLogger::startElement(string _token)
+{
+ TokenMap_t::const_iterator aIt = mp_tokenMap->find(_token);
+
+ if (aIt == mp_tokenMap->end())
+ (*mp_tokenMap)[_token] = 1;
+ else
+ (*mp_tokenMap)[_token]++;
+
+ static char sBuffer[256];
+ snprintf(sBuffer, sizeof(sBuffer), "[%d]", (*mp_tokenMap)[_token]);
+ m_path.push_back(_token + sBuffer);
+
+ m_tokenMapStack.push(mp_tokenMap);
+ mp_tokenMap.reset(new TokenMap_t);
+
+ updateCurrentPath();
+}
+
+void XPathLogger::endElement()
+{
+ mp_tokenMap = m_tokenMapStack.top();
+ m_tokenMapStack.pop();
+ m_path.pop_back();
+
+ updateCurrentPath();
+}
+
+}
diff --git a/writerfilter/source/resourcemodel/makefile.mk b/writerfilter/source/resourcemodel/makefile.mk
index 71f730e77303..1bc260455813 100644
--- a/writerfilter/source/resourcemodel/makefile.mk
+++ b/writerfilter/source/resourcemodel/makefile.mk
@@ -55,6 +55,7 @@ SLOFILES= \
$(SLO)$/ResourceModelHelper.obj \
$(SLO)$/TagLogger.obj \
$(SLO)$/WW8Analyzer.obj \
+ $(SLO)$/XPathLogger.obj \
$(SLO)$/qnametostr.obj \
$(SLO)$/resourcemodel.obj \
$(SLO)$/sprmcodetostr.obj \