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 /**
133 Returns the default accept languages based on environment settings.
134 ATTN: What is the behavior? This is only implemented if MESSAGES and
135 ICU are used.
136 */
|
137 kumpf 1.18 static AcceptLanguageList getDefaultAcceptLanguages();
|
138 alagaraja 1.6
139 private:
140
|
141 kumpf 1.17 /**
142 Parses the value portion of an HTTP Accept-Language or Content-Language
143 header into individual language elements. Comments and whitespace are
144 removed.
145 @param headerElements An array of Strings into which the language
146 elements are stored.
147 @param languageHeaderValue A String containing the value portion of
148 an HTTP Accept-Language or Content-Language header.
149 @exception Exception if a syntax error is encountered.
150 */
151 static void _parseLanguageHeader(
152 const String& languageHeaderValue,
153 Array<String>& languageElements);
154
155 /**
156 Parses an AcceptLanguage or ContentLanguage value from a header.
157 If a valid AcceptLanguage value is determined to contain a quality
158 value, then this quality is validated and returned. Otherwise -1 is
159 returned. It is up to the caller to know in what context this call
160 is being made, that is: it is the callers responsibility to know
161 whether an AcceptLanguage or a ContentLanguage value is being parsed.
162 kumpf 1.17 @param acceptLanguageHeaderElement String to be parsed into a
163 language tag and quality value. The String must not contain comments
164 or whitespace.
165 @param languageTag String into which the parsed language tag is
166 stored.
167 @param quality Real32 into which the parsed quality value is stored.
168 @exception Exception if a syntax error is encountered.
169 */
170 static void _parseAcceptLanguageElement(
171 const String& acceptLanguageElement,
172 String& languageTag,
173 Real32& quality);
174
175 /**
176 Fills the first position in the array with the most general part of
177 the language String, each subsequent postion is the array gets more
178 and more detailed. For example: en-us-fooblah would be returned as
179 ["en"]["us"]["fooblah"]
180 @param subtags Array<String>& array filled in with the root and subtags
181 @param languageTag String the language to parse
182 @return String the root of the language tag
183 kumpf 1.17 @exception Exception if a syntax error is encountered.
184 */
185 static void _parseLanguageSubtags(
186 Array<String>& subtags,
187 const String& languageTagString);
188
189 /**
190 Checks if a String represents a valid language tag primary subtag.
191 A valid primary subtag contains 1 to 8 alphabetic characters.
192 @param subtag The subtag String to validate.
193 @return True if the String represents a valid language tag primary
194 subtag; false otherwise.
195 */
196 static Boolean _isValidPrimarySubtagSyntax(const String& subtag);
197
198 /**
199 Checks if a String represents a valid language tag subtag.
200 A valid primary subtag contains 1 to 8 alphanumeric characters.
201 @param subtag The subtag String to validate.
202 @return True if the String represents a valid language tag subtag;
203 false otherwise.
204 kumpf 1.17 */
205 static Boolean _isValidSubtagSyntax(const String& subtag);
206 };
|
207 alagaraja 1.6
208 PEGASUS_NAMESPACE_END
|
209 chuck 1.4
|
210 alagaraja 1.6 #endif
|