OW_SessionLanguage.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Novell, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Novell, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
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    // Rules for subtag 1:
00082    // - Required
00083    // - May only contain chars a-z,A-Z
00084    // - Maximum length of 8 chars.
00085    // - 2 chars = Language code from ISO 639/639-1
00086    // - 3 chars = Language code from ISO 639-2
00087    // - 'i' = Language tag explicity IANA-registered
00088    // - 'x' = Language tag is private, nonstandard extension
00089    char m_subtag1[9];
00090 
00091    // Rules for subtag 2:
00092    // - Optional
00093    // - May only contain chars 0-9,a-z,A-Z
00094    // - Maximum length of 8 chars
00095    //  - 2 chars = Country/Region code from ISO 3166
00096    // - 3-8 chars = May be registered with IANA
00097    // - 1 char = Invalid subtag
00098    char m_subtag2[9];
00099 
00100    // Rules for subtag3:
00101    // - Optional
00102    // - Maximum length of 8 chars
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 }  // End of namespace OW_NAMESPACE
00161 
00162 #endif
00163 

Generated on Thu Feb 9 08:48:11 2006 for openwbem by  doxygen 1.4.6