|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.velocity.tools.view.i18n.MultiViewsTool
public class MultiViewsTool
Allows for transparent content negotiation in a manner mimicking Apache httpd's MultiViews.
Reads the default language out of the ViewContext as
org.apache.velocity.tools.view.i18n.defaultLanguage
.
See findLocalizedResource(String, String)
and findLocalizedResource(String, Locale)
for usage.
Field Summary | |
---|---|
protected static java.lang.String |
DEFAULT_LANGUAGE_KEY
The key used to search initialization, context, and JVM parameters for the default language to use. |
protected java.lang.String |
defaultLanguage
The two character abbreviation for the request's default language. |
protected org.apache.velocity.app.VelocityEngine |
engine
|
Constructor Summary | |
---|---|
MultiViewsTool()
Creates a new uninitialized instance. |
Method Summary | |
---|---|
java.lang.String |
findLocalizedResource(java.lang.String name)
Calls findLocalizedResource(String, String) using the
default language. |
java.lang.String |
findLocalizedResource(java.lang.String name,
java.util.Locale locale)
Calls findLocalizedResource(String, String) using the
language extracted from locale . |
java.lang.String |
findLocalizedResource(java.lang.String name,
java.lang.String language)
Finds the a localized version of the requested Velocity resource (such as a file or template) which is most appropriate for the locale of the current request. |
void |
init(java.lang.Object obj)
Extracts the default language from the specified ViewContext , looking first at the Velocity
context, then the servlet context, then lastly at the JVM
default. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final java.lang.String DEFAULT_LANGUAGE_KEY
protected java.lang.String defaultLanguage
protected org.apache.velocity.app.VelocityEngine engine
Constructor Detail |
---|
public MultiViewsTool()
init(java.lang.Object)
to initialize it.
Method Detail |
---|
public void init(java.lang.Object obj)
ViewContext
, looking first at the Velocity
context, then the servlet context, then lastly at the JVM
default. This "narrow scope to wide scope" pattern makes it
easy to setup language overrides at different levels within
your application.
obj
- the current ViewContext
java.lang.IllegalArgumentException
- if the param is not a ViewContextpublic java.lang.String findLocalizedResource(java.lang.String name, java.util.Locale locale)
findLocalizedResource(String, String)
using the
language extracted from locale
.
findLocalizedResource(String, String)
public java.lang.String findLocalizedResource(java.lang.String name)
findLocalizedResource(String, String)
using the
default language.
findLocalizedResource(String, String)
public java.lang.String findLocalizedResource(java.lang.String name, java.lang.String language)
Finds the a localized version of the requested Velocity
resource (such as a file or template) which is most appropriate
for the locale of the current request. Use in conjuction with
Apache httpd's MultiViews
, or by itself.
Usage from a template would be something like the following:
#parse ($multiviews.findLocalizedResource("header.vm", "en"))
#include ($multiviews.findLocalizedResource("my_page.html", "en"))
#parse ($multiviews.findLocalizedResource("footer.vm", "en"))
You might also wrap this method using another pull/view tool
which does internationalization/localization/content negation
for a single point of access.
name
- The unlocalized name of the file to find.language
- The language to find localized context for.
name
if it is
not localizable.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |