Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / i18npool / source / localedata / LocaleNode.hxx
blobaa52a92c8a74c8522c742340ffe487a510a6452d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
24 #include <vector>
26 #include <com/sun/star/registry/XImplementationRegistration.hpp>
27 #include <com/sun/star/lang/XComponent.hpp>
29 #include <com/sun/star/xml/sax/SAXParseException.hpp>
31 #include <com/sun/star/io/XOutputStream.hpp>
32 #include <com/sun/star/io/XActiveDataSource.hpp>
34 #include <cppuhelper/servicefactory.hxx>
35 #include <cppuhelper/implbase1.hxx>
36 #include <cppuhelper/implbase3.hxx>
38 using namespace ::rtl;
39 using namespace ::std;
40 using namespace ::com::sun::star::xml::sax;
41 using namespace ::cppu;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::lang;
44 using namespace ::com::sun::star::registry;
45 using namespace ::com::sun::star::xml::sax;
46 using namespace ::com::sun::star::io;
48 class OFileWriter
50 public:
52 OFileWriter(const char *pcFile, const char *locale );
53 virtual ~OFileWriter();
54 virtual void writeStringCharacters(const ::rtl::OUString& str) const;
55 virtual void writeAsciiString(const char *str)const ;
56 virtual void writeInt(sal_Int16 nb) const;
57 virtual void writeFunction(const char *func, const char *count, const char *array) const;
58 virtual void writeRefFunction(const char *func, const ::rtl::OUString& useLocale) const;
59 virtual void writeFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const;
60 virtual void writeRefFunction(const char *func, const ::rtl::OUString& useLocale, const char *to) const;
61 virtual void writeFunction2(const char *func, const char *style, const char* attr, const char *array) const;
62 virtual void writeRefFunction2(const char *func, const ::rtl::OUString& useLocale) const;
63 virtual void writeFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const;
64 virtual void writeRefFunction3(const char *func, const ::rtl::OUString& useLocale) const;
65 virtual void writeIntParameter(const sal_Char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const;
66 virtual bool writeDefaultParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& str, sal_Int16 count) const;
67 virtual bool writeDefaultParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& str) const;
68 virtual void writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars) const;
69 virtual void writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count) const;
70 virtual void writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count0, sal_Int16 count1) const;
71 virtual void writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, const sal_Int16 count) const;
72 virtual void writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars) const;
73 virtual void writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count0, sal_Int16 count1) const;
74 virtual void flush(void) const ;
75 virtual void closeOutput(void) const;
76 /// Return the locale string, something like en_US or de_DE
77 const char * getLocale() const { return theLocale; }
78 private:
79 char m_pcFile[1024];
80 char theLocale[50];
81 FILE *m_f;
84 class Attr {
85 Sequence <OUString> name;
86 Sequence <OUString> value;
88 public:
89 Attr (const Reference< XAttributeList > & attr);
90 const OUString& getValueByName (const sal_Char *str) const;
91 sal_Int32 getLength() const;
92 const OUString& getTypeByIndex (sal_Int32 idx) const;
93 const OUString& getValueByIndex (sal_Int32 idx) const ;
96 class LocaleNode
98 OUString aName;
99 OUString aValue;
100 Attr aAttribs;
101 LocaleNode * parent;
102 LocaleNode* * children;
103 sal_Int32 nChildren;
104 sal_Int32 childArrSize;
106 void setParent ( LocaleNode* node);
108 protected:
109 mutable int nError;
111 public:
112 LocaleNode (const OUString& name, const Reference< XAttributeList > & attr);
113 inline void setValue(const OUString &oValue) { aValue += oValue; };
114 inline const OUString& getName() const { return aName; };
115 inline const OUString& getValue() const { return aValue; };
116 inline const Attr& getAttr() const { return aAttribs; };
117 inline sal_Int32 getNumberOfChildren () const { return nChildren; };
118 inline LocaleNode * getChildAt (sal_Int32 idx) const { return children[idx] ; };
119 const LocaleNode * findNode ( const sal_Char *name) const;
120 void print () const;
121 void printR () const;
122 virtual ~LocaleNode();
123 void addChild ( LocaleNode * node);
124 const LocaleNode* getParent() const { return parent; };
125 const LocaleNode* getRoot() const;
126 int getError() const;
127 virtual void generateCode (const OFileWriter &of) const;
128 // MUST >= nMinLen
129 // nMinLen <= 0 : no error
130 // nMinLen > 0 : error if less than nMinLen characters
131 // SHOULD NOT > nMaxLen
132 // nMaxLen < 0 : any length
133 // nMaxLen >= 0 : warning if more than nMaxLen characters
134 OUString writeParameterCheckLen( const OFileWriter &of, const char* pParameterName, const LocaleNode* pNode, sal_Int32 nMinLen, sal_Int32 nMaxLen ) const;
135 OUString writeParameterCheckLen( const OFileWriter &of, const char* pNodeName, const char* pParameterName, sal_Int32 nMinLen, sal_Int32 nMaxLen ) const;
136 // ++nError with output to stderr
137 void incError( const char* pStr ) const;
138 // ++nError with output to stderr
139 void incError( const ::rtl::OUString& rStr ) const;
140 // ++nError with output to stderr, pStr should contain "%d", otherwise appended
141 void incErrorInt( const char* pStr, int nVal ) const;
142 // ++nError with output to stderr, pStr should contain "%s", otherwise appended
143 void incErrorStr( const char* pStr, const ::rtl::OUString& rVal ) const;
144 // ++nError with output to stderr, pStr should contain "%s %s", otherwise
145 // appended
146 void incErrorStrStr( const char* pStr, const ::rtl::OUString& rVal1, const ::rtl::OUString& rVal2 ) const;
147 // used by incError...(), returns a pointer to a static buffer,
148 // pDefaultConversion is appended if pFormat doesn't contain a %
149 // specification and should be something like ": %d" or ": %s" or similar.
150 char* prepareErrorFormat( const char* pFormat, const char* pDefaultConversion ) const;
151 static LocaleNode* createNode (const OUString& name,const Reference< XAttributeList > & attr);
154 class LCInfoNode : public LocaleNode {
155 public:
156 inline LCInfoNode (const OUString& name,
157 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
158 virtual void generateCode (const OFileWriter &of) const;
162 class LCCTYPENode : public LocaleNode {
163 public:
164 inline LCCTYPENode (const OUString& name,
165 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
167 virtual void generateCode (const OFileWriter &of) const;
170 class LCFormatNode : public LocaleNode {
171 static sal_Int16 mnSection;
172 static sal_Int16 mnFormats;
173 public:
174 inline LCFormatNode (const OUString& name,
175 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
177 virtual void generateCode (const OFileWriter &of) const;
180 class LCCollationNode : public LocaleNode {
181 public:
182 inline LCCollationNode (const OUString& name,
183 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
185 virtual void generateCode (const OFileWriter &of) const;
188 class LCIndexNode : public LocaleNode {
189 public:
190 inline LCIndexNode (const OUString& name,
191 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
193 virtual void generateCode (const OFileWriter &of) const;
196 class LCSearchNode : public LocaleNode {
197 public:
198 inline LCSearchNode (const OUString& name,
199 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
201 virtual void generateCode (const OFileWriter &of) const;
204 class LCCalendarNode : public LocaleNode {
205 public:
206 inline LCCalendarNode (const OUString& name,
207 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
209 virtual void generateCode (const OFileWriter &of) const;
212 class LCCurrencyNode : public LocaleNode {
213 public:
214 inline LCCurrencyNode (const OUString& name,
215 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
217 virtual void generateCode (const OFileWriter &of) const;
220 class LCTransliterationNode : public LocaleNode {
221 public:
222 inline LCTransliterationNode (const OUString& name,
223 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
225 virtual void generateCode (const OFileWriter &of) const;
228 class LCMiscNode : public LocaleNode {
229 public:
230 inline LCMiscNode (const OUString& name,
231 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
233 virtual void generateCode (const OFileWriter &of) const;
236 class LCNumberingLevelNode : public LocaleNode {
237 public:
238 inline LCNumberingLevelNode (const OUString& name,
239 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
241 virtual void generateCode (const OFileWriter &of) const;
244 class LCOutlineNumberingLevelNode : public LocaleNode {
245 public:
246 inline LCOutlineNumberingLevelNode (const OUString& name,
247 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; };
249 virtual void generateCode (const OFileWriter &of) const;
252 #endif
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */