summaryrefslogtreecommitdiff
path: root/writerfilter/source/ooxml/OOXMLFactory.cxx
diff options
context:
space:
mode:
authorHenning Brinkmann <hbrinkm@openoffice.org>2009-07-31 13:23:57 +0200
committerHenning Brinkmann <hbrinkm@openoffice.org>2009-07-31 13:23:57 +0200
commit4f16cedfc635fa02b5a4770009d2ba0a82372c09 (patch)
tree1d30a856d9b736e958801f95142d3b050c1b4135 /writerfilter/source/ooxml/OOXMLFactory.cxx
parent9d1bb23a6e6e93aba40f6a813d224acc888a7b32 (diff)
Factory for the new model of generating the OOXML scanner
Diffstat (limited to 'writerfilter/source/ooxml/OOXMLFactory.cxx')
-rw-r--r--writerfilter/source/ooxml/OOXMLFactory.cxx223
1 files changed, 223 insertions, 0 deletions
diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx
new file mode 100644
index 000000000..e2fc4cd03
--- /dev/null
+++ b/writerfilter/source/ooxml/OOXMLFactory.cxx
@@ -0,0 +1,223 @@
+/*************************************************************************
+ *
+ * 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
+ *
+ * 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/instance.hxx>
+#include <osl/mutex.hxx>
+#include "OOXMLFactory.hxx"
+#include "OOXMLFastHelper.hxx"
+
+namespace writerfilter {
+namespace ooxml {
+
+CreateElement::CreateElement()
+:m_nResource(RT_NoResource), m_nId(0)
+{
+}
+
+CreateElement::CreateElement(ResourceType_t nResource, Id nId)
+: m_nResource(nResource), m_nId(nId)
+{
+}
+
+// class OOXMLFactory_ns
+
+AttributeToResourceMapPointer OOXMLFactory_ns::getAttributeToResourceMap(Id nId)
+{
+ if (m_AttributesMap.find(nId) == m_AttributesMap.end())
+ m_AttributesMap[nId] = createAttributeToResourceMap(nId);
+
+ return m_AttributesMap[nId];
+}
+
+ListValueMapPointer OOXMLFactory_ns::getListValueMap(Id nId)
+{
+ if (m_ListValuesMap.find(nId) == m_ListValuesMap.end())
+ m_ListValuesMap[nId] = createListValueMap(nId);
+
+ return m_ListValuesMap[nId];
+}
+
+CreateElementMapPointer OOXMLFactory_ns::getCreateElementMap(Id nId)
+{
+ if (m_CreateElementsMap.find(nId) == m_CreateElementsMap.end())
+ m_CreateElementsMap[nId] = createCreateElementMap(nId);
+
+ return m_CreateElementsMap[nId];
+}
+
+TokenToIdMapPointer OOXMLFactory_ns::getTokenToIdMap(Id nId)
+{
+ if (m_TokenToIdsMap.find(nId) == m_TokenToIdsMap.end())
+ m_TokenToIdsMap[nId] = createTokenToIdMap(nId);
+
+ return m_TokenToIdsMap[nId];
+}
+
+string OOXMLFactory_ns::getDefineName(Id /*nId*/) const
+{
+ return "";
+}
+
+// class OOXMLFactory
+
+typedef rtl::Static< osl::Mutex, OOXMLFactory > OOXMLFactory_Mutex;
+
+OOXMLFactory::Pointer_t OOXMLFactory::m_Instance;
+
+OOXMLFactory::OOXMLFactory()
+{
+ // multi-thread-safe mutex for all platforms
+
+ osl::MutexGuard aGuard(OOXMLFactory_Mutex::get());
+}
+
+OOXMLFactory::~OOXMLFactory()
+{
+}
+
+OOXMLFactory::Pointer_t OOXMLFactory::getInstance()
+{
+ if (m_Instance.get() == NULL)
+ m_Instance.reset(new OOXMLFactory());
+
+ return m_Instance;
+}
+
+void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler,
+ const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
+{
+ Id nId = pHandler->getId();
+ OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nId);
+
+ if (pFactory.get() != NULL)
+ {
+#ifdef DEBUG_ATTRIBUTES
+ debug_logger->startElement("attributes");
+ debug_logger->attribute("define", pFactory->getDefineName(nId));
+#endif
+
+ AttributeToResourceMapPointer pMap = pFactory->getAttributeToResourceMap(nId);
+
+ AttributeToResourceMap::const_iterator aIt;
+ AttributeToResourceMap::const_iterator aEndIt = pMap->end();
+
+ for (aIt = pMap->begin(); aIt != aEndIt; aIt++)
+ {
+ if (Attribs->hasAttribute(aIt->first))
+ {
+ switch (aIt->second)
+ {
+ case RT_Boolean:
+ {
+ ::rtl::OUString aValue(Attribs->getValue(aIt->first));
+ OOXMLFastHelper<OOXMLBooleanValue>::newProperty(pHandler, aIt->first, aValue);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+#ifdef DEBUG_ATTRIBUTES
+ debug_logger->endElement("attributes");
+#endif
+ }
+}
+
+uno::Reference< xml::sax::XFastContextHandler>
+OOXMLFactory::createFastChildContext(OOXMLFastContextHandler * pHandler,
+ Token_t Element)
+{
+ Id nDefine = pHandler->getDefine();
+
+ OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
+
+ return createFastChildContextFromFactory(pHandler, pFactory, Element);
+}
+
+void OOXMLFactory::characters(OOXMLFastContextHandler * pHandler,
+ const ::rtl::OUString & rString)
+{
+ Id nDefine = pHandler->getDefine();
+ OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
+
+ if (pFactory.get() != NULL)
+ {
+ pFactory->charactersAction(pHandler, rString);
+ }
+}
+
+void OOXMLFactory::startAction(OOXMLFastContextHandler * pHandler, Token_t /*nToken*/)
+{
+ Id nDefine = pHandler->getDefine();
+ OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
+
+ if (pFactory.get() != NULL)
+ {
+#ifdef DEBUG_ELEMENT
+ debug_logger->startElement("factory-startAction");
+#endif
+ pFactory->startAction(pHandler);
+#ifdef DEBUG_ELEMENT
+ debug_logger->endElement("factory-startAction");
+#endif
+ }
+}
+
+void OOXMLFactory::endAction(OOXMLFastContextHandler * pHandler, Token_t nToken)
+{
+ Id nDefine = pHandler->getDefine();
+ OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine);
+
+ if (pFactory.get() != NULL)
+ {
+#ifdef DEBUG_ELEMENT
+ debug_logger->startElement("factory-endAction");
+#endif
+ pFactory->endAction(pHandler);
+#ifdef DEBUG_ELEMENT
+ debug_logger->endElement("factory-endAction");
+#endif
+ }
+}
+
+void OOXMLFactory_ns::startAction(OOXMLFastContextHandler *)
+{
+}
+
+void OOXMLFactory_ns::endAction(OOXMLFastContextHandler *)
+{
+}
+
+void OOXMLFactory_ns::charactersAction(OOXMLFastContextHandler *, const ::rtl::OUString &)
+{
+}
+
+}
+}
+