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