commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Jakarta-commons Wiki] Update of "ResourcesUserGuideIntro" by NiallPemberton
Date Mon, 28 Nov 2005 17:02:48 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-commons Wiki" for change notification.

The following page has been changed by NiallPemberton:
http://wiki.apache.org/jakarta-commons/ResourcesUserGuideIntro

------------------------------------------------------------------------------
- || [wiki:ResourcesUserGuide Contents] || [wiki:ResourcesUserGuideIntro Getting Started]
|| [wiki:ResourcesUserGuideMessages Messages] || [wiki:ResourcesUserGuideImplementations Standard]
|| [wiki:ResourcesUserGuideCreating Creating] ||
+ || [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/
XREF] ||
  ----
  = 1. Getting Started =
  
- == 1.1 Getting/Creating a Factory ==
+ == 1.1 Using Resources ==
+ The first thing is to get hold of / create a [http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/ResourcesFactory.html
ResourcesFactory] for the '''Resources''' implementation you want to use...
+ {{{
+         ResourcesFactory factory = new PropertyResourcesFactory();
+         factory.setReturnNull(true);
+ }}}
+ N.B. See below for an explantion of the '''return null''' configuration option.
  
-   '''TO DO''' put something here  
+ Then you can get a Resources instance (the factory may either create a new instance or provide
a cached instance, depending on its implementation)...
+ {{{
+         Resources resources = factory.getResources("Bar", "file:c:/myapp/foo/Bar");
+ }}}
+ Once you have the resources instance, you can then use it to retrieve ''localized resources''
using one of the five ''content retrieval'' methods provided...
+ {{{
+         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.2 Using Resources ==
+ === 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].
  
-   '''TO DO''' put something here  
+ Use the factory's write method for that property to configure your Resources instances for
this option:
+ {{{
+         factory.setReturnNull(true);
+ }}}
+ === 1.1.2 Resources Implementations ===
+ OK the next question is what '''Resources implementation do I use?''' You have two choices...
+  * [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:ResourcesUserGuideCreating Creating an Implementation] - create your own implementation.
  
- == 1.3 Return Null? ==
+ == 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:
+  * [http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/Message.html
Message] - a message representation.
+  * [http://jakarta.apache.org/commons/resources/apidocs/org/apache/commons/resources/MessageList.html
MessageList] - a set of Message objects.
  
-   '''TO DO''' put something here  
+ There is also a convenience class, provding static methods to facilitate handling messages:
+  * [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.
  
  ----
- || [wiki:ResourcesUserGuide Contents] || [wiki:ResourcesUserGuideIntro Getting Started]
|| [wiki:ResourcesUserGuideMessages Messages] || [wiki:ResourcesUserGuideImplementations Standard]
|| [wiki:ResourcesUserGuideCreating Creating] ||
+ || [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/
XREF] ||
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message