[Libreoffice-commits] core.git: writerfilter/CustomTarget_source.mk writerfilter/source

Miklos Vajna vmiklos at collabora.co.uk
Sun Jun 22 08:05:17 PDT 2014


 writerfilter/CustomTarget_source.mk        |    6 +-
 writerfilter/source/ooxml/factoryinc.py    |   50 ++++++++++++++++
 writerfilter/source/ooxml/factoryinc.xsl   |   86 -----------------------------
 writerfilter/source/ooxml/factorytools.xsl |   14 ----
 4 files changed, 53 insertions(+), 103 deletions(-)

New commits:
commit 76d9ad4b535aa51efd85e66c727546803e09e456
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Sun Jun 22 16:07:51 2014 +0200

    writerfilter: convert factoryinc to Python
    
    Change-Id: I23ee4844fcc034f1d586c10d6a16db71a4db5363

diff --git a/writerfilter/CustomTarget_source.mk b/writerfilter/CustomTarget_source.mk
index 55ba50a..a791bfa 100644
--- a/writerfilter/CustomTarget_source.mk
+++ b/writerfilter/CustomTarget_source.mk
@@ -84,9 +84,9 @@ $(writerfilter_GEN_ooxml_Factory_cxx) : $(writerfilter_SRC)/ooxml/factoryimpl.xs
 	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,XSL,1)
 	$(call gb_Helper_abbreviate_dirs, $(writerfilter_XSLTCOMMAND) $< $(writerfilter_GEN_ooxml_Model_processed)) > $@
 
-$(writerfilter_GEN_ooxml_Factory_hxx) : $(writerfilter_SRC)/ooxml/factoryinc.xsl $(writerfilter_GEN_ooxml_Model_processed)
-	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,XSL,1)
-	$(call gb_Helper_abbreviate_dirs, $(writerfilter_XSLTCOMMAND) $< $(writerfilter_GEN_ooxml_Model_processed)) > $@
+$(writerfilter_GEN_ooxml_Factory_hxx) : $(writerfilter_SRC)/ooxml/factoryinc.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_GEN_ooxml_FactoryValues_hxx) : $(writerfilter_SRC_ooxml_FactoryValues_xsl) $(writerfilter_GEN_ooxml_Model_processed)
 	$(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,XSL,1)
diff --git a/writerfilter/source/ooxml/factoryinc.py b/writerfilter/source/ooxml/factoryinc.py
new file mode 100644
index 0000000..f29462d
--- /dev/null
+++ b/writerfilter/source/ooxml/factoryinc.py
@@ -0,0 +1,50 @@
+#!/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
+
+
+def createInclude(model):
+    print("""
+#ifndef OOXML_FACTORY_GENERATED_HXX
+#define OOXML_FACTORY_GENERATED_HXX
+
+namespace writerfilter {
+namespace ooxml {
+
+/// @cond GENERATED
+    """)
+
+    # Create namespaces.
+    counter = 1
+    for namespace in sorted([ns.getAttribute("name") for ns in model.getElementsByTagName("namespace")]):
+        print("const Id NN_%s = %s << 16;" % (namespace.replace('-', '_'), counter))
+        counter += 1
+
+    # Create defines.
+    counter = 1
+    defines = []
+    for define in sorted([ns.getAttribute("name") for ns in model.getElementsByTagName("define")]):
+        if define not in defines:
+            print("const Id DEFINE_%s = %s;" % (define, counter))
+            defines.append(define)
+        counter += 1
+    print("""/// @endcond
+}}
+
+#endif // OOXML_FACTORY_GENERATED_HXX""")
+
+
+modelPath = sys.argv[1]
+model = minidom.parse(modelPath)
+createInclude(model)
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/writerfilter/source/ooxml/factoryinc.xsl b/writerfilter/source/ooxml/factoryinc.xsl
deleted file mode 100644
index a72cffd..0000000
--- a/writerfilter/source/ooxml/factoryinc.xsl
+++ /dev/null
@@ -1,86 +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="factorynamespaceidimpls">
-    <xsl:for-each select="/model/namespace">
-      <xsl:sort select="@name"/>
-      <xsl:text>
-const Id </xsl:text>
-<xsl:call-template name="idfornamespace"/>
-<xsl:text> = </xsl:text>
-<xsl:value-of select="position()"/>
-<xsl:text> << 16;</xsl:text>
-    </xsl:for-each>
-</xsl:template>
-
-  <xsl:template match="/">
-    <xsl:text>
-#ifndef OOXML_FACTORY_GENERATED_HXX
-#define OOXML_FACTORY_GENERATED_HXX
-
-namespace writerfilter {
-namespace ooxml {
-
-/// @cond GENERATED
-    </xsl:text>
-    <xsl:call-template name="factorynamespaceidimpls"/>
-    <xsl:call-template name="factorydefineidimpls"/>
-    <xsl:text>
-/// @endcond
-}}
-
-#endif // OOXML_FACTORY_GENERATED_HXX
-</xsl:text>
-</xsl:template>
-
-</xsl:stylesheet>
diff --git a/writerfilter/source/ooxml/factorytools.xsl b/writerfilter/source/ooxml/factorytools.xsl
index 08c4f40..7968796 100644
--- a/writerfilter/source/ooxml/factorytools.xsl
+++ b/writerfilter/source/ooxml/factorytools.xsl
@@ -290,18 +290,4 @@ NS_<namespace/@alias>
     </xsl:for-each>
 </xsl:template>
 
-<xsl:template name="factorydefineidimpls">
-    <xsl:for-each select="//rng:define">
-        <xsl:sort select="@name"/>
-        <xsl:if test="generate-id(key('definename', @name)[1]) = generate-id(.)">
-            <xsl:text>
-const Id </xsl:text>
-            <xsl:call-template name="localidfordefine"/>
-            <xsl:text> = </xsl:text>
-            <xsl:value-of select="position()"/>
-            <xsl:text>;</xsl:text>
-        </xsl:if>
-    </xsl:for-each>
-</xsl:template>
-
 </xsl:stylesheet>


More information about the Libreoffice-commits mailing list