summaryrefslogtreecommitdiff
path: root/writerfilter/source/resourcemodel
diff options
context:
space:
mode:
Diffstat (limited to 'writerfilter/source/resourcemodel')
-rw-r--r--writerfilter/source/resourcemodel/Fraction.cxx150
-rw-r--r--writerfilter/source/resourcemodel/LoggedResources.cxx322
-rw-r--r--writerfilter/source/resourcemodel/Protocol.cxx218
-rw-r--r--writerfilter/source/resourcemodel/ResourceModelHelper.cxx48
-rw-r--r--writerfilter/source/resourcemodel/TagLogger.cxx489
-rw-r--r--writerfilter/source/resourcemodel/WW8Analyzer.cxx216
-rw-r--r--writerfilter/source/resourcemodel/WW8Analyzer.hxx99
-rw-r--r--writerfilter/source/resourcemodel/XPathLogger.cxx90
-rw-r--r--writerfilter/source/resourcemodel/analyzerfooter4
-rw-r--r--writerfilter/source/resourcemodel/analyzerheader36
-rwxr-xr-xwriterfilter/source/resourcemodel/genqnametostr35
-rw-r--r--writerfilter/source/resourcemodel/makefile.mk207
-rw-r--r--writerfilter/source/resourcemodel/namespace_preprocess.pl50
-rw-r--r--writerfilter/source/resourcemodel/qnametostrfooter24
-rw-r--r--writerfilter/source/resourcemodel/qnametostrheader57
-rw-r--r--writerfilter/source/resourcemodel/resourcemodel.cxx563
-rw-r--r--writerfilter/source/resourcemodel/resourcemodel.hxx110
-rwxr-xr-xwriterfilter/source/resourcemodel/setdebugflags3
-rw-r--r--writerfilter/source/resourcemodel/sprmcodetostrfooter1
-rw-r--r--writerfilter/source/resourcemodel/sprmcodetostrheader50
-rw-r--r--writerfilter/source/resourcemodel/util.cxx427
21 files changed, 3199 insertions, 0 deletions
diff --git a/writerfilter/source/resourcemodel/Fraction.cxx b/writerfilter/source/resourcemodel/Fraction.cxx
new file mode 100644
index 000000000000..c50668a7db03
--- /dev/null
+++ b/writerfilter/source/resourcemodel/Fraction.cxx
@@ -0,0 +1,150 @@
+/*************************************************************************
+ *
+ * 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/Fraction.hxx>
+
+namespace writerfilter {
+namespace resourcemodel {
+
+sal_uInt32 gcd(sal_uInt32 a, sal_uInt32 b)
+{
+ if (a == 0 || b == 0)
+ return a | b;
+
+ sal_uInt32 nShift = 0;
+ while (((a | b) & 1) == 0)
+ {
+ a >>= 1;
+ b >>= 1;
+ ++nShift;
+ }
+
+ while ((a & 1) == 0)
+ a >>= 1;
+
+ do
+ {
+ while ((b & 1) == 0)
+ b >>= 1;
+
+ if (a < b)
+ {
+ b -= a;
+ }
+ else
+ {
+ sal_uInt32 nDiff = a - b;
+ a = b;
+ b = nDiff;
+ }
+
+ b >>= 1;
+ }
+ while (b != 0);
+
+ return a << nShift;
+}
+
+sal_uInt32 lcm(sal_Int32 a, sal_Int32 b)
+{
+ return abs(a * b) / gcd(abs(a), abs(b));
+}
+
+Fraction::Fraction(sal_Int32 nNumerator, sal_Int32 nDenominator)
+{
+ init(nNumerator, nDenominator);
+}
+
+Fraction::Fraction(const Fraction & a, const Fraction & b)
+{
+ init(a.mnNumerator * b.mnDenominator, a.mnDenominator * b.mnNumerator);
+}
+
+Fraction::~Fraction()
+{
+}
+
+void Fraction::init(sal_Int32 nNumerator, sal_Int32 nDenominator)
+{
+ sal_uInt32 nGCD = gcd(nNumerator, nDenominator);
+
+ mnNumerator = nNumerator/ nGCD;
+ mnDenominator = nDenominator / nGCD;
+}
+
+void Fraction::assign(const Fraction & rFraction)
+{
+ init(rFraction.mnNumerator, rFraction.mnDenominator);
+}
+
+Fraction Fraction::inverse() const
+{
+ return Fraction(mnDenominator, mnNumerator);
+}
+
+Fraction Fraction::operator + (const Fraction & rFraction) const
+{
+ sal_uInt32 nLCM = lcm(mnDenominator, rFraction.mnDenominator);
+
+ return Fraction(mnNumerator * nLCM / mnDenominator + rFraction.mnNumerator * nLCM / rFraction.mnDenominator, nLCM);
+}
+
+Fraction Fraction::operator - (const Fraction & rFraction) const
+{
+ sal_uInt32 nLCM = lcm(mnDenominator, rFraction.mnDenominator);
+
+ return Fraction(mnNumerator * nLCM / mnDenominator - rFraction.mnNumerator * nLCM / rFraction.mnDenominator, nLCM);
+}
+
+Fraction Fraction::operator * (const Fraction & rFraction) const
+{
+ return Fraction(mnNumerator * rFraction.mnNumerator, mnDenominator * rFraction.mnDenominator);
+}
+
+Fraction Fraction::operator / (const Fraction & rFraction) const
+{
+ return *this * rFraction.inverse();
+}
+
+Fraction Fraction::operator = (const Fraction & rFraction)
+{
+ assign(rFraction);
+
+ return *this;
+}
+
+Fraction::operator sal_Int32() const
+{
+ return mnNumerator / mnDenominator;
+}
+
+Fraction::operator float() const
+{
+ return static_cast<float>(mnNumerator) / static_cast<float>(mnDenominator);
+}
+
+}}
diff --git a/writerfilter/source/resourcemodel/LoggedResources.cxx b/writerfilter/source/resourcemodel/LoggedResources.cxx
new file mode 100644
index 000000000000..f60b48b82b5b
--- /dev/null
+++ b/writerfilter/source/resourcemodel/LoggedResources.cxx
@@ -0,0 +1,322 @@
+/*************************************************************************
+ *
+ * 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 <rtl/ustrbuf.hxx>
+#include <resourcemodel/LoggedResources.hxx>
+#include <resourcemodel/QNameToString.hxx>
+
+namespace writerfilter
+{
+
+// class: LoggedResourcesHelper
+
+LoggedResourcesHelper::LoggedResourcesHelper(TagLogger::Pointer_t pLogger, const string & sPrefix)
+: mpLogger(pLogger), msPrefix(sPrefix)
+{
+}
+
+LoggedResourcesHelper::~LoggedResourcesHelper()
+{
+}
+
+void LoggedResourcesHelper::startElement(const string & sElement)
+{
+ mpLogger->startElement(msPrefix + "." + sElement);
+}
+
+void LoggedResourcesHelper::endElement(const string & sElement)
+{
+ mpLogger->endElement(msPrefix + "." + sElement);
+}
+
+void LoggedResourcesHelper::chars(const ::rtl::OUString & rChars)
+{
+ mpLogger->chars(rChars);
+}
+
+void LoggedResourcesHelper::chars(const string & rChars)
+{
+ mpLogger->chars(rChars);
+}
+
+void LoggedResourcesHelper::attribute(const string & rName, const string & rValue)
+{
+ mpLogger->attribute(rName, rValue);
+}
+
+void LoggedResourcesHelper::attribute(const string & rName, sal_uInt32 nValue)
+{
+ mpLogger->attribute(rName, nValue);
+}
+
+void LoggedResourcesHelper::setPrefix(const string & rPrefix)
+{
+ msPrefix = rPrefix;
+}
+
+// class: LoggedStream
+
+LoggedStream::LoggedStream(TagLogger::Pointer_t pLogger, const string & sPrefix)
+: mHelper(pLogger, sPrefix)
+{
+}
+
+LoggedStream::~LoggedStream()
+{
+}
+
+void LoggedStream::startSectionGroup()
+{
+#ifdef DEBUG_LOGGING
+ mHelper.startElement("section");
+#endif
+
+ lcl_startSectionGroup();
+}
+
+void LoggedStream::endSectionGroup()
+{
+ lcl_endSectionGroup();
+
+#ifdef DEBUG_LOGGING
+ mHelper.endElement("section");
+#endif
+}
+
+void LoggedStream::startParagraphGroup()
+{
+#ifdef DEBUG_LOGGING
+ mHelper.startElement("paragraph");
+#endif
+
+ lcl_startParagraphGroup();
+}
+
+void LoggedStream::endParagraphGroup()
+{
+ lcl_endParagraphGroup();
+
+#ifdef DEBUG_LOGGING
+ mHelper.endElement("paragraph");
+#endif
+}
+
+
+void LoggedStream::startCharacterGroup()
+{
+#ifdef DEBUG_LOGGING
+ mHelper.startElement("charactergroup");
+#endif
+
+ lcl_startCharacterGroup();
+}
+
+void LoggedStream::endCharacterGroup()
+{
+ lcl_endCharacterGroup();
+
+#ifdef DEBUG_LOGGING
+ mHelper.endElement("charactergroup");
+#endif
+}
+
+void LoggedStream::startShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape )
+{
+#ifdef DEBUG_LOGGING
+ mHelper.startElement("shape");
+#endif
+
+ lcl_startShape(xShape);
+}
+
+void LoggedStream::endShape()
+{
+ lcl_endShape();
+
+#ifdef DEBUG_LOGGING
+ mHelper.endElement("shape");
+#endif
+}
+
+void LoggedStream::text(const sal_uInt8 * data, size_t len)
+{
+#ifdef DEBUG_LOGGING
+ mHelper.startElement("text");
+
+ ::rtl::OUString sText( (const sal_Char*) data, len, RTL_TEXTENCODING_MS_1252 );
+
+ mHelper.startElement("data");
+ mHelper.chars(sText);
+ mHelper.endElement("data");
+#endif
+
+ lcl_text(data, len);
+
+#ifdef DEBUG_LOGGING
+ mHelper.endElement("text");
+#endif
+}
+
+void LoggedStream::utext(const sal_uInt8 * data, size_t len)
+{
+#ifdef DEBUG_LOGGING
+ mHelper.startElement("utext");
+ mHelper.startElement("data");
+
+ ::rtl::OUString sText;
+ ::rtl::OUStringBuffer aBuffer = ::rtl::OUStringBuffer(len);
+ aBuffer.append( (const sal_Unicode *) data, len);
+ sText = aBuffer.makeStringAndClear();
+
+ mHelper.chars(sText);
+
+ mHelper.endElement("data");
+#endif
+
+ lcl_utext(data, len);
+
+#ifdef DEBUG_LOGGING
+ mHelper.endElement("utext");
+#endif
+}
+
+void LoggedStream::props(writerfilter::Reference<Properties>::Pointer_t ref)
+{
+#ifdef DEBUG_LOGGING
+ mHelper.startElement("props");
+#endif
+
+ lcl_props(ref);
+
+#ifdef DEBUG_LOGGING
+ mHelper.endElement("props");
+#endif
+}
+
+void LoggedStream::table(Id name, writerfilter::Reference<Table>::Pointer_t ref)
+{
+#ifdef DEBUG_LOGGING
+ mHelper.startElement("table");
+ mHelper.attribute("name", (*QNameToString::Instance())(name));
+#endif
+
+ lcl_table(name, ref);
+
+#ifdef DEBUG_LOGGING
+ mHelper.endElement("table");
+#endif
+}
+
+void LoggedStream::substream(Id name, writerfilter::Reference<Stream>::Pointer_t ref)
+{
+#ifdef DEBUG_LOGGING
+ mHelper.startElement("substream");
+ mHelper.attribute("name", (*QNameToString::Instance())(name));
+#endif
+
+ lcl_substream(name, ref);
+
+#ifdef DEBUG_LOGGING
+ mHelper.endElement("substream");
+#endif
+}
+
+void LoggedStream::info(const string & _info)
+{
+#ifdef DEBUG_LOGGING
+ mHelper.startElement("info");
+ mHelper.attribute("text", _info);
+#endif
+
+ lcl_info(_info);
+
+#ifdef DEBUG_LOGGING
+ mHelper.endElement("info");
+#endif
+}
+
+// class LoggedProperties
+LoggedProperties::LoggedProperties(TagLogger::Pointer_t pLogger, const string & sPrefix)
+: mHelper(pLogger, sPrefix)
+{
+}
+
+LoggedProperties::~LoggedProperties()
+{
+}
+
+void LoggedProperties::attribute(Id name, Value & val)
+{
+#ifdef DEBUG_LOGGING
+ mHelper.startElement("attribute");
+ mHelper.attribute("name", (*QNameToString::Instance())(name));
+ mHelper.attribute("value", val.toString());
+ mHelper.endElement("attribute");
+#endif
+
+ lcl_attribute(name, val);
+}
+
+void LoggedProperties::sprm(Sprm & _sprm)
+{
+#ifdef DEBUG_LOGGING
+ mHelper.startElement("sprm");
+ mHelper.attribute("name", (*QNameToString::Instance())(_sprm.getId()));
+ mHelper.chars(sprm.toString());
+#endif
+
+ lcl_sprm(_sprm);
+
+#ifdef DEBUG_LOGGING
+ mHelper.endElement("sprm");
+#endif
+}
+
+LoggedTable::LoggedTable(TagLogger::Pointer_t pLogger, const string & sPrefix)
+: mHelper(pLogger, sPrefix)
+{
+}
+
+LoggedTable::~LoggedTable()
+{
+}
+
+void LoggedTable::entry(int pos, writerfilter::Reference<Properties>::Pointer_t ref)
+{
+#ifdef DEBUG_LOGGING
+ mHelper.startElement("entry");
+ mHelper.attribute("pos", pos);
+#endif
+
+ lcl_entry(pos, ref);
+
+#ifdef DEBUG_LOGGING
+ mHelper.endElement("entry");
+#endif
+}
+
+}
diff --git a/writerfilter/source/resourcemodel/Protocol.cxx b/writerfilter/source/resourcemodel/Protocol.cxx
new file mode 100644
index 000000000000..51d12eb4f2d6
--- /dev/null
+++ b/writerfilter/source/resourcemodel/Protocol.cxx
@@ -0,0 +1,218 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: WW8ResourceModel.hxx,v $
+ * $Revision: 1.4 $
+ *
+ * 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.
+ *
+ ************************************************************************/
+
+#ifdef DEBUG
+#include <stdio.h>
+#include <rtl/ustrbuf.hxx>
+#include <resourcemodel/Protocol.hxx>
+#include <resourcemodel/WW8ResourceModel.hxx>
+#include <resourcemodel/QNameToString.hxx>
+namespace writerfilter
+{
+
+/*
+ StreamProtocol
+*/
+
+StreamProtocol::StreamProtocol(Stream * pStream,
+ TagLogger::Pointer_t pTagLogger)
+ : m_pStream(pStream), m_pTagLogger(pTagLogger)
+{
+}
+
+StreamProtocol::~StreamProtocol()
+{
+}
+
+void StreamProtocol::startSectionGroup()
+{
+ m_pTagLogger->element("protocol-startSectionGroup");
+ m_pStream->startSectionGroup();
+}
+
+void StreamProtocol::endSectionGroup()
+{
+ m_pTagLogger->element("protocol-endSectionGroup");
+ m_pStream->endSectionGroup();
+}
+
+void StreamProtocol::startParagraphGroup()
+{
+ m_pTagLogger->element("protocol-startParagraphGroup");
+ m_pStream->startParagraphGroup();
+}
+
+void StreamProtocol::endParagraphGroup()
+{
+ m_pTagLogger->element("protocol-endParagraphGroup");
+ m_pStream->endParagraphGroup();
+}
+
+void StreamProtocol::startCharacterGroup()
+{
+ m_pTagLogger->element("protocol-startCharacterGroup");
+ m_pStream->startCharacterGroup();
+}
+
+void StreamProtocol::endCharacterGroup()
+{
+ m_pTagLogger->element("protocol-endCharacterGroup");
+ m_pStream->endCharacterGroup();
+}
+
+void StreamProtocol::text(const sal_uInt8 * data, size_t len)
+{
+ ::rtl::OUString sText((const sal_Char*) data, len,
+ RTL_TEXTENCODING_MS_1252);
+ m_pTagLogger->startElement("protocol-text");
+ m_pTagLogger->chars(sText);
+ m_pTagLogger->endElement("protocol-text");
+
+ m_pStream->text(data, len);
+}
+
+void StreamProtocol::utext(const sal_uInt8 * data, size_t len)
+{
+ ::rtl::OUString sText;
+ ::rtl::OUStringBuffer aBuffer = ::rtl::OUStringBuffer(len);
+ aBuffer.append( (const sal_Unicode *) data, len);
+ sText = aBuffer.makeStringAndClear();
+
+ m_pTagLogger->startElement("protocol-utext");
+ m_pTagLogger->chars(sText);
+ m_pTagLogger->endElement("protocol-utext");
+
+ m_pStream->utext(data, len);
+}
+
+void StreamProtocol::props(writerfilter::Reference<Properties>::Pointer_t ref)
+{
+ m_pTagLogger->startElement("protocol-props");
+ m_pStream->props(ref);
+ m_pTagLogger->endElement("protocol-props");
+}
+
+void StreamProtocol::table(Id name,
+ writerfilter::Reference<Table>::Pointer_t ref)
+{
+ m_pTagLogger->startElement("protocol-table");
+ m_pTagLogger->attribute("name", (*QNameToString::Instance())(name));
+ m_pStream->table(name, ref);
+ m_pTagLogger->endElement("protocol-table");
+}
+
+void StreamProtocol::substream(Id name,
+ writerfilter::Reference<Stream>::Pointer_t ref)
+{
+ m_pTagLogger->startElement("protocol-substream");
+ m_pTagLogger->attribute("name", (*QNameToString::Instance())(name));
+
+ m_pStream->substream(name, ref);
+ m_pTagLogger->endElement("protocol-substream");
+}
+
+void StreamProtocol::info(const string & rInfo)
+{
+ m_pStream->info(rInfo);
+}
+
+void StreamProtocol::startShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape )
+{
+ m_pTagLogger->element("protocol-startShape");
+
+ m_pStream->startShape(xShape);
+}
+
+void StreamProtocol::endShape()
+{
+ m_pTagLogger->element("protocol-endShape");
+
+ m_pStream->endShape();
+}
+
+/*
+ PropertiesProtocol
+*/
+
+PropertiesProtocol::PropertiesProtocol(Properties * pProperties,
+ TagLogger::Pointer_t pTagLogger)
+: m_pProperties(pProperties), m_pTagLogger(pTagLogger)
+{
+}
+
+PropertiesProtocol::~PropertiesProtocol()
+{
+}
+
+void PropertiesProtocol::attribute(Id name, Value & val)
+{
+ m_pTagLogger->startElement("protocol-attribute");
+ m_pTagLogger->attribute("name", (*QNameToString::Instance())(name));
+ m_pTagLogger->attribute("value", val.toString());
+ m_pProperties->attribute(name, val);
+ m_pTagLogger->endElement("protocol-attribute");
+}
+
+void PropertiesProtocol::sprm(Sprm & _sprm)
+{
+ m_pTagLogger->startElement("protocol-sprm");
+ static char sBuffer[256];
+ snprintf(sBuffer, sizeof(sBuffer), "%04" SAL_PRIxUINT32, _sprm.getId());
+ m_pTagLogger->attribute("id", sBuffer);
+ m_pTagLogger->attribute("name", _sprm.getName());
+ m_pTagLogger->chars(_sprm.toString());
+ m_pProperties->sprm(_sprm);
+ m_pTagLogger->endElement("protocol-sprm");
+}
+
+/*
+ TableProtocol
+ */
+
+TableProtocol::TableProtocol(Table * pTable, TagLogger::Pointer_t pTagLogger)
+: m_pTable(pTable), m_pTagLogger(pTagLogger)
+{
+}
+
+TableProtocol::~TableProtocol()
+{
+}
+
+void TableProtocol::entry(int pos,
+ writerfilter::Reference<Properties>::Pointer_t ref)
+{
+ m_pTagLogger->startElement("protocol-entry");
+ m_pTagLogger->attribute("pos", pos);
+ m_pTable->entry(pos, ref);
+ m_pTagLogger->endElement("protocol-entry");
+}
+
+}
+#endif // DEBUG
diff --git a/writerfilter/source/resourcemodel/ResourceModelHelper.cxx b/writerfilter/source/resourcemodel/ResourceModelHelper.cxx
new file mode 100644
index 000000000000..fee286fb4570
--- /dev/null
+++ b/writerfilter/source/resourcemodel/ResourceModelHelper.cxx
@@ -0,0 +1,48 @@
+/*************************************************************************
+ *
+ * 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/ResourceModelHelper.hxx"
+
+namespace writerfilter {
+namespace resourcemodel {
+
+void resolveSprmProps(Properties & rHandler, Sprm & rSprm)
+{
+ writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
+ if( pProperties.get())
+ pProperties->resolve(rHandler);
+}
+
+void resolveAttributeProperties(Properties & rHandler, Value & val)
+{
+ writerfilter::Reference<Properties>::Pointer_t pProperties = val.getProperties();
+ if( pProperties.get())
+ pProperties->resolve(rHandler);
+}
+
+
+}}
diff --git a/writerfilter/source/resourcemodel/TagLogger.cxx b/writerfilter/source/resourcemodel/TagLogger.cxx
new file mode 100644
index 000000000000..ebb28aa0148b
--- /dev/null
+++ b/writerfilter/source/resourcemodel/TagLogger.cxx
@@ -0,0 +1,489 @@
+/*************************************************************************
+ *
+ * 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 <fstream>
+#include <string.h>
+#include <resourcemodel/TagLogger.hxx>
+#include <resourcemodel/util.hxx>
+#include <resourcemodel/QNameToString.hxx>
+
+namespace writerfilter
+{
+XMLTag::Pointer_t XMLTag::NIL(new XMLTag("NIL"));
+
+void XMLTag::addAttr(string sName, string sValue)
+{
+ XMLAttribute aAttr(sName, sValue);
+
+ mAttrs.push_back(aAttr);
+}
+
+void XMLTag::addAttr(string sName, const ::rtl::OUString & sValue)
+{
+ addAttr(sName,
+ OUStringToOString
+ (sValue, RTL_TEXTENCODING_ASCII_US).getStr());
+}
+
+void XMLTag::addAttr(string sName, sal_uInt32 nValue)
+{
+ static char buffer[256];
+ snprintf(buffer, sizeof(buffer), "%" SAL_PRIdINT32, nValue);
+ addAttr(sName, buffer);
+}
+
+void XMLTag::addAttr(string sName, uno::Any aAny)
+{
+ string aTmpStrInt;
+ string aTmpStrFloat;
+ string aTmpStrString;
+
+ static char buffer[256];
+
+ try
+ {
+ sal_Int32 nInt = 0;
+ aAny >>= nInt;
+
+ snprintf(buffer, sizeof(buffer), "%" SAL_PRIdINT32,
+ nInt);
+
+ aTmpStrInt = buffer;
+ }
+ catch (uno::Exception aExcept)
+ {
+ aTmpStrInt = "exception";
+ }
+
+ try
+ {
+ float nFloat = 0.0;
+ aAny >>= nFloat;
+
+ snprintf(buffer, sizeof(buffer), "%f",
+ nFloat);
+
+ aTmpStrFloat = buffer;
+ }
+ catch (uno::Exception aExcept)
+ {
+ aTmpStrFloat = "exception";
+ }
+
+ try
+ {
+ ::rtl::OUString aStr;
+ aAny >>= aStr;
+
+ aTmpStrString = OUStringToOString(aStr, RTL_TEXTENCODING_ASCII_US).getStr();
+ }
+ catch (uno::Exception aExcept)
+ {
+ aTmpStrString = "exception";
+ }
+
+ addAttr(sName, "i:" + aTmpStrInt + " f:" + aTmpStrFloat + " s:" +
+ aTmpStrString);
+}
+
+void XMLTag::addTag(XMLTag::Pointer_t pTag)
+{
+ if (pTag != XMLTag::Pointer_t())
+ mTags.push_back(pTag);
+}
+
+void XMLTag::chars(const string & rChars)
+{
+ mChars += rChars;
+}
+
+void XMLTag::chars(const ::rtl::OUString & rChars)
+{
+ chars(OUStringToOString(rChars, RTL_TEXTENCODING_ASCII_US).getStr());
+}
+
+const string & XMLTag::getTag() const
+{
+ return mTag;
+}
+
+string XMLTag::toString() const
+{
+ if (mChars.length() > 0)
+ return mChars;
+
+ string sResult;
+
+ if (mMode == START || mMode == COMPLETE)
+ {
+ sResult += "<" + mTag;
+
+ XMLAttributes_t::const_iterator aIt = mAttrs.begin();
+ while (aIt != mAttrs.end())
+ {
+ sResult += " ";
+ sResult += aIt->mName;
+ sResult += "=\"";
+ sResult += xmlify(aIt->mValue);
+ sResult += "\"";
+
+ aIt++;
+ }
+
+ sResult +=">";
+
+ if (mTags.size() > 0)
+ {
+ XMLTags_t::const_iterator aItTags = mTags.begin();
+ while (aItTags != mTags.end())
+ {
+ if ((*aItTags).get() != NULL)
+ sResult += (*aItTags)->toString();
+
+ aItTags++;
+ }
+ }
+ }
+
+ if (mMode == END || mMode == COMPLETE)
+ sResult += "</" + mTag + ">";
+
+ return sResult;
+}
+
+ostream & XMLTag::output(ostream & o, const string & sIndent) const
+{
+ bool bHasContent = mChars.size() > 0 || mTags.size() > 0;
+
+ if (mMode == START || mMode == COMPLETE)
+ {
+ o << sIndent << "<" << mTag;
+
+ XMLAttributes_t::const_iterator aItAttrs(mAttrs.begin());
+ while (aItAttrs != mAttrs.end())
+ {
+ o << " " << aItAttrs->mName << "=\""
+ << xmlify(aItAttrs->mValue)
+ << "\"";
+
+ aItAttrs++;
+ }
+
+ if (bHasContent)
+ {
+ o << ">";
+
+ string sNewIndent = sIndent + " ";
+ XMLTags_t::const_iterator aItTags(mTags.begin());
+ while (aItTags != mTags.end())
+ {
+ if (aItTags == mTags.begin())
+ o << endl;
+
+ (*aItTags)->output(o, sNewIndent);
+ aItTags++;
+ }
+
+ o << mChars;
+ }
+ }
+
+ if (mMode == END || mMode == COMPLETE)
+ {
+ if (bHasContent)
+ {
+ if (mTags.size() > 0)
+ o << sIndent;
+
+ o << "</" << mTag << ">" << endl;
+ }
+ else
+ o << "/>" << endl;
+ }
+
+ return o;
+}
+
+struct eqstr
+{
+ bool operator()(const char* s1, const char* s2) const
+ {
+ return strcmp(s1, s2) == 0;
+ }
+};
+
+typedef hash_map<const char *, TagLogger::Pointer_t, hash<const char *>, eqstr> TagLoggerHashMap_t;
+static TagLoggerHashMap_t * tagLoggers = NULL;
+
+TagLogger::TagLogger()
+: mFileName("writerfilter")
+{
+}
+
+TagLogger::~TagLogger()
+{
+}
+
+void TagLogger::setFileName(const string & rName)
+{
+ mFileName = rName;
+}
+
+TagLogger::Pointer_t TagLogger::getInstance(const char * name)
+{
+ if (tagLoggers == NULL)
+ tagLoggers = new TagLoggerHashMap_t();
+
+ TagLoggerHashMap_t::iterator aIt = tagLoggers->end();
+
+ if (! tagLoggers->empty())
+ aIt = tagLoggers->find(name);
+
+ if (aIt == tagLoggers->end())
+ {
+ TagLogger::Pointer_t pTagLogger(new TagLogger());
+ pair<const char *, TagLogger::Pointer_t> entry(name, pTagLogger);
+ aIt = tagLoggers->insert(entry).first;
+ }
+
+ return aIt->second;
+}
+
+XMLTag::Pointer_t TagLogger::currentTag() const
+{
+ bool bEmpty=mTags.empty();
+ if (!bEmpty)
+ return mTags.top();
+
+ return XMLTag::NIL;
+}
+
+void TagLogger::startDocument()
+{
+ XMLTag::Pointer_t pTag(new XMLTag("root"));
+ mTags.push(pTag);
+ mpRoot = pTag;
+}
+
+void TagLogger::element(const string & name)
+{
+ startElement(name);
+ endElement(name);
+}
+
+void TagLogger::startElement(const string & name)
+{
+ XMLTag::Pointer_t pTag(new XMLTag(name));
+ currentTag()->addTag(pTag);
+ mTags.push(pTag);
+}
+
+void TagLogger::attribute(const string & name, const string & value)
+{
+ currentTag()->addAttr(name, value);
+}
+
+void TagLogger::attribute(const string & name, const ::rtl::OUString & value)
+{
+ currentTag()->addAttr(name, value);
+}
+
+void TagLogger::attribute(const string & name, sal_uInt32 value)
+{
+ currentTag()->addAttr(name, value);
+}
+
+void TagLogger::attribute(const string & name, const uno::Any aAny)
+{
+ currentTag()->addAttr(name, aAny);
+}
+
+void TagLogger::addTag(XMLTag::Pointer_t pTag)
+{
+ currentTag()->addTag(pTag);
+}
+
+void TagLogger::chars(const string & rChars)
+{
+ currentTag()->chars(xmlify(rChars));
+}
+
+void TagLogger::chars(const ::rtl::OUString & rChars)
+{
+ chars(OUStringToOString(rChars, RTL_TEXTENCODING_ASCII_US).getStr());
+}
+
+void TagLogger::endElement(const string & name)
+{
+ string nameRemoved = currentTag()->getTag();
+
+ if (name == nameRemoved)
+ mTags.pop();
+ else {
+ XMLTag::Pointer_t pTag(new XMLTag("end.mismatch"));
+ pTag->addAttr("name", name);
+ pTag->addAttr("top", nameRemoved);
+
+ currentTag()->addTag(pTag);
+ }
+
+}
+
+void TagLogger::endDocument()
+{
+ mTags.pop();
+}
+
+ostream & TagLogger::output(ostream & o) const
+{
+ return mpRoot->output(o);
+}
+
+void TagLogger::dump(const char * name)
+{
+ TagLoggerHashMap_t::iterator aIt(tagLoggers->find(name));
+ if (aIt != tagLoggers->end())
+ {
+ string fileName;
+ char * temp = getenv("TAGLOGGERTMP");
+
+ if (temp != NULL)
+ fileName += temp;
+ else
+ fileName += "/tmp";
+
+ string sPrefix = aIt->second->mFileName;
+ size_t nLastSlash = sPrefix.find_last_of('/');
+ size_t nLastBackslash = sPrefix.find_last_of('\\');
+ size_t nCutPos = nLastSlash;
+ if (nLastBackslash < nCutPos)
+ nCutPos = nLastBackslash;
+ if (nCutPos < sPrefix.size())
+ sPrefix = sPrefix.substr(nCutPos + 1);
+
+ fileName += "/";
+ fileName += sPrefix;
+ fileName +=".";
+ fileName += name;
+ fileName += ".xml";
+
+ ofstream dumpStream(fileName.c_str());
+ aIt->second->output(dumpStream);
+ }
+}
+
+PropertySetToTagHandler::PropertySetToTagHandler(IdToString::Pointer_t pIdToString)
+ : mpTag(new XMLTag("propertyset")), mpIdToString(pIdToString)
+{
+}
+
+PropertySetToTagHandler::~PropertySetToTagHandler()
+{
+}
+
+void PropertySetToTagHandler::resolve
+(XMLTag & rTag, writerfilter::Reference<Properties>::Pointer_t pProps)
+{
+ if (pProps.get() != NULL)
+ {
+ PropertySetToTagHandler aHandler(mpIdToString);
+ pProps->resolve(aHandler);
+ rTag.addTag(aHandler.getTag());
+ }
+}
+
+void PropertySetToTagHandler::attribute(Id name, Value & val)
+{
+ XMLTag::Pointer_t pTag(new XMLTag("attribute"));
+
+ pTag->addAttr("name", (*QNameToString::Instance())(name));
+ pTag->addAttr("value", val.toString());
+
+ resolve(*pTag, val.getProperties());
+
+ mpTag->addTag(pTag);
+}
+
+void PropertySetToTagHandler::sprm(Sprm & rSprm)
+{
+ XMLTag::Pointer_t pTag(new XMLTag("sprm"));
+
+ string sName;
+
+ if (mpIdToString != IdToString::Pointer_t())
+ sName = mpIdToString->toString(rSprm.getId());
+
+ pTag->addAttr("name", sName);
+
+ static char sBuffer[256];
+ snprintf(sBuffer, sizeof(sBuffer),
+ "0x%" SAL_PRIxUINT32 ", %" SAL_PRIuUINT32, rSprm.getId(),
+ rSprm.getId());
+ pTag->addAttr("id", sBuffer);
+ pTag->addAttr("value", rSprm.getValue()->toString());
+
+ resolve(*pTag, rSprm.getProps());
+
+ mpTag->addTag(pTag);
+}
+
+
+XMLTag::Pointer_t unoPropertySetToTag(uno::Reference<beans::XPropertySet> rPropSet)
+{
+ uno::Reference<beans::XPropertySetInfo> xPropSetInfo(rPropSet->getPropertySetInfo());
+ uno::Sequence<beans::Property> aProps(xPropSetInfo->getProperties());
+
+ XMLTag::Pointer_t pResult(new XMLTag("unoPropertySet"));
+
+ for (int i = 0; i < aProps.getLength(); ++i)
+ {
+ XMLTag::Pointer_t pPropTag(new XMLTag("property"));
+
+ ::rtl::OUString sName(aProps[i].Name);
+
+ pPropTag->addAttr("name", sName);
+ try
+ {
+ pPropTag->addAttr("value", rPropSet->getPropertyValue(sName));
+ }
+ catch (uno::Exception aException)
+ {
+ XMLTag::Pointer_t pException(new XMLTag("exception"));
+
+ pException->chars("getPropertyValue(\"");
+ pException->chars(sName);
+ pException->chars("\")");
+ pPropTag->addTag(pException);
+ }
+
+ pResult->addTag(pPropTag);
+ }
+
+ return pResult;
+}
+
+}
diff --git a/writerfilter/source/resourcemodel/WW8Analyzer.cxx b/writerfilter/source/resourcemodel/WW8Analyzer.cxx
new file mode 100644
index 000000000000..75691b5f1483
--- /dev/null
+++ b/writerfilter/source/resourcemodel/WW8Analyzer.cxx
@@ -0,0 +1,216 @@
+/*************************************************************************
+ *
+ * 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 <WW8Analyzer.hxx>
+#include <doctok/resourceids.hxx>
+#include <resourcemodel/QNameToString.hxx>
+
+namespace writerfilter
+{
+bool eqSalUInt32::operator () (sal_uInt32 n1, sal_uInt32 n2) const
+{
+ return n1 == n2;
+}
+
+WW8Analyzer::WW8Analyzer()
+{
+}
+
+WW8Analyzer::~WW8Analyzer()
+{
+ dumpStats(cout);
+}
+
+void WW8Analyzer::attribute(Id name, Value & val)
+{
+ string aAttrName = (*QNameToString::Instance())(name);
+ string aStr;
+
+ if (aAttrName.length() > 6)
+ aStr = aAttrName.substr(4, 2);
+ else
+ logger("DEBUG", "WW8Analyzer::attribute:" + aAttrName);
+
+ bool bAdd = false;
+ if (aStr.compare("LC") == 0 || aStr.compare("FC") == 0)
+ {
+ if (val.getInt() != 0)
+ {
+ bAdd = true;
+ }
+ }
+ else
+ {
+ bAdd = true;
+ }
+
+ if (bAdd)
+ {
+ if (mAttributeMap.count(name) > 0)
+ {
+ sal_uInt32 nCount = mAttributeMap[name] + 1;
+ mAttributeMap[name] = nCount;
+ }
+ else
+ mAttributeMap[name] = 1;
+
+ mAttributeIdSet.insert(name);
+ }
+}
+
+void WW8Analyzer::sprm(Sprm & sprm_)
+{
+ if (mSprmMap.count(sprm_.getId()) > 0)
+ {
+ sal_uInt32 nCount = mSprmMap[sprm_.getId()] + 1;
+ mSprmMap[sprm_.getId()] = nCount;
+ }
+ else
+ mSprmMap[sprm_.getId()] = 1;
+
+ mSprmIdSet.insert(sprm_.getId());
+
+ writerfilter::Reference<Properties>::Pointer_t pProps = sprm_.getProps();
+
+ if (pProps.get() != NULL)
+ {
+ pProps->resolve(*this);
+ }
+
+}
+
+void WW8Analyzer::entry(int /*pos*/, ::writerfilter::Reference<Properties>::Pointer_t ref)
+{
+ ref->resolve(*this);
+}
+
+void WW8Analyzer::data(const sal_uInt8 * /*buf*/, size_t /*len*/,
+ ::writerfilter::Reference<Properties>::Pointer_t /*ref*/)
+{
+}
+
+void WW8Analyzer::startSectionGroup()
+{
+}
+
+void WW8Analyzer::endSectionGroup()
+{
+}
+
+void WW8Analyzer::startParagraphGroup()
+{
+}
+
+void WW8Analyzer::endParagraphGroup()
+{
+}
+
+void WW8Analyzer::startCharacterGroup()
+{
+}
+
+void WW8Analyzer::endCharacterGroup()
+{
+}
+
+void WW8Analyzer::text(const sal_uInt8 * /*data*/, size_t /*len*/)
+{
+}
+
+void WW8Analyzer::utext(const sal_uInt8 * /*data*/, size_t /*len*/)
+{
+}
+
+void WW8Analyzer::props(writerfilter::Reference<Properties>::Pointer_t ref)
+{
+ ref->resolve(*this);
+}
+
+void WW8Analyzer::table(Id /*id*/, writerfilter::Reference<Table>::Pointer_t ref)
+{
+ ref->resolve(*this);
+}
+
+void WW8Analyzer::substream(Id /*name*/,
+ writerfilter::Reference<Stream>::Pointer_t ref)
+{
+ ref->resolve(*this);
+}
+
+void WW8Analyzer::info(const string & /*info*/)
+{
+}
+
+void WW8Analyzer::startShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > /*xShape*/ )
+{
+}
+
+void WW8Analyzer::endShape( )
+{
+}
+
+void WW8Analyzer::dumpStats(ostream & o) const
+{
+ {
+ for (IdSet::const_iterator aIt = mSprmIdSet.begin();
+ aIt != mSprmIdSet.end(); aIt++)
+ {
+ sal_uInt32 aId = *aIt;
+
+ o << "<sprm>" << endl
+ << "<id>" << hex << aId << "</id>" << endl
+ << "<name>" << (*SprmIdToString::Instance())(aId)
+ << "</name>" << endl
+ << "<count>" << dec << mSprmMap[aId] << "</count>"
+ << endl
+ << "</sprm>" << endl;
+ }
+ }
+
+ {
+ for (IdSet::const_iterator aIt = mAttributeIdSet.begin();
+ aIt != mAttributeIdSet.end(); aIt++)
+ {
+ sal_uInt32 aId = *aIt;
+
+ o << "<attribute>" << endl
+ << "<name>" << (*QNameToString::Instance())(aId) << "</name>"
+ << endl
+ << "<count>" << dec << mAttributeMap[aId] << "</count>"
+ << endl
+ << "</attribute>" << endl;
+ }
+ }
+
+}
+
+Stream::Pointer_t createAnalyzer()
+{
+ return Stream::Pointer_t(new WW8Analyzer());
+}
+
+}
diff --git a/writerfilter/source/resourcemodel/WW8Analyzer.hxx b/writerfilter/source/resourcemodel/WW8Analyzer.hxx
new file mode 100644
index 000000000000..a2fc9e4d4b3d
--- /dev/null
+++ b/writerfilter/source/resourcemodel/WW8Analyzer.hxx
@@ -0,0 +1,99 @@
+/*************************************************************************
+ *
+ * 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_WW8_ANALYZER_HXX
+#define INCLUDED_WW8_ANALYZER_HXX
+
+#include <resourcemodel/WW8ResourceModel.hxx>
+
+#include <hash_set>
+#include <map>
+
+namespace writerfilter
+{
+using namespace std;
+
+struct eqSalUInt32
+{
+ bool operator () (sal_uInt32 n1, sal_uInt32 n2) const;
+};
+
+class WW8Analyzer : public Properties, public Table,
+ public BinaryObj, public Stream
+{
+ typedef map<sal_uInt32, sal_uInt32> SprmMap;
+
+ typedef hash_set<sal_uInt32, hash<sal_uInt32>, eqSalUInt32> IdSet;
+ typedef map<Id, sal_uInt32> AttributeMap;
+
+ mutable SprmMap mSprmMap;
+ IdSet mSprmIdSet;
+ mutable AttributeMap mAttributeMap;
+ IdSet mAttributeIdSet;
+
+public:
+ WW8Analyzer();
+ virtual ~WW8Analyzer();
+
+ // Properties
+
+ virtual void attribute(Id Name, Value & val);
+ virtual void sprm(Sprm & sprm);
+
+ // Table
+
+ virtual void entry(int pos, writerfilter::Reference<Properties>::Pointer_t ref);
+
+ // BinaryObj
+
+ virtual void data(const sal_uInt8* buf, size_t len,
+ writerfilter::Reference<Properties>::Pointer_t ref);
+
+ // Stream
+
+ virtual void startSectionGroup();
+ virtual void endSectionGroup();
+ virtual void startParagraphGroup();
+ virtual void endParagraphGroup();
+ virtual void startCharacterGroup();
+ virtual void endCharacterGroup();
+ virtual void text(const sal_uInt8 * data, size_t len);
+ virtual void utext(const sal_uInt8 * data, size_t len);
+ virtual void props(writerfilter::Reference<Properties>::Pointer_t ref);
+ virtual void table(Id name,
+ writerfilter::Reference<Table>::Pointer_t ref);
+ virtual void substream(Id name,
+ writerfilter::Reference<Stream>::Pointer_t ref);
+ virtual void info(const string & info);
+ virtual void startShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape );
+ virtual void endShape( );
+
+ void dumpStats(ostream & o) const;
+};
+}
+
+#endif // INCLUDED_WW8_ANALYZER_HXX
diff --git a/writerfilter/source/resourcemodel/XPathLogger.cxx b/writerfilter/source/resourcemodel/XPathLogger.cxx
new file mode 100644
index 000000000000..89255c8311f8
--- /dev/null
+++ b/writerfilter/source/resourcemodel/XPathLogger.cxx
@@ -0,0 +1,90 @@
+/*************************************************************************
+ *
+ * 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 <stdio.h>
+#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/analyzerfooter b/writerfilter/source/resourcemodel/analyzerfooter
new file mode 100644
index 000000000000..b24a23641b2f
--- /dev/null
+++ b/writerfilter/source/resourcemodel/analyzerfooter
@@ -0,0 +1,4 @@
+ out << "</ids>" << endl;
+}
+
+}
diff --git a/writerfilter/source/resourcemodel/analyzerheader b/writerfilter/source/resourcemodel/analyzerheader
new file mode 100644
index 000000000000..1b4e2674ffab
--- /dev/null
+++ b/writerfilter/source/resourcemodel/analyzerheader
@@ -0,0 +1,36 @@
+/*************************************************************************
+ *
+ * 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 <doctok/resourceids.hxx>
+#include <ooxml/resourceids.hxx>
+#include <resourcemodel/QNameToString.hxx>
+
+namespace writerfilter
+{
+void analyzerIds(::std::iostream & out)
+{
+ out << "<ids>" << endl;
diff --git a/writerfilter/source/resourcemodel/genqnametostr b/writerfilter/source/resourcemodel/genqnametostr
new file mode 100755
index 000000000000..12bad07b9b85
--- /dev/null
+++ b/writerfilter/source/resourcemodel/genqnametostr
@@ -0,0 +1,35 @@
+#!/bin/tcsh
+#************************************************************************
+#
+# 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.
+#
+# ***********************************************************************/
+
+cat qnametostrheader > qnametostr.cxx
+cat ../doctok/qnametostr.tmp >> qnametostr.cxx
+cat ../ooxml/qnametostr.tmp >> qnametostr.cxx
+cat qnametostrfooter >> qnametostr.cxx
+cat sprmcodetostrheader > sprmcodetostr.cxx
+cat ../doctok/sprmcodetostr.tmp >> sprmcodetostr.cxx
+echo "}" >> sprmcodetostr.cxx
diff --git a/writerfilter/source/resourcemodel/makefile.mk b/writerfilter/source/resourcemodel/makefile.mk
new file mode 100644
index 000000000000..1bc260455813
--- /dev/null
+++ b/writerfilter/source/resourcemodel/makefile.mk
@@ -0,0 +1,207 @@
+#************************************************************************
+#
+# 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.
+#
+# ***********************************************************************/
+
+PRJ=..$/..
+PRJNAME=writerfilter
+TARGET=resourcemodel
+#LIBTARGET=NO
+#USE_DEFFILE=TRUE
+ENABLE_EXCEPTIONS=TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+.INCLUDE : $(PRJ)$/inc$/writerfilter.mk
+
+#CFLAGS+=-DISOLATION_AWARE_ENABLED -DWIN32_LEAN_AND_MEAN -DXML_UNICODE -D_NTSDK -DUNICODE -D_UNICODE -D_WIN32_WINNT=0x0501
+#CFLAGS+=-wd4710 -wd4711 -wd4514 -wd4619 -wd4217 -wd4820
+CDEFS+=-DWRITERFILTER_DLLIMPLEMENTATION
+
+
+# --- Files --------------------------------------------------------
+
+# work around gcc taking hours and/or OOM'ing on this file
+NOOPTFILES= \
+ $(SLO)$/qnametostr.obj
+
+SLOFILES= \
+ $(SLO)$/Fraction.obj \
+ $(SLO)$/LoggedResources.obj \
+ $(SLO)$/Protocol.obj \
+ $(SLO)$/ResourceModelHelper.obj \
+ $(SLO)$/TagLogger.obj \
+ $(SLO)$/WW8Analyzer.obj \
+ $(SLO)$/XPathLogger.obj \
+ $(SLO)$/qnametostr.obj \
+ $(SLO)$/resourcemodel.obj \
+ $(SLO)$/sprmcodetostr.obj \
+ $(SLO)$/util.obj \
+
+# linux 64 bit: compiler (gcc 4.2.3) fails with 'out of memory'
+.IF "$(OUTPATH)"=="unxlngx6"
+NOOPTFILES= \
+ $(SLO)$/qnametostr.obj
+.ENDIF
+
+SHL1TARGET=$(TARGET)
+
+.IF "$(GUI)"=="UNX" || "$(GUI)"=="MAC"
+RTFTOKLIB=-lrtftok
+DOCTOKLIB=-ldoctok
+OOXMLLIB=-looxml
+.ELIF "$(GUI)"=="WNT"
+RTFTOKLIB=$(LB)$/irtftok.lib
+DOCTOKLIB=$(LB)$/idoctok.lib
+OOXMLLIB=$(LB)$/iooxml.lib
+.ENDIF
+
+SHL1STDLIBS=$(SALLIB)\
+ $(CPPULIB)\
+ $(CPPUHELPERLIB) \
+ $(COMPHELPERLIB)
+
+SHL1IMPLIB=i$(SHL1TARGET)
+SHL1USE_EXPORTS=name
+
+SHL1OBJS=$(SLOFILES)
+
+SHL1DEF=$(MISC)$/$(SHL1TARGET).def
+DEF1NAME=$(SHL1TARGET)
+DEFLIB1NAME=$(TARGET)
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
+
+RESOURCEMODELCXXOUTDIR=$(MISC)
+DOCTOKHXXOUTDIR=$(INCCOM)$/doctok
+OOXMLHXXOUTDIR=$(INCCOM)$/ooxml
+
+DOCTOKHXXOUTDIRCREATED=$(DOCTOKHXXOUTDIR)$/created
+OOXMLHXXOUTDIRCREATED=$(OOXMLHXXOUTDIR)$/created
+
+OOXMLMODEL=..$/ooxml$/model.xml
+OOXMLPREPROCESSXSL=..$/ooxml$/modelpreprocess.xsl
+OOXMLPREPROCESSXSLCOPIED=$(MISC)$/modelpreprocess.xsl
+OOXMLQNAMETOSTRXSL=..$/ooxml$/qnametostr.xsl
+OOXMLANALYZERXSL=..$/ooxml$/analyzer.xsl
+OOXMLRESOURCEIDSXSL=..$/ooxml$/resourceids.xsl
+OOXMLFACTORYTOOLSXSL=..$/ooxml$/factorytools.xsl
+DOCTOKMODEL=..$/doctok$/resources.xmi
+DOCTOKQNAMETOSTRXSL=..$/doctok$/qnametostr.xsl
+DOCTOKANALYZERXSL=..$/doctok$/analyzer.xsl
+DOCTOKSPRMCODETOSTRXSL=..$/doctok$/sprmcodetostr.xsl
+DOCTOKRESOURCEIDSXSL=..$/doctok$/resourceids.xsl
+DOCTOKSPRMIDSXSL=..$/doctok$/sprmids.xsl
+DOCTOKRESOURCETOOLS=..$/doctok$/resourcetools.xsl
+
+NSPROCESS=namespace_preprocess.pl
+
+MODELPROCESSED=$(MISC)$/model_preprocessed.xml
+
+QNAMETOSTRCXX=$(RESOURCEMODELCXXOUTDIR)$/qnametostr.cxx
+OOXMLQNAMETOSTRTMP=$(RESOURCEMODELCXXOUTDIR)$/OOXMLqnameToStr.tmp
+DOCTOKQNAMETOSTRTMP=$(RESOURCEMODELCXXOUTDIR)$/DOCTOKqnameToStr.tmp
+SPRMCODETOSTRCXX=$(RESOURCEMODELCXXOUTDIR)$/sprmcodetostr.cxx
+SPRMCODETOSTRTMP=$(RESOURCEMODELCXXOUTDIR)$/sprmcodetostr.tmp
+DOCTOKRESOURCEIDSHXX=$(DOCTOKHXXOUTDIR)$/resourceids.hxx
+SPRMIDSHXX=$(DOCTOKHXXOUTDIR)$/sprmids.hxx
+OOXMLRESOURCEIDSHXX=$(OOXMLHXXOUTDIR)$/resourceids.hxx
+
+NSXSL=$(MISC)$/namespacesmap.xsl
+NAMESPACESTXT=$(SOLARVER)$/$(INPATH)$/inc$(UPDMINOREXT)$/oox$/namespaces.txt
+
+GENERATEDHEADERS=$(DOCTOKRESOURCEIDSHXX) $(OOXMLRESOURCEIDSHXX) $(SPRMIDSHXX)
+GENERATEDFILES= \
+ $(GENERATEDHEADERS) \
+ $(QNAMETOSTRCXX) \
+ $(SPRMCODETOSTRCXX) \
+ $(MODELPROCESSED) \
+ $(OOXMLQNAMETOSTRTMP) \
+ $(DOCTOKQNAMETOSTRTMP) \
+ $(SPRMCODETOSTRTMP)
+
+$(OOXMLQNAMETOSTRTMP): $(OOXMLQNAMETOSTRXSL) $(MODELPROCESSED)
+ @echo "Making: " $(@:f)
+ $(XSLTPROC) $(OOXMLQNAMETOSTRXSL:s!\!/!) $(MODELPROCESSED) > $@
+
+$(DOCTOKQNAMETOSTRTMP): $(DOCTOKQNAMETOSTRXSL) $(DOCTOKMODEL)
+ @echo "Making: " $(@:f)
+ $(XSLTPROC) $(DOCTOKQNAMETOSTRXSL:s!\!/!) $(DOCTOKMODEL) > $@
+
+$(QNAMETOSTRCXX): $(OOXMLQNAMETOSTRTMP) $(DOCTOKQNAMETOSTRTMP) qnametostrheader qnametostrfooter $(OOXMLFACTORYTOOLSXSL) $(DOCTOKRESOURCETOOLS)
+ @$(TYPE) qnametostrheader $(OOXMLQNAMETOSTRTMP) $(DOCTOKQNAMETOSTRTMP) qnametostrfooter > $@
+
+$(SPRMCODETOSTRTMP): $(DOCTOKSPRMCODETOSTRXSL) $(DOCTOKMODEL)
+ @echo "Making: " $(@:f)
+ $(XSLTPROC) $(DOCTOKSPRMCODETOSTRXSL:s!\!/!) $(DOCTOKMODEL) > $@
+
+$(SPRMCODETOSTRCXX): sprmcodetostrheader $(SPRMCODETOSTRTMP) sprmcodetostrfooter
+ @$(TYPE) $< > $@
+
+$(SLO)$/sprmcodetostr.obj: $(SPRMCODETOSTRCXX)
+$(SLO)$/qnametostr.obj: $(QNAMETOSTRCXX)
+
+$(SLOFILES): $(GENERATEDHEADERS)
+
+$(DOCTOKHXXOUTDIRCREATED):
+ @$(MKDIRHIER) $(DOCTOKHXXOUTDIR)
+ @$(TOUCH) $@
+
+$(DOCTOKRESOURCEIDSHXX): $(DOCTOKHXXOUTDIRCREATED) $(DOCTOKRESOURCETOOLS) $(DOCTOKRESOURCEIDSXSL) $(DOCTOKMODEL)
+ @echo "Making: " $(@:f)
+ $(COMMAND_ECHO)$(XSLTPROC) $(DOCTOKRESOURCEIDSXSL:s!\!/!) $(DOCTOKMODEL) > $@
+
+$(OOXMLHXXOUTDIRCREATED):
+ @$(MKDIRHIER) $(OOXMLHXXOUTDIR)
+ @$(TOUCH) $@
+
+$(OOXMLPREPROCESSXSLCOPIED): $(OOXMLPREPROCESSXSL)
+ @$(COPY) $(OOXMLPREPROCESSXSL) $@
+
+$(NSXSL) : $(OOXMLMODEL) $(NAMESPACESTXT) $(NSPROCESS)
+ @$(PERL) $(NSPROCESS) $(NAMESPACESTXT) > $@
+
+$(MODELPROCESSED): $(NSXSL) $(OOXMLPREPROCESSXSLCOPIED) $(OOXMLMODEL)
+ @echo "Making: " $(@:f)
+ $(COMMAND_ECHO)$(XSLTPROC) $(NSXSL) $(OOXMLMODEL) > $@
+
+$(OOXMLRESOURCEIDSHXX): $(OOXMLHXXOUTDIRCREATED) $(OOXMLFACTORYTOOLSXSL) $(OOXMLRESOURCEIDSXSL) $(MODELPROCESSED)
+ @echo "Making: " $(@:f)
+ $(COMMAND_ECHO)$(XSLTPROC) $(OOXMLRESOURCEIDSXSL:s!\!/!) $(MODELPROCESSED) > $@
+
+$(SPRMIDSHXX): $(DOCTOKHXXOUTDIRCREATED) $(DOCTOKSPRMIDSXSL) $(DOCTOKMODEL)
+ @echo "Making: " $(@:f)
+ $(COMMAND_ECHO)$(XSLTPROC) $(DOCTOKSPRMIDSXSL:s!\!/!) $(DOCTOKMODEL) > $@
+
+.PHONY: genclean genmake gendirs
+
+genclean:
+ rm -f $(GENERATEDFILES)
+
+genmake: $(GENERATEDFILES)
+
diff --git a/writerfilter/source/resourcemodel/namespace_preprocess.pl b/writerfilter/source/resourcemodel/namespace_preprocess.pl
new file mode 100644
index 000000000000..66644b70fd47
--- /dev/null
+++ b/writerfilter/source/resourcemodel/namespace_preprocess.pl
@@ -0,0 +1,50 @@
+$ARGV0 = shift @ARGV;
+
+print <<EOF;
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:output method="xml"/>
+
+ <xsl:include href="./modelpreprocess.xsl"/>
+
+ <xsl:template match="namespace-alias[\@id]">
+ <xsl:variable name="value">
+ <xsl:call-template name="getnamespaceid">
+ <xsl:with-param name="id" select="\@id" />
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:copy>
+ <xsl:apply-templates select="@*"/>
+ <xsl:attribute name="id">
+ <xsl:value-of select="\$value"/>
+ </xsl:attribute>
+ </xsl:copy>
+ </xsl:template>
+
+ <xsl:template name="getnamespaceid">
+ <xsl:param name='id'/>
+ <xsl:choose>
+EOF
+
+
+# print the mapping
+open ( NAMESPACES, $ARGV0 ) || die "can't open namespace file: $!";
+while ( <NAMESPACES> )
+{
+ chomp( $_ );
+ # line format is: numeric-id short-name namespace-URL
+ $_ =~ /^([0-9]+)\s+([a-zA-Z]+)\s+([a-zA-Z0-9-.:\/]+)\s*$/ or die "Error: invalid character in input data";
+ print <<EOF;
+ <xsl:when test="\$id = '$2'">
+ <xsl:text>$1</xsl:text>
+ </xsl:when>
+EOF
+}
+
+print <<EOF;
+ </xsl:choose>
+ </xsl:template>
+
+</xsl:stylesheet>
+EOF
diff --git a/writerfilter/source/resourcemodel/qnametostrfooter b/writerfilter/source/resourcemodel/qnametostrfooter
new file mode 100644
index 000000000000..d0af0f6fa30f
--- /dev/null
+++ b/writerfilter/source/resourcemodel/qnametostrfooter
@@ -0,0 +1,24 @@
+QNameToString::QNameToString()
+{
+ init_doctok();
+ init_ooxml();
+}
+
+void WRITERFILTER_DLLPUBLIC analyzerIds()
+{
+ cout << "<ids type=\"sprm\">" << endl;
+
+ sprmidsToXML(cout);
+ ooxmlsprmidsToXML(cout);
+
+ cout << "</ids>" << endl;
+
+ cout << "<ids type=\"attribute\">" << endl;
+
+ doctokidsToXML(cout);
+ ooxmlidsToXML(cout);
+
+ cout << "</ids>" << endl;
+}
+
+}
diff --git a/writerfilter/source/resourcemodel/qnametostrheader b/writerfilter/source/resourcemodel/qnametostrheader
new file mode 100644
index 000000000000..6cbd0b3fec10
--- /dev/null
+++ b/writerfilter/source/resourcemodel/qnametostrheader
@@ -0,0 +1,57 @@
+/*************************************************************************
+ *
+ * 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 <doctok/resourceids.hxx>
+#include <ooxml/resourceids.hxx>
+#include <resourcemodel/QNameToString.hxx>
+#include <stdio.h>
+
+namespace writerfilter
+{
+
+QNameToString::Pointer_t QNameToString::pInstance;
+
+QNameToString::Pointer_t WRITERFILTER_DLLPUBLIC QNameToString::Instance()
+{
+ if (pInstance.get() == NULL)
+ pInstance = QNameToString::Pointer_t(new QNameToString());
+
+ return pInstance;
+}
+
+string WRITERFILTER_DLLPUBLIC QNameToString::operator()(Id qName)
+{
+ string sResult;
+
+ Map::const_iterator aIt = mMap.find(qName);
+
+ if (aIt != mMap.end())
+ sResult = aIt->second;
+
+ return mMap[qName];
+}
+
diff --git a/writerfilter/source/resourcemodel/resourcemodel.cxx b/writerfilter/source/resourcemodel/resourcemodel.cxx
new file mode 100644
index 000000000000..096792c76b8e
--- /dev/null
+++ b/writerfilter/source/resourcemodel/resourcemodel.cxx
@@ -0,0 +1,563 @@
+/*************************************************************************
+ *
+ * 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 <stdio.h>
+#include <resourcemodel/WW8ResourceModel.hxx>
+#include <resourcemodel/TableManager.hxx>
+#include <resourcemodel/QNameToString.hxx>
+#include <resourcemodel/exceptions.hxx>
+#include <resourcemodel/SubSequence.hxx>
+#include <resourcemodel/util.hxx>
+#include <resourcemodel.hxx>
+
+namespace writerfilter {
+
+class ResourceModelOutputWithDepth : public OutputWithDepth<string>
+{
+public:
+ ResourceModelOutputWithDepth()
+ : OutputWithDepth<string>("<tablegroup>", "</tablegroup>") {}
+
+ ~ResourceModelOutputWithDepth() {outputGroup();}
+
+ void output(const string & str) const { cout << str << endl; }
+};
+
+ResourceModelOutputWithDepth output;
+
+Stream::Pointer_t createStreamHandler()
+{
+ return Stream::Pointer_t(new WW8StreamHandler());
+}
+
+void dump(OutputWithDepth<string> & /*o*/, const char * /*name*/,
+ writerfilter::Reference<Properties>::Pointer_t /*props*/)
+{
+}
+
+void dump(OutputWithDepth<string> & o, const char * name, sal_uInt32 n)
+{
+ char sBuffer[256];
+ snprintf(sBuffer, sizeof(sBuffer), "%" SAL_PRIuUINT32, n);
+ string tmpStr = name;
+ tmpStr += "=";
+ tmpStr += sBuffer;
+
+ o.addItem(tmpStr);
+}
+
+void dump(OutputWithDepth<string> & /*o*/, const char * /*name*/,
+ const rtl::OUString & /*str*/)
+{
+}
+
+void dump(OutputWithDepth<string> & /*o*/, const char * /*name*/,
+ writerfilter::Reference<BinaryObj>::Pointer_t /*binary*/)
+{
+}
+
+string gInfo = "";
+// ------- WW8TableDataHandler ---------
+
+class TablePropsRef : public writerfilter::Reference<Properties>
+{
+public:
+ typedef boost::shared_ptr<TablePropsRef> Pointer_t;
+
+ TablePropsRef() {}
+ virtual ~TablePropsRef() {}
+
+ virtual void resolve(Properties & /*rHandler*/) {}
+
+ virtual string getType() const { return "TableProps"; }
+ void reset() {}
+ void insert(Pointer_t /* pTablePropsRef */) {}
+};
+
+typedef TablePropsRef::Pointer_t TablePropsRef_t;
+
+class WW8TableDataHandler : public TableDataHandler<string,
+ TablePropsRef_t>
+{
+public:
+ typedef boost::shared_ptr<WW8TableDataHandler> Pointer_t;
+ virtual void startTable(unsigned int nRows, unsigned int nDepth,
+ TablePropsRef_t pProps);
+ virtual void endTable();
+ virtual void startRow(unsigned int nCols,
+ TablePropsRef_t pProps);
+ virtual void endRow();
+ virtual void startCell(const string & start, TablePropsRef_t pProps);
+ virtual void endCell(const string & end);
+};
+
+void WW8TableDataHandler::startTable(unsigned int nRows, unsigned int nDepth,
+ TablePropsRef_t /*pProps*/)
+{
+ char sBuffer[256];
+
+ string tmpStr = "<tabledata.table rows=\"";
+ snprintf(sBuffer, sizeof(sBuffer), "%d", nRows);
+ tmpStr += sBuffer;
+ tmpStr += "\" depth=\"";
+ snprintf(sBuffer, sizeof(sBuffer), "%d", nDepth);
+ tmpStr += sBuffer;
+ tmpStr += "\">";
+
+ output.addItem(tmpStr);
+}
+
+void WW8TableDataHandler::endTable()
+{
+ output.addItem("</tabledata.table>");
+}
+
+void WW8TableDataHandler::startRow
+(unsigned int nCols, TablePropsRef_t /*pProps*/)
+{
+ char sBuffer[256];
+
+ snprintf(sBuffer, sizeof(sBuffer), "%d", nCols);
+ string tmpStr = "<tabledata.row cells=\"";
+ tmpStr += sBuffer;
+ tmpStr += "\">";
+ output.addItem(tmpStr);
+}
+
+void WW8TableDataHandler::endRow()
+{
+ output.addItem("</tabledata.row>");
+}
+
+void WW8TableDataHandler::startCell(const string & start,
+ TablePropsRef_t /*pProps*/)
+{
+ output.addItem("<tabledata.cell>");
+ output.addItem(start);
+ output.addItem(", ");
+}
+
+void WW8TableDataHandler::endCell(const string & end)
+{
+ output.addItem(end);
+ output.addItem("</tabledata.cell>");
+}
+
+// ----- WW8TableDataManager -------------------------------
+
+class WW8TableManager :
+ public TableManager<string, TablePropsRef_t>
+{
+ typedef TableDataHandler<string, TablePropsRef_t>
+ TableDataHandlerPointer_t;
+
+public:
+ WW8TableManager();
+ virtual ~WW8TableManager() {}
+ virtual void endParagraphGroup();
+ virtual bool sprm(Sprm & rSprm);
+};
+
+WW8TableManager::WW8TableManager()
+{
+ TableDataHandler<string, TablePropsRef_t>::Pointer_t pHandler(new WW8TableDataHandler());
+ setHandler(pHandler);
+}
+
+bool WW8TableManager::sprm(Sprm & rSprm)
+{
+ TableManager<string, TablePropsRef_t>::sprm(rSprm);
+ output.setDepth(getTableDepthNew());
+ return true;
+}
+
+void WW8TableManager::endParagraphGroup()
+{
+ string tmpStr = "<tabledepth depth=\"";
+ char sBuffer[256];
+ snprintf(sBuffer, sizeof(sBuffer), "%" SAL_PRIuUINT32, getTableDepthNew());
+ tmpStr += sBuffer;
+ tmpStr += "\"/>";
+ output.addItem(tmpStr);
+ TableManager<string, TablePropsRef_t>::endParagraphGroup();
+}
+
+WW8TableManager gTableManager;
+
+/* WW8StreamHandler */
+
+WW8StreamHandler::WW8StreamHandler()
+: mnUTextCount(0)
+{
+ output.closeGroup();
+ output.addItem("<stream>");
+ gTableManager.startLevel();
+}
+
+WW8StreamHandler::~WW8StreamHandler()
+{
+ gTableManager.endLevel();
+
+ output.closeGroup();
+ output.addItem("</stream>");
+}
+
+void WW8StreamHandler::startSectionGroup()
+{
+ output.addItem("<section-group>");
+}
+
+void WW8StreamHandler::endSectionGroup()
+{
+ output.addItem("</section-group>");
+}
+
+void WW8StreamHandler::startParagraphGroup()
+{
+ output.openGroup();
+ output.addItem("<paragraph-group>");
+
+ gTableManager.startParagraphGroup();
+ gTableManager.handle(gInfo);
+}
+
+void WW8StreamHandler::endParagraphGroup()
+{
+ gTableManager.endParagraphGroup();
+
+ output.addItem("</paragraph-group>");
+ output.closeGroup();
+
+}
+
+void WW8StreamHandler::startCharacterGroup()
+{
+ output.addItem("<character-group>");
+}
+
+void WW8StreamHandler::endCharacterGroup()
+{
+ output.addItem("</character-group>");
+}
+
+void WW8StreamHandler::startShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > /*xShape*/ )
+{
+ output.addItem("<shape>");
+}
+
+void WW8StreamHandler::endShape( )
+{
+ output.addItem( "</shape>" );
+}
+
+void WW8StreamHandler::text(const sal_uInt8 * data, size_t len)
+{
+ string tmpStr = "<text>";
+
+ for (unsigned int n = 0; n < len; ++n)
+ {
+ switch (static_cast<unsigned char>(data[n]))
+ {
+ case '<':
+ tmpStr += "&lt;";
+
+ break;
+ case '>':
+ tmpStr += "&gt;";
+
+ break;
+
+ case '&':
+ tmpStr += "&amp;";
+
+ break;
+ default:
+ if (isprint(data[n]))
+ tmpStr += static_cast<char>(data[n]);
+ else
+ {
+ char sBuffer[256];
+
+ snprintf(sBuffer, sizeof(sBuffer), "\\0x%02x", data[n]);
+
+ tmpStr += sBuffer;
+ }
+ }
+ }
+
+ tmpStr += "</text>";
+
+ output.addItem(tmpStr);
+
+ gTableManager.text(data, len);
+}
+
+void WW8StreamHandler::utext(const sal_uInt8 * data, size_t len)
+{
+ static char sBuffer[256];
+ snprintf(sBuffer, sizeof(sBuffer), "<utext count=\"%d\">", mnUTextCount);
+ string tmpStr(sBuffer);
+
+ for (unsigned int n = 0; n < len; ++n)
+ {
+ sal_Unicode nChar = data[n * 2] + (data[n * 2 + 1] << 8);
+ if (nChar < 0xff && isprint(nChar))
+ {
+ switch (nChar)
+ {
+ case '&':
+ tmpStr += "&amp;";
+ break;
+ case '<':
+ tmpStr += "&lt;";
+ break;
+ case '>':
+ tmpStr += "&gt;";
+ break;
+ default:
+ tmpStr += static_cast<char>(nChar);
+ }
+ }
+ else
+ {
+ snprintf(sBuffer, sizeof(sBuffer), "\\0x%04x", nChar);
+
+ tmpStr += sBuffer;
+ }
+ }
+
+ tmpStr += "</utext>";
+
+ output.addItem(tmpStr);
+
+ gTableManager.utext(data, len);
+
+ mnUTextCount++;
+}
+
+void WW8StreamHandler::props(writerfilter::Reference<Properties>::Pointer_t ref)
+{
+ WW8PropertiesHandler aHandler;
+
+ output.addItem("<properties type=\"" + ref->getType() + "\">");
+ ref->resolve(aHandler);
+
+ //gTableManager.props(ref);
+
+ output.addItem("</properties>");
+}
+
+void WW8StreamHandler::table(Id name, writerfilter::Reference<Table>::Pointer_t ref)
+{
+ WW8TableHandler aHandler;
+
+ output.addItem("<table id=\"" + (*QNameToString::Instance())(name)
+ + "\">");
+
+ try
+ {
+ ref->resolve(aHandler);
+ }
+ catch (Exception e)
+ {
+ output.addItem("<exception>" + e.getText() + "</exception>");
+ }
+
+ output.addItem("</table>");
+}
+
+void WW8StreamHandler::substream(Id name,
+ writerfilter::Reference<Stream>::Pointer_t ref)
+{
+ output.addItem("<substream name=\"" + (*QNameToString::Instance())(name)
+ + "\">");
+
+ gTableManager.startLevel();
+
+ ref->resolve(*this);
+
+ gTableManager.endLevel();
+
+ output.addItem("</substream>");
+}
+
+void WW8StreamHandler::info(const string & info_)
+{
+ gInfo = info_;
+ output.addItem("<info>" + info_ + "</info>");
+}
+
+void WW8PropertiesHandler::attribute(Id name, Value & val)
+{
+ boost::shared_ptr<rtl::OString> pStr(new ::rtl::OString());
+ ::rtl::OUString aStr = val.getString();
+ aStr.convertToString(pStr.get(), RTL_TEXTENCODING_ASCII_US,
+ OUSTRING_TO_OSTRING_CVTFLAGS);
+ string sXMLValue = xmlify(pStr->getStr());
+
+ char sBuffer[256];
+ snprintf(sBuffer, sizeof(sBuffer), "0x%x", val.getInt());
+
+ output.addItem("<attribute name=\"" +
+ (*QNameToString::Instance())(name) +
+ "\" value=\"" +
+ sXMLValue +
+ + "\" hexvalue=\""
+ + sBuffer + "\">");
+
+ writerfilter::Reference<Properties>::Pointer_t pProps = val.getProperties();
+
+ if (pProps.get() != NULL)
+ {
+ output.addItem("<properties name=\"" +
+ (*QNameToString::Instance())(name)
+ + "\" type=\"" + pProps->getType() + "\">");
+
+ try
+ {
+ pProps->resolve(*this);
+ }
+ catch (ExceptionOutOfBounds e)
+ {
+ }
+
+ output.addItem("</properties>");
+ }
+
+ writerfilter::Reference<Stream>::Pointer_t pStream = val.getStream();
+
+ if (pStream.get() != NULL)
+ {
+ try
+ {
+ WW8StreamHandler aHandler;
+
+ pStream->resolve(aHandler);
+ }
+ catch (ExceptionOutOfBounds e)
+ {
+ }
+ }
+
+ writerfilter::Reference<BinaryObj>::Pointer_t pBinObj = val.getBinary();
+
+ if (pBinObj.get() != NULL)
+ {
+ try
+ {
+ WW8BinaryObjHandler aHandler;
+
+ pBinObj->resolve(aHandler);
+ }
+ catch (ExceptionOutOfBounds e)
+ {
+ }
+ }
+
+ output.addItem("</attribute>");
+}
+
+void WW8PropertiesHandler::sprm(Sprm & sprm_)
+{
+ string tmpStr = "<sprm id=\"";
+ char buffer[256];
+ snprintf(buffer, sizeof(buffer), "0x%" SAL_PRIxUINT32, sprm_.getId());
+ tmpStr += buffer;
+ tmpStr += "\" name=\"";
+ tmpStr += sprm_.getName();
+ tmpStr += "\">";
+ output.addItem(tmpStr);
+ output.addItem(sprm_.toString());
+
+ writerfilter::Reference<Properties>::Pointer_t pProps = sprm_.getProps();
+
+ if (pProps.get() != NULL)
+ {
+ output.addItem("<properties type=\"" + pProps->getType() + "\">");
+ pProps->resolve(*this);
+ output.addItem("</properties>");
+ }
+
+ writerfilter::Reference<BinaryObj>::Pointer_t pBinObj = sprm_.getBinary();
+
+ if (pBinObj.get() != NULL)
+ {
+ output.addItem("<binary>");
+ WW8BinaryObjHandler aHandler;
+ pBinObj->resolve(aHandler);
+ output.addItem("</binary>");
+ }
+
+ writerfilter::Reference<Stream>::Pointer_t pStream = sprm_.getStream();
+
+ if (pStream.get() != NULL)
+ {
+ output.addItem("<stream>");
+ WW8StreamHandler aHandler;
+ pStream->resolve(aHandler);
+ output.addItem("</stream>");
+ }
+
+ gTableManager.sprm(sprm_);
+
+ output.addItem("</sprm>");
+}
+
+void WW8TableHandler::entry(int /*pos*/,
+ writerfilter::Reference<Properties>::Pointer_t ref)
+{
+ output.addItem("<tableentry>");
+
+ WW8PropertiesHandler aHandler;
+
+ try
+ {
+ ref->resolve(aHandler);
+ }
+ catch (Exception e)
+ {
+ output.addItem("<exception>" + e.getText() + "</exception>");
+ output.addItem("</tableentry>");
+
+ throw e;
+ }
+
+ output.addItem("</tableentry>");
+}
+
+void WW8BinaryObjHandler::data
+(const sal_uInt8 * buf, size_t length,
+ writerfilter::Reference<Properties>::Pointer_t /*pRef*/)
+{
+#if 1
+ SubSequence<sal_uInt8> aSeq(buf, length);
+
+ aSeq.dump(output);
+#endif
+}
+
+}
diff --git a/writerfilter/source/resourcemodel/resourcemodel.hxx b/writerfilter/source/resourcemodel/resourcemodel.hxx
new file mode 100644
index 000000000000..9f59e68b9e1f
--- /dev/null
+++ b/writerfilter/source/resourcemodel/resourcemodel.hxx
@@ -0,0 +1,110 @@
+/*************************************************************************
+ *
+ * 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/WW8ResourceModel.hxx>
+
+namespace writerfilter {
+class WW8StreamHandler : public Stream
+{
+ int mnUTextCount;
+
+public:
+ WW8StreamHandler();
+ virtual ~WW8StreamHandler();
+
+ virtual void startSectionGroup();
+ virtual void endSectionGroup();
+ virtual void startParagraphGroup();
+ virtual void endParagraphGroup();
+ virtual void startCharacterGroup();
+ virtual void endCharacterGroup();
+ virtual void text(const sal_uInt8 * data, size_t len);
+ virtual void utext(const sal_uInt8 * data, size_t len);
+
+ virtual void props(writerfilter::Reference<Properties>::Pointer_t ref);
+ virtual void table(Id name,
+ writerfilter::Reference<Table>::Pointer_t ref);
+
+ virtual void startShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape );
+ virtual void endShape( );
+
+ virtual void substream(Id name, writerfilter::Reference<Stream>::Pointer_t ref);
+
+ virtual void info(const string & info);
+};
+
+class WW8PropertiesHandler : public Properties
+{
+ typedef boost::shared_ptr<Sprm> SprmSharedPointer_t;
+ typedef vector<SprmSharedPointer_t> SprmPointers_t;
+ SprmPointers_t sprms;
+
+public:
+ WW8PropertiesHandler()
+ {
+ }
+
+ virtual ~WW8PropertiesHandler()
+ {
+ }
+
+ virtual void attribute(Id name, Value & val);
+ virtual void sprm(Sprm & sprm);
+
+ void dumpSprm(SprmSharedPointer_t sprm);
+ void dumpSprms();
+};
+
+class WW8BinaryObjHandler : public BinaryObj
+{
+public:
+ WW8BinaryObjHandler()
+ {
+ }
+
+ virtual ~WW8BinaryObjHandler()
+ {
+ }
+
+ virtual void data(const sal_uInt8* buf, size_t len,
+ writerfilter::Reference<Properties>::Pointer_t ref);
+};
+
+class WW8TableHandler : public Table
+{
+public:
+ WW8TableHandler()
+ {
+ }
+
+ virtual ~WW8TableHandler()
+ {
+ }
+
+ void entry(int pos, writerfilter::Reference<Properties>::Pointer_t ref);
+};
+
+}
diff --git a/writerfilter/source/resourcemodel/setdebugflags b/writerfilter/source/resourcemodel/setdebugflags
new file mode 100755
index 000000000000..dafa563d7a7d
--- /dev/null
+++ b/writerfilter/source/resourcemodel/setdebugflags
@@ -0,0 +1,3 @@
+#!/bin/tcsh
+
+setenv ENFCLAGS "-DDEBUG_ELEMENT -DDEBUG_ATTRIBUTES -DDEBUG_PROPERTIES -DDEBUG_CONTEXT_STACK -DDEBUG_CREATE -DDEBUG_DOMAINMAPPER"
diff --git a/writerfilter/source/resourcemodel/sprmcodetostrfooter b/writerfilter/source/resourcemodel/sprmcodetostrfooter
new file mode 100644
index 000000000000..5c34318c2147
--- /dev/null
+++ b/writerfilter/source/resourcemodel/sprmcodetostrfooter
@@ -0,0 +1 @@
+}
diff --git a/writerfilter/source/resourcemodel/sprmcodetostrheader b/writerfilter/source/resourcemodel/sprmcodetostrheader
new file mode 100644
index 000000000000..ff0663e30bde
--- /dev/null
+++ b/writerfilter/source/resourcemodel/sprmcodetostrheader
@@ -0,0 +1,50 @@
+/*************************************************************************
+ *
+ * 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 <doctok/resourceids.hxx>
+#include <ooxml/resourceids.hxx>
+#include <resourcemodel/QNameToString.hxx>
+#include <doctok/sprmids.hxx>
+
+namespace writerfilter
+{
+
+SprmIdToString::Pointer_t SprmIdToString::pInstance;
+
+SprmIdToString::Pointer_t SprmIdToString::Instance()
+{
+ if (pInstance.get() == NULL)
+ pInstance = SprmIdToString::Pointer_t(new SprmIdToString());
+
+ return pInstance;
+}
+
+string SprmIdToString::operator()(sal_uInt32 nId)
+{
+ return mMap[nId];
+}
+
diff --git a/writerfilter/source/resourcemodel/util.cxx b/writerfilter/source/resourcemodel/util.cxx
new file mode 100644
index 000000000000..3d041d18c126
--- /dev/null
+++ b/writerfilter/source/resourcemodel/util.cxx
@@ -0,0 +1,427 @@
+/*************************************************************************
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <fstream>
+#include <string>
+#include <com/sun/star/awt/Point.hpp>
+#include <com/sun/star/awt/Rectangle.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/drawing/BitmapMode.hpp>
+#include <com/sun/star/drawing/FillStyle.hpp>
+#include <com/sun/star/drawing/HomogenMatrix3.hpp>
+#include <com/sun/star/text/TextContentAnchorType.hpp>
+#include <resourcemodel/WW8ResourceModel.hxx>
+#include <resourcemodel/TagLogger.hxx>
+#include <resourcemodel/util.hxx>
+
+namespace writerfilter
+{
+using namespace com::sun::star;
+using namespace std;
+using text::TextContentAnchorType;
+
+static string & logger_file()
+{
+ static string _logger_file = string(getenv("TEMP")?getenv("TEMP"):"/tmp") + "/writerfilter.ooxml.tmp";
+ return _logger_file;
+}
+
+static ofstream & logger_stream()
+{
+ static ofstream _logger_stream(logger_file().c_str());
+ return _logger_stream;
+}
+
+
+void logger(string prefix, string message)
+{
+ logger_stream() << prefix << ":" << message << endl;
+ logger_stream().flush();
+}
+
+ string xmlify(const string & str)
+ {
+ string result = "";
+ char sBuffer[16];
+
+ for (string::const_iterator aIt = str.begin(); aIt != str.end(); ++aIt)
+ {
+ char c = *aIt;
+
+ if (isprint(c) && c != '\"')
+ {
+ if (c == '<')
+ result += "&lt;";
+ else if (c == '>')
+ result += "&gt;";
+ else if (c == '&')
+ result += "&amp;";
+ else
+ result += c;
+ }
+ else
+ {
+ snprintf(sBuffer, sizeof(sBuffer), "\\%03d", c);
+ result += sBuffer;
+ }
+ }
+
+ return result;
+ }
+
+#ifdef DEBUG
+string propertysetToString(uno::Reference<beans::XPropertySet> const & xPropSet)
+{
+ string sResult;
+
+ static int nAttribNames = 9;
+ static string sPropertyAttribNames[9] =
+ {
+ "MAYBEVOID",
+ "BOUND",
+ "CONSTRAINED",
+ "TRANSIENT",
+ "READONLY",
+ "MAYBEAMBIGUOUS",
+ "MAYBEDEFAULT",
+ "REMOVEABLE",
+ "OPTIONAL"
+ };
+
+ static const ::rtl::OUString sMetaFile(RTL_CONSTASCII_USTRINGPARAM("MetaFile"));
+
+ uno::Reference<beans::XPropertySetInfo> xPropSetInfo
+ (xPropSet->getPropertySetInfo());
+
+ if (xPropSetInfo.is())
+ {
+ uno::Sequence<beans::Property> aProps(xPropSetInfo->getProperties());
+
+ sResult +="<propertyset>";
+
+ for (sal_Int32 n = 0; n < aProps.getLength(); n++)
+ {
+ ::rtl::OUString sPropName(aProps[n].Name);
+
+ if (xPropSetInfo->hasPropertyByName(sPropName))
+ {
+ bool bPropertyFound = true;
+ uno::Any aAny;
+ try
+ {
+ if (sPropName == sMetaFile)
+ bPropertyFound = false;
+ else
+ xPropSet->getPropertyValue(sPropName) >>= aAny;
+ }
+ catch (beans::UnknownPropertyException)
+ {
+ bPropertyFound = false;
+ }
+
+ if (bPropertyFound)
+ {
+ sResult += "<property name=\"";
+ sResult += OUStringToOString
+ (sPropName, RTL_TEXTENCODING_ASCII_US).getStr();
+ sResult +="\" type=\"";
+
+ ::rtl::OUString sPropType(aProps[n].Type.getTypeName());
+ sResult += OUStringToOString
+ (sPropType, RTL_TEXTENCODING_ASCII_US).getStr();
+
+ sResult += "\" attribs=\"";
+
+ sal_uInt16 nMask = 1;
+ bool bFirstAttrib = true;
+ sal_uInt16 nAttribs = aProps[n].Attributes;
+ for (int i = 0; i < nAttribNames; i++)
+ {
+ if ((nAttribs & nMask) != 0)
+ {
+ if (bFirstAttrib)
+ bFirstAttrib = false;
+ else
+ sResult += "|";
+
+ sResult += sPropertyAttribNames[i];
+ }
+
+ nMask <<= 1;
+ }
+
+ sResult += "\">";
+
+ char buffer[256];
+ if (sPropType ==
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
+ ("byte")))
+ {
+ sal_Int8 nValue = 0;
+ aAny >>= nValue;
+
+ snprintf(buffer, sizeof(buffer), "%d", nValue);
+ sResult += buffer;
+ }
+ if (sPropType ==
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
+ ("short")))
+ {
+ sal_Int16 nValue = 0;
+ aAny >>= nValue;
+
+ snprintf(buffer, sizeof(buffer), "%d", nValue);
+ sResult += buffer;
+ }
+ else if (sPropType ==
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
+ ("long")))
+ {
+ sal_Int32 nValue = 0;
+ aAny >>= nValue;
+
+ snprintf(buffer, sizeof(buffer), "%" SAL_PRIdINT32, nValue);
+ sResult += buffer;
+ }
+ else if (sPropType ==
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
+ ("float")))
+ {
+ float nValue = 0.0;
+ aAny >>= nValue;
+
+ snprintf(buffer, sizeof(buffer), "%f", nValue);
+ sResult += buffer;
+ }
+ else if (sPropType ==
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
+ ("double")))
+ {
+ double nValue = 0.0;
+ aAny >>= nValue;
+
+ snprintf(buffer, sizeof(buffer), "%lf", nValue);
+ sResult += buffer;
+ }
+ else if (sPropType ==
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
+ ("boolean")))
+ {
+ sal_Bool nValue = sal_False;
+ aAny >>= nValue;
+
+ if (nValue)
+ sResult += "true";
+ else
+ sResult += "false";
+ }
+ else if (sPropType ==
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
+ ("string")))
+ {
+ ::rtl::OUString sValue;
+ aAny >>= sValue;
+
+ sResult += OUStringToOString
+ (sValue, RTL_TEXTENCODING_ASCII_US).getStr();
+ }
+ else if (sPropType ==
+ ::rtl::OUString
+ (RTL_CONSTASCII_USTRINGPARAM
+ ("com.sun.star.text.TextContentAnchorType")))
+ {
+ text::TextContentAnchorType nValue;
+ aAny >>= nValue;
+
+ switch (nValue)
+ {
+ case text::TextContentAnchorType_AT_PARAGRAPH:
+ sResult += "AT_PARAGRAPH";
+ break;
+ case text::TextContentAnchorType_AS_CHARACTER:
+ sResult += "AS_CHARACTER";
+ break;
+ case text::TextContentAnchorType_AT_PAGE:
+ sResult += "AT_PAGE";
+ break;
+ case text::TextContentAnchorType_AT_FRAME:
+ sResult += "AT_FRAME";
+ break;
+ case text::TextContentAnchorType_AT_CHARACTER:
+ sResult += "AT_CHARACTER";
+ break;
+ case text::TextContentAnchorType_MAKE_FIXED_SIZE:
+ sResult += "MAKE_FIXED_SIZE";
+ break;
+ default:
+ break;
+ }
+ }
+ else if (sPropType ==
+ ::rtl::OUString
+ (RTL_CONSTASCII_USTRINGPARAM
+ ("com.sun.star.awt.Point")))
+ {
+ awt::Point aPoint;
+ aAny >>= aPoint;
+
+ snprintf(buffer, sizeof(buffer), "(%" SAL_PRIdINT32 ", %" SAL_PRIdINT32 ")", aPoint.X,
+ aPoint.Y);
+
+ sResult += buffer;
+ }
+ else if (sPropType ==
+ ::rtl::OUString
+ (RTL_CONSTASCII_USTRINGPARAM
+ ("com.sun.star.awt.Rectangle")))
+ {
+ awt::Rectangle aRect;
+ aAny >>= aRect;
+
+ snprintf(buffer, sizeof(buffer), "(%" SAL_PRIdINT32 ", %" SAL_PRIdINT32 ", %" SAL_PRIdINT32 ", %" SAL_PRIdINT32 ")",
+ aRect.X, aRect.Y, aRect.Width, aRect.Height);
+ sResult += buffer;
+ }
+ else if (sPropType ==
+ ::rtl::OUString
+ (RTL_CONSTASCII_USTRINGPARAM
+ ("com.sun.star.drawing.FillStyle")))
+ {
+ drawing::FillStyle nValue;
+ aAny >>= nValue;
+
+ switch (nValue)
+ {
+ case drawing::FillStyle_NONE:
+ sResult += "NONE";
+ break;
+ case drawing::FillStyle_SOLID:
+ sResult += "SOLID";
+ break;
+ case drawing::FillStyle_GRADIENT:
+ sResult += "GRADIENT";
+ break;
+ case drawing::FillStyle_HATCH:
+ sResult += "HATCH";
+ break;
+ case drawing::FillStyle_BITMAP:
+ sResult += "BITMAP";
+ break;
+ case drawing::FillStyle_MAKE_FIXED_SIZE:
+ sResult += "MAKE_FIXED_SIZE";
+ break;
+ }
+ }
+ else if (sPropType ==
+ ::rtl::OUString
+ (RTL_CONSTASCII_USTRINGPARAM
+ ("com.sun.star.drawing.BitmapMode")))
+ {
+ drawing::BitmapMode nValue;
+ aAny >>= nValue;
+
+ switch (nValue)
+ {
+ case drawing::BitmapMode_REPEAT:
+ sResult += "REPEAT";
+ break;
+ case drawing::BitmapMode_STRETCH:
+ sResult += "STRETCH";
+ break;
+ case drawing::BitmapMode_NO_REPEAT:
+ sResult += "NO_REPEAT";
+ break;
+ case drawing::BitmapMode_MAKE_FIXED_SIZE:
+ sResult += "MAKE_FIXED_SIZE";
+ break;
+ }
+ }
+ else if (sPropType ==
+ ::rtl::OUString
+ (RTL_CONSTASCII_USTRINGPARAM
+ ("com.sun.star.drawing.HomogenMatrix3")))
+ {
+ drawing::HomogenMatrix3 aMatrix;
+ aAny >>= aMatrix;
+
+ snprintf(buffer, sizeof(buffer),
+ "((%f %f %f)(%f %f %f)(%f %f %f))",
+ aMatrix.Line1.Column1,
+ aMatrix.Line1.Column2,
+ aMatrix.Line1.Column3,
+ aMatrix.Line2.Column1,
+ aMatrix.Line2.Column2,
+ aMatrix.Line2.Column3,
+ aMatrix.Line3.Column1,
+ aMatrix.Line3.Column2,
+ aMatrix.Line3.Column3);
+ sResult += buffer;
+ }
+
+ sResult += "</property>";
+ }
+ }
+ else
+ {
+ sResult += "<unknown-property>";
+ sResult += OUStringToOString
+ (sPropName, RTL_TEXTENCODING_ASCII_US).getStr();
+ sResult += "</unknown-property>";
+ }
+ }
+ sResult += "</propertyset>";
+ }
+
+ return sResult;
+}
+
+string toString(uno::Reference< text::XTextRange > textRange)
+{
+ string result;
+
+ if (textRange.get())
+ {
+ rtl::OUString aOUStr = textRange->getString();
+ rtl::OString aOStr(aOUStr.getStr(), aOUStr.getLength(), RTL_TEXTENCODING_ASCII_US );
+
+ result = aOStr.getStr();
+ }
+ else
+ {
+ result="(nil)";
+ }
+
+ return result;
+}
+
+string toString(const string & rString)
+{
+ return rString;
+}
+#endif
+}