Home | History | Annotate | Download | only in common
      1 /**
      2  *******************************************************************************
      3  * Copyright (C) 2001-2005, International Business Machines Corporation and    *
      4  * others. All Rights Reserved.                                                *
      5  *******************************************************************************
      6  *
      7  *******************************************************************************
      8  */
      9 #include "unicode/utypes.h"
     10 
     11 #if !UCONFIG_NO_SERVICE
     12 
     13 #include "unicode/resbund.h"
     14 #include "uresimp.h"
     15 #include "cmemory.h"
     16 #include "servloc.h"
     17 #include "ustrfmt.h"
     18 #include "uhash.h"
     19 #include "charstr.h"
     20 #include "ucln_cmn.h"
     21 #include "uassert.h"
     22 
     23 #define UNDERSCORE_CHAR ((UChar)0x005f)
     24 #define AT_SIGN_CHAR    ((UChar)64)
     25 #define PERIOD_CHAR     ((UChar)46)
     26 
     27 U_NAMESPACE_BEGIN
     28 
     29 ICUResourceBundleFactory::ICUResourceBundleFactory()
     30   : LocaleKeyFactory(VISIBLE)
     31   , _bundleName()
     32 {
     33 }
     34 
     35 ICUResourceBundleFactory::ICUResourceBundleFactory(const UnicodeString& bundleName)
     36   : LocaleKeyFactory(VISIBLE)
     37   , _bundleName(bundleName)
     38 {
     39 }
     40 
     41 ICUResourceBundleFactory::~ICUResourceBundleFactory() {}
     42 
     43 const Hashtable*
     44 ICUResourceBundleFactory::getSupportedIDs(UErrorCode& status) const
     45 {
     46     if (U_SUCCESS(status)) {
     47         return LocaleUtility::getAvailableLocaleNames(_bundleName);
     48     }
     49     return NULL;
     50 }
     51 
     52 UObject*
     53 ICUResourceBundleFactory::handleCreate(const Locale& loc, int32_t /* kind */, const ICUService* /* service */, UErrorCode& status) const
     54 {
     55     if (U_SUCCESS(status)) {
     56         // _bundleName is a package name
     57         // and should only contain invariant characters
     58                 // ??? is it always true that the max length of the bundle name is 19?
     59                 // who made this change? -- dlf
     60         char pkg[20];
     61         int32_t length;
     62         length=_bundleName.extract(0, INT32_MAX, pkg, (int32_t)sizeof(pkg), US_INV);
     63         if(length>=(int32_t)sizeof(pkg)) {
     64             return NULL;
     65         }
     66         return new ResourceBundle(pkg, loc, status);
     67     }
     68     return NULL;
     69 }
     70 
     71 #ifdef SERVICE_DEBUG
     72 UnicodeString&
     73 ICUResourceBundleFactory::debug(UnicodeString& result) const
     74 {
     75     LocaleKeyFactory::debug(result);
     76     result.append(", bundle: ");
     77     return result.append(_bundleName);
     78 }
     79 
     80 UnicodeString&
     81 ICUResourceBundleFactory::debugClass(UnicodeString& result) const
     82 {
     83     return result.append("ICUResourceBundleFactory");
     84 }
     85 #endif
     86 
     87 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ICUResourceBundleFactory)
     88 
     89 U_NAMESPACE_END
     90 
     91 /* !UCONFIG_NO_SERVICE */
     92 #endif
     93 
     94 
     95