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/registry/XImplementationRegistration.hpp>
27 : #include <com/sun/star/lang/XComponent.hpp>
28 :
29 : #include <com/sun/star/xml/sax/SAXParseException.hpp>
30 :
31 : #include <com/sun/star/io/XOutputStream.hpp>
32 : #include <com/sun/star/io/XActiveDataSource.hpp>
33 :
34 : #include <cppuhelper/implbase1.hxx>
35 : #include <cppuhelper/implbase3.hxx>
36 :
37 : using namespace ::rtl;
38 : using namespace ::std;
39 : using namespace ::com::sun::star::xml::sax;
40 : using namespace ::cppu;
41 : using namespace ::com::sun::star::uno;
42 : using namespace ::com::sun::star::lang;
43 : using namespace ::com::sun::star::registry;
44 : using namespace ::com::sun::star::xml::sax;
45 : using namespace ::com::sun::star::io;
46 :
47 : class OFileWriter
48 : {
49 : public:
50 :
51 : OFileWriter(const char *pcFile, const char *locale );
52 : virtual ~OFileWriter();
53 : virtual void writeStringCharacters(const ::rtl::OUString& str) const;
54 : virtual void writeAsciiString(const char *str)const ;
55 : virtual void writeInt(sal_Int16 nb) const;
56 : virtual void writeFunction(const char *func, const char *count, const char *array) const;
57 : virtual void writeRefFunction(const char *func, const ::rtl::OUString& useLocale) const;
58 : virtual void writeFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const;
59 : virtual void writeRefFunction(const char *func, const ::rtl::OUString& useLocale, const char *to) const;
60 : virtual void writeFunction2(const char *func, const char *style, const char* attr, const char *array) const;
61 : virtual void writeRefFunction2(const char *func, const ::rtl::OUString& useLocale) const;
62 : virtual void writeFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const;
63 : virtual void writeRefFunction3(const char *func, const ::rtl::OUString& useLocale) const;
64 : virtual void writeIntParameter(const sal_Char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const;
65 : virtual bool writeDefaultParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& str, sal_Int16 count) const;
66 : virtual bool writeDefaultParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& str) const;
67 : virtual void writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars) const;
68 : virtual void writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count) const;
69 : virtual void writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count0, sal_Int16 count1) const;
70 : virtual void writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, const sal_Int16 count) const;
71 : virtual void writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars) const;
72 : virtual void writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count0, sal_Int16 count1) const;
73 : virtual void flush(void) const ;
74 : virtual void closeOutput(void) const;
75 : /// Return the locale string, something like en_US or de_DE
76 1036 : const char * getLocale() const { return theLocale; }
77 : private:
78 : char m_pcFile[1024];
79 : char theLocale[50];
80 : FILE *m_f;
81 : };
82 :
83 46922 : class Attr {
84 : Sequence <OUString> name;
85 : Sequence <OUString> value;
86 :
87 : public:
88 : Attr (const Reference< XAttributeList > & attr);
89 : const OUString& getValueByName (const sal_Char *str) const;
90 : sal_Int32 getLength() const;
91 : const OUString& getTypeByIndex (sal_Int32 idx) const;
92 : const OUString& getValueByIndex (sal_Int32 idx) const ;
93 : };
94 :
95 : class LocaleNode
96 : {
97 : OUString aName;
98 : OUString aValue;
99 : Attr aAttribs;
100 : LocaleNode * parent;
101 : LocaleNode* * children;
102 : sal_Int32 nChildren;
103 : sal_Int32 childArrSize;
104 :
105 : void setParent ( LocaleNode* node);
106 :
107 : protected:
108 : mutable int nError;
109 :
110 : public:
111 : LocaleNode (const OUString& name, const Reference< XAttributeList > & attr);
112 152475 : inline void setValue(const OUString &oValue) { aValue += oValue; };
113 17120 : inline const OUString& getName() const { return aName; };
114 44646 : inline const OUString& getValue() const { return aValue; };
115 15900 : inline const Attr& getAttr() const { return aAttribs; };
116 19296 : inline sal_Int32 getNumberOfChildren () const { return nChildren; };
117 49573 : inline LocaleNode * getChildAt (sal_Int32 idx) const { return children[idx] ; };
118 : const LocaleNode * findNode ( const sal_Char *name) const;
119 : void print () const;
120 : void printR () const;
121 : virtual ~LocaleNode();
122 : void addChild ( LocaleNode * node);
123 882 : const LocaleNode* getParent() const { return parent; };
124 : const LocaleNode* getRoot() const;
125 : int getError() const;
126 : virtual void generateCode (const OFileWriter &of) const;
127 : // MUST >= nMinLen
128 : // nMinLen <= 0 : no error
129 : // nMinLen > 0 : error if less than nMinLen characters
130 : // SHOULD NOT > nMaxLen
131 : // nMaxLen < 0 : any length
132 : // nMaxLen >= 0 : warning if more than nMaxLen characters
133 : OUString writeParameterCheckLen( const OFileWriter &of, const char* pParameterName, const LocaleNode* pNode, sal_Int32 nMinLen, sal_Int32 nMaxLen ) const;
134 : OUString writeParameterCheckLen( const OFileWriter &of, const char* pNodeName, const char* pParameterName, sal_Int32 nMinLen, sal_Int32 nMaxLen ) const;
135 : // ++nError with output to stderr
136 : void incError( const char* pStr ) const;
137 : // ++nError with output to stderr
138 : void incError( const ::rtl::OUString& rStr ) const;
139 : // ++nError with output to stderr, pStr should contain "%d", otherwise appended
140 : void incErrorInt( const char* pStr, int nVal ) const;
141 : // ++nError with output to stderr, pStr should contain "%s", otherwise appended
142 : void incErrorStr( const char* pStr, const ::rtl::OUString& rVal ) const;
143 : // ++nError with output to stderr, pStr should contain "%s %s", otherwise
144 : // appended
145 : void incErrorStrStr( const char* pStr, const ::rtl::OUString& rVal1, const ::rtl::OUString& rVal2 ) const;
146 : // used by incError...(), returns a pointer to a static buffer,
147 : // pDefaultConversion is appended if pFormat doesn't contain a %
148 : // specification and should be something like ": %d" or ": %s" or similar.
149 : char* prepareErrorFormat( const char* pFormat, const char* pDefaultConversion ) const;
150 : static LocaleNode* createNode (const OUString& name,const Reference< XAttributeList > & attr);
151 : };
152 :
153 440 : class LCInfoNode : public LocaleNode {
154 : public:
155 220 : inline LCInfoNode (const OUString& name,
156 220 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
157 : virtual void generateCode (const OFileWriter &of) const;
158 : };
159 :
160 :
161 440 : class LCCTYPENode : public LocaleNode {
162 : public:
163 220 : inline LCCTYPENode (const OUString& name,
164 220 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
165 :
166 : virtual void generateCode (const OFileWriter &of) const;
167 : };
168 :
169 442 : class LCFormatNode : public LocaleNode {
170 : static sal_Int16 mnSection;
171 : static sal_Int16 mnFormats;
172 : public:
173 221 : inline LCFormatNode (const OUString& name,
174 221 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
175 :
176 : virtual void generateCode (const OFileWriter &of) const;
177 : };
178 :
179 440 : class LCCollationNode : public LocaleNode {
180 : public:
181 220 : inline LCCollationNode (const OUString& name,
182 220 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
183 :
184 : virtual void generateCode (const OFileWriter &of) const;
185 : };
186 :
187 440 : class LCIndexNode : public LocaleNode {
188 : public:
189 220 : inline LCIndexNode (const OUString& name,
190 220 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
191 :
192 : virtual void generateCode (const OFileWriter &of) const;
193 : };
194 :
195 440 : class LCSearchNode : public LocaleNode {
196 : public:
197 220 : inline LCSearchNode (const OUString& name,
198 220 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
199 :
200 : virtual void generateCode (const OFileWriter &of) const;
201 : };
202 :
203 440 : class LCCalendarNode : public LocaleNode {
204 : public:
205 220 : inline LCCalendarNode (const OUString& name,
206 220 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
207 :
208 : virtual void generateCode (const OFileWriter &of) const;
209 : };
210 :
211 440 : class LCCurrencyNode : public LocaleNode {
212 : public:
213 220 : inline LCCurrencyNode (const OUString& name,
214 220 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
215 :
216 : virtual void generateCode (const OFileWriter &of) const;
217 : };
218 :
219 440 : class LCTransliterationNode : public LocaleNode {
220 : public:
221 220 : inline LCTransliterationNode (const OUString& name,
222 220 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
223 :
224 : virtual void generateCode (const OFileWriter &of) const;
225 : };
226 :
227 440 : class LCMiscNode : public LocaleNode {
228 : public:
229 220 : inline LCMiscNode (const OUString& name,
230 220 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
231 :
232 : virtual void generateCode (const OFileWriter &of) const;
233 : };
234 :
235 440 : class LCNumberingLevelNode : public LocaleNode {
236 : public:
237 220 : inline LCNumberingLevelNode (const OUString& name,
238 220 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
239 :
240 : virtual void generateCode (const OFileWriter &of) const;
241 : };
242 :
243 440 : class LCOutlineNumberingLevelNode : public LocaleNode {
244 : public:
245 220 : inline LCOutlineNumberingLevelNode (const OUString& name,
246 220 : const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
247 :
248 : virtual void generateCode (const OFileWriter &of) const;
249 : };
250 :
251 : #endif
252 :
253 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|