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