<html> <head> <title>Interface XResourceBundle</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" type="text/css" href="../../../../idl.css"> </head> <body> <div id="adc-idlref"> <a name="_top_"> </a><table class="navimain" border="0" cellpadding="3"> <tr> <td class="navimain"><a href="../module-ix.html" class="navimain">Overview</a></td> <td class="navimain"><a href="module-ix.html" class="navimain">Module</a></td> <td class="navimain"><a href="XResourceBundle-xref.html" class="navimain">Use</a></td> <td class="navimainnone">Devguide</td> <td class="navimain"><a href="../../../../index-files/index-1.html" class="navimain">Index</a></td> </tr> </table> <table class="navisub" border="0" cellpadding="0"> <tr> <td class="navisub"><a href="#MethodsSummary" class="navisub">Methods' Summary</a></td> <td class="navisub"><a href="#AttributesSummary" class="navisub">Attributes' Summary</a></td> <td class="navisub"><a href="#MethodsDetails" class="navisub">Methods' Details</a></td> <td class="navisub"><a href="#AttributesDetails" class="navisub">Attributes' Details</a></td> </tr> </table> <hr> <table border="0" width="100%" cellpadding="5" cellspacing="3" class="title-table" style="margin-bottom:6pt;"> <tr> <td><p class="namechain"><a href="../../../../module-ix.html" class="namechain">::</a> <a href="../../../module-ix.html" class="namechain">com</a> :: <a href="../../module-ix.html" class="namechain">sun</a> :: <a href="../module-ix.html" class="namechain">star</a> :: <a href="module-ix.html" class="namechain">resource</a> :: </p> </td> </tr> <tr> <td class="title"><table class="title-table" width="99%"> <tr> <td width="25%" class="title2">deprecated </td> <td width="50%" class="title">interface XResourceBundle</td> <td width="*"/></tr> </table> </td> </tr> <tr> <td><dl> <dt><b>Base Interfaces</b></dt> <dd><pre style="font-family:monospace;"><strong>XResourceBundle</strong> ┗ ::com::sun::star::<a href="../container/module-ix.html">container</a>::<a href="../container/XNameAccess.html">XNameAccess</a> ┗ ::com::sun::star::<a href="../container/module-ix.html">container</a>::<a href="../container/XElementAccess.html">XElementAccess</a> </pre></dd> <dd><a name/><table border="1" width="100%" cellpadding="5" cellspacing="0" class="crosstitle"> <tr> <td class="imsum_left">::com::sun::star::<a href="../container/module-ix.html">container</a>::<a href="../container/XNameAccess.html">XNameAccess</a></td> <td class="imsum_right"><dl> <dt>(referenced interface's summary:)</dt> <dd>is used to access named objects within a container. </dd> </dl> </td> </tr> </table> </dd> </dl> </td> </tr> <tr> <td><dl> <dt><b>Usage Restrictions</b></dt> <dd><i>deprecated</i></dd> <dt><b>Deprecation Info</b></dt> <dd>draft </dd> <dt><b>Description</b></dt> <dd>Resource bundles contain locale-specific objects. </dd> <dd><p>When your program needs a locale-specific resource, such as <code>String</code> for example, your program can load it from the resource bundle that is appropriate for the current user's locale. In this way, you can write program code that is largely independent of the user's locale, which isolates most, if not all, of the locale-specific information in resource bundles. <p>This allows you to write programs that can: <UL type=SQUARE> <LI> be easily localized, or translated, into different languages. <LI> handle multiple locales at once. <LI> be easily modified, later, to support even more locales. </UL> <P> One resource bundle is, conceptually, a set of related services that supports <code>XResourceBundle</code>. Each related service of <code>XResourceBundle</code> has the same base name plus an additional component that identifies its locale. For example, suppose your resource bundle is named <code>MyResources</code>. The first service you are likely to implement is the default resource bundle, which has the same name as its family--<code>MyResources</code>. You can also provide as many related locale-specific services as you need. For example, perhaps you would provide a German one named <code>MyResources_de</code>. <P> Each related implementation of <code>XResourceBundle</code> contains the same items, but the items have been translated for the locale represented by that <code>XResourceBundle</code> implementation. For example, both <code>MyResources</code> and <code>MyResources_de</code> may have a <code>String</code> that is used on a button for confirming operations. In <code>MyResources</code> the <code>String</code> may contain <code>OK</code> and in <code>MyResources_de</code> it may contain <code>Gut</code>. <P> If there are different resources for different countries, you can make specializations: for example, <code>MyResources_de_CH</code> is the German language (de) in Switzerland (CH). If you only want to modify some of the resources in the specialization, you can do so. <P> When your program needs a locale-specific object, it loads the <code>XResourceBundle</code> implementation using the <a href="XResourceBundleLoader.html">XResourceBundleLoader</a> service: <pre> XResourceBundle myResources = xLoader.getBundle("MyResources", currentLocale); </pre> <p>The first argument specifies the family name of the resource bundle that contains the object in question. The second argument indicates the desired locale. <code>getBundle</code> uses these two arguments to construct the name of the <code>ResourceBundle</code> subclass it should load according to the following specifications. <P>The resource bundle lookup searches for services with various suffixes on the basis of (1) the desired locale and (2) the current default locale as returned by Locale.getDefault(), and (3) the root resource bundle (baseclass), in the following order from lower-level (more specific) to parent-level (less specific): <p> baseclass + "_" + language1 + "_" + country1 + "_" + variant1 <BR> baseclass + "_" + language1 + "_" + country1 <BR> baseclass + "_" + language1 <BR> baseclass + "_" + language2 + "_" + country2 + "_" + variant2 <BR> baseclass + "_" + language2 + "_" + country2 <BR> baseclass + "_" + language2 <BR> baseclass <P> For example, if the current default locale is <TT>en_US</TT>, the locale that the caller is interested in is <TT>fr_CH</TT>, and the resource bundle name is <TT>MyResources</TT>; resource bundle lookup will search for the following services, in order: <BR> <TT>MyResources_fr_CH <BR> MyResources_fr <BR> MyResources_en_US <BR> MyResources_en <BR> MyResources</TT> <P> The result of the lookup is a service, but that service may be backed by a property file on disk. If a lookup fails, <code>getBundle()</code> throws a <code>MissingResourceException</code>. <P> The base service <strong>must</strong> be fully qualified (for example, <code>myPackage::MyResources</code>, not just <code>MyResources</code>). <P> Resource bundles contain key/value pairs. The keys uniquely identify a locale-specific object in the bundle. Here is an example of a <code>XResourceBundle</code> implementation that contains two key/value pairs: <pre> class MyResource extends com.sun.star.resource.XResourceBundle { // some queryInterface stuff // ... public final Object getDirectElement(String key) { if (key.equals("okKey")) return "Ok"; if (key.equals("cancelKey")) return "Cancel"; return null; } } </pre> <p>Keys are always <code>String</code>s. In this example, the keys are <code>OkKey</code> and <code>CancelKey</code>. In the above example, the values are also <code>String</code>s--<code>OK</code> and <code>Cancel</code>--but they do not have to be. The values can be any type of object. <P> You retrieve an object from resource bundle using the appropriate get method. Because <code>OkKey</code> and <code>CancelKey</code> are both strings, you use <code>getByName</code> to retrieve them: <pre> button1 = new Button(myResourceBundle.getByName("OkKey").getString()); button2 = new Button(myResourceBundle.getByName("CancelKey").getString()); </pre> <p>The get methods all require the key as an argument and return the object if found. If the object is not found, the get methods throw a ::com::sun::star::<a href="../container/module-ix.html">container</a>::<a href="../container/NoSuchElementException.html">NoSuchElementException</a>. <P> <STRONG>NOTE:</STRONG> You should always supply a base service with no suffixes. This will be the class of "last resort" if a locale is requested that does not exist. In fact, you must provide <I>all</I> of the services in any given inheritance chain for which you provide a resource. For example, if you provide <TT>MyResources_fr_BE</TT>, you must provide <I>both</I> <TT>MyResources</TT> <I>and</I> <TT>MyResources_fr</TT>, or the resource bundle lookup will not work right. <P>You do not have to restrict yourself to using a single family of <code>ResourceBundle</code>s. For example, you could have a set of bundles for exception messages, <code>ExceptionResources</code> (<code>ExceptionResources_fr</code>, <code>ExceptionResources_de</code>, ...), and one for widgets, <code>WidgetResource</code> (<code>WidgetResources_fr</code>, <code>WidgetResources_de</code>, ...); breaking up the resources however you like. </dd> <dt><b/></dt> <dd/><dt><b/></dt> <dd/></dl> </td> </tr> </table> <hr> <a name="MethodsSummary"/><table border="1" width="100%" cellpadding="5" cellspacing="0" class="subtitle"> <tr> <td class="subtitle" colspan="2">Methods' Summary</td> </tr> <tr> <td class="imsum_left"><a href="#getLocale">getLocale</a></td> <td class="imsum_right"> </td> </tr> <tr> <td class="imsum_left"><a href="#getDirectElement">getDirectElement</a></td> <td class="imsum_right"> </td> </tr> </table> <a name="AttributesSummary"/><table border="1" width="100%" cellpadding="5" cellspacing="0" class="subtitle"> <tr> <td class="subtitle" colspan="2">Attributes' Summary</td> </tr> <tr> <td class="imsum_left"><a href="#Parent">Parent</a></td> <td class="imsum_right">contains the parent bundle of this bundle. </td> </tr> </table> <a name="MethodsDetails"/><table border="1" width="100%" cellpadding="5" cellspacing="0" class="subtitle"> <tr> <td class="subtitle">Methods' Details</td> </tr> <tr> <td class="imdetail"><a name="getLocale" class="membertitle">getLocale</a><table border="0" width="96%" cellpadding="5" cellspacing="0" class="table-in-method" bgcolor="#ffffff" align="center"> <tr> <td><table class="table-in-method" border="0"> <tr> <td valign="top" colspan="3">::com::sun::star::<a href="../lang/module-ix.html">lang</a>::<a href="../lang/Locale.html">Locale</a></td> </tr> <tr> <td valign="top"><b>getLocale</b>();</td> </tr> </table> <hr> <dl> <dt><b>Returns</b></dt> <dd>the locale for this resource bundle. <p>This function can be used to determine whether the resource bundle that is returned really corresponds to the requested locale or is a fallback. </dd> </dl> </td> </tr> </table> </td> </tr> <tr> <td class="imdetail"><a name="getDirectElement" class="membertitle">getDirectElement</a><table border="0" width="96%" cellpadding="5" cellspacing="0" class="table-in-method" bgcolor="#ffffff" align="center"> <tr> <td><table class="table-in-method" border="0"> <tr> <td valign="top" colspan="3">any</td> </tr> <tr> <td valign="top"><b>getDirectElement</b>(</td> <td valign="top">[in] string</td> <td valign="bottom"> key );</td> </tr> </table> <hr> <dl> <dt><b>Returns</b></dt> <dd>an object from a resource bundle or NULL if no resource exists. <p>It does not look in the parents. </dd> <dt><b>Parameter key</b></dt> <dd>specifies the element. </dd> </dl> </td> </tr> </table> </td> </tr> </table> <a name="AttributesDetails"/><table border="1" width="100%" cellpadding="5" cellspacing="0" class="subtitle"> <tr> <td class="subtitle">Attributes' Details</td> </tr> <tr> <td class="imdetail"><a name="Parent" class="membertitle">Parent</a><table border="0" width="96%" cellpadding="5" cellspacing="0" class="table-in-data" bgcolor="#ffffff" align="center"> <tr> <td><a href="XResourceBundle.html">XResourceBundle</a> <b>Parent</b>;<hr> <dl> <dt><b>Description</b></dt> <dd>contains the parent bundle of this bundle. </dd> <dd><p>The parent bundle is searched by the method <method scope="com::sun::star::container">XNameAccess::getByName</method> when this bundle does not contain a particular resource. </dd> </dl> </td> </tr> </table> </td> </tr> </table> <a href="#_top_">Top of Page</a><hr size="3"><p class="copyright" align="center">Copyright © 2009 Sun Microsystems, Inc.</p> </div> <!-- id="adc-idlref" --> </body> </html>