summaryrefslogtreecommitdiff
path: root/sw/source/writerfilter/ooxml/factory_ns.py
blob: 18b07aba1c62e159c3b935f6c47cc96bd55403e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/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 xml.dom import minidom
import sys


def createHeader(model, ns):
    nsToken = ns.replace('-', '_')
    print("""
#ifndef INCLUDED_OOXML_FACTORY_%s_HXX
#define INCLUDED_OOXML_FACTORY_%s_HXX
#include "ooxml/OOXMLFactory.hxx"
#include "OOXMLFactory_generated.hxx"
#include "oox/token/namespaces.hxx"
#include "ooxml/resourceids.hxx"
#include "tools/ref.hxx"

namespace writerfilter {
namespace ooxml {

/// @cond GENERATED
""" % (nsToken.upper(), nsToken.upper()))

    print("""class OOXMLFactory_%s : public OOXMLFactory_ns
{
public:
    typedef tools::SvRef<OOXMLFactory_ns> Pointer_t;

    static Pointer_t getInstance();

    virtual const AttributeInfo* getAttributeInfoArray(Id nId);
    virtual bool getElementId(Id nDefine, Id nId, ResourceType& rOutResource, Id& rOutElement);
    virtual bool getListValue(Id nId, std::string_view aValue, sal_uInt32& rOutValue);
    virtual Id getResourceId(Id nDefine, sal_Int32 nToken);
""" % nsToken)

    actions = []
    for nsNode in [i for i in model.getElementsByTagName("namespace") if i.getAttribute("name") == ns]:
        for resource in nsNode.getElementsByTagName("resource"):
            for action in [i.getAttribute("name") for i in resource.childNodes if i.nodeType == minidom.Node.ELEMENT_NODE and i.tagName == "action"]:
                if action != "characters" and action not in actions:
                    actions.append(action)
    for action in actions:
        print("    void %sAction(OOXMLFastContextHandler* pHandler);" % action)

    print("""virtual void charactersAction(OOXMLFastContextHandler* pHandler, const OUString & sText);
    virtual void attributeAction(OOXMLFastContextHandler* pHandler, Token_t nToken, const OOXMLValue::Pointer_t& pValue);

    virtual ~OOXMLFactory_%s();

protected:
    static Pointer_t m_pInstance;

    OOXMLFactory_%s();
};
""" % (nsToken, nsToken))

    print("""/// @endcond
}}
#endif //INCLUDED_OOXML_FACTORY_%s_HXX""" % nsToken.upper())


modelPath = sys.argv[1]
filePath = sys.argv[2]
model = minidom.parse(modelPath)
ns = filePath.split('OOXMLFactory_')[1].split('.hxx')[0]
createHeader(model, ns)

# vim:set shiftwidth=4 softtabstop=4 expandtab: