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

Diff for /pegasus/src/Pegasus/Common/LanguageParser.cpp between version 1.23 and 1.34

version 1.23, 2006/01/10 19:41:15 version 1.34, 2008/08/14 17:30:38
Line 1 
Line 1 
 //%2005////////////////////////////////////////////////////////////////////////  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
Line 8 
Line 8 
 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 // EMC Corporation; VERITAS Software Corporation; The Open Group. // EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; Symantec Corporation; The Open Group.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 27 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Humberto Rivero (hurivero@us.ibm.com)  
 //  
 // Modified By: Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3697, 3698, 3699, 3700  
 //              Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3701, 3702, 3703, 3704  
 //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include <Pegasus/Common/LanguageParser.h> #include <Pegasus/Common/LanguageParser.h>
 #include <Pegasus/Common/InternalException.h> #include <Pegasus/Common/InternalException.h>
 #include <Pegasus/Common/Tracer.h> #include <Pegasus/Common/Tracer.h>
 #include <Pegasus/Common/MessageLoader.h> //l10n  #include <Pegasus/Common/MessageLoader.h>
 #include <cstring> #include <cstring>
  
 #ifdef PEGASUS_HAS_ICU #ifdef PEGASUS_HAS_ICU
 # include <unicode/locid.h> # include <unicode/locid.h>
 #endif #endif
 #if defined(PEGASUS_OS_OS400)  
 # include "OS400ConvertChar.h"  
 #endif  
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
Line 73 
Line 66 
             Real32 qualityValue;             Real32 qualityValue;
             LanguageParser::_parseAcceptLanguageElement(             LanguageParser::_parseAcceptLanguageElement(
                 languageElements[i], languageTagString, qualityValue);                 languageElements[i], languageTagString, qualityValue);
             acceptLanguages.insert(LanguageTag(languageTagString), qualityValue);              acceptLanguages.insert(
                   LanguageTag(languageTagString), qualityValue);
         }         }
     }     }
     catch (Exception& e)     catch (Exception& e)
Line 114 
Line 108 
 } }
  
 void LanguageParser::parseLanguageTag( void LanguageParser::parseLanguageTag(
     const String& languageTagString_,      const String& languageTagString,
     String& language,     String& language,
     String& country,     String& country,
     String& variant)     String& variant)
 { {
     PEG_METHOD_ENTER(TRC_L10N, "LanguageParser::parseLanguageTag");     PEG_METHOD_ENTER(TRC_L10N, "LanguageParser::parseLanguageTag");
  
     // Convert locale ID format to language tag format  
     String languageTagString = languageTagString_;  
     Uint32 index = 0;  
     while ((index = languageTagString.find(index, LOCALE_ID_SEPARATOR_CHAR)) !=  
         PEG_NOT_FOUND)  
     {  
         languageTagString[index] = LANGUAGE_TAG_SEPARATOR_CHAR;  
     }  
   
     language.clear();     language.clear();
     country.clear();     country.clear();
     variant.clear();     variant.clear();
Line 164 
Line 149 
     {     {
         // Except for "i" and "x", primary tags must be 2 or 3 characters,         // Except for "i" and "x", primary tags must be 2 or 3 characters,
         // according to RFC 3066.         // according to RFC 3066.
         MessageLoaderParms parms(  
             "Common.LanguageParser.INVALID_LANGUAGE_TAG",          // Do not localize this message; it could cause recursion.
             "Invalid language tag \"$0\".", languageTagString);  
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
         throw Exception(MessageLoader::getMessage(parms));          throw Exception(Formatter::format(
               "Invalid language tag \"$0\".",
               languageTagString));
     }     }
  
     if (subtags.size() == 1)     if (subtags.size() == 1)
Line 185 
Line 171 
     {     {
         // The second subtag may not be a single character according to         // The second subtag may not be a single character according to
         // RFC 3066.         // RFC 3066.
         MessageLoaderParms parms(  
             "Common.LanguageParser.INVALID_LANGUAGE_TAG",          // Do not localize this message; it could cause recursion.
             "Invalid language tag \"$0\".", languageTagString);  
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
         throw Exception(MessageLoader::getMessage(parms));          throw Exception(Formatter::format(
               "Invalid language tag \"$0\".",
               languageTagString));
     }     }
  
     if (isStandardFormat)     if (isStandardFormat)
Line 277 
Line 264 
     return clString;     return clString;
 } }
  
   #ifdef PEGASUS_HAS_ICU
   String& LanguageParser::convertLocaleIdToLanguageTag(String& localeId)
   {
       Uint32 index = 0;
       while ((index = localeId.find(index, LOCALE_ID_SEPARATOR_CHAR)) !=
                   PEG_NOT_FOUND)
       {
           localeId[index] = LANGUAGE_TAG_SEPARATOR_CHAR;
       }
       return localeId;
   }
   #endif
   
 AcceptLanguageList LanguageParser::getDefaultAcceptLanguages() AcceptLanguageList LanguageParser::getDefaultAcceptLanguages()
 { {
 #if defined(PEGASUS_HAS_MESSAGES) && defined(PEGASUS_HAS_ICU) #if defined(PEGASUS_HAS_MESSAGES) && defined(PEGASUS_HAS_ICU)
     Locale default_loc = Locale::getDefault();     Locale default_loc = Locale::getDefault();
  
 # ifdef PEGASUS_OS_OS400      String localeId = default_loc.getName();
     char* tmp = (char*)default_loc.getName();  
     char tmp_[100];  
     EtoA(strcpy(tmp_,tmp));  
     try  
     {  
         return LanguageParser::parseAcceptLanguageHeader(tmp_);  
     }  
 # else  
     try     try
     {     {
         return LanguageParser::parseAcceptLanguageHeader(default_loc.getName());          return LanguageParser::parseAcceptLanguageHeader(
               convertLocaleIdToLanguageTag(localeId));
     }     }
 # endif  
     catch (const InvalidAcceptLanguageHeader& e)     catch (const InvalidAcceptLanguageHeader& e)
     {     {
         Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,         Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
            "src.Server.cimserver.FAILED_TO_GET_PROCESS_LOCALE",              MessageLoaderParms(
            "Could not convert the system locale to a valid accept-language "                  "src.Server.cimserver.FAILED_TO_SET_PROCESS_LOCALE",
                "format");                  "Cannot convert the system process locale into a valid "
                       "Accept-Language format."));
         Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,         Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
             e.getMessage());             e.getMessage());
         AcceptLanguageList al;         AcceptLanguageList al;
Line 459 
Line 453 
                 "Common.LanguageParser.MALFORMED_LANGUAGE_TAG",                 "Common.LanguageParser.MALFORMED_LANGUAGE_TAG",
                 "Malformed language tag \"$0\".", languageTagString);                 "Malformed language tag \"$0\".", languageTagString);
             PEG_METHOD_EXIT();             PEG_METHOD_EXIT();
             throw Exception(MessageLoader::getMessage(parms));              // throw Exception(MessageLoader::getMessage(parms));
               // do not localize message, requires a language tag for this
               // localization can cause recursion here
               throw Exception(parms.toString());
         }         }
     }     }
  


Legend:
Removed from v.1.23  
changed lines
  Added in v.1.34

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2