LibreOffice Module writerfilter (master) 1
factory_ns.py
Go to the documentation of this file.
1#!/usr/bin/env python
2#
3# This file is part of the LibreOffice project.
4#
5# This Source Code Form is subject to the terms of the Mozilla Public
6# License, v. 2.0. If a copy of the MPL was not distributed with this
7# file, You can obtain one at http://mozilla.org/MPL/2.0/.
8#
9
10from xml.dom import minidom
11import sys
12
13
14def createHeader(model, ns):
15 nsToken = ns.replace('-', '_')
16 print("""
17#ifndef INCLUDED_OOXML_FACTORY_%s_HXX
18#define INCLUDED_OOXML_FACTORY_%s_HXX
19#include "ooxml/OOXMLFactory.hxx"
20#include "OOXMLFactory_generated.hxx"
21#include "oox/token/namespaces.hxx"
22#include "ooxml/resourceids.hxx"
23#include "tools/ref.hxx"
24
25namespace writerfilter {
26namespace ooxml {
27
28/// @cond GENERATED
29""" % (nsToken.upper(), nsToken.upper()))
30
31 print("""class OOXMLFactory_%s : public OOXMLFactory_ns
32{
33public:
34 typedef tools::SvRef<OOXMLFactory_ns> Pointer_t;
35
36 static Pointer_t getInstance();
37
38 virtual const AttributeInfo* getAttributeInfoArray(Id nId);
39 virtual bool getElementId(Id nDefine, Id nId, ResourceType& rOutResource, Id& rOutElement);
40 virtual bool getListValue(Id nId, std::string_view aValue, sal_uInt32& rOutValue);
41 virtual Id getResourceId(Id nDefine, sal_Int32 nToken);
42""" % nsToken)
43
44 actions = []
45 for nsNode in [i for i in model.getElementsByTagName("namespace") if i.getAttribute("name") == ns]:
46 for resource in nsNode.getElementsByTagName("resource"):
47 for action in [i.getAttribute("name") for i in resource.childNodes if i.nodeType == minidom.Node.ELEMENT_NODE and i.tagName == "action"]:
48 if action != "characters" and action not in actions:
49 actions.append(action)
50 for action in actions:
51 print(" void %sAction(OOXMLFastContextHandler* pHandler);" % action)
52
53 print("""virtual void charactersAction(OOXMLFastContextHandler* pHandler, const OUString & sText);
54 virtual void attributeAction(OOXMLFastContextHandler* pHandler, Token_t nToken, const OOXMLValue::Pointer_t& pValue);
55
56 virtual ~OOXMLFactory_%s();
57
58protected:
59 static Pointer_t m_pInstance;
60
61 OOXMLFactory_%s();
62};
63""" % (nsToken, nsToken))
64
65 print("""/// @endcond
66}}
67#endif //INCLUDED_OOXML_FACTORY_%s_HXX""" % nsToken.upper())
68
69
70modelPath = sys.argv[1]
71filePath = sys.argv[2]
72model = minidom.parse(modelPath)
73ns = filePath.split('OOXMLFactory_')[1].split('.hxx')[0]
74createHeader(model, ns)
75
76# vim:set shiftwidth=4 softtabstop=4 expandtab:
def createHeader(model, ns)
Definition: factory_ns.py:14