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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2