[Libreoffice-commits] core.git: writerfilter/CustomTarget_source.mk writerfilter/source
Miklos Vajna
vmiklos at collabora.co.uk
Sun Jul 27 08:54:55 PDT 2014
writerfilter/CustomTarget_source.mk | 11
writerfilter/source/ooxml/factoryimpl_ns.py | 715 ++++++++++++++++++++
writerfilter/source/ooxml/factoryimpl_ns.xsl | 945 ---------------------------
writerfilter/source/ooxml/factorytools.xsl | 262 -------
4 files changed, 719 insertions(+), 1214 deletions(-)
New commits:
commit 821ab16a1fb0353397914131ab559685d12b92b7
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Sun Jul 27 17:46:42 2014 +0200
writerfilter: convert factoryimpl_ns to Python
Change-Id: Ia2380a23e31583f40a368168bc09d7fddd3e4ab7
diff --git a/writerfilter/CustomTarget_source.mk b/writerfilter/CustomTarget_source.mk
index b84e235..6ff9c09 100644
--- a/writerfilter/CustomTarget_source.mk
+++ b/writerfilter/CustomTarget_source.mk
@@ -12,7 +12,6 @@ $(eval $(call gb_CustomTarget_CustomTarget,writerfilter/source))
writerfilter_WORK := $(call gb_CustomTarget_get_workdir,writerfilter/source)
writerfilter_SRC := $(SRCDIR)/writerfilter/source
-writerfilter_XSLTCOMMAND := $(call gb_ExternalExecutable_get_command,xsltproc)
writerfilter_PYTHONCOMMAND := $(call gb_ExternalExecutable_get_command,python)
writerfilter_OOXMLNAMESPACES= \
@@ -66,11 +65,9 @@ writerfilter_GEN_ooxml_FastTokens_hxx=$(writerfilter_WORK)/ooxml/OOXMLFastTokens
writerfilter_GEN_ooxml_GperfFastToken_hxx=$(writerfilter_WORK)/ooxml/gperffasttoken.hxx
writerfilter_GEN_ooxml_Model_processed=$(writerfilter_WORK)/ooxml/model_preprocessed.xml
writerfilter_GEN_ooxml_NamespaceIds_hxx=$(writerfilter_WORK)/ooxml/OOXMLnamespaceids.hxx
-writerfilter_GEN_ooxml_Namespacesmap_xsl=$(writerfilter_WORK)/ooxml/namespacesmap.xsl
writerfilter_GEN_ooxml_QNameToStr_cxx=$(writerfilter_WORK)/ooxml/qnametostr.cxx
writerfilter_GEN_ooxml_ResourceIds_hxx=$(writerfilter_WORK)/ooxml/resourceids.hxx
writerfilter_GEN_ooxml_Token_xml=$(writerfilter_WORK)/ooxml/token.xml
-writerfilter_SRC_ooxml_FactoryTools_xsl=$(writerfilter_SRC)/ooxml/factorytools.xsl
writerfilter_SRC_ooxml_FactoryValues_py=$(writerfilter_SRC)/ooxml/factory_values.py
writerfilter_SRC_ooxml_FastTokens_py=$(writerfilter_SRC)/ooxml/fasttokens.py
writerfilter_SRC_ooxml_GperfFastTokenHandler_py=$(writerfilter_SRC)/ooxml/gperffasttokenhandler.py
@@ -121,9 +118,9 @@ $(writerfilter_GEN_ooxml_Token_xml) : $(SRCDIR)/oox/source/token/tokens.txt $(wr
sed -f $(writerfilter_SRC)/ooxml/tokens-to-xml.sed \
< $(SRCDIR)/oox/source/token/tokens.txt > $@
-$(writerfilter_WORK)/ooxml/OOXMLFactory%.cxx : $(writerfilter_SRC)/ooxml/factoryimpl_ns.xsl $(writerfilter_GEN_ooxml_Model_processed)
- $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,XSL,1)
- $(call gb_Helper_abbreviate_dirs, $(writerfilter_XSLTCOMMAND) --stringparam file $@ $< $(writerfilter_GEN_ooxml_Model_processed)) > $@
+$(writerfilter_WORK)/ooxml/OOXMLFactory%.cxx : $(writerfilter_SRC)/ooxml/factoryimpl_ns.py $(writerfilter_GEN_ooxml_Model_processed)
+ $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,PY ,1)
+ $(call gb_Helper_abbreviate_dirs, $(writerfilter_PYTHONCOMMAND) $< $(writerfilter_GEN_ooxml_Model_processed) $@) > $@
$(writerfilter_WORK)/ooxml/OOXMLFactory%.hxx : $(writerfilter_SRC)/ooxml/factory_ns.py $(writerfilter_GEN_ooxml_Model_processed)
$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,PY ,1)
@@ -132,6 +129,6 @@ $(writerfilter_WORK)/ooxml/OOXMLFactory%.hxx : $(writerfilter_SRC)/ooxml/factory
$(call gb_CustomTarget_get_target,writerfilter/source) : $(writerfilter_ALL)
-$(writerfilter_ALL) :| $(call gb_ExternalExecutable_get_dependencies,xsltproc) $(call gb_ExternalExecutable_get_dependencies,python) $(writerfilter_WORK)/ooxml/.dir
+$(writerfilter_ALL) :| $(call gb_ExternalExecutable_get_dependencies,python) $(writerfilter_WORK)/ooxml/.dir
# vim: set noet sw=4 ts=4:
diff --git a/writerfilter/source/ooxml/factoryimpl_ns.py b/writerfilter/source/ooxml/factoryimpl_ns.py
new file mode 100644
index 0000000..4dc8ff0
--- /dev/null
+++ b/writerfilter/source/ooxml/factoryimpl_ns.py
@@ -0,0 +1,715 @@
+#!/usr/bin/env python
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+from __future__ import print_function
+from xml.dom import minidom
+import sys
+
+
+# factoryMutexDecl
+
+
+def factoryMutexDecl(nsLabel):
+ print("typedef rtl::Static<osl::Mutex, OOXMLFactory_%s> OOXMLFactory_%s_Mutex;" % (nsLabel, nsLabel))
+ print()
+
+
+# factoryConstructor
+
+
+def factoryConstructor(nsLabel):
+ print("""OOXMLFactory_%s::OOXMLFactory_%s()
+{
+ // multi-thread-safe mutex for all platforms
+
+ osl::MutexGuard aGuard(OOXMLFactory_%s_Mutex::get());
+}""" % (nsLabel, nsLabel, nsLabel))
+ print()
+
+
+# factoryDestructor
+
+
+def factoryDestructor(nsLabel):
+ print("""OOXMLFactory_%s::~OOXMLFactory_%s()
+{
+}""" % (nsLabel, nsLabel))
+ print()
+
+
+# factoryGetInstance
+
+
+def factoryGetInstance(nsLabel):
+ print("""OOXMLFactory_ns::Pointer_t OOXMLFactory_%s::m_pInstance;
+
+OOXMLFactory_ns::Pointer_t OOXMLFactory_%s::getInstance()
+{
+ if (m_pInstance.get() == NULL)
+ m_pInstance.reset(new OOXMLFactory_%s());
+
+ return m_pInstance;
+}""" % (nsLabel, nsLabel, nsLabel))
+ print()
+
+
+# factoryAttributeToResourceMap
+
+
+def nsToLabel(nsNode):
+ return nsNode.getAttribute("name").replace('-', '_')
+
+
+def getChildByName(parentNode, childName):
+ elementNodes = [i for i in parentNode.childNodes if i.localName == childName]
+ assert len(elementNodes) == 1
+ return elementNodes[0]
+
+
+def resourceForAttribute(nsNode, attrNode):
+ resourceName = ""
+
+ for refNode in getChildrenByName(attrNode, "ref"):
+ refName = refNode.getAttribute("name")
+ for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("name") == refName]:
+ resourceName = resourceNode.getAttribute("resource")
+ break
+ if not len(resourceName):
+ for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]:
+ resourceName = resourceForAttribute(nsNode, define)
+ break
+ if len(resourceName):
+ break
+
+ if not len(resourceName):
+ if len(attrNode.getElementsByTagName("text") + [i for i in attrNode.getElementsByTagName("data") if i.getAttribute("type") in ("base64Binary", "string")]):
+ resourceName = "String"
+ elif len([i for i in attrNode.getElementsByTagName("data") if i.getAttribute("type") == "boolean"]):
+ resourceName = "Boolean"
+ elif len([i for i in attrNode.getElementsByTagName("data") if i.getAttribute("type") in ("unsignedInt", "integer", "int")]):
+ resourceName = "Integer"
+ return resourceName
+
+
+def idForNamespace(nsNode):
+ return "NN_%s" % nsNode.getAttribute("name").replace('-', '_')
+
+
+def localIdForDefine(defineNode):
+ return "DEFINE_%s" % defineNode.getAttribute("name")
+
+
+def idForDefine(nsNode, defineNode):
+ return "%s|%s" % (idForNamespace(nsNode), localIdForDefine(defineNode))
+
+
+def fastNamespace(attrNode):
+ return "NS_%s" % attrNode.getAttribute("prefix")
+
+
+def fastLocalName(attrNode):
+ return "OOXML_%s" % attrNode.getAttribute("localname")
+
+
+def fastToken(attrNode):
+ ret = []
+ if len(attrNode.getAttribute("prefix")):
+ ret.append("%s|" % fastNamespace(attrNode))
+ ret.append(fastLocalName(attrNode))
+ return "".join(ret)
+
+
+def factoryAttributeToResourceMapInner(nsNode, defineNode):
+ ret = []
+ defineName = defineNode.getAttribute("name")
+ for refNode in getChildrenByName(defineNode, "ref"):
+ refName = refNode.getAttribute("name")
+ parent = refNode.parentNode
+ if parent.localName in ("element", "attribute"):
+ continue
+ for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]:
+ ret.extend(factoryAttributeToResourceMapInner(nsNode, define))
+
+ attrNodes = defineNode.getElementsByTagName("attribute")
+ for attrNode in attrNodes:
+ attrToken = fastToken(attrNode)
+ if attrNode == attrNodes[0]:
+ ret.append(" // %s" % defineName)
+ resourceName = resourceForAttribute(nsNode, attrNode)
+ refDefine = "0"
+ if len(resourceName):
+ for refNode in attrNode.getElementsByTagName("ref"):
+ refName = refNode.getAttribute("name")
+ for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]:
+ refDefine = idForDefine(nsNode, define)
+ ret.append(" (*pMap)[%s] = AttributeInfo(RT_%s, %s);" % (attrToken, resourceName, refDefine))
+ else:
+ ret.append(" // empty resource: %s" % fastToken(attrNode))
+
+ return ret
+
+
+def factoryAttributeToResourceMap(nsNode):
+ print("""AttributeToResourceMapPointer OOXMLFactory_%s::createAttributeToResourceMap(Id nId)
+{
+ AttributeToResourceMapPointer pMap(new AttributeToResourceMap());
+
+ switch (nId)
+ {""" % nsToLabel(nsNode))
+ for defineNode in getChildrenByName(getChildByName(nsNode, "grammar"), "define"):
+ inner = "\n".join(factoryAttributeToResourceMapInner(nsNode, defineNode))
+ if len(inner):
+ print(" case %s:" % idForDefine(nsNode, defineNode))
+ print(inner)
+ print(" break;")
+
+ print(""" default:
+ break;
+ }
+
+ return pMap;
+}""")
+ print()
+
+
+# factoryListValueMap
+
+
+def idToLabel(idName):
+ if ":" in idName:
+ ns, ln = idName.split(':')
+ return "NS_%s::LN_%s" % (ns, ln)
+ else:
+ return idName
+
+
+def valueToLabel(value):
+ return value.replace('-', 'm').replace('+', 'p').replace(' ', '_').replace(',', '_')
+
+
+def factoryListValueMap(nsNode):
+ print("""ListValueMapPointer OOXMLFactory_%s::createListValueMap(Id nId)
+{
+ ListValueMapPointer pMap(new ListValueMap());
+
+ switch (nId)
+ {""" % nsToLabel(nsNode))
+
+ for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("resource") == "List"]:
+ print(" case %s:" % idForDefine(nsNode, resourceNode))
+ for valueNode in getChildrenByName(resourceNode, "value"):
+ valueData = ""
+ if len(valueNode.childNodes):
+ valueData = valueNode.childNodes[0].data
+ print(" (*pMap)[OOXMLValueString_%s] = %s;" % (valueToLabel(valueData), idToLabel(valueNode.getAttribute("tokenid"))))
+ print(" break;")
+
+ print(""" default:
+ break;
+ }
+
+ return pMap;
+}""")
+
+
+# factoryCreateElementMap
+
+
+def contextResource(files, nsNode, refNode):
+ refName = refNode.getAttribute("name")
+ for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("name") == refName]:
+ return resourceNode.getAttribute("resource")
+
+ for includeNode in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "include") if i.getAttribute("href") in files]:
+ namespaceNode = files[includeNode.getAttribute("href")]
+ for resourceNode in [i for i in getChildrenByName(namespaceNode, "resource") if i.getAttribute("name") == refName]:
+ return resourceNode.getAttribute("resource")
+
+ if refName == "BUILT_IN_ANY_TYPE":
+ return "Any"
+ else:
+ for namespaceNode in getChildrenByName(nsNode.parentNode, "namespace"):
+ for resourceNode in [i for i in getChildrenByName(namespaceNode, "resource") if i.getAttribute("name") == refName]:
+ return resourceNode.getAttribute("resource")
+ return ""
+
+
+def idForRef(nsNode, refNode):
+ refName = refNode.getAttribute("name")
+ result1 = ""
+ for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]:
+ result1 = idForDefine(nsNode, define)
+ if refName == "BUILT_IN_ANY_TYPE":
+ return "0"
+ elif result1 == "":
+ for namespaceNode in getChildrenByName(nsNode.parentNode, "namespace"):
+ for define in [i for i in getChildrenByName(getChildByName(namespaceNode, "grammar"), "define") if i.getAttribute("name") == refName]:
+ return idForDefine(namespaceNode, define)
+ else:
+ return result1
+
+
+def factoryCreateElementMapInner(files, nsNode, defineNode, resourceNamespaceNode=None):
+ if not resourceNamespaceNode:
+ resourceNamespaceNode = nsNode
+ ret = []
+ for refNode in defineNode.getElementsByTagName("ref"):
+ parent = refNode.parentNode
+ if parent.localName in ("element", "attribute"):
+ continue
+ refName = refNode.getAttribute("name")
+
+ block = []
+ for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]:
+ block = factoryCreateElementMapInner(files, nsNode, define)
+
+ if len(block) == 0:
+ block1 = []
+ for namespaceNode in getChildrenByName(nsNode.parentNode, "namespace"):
+ for define in [i for i in getChildrenByName(getChildByName(namespaceNode, "grammar"), "define") if i.getAttribute("name") == refName]:
+ block1.extend(factoryCreateElementMapInner(files, namespaceNode, define, nsNode))
+ else:
+ block1 = block
+
+ if len(block1):
+ ret.append(" /* ref: %s*/" % refName)
+ ret.extend(block1)
+
+ for elementNode in defineNode.getElementsByTagName("element"):
+ resource = ""
+ for refNode in getChildrenByName(elementNode, "ref"):
+ refName = refNode.getAttribute("name")
+ resource = contextResource(files, resourceNamespaceNode, refNode)
+ if len(resource):
+ break
+ if len(resource):
+ ret.append(" (*pMap)[%s] = CreateElement(RT_%s, %s);" % (fastToken(elementNode), resource, idForRef(nsNode, getChildByName(elementNode, "ref"))))
+
+ return ret
+
+
+def factoryCreateElementMapFromStart(files, nsNode):
+ for startNode in getChildrenByName(nsNode, "start"):
+ startName = startNode.getAttribute("name")
+ block = None
+ for defineNode in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == startName]:
+ block = factoryCreateElementMapInner(files, nsNode, defineNode)
+ print(" /* start: %s*/" % startName)
+ if block:
+ print("\n".join(block))
+ print(""" break;
+ }
+
+ return pMap;
+}""")
+ print()
+
+
+def factoryCreateElementMap(files, nsNode):
+ print("""CreateElementMapPointer OOXMLFactory_%s::createCreateElementMap(Id nId)
+{
+ CreateElementMapPointer pMap(new CreateElementMap());
+
+ switch (nId)
+ {""" % nsToLabel(nsNode))
+
+ for defineNode in getChildrenByName(getChildByName(nsNode, "grammar"), "define"):
+ inner = "\n".join(factoryCreateElementMapInner(files, nsNode, defineNode))
+ if len(inner):
+ print(" case %s:" % idForDefine(nsNode, defineNode))
+ print(inner)
+ print(" break;")
+ print(" default:")
+ factoryCreateElementMapFromStart(files, nsNode)
+
+
+# factoryActions
+
+
+def charactersActionForValues(nsNode, refNode):
+ ret = []
+
+ refName = refNode.getAttribute("name")
+ for defineNode in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if defineNode.getAttribute("name") == refName]:
+ ret.append(" {")
+ ret.append(" // %s" % defineNode.getAttribute("name"))
+ for dataNode in getChildrenByName(defineNode, "data"):
+ if dataNode.getAttribute("type") == "int":
+ ret.append(" OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue(sText));")
+ ret.append(" pValueHandler->setValue(pValue);")
+ elif dataNode.getAttribute("type") == "list":
+ ret.append(" ListValueMapPointer pListValueMap = getListValueMap(nDefine);")
+ ret.append(" if (pListValueMap.get() != NULL)")
+ ret.append(" {")
+ ret.append(" OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue((*pListValueMap)[sText]));")
+ ret.append(" pValueHandler->setValue(pValue);")
+ ret.append(" }")
+ ret.append(" }")
+
+ return ret
+
+
+def factoryChooseAction(actionNode):
+ ret = []
+ if actionNode.hasAttribute("tokenid"):
+ ret.append(" if (sal::static_int_cast<Id>(pHandler->getId()) == %s)" % idToLabel(actionNode.getAttribute("tokenid")))
+ ret.append(" {")
+ for condNode in getChildrenByName(actionNode, "cond"):
+ ret.append(" {")
+ ret.append(" OOXMLPropertySetEntryToInteger aHandler(%s);" % idToLabel(condNode.getAttribute("tokenid")))
+ ret.append(" dynamic_cast<OOXMLFastContextHandlerStream*>(pHandler)->getPropertySetAttrs()->resolve(aHandler);")
+ ret.append("")
+ ret.append(" if (sal::static_int_cast<Id>(aHandler.getValue()) == %s)" % idToLabel(condNode.getAttribute("value")))
+ ret.append(" {")
+
+ if actionNode.getAttribute("action") in ("handleXNotes", "handleHdrFtr", "handleComment", "handlePicture", "handleBreak", "handleOLE", "handleFontRel"):
+ ret.append(" dynamic_cast<OOXMLFastContextHandlerProperties*>(pHandler)->%s();" % actionNode.getAttribute("action"))
+ elif actionNode.getAttribute("action") == "propagateCharacterPropertiesAsSet":
+ ret.append(" pHandler->propagateCharacterPropertiesAsSet(%s);" % idToLabel(actionNode.getAttribute("sendtokenid")))
+ elif actionNode.getAttribute("action") in ("startCell", "endCell"):
+ ret.append(" dynamic_cast<OOXMLFastContextHandlerTextTableCell*>(pHandler)->%s();" % actionNode.getAttribute("action"))
+ elif actionNode.getAttribute("action") in ("startRow", "endRow"):
+ ret.append(" dynamic_cast<OOXMLFastContextHandlerTextTableRow*>(pHandler)->%s();" % actionNode.getAttribute("action"))
+ elif actionNode.getAttribute("action") == "handleGridBefore":
+ ret.append(" dynamic_cast<OOXMLFastContextHandlerTextTableRow*>(pHandler)->%s();" % actionNode.getAttribute("action"))
+ elif actionNode.getAttribute("action") in ("sendProperty", "handleHyperlink"):
+ ret.append(" dynamic_cast<OOXMLFastContextHandlerStream*>(pHandler)->%s();" % actionNode.getAttribute("action"))
+ elif actionNode.getAttribute("action") == "fieldstart":
+ ret.append(" pHandler->startField();")
+ elif actionNode.getAttribute("action") == "fieldsep":
+ ret.append(" pHandler->fieldSeparator();")
+ elif actionNode.getAttribute("action") == "fieldend":
+ ret.append(" pHandler->endField();")
+ elif actionNode.getAttribute("action") == "printproperty":
+ ret.append(" dynamic_cast<OOXMLFastContextHandlerStream*>(pHandler)->sendProperty(%s);" % idToLabel(actionNode.getAttribute("sendtokenid")))
+ elif actionNode.getAttribute("action") == "sendPropertiesWithId":
+ ret.append(" pHandler->sendPropertiesWithId(%s);" % idToLabel(actionNode.getAttribute("sendtokenid")))
+ elif actionNode.getAttribute("action") == "text":
+ ret.append(" pHandler->text(sText);")
+ elif actionNode.getAttribute("action") == "positionOffset":
+ ret.append(" pHandler->positionOffset(sText);")
+ elif actionNode.getAttribute("action") == "positivePercentage":
+ ret.append(" pHandler->positivePercentage(sText);")
+ elif actionNode.getAttribute("action") == "alignH":
+ ret.append(" pHandler->alignH(sText);")
+ elif actionNode.getAttribute("action") == "alignV":
+ ret.append(" pHandler->alignV(sText);")
+ elif actionNode.getAttribute("action") == "tokenproperty":
+ ret.append(" OOXMLFastHelper<OOXMLIntegerValue>::newProperty(pHandler, %s, pHandler->getToken());" % idToLabel("ooxml:token"))
+ else:
+ ret.append(" pHandler->%s();" % actionNode.getAttribute("action"))
+
+ for condNode in getChildrenByName(actionNode, "cond"):
+ ret.append(" }")
+ ret.append(" }")
+ if actionNode.hasAttribute("tokenid"):
+ ret.append(" }")
+
+ return ret
+
+
+def factoryAction(nsNode, action):
+ switchblock1 = []
+ for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if len([j for j in getChildrenByName(i, "action") if j.getAttribute("name") == action])]:
+ switchblock1.append(" case %s:" % idForDefine(nsNode, resourceNode))
+ for actionNode in [i for i in getChildrenByName(resourceNode, "action") if i.getAttribute("name") == action]:
+ switchblock1.extend(factoryChooseAction(actionNode))
+ if action == "characters":
+ switchblock1.append(" break;")
+ switchblock1.append("")
+ else:
+ switchblock1[-1] += " break;"
+ switchblock1.append("")
+
+ switchblock2 = []
+ if action == "characters":
+ for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("resource") == "Value"]:
+ if not len(getChildrenByName(resourceNode, "attribute")):
+ resourceName = resourceNode.getAttribute("name")
+ switchblock2.append(" case %s:" % idForDefine(nsNode, resourceNode))
+ ret = []
+ for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == resourceName]:
+ for refNode in getChildrenByName(define, "ref"):
+ ret.extend(charactersActionForValues(nsNode, refNode))
+ switchblock2.extend(ret)
+ switchblock2.append(" break;")
+
+ sys.stdout.write("void OOXMLFactory_%s::%sAction(OOXMLFastContextHandler*" % (nsToLabel(nsNode), action))
+ if len(switchblock1) or len(switchblock2):
+ sys.stdout.write(" pHandler")
+ if action == "characters":
+ sys.stdout.write(", const OUString&")
+ if "sText" in "".join(switchblock1) or "sText" in "".join(switchblock2):
+ sys.stdout.write(" sText")
+ print(")")
+ print("{")
+ if len(switchblock1) or len(switchblock2):
+ print(" sal_uInt32 nDefine = pHandler->getDefine();")
+ if len(switchblock1):
+ print(" switch (nDefine)")
+ print(" {")
+ print("")
+ if switchblock1[-1] == "":
+ switchblock1 = switchblock1[:-1]
+ print("\n ".join(switchblock1))
+ print(" default:")
+ print(" break;")
+ print(" }")
+ if len(switchblock2):
+ print(" switch (nDefine)")
+ print(" {")
+ print("\n ".join(switchblock2))
+ print(" default:")
+ print(" break;")
+ print(" }")
+ print("}")
+
+
+def factoryActions(nsNode):
+ actions = []
+ for resourceNode in getChildrenByName(nsNode, "resource"):
+ for actionNode in getChildrenByName(resourceNode, "action"):
+ actionName = actionNode.getAttribute("name")
+ if actionName != "characters" and actionName not in actions:
+ actions.append(actionName)
+ for action in sorted(actions):
+ factoryAction(nsNode, action)
+ print()
+ print()
+ factoryAction(nsNode, "characters")
+ print()
+
+
+# factoryGetDefineName
+
+
+def factoryGetDefineName(nsNode):
+ print("""#ifdef DEBUG_DOMAINMAPPER
+string OOXMLFactory_%s::getDefineName(Id nId) const
+{
+ static IdToStringMapPointer pMap;
+
+ if (pMap.get() == NULL)
+ {
+ pMap = IdToStringMapPointer(new IdToStringMap());
+
+""" % nsToLabel(nsNode))
+ for defineNode in getChildrenByName(getChildByName(nsNode, "grammar"), "define"):
+ print(""" (*pMap)[%s] = "%s";""" % (idForDefine(nsNode, defineNode), defineNode.getAttribute("name")))
+ print(""" }
+
+ return (*pMap)[nId];
+}
+#endif
+
+""")
+
+
+# factoryTokenToIdMap
+
+
+def factoryTokenToIdMapInner(nsNode, defineNode):
+ ret = []
+ for refNode in defineNode.getElementsByTagName("ref"):
+ refName = refNode.getAttribute("name")
+ parent = refNode.parentNode
+ if parent.localName in ("element", "attribute"):
+ continue
+ refblock1 = []
+ for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]:
+ refblock1.extend(factoryTokenToIdMapInner(nsNode, define))
+ if not len(refblock1):
+ for namespaceNode in getChildrenByName(nsNode.parentNode, "namespace"):
+ for define in [i for i in getChildrenByName(getChildByName(namespaceNode, "grammar"), "define") if i.getAttribute("name") == refName]:
+ ret.extend(factoryTokenToIdMapInner(namespaceNode, define))
+ else:
+ ret.extend(refblock1)
+
+ body = []
+ defineName = defineNode.getAttribute("name")
+ for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("name") == defineName]:
+ for node in [i for i in resourceNode.childNodes if i.localName in ("element", "attribute")]:
+ if node.hasAttribute("tokenid"):
+ body.append("(*pMap)[%s] = %s;" % (fastToken(node), idToLabel(node.getAttribute("tokenid"))))
+ if len(body):
+ ret.append("// %s" % defineName)
+ ret.extend(body)
+
+ return ret
+
+
+def factoryTokenToIdMap(nsNode):
+ print("""TokenToIdMapPointer OOXMLFactory_%s::createTokenToIdMap(Id nId)
+{
+ TokenToIdMapPointer pMap(new TokenToIdMap());
+
+ switch (nId)
+ {""" % nsToLabel(nsNode))
+ for defineNode in getChildrenByName(getChildByName(nsNode, "grammar"), "define"):
+ inner = "\n".join(factoryTokenToIdMapInner(nsNode, defineNode))
+ if len(inner):
+ print(" case %s:" % idForDefine(nsNode, defineNode))
+ print(inner)
+ print(" break;")
+ print(" default:")
+ for startNode in getChildrenByName(nsNode, "start"):
+ startName = startNode.getAttribute("name")
+ print(" // %s" % startName)
+ for defineNode in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == startName]:
+ inner = factoryTokenToIdMapInner(nsNode, defineNode)
+ if len(inner):
+ print("\n".join(inner))
+ print(""" break;
+ }
+
+ return pMap;
+}
+""")
+
+
+# factoryAttributeAction
+
+
+def factoryAttributeActionDefineInner(nsNode, defineNode):
+ ret = []
+
+ defineName = defineNode.getAttribute("name")
+ block = []
+ for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("name") == defineName]:
+ for attributeNode in getChildrenByName(resourceNode, "attribute"):
+ if attributeNode.hasAttribute("action"):
+ block.append("case %s:" % fastToken(attributeNode))
+ block.append(" pHandler->%s(pValue);" % attributeNode.getAttribute("action"))
+ block.append(" break;")
+ if len(block):
+ resource = ""
+ for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("name") == defineName]:
+ resource = resourceNode.getAttribute("resource")
+ break
+ ret.append("{")
+ ret.append(" OOXMLFastContextHandler%s* pHandler = dynamic_cast<OOXMLFastContextHandler%s*>(_pHandler);" % (resource, resource))
+ ret.append("")
+ ret.append(" switch (nToken)")
+ ret.append(" {")
+ ret.extend(block)
+ ret.append(" default:")
+ ret.append(" break;")
+ ret.append(" }")
+ ret.append("}")
+
+ return ret
+
+
+def factoryAttributeActionInner(nsNode):
+ ret = []
+
+ for defineNode in getChildrenByName(getChildByName(nsNode, "grammar"), "define"):
+ inner = factoryAttributeActionDefineInner(nsNode, defineNode)
+ if len(inner):
+ ret.append(" case %s:" % idForDefine(nsNode, defineNode))
+ ret.extend(inner)
+ ret.append(" break;")
+
+ return ret
+
+
+def factoryAttributeAction(nsNode):
+ nsLabel = nsToLabel(nsNode)
+ inner = factoryAttributeActionInner(nsNode)
+ if len(inner):
+ print("""void OOXMLFactory_%s::attributeAction(OOXMLFastContextHandler* _pHandler, Token_t nToken, OOXMLValue::Pointer_t pValue)
+{
+ switch (_pHandler->getDefine())
+ {""" % nsLabel)
+ print("\n".join(inner))
+ print(" default:")
+ print(" break;")
+ print(" }")
+ print("}")
+ print()
+ else:
+ print("void OOXMLFactory_%s::attributeAction(OOXMLFastContextHandler*, Token_t, OOXMLValue::Pointer_t)" % nsLabel)
+ print("{")
+ print("}")
+ print()
+
+
+# factoryGetName
+
+
+def factoryGetName(nsNode):
+ print("""#ifdef DEBUG_DOMAINMAPPER
+string OOXMLFactory_%s::getName() const
+{
+ return "%s";
+}
+#endif
+""" % (nsToLabel(nsNode), nsNode.getAttribute("name")))
+
+
+# createImpl
+
+
+def getChildrenByName(parentNode, childName):
+ return [i for i in parentNode.childNodes if i.localName == childName]
+
+
+def createImpl(modelNode, nsName):
+ print("""
+#include "ooxml/resourceids.hxx"
+#include "OOXMLFactory_values.hxx"
+#include "OOXMLFactory_%s.hxx"
+#include "ooxml/OOXMLFastHelper.hxx"
+
+#ifdef _MSC_VER
+#pragma warning(disable:4065) // switch statement contains 'default' but no 'case' labels
+#endif
+
+namespace writerfilter {
+namespace ooxml {
+
+/// @cond GENERATED""" % nsName)
+ print()
+
+ files = {}
+ for nsNode in getChildrenByName(modelNode, "namespace"):
+ if nsNode.hasAttribute("file"):
+ files[nsNode.getAttribute("file")] = nsNode
+
+ for nsNode in [i for i in getChildrenByName(modelNode, "namespace") if i.getAttribute("name") == nsName]:
+ nsLabel = nsToLabel(nsNode)
+
+ factoryMutexDecl(nsLabel)
+ factoryConstructor(nsLabel)
+ factoryDestructor(nsLabel)
+ factoryGetInstance(nsLabel)
+ factoryAttributeToResourceMap(nsNode)
+ factoryListValueMap(nsNode)
+ factoryCreateElementMap(files, nsNode)
+ factoryActions(nsNode)
+ factoryGetDefineName(nsNode)
+ factoryTokenToIdMap(nsNode)
+ factoryAttributeAction(nsNode)
+ factoryGetName(nsNode)
+
+ print("""/// @endcond
+}}""")
+
+
+def main():
+ modelPath = sys.argv[1]
+ filePath = sys.argv[2]
+ modelNode = getChildByName(minidom.parse(modelPath), "model")
+ nsName = filePath.split('OOXMLFactory_')[1].split('.cxx')[0]
+ createImpl(modelNode, nsName)
+
+if __name__ == "__main__":
+ main()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/writerfilter/source/ooxml/factoryimpl_ns.xsl b/writerfilter/source/ooxml/factoryimpl_ns.xsl
deleted file mode 100644
index 4adaed4..0000000
--- a/writerfilter/source/ooxml/factoryimpl_ns.xsl
+++ /dev/null
@@ -1,945 +0,0 @@
-<!--
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
--->
-<xsl:stylesheet
- version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
- xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
- xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
- xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
- xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
- xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
- xmlns:xlink="http://www.w3.org/1999/xlink"
- xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
- xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
- xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
- xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
- xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
- xmlns:math="http://www.w3.org/1998/Math/MathML"
- xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
- xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
- xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
- xmlns:ooo="http://openoffice.org/2004/office"
- xmlns:ooow="http://openoffice.org/2004/writer"
- xmlns:oooc="http://openoffice.org/2004/calc"
- xmlns:dom="http://www.w3.org/2001/xml-events"
- xmlns:xforms="http://www.w3.org/2002/xforms"
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:rng="http://relaxng.org/ns/structure/1.0"
- xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
- xmlns:UML = 'org.omg.xmi.namespace.UML' xml:space="default">
- <xsl:output method="text" />
- <xsl:param name="prefix"/>
-
- <xsl:include href="factorytools.xsl"/>
-
-<xsl:template name="factorymutex">
- <xsl:call-template name="factoryclassname"/>
- <xsl:text>_Mutex</xsl:text>
-</xsl:template>
-
-<xsl:template name="factorymutexdecl">
- <xsl:variable name="classname">
- <xsl:call-template name="factoryclassname"/>
- </xsl:variable>
- <xsl:text>
-typedef rtl::Static < osl::Mutex, </xsl:text>
- <xsl:value-of select="$classname"/>
- <xsl:text> > </xsl:text>
- <xsl:value-of select="$classname"/>
- <xsl:text>_Mutex;
-</xsl:text>
-</xsl:template>
-
-<xsl:template name="factoryconstructor">
- <xsl:variable name="classname">
- <xsl:call-template name="factoryclassname"/>
- </xsl:variable>
- <xsl:text>
-</xsl:text>
- <xsl:value-of select="$classname"/>
- <xsl:text>::</xsl:text>
- <xsl:value-of select="$classname"/>
- <xsl:text>()
-{
- // multi-thread-safe mutex for all platforms
-
- osl::MutexGuard aGuard(</xsl:text>
- <xsl:call-template name="factorymutex"/>
- <xsl:text>::get());
-}
-</xsl:text>
-</xsl:template>
-
-<xsl:template name="factorydestructor">
- <xsl:variable name="classname">
- <xsl:call-template name="factoryclassname"/>
- </xsl:variable>
- <xsl:text>
-</xsl:text>
- <xsl:value-of select="$classname"/>
- <xsl:text>::~</xsl:text>
- <xsl:value-of select="$classname"/>
- <xsl:text>()
-{
-}
-</xsl:text>
-</xsl:template>
-
-<xsl:template name="factorygetinstance">
- <xsl:variable name="classname">
- <xsl:call-template name="factoryclassname"/>
- </xsl:variable>
- <xsl:text>
-OOXMLFactory_ns::Pointer_t </xsl:text>
- <xsl:value-of select="$classname"/>
- <xsl:text>::m_pInstance;
-
-OOXMLFactory_ns::Pointer_t </xsl:text>
- <xsl:value-of select="$classname"/>
- <xsl:text>::getInstance()
-{
- if (m_pInstance.get() == NULL)
- m_pInstance.reset(new </xsl:text>
- <xsl:value-of select="$classname"/>
- <xsl:text>());
-
- return m_pInstance;
-}
-</xsl:text>
-</xsl:template>
-
-<!--
- Returns resource for attribute.
--->
-
-<xsl:template name="resourceforattribute">
- <xsl:variable name="mynsid" select="generate-id(ancestor::namespace)"/>
- <xsl:for-each select="rng:ref">
- <xsl:variable name="name" select="@name"/>
- <xsl:variable name="resource1">
- <xsl:for-each select="key('context-resource', @name)[generate-id(ancestor::namespace) = $mynsid]">
- <xsl:value-of select="@resource"/>
- </xsl:for-each>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="string-length($resource1) > 0">
- <xsl:value-of select="$resource1"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$name]">
- <xsl:call-template name="resourceforattribute"/>
- </xsl:for-each>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- <xsl:for-each select=".//rng:text">
- <xsl:text>String</xsl:text>
- </xsl:for-each>
- <xsl:for-each select=".//rng:data[@type='base64Binary']">
- <xsl:text>String</xsl:text>
- </xsl:for-each>
- <xsl:for-each select=".//rng:data[@type='boolean']">
- <xsl:text>Boolean</xsl:text>
- </xsl:for-each>
- <xsl:for-each select=".//rng:data[@type='unsignedInt']">
- <xsl:text>Integer</xsl:text>
- </xsl:for-each>
- <xsl:for-each select=".//rng:data[@type='int']">
- <xsl:text>Integer</xsl:text>
- </xsl:for-each>
- <xsl:for-each select=".//rng:data[@type='integer']">
- <xsl:text>Integer</xsl:text>
- </xsl:for-each>
- <xsl:for-each select=".//rng:data[@type='string']">
- <xsl:text>String</xsl:text>
- </xsl:for-each>
-</xsl:template>
-
-<!--
-
-creates code block in OOXMLFactory_<namespace>::createAttributeToResourceMap
-for a rng:define
-
- -->
-<xsl:template name="factoryattributetoresourcemapinner">
- <xsl:variable name="defname" select="@name"/>
- <xsl:for-each select=".//rng:ref[not(ancestor::rng:element or ancestor::rng:attribute)]">
- <xsl:variable name="name" select="@name"/>
- <xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$name]">
- <xsl:call-template name="factoryattributetoresourcemapinner"/>
- </xsl:for-each>
- </xsl:for-each>
-
- <xsl:for-each select=".//rng:attribute">
- <xsl:if test="position()=1">
- <xsl:text>
- // </xsl:text>
- <xsl:value-of select="$defname"/>
- </xsl:if>
- <xsl:variable name="resource">
- <xsl:call-template name="resourceforattribute"/>
- </xsl:variable>
-
- <xsl:choose>
- <xsl:when test="string-length($resource) > 0">
- <xsl:variable name="refdefine1">
- <xsl:for-each select="rng:ref">
- <xsl:variable name="refname" select="@name"/>
- <xsl:for-each select="ancestor::rng:grammar/rng:define[@name=$refname]">
- <xsl:call-template name="idfordefine"/>
- </xsl:for-each>
- </xsl:for-each>
- </xsl:variable>
- <xsl:variable name="refdefine">
- <xsl:choose>
- <xsl:when test="string-length($refdefine1) > 0">
- <xsl:value-of select="$refdefine1"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>0</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:text>
- (*pMap)[</xsl:text>
- <xsl:call-template name="fasttoken"/>
- <xsl:text>] = AttributeInfo(RT_</xsl:text>
- <xsl:value-of select="$resource"/>
- <xsl:text>, </xsl:text>
- <xsl:value-of select="$refdefine"/>
- <xsl:text>);</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>
- // empty resource: </xsl:text>
- <xsl:call-template name="fasttoken"/>
- </xsl:otherwise>
- </xsl:choose>
-
- </xsl:for-each>
-</xsl:template>
-
-<!-- factoryattributetoresourcemap -->
-<xsl:template name="factoryattributetoresourcemap">
- <xsl:text>
-AttributeToResourceMapPointer </xsl:text>
- <xsl:call-template name="factoryclassname"/>
- <xsl:text>::createAttributeToResourceMap(Id nId)
-{
- AttributeToResourceMapPointer pMap(new AttributeToResourceMap());
-
- switch (nId)
- {</xsl:text>
- <xsl:for-each select="rng:grammar/rng:define">
- <xsl:variable name="inner">
- <xsl:call-template name="factoryattributetoresourcemapinner"/>
- </xsl:variable>
- <xsl:if test="string-length($inner) > 0">
- <xsl:text>
- </xsl:text>
- <xsl:call-template name="caselabeldefine"/>
- <xsl:value-of select="$inner"/>
- <xsl:text>
- break;</xsl:text>
- </xsl:if>
- </xsl:for-each>
- default:
- break;
- }
-
- return pMap;
-}
-</xsl:template>
-
-<!-- factorylistvaluemap -->
-<xsl:template name="factorylistvaluemap">
- <xsl:text>
-ListValueMapPointer </xsl:text>
- <xsl:call-template name="factoryclassname"/>
- <xsl:text>::createListValueMap(Id nId)
-{
- ListValueMapPointer pMap(new ListValueMap());
-
- switch (nId)
- {</xsl:text>
- <xsl:for-each select="resource[@resource='List']">
- <xsl:text>
- </xsl:text>
- <xsl:call-template name="caselabeldefine"/>
- <xsl:for-each select="value">
- <xsl:text>
- (*pMap)[</xsl:text>
- <xsl:call-template name="valuestringname">
- <xsl:with-param name="string" select="text()"/>
- </xsl:call-template>
- <xsl:text>] = </xsl:text>
- <xsl:call-template name="idtoqname">
- <xsl:with-param name="id" select="@tokenid"/>
- </xsl:call-template>
- <xsl:text>;</xsl:text>
- </xsl:for-each>
- <xsl:text>
- break;</xsl:text>
- </xsl:for-each>
- <xsl:text>
- default:
- break;
- }
-
- return pMap;
-}</xsl:text>
-</xsl:template>
-
-<!-- factoryelementtoresorucemapinner -->
-<xsl:template name="factorycreateelementmapinner">
- <xsl:for-each select=".//rng:ref[not(ancestor::rng:element or ancestor::rng:attribute)]">
- <xsl:variable name="name" select="@name"/>
- <xsl:variable name="block">
- <xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$name]">
- <xsl:call-template name="factorycreateelementmapinner"/>
- </xsl:for-each>
- </xsl:variable>
- <xsl:variable name="block1">
- <xsl:choose>
- <xsl:when test="string-length($block) = 0">
- <xsl:for-each select="ancestor::model/namespace/rng:grammar/rng:define[@name=$name]">
- <xsl:call-template name="factorycreateelementmapinner"/>
- </xsl:for-each>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$block"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:if test="string-length($block1) > 0">
- <xsl:text>
- /* ref: </xsl:text>
- <xsl:value-of select="$name"/>
- <xsl:text>*/</xsl:text>
- <xsl:value-of select="$block1"/>
- </xsl:if>
- </xsl:for-each>
- <xsl:for-each select=".//rng:element">
- <xsl:variable name="resource">
- <xsl:for-each select="rng:ref">
- <xsl:call-template name="contextresource"/>
- </xsl:for-each>
- </xsl:variable>
- <xsl:if test="string-length($resource) > 0">
- <xsl:text>
- (*pMap)[</xsl:text>
- <xsl:call-template name="fasttoken"/>
- <xsl:text>] = CreateElement(RT_</xsl:text>
- <xsl:value-of select="$resource"/>
- <xsl:text>, </xsl:text>
- <xsl:for-each select="rng:ref">
- <xsl:call-template name="idforref"/>
- </xsl:for-each>
- <xsl:text>);</xsl:text>
- </xsl:if>
- </xsl:for-each>
-</xsl:template>
-
-<xsl:template name="factorycreateelementmapfromstart">
- <xsl:for-each select="start">
- <xsl:variable name="name" select="@name"/>
- <xsl:variable name="block">
- <xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$name]">
- <xsl:call-template name="factorycreateelementmapinner">
- </xsl:call-template>
- </xsl:for-each>
- </xsl:variable>
- <xsl:text>
- /* start: </xsl:text>
- <xsl:value-of select="$name"/>
- <xsl:text>*/</xsl:text>
- <xsl:if test="string-length($block) > 0">
- <xsl:value-of select="$block"/>
- </xsl:if>
- </xsl:for-each>
-</xsl:template>
-
-<!-- factoryelementtoresourcemap -->
-<xsl:template name="factorycreateelementmap">
- <xsl:text>
-CreateElementMapPointer </xsl:text>
- <xsl:call-template name="factoryclassname"/>
- <xsl:text>::createCreateElementMap(Id nId)
-{
- CreateElementMapPointer pMap(new CreateElementMap());
-
- switch (nId)
- {</xsl:text>
- <xsl:for-each select="rng:grammar/rng:define">
- <xsl:variable name="inner">
- <xsl:call-template name="factorycreateelementmapinner"/>
- </xsl:variable>
- <xsl:if test="string-length($inner) > 0">
- <xsl:text>
- </xsl:text>
- <xsl:call-template name="caselabeldefine"/>
- <xsl:value-of select="$inner"/>
- <xsl:text>
- break;</xsl:text>
- </xsl:if>
- </xsl:for-each>
- <xsl:text>
- default:</xsl:text>
- <xsl:call-template name="factorycreateelementmapfromstart"/>
- <xsl:text>
- break;
- }
-
- return pMap;
-}</xsl:text>
-</xsl:template>
-
- <!--
- Chooses the action for the current <action> element.
- -->
- <xsl:template name="factorychooseaction">
- <xsl:if test="@tokenid">
- <xsl:text>
- if (sal::static_int_cast<Id>(pHandler->getId()) == </xsl:text>
- <xsl:call-template name="idtoqname">
- <xsl:with-param name="id" select="@tokenid"/>
- </xsl:call-template>
- <xsl:text>)
- {</xsl:text>
- </xsl:if>
- <xsl:for-each select="./cond">
- <xsl:text>
- {
- OOXMLPropertySetEntryToInteger aHandler(</xsl:text>
- <xsl:call-template name="idtoqname">
- <xsl:with-param name="id" select="@tokenid"/>
- </xsl:call-template>
- <xsl:text>);
- dynamic_cast<OOXMLFastContextHandlerStream*>(pHandler)->getPropertySetAttrs()->resolve(aHandler);
-
- if (sal::static_int_cast<Id>(aHandler.getValue()) == </xsl:text>
- <xsl:call-template name="idtoqname">
- <xsl:with-param name="id" select="@value"/>
- </xsl:call-template>
- <xsl:text>)
- {</xsl:text>
- </xsl:for-each>
- <xsl:choose>
- <xsl:when test="@action='handleXNotes' or
- @action='handleHdrFtr' or
- @action='handleComment' or
- @action='handlePicture' or
- @action='handleBreak' or
- @action='handleOLE' or
- @action='handleFontRel'">
- <xsl:text>
- dynamic_cast<OOXMLFastContextHandlerProperties*>(pHandler)-></xsl:text>
- <xsl:value-of select="@action"/>
- <xsl:text>();</xsl:text>
- </xsl:when>
- <xsl:when test="@action='propagateCharacterPropertiesAsSet'">
- <xsl:text>
- pHandler->propagateCharacterPropertiesAsSet(</xsl:text>
- <xsl:call-template name="idtoqname">
- <xsl:with-param name="id" select="@sendtokenid"/>
- </xsl:call-template>
- <xsl:text>);</xsl:text>
- </xsl:when>
- <xsl:when test="@action='startCell' or @action='endCell'">
- <xsl:text>
- dynamic_cast<OOXMLFastContextHandlerTextTableCell*>(pHandler)-></xsl:text>
- <xsl:value-of select="@action"/>
- <xsl:text>();</xsl:text>
- </xsl:when>
- <xsl:when test="@action='startRow' or @action='endRow'">
- <xsl:text>
- dynamic_cast<OOXMLFastContextHandlerTextTableRow*>(pHandler)-></xsl:text>
- <xsl:value-of select="@action"/>
- <xsl:text>();</xsl:text>
- </xsl:when>
- <xsl:when test="@action='handleGridBefore'">
- <xsl:text>
- dynamic_cast<OOXMLFastContextHandlerTextTableRow*>(pHandler)->handleGridBefore();</xsl:text>
- </xsl:when>
- <xsl:when test="@action='sendProperty' or @action='handleHyperlink'">
- <xsl:text>
- dynamic_cast<OOXMLFastContextHandlerStream*>(pHandler)-></xsl:text>
- <xsl:value-of select="@action"/>
- <xsl:text>();</xsl:text>
- </xsl:when>
- <xsl:when test="@action='fieldstart'">
- <xsl:text>
- pHandler->startField();</xsl:text>
- </xsl:when>
- <xsl:when test="@action='fieldsep'">
- <xsl:text>
- pHandler->fieldSeparator();</xsl:text>
- </xsl:when>
- <xsl:when test="@action='fieldend'">
- <xsl:text>
- pHandler->endField();</xsl:text>
- </xsl:when>
- <xsl:when test="@action='printproperty'">
- <xsl:text>
- dynamic_cast<OOXMLFastContextHandlerStream*>(pHandler)->sendProperty(</xsl:text>
- <xsl:call-template name="idtoqname">
- <xsl:with-param name="id" select="@sendtokenid"/>
- </xsl:call-template>
- <xsl:text>);</xsl:text>
- </xsl:when>
- <xsl:when test="@action='sendPropertiesWithId'">
- <xsl:text>
- pHandler->sendPropertiesWithId(</xsl:text>
- <xsl:call-template name="idtoqname">
- <xsl:with-param name="id" select="@sendtokenid"/>
- </xsl:call-template>
- <xsl:text>);</xsl:text>
- </xsl:when>
- <xsl:when test="@action='text'">
- pHandler->text(sText);
- </xsl:when>
- <xsl:when test="@action='positionOffset'">
- pHandler->positionOffset(sText);
- </xsl:when>
- <xsl:when test="@action='positivePercentage'">
- pHandler->positivePercentage(sText);
- </xsl:when>
- <xsl:when test="@action='alignH'">
- pHandler->alignH(sText);
- </xsl:when>
- <xsl:when test="@action='alignV'">
- pHandler->alignV(sText);
- </xsl:when>
- <xsl:when test="@action='newProperty'">
- <xsl:text>
- OOXMLFastHelper<OOXMLIntegerValue>::newProperty(pHandler, </xsl:text>
- <xsl:call-template name="idtoqname">
- <xsl:with-param name="id" select="@tokenid"/>
- </xsl:call-template>
- <xsl:text>, "</xsl:text>
- <xsl:value-of select="@value"/>
- <xsl:text>");</xsl:text>
- </xsl:when>
- <xsl:when test="@action='tokenproperty'">
- <xsl:text>
- OOXMLFastHelper<OOXMLIntegerValue>::newProperty(pHandler, </xsl:text>
- <xsl:call-template name="idtoqname">
- <xsl:with-param name="id">ooxml:token</xsl:with-param>
- </xsl:call-template>
- <xsl:text>, pHandler->getToken());</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>
- pHandler-></xsl:text>
- <xsl:value-of select="@action"/>
- <xsl:text>();</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:for-each select="./cond">
- <xsl:text>
- }
- }</xsl:text>
- </xsl:for-each>
- <xsl:if test="@tokenid">
- <xsl:text>
- }</xsl:text>
- </xsl:if>
- </xsl:template>
-
-<!-- factoryaction -->
-<xsl:template name="factoryaction">
- <xsl:param name="action"/>
- <xsl:variable name="switchblock1">
- <xsl:for-each select="resource[action/@name=$action]">
- <xsl:text>
- </xsl:text>
- <xsl:call-template name="caselabeldefine"/>
- <xsl:for-each select="action[@name=$action]">
- <xsl:call-template name="factorychooseaction"/>
- </xsl:for-each>
- <xsl:text> break;
</xsl:text>
- </xsl:for-each>
- </xsl:variable>
- <xsl:variable name="switchblock2">
- <xsl:if test="$action='characters'">
- <xsl:for-each select="resource[@resource='Value']">
- <xsl:if test="count(attribute) = 0">
- <xsl:variable name="name" select="@name"/>
- <xsl:text> </xsl:text>
- <xsl:call-template name="caselabeldefine"/>
- <xsl:text>
</xsl:text>
- <xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$name]">
- <xsl:for-each select="rng:ref">
- <xsl:call-template name="charactersactionforvalues"/>
- </xsl:for-each>
- </xsl:for-each>
- <xsl:text> break;
</xsl:text>
- </xsl:if>
- </xsl:for-each>
- </xsl:if>
- </xsl:variable>
- <xsl:text>

