(file) Return to MessageLoader.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 karl  1.13 //%2005////////////////////////////////////////////////////////////////////////
  2 karl  1.7  //
  3 karl  1.10 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.7  // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.10 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.13 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.7  //
 12            // Permission is hereby granted, free of charge, to any person obtaining a copy
 13            // of this software and associated documentation files (the "Software"), to
 14            // deal in the Software without restriction, including without limitation the
 15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16            // sell copies of the Software, and to permit persons to whom the Software is
 17            // furnished to do so, subject to the following conditions:
 18            // 
 19            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27            //
 28            //==============================================================================
 29 alagaraja 1.8  //
 30                //%/////////////////////////////////////////////////////////////////////////////
 31                
 32                #ifndef Pegasus_MessageLoader_h
 33                #define Pegasus_MessageLoader_h
 34                
 35                #include <cstdlib>
 36                #include <cctype>
 37                #include <Pegasus/Common/Linkage.h>
 38                #include <Pegasus/Common/Config.h>
 39                #include <Pegasus/Common/String.h>
 40                #include <Pegasus/Common/Formatter.h>
 41                #include <Pegasus/Common/AcceptLanguages.h>
 42                #include <Pegasus/Common/ContentLanguages.h>
 43                
 44                //ICU specific 
 45                #ifdef PEGASUS_HAS_ICU
 46                #include <unicode/uloc.h> 
 47                #include <unicode/ures.h>
 48                #include <unicode/umsg.h>
 49                #include <unicode/ucnv.h>
 50 alagaraja 1.8  #include <unicode/fmtable.h>
 51                #include <unicode/msgfmt.h>
 52                #endif
 53 chuck     1.6  
 54                #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
 55                
 56 alagaraja 1.8  PEGASUS_NAMESPACE_BEGIN
 57                
 58 denise.eckstein 1.9  /** <I><B>Experimental Interface</B></I><BR>
 59 alagaraja       1.8   * MessageLoaderParms class is basically a stuct class containing public variables that control
 60                       * the way MessageLoader behaves. MessageLoader uses the fields in this class to decide where and
 61                       * how to load messages from the message resources.
 62                       */
 63                      
 64                      class PEGASUS_COMMON_LINKAGE MessageLoaderParms{
 65                      	
 66                      public:
 67                      	
 68                      	/*
 69                      	 * String msg_id: unique message identifier for a particular message in a message resource
 70                      	 */
 71                      	String msg_id;	
 72                      	
 73                      	/*
 74                      	 * String default_msg: the default message to use if a message cannot be loaded from a message resource
 75                      	 */		
 76                      	String default_msg;     
 77                      	
 78                      	/*
 79                      	 * String msg_src_path: this path tells MessageLoader where to find message resources
 80 alagaraja       1.8  	 * it can be empty, fully qualified or relative to $PEGASUS_HOME
 81                      	 */
 82                      	String msg_src_path;
 83                      	
 84                      	/*
 85                      	 * AcceptLanguages acceptlanguages: This contains the languages that are acceptable by the caller
 86                      	 * of MessageLoader::getMessage(). That is, MessageLoader will do its best to return a message in 
 87                      	 * a language that was specified in this container.  This container is naturally ordered using the quality 
 88                      	 * values attached to the languages and MessageLoader iterates through this container in its natural 
 89                      	 * ordering.  This container is used by MessageLoader to load messages if it is not empty.
 90                      	 */
 91                      	AcceptLanguages acceptlanguages;
 92                      	
 93                      	/*
 94                      	 * ContentLanguages contentlanguages: This is set by MessageLoader::getMessage() after a message has
 95                      	 * been loaded from either a message resource or the default message.  After the call to MessageLoader::getMessage()
 96                      	 * the caller can check the MessageLoaderParms.contentlanguages object to see what MessageLoader set it to.
 97                      	 * In all cases where a message is returned from MessageLoader::getMessage(), this field will be set to match the
 98                      	 * language that the message was found in.
 99                      	 */
100                      	ContentLanguages contentlanguages;
101 alagaraja       1.8  	
102                      	/*
103                      	 * Boolean useProcessLocale: Default is false, if true, MessageLoader uses the system default language
104                      	 * to loads messages from.
105                      	 */
106                      	Boolean useProcessLocale;
107                      	
108                      	/*
109                      	 * Boolean useThreadLocale: Default is true, this tells MessageLoader to use the AcceptLanguages container
110                      	 * from the current Pegasus thread.
111                      	 */
112                      	Boolean useThreadLocale;
113                      	
114                      	/*
115                      	 * Boolean useICUfallback: Default is false.  Only relevant if PEGASUS_HAS_ICU is defined.
116                      	 * MessageLoader::getMessage() default behaviour is to extract messages for the langauge exactly
117                      	 * matching an available message resource.  If this is set to true, the MessageLoader is free to extract
118                      	 * a message from a less specific message resource according to its search algorithm.
119                      	 */
120                      	#ifdef PEGASUS_HAS_ICU
121                      	Boolean useICUfallback;
122 alagaraja       1.8  	#endif
123                      	
124                      	/*
125 karl            1.11 	 * const Formatter::Arg&0-9: These are assigned the various substitutions necessary to properly format
126 alagaraja       1.8  	 * the message being extracted.  MessageLoader substitutes these in the correct places in the message
127                      	 * being returned from MessageLoader::getMessage()
128                      	 */
129                      	Formatter::Arg arg0; 
130                      	Formatter::Arg arg1;
131                      	Formatter::Arg arg2;
132                      	Formatter::Arg arg3;
133                      	Formatter::Arg arg4;
134                      	Formatter::Arg arg5;
135                      	Formatter::Arg arg6;
136                      	Formatter::Arg arg7;
137                      	Formatter::Arg arg8;
138                      	Formatter::Arg arg9;
139                      	
140 karl            1.11     /** Constructor */
141                          MessageLoaderParms();
142                      
143                          /** Constructor */
144                          MessageLoaderParms(
145                      	const String& id, 
146                      	const String& msg, 
147                      	const Formatter::Arg& arg0,
148                      	const Formatter::Arg& arg1,
149                      	const Formatter::Arg& arg2,
150                      	const Formatter::Arg& arg3,
151                      	const Formatter::Arg& arg4,
152                      	const Formatter::Arg& arg5 = Formatter::DEFAULT_ARG,
153                      	const Formatter::Arg& arg6 = Formatter::DEFAULT_ARG,
154                      	const Formatter::Arg& arg7 = Formatter::DEFAULT_ARG,
155                      	const Formatter::Arg& arg8 = Formatter::DEFAULT_ARG,
156                      	const Formatter::Arg& arg9 = Formatter::DEFAULT_ARG);
157                      
158                          /** Constructor */
159                          MessageLoaderParms(
160                      	const String& id, 
161 karl            1.11 	const String& msg);
162                          
163                          /** Constructor */
164                          MessageLoaderParms(
165                      	const String& id, 
166                      	const String& msg, 
167                      	const Formatter::Arg& arg0);
168                      
169                          /** Constructor */
170                          MessageLoaderParms(
171                      	const String& id, 
172                      	const String& msg, 
173                      	const Formatter::Arg& arg0,
174                      	const Formatter::Arg& arg1);
175                      
176                          /** Constructor */
177                          MessageLoaderParms(
178                      	const String& id, 
179                      	const String& msg, 
180                      	const Formatter::Arg& arg0,
181                      	const Formatter::Arg& arg1,
182 karl            1.11 	const Formatter::Arg& arg2);
183                      
184                          /** Constructor */
185                          MessageLoaderParms(
186                      	const String& id, 
187                      	const String& msg, 
188                      	const Formatter::Arg& arg0,
189                      	const Formatter::Arg& arg1,
190                      	const Formatter::Arg& arg2,
191                      	const Formatter::Arg& arg3);
192                      
193                          MessageLoaderParms(
194                      	const char* id, 
195                      	const char* msg);
196                      
197                          MessageLoaderParms(
198                      	const char* id, 
199                      	const char* msg, 
200                      	const String& arg0);
201                      
202                          MessageLoaderParms(
203 karl            1.11 	const char* id, 
204                      	const char* msg, 
205                      	const String& arg0,
206                      	const String& arg1);
207                          
208                          /** Converts to string. */
209                          String toString();
210                      
211                          ~MessageLoaderParms();
212                      
213                      private:
214                      
215                          void _init();
216 alagaraja       1.8  }; // end MessageLoaderParms
217                      
218                      
219                      /*
220                       * MessageLoader is a static class resposible for looking up messages in message resources. 
221                       * For specific behaviour details of this class see the Globalization HOWTO.
222                       */
223                      
224                      class PEGASUS_COMMON_LINKAGE MessageLoader{
225                      	
226                      public:
227                      	
228                      	/*
229                      	 * Retrieves a message from a message resource
230                      	 * @param parms MessageLoaderParms - controls the behaviour of how a message is retrieved
231                      	 * @return String - the formatted message
232                      	 */
233                      	static String getMessage(MessageLoaderParms &parms);
234                      	
235                      	static void setPegasusMsgHome(String home);
236 joyce.j         1.15 
237                          static void setPegasusMsgHomeRelative(const String& argv0);
238 alagaraja       1.8  	
239                      	static Boolean _useProcessLocale;
240                      	
241                      	static Boolean _useDefaultMsg;
242                       	
243                      	static AcceptLanguages _acceptlanguages;
244                      	
245                      private:
246                      
247                      	static String formatDefaultMessage(MessageLoaderParms &parms);
248                      	
249                      	static String getQualifiedMsgPath(String path);
250                      
251 joyce.j         1.15 	static void initPegasusMsgHome(const String & startDir);
252 alagaraja       1.8  	
253                      	static void checkDefaultMsgLoading();
254                      	
255                      	static String pegasus_MSG_HOME;
256                      	
257                      	#ifdef PEGASUS_HAS_ICU
258                      		static String loadICUMessage(MessageLoaderParms &parms);
259                      		
260                      		static String extractICUMessage(UResourceBundle * resbundl, MessageLoaderParms &parms);
261                      		
262                      		static String formatICUMessage(UResourceBundle * resbundl, const UChar *msg, int msg_len, MessageLoaderParms &parms);
263                      		
264                      		static String uChar2String(UChar * uchar_str);
265                      		
266                      		static String uChar2String(UChar * uchar_str, int len);
267                      		
268 chuck           1.14         static void xferFormattable(Formatter::Arg& arg, Formattable &formattable);
269 alagaraja       1.8  	#endif
270                      	
271                      }; // end MessageLoader
272                      
273                      PEGASUS_NAMESPACE_END
274 chuck           1.6  
275                      #endif  // PEGASUS_USE_EXPERIMENTAL_INTERFACES
276 alagaraja       1.8  
277                      #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2