Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef _LOCALE_NODE_
20 : #define _LOCALE_NODE_
21 : #include <com/sun/star/xml/sax/XParser.hpp>
22 : #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
23 :
24 : #include <vector>
25 :
26 : #include <com/sun/star/lang/XComponent.hpp>
27 : #include <com/sun/star/xml/sax/SAXParseException.hpp>
28 : #include <com/sun/star/io/XOutputStream.hpp>
29 : #include <com/sun/star/io/XActiveDataSource.hpp>
30 :
31 : #include <cppuhelper/implbase1.hxx>
32 : #include <cppuhelper/implbase3.hxx>
33 :
34 : using namespace ::rtl;
35 : using namespace ::std;
36 : using namespace ::cppu;
37 : using namespace ::com::sun::star::uno;
38 : using namespace ::com::sun::star::lang;
39 : using namespace ::com::sun::star::xml::sax;
40 : using namespace ::com::sun::star::io;
41 :
42 : class OFileWriter
43 : {
44 : public:
45 :
46 : OFileWriter(const char *pcFile, const char *locale );
47 : virtual ~OFileWriter();
48 : virtual void writeStringCharacters(const OUString& str) const;
49 : virtual void writeAsciiString(const char *str)const ;
50 : virtual void writeInt(sal_Int16 nb) const;
51 : virtual void writeFunction(const char *func, const char *count, const char *array) const;
52 : virtual void writeRefFunction(const char *func, const OUString& useLocale) const;
53 : virtual void writeFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const;
54 : virtual void writeRefFunction(const char *func, const OUString& useLocale, const char *to) const;
55 : virtual void writeFunction2(const char *func, const char *style, const char* attr, const char *array) const;
56 : virtual void writeRefFunction2(const char *func, const OUString& useLocale) const;
57 : virtual void writeFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const;
58 : virtual void writeRefFunction3(const char *func, const OUString& useLocale) const;
59 : virtual void writeIntParameter(const sal_Char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const;
60 : virtual bool writeDefaultParameter(const sal_Char* pAsciiStr, const OUString& str, sal_Int16 count) const;
61 : virtual bool writeDefaultParameter(const sal_Char* pAsciiStr, const OUString& str) const;
62 : virtual void writeParameter(const sal_Char* pAsciiStr, const OUString& aChars) const;
63 : virtual void writeParameter(const sal_Char* pAsciiStr, const OUString& aChars, sal_Int16 count) const;
64 : virtual void writeParameter(const sal_Char* pAsciiStr, const OUString& aChars, sal_Int16 count0, sal_Int16 count1) const;
65 : virtual void writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const OUString& aChars, const sal_Int16 count) const;
66 : virtual void writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const OUString& aChars) const;
67 : virtual void writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const OUString& aChars, sal_Int16 count0, sal_Int16 count1) const;
68 : virtual void flush(void) const ;
69 : virtual void closeOutput(void) const;
70 : /// Return the locale string, something like en_US or de_DE
71 1057 : const char * getLocale() const { return theLocale; }
72 : private:
73 : char m_pcFile[1024];
74 : char theLocale[50];
75 : FILE *m_f;
76 : };
77 :
78 47844 : class Attr {
79 : Sequence <OUString> name;
80 : Sequence <OUString> value;
81 :
82 : public:
83 : Attr (const Reference< XAttributeList > & attr);
84 : const OUString& getValueByName (const sal_Char *str) const;
85 : sal_Int32 getLength() const;
86 : const OUString& getTypeByIndex (sal_Int32 idx) const;
87 : const OUString& getValueByIndex (sal_Int32 idx) const ;
88 : };
89 :
90 : class LocaleNode
91 : {
92 : OUString aName;
93 : OUString aValue;
94 : Attr aAttribs;
95 : LocaleNode * parent;
96 : LocaleNode* * children;
97 : sal_Int32 nChildren;
98 : sal_Int32 childArrSize;
99 :
100 : void setParent ( LocaleNode* node);
101 :
102 : protected:
103 : mutable int nError;
104 :
105 : public:
106 : LocaleNode (const OUString& name, const Reference< XAttributeList > & attr);
107 155433 : inline void setValue(const OUString &oValue) { aValue += oValue; };
108 17492 : inline const OUString& getName() const { return aName; };
109 45427 : inline const OUString& getValue() const { return aValue; };
110 16275 : inline const Attr& getAttr() const { return aAttribs; };
111 19674 : inline sal_Int32 getNumberOfChildren () const { return nChildren; };
112 50518 : inline LocaleNode * getChildAt (sal_Int32 idx) const { return children[idx] ; };
113 : const LocaleNode * findNode ( const sal_Char *name) const;
114 : void print () const;
115 : void printR () const;
116 : virtual ~LocaleNode();
117 : void addChild ( LocaleNode * node);
118 900 : const LocaleNode* getParent() const { return parent; };
119 : const LocaleNode* getRoot() const;
120 : int getError() const;
121 : virtual void generateCode (const OFileWriter &of) const;
122 : // MUST >= nMinLen
123 : // nMinLen <= 0 : no error
124 : // nMinLen > 0 : error if less than nMinLen characters
125 : // SHOULD NOT > nMaxLen
126 : // nMaxLen < 0 : any length
127 : // nMaxLen >= 0 : warning if more than nMaxLen characters
128 : OUString writeParameterCheckLen( const OFileWriter &of, const char* pParameterName, const LocaleNode* pNode, sal_Int32 nMinLen, sal_Int32 nMaxLen ) const;
129 : OUString writeParameterCheckLen( const OFileWriter &of, const char* pNodeName, const char* pParameterName, sal_Int32 nMinLen, sal_Int32 nMaxLen ) const;
130 : // ++nError with output to stderr
131 : void incError( const char* pStr ) const;
132 : // ++nError with output to stderr
133 : void incError( const OUString& rStr ) const;
134 : // ++nError with output to stderr, pStr should contain "%d", otherwise appended
135 : void incErrorInt( const char* pStr, int nVal ) const;
136 : // ++nError with output to stderr, pStr should contain "%s", otherwise appended
137 : void incErrorStr( const char* pStr, const OUString& rVal ) const;
138 : // ++nError with output to stderr, pStr should contain "%s %s", otherwise
139 : // appended
140 : void incErrorStrStr( const char* pStr, const OUString& rVal1, const OUString& rVal2 ) const;
141 : // used by incError...(), returns a pointer to a static buffer,
142 : // pDefaultConversion is appended if pFormat doesn't contain a %
143 : // specification and should be something like ": %d" or ": %s" or similar.
144 : char* prepareErrorFormat( const char* pFormat, const char* pDefaultConversion ) const;
145 : static LocaleNode* createNode (const OUString& name,const Reference< XAttributeList > & attr);
146 : };
147 :
148 446 : class LCInfoNode : public LocaleNode {
149 : public:
150 223 : inline LCInfoNode (const OUString& name,
151 223 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
152 : virtual void generateCode (const OFileWriter &of) const;
153 : };
154 :
155 :
156 446 : class LCCTYPENode : public LocaleNode {
157 : public:
158 223 : inline LCCTYPENode (const OUString& name,
159 223 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
160 :
161 : virtual void generateCode (const OFileWriter &of) const;
162 : };
163 :
164 448 : class LCFormatNode : public LocaleNode {
165 : static sal_Int16 mnSection;
166 : static sal_Int16 mnFormats;
167 : public:
168 224 : inline LCFormatNode (const OUString& name,
169 224 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
170 :
171 : virtual void generateCode (const OFileWriter &of) const;
172 : };
173 :
174 446 : class LCCollationNode : public LocaleNode {
175 : public:
176 223 : inline LCCollationNode (const OUString& name,
177 223 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
178 :
179 : virtual void generateCode (const OFileWriter &of) const;
180 : };
181 :
182 446 : class LCIndexNode : public LocaleNode {
183 : public:
184 223 : inline LCIndexNode (const OUString& name,
185 223 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
186 :
187 : virtual void generateCode (const OFileWriter &of) const;
188 : };
189 :
190 446 : class LCSearchNode : public LocaleNode {
191 : public:
192 223 : inline LCSearchNode (const OUString& name,
193 223 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
194 :
195 : virtual void generateCode (const OFileWriter &of) const;
196 : };
197 :
198 446 : class LCCalendarNode : public LocaleNode {
199 : public:
200 223 : inline LCCalendarNode (const OUString& name,
201 223 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
202 :
203 : virtual void generateCode (const OFileWriter &of) const;
204 : };
205 :
206 446 : class LCCurrencyNode : public LocaleNode {
207 : public:
208 223 : inline LCCurrencyNode (const OUString& name,
209 223 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
210 :
211 : virtual void generateCode (const OFileWriter &of) const;
212 : };
213 :
214 446 : class LCTransliterationNode : public LocaleNode {
215 : public:
216 223 : inline LCTransliterationNode (const OUString& name,
217 223 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
218 :
219 : virtual void generateCode (const OFileWriter &of) const;
220 : };
221 :
222 446 : class LCMiscNode : public LocaleNode {
223 : public:
224 223 : inline LCMiscNode (const OUString& name,
225 223 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
226 :
227 : virtual void generateCode (const OFileWriter &of) const;
228 : };
229 :
230 446 : class LCNumberingLevelNode : public LocaleNode {
231 : public:
232 223 : inline LCNumberingLevelNode (const OUString& name,
233 223 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
234 :
235 : virtual void generateCode (const OFileWriter &of) const;
236 : };
237 :
238 446 : class LCOutlineNumberingLevelNode : public LocaleNode {
239 : public:
240 223 : inline LCOutlineNumberingLevelNode (const OUString& name,
241 223 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
242 :
243 : virtual void generateCode (const OFileWriter &of) const;
244 : };
245 :
246 : #endif
247 :
248 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|