diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-06-22 16:07:51 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-06-22 17:04:09 +0200 |
commit | 76d9ad4b535aa51efd85e66c727546803e09e456 (patch) | |
tree | 94b91a2cb0bd0aeb9a8b80736556bf590ee1b970 | |
parent | ad2e71573d66a76d16301bbdd794bbc775db5cd0 (diff) |
writerfilter: convert factoryinc to Python
Change-Id: I23ee4844fcc034f1d586c10d6a16db71a4db5363
-rw-r--r-- | writerfilter/CustomTarget_source.mk | 6 | ||||
-rw-r--r-- | writerfilter/source/ooxml/factoryinc.py | 50 | ||||
-rw-r--r-- | writerfilter/source/ooxml/factoryinc.xsl | 86 | ||||
-rw-r--r-- | writerfilter/source/ooxml/factorytools.xsl | 14 |
4 files changed, 53 insertions, 103 deletions
diff --git a/writerfilter/CustomTarget_source.mk b/writerfilter/CustomTarget_source.mk index 55ba50ae6d32..a791bfa42d64 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 000000000000..f29462d08635 --- /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 a72cffd83679..000000000000 --- 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 08c4f407de53..7968796f38d3 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> |