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

  1 martin 1.27 //%LICENSE////////////////////////////////////////////////////////////////
  2             // 
  3             // Licensed to The Open Group (TOG) under one or more contributor license
  4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5             // this work for additional information regarding copyright ownership.
  6             // Each contributor licenses this file to you under the OpenPegasus Open
  7             // Source License; you may not use this file except in compliance with the
  8             // License.
  9             // 
 10             // Permission is hereby granted, free of charge, to any person obtaining a
 11             // copy of this software and associated documentation files (the "Software"),
 12             // to deal in the Software without restriction, including without limitation
 13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14             // and/or sell copies of the Software, and to permit persons to whom the
 15             // Software is furnished to do so, subject to the following conditions:
 16             // 
 17             // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19             // 
 20             // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21             // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 22 martin 1.27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 karl   1.7  // 
 28 martin 1.27 //////////////////////////////////////////////////////////////////////////
 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 kumpf     1.16 #include <Pegasus/Common/AcceptLanguageList.h>
 42                #include <Pegasus/Common/ContentLanguageList.h>
 43 alagaraja 1.8  
 44                PEGASUS_NAMESPACE_BEGIN
 45                
 46 kumpf     1.20 /**
 47 kumpf     1.23     MessageLoaderParms class is basically a stuct class containing public
 48                    variables that control the way MessageLoader behaves. MessageLoader uses
 49                    the fields in this class to decide where and how to load messages from
 50                    the message resources.
 51 alagaraja 1.8   */
 52 kumpf     1.23 class PEGASUS_COMMON_LINKAGE MessageLoaderParms
 53                {
 54                public:
 55 alagaraja 1.8  
 56 kumpf     1.23     /**
 57 kumpf     1.26         Unique message identifier for a particular
 58 kumpf     1.23         message in a message resource
 59                     */
 60 kumpf     1.26     const char* msg_id;
 61 kumpf     1.23 
 62                    /**
 63                        String default_msg: the default message to use if a message
 64                        cannot be loaded from a message resource
 65                     */
 66                    String default_msg;
 67                
 68                    /**
 69                        String msg_src_path: this path tells MessageLoader where to
 70                        find message resources.
 71                        It can be empty, fully qualified or relative to $PEGASUS_HOME
 72                     */
 73                    String msg_src_path;
 74                
 75                    /**
 76                        AcceptLanguageList acceptlanguages: This contains the languages
 77                        that are acceptable by the caller of MessageLoader::getMessage()
 78                        or openMessageFile(). That is, MessageLoader will do its best to
 79                        return a message in a language that was specified in this container.
 80                        This container is naturally ordered using the quality values
 81                        attached to the languages and MessageLoader iterates through this
 82 kumpf     1.23         container in its natural ordering.  This container is used by
 83                        MessageLoader to load messages if it is not empty.
 84                     */
 85                    AcceptLanguageList acceptlanguages;
 86                
 87                    /**
 88                        ContentLanguageList contentlanguages: This is set by
 89                        MessageLoader::getMessage() and after a message has been loaded
 90                        from either a message resource or the default message, or by
 91                        MessageLoader::openMessageFile() after it has identified and
 92                        opened a message resource. After the call to
 93                        MessageLoader::getMessage() or MessageLoader::openMessageFile(),
 94                        the caller can check the MessageLoaderParms.contentlanguages
 95                        object to see what MessageLoader set it to. In all cases where a
 96                        message is returned from MessageLoader::getMessage() or will be
 97                        returned from MessageLoader::getMessage2(), this field will be
 98                        set to match the language that the message was (or will be)
 99                        found in.
100                     */
101                    ContentLanguageList contentlanguages;
102                
103 kumpf     1.23     /**
104                        Boolean useProcessLocale: Default is false, if true, MessageLoader
105                        uses the system default language to loads messages from.
106                     */
107                    Boolean useProcessLocale;
108                
109                    /**
110                        Boolean useThreadLocale: Default is true, this tells
111                        MessageLoader to use the AcceptLanguageList container
112                        from the current Pegasus thread.
113                     */
114                    Boolean useThreadLocale;
115                
116                    /**
117                        const Formatter::Arg&0-9: These are assigned the various
118                        substitutions necessary to properly format the message being
119                        extracted.  MessageLoader substitutes these in the correct
120                        places in the message being returned from
121                        MessageLoader::getMessage()
122                     */
123                    Formatter::Arg arg0;
124 kumpf     1.23     Formatter::Arg arg1;
125                    Formatter::Arg arg2;
126                    Formatter::Arg arg3;
127                    Formatter::Arg arg4;
128                    Formatter::Arg arg5;
129                    Formatter::Arg arg6;
130                    Formatter::Arg arg7;
131                    Formatter::Arg arg8;
132                    Formatter::Arg arg9;
133 dave.sudlik 1.21 
134 karl        1.11     /** Constructor */
135                      MessageLoaderParms();
136                  
137                      /** Constructor */
138                      MessageLoaderParms(
139 kumpf       1.26         const char* id,
140                          const char* msg,
141 kumpf       1.23         const Formatter::Arg& arg0,
142                          const Formatter::Arg& arg1,
143                          const Formatter::Arg& arg2,
144                          const Formatter::Arg& arg3,
145                          const Formatter::Arg& arg4,
146                          const Formatter::Arg& arg5 = Formatter::DEFAULT_ARG,
147                          const Formatter::Arg& arg6 = Formatter::DEFAULT_ARG,
148                          const Formatter::Arg& arg7 = Formatter::DEFAULT_ARG,
149                          const Formatter::Arg& arg8 = Formatter::DEFAULT_ARG,
150                          const Formatter::Arg& arg9 = Formatter::DEFAULT_ARG);
151 karl        1.11 
152                      /** Constructor */
153                      MessageLoaderParms(
154 kumpf       1.26         const char* id,
155                          const char* msg);
156                  
157                      /**
158                          Constructor with a String default message argument and no
159                          substitutions.  This form is handy for cases like command usage
160                          strings where the message is built up dynamically from component parts.
161                      */
162                      MessageLoaderParms(
163                          const char* id,
164 kumpf       1.23         const String& msg);
165                  
166 karl        1.11     /** Constructor */
167                      MessageLoaderParms(
168 kumpf       1.26         const char* id,
169                          const char* msg,
170 kumpf       1.23         const Formatter::Arg& arg0);
171 karl        1.11 
172                      /** Constructor */
173                      MessageLoaderParms(
174 kumpf       1.26         const char* id,
175                          const char* msg,
176 kumpf       1.23         const Formatter::Arg& arg0,
177                          const Formatter::Arg& arg1);
178 karl        1.11 
179                      /** Constructor */
180                      MessageLoaderParms(
181 kumpf       1.26         const char* id,
182                          const char* msg,
183 kumpf       1.23         const Formatter::Arg& arg0,
184                          const Formatter::Arg& arg1,
185                          const Formatter::Arg& arg2);
186 karl        1.11 
187                      /** Constructor */
188                      MessageLoaderParms(
189 kumpf       1.26         const char* id,
190                          const char* msg,
191 kumpf       1.23         const Formatter::Arg& arg0,
192                          const Formatter::Arg& arg1,
193                          const Formatter::Arg& arg2,
194                          const Formatter::Arg& arg3);
195 karl        1.11 
196                      /** Converts to string. */
197                      String toString();
198                  
199                      ~MessageLoaderParms();
200                  
201                  private:
202 kumpf       1.25 
203 kumpf       1.23     void* _resbundl;
204 karl        1.11 
205                      void _init();
206 alagaraja   1.8  
207 kumpf       1.23     friend class MessageLoader;
208 kumpf       1.25     friend class MessageLoaderICU;
209 kumpf       1.23 };
210 alagaraja   1.8  
211 kumpf       1.23 
212                  /**
213                      MessageLoader is a static class resposible for looking up messages in
214                      message resources.
215                      For specific behaviour details of this class see the Globalization HOWTO.
216 alagaraja   1.8   */
217 kumpf       1.23 class PEGASUS_COMMON_LINKAGE MessageLoader
218                  {
219                  public:
220 alagaraja   1.8  
221 kumpf       1.23     /**
222                          Retrieves a message from a message resource
223                          @param parms MessageLoaderParms - controls the behaviour of how a
224                          message is retrieved
225                          @return String - the formatted message
226                       */
227                      static String getMessage(MessageLoaderParms& parms);
228                  
229                      /**
230 kumpf       1.25         Opens a message resource bundle.  If unsuccessful, a subsequent call
231                          to getMessage2() with the specified MessageLoaderParms object will
232 kumpf       1.23         result in the default message being formatted.
233                          ATTN: Do we want *real* error codes for this?
234                          @param parms MessageLoaderParms - controls the behaviour of how a
235                              message is retrieved, this parameter should be used *ONLY* on
236                              subsequent calls to getMessage2() and closeMessageFile().
237                       */
238                      static void openMessageFile(MessageLoaderParms& parms);
239                  
240                      /**
241                          Closes a message resource bundle.
242                          @param parms MessageLoaderParms - identifies a previously opened
243                              resource bundle returned from openMessageFile().
244                       */
245                      static void closeMessageFile(MessageLoaderParms& parms);
246                  
247                      /**
248                          Retrieves a message from a message resource previously opened by
249                          openMessageFile()
250                          @param parms MessageLoaderParms - controls the behaviour of how a
251                              message is retrieved, and is the same MessageLoaderParms
252                              parameter that was passed to openMessageFile().
253 kumpf       1.23         @return String - the formatted message
254                       */
255                      static String getMessage2(MessageLoaderParms& parms);
256 dave.sudlik 1.21 
257 kumpf       1.23     static void setPegasusMsgHome(String home);
258 joyce.j     1.15 
259                      static void setPegasusMsgHomeRelative(const String& argv0);
260 kumpf       1.23 
261 kumpf       1.25     static String getQualifiedMsgPath(const String& path);
262                  
263 kumpf       1.23     static Boolean _useProcessLocale;
264                  
265                      static Boolean _useDefaultMsg;
266                  
267                      static AcceptLanguageList _acceptlanguages;
268                  
269 alagaraja   1.8  private:
270                  
271 kumpf       1.23     static String formatDefaultMessage(MessageLoaderParms& parms);
272                  
273                      static void initPegasusMsgHome(const String& startDir);
274                  
275                      static void checkDefaultMsgLoading();
276                  
277                      static String pegasus_MSG_HOME;
278                  };
279 alagaraja   1.8  
280                  PEGASUS_NAMESPACE_END
281 chuck       1.6  
282 alagaraja   1.8  #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2