Commits

Anonymous committed bf600d9

new: XPathLogger

  • Participants
  • Parent commits c3919fb

Comments (0)

Files changed (6)

writerfilter/inc/resourcemodel/XPathLogger.hxx

+/*************************************************************************
+ *
+ * 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

writerfilter/source/ooxml/OOXMLFastContextHandler.cxx

 #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>
 #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");
     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;
     debug_logger->addTag(toTag());
     debug_logger->endElement("at-end");
     debug_logger->endElement("contexthandler.element");
+    mpParserState->getXPathLogger().endElement();
 #endif
 }
 
 {
 #ifdef DEBUG_CONTEXT_HANDLER
     debug_logger->endElement("contexthandler.unknown-element");
+    mpParserState->getXPathLogger().endElement();
 #endif
 }
 

writerfilter/source/ooxml/OOXMLParserState.cxx

 
     return pTag;
  }
+
+XPathLogger & OOXMLParserState::getXPathLogger()
+{
+    return m_xPathLogger;
+}
 #endif
 
 }}

writerfilter/source/ooxml/OOXMLParserState.hxx

 
 #ifdef DEBUG
 #include <resourcemodel/TagLogger.hxx>
+#include <resourcemodel/XPathLogger.hxx>
 #endif
 
 namespace writerfilter {
     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;
     unsigned int getContextCount() const;
     string toString() const;
     XMLTag::Pointer_t toTag() const;
+    XPathLogger & getXPathLogger();
 #endif
 
 };

writerfilter/source/resourcemodel/XPathLogger.cxx

+/*************************************************************************
+ *
+ * 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();
+}
+
+}

writerfilter/source/resourcemodel/makefile.mk

 	$(SLO)$/ResourceModelHelper.obj \
 	$(SLO)$/TagLogger.obj \
 	$(SLO)$/WW8Analyzer.obj \
+	$(SLO)$/XPathLogger.obj \
 	$(SLO)$/qnametostr.obj \
 	$(SLO)$/resourcemodel.obj \
 	$(SLO)$/sprmcodetostr.obj \