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

  1 karl  1.18 //%2006////////////////////////////////////////////////////////////////////////
  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.18 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 karl  1.7  //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15            // of this software and associated documentation files (the "Software"), to
 16            // deal in the Software without restriction, including without limitation the
 17            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18            // sell copies of the Software, and to permit persons to whom the Software is
 19            // furnished to do so, subject to the following conditions:
 20            // 
 21            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29            //
 30            //==============================================================================
 31 alagaraja 1.8  //
 32                //%/////////////////////////////////////////////////////////////////////////////
 33                
 34                #ifndef Pegasus_MessageLoader_h
 35                #define Pegasus_MessageLoader_h
 36                
 37                #include <cstdlib>
 38                #include <cctype>
 39                #include <Pegasus/Common/Linkage.h>
 40                #include <Pegasus/Common/Config.h>
 41                #include <Pegasus/Common/String.h>
 42                #include <Pegasus/Common/Formatter.h>
 43 kumpf     1.16 #include <Pegasus/Common/AcceptLanguageList.h>
 44                #include <Pegasus/Common/ContentLanguageList.h>
 45 alagaraja 1.8  
 46                //ICU specific 
 47                #ifdef PEGASUS_HAS_ICU
 48                #include <unicode/uloc.h> 
 49                #include <unicode/ures.h>
 50                #include <unicode/umsg.h>
 51                #include <unicode/ucnv.h>
 52                #include <unicode/fmtable.h>
 53                #include <unicode/msgfmt.h>
 54                #endif
 55 chuck     1.6  
 56 alagaraja 1.8  PEGASUS_NAMESPACE_BEGIN
 57                
 58 kumpf     1.20 /**
 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 kumpf     1.16 	 * AcceptLanguageList acceptlanguages: This contains the languages that are acceptable by the caller
 86 alagaraja 1.8  	 * 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 kumpf     1.16 	AcceptLanguageList acceptlanguages;
 92 alagaraja 1.8  	
 93                	/*
 94 kumpf     1.16 	 * ContentLanguageList contentlanguages: This is set by MessageLoader::getMessage() after a message has
 95 alagaraja 1.8  	 * 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 kumpf     1.16 	ContentLanguageList 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 kumpf     1.16 	 * Boolean useThreadLocale: Default is true, this tells MessageLoader to use the AcceptLanguageList container
110 alagaraja 1.8  	 * 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                	#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 kumpf     1.16 	static AcceptLanguageList _acceptlanguages;
244 alagaraja 1.8  	
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 alagaraja 1.8  #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2