1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef _LOCALE_NODE_ 28 #define _LOCALE_NODE_ 29 #include <com/sun/star/xml/sax/XParser.hpp> 30 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> 31 32 #include <vector> 33 34 #include <com/sun/star/registry/XImplementationRegistration.hpp> 35 #include <com/sun/star/lang/XComponent.hpp> 36 37 #include <com/sun/star/xml/sax/SAXParseException.hpp> 38 #include <com/sun/star/xml/sax/XParser.hpp> 39 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> 40 41 #include <com/sun/star/io/XOutputStream.hpp> 42 #include <com/sun/star/io/XActiveDataSource.hpp> 43 44 #include <cppuhelper/servicefactory.hxx> 45 #include <cppuhelper/implbase1.hxx> 46 #include <cppuhelper/implbase3.hxx> 47 48 using namespace ::rtl; 49 using namespace ::std; 50 using namespace ::com::sun::star::xml::sax; 51 using namespace ::cppu; 52 using namespace ::com::sun::star::uno; 53 using namespace ::com::sun::star::lang; 54 using namespace ::com::sun::star::registry; 55 using namespace ::com::sun::star::xml::sax; 56 using namespace ::com::sun::star::io; 57 58 class OFileWriter 59 { 60 public: 61 62 OFileWriter(const char *pcFile, const char *locale ); 63 virtual ~OFileWriter(); 64 virtual void writeStringCharacters(const ::rtl::OUString& str) const; 65 virtual void writeAsciiString(const char *str)const ; 66 virtual void writeInt(sal_Int16 nb) const; 67 virtual void writeFunction(const char *func, const char *count, const char *array) const; 68 virtual void writeRefFunction(const char *func, const ::rtl::OUString& useLocale) const; 69 virtual void writeFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const; 70 virtual void writeRefFunction(const char *func, const ::rtl::OUString& useLocale, const char *to) const; 71 virtual void writeFunction2(const char *func, const char *style, const char* attr, const char *array) const; 72 virtual void writeRefFunction2(const char *func, const ::rtl::OUString& useLocale) const; 73 virtual void writeFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const; 74 virtual void writeRefFunction3(const char *func, const ::rtl::OUString& useLocale) const; 75 virtual void writeIntParameter(const sal_Char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const; 76 virtual bool writeDefaultParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& str, sal_Int16 count) const; 77 virtual bool writeDefaultParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& str) const; 78 virtual void writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars) const; 79 virtual void writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count) const; 80 virtual void writeParameter(const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count0, sal_Int16 count1) const; 81 virtual void writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, const sal_Int16 count) const; 82 virtual void writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars) const; 83 virtual void writeParameter(const sal_Char* pTagStr, const sal_Char* pAsciiStr, const ::rtl::OUString& aChars, sal_Int16 count0, sal_Int16 count1) const; 84 virtual void flush(void) const ; 85 virtual void closeOutput(void) const; 86 /// Return the locale string, something like en_US or de_DE 87 const char * getLocale() const { return theLocale; } 88 private: 89 char m_pcFile[1024]; 90 char theLocale[50]; 91 FILE *m_f; 92 }; 93 94 class Attr { 95 Sequence <OUString> name; 96 Sequence <OUString> value; 97 98 public: 99 Attr (const Reference< XAttributeList > & attr); 100 const OUString& getValueByName (const sal_Char *str) const; 101 sal_Int32 getLength() const; 102 const OUString& getTypeByIndex (sal_Int32 idx) const; 103 const OUString& getValueByIndex (sal_Int32 idx) const ; 104 }; 105 106 class LocaleNode 107 { 108 OUString aName; 109 OUString aValue; 110 Attr * xAttribs; 111 LocaleNode * parent; 112 LocaleNode* * children; 113 sal_Int32 nChildren; 114 sal_Int32 childArrSize; 115 116 void setParent ( LocaleNode* node); 117 118 protected: 119 mutable int nError; 120 121 public: 122 LocaleNode (const OUString& name, const Reference< XAttributeList > & attr); 123 inline void setValue(const OUString &oValue) { aValue += oValue; }; 124 inline const OUString& getName() const { return aName; }; 125 inline const OUString& getValue() const { return aValue; }; 126 inline const Attr* getAttr() const { return xAttribs; }; 127 inline sal_Int32 getNumberOfChildren () const { return nChildren; }; 128 inline LocaleNode * getChildAt (sal_Int32 idx) const { return children[idx] ; }; 129 const LocaleNode * findNode ( const sal_Char *name) const; 130 void print () const; 131 void printR () const; 132 virtual ~LocaleNode(); 133 void addChild ( LocaleNode * node); 134 const LocaleNode* getParent() const { return parent; }; 135 const LocaleNode* getRoot() const; 136 int getError() const; 137 virtual void generateCode (const OFileWriter &of) const; 138 // MUST >= nMinLen 139 // nMinLen <= 0 : no error 140 // nMinLen > 0 : error if less than nMinLen characters 141 // SHOULD NOT > nMaxLen 142 // nMaxLen < 0 : any length 143 // nMaxLen >= 0 : warning if more than nMaxLen characters 144 OUString writeParameterCheckLen( const OFileWriter &of, const char* pParameterName, const LocaleNode* pNode, sal_Int32 nMinLen, sal_Int32 nMaxLen ) const; 145 OUString writeParameterCheckLen( const OFileWriter &of, const char* pNodeName, const char* pParameterName, sal_Int32 nMinLen, sal_Int32 nMaxLen ) const; 146 // ++nError with output to stderr 147 void incError( const char* pStr ) const; 148 // ++nError with output to stderr 149 void incError( const ::rtl::OUString& rStr ) const; 150 // ++nError with output to stderr, pStr should contain "%d", otherwise appended 151 void incErrorInt( const char* pStr, int nVal ) const; 152 // ++nError with output to stderr, pStr should contain "%s", otherwise appended 153 void incErrorStr( const char* pStr, const ::rtl::OUString& rVal ) const; 154 // used by incError...(), returns a pointer to a static buffer, 155 // pDefaultConversion is appended if pFormat doesn't contain a % 156 // specification and should be something like ": %d" or ": %s" or similar. 157 char* prepareErrorFormat( const char* pFormat, const char* pDefaultConversion ) const; 158 static LocaleNode* createNode (const OUString& name,const Reference< XAttributeList > & attr); 159 }; 160 161 class LCInfoNode : public LocaleNode { 162 public: 163 inline LCInfoNode (const OUString& name, 164 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; }; 165 virtual void generateCode (const OFileWriter &of) const; 166 }; 167 168 169 class LCCTYPENode : public LocaleNode { 170 public: 171 inline LCCTYPENode (const OUString& name, 172 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; }; 173 174 virtual void generateCode (const OFileWriter &of) const; 175 }; 176 177 class LCFormatNode : public LocaleNode { 178 static sal_Int16 mnSection; 179 static sal_Int16 mnFormats; 180 public: 181 inline LCFormatNode (const OUString& name, 182 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; }; 183 184 virtual void generateCode (const OFileWriter &of) const; 185 }; 186 187 class LCCollationNode : public LocaleNode { 188 public: 189 inline LCCollationNode (const OUString& name, 190 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; }; 191 192 virtual void generateCode (const OFileWriter &of) const; 193 }; 194 195 class LCIndexNode : public LocaleNode { 196 public: 197 inline LCIndexNode (const OUString& name, 198 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; }; 199 200 virtual void generateCode (const OFileWriter &of) const; 201 }; 202 203 class LCSearchNode : public LocaleNode { 204 public: 205 inline LCSearchNode (const OUString& name, 206 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; }; 207 208 virtual void generateCode (const OFileWriter &of) const; 209 }; 210 211 class LCCalendarNode : public LocaleNode { 212 public: 213 inline LCCalendarNode (const OUString& name, 214 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; }; 215 216 virtual void generateCode (const OFileWriter &of) const; 217 }; 218 219 class LCCurrencyNode : public LocaleNode { 220 public: 221 inline LCCurrencyNode (const OUString& name, 222 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; }; 223 224 virtual void generateCode (const OFileWriter &of) const; 225 }; 226 227 class LCTransliterationNode : public LocaleNode { 228 public: 229 inline LCTransliterationNode (const OUString& name, 230 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; }; 231 232 virtual void generateCode (const OFileWriter &of) const; 233 }; 234 235 class LCMiscNode : public LocaleNode { 236 public: 237 inline LCMiscNode (const OUString& name, 238 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; }; 239 240 virtual void generateCode (const OFileWriter &of) const; 241 }; 242 243 class LCNumberingLevelNode : public LocaleNode { 244 public: 245 inline LCNumberingLevelNode (const OUString& name, 246 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; }; 247 248 virtual void generateCode (const OFileWriter &of) const; 249 }; 250 251 class LCOutlineNumberingLevelNode : public LocaleNode { 252 public: 253 inline LCOutlineNumberingLevelNode (const OUString& name, 254 const Reference< XAttributeList > & attr) : LocaleNode (name, attr) { ; }; 255 256 virtual void generateCode (const OFileWriter &of) const; 257 }; 258 259 #endif 260