This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: converted to 1.6 markup

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2bdbcef6-104b-4155-a78d-de0a838d4403"><ac:plain-text-body><![CDATA[

[http://jakarta.apache.org/commons/resources/ Home]

[wiki:Resources Wiki] [wiki

:ResourcesUserGuide Guide]

[wiki:ResourcesUserGuideIntro Getting Started] [

wiki:ResourcesUserGuideMessages Messages]

[wiki:ResourcesUserGuideImplementations Standard] [wiki

:ResourcesUserGuideCreating Creating]

[http://jakarta.apache.org/commons/resources/apidocs/ API] [http://jakarta.apache.org/commons/resources/xref/

Source]

]]></ac:plain-text-body></ac:structured-macro>

...

4. Creating a Resources Implementation

Wiki MarkupYou can implement the \[http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/Resources.html Resources\] and \[http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/ResourcesFactory.html ResourcesFactory\] interfaces directly, however, by far the easiest way is to use one of the *base* implementations provided.

The two base Resources classes are:

  • Wiki Markup\[http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/impl/ResourcesBase.html ResourcesBase\] - implements Resources
    • init() - (optional) for initialization processing.
    • getKeys() - (required) return the set (Iterator) of keys in this Resources
    • getObject(key, Locale, TimeZone) - (required) retrieve the content for a key/Locale/Timezone
    Wiki Markup\[http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/impl/
  • CollectionResourcesBase.html CollectionResourcesBase\] - extends *ResourcesBase* and provides a mechanism for caching a set of *Map*s containing key/value pairs for a Locale.
    • init() - (optional) for initialization processing.
    • getLocaleMap(baseUrl, Locale) (required) returns a Map of key/value pairs for a Locale.

...

No Format
    public class MyResources extends CollectionsResourcesBase {

        public MyResources(String name, config) {
            super(name, config);
        }

        public void init() {
            // do initialization here, if required
        }

        public Object getLocaleMap(String baseUrl, Locale locale) {
            // must implement this method
        }
    }

4.3 ResourcesFactory

Wiki MarkupTo create a *factory* for your *Resources* implementation, extend the \[http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/impl/ ResourcesFactoryBase .html ResourcesFactoryBase\] ...

No Format
    public class MyResourcesFactory extends ResourcesFactoryBase {

        public MyResources() {
            super();
        }

        protected Resources createResources(String name, String config) {
            Resources resources = new MyResources(name);
            Resources res = new PropertyResources(name, config);
            resources.setReturnNull(isReturnNull());
            resources.init();
            return resources;
        }
    }

Wiki Markup*N.B* for implementations to be used in a Web Application there is a \[http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/impl/WebappResourcesFactoryBase.html WebappResourcesFactoryBase\] factory which includes a *ServletContext* property with appropriate read/write methods.

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="eb8a7d96-6de9-4d39-99b4-6a35b73f3540"><ac:plain-text-body><![CDATA[

[http://jakarta.apache.org/commons/resources/ Home]

[wiki:Resources Wiki] [wiki

:ResourcesUserGuide Guide]

[wiki:ResourcesUserGuideIntro Getting Started] [

wiki:ResourcesUserGuideMessages Messages]

[wiki:ResourcesUserGuideImplementations Standard] [wiki

:ResourcesUserGuideCreating Creating]

[http://jakarta.apache.org/commons/resources/apidocs/ API] [http://jakarta.apache.org/commons/resources/xref/

Source]

]]></ac:plain-text-body></ac:structured-macro>