1*cdf0e10cSrcweir/************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir#ifndef __com_sun_star_resource_XResourceBundle_idl__ 28*cdf0e10cSrcweir#define __com_sun_star_resource_XResourceBundle_idl__ 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir#ifndef __com_sun_star_container_XNameAccess_idl__ 31*cdf0e10cSrcweir#include <com/sun/star/container/XNameAccess.idl> 32*cdf0e10cSrcweir#endif 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir#ifndef __com_sun_star_lang_Locale_idl__ 35*cdf0e10cSrcweir#include <com/sun/star/lang/Locale.idl> 36*cdf0e10cSrcweir#endif 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir//============================================================================= 40*cdf0e10cSrcweir 41*cdf0e10cSrcweirmodule com { module sun { module star { module resource { 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir//============================================================================= 44*cdf0e10cSrcweir/** Resource bundles contain locale-specific objects. 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir <p>When your program needs a locale-specific resource, such as 47*cdf0e10cSrcweir <code>String</code> for example, your program can load it from the 48*cdf0e10cSrcweir resource bundle that is appropriate for the current user's locale. In 49*cdf0e10cSrcweir this way, you can write program code that is largely independent of 50*cdf0e10cSrcweir the user's locale, which isolates most, if not all, of the 51*cdf0e10cSrcweir locale-specific information in resource bundles. 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir <p>This allows you to write programs that can: 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir <UL type=SQUARE> 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir <LI> be easily localized, or translated, into different 58*cdf0e10cSrcweir languages. 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir <LI> handle multiple locales at once. 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir <LI> be easily modified, later, to support even more locales. 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir </UL> 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir <P> One resource bundle is, conceptually, a set of related services 67*cdf0e10cSrcweir that supports <code>XResourceBundle</code>. Each related service of 68*cdf0e10cSrcweir <code>XResourceBundle</code> has the same base name plus an 69*cdf0e10cSrcweir additional component that identifies its locale. For example, suppose 70*cdf0e10cSrcweir your resource bundle is named <code>MyResources</code>. The first 71*cdf0e10cSrcweir service you are likely to implement is the default resource bundle, 72*cdf0e10cSrcweir which has the same name as its family--<code>MyResources</code>. You 73*cdf0e10cSrcweir can also provide as many related locale-specific services as you need. 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir For example, perhaps you would provide a German one named 76*cdf0e10cSrcweir <code>MyResources_de</code>. 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir <P> 79*cdf0e10cSrcweir Each related implementation of <code>XResourceBundle</code> contains 80*cdf0e10cSrcweir the same items, but the items have been translated for the locale 81*cdf0e10cSrcweir represented by that <code>XResourceBundle</code> implementation. For 82*cdf0e10cSrcweir example, both <code>MyResources</code> and <code>MyResources_de</code> 83*cdf0e10cSrcweir may have a <code>String</code> that is used on a button for 84*cdf0e10cSrcweir confirming operations. In <code>MyResources</code> the 85*cdf0e10cSrcweir <code>String</code> may contain <code>OK</code> and in 86*cdf0e10cSrcweir <code>MyResources_de</code> it may contain <code>Gut</code>. 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir <P> 89*cdf0e10cSrcweir If there are different resources for different countries, you 90*cdf0e10cSrcweir can make specializations: for example, <code>MyResources_de_CH</code> 91*cdf0e10cSrcweir is the German language (de) in Switzerland (CH). If you only want to 92*cdf0e10cSrcweir modify some of the resources in the specialization, you can do so. 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir <P> 95*cdf0e10cSrcweir When your program needs a locale-specific object, it loads 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir the <code>XResourceBundle</code> implementation using the 98*cdf0e10cSrcweir <type>XResourceBundleLoader</type> service: 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir <listing> 101*cdf0e10cSrcweir XResourceBundle myResources = xLoader.getBundle("MyResources", currentLocale); 102*cdf0e10cSrcweir </listing> 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir <p>The first argument specifies the family name of the resource 105*cdf0e10cSrcweir bundle that contains the object in question. The second argument 106*cdf0e10cSrcweir indicates the desired locale. <code>getBundle</code> uses these two 107*cdf0e10cSrcweir arguments to construct the name of the <code>ResourceBundle</code> 108*cdf0e10cSrcweir subclass it should load according to the following specifications. 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir <P>The resource bundle lookup searches for services with various 111*cdf0e10cSrcweir suffixes on the basis of (1) the desired locale and (2) the current 112*cdf0e10cSrcweir default locale as returned by Locale.getDefault(), and (3) the root 113*cdf0e10cSrcweir resource bundle (baseclass), in the following order from lower-level 114*cdf0e10cSrcweir (more specific) to parent-level (less specific): 115*cdf0e10cSrcweir <p> baseclass + "_" + language1 + "_" + country1 + "_" + variant1 116*cdf0e10cSrcweir <BR> baseclass + "_" + language1 + "_" + country1 117*cdf0e10cSrcweir <BR> baseclass + "_" + language1 118*cdf0e10cSrcweir <BR> baseclass + "_" + language2 + "_" + country2 + "_" + variant2 119*cdf0e10cSrcweir <BR> baseclass + "_" + language2 + "_" + country2 120*cdf0e10cSrcweir <BR> baseclass + "_" + language2 121*cdf0e10cSrcweir <BR> baseclass 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir <P> For example, if the current default locale is <TT>en_US</TT>, the 124*cdf0e10cSrcweir locale that the caller is interested in is <TT>fr_CH</TT>, and the 125*cdf0e10cSrcweir resource bundle name is <TT>MyResources</TT>; resource bundle lookup 126*cdf0e10cSrcweir will search for the following services, in order: 127*cdf0e10cSrcweir <BR> <TT>MyResources_fr_CH 128*cdf0e10cSrcweir <BR> MyResources_fr 129*cdf0e10cSrcweir <BR> MyResources_en_US 130*cdf0e10cSrcweir <BR> MyResources_en 131*cdf0e10cSrcweir <BR> MyResources</TT> 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir <P> The result of the lookup is a service, but that service may be 134*cdf0e10cSrcweir backed by a property file on disk. If a lookup fails, 135*cdf0e10cSrcweir <code>getBundle()</code> throws a 136*cdf0e10cSrcweir <code>MissingResourceException</code>. 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir <P> The base service <strong>must</strong> be fully qualified (for 139*cdf0e10cSrcweir example, <code>myPackage::MyResources</code>, not just 140*cdf0e10cSrcweir <code>MyResources</code>). 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir <P> Resource bundles contain key/value pairs. The keys uniquely 143*cdf0e10cSrcweir identify a locale-specific object in the bundle. Here is an 144*cdf0e10cSrcweir example of a <code>XResourceBundle</code> implementation that contains 145*cdf0e10cSrcweir two key/value pairs: 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir <listing> 148*cdf0e10cSrcweir class MyResource extends com.sun.star.resource.XResourceBundle 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir // some queryInterface stuff 151*cdf0e10cSrcweir // ... 152*cdf0e10cSrcweir public final Object getDirectElement(String key) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir if (key.equals("okKey")) return "Ok"; 155*cdf0e10cSrcweir if (key.equals("cancelKey")) return "Cancel"; 156*cdf0e10cSrcweir return null; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir </listing> 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir <p>Keys are always <code>String</code>s. In this example, the keys 162*cdf0e10cSrcweir are <code>OkKey</code> and <code>CancelKey</code>. In the above 163*cdf0e10cSrcweir example, the values are also <code>String</code>s--<code>OK</code> 164*cdf0e10cSrcweir and <code>Cancel</code>--but they do not have to be. The values can 165*cdf0e10cSrcweir be any type of object. 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir <P> You retrieve an object from resource bundle using the appropriate 168*cdf0e10cSrcweir get method. Because <code>OkKey</code> and <code>CancelKey</code> 169*cdf0e10cSrcweir are both strings, you use <code>getByName</code> to retrieve them: 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir <listing> 172*cdf0e10cSrcweir button1 = new Button(myResourceBundle.getByName("OkKey").getString()); 173*cdf0e10cSrcweir button2 = new Button(myResourceBundle.getByName("CancelKey").getString()); 174*cdf0e10cSrcweir </listing> 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir <p>The get methods all require the key as an argument and return 177*cdf0e10cSrcweir the object if found. If the object is not found, the get methods 178*cdf0e10cSrcweir throw a <type scope="com::sun::star::container">NoSuchElementException</type>. 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir <P> <STRONG>NOTE:</STRONG> You should always supply a base service 181*cdf0e10cSrcweir with no suffixes. This will be the class of "last resort" if a 182*cdf0e10cSrcweir locale is requested that does not exist. In fact, you must provide 183*cdf0e10cSrcweir <I>all</I> of the services in any given inheritance chain for which 184*cdf0e10cSrcweir you provide a resource. For example, if you provide 185*cdf0e10cSrcweir <TT>MyResources_fr_BE</TT>, you must provide <I>both</I> 186*cdf0e10cSrcweir <TT>MyResources</TT> <I>and</I> <TT>MyResources_fr</TT>, or the 187*cdf0e10cSrcweir resource bundle lookup will not work right. 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir <P>You do not have to restrict yourself to using a single family of 190*cdf0e10cSrcweir <code>ResourceBundle</code>s. For example, you could have a set of 191*cdf0e10cSrcweir bundles for exception messages, <code>ExceptionResources</code> 192*cdf0e10cSrcweir (<code>ExceptionResources_fr</code>, <code>ExceptionResources_de</code>, ...), 193*cdf0e10cSrcweir and one for widgets, <code>WidgetResource</code> (<code>WidgetResources_fr</code>, 194*cdf0e10cSrcweir <code>WidgetResources_de</code>, ...); breaking up the resources however you like. 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir @see MissingResourceException 197*cdf0e10cSrcweir @see Locale 198*cdf0e10cSrcweir @version 0.1 26 May 1999 199*cdf0e10cSrcweir @author Mark Davis 200*cdf0e10cSrcweir @author Markus Meyer 201*cdf0e10cSrcweir @deprecated draft 202*cdf0e10cSrcweir*/ 203*cdf0e10cSrcweirpublished interface XResourceBundle: com::sun::star::container::XNameAccess 204*cdf0e10cSrcweir{ 205*cdf0e10cSrcweir //------------------------------------------------------------------------- 206*cdf0e10cSrcweir /** contains the parent bundle of this bundle. 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir <p>The parent bundle is searched by the method 209*cdf0e10cSrcweir <method scope="com::sun::star::container">XNameAccess::getByName</method> 210*cdf0e10cSrcweir when this bundle does not contain a particular resource. 211*cdf0e10cSrcweir */ 212*cdf0e10cSrcweir [attribute] XResourceBundle Parent; 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir //------------------------------------------------------------------------- 215*cdf0e10cSrcweir /** @returns 216*cdf0e10cSrcweir the locale for this resource bundle. 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir <p>This function can be used to determine whether the 219*cdf0e10cSrcweir resource bundle that is returned really corresponds to the 220*cdf0e10cSrcweir requested locale or is a fallback. 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir */ 223*cdf0e10cSrcweir com::sun::star::lang::Locale getLocale(); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir //------------------------------------------------------------------------- 226*cdf0e10cSrcweir /** @returns 227*cdf0e10cSrcweir an object from a resource bundle or NULL if no resource 228*cdf0e10cSrcweir exists. 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir <p>It does not look in the parents. 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir @param key 233*cdf0e10cSrcweir specifies the element. 234*cdf0e10cSrcweir */ 235*cdf0e10cSrcweir any getDirectElement( [in] string key ); 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir}; 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir//============================================================================= 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir}; }; }; }; 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir#endif 244