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

  1 karl  1.19 //%2006////////////////////////////////////////////////////////////////////////
  2 karl  1.5  //
  3 karl  1.7  // 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.5  // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.7  // 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.8  // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.19 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 karl  1.5  //
 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.6  //
 32                // Author: Humberto Rivero (hurivero@us.ibm.com)
 33                //
 34 aruran.ms 1.13 // Modified By: Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3697, 3698, 3699, 3700
 35 aruran.ms 1.16 //              Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3701, 3702, 3703
 36 kumpf     1.17 //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 37 alagaraja 1.6  //
 38                //%/////////////////////////////////////////////////////////////////////////////
 39                
 40                #ifndef Pegasus_LanguageParser_h
 41                #define Pegasus_LanguageParser_h
 42                
 43                #include <cstdlib>
 44                #include <cctype>
 45                #include <Pegasus/Common/Linkage.h>
 46                #include <Pegasus/Common/Config.h>
 47                #include <Pegasus/Common/String.h>
 48                #include <Pegasus/Common/Array.h>
 49 kumpf     1.18 #include <Pegasus/Common/AcceptLanguageList.h>
 50                #include <Pegasus/Common/ContentLanguageList.h>
 51 alagaraja 1.6  
 52                PEGASUS_NAMESPACE_BEGIN
 53                
 54 kumpf     1.17 /**
 55                    This class parses and validates Accept-Language and Content-Language values
 56                    from the respective HTTP headers, and provides utility functions to parse
 57                    and manipulate language information
 58 alagaraja 1.6   */
 59 kumpf     1.17 class PEGASUS_COMMON_LINKAGE LanguageParser
 60                {
 61 alagaraja 1.6  public:
 62                
 63 kumpf     1.17     /**
 64 kumpf     1.18         Builds an AcceptLanguageList object from an HTTP Accept-Language
 65 kumpf     1.17         header value.
 66                        @param acceptLanguageHeader A String containing an HTTP
 67 kumpf     1.18         Accept-Language header value from which to build the AcceptLanguageList
 68 kumpf     1.17         object.
 69                        @exception InvalidAcceptLanguageHeader if a syntax error is
 70                        encountered.
 71                     */
 72 kumpf     1.18     static AcceptLanguageList parseAcceptLanguageHeader(
 73 kumpf     1.17         const String& acceptLanguageHeader);
 74                
 75                    /**
 76 kumpf     1.18         Builds a ContentLanguageList object from an HTTP Content-Language
 77 kumpf     1.17         header value.
 78                        @param contentLanguageHeader A String containing an HTTP
 79 kumpf     1.18         Content-Language header value from which to build the
 80                        ContentLanguageList object.
 81 kumpf     1.17         @exception InvalidContentLanguageHeader if a syntax error is
 82                        encountered.
 83                     */
 84 kumpf     1.18     static ContentLanguageList parseContentLanguageHeader(
 85 kumpf     1.17         const String& contentLanguageHeader);
 86                
 87                    /**
 88                        Validates the syntax of a language tag according to RFC 3066.
 89                        Parses the language tag into language, country, and variant, if
 90                        the language tag is formed using ISO codes (ISO 639 and ISO 3166).
 91                        @param languageTagString The language tag string to parse and
 92                        validate.
 93                        @param language The returned language value parsed from the language
 94                        tag, if applicable.
 95                        @param country The returned country value parsed from the language
 96                        tag, if applicable.
 97                        @param variant The returned language variant value parsed from the
 98                        language tag, if applicable.
 99                        @exception Exception if the language tag is syntactically invalid.
100                     */
101                    static void parseLanguageTag(
102                        const String& languageTagString,
103                        String& language,
104                        String& country,
105                        String& variant);
106 kumpf     1.17 
107                    /**
108                        Validates the syntax of an Accept-Language quality value.
109                        @param quality A Real32 quality value to validate.
110                        @exception Exception if the quality value is invalid.
111                     */
112                    static void validateQualityValue(Real32 quality);
113                
114                    /**
115 kumpf     1.18         Builds an HTTP Accept-Language header value from an AcceptLanguageList
116 kumpf     1.17         object.
117 kumpf     1.18         @param acceptLanguages The AcceptLanguageList object to be encoded in
118                        an HTTP Accept-Language header.
119 kumpf     1.17      */
120                    static String buildAcceptLanguageHeader(
121 kumpf     1.18         const AcceptLanguageList& acceptLanguages);
122 kumpf     1.17 
123                    /**
124 kumpf     1.18         Builds an HTTP Content-Language header value from a ContentLanguageList
125 kumpf     1.17         object.
126 kumpf     1.18         @param contentLanguages The ContentLanguageList object to be encoded
127                        in an HTTP Content-Language header.
128 kumpf     1.17      */
129                    static String buildContentLanguageHeader(
130 kumpf     1.18         const ContentLanguageList& contentLanguages);
131 kumpf     1.17 
132 kumpf     1.20 #ifdef PEGASUS_HAS_ICU
133                    /**
134                        Converts a locale ID to language tag syntax by replacing the '_'
135                        separators with '-' separators.
136                        @param localeId The locale ID string to convert to language tag
137                        syntax.  The conversion is performed on the localeId object
138                        directly.
139                        @return The converted String with language tag syntax.
140                     */
141                    static String& convertLocaleIdToLanguageTag(String& localeId);
142                #endif
143                
144 kumpf     1.17     /**
145                        Returns the default accept languages based on environment settings.
146                        ATTN: What is the behavior?  This is only implemented if MESSAGES and
147                        ICU are used.
148                     */
149 kumpf     1.18     static AcceptLanguageList getDefaultAcceptLanguages();
150 alagaraja 1.6  
151                private:
152                
153 kumpf     1.17     /**
154                        Parses the value portion of an HTTP Accept-Language or Content-Language
155                        header into individual language elements.  Comments and whitespace are
156                        removed.
157                        @param headerElements An array of Strings into which the language
158                        elements are stored.
159                        @param languageHeaderValue A String containing the value portion of
160                        an HTTP Accept-Language or Content-Language header.
161                        @exception Exception if a syntax error is encountered.
162                     */
163                    static void _parseLanguageHeader(
164                        const String& languageHeaderValue,
165                        Array<String>& languageElements);
166                
167                    /**
168                        Parses an AcceptLanguage or ContentLanguage value from a header.
169                        If a valid AcceptLanguage value is determined to contain a quality
170                        value, then this quality is validated and returned. Otherwise -1 is
171                        returned.  It is up to the caller to know in what context this call
172                        is being made, that is: it is the callers responsibility to know
173                        whether an AcceptLanguage or a ContentLanguage value is being parsed.
174 kumpf     1.17         @param acceptLanguageHeaderElement String to be parsed into a
175                        language tag and quality value.  The String must not contain comments
176                        or whitespace.
177                        @param languageTag String into which the parsed language tag is
178                        stored.
179                        @param quality Real32 into which the parsed quality value is stored.
180                        @exception Exception if a syntax error is encountered.
181                     */
182                    static void _parseAcceptLanguageElement(
183                        const String& acceptLanguageElement,
184                        String& languageTag,
185                        Real32& quality);
186                
187                    /**
188                        Fills the first position in the array with the most general part of
189                        the language String, each subsequent postion is the array gets more
190                        and more detailed.  For example: en-us-fooblah would be returned as
191                        ["en"]["us"]["fooblah"]
192                        @param subtags Array<String>& array filled in with the root and subtags
193                        @param languageTag String the language to parse
194                        @return String the root of the language tag
195 kumpf     1.17         @exception Exception if a syntax error is encountered.
196                     */
197                    static void _parseLanguageSubtags(
198                        Array<String>& subtags,
199                        const String& languageTagString);
200                
201                    /**
202                        Checks if a String represents a valid language tag primary subtag.
203                        A valid primary subtag contains 1 to 8 alphabetic characters.
204                        @param subtag The subtag String to validate.
205                        @return True if the String represents a valid language tag primary
206                        subtag; false otherwise.
207                     */
208                    static Boolean _isValidPrimarySubtagSyntax(const String& subtag);
209                
210                    /**
211                        Checks if a String represents a valid language tag subtag.
212                        A valid primary subtag contains 1 to 8 alphanumeric characters.
213                        @param subtag The subtag String to validate.
214                        @return True if the String represents a valid language tag subtag;
215                        false otherwise.
216 kumpf     1.17      */
217                    static Boolean _isValidSubtagSyntax(const String& subtag);
218                };
219 alagaraja 1.6  
220                PEGASUS_NAMESPACE_END
221 chuck     1.4  
222 alagaraja 1.6  #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2