Revert "tdf#158280 Replace usage of InputDialog with SvxNameDialog"
[LibreOffice.git] / oox / source / token / namespaces.py
blob41df70a88274e3562d97708a566959e9da288fc7
1 # This file is part of the LibreOffice project.
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 # This file incorporates work covered by the following license notice:
9 # Licensed to the Apache Software Foundation (ASF) under one or more
10 # contributor license agreements. See the NOTICE file distributed
11 # with this work for additional information regarding copyright
12 # ownership. The ASF licenses this file to you under the Apache
13 # License, Version 2.0 (the "License"); you may not use this file
14 # except in compliance with the License. You may obtain a copy of
15 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 import sys
19 import re
21 infile_name = sys.argv[1]
22 id_out_name = sys.argv[2]
23 name_out_name = sys.argv[3]
24 txt_out_name = sys.argv[4]
25 instrict_name = sys.argv[5]
26 strict_out_name = sys.argv[6]
28 # parse input file
30 namespaces = {}
32 with open(infile_name) as infile:
33 for line in infile:
34 line = line.strip()
35 # trim comments
36 line = line.split('#')[0]
37 # skip empty lines
38 if line:
39 # check for valid characters
40 m = re.match(r'([a-zA-Z][a-zA-Z0-9]*)\s+([a-zA-Z0-9-.:\/]+)\s*$', line)
41 if not m:
42 sys.exit('Invalid character in input data: ' + line)
43 namespaces[m.group(1)] = m.group(2)
45 # OOXML strict namespaces
47 namespaces_strict = {}
48 with open(instrict_name) as infile_strict:
49 for line in infile_strict:
50 line = line.strip()
51 # trim comments
52 line = line.split('#')[0]
53 # skip empty lines
54 if line:
55 # check for valid characters
56 m = re.match(r'([a-zA-Z][a-zA-Z0-9]*)\s+([a-zA-Z0-9-.:\/]+)\s*$', line)
57 if not m:
58 sys.exit("Error: invalid character in input data: " + line)
59 namespaces_strict[m.group(1)] = m.group(2)
61 # generate output files
63 idfile = open(id_out_name, 'w')
64 namefile = open(name_out_name, 'w')
65 txtfile = open(txt_out_name, 'w')
66 namefile_strict = open(strict_out_name, 'w')
68 # number of bits to shift the namespace identifier
69 shift = 16
71 idfile.write("const size_t NMSP_SHIFT = {};\n".format(shift))
73 i = 1
74 for token in sorted(namespaces.keys()):
75 idfile.write("const sal_Int32 NMSP_{} = {} << NMSP_SHIFT;\n".format(token, i))
76 cur_id = i << shift
77 namefile.write("{{ {}, \"{}\" }},\n".format(cur_id, namespaces[token]))
78 namefile_strict.write("{{ {}, \"{}\" }},\n".format(cur_id, namespaces_strict[token]))
79 txtfile.write("{} {} {}\n".format(cur_id, token, namespaces[token]))
80 txtfile.write("{} {} {}\n".format(cur_id, token, namespaces_strict[token]))
81 i += 1
83 idfile.close()
84 namefile.close()
85 namefile_strict.close()
86 txtfile.close()