00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00035 #ifndef OW_SESSIONLANGUAGE_HPP_INCLUDE_GUARD
00036 #define OW_SESSIONLANGUAGE_HPP_INCLUDE_GUARD
00037
00038 #include "OW_config.h"
00039 #include "OW_String.hpp"
00040 #include "OW_Array.hpp"
00041 #include "OW_OperationContext.hpp"
00042 #include "OW_CommonFwd.hpp"
00043
00044 namespace OW_NAMESPACE
00045 {
00046
00048 class OW_COMMON_API LanguageTag
00049 {
00050 public:
00051 LanguageTag();
00052 LanguageTag(const char* languageTag);
00053 LanguageTag(const LanguageTag& arg);
00054
00055 bool invalid() const { return (m_subtag1[0] == 0); }
00056 Int32 getWeight() const { return m_weight; }
00057
00058 LanguageTag& operator= (const LanguageTag& arg);
00059 LanguageTag& operator= (const char* arg);
00060
00061 int compareWeight(const LanguageTag& arg) const;
00062 bool operator < (const LanguageTag& arg) const { return (compareWeight(arg) < 0); }
00063 bool operator > (const LanguageTag& arg) const { return (compareWeight(arg) > 0); }
00064 bool operator <= (const LanguageTag& arg) const { return (compareWeight(arg) <= 0); }
00065 bool operator >= (const LanguageTag& arg) const { return (compareWeight(arg) >= 0); }
00066 bool operator == (const LanguageTag& arg) const { return (compareWeight(arg) == 0); }
00067 bool operator != (const LanguageTag& arg) const { return (compareWeight(arg) != 0); }
00068 const char* assign(const char* arg);
00069 LanguageTag& copy(const LanguageTag& arg);
00070 String toString() const;
00071 String getSubtag1() const { return String(m_subtag1); }
00072 String getSubtag2() const { return String(m_subtag2); }
00073 String getSubtag3() const { return String(m_subtag3); }
00074
00075 private:
00076 const char* setWeight(const char* arg);
00077 const char* setSubTags(const char* languageTag);
00078 const char* parseSubTag(const char* arg, char* tagField);
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 char m_subtag1[9];
00090
00091
00092
00093
00094
00095
00096
00097
00098 char m_subtag2[9];
00099
00100
00101
00102
00103 char m_subtag3[9];
00104
00105 Int32 m_weight;
00106
00107 bool m_explicitQualityValue;
00108
00109 friend class SessionLanguage;
00110 };
00111
00112 typedef Array<LanguageTag> LanguageTagArray;
00113
00117 class OW_COMMON_API SessionLanguage : public OperationContext::Data
00118 {
00119 public:
00120 SessionLanguage();
00121 SessionLanguage(const char* acceptLangHdrValue);
00122 SessionLanguage(const SessionLanguage& arg);
00123 SessionLanguage& operator=(const SessionLanguage& arg);
00124
00125 int langCount() const { return m_langTags.size(); }
00126 String getAcceptLanguageString() const { return m_acceptLanguageString; }
00127 SessionLanguage& assign(const char* acceptLangHdrValue);
00128
00135 String getBestLanguage(const StringArray& languages, const String& defaultLanguage = String()) const;
00136 void addContentLanguage(const String& contentLanguage);
00137 String getContentLanguage() const;
00138
00139 private:
00140 void buildLangTags(const char* acceptLangHdrValue);
00141 static bool langsMatch(const LanguageTag& t1, const LanguageTag& t2,
00142 int level);
00143
00144 #ifdef OW_WIN32
00145 #pragma warning (push)
00146 #pragma warning (disable: 4251)
00147 #endif
00148
00149 LanguageTagArray m_langTags;
00150
00151 #ifdef OW_WIN32
00152 #pragma warning (pop)
00153 #endif
00154
00155 String m_contentLanguage;
00156 String m_acceptLanguageString;
00157 };
00158 OW_EXPORT_TEMPLATE(OW_COMMON_API, IntrusiveReference, SessionLanguage);
00159
00160 }
00161
00162 #endif
00163