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="7f47872d-5246-487f-8452-1ef40f659315"><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>

...

1. Getting Started

1.1 Using Resources

Wiki MarkupThe first thing is to get hold of / create is a \[http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/ResourcesFactory.html ResourcesFactory\] for the *Resources* implementation you want to use...

No Format
        ResourcesFactory factory = new PropertyResourcesFactory();
        factory.setReturnNull(true);

...

No Format
        Object resource = resources.getObject("foo.key", locale, null);
        String resource = resources.getString("foo.key", locale, null);
        byte[] resource = resources.getBytes("foo.key", locale, null);
        Reader resource = resources.getReader("foo.key", locale, null);
        InputStream resource = resources.getInputStream("foo.key", locale, null);

1.1.1 Return Null Option

...

The *return null* configuration option indicates what the above five _content retrieval_ methods should do when a resource key is not found - they _either_ return a *{{null}}* value or throw a \[http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/ ResourcesKeyException.html ResourcesKeyException\].

Use the factory's write method for that property to configure your Resources instances for this option:

...

OK the next question is what Resources implementation do I use? You have two choices...

  • Wiki Markup\[wiki:ResourcesUserGuideImplementations Standard Implementations\] - Commons Resources comes with a set of standard implementations for *properties* files, *XML* documents, *database* resources and versions for use in a *Web Application*
  • Wiki Markup\[wiki:ResourcesUserGuideCreating Creating an Implementation\] - create your own implementation. \\

1.2 Messages

The majority of what Commons Resources is about centers around the Resources type. However there are also two types defined for handling messages:

  • Wiki Markup\[http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/Message.html Message\] - a message representation. Wiki Markup\[http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/
  • MessageList.html MessageList\] - a set of Message objects. \\

There is also a convenience wrapper class, that provides message string lookups from a Resources instance, and parameter replacement:

  • Wiki Markup\[http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/Messages.html Messages\] - convenience class for handling messages. \\ \\

...



See the \[wiki:ResourcesUserGuideMessages Messages\] section in this User Guide for more details.

...

...

[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>