org.moremotion.resource
Class Resource

java.lang.Object
  extended by org.moremotion.resource.Resource

public class Resource
extends java.lang.Object

Represents a multi-lingual resource. A resource has a resource Id, arguments and the name of the Resource Bundle where the resource definition exist.

Example:

 String tableName = "table_x";
 String dbName = "products";

 Resource res = new Resource("TABLE_NOT_FOUND", new String[]{tableName,dbName}, "myres");

 ADOM myds = request.newRequestADOM("myds");
 myds.setNodeValue("msg", res.toString());
 
toString() Method returns a specially formatted string. E.g:
   $res(TABLE_NOT_FOUND#myres,table_x,products)
 
Such $res() definitions existing in an ADOM are resolved with the actual resource text in the language of the page to be displayed next. The actual text of a resource i.e. TABLE_NOT_FOUND is taken from the resource bundle i.e. myres and the %0, %1 symbols in the resource text are replaced with arguments i.e. table_x, products.

Version:
$Id: Resource.java 51 2008-03-10 11:46:54Z erkan $

Field Summary
static java.lang.String RES
           
 
Constructor Summary
Resource(java.lang.String id)
          Creates a new resource.
Resource(java.lang.String id, java.lang.String[] arguments)
          Creates a new resource.
Resource(java.lang.String id, java.lang.String[] arguments, java.lang.String resBundleName)
          Creates a new resource.
 
Method Summary
 boolean bundleAssigned()
          Returns 'true' is a bundle name is assigned to resource 'false' otherwise
 java.lang.String format(java.lang.String language)
          Formats this resource by retrieving the actual text in specified language from the resource bundle and replacing the resource argument symbols in it.
 java.lang.String[] getArguments()
          Returns the resource arguments.
 java.lang.String getBundleName()
          Returns the name of the resource bundle
 java.lang.String getId()
          Returns the resource Id.
static void main(java.lang.String[] args)
          Test method.
static Resource parse(java.lang.String resfunc)
          Parses the resource function in the specified string and returns a resource object.
 void setArguments(java.lang.String[] value)
          Sets the resource arguments.
 void setBundleName(java.lang.String bundleName)
          Sets the name of the resource bundle
 java.lang.String toString()
          Returns the string respresentation of this resource as $res() function.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

RES

public static final java.lang.String RES
See Also:
Constant Field Values
Constructor Detail

Resource

public Resource(java.lang.String id)
Creates a new resource.

Parameters:
id - The resource Id

Resource

public Resource(java.lang.String id,
                java.lang.String[] arguments)
Creates a new resource.

Parameters:
id - The resource Id
arguments - The String array each element of it positionally corresponding to a resource argument

Resource

public Resource(java.lang.String id,
                java.lang.String[] arguments,
                java.lang.String resBundleName)
Creates a new resource.

Parameters:
id - The resource Id
arguments - The String array each element of it positionally corresponding to a resource argument
resBundleName - The name of the resource bundle where the actual resource text of this resource is kept
Method Detail

setBundleName

public void setBundleName(java.lang.String bundleName)
Sets the name of the resource bundle


getBundleName

public java.lang.String getBundleName()
Returns the name of the resource bundle


bundleAssigned

public boolean bundleAssigned()
Returns 'true' is a bundle name is assigned to resource 'false' otherwise


getId

public java.lang.String getId()
Returns the resource Id.


getArguments

public java.lang.String[] getArguments()
Returns the resource arguments.


setArguments

public void setArguments(java.lang.String[] value)
Sets the resource arguments.


toString

public java.lang.String toString()
Returns the string respresentation of this resource as $res() function. $res(RESOURCE_ID#bundle_name,res_arg1,res_arg2,..)

Overrides:
toString in class java.lang.Object

format

public java.lang.String format(java.lang.String language)
                        throws ResourceException
Formats this resource by retrieving the actual text in specified language from the resource bundle and replacing the resource argument symbols in it.

Parameters:
language - The language code i.e. en, de, fr, tr, etc.
Returns:
The formatted string
Throws:
ResourceException - if retrieval of the actual text fails.

parse

public static Resource parse(java.lang.String resfunc)
                      throws ResourceException
Parses the resource function in the specified string and returns a resource object.

Throws:
ResourceException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Test method.

Throws:
java.lang.Exception


Copyright © 2002-2008 MOR YAZILIM. All Rights Reserved.