PageMixer API - 3.1

jp.ne.dti.lares.foozy.pagemixer.page
Class LocalePage

java.lang.Object
  |
  +--jp.ne.dti.lares.foozy.pagemixer.page.LocalePage
All Implemented Interfaces:
Page

public class LocalePage
extends java.lang.Object
implements Page

Page information accessing for locale sensitive page.

This class models the 'page' as the set of data for each locales. In other words, this class creates locale sensitive descriptor and returns different values(e.g.: content type, encoding and so on) for each locales.

This locale sensitive behavior uses 'java.util.ResourceBundle'. to look information shown below up.

It is recommended to omit encoding specification (= use encoding specified in content type) for maintenancability, if you write resource out in that encoding.

Since:
PageMixer 3.0

Field Summary
static java.lang.String KEY_CONTENT_TYPE
          Key name to look content type up in ResourceBundle.
static java.lang.String KEY_ENCODING
          Key name to look encoding up in ResourceBundle.
static java.lang.String KEY_LOCATION
          Key name to look resource location up in ResourceBundle.
 
Fields inherited from interface jp.ne.dti.lares.foozy.pagemixer.page.Page
DEFAULT_ENCODING
 
Constructor Summary
LocalePage()
          Constructor.
LocalePage(java.lang.String location)
          Constructor.
 
Method Summary
 void close(java.lang.Object descriptor)
          Discard locale sensitive descriptor object.
 void expire(long limit)
          Expire old page entries.
 java.lang.String getContentType(java.lang.Object descriptor)
          Get content type for correnspnded page.
 java.lang.String getEncoding(java.lang.Object descriptor)
          Get encoding of real resource for correnspnded page.
 java.lang.String getLocation(java.lang.Object descriptor)
          Get resource location to locate real resource for correnspnded page.
 PageEntry getPageEntry(java.lang.Object descriptor)
          Get page entry stored with locale of page as key from "Map".
 java.lang.Object open(java.lang.String location, java.util.Locale locale)
          Create locale sensitive descriptor object.
 void putPageEntry(java.lang.Object descriptor, PageEntry entry)
          Store specified entry into "Map" with locale of page as key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_LOCATION

public static final java.lang.String KEY_LOCATION
Key name to look resource location up in ResourceBundle.

This has value "location".

See Also:
getLocation(Object)

KEY_CONTENT_TYPE

public static final java.lang.String KEY_CONTENT_TYPE
Key name to look content type up in ResourceBundle.

This has value "contentType".

See Also:
getContentType(Object)

KEY_ENCODING

public static final java.lang.String KEY_ENCODING
Key name to look encoding up in ResourceBundle.

This has value "encoding".

See Also:
getEncoding(Object)
Constructor Detail

LocalePage

public LocalePage(java.lang.String location)
Constructor.

If null is specified as 'location', this treats 'location' parameter of open(String, Locale) as location of page resource.

So, it is recommended to specify 'location' of page explicitly, if:

Parameters:
location - of page resource

LocalePage

public LocalePage()
Constructor.

This is equivalent with LocalePage(null).

Method Detail

open

public java.lang.Object open(java.lang.String location,
                             java.util.Locale locale)
                      throws java.io.IOException
Create locale sensitive descriptor object.

This tries to get ResourceBundle by 'locale'. "Location" is used as base name of ResourceBundle, when this is constructed default constructor or with 'null' location. It is ignored otherwise.

Specified by:
open in interface Page
Parameters:
location - to symbolize target page
locale - of target page
Returns:
descriptor object
Throws:
java.io.IOException - fail to look ResourceBundle up

close

public void close(java.lang.Object descriptor)
           throws java.io.IOException
Discard locale sensitive descriptor object.

In fact, this method does nothing, because ResourceBundle has no API to discard.

Specified by:
close in interface Page
Parameters:
descriptor - of page
Throws:
java.io.IOException - never thrown, in fact

getLocation

public java.lang.String getLocation(java.lang.Object descriptor)
                             throws java.io.IOException
Get resource location to locate real resource for correnspnded page.

This looks resource location up by appling KEY_LOCATION to ResourceBundle.

Specified by:
getLocation in interface Page
Parameters:
descriptor - of page
Returns:
location to locate real resource for page
Throws:
java.io.IOException - fail to get information

getContentType

public java.lang.String getContentType(java.lang.Object descriptor)
                                throws java.io.IOException
Get content type for correnspnded page.

This looks content type up by appling KEY_CONTENT_TYPE to ResourceBundle.

Specified by:
getContentType in interface Page
Parameters:
descriptor - of page
Returns:
content type of page
Throws:
java.io.IOException - fail to get information

getEncoding

public java.lang.String getEncoding(java.lang.Object descriptor)
                             throws java.io.IOException
Get encoding of real resource for correnspnded page.

This looks encoding up by appling KEY_ENCODING to ResourceBundle, and treats it as shown below:

null(= not found)
result of getCharSet() with content type is returned(this also may be null)
"default encoding"
null, which means using runtime environment default encoding, is returned
otherwise
found value itself is used
Specified by:
getEncoding in interface Page
Parameters:
descriptor - of page
Returns:
encoding of InputStream to read page data in
Throws:
java.io.IOException - fail to get information

putPageEntry

public void putPageEntry(java.lang.Object descriptor,
                         PageEntry entry)
                  throws java.io.IOException
Store specified entry into "Map" with locale of page as key.
Specified by:
putPageEntry in interface Page
Parameters:
descriptor - of page
entry - to store

getPageEntry

public PageEntry getPageEntry(java.lang.Object descriptor)
                       throws java.io.IOException
Get page entry stored with locale of page as key from "Map".
Specified by:
getPageEntry in interface Page
Parameters:
descriptor - of page
Returns:
entry identified by locale of page

expire

public void expire(long limit)
Expire old page entries.

This expire page entries, whose last accessing timestamp is earlier than specified one, from "Map".

Specified by:
expire in interface Page
Parameters:
limit - milliseconds of last access timestamp

PageMixer API - 3.1