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