</xsl:text>
- <xsl:text>void </xsl:text>
- <xsl:call-template name="factoryclassname"/>
- <xsl:text>::</xsl:text>
- <xsl:value-of select="$action"/>
- <xsl:text>Action(OOXMLFastContextHandler*</xsl:text>
- <xsl:if test="string-length($switchblock1) > 0 or string-length($switchblock2) > 0">
- <xsl:text> pHandler</xsl:text>
- </xsl:if>
- <xsl:if test="$action='characters'">
- <xsl:text>, const OUString &</xsl:text>
- <xsl:if test="contains($switchblock1, 'sText') or contains($switchblock2, 'sText')">
- <xsl:text> sText</xsl:text>
- </xsl:if>
- </xsl:if>
- <xsl:text>)
</xsl:text>
- <xsl:text>{
</xsl:text>
- <xsl:if test="string-length($switchblock1) > 0 or string-length($switchblock2) > 0">
- <xsl:text> sal_uInt32 nDefine = pHandler->getDefine();
</xsl:text>
- </xsl:if>
- <xsl:if test="string-length($switchblock1) > 0">
- <xsl:text> switch (nDefine)
</xsl:text>
- <xsl:text> {
</xsl:text>
- <xsl:value-of select="$switchblock1"/>
- <xsl:text> default:
</xsl:text>
- <xsl:text> break;
</xsl:text>
- <xsl:text> }
</xsl:text>
- </xsl:if>
- <xsl:if test="string-length($switchblock2) > 0">
- <xsl:text> switch (nDefine)
</xsl:text>
- <xsl:text> {
</xsl:text>
- <xsl:value-of select="$switchblock2"/>
- <xsl:text> default:
</xsl:text>
- <xsl:text> break;
</xsl:text>
- <xsl:text> }
</xsl:text>
- </xsl:if>
- <xsl:text>}
</xsl:text>
-</xsl:template>
-
-<xsl:template name="charactersactionforvalues">
- <xsl:variable name="name" select="@name"/>
- <xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$name]">
- <xsl:text> {
</xsl:text>
- <xsl:text> // </xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text>
</xsl:text>
- <xsl:for-each select="rng:data[@type='int']">
- <xsl:text> OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue(sText));
</xsl:text>
- <xsl:text> pValueHandler->setValue(pValue);
</xsl:text>
- </xsl:for-each>
- <xsl:for-each select="rng:list">
- <xsl:text> ListValueMapPointer pListValueMap = getListValueMap(nDefine);
</xsl:text>
- <xsl:text> if (pListValueMap.get() != NULL)
</xsl:text>
- <xsl:text> {
</xsl:text>
- <xsl:text> OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue((*pListValueMap)[sText]));
</xsl:text>
- <xsl:text> pValueHandler->setValue(pValue);</xsl:text>
- <xsl:text> }
</xsl:text>
- </xsl:for-each>
- <xsl:text> }
</xsl:text>
- </xsl:for-each>
-</xsl:template>
-
-<!-- factoryactions -->
-<xsl:template name="factoryactions">
- <xsl:variable name="ns" select="@name"/>
- <xsl:for-each select="resource/action[not(@name='characters')]">
- <xsl:sort select="@name"/>
- <xsl:if test="generate-id(key('actions', @name)[ancestor::namespace/@name=$ns][1]) = generate-id(.)">
- <xsl:variable name="name" select="@name"/>
- <xsl:for-each select="ancestor::namespace">
- <xsl:call-template name="factoryaction">
- <xsl:with-param name="action" select="$name"/>
- </xsl:call-template>
- </xsl:for-each>
- </xsl:if>
- </xsl:for-each>
- <xsl:call-template name="factoryaction">
- <xsl:with-param name="action">characters</xsl:with-param>
- </xsl:call-template>
-</xsl:template>
-
-<xsl:template name="factorygetdefinename">
- <xsl:text>
-#ifdef DEBUG_DOMAINMAPPER
-string </xsl:text>
- <xsl:call-template name="factoryclassname"/>
- <xsl:text>::getDefineName(Id nId) const
-{
- static IdToStringMapPointer pMap;
-
- if (pMap.get() == NULL)
- {
- pMap = IdToStringMapPointer(new IdToStringMap());
-
-</xsl:text>
- <xsl:for-each select="rng:grammar/rng:define">
- <xsl:text>
- (*pMap)[</xsl:text>
- <xsl:call-template name="idfordefine"/>
- <xsl:text>] = "</xsl:text>
- <xsl:value-of select="@name"/>
- <xsl:text>";</xsl:text>
- </xsl:for-each>
- }
-
- return (*pMap)[nId];
-}
-#endif
-
-</xsl:template>
-
-<xsl:template name="factorytokentoidmapinner">
- <xsl:variable name="name" select="@name"/>
- <xsl:for-each select=".//rng:ref[not(ancestor::rng:element or ancestor::rng:attribute)]">
- <xsl:variable name="refname" select="@name"/>
- <xsl:variable name="refblock1">
- <xsl:for-each
- select="ancestor::rng:grammar/rng:define[@name=$refname]">
- <xsl:call-template name="factorytokentoidmapinner"/>
- </xsl:for-each>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="string-length($refblock1) = 0">
- <xsl:for-each select="ancestor::model/namespace/rng:grammar/rng:define[@name=$refname]">
- <xsl:call-template name="factorytokentoidmapinner"/>
- </xsl:for-each>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$refblock1"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- <xsl:variable name="body">
- <xsl:for-each select="ancestor::namespace/resource[@name=$name]">
- <xsl:for-each select="element[@tokenid]|attribute[@tokenid]">
- <xsl:text>
- (*pMap)[</xsl:text>
- <xsl:call-template name="fasttoken"/>
- <xsl:text>] = </xsl:text>
- <xsl:call-template name="idtoqname">
- <xsl:with-param name="id" select="@tokenid"/>
- </xsl:call-template>
- <xsl:text>;</xsl:text>
- </xsl:for-each>
- </xsl:for-each>
- </xsl:variable>
- <xsl:if test="string-length($body) > 0">
- <xsl:text>
- // </xsl:text>
- <xsl:value-of select="$name"/>
- <xsl:value-of select="$body"/>
- </xsl:if>
-</xsl:template>
-
-<xsl:template name="factorytokentoidmap">
- <xsl:text>
-TokenToIdMapPointer </xsl:text>
- <xsl:call-template name="factoryclassname"/>
- <xsl:text>::createTokenToIdMap(Id nId)
-{
- TokenToIdMapPointer pMap(new TokenToIdMap());
-
- switch (nId)
- {</xsl:text>
- <xsl:for-each select="rng:grammar/rng:define">
- <xsl:variable name="inner">
- <xsl:call-template name="factorytokentoidmapinner"/>
- </xsl:variable>
- <xsl:if test="string-length($inner) > 0">
- <xsl:text>
- </xsl:text>
- <xsl:call-template name="caselabeldefine"/>
- <xsl:value-of select="$inner"/>
- <xsl:text>
- break;</xsl:text>
- </xsl:if>
- </xsl:for-each>
- <xsl:text>
- default:</xsl:text>
- <xsl:for-each select="start">
- <xsl:variable name="name" select="@name"/>
- <xsl:text>
- // </xsl:text>
- <xsl:value-of select="$name"/>
- <xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$name]">
- <xsl:call-template name="factorytokentoidmapinner"/>
- </xsl:for-each>
- </xsl:for-each>
- <xsl:text>
- break;
- }
-
- return pMap;
-}
-</xsl:text>
-</xsl:template>
-
-<xsl:template name="factoryattributeactiondefineinner">
- <xsl:variable name="name" select="@name"/>
- <xsl:variable name="block">
- <xsl:for-each select="ancestor::namespace/resource[@name=$name]">
- <xsl:for-each select="attribute[@action]">
- <xsl:text>
- case </xsl:text>
- <xsl:call-template name="fasttoken"/>
- <xsl:text>:
- pHandler-></xsl:text>
- <xsl:value-of select="@action"/>
- <xsl:text>(pValue);
- break;</xsl:text>
- </xsl:for-each>
- </xsl:for-each>
- </xsl:variable>
- <xsl:if test="string-length($block) > 0">
- <xsl:variable name="handlertype">
- <xsl:text>OOXMLFastContextHandler</xsl:text>
- <xsl:for-each select="ancestor::namespace/resource[@name=$name]">
- <xsl:value-of select="@resource"/>
- </xsl:for-each>
- </xsl:variable>
- <xsl:text>
- {
- </xsl:text>
- <xsl:value-of select="$handlertype"/>
- <xsl:text> * pHandler = dynamic_cast<</xsl:text>
- <xsl:value-of select="$handlertype"/>
- <xsl:text> * >(_pHandler);
-
- switch(nToken)
- {</xsl:text>
- <xsl:value-of select="$block"/>
- <xsl:text>
- default:
- break;
- }
- }</xsl:text>
- </xsl:if>
-</xsl:template>
-
-<xsl:template name="factoryattributeactioninner">
- <xsl:for-each select="rng:grammar/rng:define">
- <xsl:variable name="inner">
- <xsl:call-template name="factoryattributeactiondefineinner"/>
- </xsl:variable>
- <xsl:if test="string-length($inner) > 0">
- <xsl:text>
- </xsl:text>
- <xsl:call-template name="caselabeldefine"/>
- <xsl:value-of select="$inner"/>
- <xsl:text>
- break;</xsl:text>
- </xsl:if>
- </xsl:for-each>
-</xsl:template>
-
-<xsl:template name="factoryattributeaction">
- <xsl:variable name="inner">
- <xsl:call-template name="factoryattributeactioninner"/>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="string-length($inner) > 0">
- <xsl:text>
-void </xsl:text>
-<xsl:call-template name="factoryclassname"/>
-<xsl:text>::attributeAction(OOXMLFastContextHandler * _pHandler, Token_t nToken, OOXMLValue::Pointer_t pValue)
-{
- switch(_pHandler->getDefine())
- {</xsl:text>
- <xsl:value-of select="$inner"/>
- <xsl:text>
- default:
- break;
- }
-}
-</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>
-void </xsl:text>
-<xsl:call-template name="factoryclassname"/>
-<xsl:text>::attributeAction(OOXMLFastContextHandler *, Token_t, OOXMLValue::Pointer_t)
-{
-}
-</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<xsl:template name="factorygetname">
- <xsl:param name="ns"/>
- <xsl:text>
-#ifdef DEBUG_DOMAINMAPPER
-string </xsl:text>
-<xsl:call-template name="factoryclassname"/>
-<xsl:text>::getName() const
-{
- return "</xsl:text>
- <xsl:value-of select="$ns"/>
- <xsl:text>";
-}
-#endif
-</xsl:text>
-</xsl:template>
-
- <xsl:template match="/">
- <xsl:variable name="ns" select="substring-before(substring-after($file, 'OOXMLFactory_'), '.cxx')"/>
- <xsl:text>
-#include "ooxml/resourceids.hxx"
-#include "OOXMLFactory_values.hxx"
-#include "OOXMLFactory_</xsl:text>
- <xsl:value-of select="$ns"/>
- <xsl:text>.hxx"
-#include "ooxml/OOXMLFastHelper.hxx"
-
-#ifdef _MSC_VER
-#pragma warning(disable:4065) // switch statement contains 'default' but no 'case' labels
-#endif
-
-namespace writerfilter {
-namespace ooxml {
-
-/// @cond GENERATED
- </xsl:text>
- <xsl:for-each select="/model/namespace[@name=$ns]">
- <xsl:call-template name="factorymutexdecl"/>
- <xsl:call-template name="factoryconstructor"/>
- <xsl:call-template name="factorydestructor"/>
- <xsl:call-template name="factorygetinstance"/>
- <xsl:call-template name="factoryattributetoresourcemap"/>
- <xsl:call-template name="factorylistvaluemap"/>
- <xsl:call-template name="factorycreateelementmap"/>
- <xsl:call-template name="factoryactions"/>
- <xsl:call-template name="factorygetdefinename"/>
- <xsl:call-template name="factorytokentoidmap"/>
- <xsl:call-template name="factoryattributeaction"/>
- <xsl:call-template name="factorygetname">
- <xsl:with-param name="ns" select="$ns"/>
- </xsl:call-template>
- </xsl:for-each>
- <xsl:text>
-/// @endcond
-}}
-</xsl:text>
-</xsl:template>
-
-</xsl:stylesheet>
diff --git a/writerfilter/source/ooxml/factorytools.xsl b/writerfilter/source/ooxml/factorytools.xsl
deleted file mode 100644
index e99669a..0000000
--- a/writerfilter/source/ooxml/factorytools.xsl
+++ /dev/null
@@ -1,262 +0,0 @@
-<!--
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
--->
-<xsl:stylesheet
- version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
- xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
- xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
- xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
- xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
- xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
- xmlns:xlink="http://www.w3.org/1999/xlink"
- xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
- xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
- xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
- xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
- xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
- xmlns:math="http://www.w3.org/1998/Math/MathML"
- xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
- xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
- xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
- xmlns:ooo="http://openoffice.org/2004/office"
- xmlns:ooow="http://openoffice.org/2004/writer"
- xmlns:oooc="http://openoffice.org/2004/calc"
- xmlns:dom="http://www.w3.org/2001/xml-events"
- xmlns:xforms="http://www.w3.org/2002/xforms"
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:rng="http://relaxng.org/ns/structure/1.0"
- xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
- xmlns:xalan="http://xml.apache.org/xalan"
- xmlns:UML = 'org.omg.xmi.namespace.UML'
- xmlns:common="http://exslt.org/common"
- exclude-result-prefixes = "xalan"
- xml:space="default">
-
-<!--
- KEYS
--->
-<xsl:key name="context-resource"
- match="resource" use="@name"/>
-
-<xsl:key name="tokenids" match="@tokenid|@sendtokenid" use="."/>
-
-<xsl:key name="actions" match="/model/namespace/resource/action"
- use="@name"/>
-
-<xsl:key name="definename" match="//rng:define" use="@name"/>
-
-<xsl:key name="resources" match="/model/namespace/resource" use="@resource"/>
-
-<xsl:key name="value-with-content" match="//rng:value"
- use="text()"/>
-
-<xsl:key name="same-token-name" match="rng:element|rng:attribute" use="@localname"/>
-
-<!--
-IDENTIFIERs
--->
-
-<!--
-
-generates token identifer for a namespace
-
-NN_<namespace/@name>
-
--->
-<xsl:template name="fastnamespace">
- <xsl:if test="string-length(@prefix) > 0">
- <xsl:text>NS_</xsl:text>
- <xsl:value-of select="@prefix"/>
- </xsl:if>
-</xsl:template>
-
-<!--
-
-generates local part of token identifier for a rng:define
-
-OOXML_<rng:define/@localname>
-
--->
-<xsl:template name="fastlocalname">
- <xsl:text>OOXML_</xsl:text>
- <xsl:value-of select="@localname"/>
-</xsl:template>
-
-<!--
-
-generates identifier for a token
-
--->
-<xsl:template name="fasttoken">
- <xsl:variable name="ns">
- <xsl:call-template name="fastnamespace"/>
- </xsl:variable>
- <xsl:if test="string-length($ns) > 0">
- <xsl:value-of select="$ns"/>
- <xsl:text>|</xsl:text>
- </xsl:if>
- <xsl:call-template name="fastlocalname"/>
-</xsl:template>
-
-<!-- generates identifier for a namespace
-
-NN_<namespace/@name>
-
--->
-<xsl:template name="idfornamespace">
- <xsl:text>NN_</xsl:text>
- <xsl:value-of select="translate(@name, '-', '_')"/>
-</xsl:template>
-
-<!-- generates local part of identier for rng:define
-
-DEFINE_<rng:define/@name>
-
--->
-<xsl:template name="localidfordefine">
- <xsl:text>DEFINE_</xsl:text>
- <xsl:value-of select="@name"/>
-</xsl:template>
-
-<!-- generates id for a rng:define
-
-NN_<namespace/@name> | DEFINE_<rng:define/@name>
-
--->
-<xsl:template name="idfordefine">
- <xsl:for-each select="ancestor::namespace">
- <xsl:call-template name="idfornamespace"/>
- </xsl:for-each>
- <xsl:text>|</xsl:text>
- <xsl:call-template name="localidfordefine"/>
-</xsl:template>
-
-<!--
-
-creates case label for a rng:define:
-
-case NN_<namesapce/@name> | DEFINE_<rng:define/@name>:
-
--->
-<xsl:template name="caselabeldefine">
- <xsl:text>case </xsl:text>
- <xsl:call-template name="idfordefine"/>
- <xsl:text>:</xsl:text>
-</xsl:template>
-
-<!--
- Generates name for a value string.
-
- Value strings are possible values for attributes in OOXML.
-
- @param string the string as present in the according <rng:value>
--->
-<xsl:template name="valuestringname">
- <xsl:param name="string"/>
- <xsl:text>OOXMLValueString_</xsl:text>
- <xsl:value-of select="translate($string, '-+ ,', 'mp__')"/>
-</xsl:template>
-
-<!--
- Generates qname for id.
-
- @param id the id to generate qname for
-
- If id is of format <prefix>:<localname> the result is
-
- NS_<prefix>::LN_<localname>
-
- If id does not contain ":" the result is just id.
--->
-<xsl:template name="idtoqname">
- <xsl:param name="id"/>
- <xsl:choose>
- <xsl:when test="contains($id, ':')">
- <xsl:text>NS_</xsl:text>
- <xsl:value-of select='substring-before($id, ":")'/>
- <xsl:text>::LN_</xsl:text>
- <xsl:value-of select='substring-after($id, ":")'/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$id"/>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<!--
- Returns the value of the @resource attribute of the <resource>
- node according to the current <define>.
--->
-<xsl:template name="contextresource">
- <xsl:variable name="name" select="@name"/>
- <xsl:variable name="nsid" select="generate-id(ancestor::namespace)"/>
- <xsl:variable name="resourcesamens">
- <xsl:for-each select="key('context-resource', @name)">
- <xsl:if test="generate-id(ancestor::namespace) = $nsid">
- <xsl:value-of select="@resource"/>
- </xsl:if>
- </xsl:for-each>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="$name='BUILT_IN_ANY_TYPE'">
- <xsl:text>Any</xsl:text>
- </xsl:when>
- <xsl:when test="string-length($resourcesamens) = 0">
- <xsl:for-each select="key('context-resource', @name)[1]">
- <xsl:value-of select="@resource"/>
- </xsl:for-each>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$resourcesamens"/>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<xsl:template name="idforref">
- <xsl:variable name="name" select="@name"/>
- <xsl:variable name="result1">
- <xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$name]">
- <xsl:call-template name="idfordefine"/>
- </xsl:for-each>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="$name='BUILT_IN_ANY_TYPE'">
- <xsl:text>0</xsl:text>
- </xsl:when>
- <xsl:when test="string-length($result1) = 0">
- <xsl:for-each select="(ancestor::model/namespace/rng:grammar/rng:define[@name=$name])[1]">
- <xsl:call-template name="idfordefine"/>
- </xsl:for-each>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$result1"/>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<!-- factoryclassname -->
-<xsl:template name="factoryclassname">
- <xsl:text>OOXMLFactory_</xsl:text>
- <xsl:value-of select="translate(@name, '-', '_')"/>
-</xsl:template>
-
-</xsl:stylesheet>
More information about the Libreoffice-commits
mailing list