1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: LocaleNode.hxx,v $
10 * $Revision: 1.14.24.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include <com/sun/star/xml/sax/XParser.hpp>
33 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
37 #include <com/sun/star/registry/XImplementationRegistration.hpp>
38 #include <com/sun/star/lang/XComponent.hpp>
40 #include <com/sun/star/xml/sax/SAXParseException.hpp>
41 #include <com/sun/star/xml/sax/XParser.hpp>
42 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
44 #include <com/sun/star/io/XOutputStream.hpp>
45 #include <com/sun/star/io/XActiveDataSource.hpp>
47 #include <cppuhelper/servicefactory.hxx>
48 #include <cppuhelper/implbase1.hxx>
49 #include <cppuhelper/implbase3.hxx>
51 using namespace ::rtl
;
52 using namespace ::std
;
53 using namespace ::com::sun::star::xml::sax
;
54 using namespace ::cppu
;
55 using namespace ::com::sun::star::uno
;
56 using namespace ::com::sun::star::lang
;
57 using namespace ::com::sun::star::registry
;
58 using namespace ::com::sun::star::xml::sax
;
59 using namespace ::com::sun::star::io
;
65 OFileWriter(const char *pcFile
, const char *locale
);
66 virtual ~OFileWriter();
67 virtual void writeStringCharacters(const ::rtl::OUString
& str
) const;
68 virtual void writeAsciiString(const char *str
)const ;
69 virtual void writeInt(sal_Int16 nb
) const;
70 virtual void writeFunction(const char *func
, const char *count
, const char *array
) const;
71 virtual void writeRefFunction(const char *func
, const ::rtl::OUString
& useLocale
) const;
72 virtual void writeFunction(const char *func
, const char *count
, const char *array
, const char *from
, const char *to
) const;
73 virtual void writeRefFunction(const char *func
, const ::rtl::OUString
& useLocale
, const char *to
) const;
74 virtual void writeFunction2(const char *func
, const char *style
, const char* attr
, const char *array
) const;
75 virtual void writeRefFunction2(const char *func
, const ::rtl::OUString
& useLocale
) const;
76 virtual void writeFunction3(const char *func
, const char *style
, const char* levels
, const char* attr
, const char *array
) const;
77 virtual void writeRefFunction3(const char *func
, const ::rtl::OUString
& useLocale
) const;
78 virtual void writeIntParameter(const sal_Char
* pAsciiStr
, const sal_Int16 count
, sal_Int16 val
) const;
79 virtual bool writeDefaultParameter(const sal_Char
* pAsciiStr
, const ::rtl::OUString
& str
, sal_Int16 count
) const;
80 virtual bool writeDefaultParameter(const sal_Char
* pAsciiStr
, const ::rtl::OUString
& str
) const;
81 virtual void writeParameter(const sal_Char
* pAsciiStr
, const ::rtl::OUString
& aChars
) const;
82 virtual void writeParameter(const sal_Char
* pAsciiStr
, const ::rtl::OUString
& aChars
, sal_Int16 count
) const;
83 virtual void writeParameter(const sal_Char
* pAsciiStr
, const ::rtl::OUString
& aChars
, sal_Int16 count0
, sal_Int16 count1
) const;
84 virtual void writeParameter(const sal_Char
* pTagStr
, const sal_Char
* pAsciiStr
, const ::rtl::OUString
& aChars
, const sal_Int16 count
) const;
85 virtual void writeParameter(const sal_Char
* pTagStr
, const sal_Char
* pAsciiStr
, const ::rtl::OUString
& aChars
) const;
86 virtual void writeParameter(const sal_Char
* pTagStr
, const sal_Char
* pAsciiStr
, const ::rtl::OUString
& aChars
, sal_Int16 count0
, sal_Int16 count1
) const;
87 virtual void flush(void) const ;
88 virtual void closeOutput(void) const;
89 /// Return the locale string, something like en_US or de_DE
90 const char * getLocale() const { return theLocale
; }
98 Sequence
<OUString
> name
;
99 Sequence
<OUString
> value
;
102 Attr (const Reference
< XAttributeList
> & attr
);
103 const OUString
& getValueByName (const sal_Char
*str
) const;
104 sal_Int32
getLength() const;
105 const OUString
& getTypeByIndex (sal_Int32 idx
) const;
106 const OUString
& getValueByIndex (sal_Int32 idx
) const ;
115 LocaleNode
* * children
;
117 sal_Int32 childArrSize
;
119 void setParent ( LocaleNode
* node
);
125 LocaleNode (const OUString
& name
, const Reference
< XAttributeList
> & attr
);
126 inline void setValue(const OUString
&oValue
) { aValue
+= oValue
; };
127 inline const OUString
& getName() const { return aName
; };
128 inline const OUString
& getValue() const { return aValue
; };
129 inline const Attr
* getAttr() const { return xAttribs
; };
130 inline sal_Int32
getNumberOfChildren () const { return nChildren
; };
131 inline LocaleNode
* getChildAt (sal_Int32 idx
) const { return children
[idx
] ; };
132 const LocaleNode
* findNode ( const sal_Char
*name
) const;
134 void printR () const;
135 virtual ~LocaleNode();
136 void addChild ( LocaleNode
* node
);
137 const LocaleNode
* getParent() const { return parent
; };
138 const LocaleNode
* getRoot() const;
139 int getError() const;
140 virtual void generateCode (const OFileWriter
&of
) const;
142 // nMinLen <= 0 : no error
143 // nMinLen > 0 : error if less than nMinLen characters
144 // SHOULD NOT > nMaxLen
145 // nMaxLen < 0 : any length
146 // nMaxLen >= 0 : warning if more than nMaxLen characters
147 OUString
writeParameterCheckLen( const OFileWriter
&of
, const char* pParameterName
, const LocaleNode
* pNode
, sal_Int32 nMinLen
, sal_Int32 nMaxLen
) const;
148 OUString
writeParameterCheckLen( const OFileWriter
&of
, const char* pNodeName
, const char* pParameterName
, sal_Int32 nMinLen
, sal_Int32 nMaxLen
) const;
149 // ++nError with output to stderr
150 void incError( const char* pStr
) const;
151 // ++nError with output to stderr
152 void incError( const ::rtl::OUString
& rStr
) const;
153 // ++nError with output to stderr, pStr should contain "%d", otherwise appended
154 void incErrorInt( const char* pStr
, int nVal
) const;
155 // ++nError with output to stderr, pStr should contain "%s", otherwise appended
156 void incErrorStr( const char* pStr
, const ::rtl::OUString
& rVal
) const;
157 // used by incError...(), returns a pointer to a static buffer,
158 // pDefaultConversion is appended if pFormat doesn't contain a %
159 // specification and should be something like ": %d" or ": %s" or similar.
160 char* prepareErrorFormat( const char* pFormat
, const char* pDefaultConversion
) const;
161 static LocaleNode
* createNode (const OUString
& name
,const Reference
< XAttributeList
> & attr
);
164 class LCInfoNode
: public LocaleNode
{
166 inline LCInfoNode (const OUString
& name
,
167 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
168 virtual void generateCode (const OFileWriter
&of
) const;
172 class LCCTYPENode
: public LocaleNode
{
174 inline LCCTYPENode (const OUString
& name
,
175 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
177 virtual void generateCode (const OFileWriter
&of
) const;
180 class LCFormatNode
: public LocaleNode
{
181 static sal_Int16 mnSection
;
182 static sal_Int16 mnFormats
;
184 inline LCFormatNode (const OUString
& name
,
185 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
187 virtual void generateCode (const OFileWriter
&of
) const;
190 class LCCollationNode
: public LocaleNode
{
192 inline LCCollationNode (const OUString
& name
,
193 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
195 virtual void generateCode (const OFileWriter
&of
) const;
198 class LCIndexNode
: public LocaleNode
{
200 inline LCIndexNode (const OUString
& name
,
201 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
203 virtual void generateCode (const OFileWriter
&of
) const;
206 class LCSearchNode
: public LocaleNode
{
208 inline LCSearchNode (const OUString
& name
,
209 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
211 virtual void generateCode (const OFileWriter
&of
) const;
214 class LCCalendarNode
: public LocaleNode
{
216 inline LCCalendarNode (const OUString
& name
,
217 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
219 virtual void generateCode (const OFileWriter
&of
) const;
222 class LCCurrencyNode
: public LocaleNode
{
224 inline LCCurrencyNode (const OUString
& name
,
225 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
227 virtual void generateCode (const OFileWriter
&of
) const;
230 class LCTransliterationNode
: public LocaleNode
{
232 inline LCTransliterationNode (const OUString
& name
,
233 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
235 virtual void generateCode (const OFileWriter
&of
) const;
238 class LCMiscNode
: public LocaleNode
{
240 inline LCMiscNode (const OUString
& name
,
241 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
243 virtual void generateCode (const OFileWriter
&of
) const;
246 class LCNumberingLevelNode
: public LocaleNode
{
248 inline LCNumberingLevelNode (const OUString
& name
,
249 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
251 virtual void generateCode (const OFileWriter
&of
) const;
254 class LCOutlineNumberingLevelNode
: public LocaleNode
{
256 inline LCOutlineNumberingLevelNode (const OUString
& name
,
257 const Reference
< XAttributeList
> & attr
) : LocaleNode (name
, attr
) { ; };
259 virtual void generateCode (const OFileWriter
&of
) const;