jstrachan 2003/01/16 08:21:47
Added: jelly/jelly-tags/fmt maven.xml project.xml
project.properties build.xml
jelly/jelly-tags/fmt/src/test/org/apache/commons/jelly/tags/fmt
xyz_zh.properties suite.jelly TestFMTSuite.java
abc.properties xyz.properties
jelly/jelly-tags/fmt/src/java/org/apache/commons/jelly/tags/fmt
BundleTag.java SetLocaleTag.java ParamTag.java
MessageTag.java LocalizationContext.java
FmtTagLibrary.java Config.java
Log:
Added Willie Vu's initial implementation of the JSTL i18n tags.
Revision Changes Path
1.1 jakarta-commons-sandbox/jelly/jelly-tags/fmt/maven.xml
Index: maven.xml
===================================================================
<project default="java:jar">
</project>
1.1 jakarta-commons-sandbox/jelly/jelly-tags/fmt/project.xml
Index: project.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE project [
<!-- see file for description -->
<!ENTITY commonDeps SYSTEM "file:../../commonDependencies.ent">
]>
<project>
<extend>../tag-project.xml</extend>
<id>commons-jelly-tags-fmt</id>
<groupId>commons-jelly</groupId>
<name>commons-jelly-tags-fmt</name>
<package>org.apache.commons.jelly.tags.fmt</package>
<description>
The Jelly JSP Standard Tag Library (JSTL) for I18N and Formatting
</description>
<shortDescription>Commons Jelly FMT Tag Library</shortDescription>
<url>http://jakarta.apache.org/commons/sandbox/jelly/tags/fmt/</url>
<siteDirectory>/www/jakarta.apache.org/commons/sandbox/jelly/fmt/</siteDirectory>
<distributionDirectory>/www/jakarta.apache.org/builds/jakarta-commons-sandbox/jelly/tags/fmt</distributionDirectory>
<repository>
<connection>scm:cvs:pserver:[EMAIL PROTECTED]:/home/cvspublic:jakarta-commons-sandbox/jelly/jelly-tags/fmt/</connection>
<url>http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/jelly/jelly-tags/fmt/</url>
</repository>
<dependencies>
&commonDeps;
<!-- START for compilation -->
<dependency>
<id>commons-jelly</id>
<version>SNAPSHOT</version>
</dependency>
<!-- END for compilation -->
<!-- below for testing, pulled in by ant taglib -->
<dependency>
<id>commons-jelly+tags-ant</id>
<version>SNAPSHOT</version>
</dependency>
<dependency>
<id>ant</id>
<version>1.5.1</version>
</dependency>
<dependency>
<id>ant+optional</id>
<version>1.5.1</version>
</dependency>
<dependency>
<id>commons-grant</id>
<version>1.0-beta-4</version>
</dependency>
</dependencies>
</project>
1.1 jakarta-commons-sandbox/jelly/jelly-tags/fmt/project.properties
Index: project.properties
===================================================================
# -------------------------------------------------------------------
# P R O J E C T P R O P E R T I E S
# -------------------------------------------------------------------
maven.junit.fork=true
maven.compile.deprecation = on
maven.checkstyle.properties =../tag-checkstyle.properties
1.1 jakarta-commons-sandbox/jelly/jelly-tags/fmt/build.xml
Index: build.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<project default="jar" name="commons-jelly-tags-jsl" basedir=".">
<property name="defaulttargetdir" value="target"></property>
<property name="classesdir" value="target/classes"></property>
<property name="testclassesdir" value="target/test-classes"></property>
<property name="testreportdir" value="target/test-reports"></property>
<property name="resourcedir" value="."></property>
<property name="distdir" value="dist"></property>
<property name="javadocdir" value="target/docs/apidocs"></property>
<property name="final.name" value="commons-jelly-tags-jsl-1.0-SNAPSHOT"></property>
<target name="init" description="o Initializes some properties">
<mkdir dir="lib"></mkdir>
<condition property="noget">
<equals arg2="only" arg1="${build.sysclasspath}"></equals>
</condition>
</target>
<target name="compile" description="o Compile the code" depends="get-deps">
<mkdir dir="${classesdir}"></mkdir>
<javac destdir="${classesdir}" deprecation="true" debug="true" optimize="false"
excludes="**/package.html">
<src>
<pathelement location="src/java"></pathelement>
</src>
<classpath>
<fileset dir="lib">
<include name="*.jar"></include>
</fileset>
</classpath>
</javac>
<copy todir="${classesdir}">
<fileset dir="src/java">
<include name="**/*.properties"></include>
</fileset>
</copy>
<copy todir="${testclassesdir}">
<fileset dir="src/test">
<include name="**/*.jelly"></include>
<include name="**/*.xml"></include>
<include name="**/*.xsl"></include>
<include name="**/*.rng"></include>
<include name="**/*.dtd"></include>
<include name="**/*.properties"></include>
<include name="**/*.html"></include>
</fileset>
</copy>
</target>
<target name="jar" description="o Create the jar" depends="compile,test">
<jar jarfile="target/${final.name}.jar" excludes="**/package.html"
basedir="${classesdir}"></jar>
</target>
<target name="clean" description="o Clean up the generated directories">
<delete dir="${defaulttargetdir}"></delete>
<delete dir="${distdir}"></delete>
</target>
<target name="dist" description="o Create a distribution" depends="jar, javadoc">
<mkdir dir="dist"></mkdir>
<copy todir="dist">
<fileset dir="${defaulttargetdir}"></fileset>
</copy>
</target>
<target name="test" description="o Run the test cases" if="test.failure"
depends="internal-test">
<fail message="There were test failures."></fail>
</target>
<target name="internal-test" depends="compile-tests">
<mkdir dir="${testreportdir}"></mkdir>
<junit dir="./" failureproperty="test.failure" printSummary="yes" fork="true"
haltonerror="true">
<sysproperty key="basedir" value="."></sysproperty>
<formatter type="xml"></formatter>
<formatter usefile="true" type="plain"></formatter>
<classpath>
<fileset dir="lib">
<include name="*.jar"></include>
</fileset>
<pathelement path="${testclassesdir}"></pathelement>
<pathelement path="${classesdir}"></pathelement>
</classpath>
<batchtest todir="${testreportdir}">
<fileset dir="src/test">
<include name="**/Test*.java"></include>
</fileset>
</batchtest>
</junit>
</target>
<target name="compile-tests" depends="compile">
<mkdir dir="${testclassesdir}"></mkdir>
<javac destdir="${testclassesdir}" deprecation="true" debug="true"
optimize="false" excludes="**/package.html">
<src>
<pathelement location="src/test"></pathelement>
</src>
<classpath>
<fileset dir="lib">
<include name="*.jar"></include>
</fileset>
<pathelement path="${classesdir}"></pathelement>
</classpath>
</javac>
</target>
<target name="javadoc" description="o Generate javadoc" depends="jar">
<mkdir dir="${javadocdir}"></mkdir>
<tstamp>
<format pattern="2002-yyyy" property="year"></format>
</tstamp>
<property name="copyright" value="Copyright &copy; Apache Software
Foundation. All Rights Reserved."></property>
<property name="title" value="commons-jelly-tags-jsl 1.0-SNAPSHOT
API"></property>
<javadoc use="true" private="true" destdir="${javadocdir}" author="true"
version="true" sourcepath="src/java"
packagenames="org.apache.commons.jelly.tags.ant.*">
<classpath>
<fileset dir="lib">
<include name="*.jar"></include>
</fileset>
<pathelement location="target/${final.name}.jar"></pathelement>
</classpath>
</javadoc>
</target>
<target name="get-deps" unless="noget" depends="init">
<get dest="lib/commons-jexl-1.0-beta-1.jar" usetimestamp="true"
ignoreerrors="true"
src="http://www.ibiblio.org/maven/commons-jexl/jars/commons-jexl-1.0-beta-1.jar"></get>
<get dest="lib/xml-apis-1.0.b2.jar" usetimestamp="true" ignoreerrors="true"
src="http://www.ibiblio.org/maven/xml-apis/jars/xml-apis-1.0.b2.jar"></get>
<get dest="lib/commons-beanutils-SNAPSHOT.jar" usetimestamp="true"
ignoreerrors="true"
src="http://www.ibiblio.org/maven/commons-beanutils/jars/commons-beanutils-SNAPSHOT.jar"></get>
<get dest="lib/commons-collections-2.1.jar" usetimestamp="true"
ignoreerrors="true"
src="http://www.ibiblio.org/maven/commons-collections/jars/commons-collections-2.1.jar"></get>
<get dest="lib/commons-logging-1.0.jar" usetimestamp="true" ignoreerrors="true"
src="http://www.ibiblio.org/maven/commons-logging/jars/commons-logging-1.0.jar"></get>
<get dest="lib/dom4j-1.4-dev-8.jar" usetimestamp="true" ignoreerrors="true"
src="http://www.ibiblio.org/maven/dom4j/jars/dom4j-1.4-dev-8.jar"></get>
<get dest="lib/jaxp-1.2.jar" usetimestamp="true" ignoreerrors="true"
src="http://www.ibiblio.org/maven/jaxp/jars/jaxp-1.2.jar"></get>
<get dest="lib/xerces-2.2.1.jar" usetimestamp="true" ignoreerrors="true"
src="http://www.ibiblio.org/maven/xerces/jars/xerces-2.2.1.jar"></get>
<get dest="lib/commons-jelly-SNAPSHOT.jar" usetimestamp="true"
ignoreerrors="true"
src="http://www.ibiblio.org/maven/commons-jelly/jars/commons-jelly-SNAPSHOT.jar"></get>
<get dest="lib/commons-jelly-tags-ant-SNAPSHOT.jar" usetimestamp="true"
ignoreerrors="true"
src="http://www.ibiblio.org/maven/commons-jelly/jars/commons-jelly-tags-ant-SNAPSHOT.jar"></get>
<get dest="lib/ant-1.5.1.jar" usetimestamp="true" ignoreerrors="true"
src="http://www.ibiblio.org/maven/ant/jars/ant-1.5.1.jar"></get>
<get dest="lib/ant-optional-1.5.1.jar" usetimestamp="true" ignoreerrors="true"
src="http://www.ibiblio.org/maven/ant/jars/ant-optional-1.5.1.jar"></get>
<get dest="lib/commons-grant-1.0-beta-4.jar" usetimestamp="true"
ignoreerrors="true"
src="http://www.ibiblio.org/maven/commons-grant/jars/commons-grant-1.0-beta-4.jar"></get>
<get dest="lib/junit-3.8.1.jar" usetimestamp="true" ignoreerrors="true"
src="http://www.ibiblio.org/maven/junit/jars/junit-3.8.1.jar"></get>
<get dest="lib/ant-1.5.jar" usetimestamp="true" ignoreerrors="true"
src="http://www.ibiblio.org/maven/ant/jars/ant-1.5.jar"></get>
<get dest="lib/ant-optional-1.5.jar" usetimestamp="true" ignoreerrors="true"
src="http://www.ibiblio.org/maven/ant/jars/ant-optional-1.5.jar"></get>
</target>
<target name="install-maven">
<get dest="${user.home}/maven-install-latest.jar" usetimestamp="true"
src="${maven.repo.remote}/maven/maven-install-latest.jar"></get>
<unjar dest="${maven.home}" src="${user.home}/maven-install-latest.jar"></unjar>
</target>
</project>
1.1
jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/test/org/apache/commons/jelly/tags/fmt/xyz_zh.properties
Index: xyz_zh.properties
===================================================================
# Sample ResourceBundle properties file
123.key1=value1-zh
123.key2=value2-zh
123.key3={0} value3-zh {1}
1.1
jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/test/org/apache/commons/jelly/tags/fmt/suite.jelly
Index: suite.jelly
===================================================================
<?xml version="1.0"?>
<test:suite xmlns:j="jelly:core"
xmlns:fmt="jelly:org.apache.commons.jelly.tags.fmt.FmtTagLibrary"
xmlns:m="jelly:ant"
xmlns:test="jelly:junit"
xmlns:log="jelly:log">
<test:case name="testSimple" xmlns="dummy">
<j:set var="keyvar" value="key2"/>
<fmt:bundle basename="org.apache.commons.jelly.tags.fmt.abc">
<fmt:message key="key1" var="dummyKey1"/>
<fmt:message var="dummyKey2">${keyvar}</fmt:message>
<fmt:message var="dummyKeyInvalid">invalid.key</fmt:message>
</fmt:bundle>
<m:echo>i10n content is </m:echo>
<m:echo>key1: '${dummyKey1}'</m:echo>
<m:echo>key2: '${dummyKey2}'</m:echo>
<m:echo>keyInvalid: '${dummyKeyInvalid}'</m:echo>
<test:assertEquals expected="value1" actual="${dummyKey1}" />
<test:assertEquals expected="value2" actual="${dummyKey2}" />
<test:assertEquals expected="???invalid.key???"
actual="${dummyKeyInvalid}" />
</test:case>
<test:case name="testParam" xmlns="dummy">
<j:set var="keyvar" value="key3"/>
<j:set var="valuevar" value="param1"/>
<fmt:bundle basename="org.apache.commons.jelly.tags.fmt.abc">
<fmt:message var="dummyKey3">${keyvar}<fmt:param
value="${valuevar}"/>
<fmt:param value="param2"/>
</fmt:message>
</fmt:bundle>
<m:echo>i10n content is </m:echo>
<m:echo>key3: '${dummyKey3}'</m:echo>
<test:assertEquals expected="value3 param1 param2"
actual="${dummyKey3}" />
</test:case>
<test:case name="testPrefix" xmlns="dummy">
<fmt:bundle basename="org.apache.commons.jelly.tags.fmt.xyz"
prefix="123.">
<fmt:message key="key1" var="dummyKey1"/>
<fmt:message var="dummyKey2">key2</fmt:message>
<fmt:message var="dummyKeyInvalid">invalid.key</fmt:message>
</fmt:bundle>
<m:echo>i10n content is </m:echo>
<m:echo>key1: '${dummyKey1}'</m:echo>
<m:echo>key2: '${dummyKey2}'</m:echo>
<m:echo>keyInvalid: '${dummyKeyInvalid}'</m:echo>
<test:assertEquals expected="value1" actual="${dummyKey1}" />
<test:assertEquals expected="value2" actual="${dummyKey2}" />
<test:assertEquals expected="???123.invalid.key???"
actual="${dummyKeyInvalid}" />
</test:case>
<test:case name="testSetLocale" xmlns="dummy">
<fmt:setLocale value="zh"/>
<fmt:bundle basename="org.apache.commons.jelly.tags.fmt.xyz"
prefix="123.">
<fmt:message key="key1" var="dummyKey1"/>
<fmt:message var="dummyKey2">key2</fmt:message>
<fmt:message var="dummyKeyInvalid">invalid.key</fmt:message>
</fmt:bundle>
<m:echo>i10n content is </m:echo>
<m:echo>key1: '${dummyKey1}'</m:echo>
<m:echo>key2: '${dummyKey2}'</m:echo>
<m:echo>keyInvalid: '${dummyKeyInvalid}'</m:echo>
<test:assertEquals expected="value1-zh" actual="${dummyKey1}" />
<test:assertEquals expected="value2-zh" actual="${dummyKey2}" />
<test:assertEquals expected="???123.invalid.key???"
actual="${dummyKeyInvalid}" />
</test:case>
</test:suite>
1.1
jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/test/org/apache/commons/jelly/tags/fmt/TestFMTSuite.java
Index: TestFMTSuite.java
===================================================================
/*
*
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/test/org/apache/commons/jelly/tags/fmt/TestFMTSuite.java,v
1.1 2003/01/16 16:21:46 jstrachan Exp
* 1.1
* 2003/01/16 16:21:46
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* TestFMTSuite.java,v 1.1 2003/01/16 16:21:46 jstrachan Exp
*/
package org.apache.commons.jelly.tags.fmt;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import org.apache.commons.jelly.tags.junit.JellyTestSuite;
/**
* A helper class to run jelly test cases as part of Ant's JUnit tests
*
* @author <a href="mailto:[EMAIL PROTECTED]">Willie Vu</a>
* @version 1.1
*/
public class TestFMTSuite extends JellyTestSuite {
public static void main(String[] args) throws Exception {
TestRunner.run(suite());
}
public static TestSuite suite() throws Exception {
return createTestSuite(TestFMTSuite.class, "suite.jelly");
}
}
1.1
jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/test/org/apache/commons/jelly/tags/fmt/abc.properties
Index: abc.properties
===================================================================
# Sample ResourceBundle properties file
key1=value1
key2=value2
key3=value3 {0} {1}
1.1
jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/test/org/apache/commons/jelly/tags/fmt/xyz.properties
Index: xyz.properties
===================================================================
# Sample ResourceBundle properties file
123.key1=value1
123.key2=value2
123.key3=value3 {0} {1}
1.1
jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/java/org/apache/commons/jelly/tags/fmt/BundleTag.java
Index: BundleTag.java
===================================================================
/*
*
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/java/org/apache/commons/jelly/tags/fmt/BundleTag.java,v
1.1 2003/01/16 16:21:46 jstrachan Exp
* 1.1
* 2003/01/16 16:21:46
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* BundleTag.java,v 1.1 2003/01/16 16:21:46 jstrachan Exp
*/
package org.apache.commons.jelly.tags.fmt;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.expression.Expression;
import java.util.Enumeration;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
/**
* Support for tag handlers for <bundle>, the resource bundle loading
* tag in JSTL.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Willie Vu</a>
* @version 1.1
*
* @task decide how to implement setResponseLocale
*/
public class BundleTag extends TagSupport {
//*********************************************************************
// Private constants
private static final Locale EMPTY_LOCALE = new Locale("", "");
//*********************************************************************
// Protected state
private Expression basename; // 'basename' attribute
private Expression prefix; // 'prefix' attribute
/** evaluated basename */
private String ebasename;
/** evaluated prefix */
private String eprefix;
//*********************************************************************
// Private state
private LocalizationContext locCtxt;
//*********************************************************************
// Constructor and initialization
public BundleTag() {
}
//*********************************************************************
// Collaboration with subtags
public LocalizationContext getLocalizationContext() {
return locCtxt;
}
public String getPrefixAsString() {
return eprefix;
}
//*********************************************************************
// Tag logic
/**
* Evaluates this tag after all the tags properties have been initialized.
*
*/
public void doTag(XMLOutput output) throws Exception {
Object basenameInput = null;
if (this.basename != null) {
basenameInput = this.basename.evaluate(context);
}
if (basenameInput != null) {
ebasename = basenameInput.toString();
}
Object prefixInput = null;
if (this.prefix != null) {
prefixInput = this.prefix.evaluate(context);
}
if (prefixInput != null) {
eprefix = prefixInput.toString();
}
this.locCtxt = this.getLocalizationContext(context, ebasename);
invokeBody(output);
}
//*********************************************************************
// Public utility methods
/**
* Gets the default I18N localization context.
*
* @param jc Page in which to look up the default I18N localization context
*/
public static LocalizationContext getLocalizationContext(JellyContext jc) {
LocalizationContext locCtxt = null;
Object obj = jc.getVariable(Config.FMT_LOCALIZATION_CONTEXT);
if (obj == null) {
return null;
}
if (obj instanceof LocalizationContext) {
locCtxt = (LocalizationContext) obj;
} else {
// localization context is a bundle basename
locCtxt = getLocalizationContext(jc, (String) obj);
}
return locCtxt;
}
/**
* Gets the resource bundle with the given base name, whose locale is
* determined as follows:
*
* Check if a match exists between the ordered set of preferred
* locales and the available locales, for the given base name.
* The set of preferred locales consists of a single locale
* (if the <tt>org.apache.commons.jelly.tags.fmt.locale</tt> configuration
* setting is present).
*
* <p> If no match was found in the previous step, check if a match
* exists between the fallback locale (given by the
* <tt>org.apache.commons.jelly.tags.fmt.fallbackLocale</tt> configuration
* setting) and the available locales, for the given base name.
*
* @param pageContext Page in which the resource bundle with the
* given base name is requested
* @param basename Resource bundle base name
*
* @return Localization context containing the resource bundle with the
* given base name and the locale that led to the resource bundle match,
* or the empty localization context if no resource bundle match was found
*/
public static LocalizationContext getLocalizationContext(JellyContext jc,
String basename) {
LocalizationContext locCtxt = null;
ResourceBundle bundle = null;
if ((basename == null) || basename.equals("")) {
return new LocalizationContext();
}
// Try preferred locales
Locale pref = null; {
Object tmp = jc.getVariable(Config.FMT_LOCALE);
if (tmp != null && tmp instanceof Locale) {
pref = (Locale) tmp;
}
}
if (pref != null) {
// Preferred locale is application-based
bundle = findMatch(basename, pref);
if (bundle != null) {
locCtxt = new LocalizationContext(bundle, pref);
}
}
if (locCtxt == null) {
// No match found with preferred locales, try using fallback
locale
{
Object tmp =
jc.getVariable(Config.FMT_FALLBACK_LOCALE);
if (tmp != null && tmp instanceof Locale) {
pref = (Locale) tmp;
}
}
if (pref != null) {
bundle = findMatch(basename, pref);
if (bundle != null) {
locCtxt = new LocalizationContext(bundle,
pref);
}
}
}
if (locCtxt == null) {
// try using the root resource bundle with the given basename
try {
bundle = ResourceBundle.getBundle(basename,
EMPTY_LOCALE,
Thread.currentThread().getContextClassLoader());
if (bundle != null) {
locCtxt = new LocalizationContext(bundle,
null);
}
} catch (MissingResourceException mre) {
// do nothing
}
}
if (locCtxt != null) {
// set response locale
if (locCtxt.getLocale() != null) {
// TODO
// SetLocaleSupport.setResponseLocale(jc,
locCtxt.getLocale());
}
} else {
// create empty localization context
locCtxt = new LocalizationContext();
}
return locCtxt;
}
/*
* Gets the resource bundle with the given base name and preferred locale.
*
* This method calls java.util.ResourceBundle.getBundle(), but ignores
* its return value unless its locale represents an exact or language match
* with the given preferred locale.
*
* @param basename the resource bundle base name
* @param pref the preferred locale
*
* @return the requested resource bundle, or <tt>null</tt> if no resource
* bundle with the given base name exists or if there is no exact- or
* language-match between the preferred locale and the locale of
* the bundle returned by java.util.ResourceBundle.getBundle().
*/
private static ResourceBundle findMatch(String basename, Locale pref) {
ResourceBundle match = null;
try {
ResourceBundle bundle =
ResourceBundle.getBundle(basename, pref,
Thread.currentThread().getContextClassLoader());
Locale avail = bundle.getLocale();
if (pref.equals(avail)) {
// Exact match
match = bundle;
} else {
if (pref.getLanguage().equals(avail.getLanguage())
&& ("".equals(avail.getCountry()))) {
// Language match.
// By making sure the available locale does
not have a
// country and matches the preferred locale's
language, we
// rule out "matches" based on the container's
default
// locale. For example, if the preferred
locale is
// "en-US", the container's default locale is
"en-UK", and
// there is a resource bundle (with the
requested base
// name) available for "en-UK",
ResourceBundle.getBundle()
// will return it, but even though its
language matches
// that of the preferred locale, we must
ignore it,
// because matches based on the container's
default locale
// are not portable across different
containers with
// different default locales.
match = bundle;
}
}
} catch (MissingResourceException mre) {
}
return match;
}
/** Setter for property basename.
* @param basename New value of property basename.
*
*/
public void setBasename(Expression basename) {
this.basename = basename;
}
/** Setter for property prefix.
* @param prefix New value of property prefix.
*
*/
public void setPrefix(Expression prefix) {
this.prefix = prefix;
}
}
1.1
jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/java/org/apache/commons/jelly/tags/fmt/SetLocaleTag.java
Index: SetLocaleTag.java
===================================================================
/*
*
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/java/org/apache/commons/jelly/tags/fmt/SetLocaleTag.java,v
1.1 2003/01/16 16:21:46 jstrachan Exp
* 1.1
* 2003/01/16 16:21:46
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* SetLocaleTag.java,v 1.1 2003/01/16 16:21:46 jstrachan Exp
*/
package org.apache.commons.jelly.tags.fmt;
import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.Tag;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.expression.Expression;
import java.util.Locale;
/**
* Support for tag handlers for <setLocale>, the locale setting
* tag in JSTL.
* @author <a href="mailto:[EMAIL PROTECTED]">Willie Vu</a>
* @version 1.1
*
* @task decide how to implement setResponseLocale
*/
public class SetLocaleTag extends TagSupport {
private static final char HYPHEN = '-';
private static final char UNDERSCORE = '_';
private Expression value;
private Expression variant;
private String scope;
/** Creates a new instance of SetLocaleTag */
public SetLocaleTag() {
}
/**
* Evaluates this tag after all the tags properties have been initialized.
*
*/
public void doTag(XMLOutput output) throws Exception {
Locale locale = null;
Object valueInput = null;
if (this.value != null) {
valueInput = this.value.evaluate(context);
}
Object variantInput = null;
if (this.variant != null) {
variantInput = this.variant.evaluate(context);
}
if (valueInput == null) {
locale = Locale.getDefault();
} else if (valueInput instanceof String) {
if (((String) valueInput).trim().equals("")) {
locale = Locale.getDefault();
} else {
locale = parseLocale((String) valueInput, (String)
variantInput);
}
} else {
locale = (Locale) valueInput;
}
if (scope != null) {
context.setVariable(Config.FMT_LOCALE, scope, locale);
}
else {
context.setVariable(Config.FMT_LOCALE, locale);
}
//setResponseLocale(pageContext, locale);
}
public void setValue(Expression value) {
this.value = value;
}
public void setVariant(Expression variant) {
this.variant = variant;
}
public void setScope(String scope) {
this.scope = scope;
}
//*********************************************************************
// Public utility methods
/**
* See parseLocale(String, String) for details.
*/
public static Locale parseLocale(String locale) {
return parseLocale(locale, null);
}
/**
* Parses the given locale string into its language and (optionally)
* country components, and returns the corresponding
* <tt>java.util.Locale</tt> object.
*
* If the given locale string is null or empty, the runtime's default
* locale is returned.
*
* @param locale the locale string to parse
* @param variant the variant
*
* @return <tt>java.util.Locale</tt> object corresponding to the given
* locale string, or the runtime's default locale if the locale string is
* null or empty
*
* @throws IllegalArgumentException if the given locale does not have a
* language component or has an empty country component
*/
public static Locale parseLocale(String locale, String variant) {
Locale ret = null;
String language = locale;
String country = null;
int index = -1;
if (((index = locale.indexOf(HYPHEN)) > -1)
|| ((index = locale.indexOf(UNDERSCORE)) > -1)) {
language = locale.substring(0, index);
country = locale.substring(index+1);
}
if ((language == null) || (language.length() == 0)) {
throw new IllegalArgumentException("Missing language");
}
if (country == null) {
if (variant != null)
ret = new Locale(language, "", variant);
else
ret = new Locale(language, "");
} else if (country.length() > 0) {
if (variant != null)
ret = new Locale(language, country, variant);
else
ret = new Locale(language, country);
} else {
throw new IllegalArgumentException("Missing country");
}
return ret;
}
}
1.1
jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/java/org/apache/commons/jelly/tags/fmt/ParamTag.java
Index: ParamTag.java
===================================================================
/*
*
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/java/org/apache/commons/jelly/tags/fmt/ParamTag.java,v
1.1 2003/01/16 16:21:46 jstrachan Exp
* 1.1
* 2003/01/16 16:21:46
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ParamTag.java,v 1.1 2003/01/16 16:21:46 jstrachan Exp
*/
package org.apache.commons.jelly.tags.fmt;
import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.Tag;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.expression.Expression;
/**
* Support for tag handlers for <param>, the parameter setting
* tag in JSTL.
* @author <a href="mailto:[EMAIL PROTECTED]">Willie Vu</a>
* @version 1.1
*
* @task handle body content trimming
*/
public class ParamTag extends TagSupport {
/** Holds value of property value. */
private Expression value;
/** Creates a new instance of ParamTag */
public ParamTag() {
}
/**
* Evaluates this tag after all the tags properties have been initialized.
*
*/
public void doTag(XMLOutput output) throws Exception {
MessageTag parent = null;
Tag t = findAncestorWithClass(this, MessageTag.class);
if (t != null) {
parent = (MessageTag) t;
} else {
// must be nested inside a <fmt:message> action.
throw new JellyException("must be nested inside a
<fmt:message> action.");
}
Object valueInput = null;
if (this.value != null) {
valueInput = this.value.evaluate(context);
}
else {
// get value from body
valueInput = getBodyText();
}
parent.addParam(valueInput);
}
/** Setter for property value.
* @param value New value of property value.
*
*/
public void setValue(Expression value) {
this.value = value;
}
}
1.1
jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/java/org/apache/commons/jelly/tags/fmt/MessageTag.java
Index: MessageTag.java
===================================================================
/*
*
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/java/org/apache/commons/jelly/tags/fmt/MessageTag.java,v
1.1 2003/01/16 16:21:46 jstrachan Exp
* 1.1
* 2003/01/16 16:21:46
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* MessageTag.java,v 1.1 2003/01/16 16:21:46 jstrachan Exp
*/
package org.apache.commons.jelly.tags.fmt;
import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.Tag;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.expression.Expression;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
/**
* Support for tag handlers for <message>, the lookup up
* localized message tag in JSTL.
* @author <a href="mailto:[EMAIL PROTECTED]">Willie Vu</a>
* @version 1.1
*
* @task decide how to implement setResponseLocale
* @task handle trimming of key coming from body content
*/
public class MessageTag extends TagSupport {
private static final String UNDEFINED_KEY = "???";
private Expression key;
private Expression bundle;
private LocalizationContext locCtxt;
private String var;
private String scope;
private List params;
/** Creates a new instance of MessageTag */
public MessageTag() {
params = new ArrayList();
}
/**
* Adds an argument (for parametric replacement) to this tag's message.
*/
public void addParam(Object arg) {
params.add(arg);
}
public void doTag(XMLOutput output) throws Exception {
Object keyInput = null;
if (this.key != null) {
keyInput = this.key.evaluate(context);
}
else {
// get key from body
keyInput = getBodyText();
}
if ((keyInput == null) || keyInput.equals("")) {
output.write("??????");
return;
}
Object bundleInput = null;
if (this.bundle != null) {
bundleInput = this.bundle.evaluate(context);
}
if (bundleInput != null && bundleInput instanceof LocalizationContext)
{
locCtxt = (LocalizationContext) bundleInput;
}
String prefix = null;
if (locCtxt == null) {
Tag t = findAncestorWithClass(this, BundleTag.class);
if (t != null) {
// use resource bundle from parent <bundle> tag
BundleTag parent = (BundleTag) t;
locCtxt = parent.getLocalizationContext();
prefix = parent.getPrefixAsString();
} else {
locCtxt = BundleTag.getLocalizationContext(context);
}
} else {
// localization context taken from 'bundle' attribute
if (locCtxt.getLocale() != null) {
// TODO
// SetLocaleSupport.setResponseLocale(pageContext,
// locCtxt.getLocale());
}
}
String message = UNDEFINED_KEY + keyInput + UNDEFINED_KEY;
if (locCtxt != null) {
ResourceBundle bundle = locCtxt.getResourceBundle();
if (bundle != null) {
try {
// prepend 'prefix' attribute from parent
bundle
if (prefix != null) {
keyInput = prefix + keyInput;
}
message =
bundle.getString(keyInput.toString());
// Perform parametric replacement if required
if (!params.isEmpty()) {
Object[] messageArgs =
params.toArray();
MessageFormat formatter = new
MessageFormat("");
if (locCtxt.getLocale() != null) {
formatter.setLocale(locCtxt.getLocale());
}
formatter.applyPattern(message);
message =
formatter.format(messageArgs);
}
} catch (MissingResourceException mre) {
message = UNDEFINED_KEY + keyInput +
UNDEFINED_KEY;
}
}
}
if (scope != null) {
if (var != null) {
context.setVariable(var, scope, message);
}
else {
throw new JellyException( "If 'scope' is specified,
'var' must be defined for this tag" );
}
}
else {
if (var != null) {
context.setVariable(var, message);
}
else {
// write the message
output.write(message);
}
}
}
/** Setter for property key.
* @param key New value of property key.
*
*/
public void setKey(Expression key) {
this.key = key;
}
/** Setter for property bundle.
* @param bundle New value of property bundle.
*
*/
public void setBundle(Expression bundle) {
this.bundle = bundle;
}
/** Setter for property var.
* @param var New value of property var.
*
*/
public void setVar(String var) {
this.var = var;
}
/** Setter for property scope.
* @param scope New value of property scope.
*
*/
public void setScope(String scope) {
this.scope = scope;
}
}
1.1
jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/java/org/apache/commons/jelly/tags/fmt/LocalizationContext.java
Index: LocalizationContext.java
===================================================================
/*
*
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/java/org/apache/commons/jelly/tags/fmt/LocalizationContext.java,v
1.1 2003/01/16 16:21:46 jstrachan Exp
* 1.1
* 2003/01/16 16:21:46
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* LocalizationContext.java,v 1.1 2003/01/16 16:21:46 jstrachan Exp
*/
package org.apache.commons.jelly.tags.fmt;
import java.util.ResourceBundle;
import java.util.Locale;
/**
* Class representing an I18N localization context.
*
* <p> An I18N localization context has two components: a resource bundle and
* the locale that led to the resource bundle match.
*
* <p> The resource bundle component is used by <fmt:message> for mapping
* message keys to localized messages, and the locale component is used by the
* <fmt:message>, <fmt:formatNumber>, <fmt:parseNumber>,
<fmt:formatDate>,
* and <fmt:parseDate> actions as their formatting locale.
*
* @see javax.servlet.jsp.jstl.fmt.LocalizationContext
*
* @author <a href="mailto:[EMAIL PROTECTED]">Willie Vu</a>
* @version 1.1
*/
public class LocalizationContext {
// the localization context's resource bundle
final private ResourceBundle bundle;
// the localization context's locale
final private Locale locale;
/**
* Constructs an empty I18N localization context.
*/
public LocalizationContext() {
bundle = null;
locale = null;
}
/**
* Constructs an I18N localization context from the given resource bundle
* and locale.
*
* <p> The specified locale is the application- or browser-based preferred
* locale that led to the resource bundle match.
*
* @param bundle The localization context's resource bundle
* @param locale The localization context's locale
*/
public LocalizationContext(ResourceBundle bundle, Locale locale) {
this.bundle = bundle;
this.locale = locale;
}
/**
* Constructs an I18N localization context from the given resource bundle.
*
* <p> The localization context's locale is taken from the given
* resource bundle.
*
* @param bundle The resource bundle
*/
public LocalizationContext(ResourceBundle bundle) {
this.bundle = bundle;
this.locale = bundle.getLocale();
}
/**
* Gets the resource bundle of this I18N localization context.
*
* @return The resource bundle of this I18N localization context, or null
* if this I18N localization context is empty
*/
public ResourceBundle getResourceBundle() {
return bundle;
}
/**
* Gets the locale of this I18N localization context.
*
* @return The locale of this I18N localization context, or null if this
* I18N localization context is empty, or its resource bundle is a
* (locale-less) root resource bundle.
*/
public Locale getLocale() {
return locale;
}
}
1.1
jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/java/org/apache/commons/jelly/tags/fmt/FmtTagLibrary.java
Index: FmtTagLibrary.java
===================================================================
/*
*
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/java/org/apache/commons/jelly/tags/fmt/FmtTagLibrary.java,v
1.1 2003/01/16 16:21:46 jstrachan Exp
* 1.1
* 2003/01/16 16:21:46
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* FmtTagLibrary.java,v 1.1 2003/01/16 16:21:46 jstrachan Exp
*/
package org.apache.commons.jelly.tags.fmt;
import org.apache.commons.jelly.TagLibrary;
/** Describes the tag library for tags in JSTL.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Willie Vu</a>
* @version 1.1
*
* @task implement <fmt:setBundle>
* @task implement <fmt:timeZone>
* @task implement <fmt:setTimeZone>
* @task implement <fmt:formatNumber>
* @task implement <fmt:parseNumber>
* @task implement <fmt:formatDate>
* @task implement <fmt:parseDate>
* @task implement <fmt:timeZone>
* @task decide how to support <fmt:requestEncoding>
*/
public class FmtTagLibrary extends TagLibrary {
/** Creates a new instance of FmtTagLibrary */
public FmtTagLibrary() {
registerTag("bundle", BundleTag.class);
registerTag("message", MessageTag.class);
registerTag("param", ParamTag.class);
registerTag("setLocale", SetLocaleTag.class);
}
}
1.1
jakarta-commons-sandbox/jelly/jelly-tags/fmt/src/java/org/apache/commons/jelly/tags/fmt/Config.java
Index: Config.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.jelly.tags.fmt;
import org.apache.commons.jelly.JellyContext;
/**
* Class supporting access to configuration data.
* @author <a href="mailto:[EMAIL PROTECTED]">Willie Vu</a>
* @version 1.1
*/
public class Config {
/*
* I18N/Formatting actions related configuration data
*/
/**
* Name of configuration setting for application- (as opposed to browser-)
* based preferred locale
*/
public static final String FMT_LOCALE
= "org.apache.commons.jelly.tags.fmt.locale";
/**
* Name of configuration setting for fallback locale
*/
public static final String FMT_FALLBACK_LOCALE
= "org.apache.commons.jelly.tags.fmt.fallbackLocale";
/**
* Name of configuration setting for i18n localization context
*/
public static final String FMT_LOCALIZATION_CONTEXT
= "org.apache.commons.jelly.tags.fmt.localizationContext";
/**
* Name of localization setting for time zone
*/
public static final String FMT_TIME_ZONE
= "org.apache.commons.jelly.tags.fmt.timeZone";
/**
* Looks up a configuration variable in the given scope.
*
* <p> The lookup of configuration variables is performed as if each scope
* had its own name space, that is, the same configuration variable name
* in one scope does not replace one stored in a different scope.
*
* @param jc Page context in which the configuration variable is to be
* looked up
* @param name Configuration variable name
* @param scope Scope in which the configuration variable is to be looked
* up
*
* @return The <tt>java.lang.Object</tt> associated with the configuration
* variable, or null if it is not defined.
*/
// public static Object get(JellyContext jc, String name, int scope) {
// switch (scope) {
// case JellyContext.PAGE_SCOPE:
// return jc.getAttribute(name + PAGE_SCOPE_SUFFIX,
scope);
// case JellyContext.REQUEST_SCOPE:
// return jc.getAttribute(name + REQUEST_SCOPE_SUFFIX,
scope);
// case JellyContext.SESSION_SCOPE:
// return jc.getAttribute(name + SESSION_SCOPE_SUFFIX,
scope);
// case JellyContext.APPLICATION_SCOPE:
// return jc.getAttribute(name +
APPLICATION_SCOPE_SUFFIX, scope);
// default:
// throw new IllegalArgumentException("unknown scope");
// }
// }
/**
* Looks up a configuration variable in the "request" scope.
*
* <p> The lookup of configuration variables is performed as if each scope
* had its own name space, that is, the same configuration variable name
* in one scope does not replace one stored in a different scope.
*
* @param request Request object in which the configuration variable is to
* be looked up
* @param name Configuration variable name
*
* @return The <tt>java.lang.Object</tt> associated with the configuration
* variable, or null if it is not defined.
*/
// public static Object get(ServletRequest request, String name) {
// return request.getAttribute(name + REQUEST_SCOPE_SUFFIX);
// }
/**
* Looks up a configuration variable in the "session" scope.
*
* <p> The lookup of configuration variables is performed as if each scope
* had its own name space, that is, the same configuration variable name
* in one scope does not replace one stored in a different scope.
*
* @param session Session object in which the configuration variable is to
* be looked up
* @param name Configuration variable name
*
* @return The <tt>java.lang.Object</tt> associated with the configuration
* variable, or null if it is not defined.
*/
// public static Object get(HttpSession session, String name) {
// return session.getAttribute(name + SESSION_SCOPE_SUFFIX);
// }
/**
* Looks up a configuration variable in the "application" scope.
*
* <p> The lookup of configuration variables is performed as if each scope
* had its own name space, that is, the same configuration variable name
* in one scope does not replace one stored in a different scope.
*
* @param context Servlet context in which the configuration variable is
* to be looked up
* @param name Configuration variable name
*
* @return The <tt>java.lang.Object</tt> associated with the configuration
* variable, or null if it is not defined.
*/
// public static Object get(ServletContext context, String name) {
// return context.getAttribute(name + APPLICATION_SCOPE_SUFFIX);
// }
/**
* Sets the value of a configuration variable in the given scope.
*
* <p> Setting the value of a configuration variable is performed as if
* each scope had its own namespace, that is, the same configuration
* variable name in one scope does not replace one stored in a different
* scope.
*
* @param jc Page context in which the configuration variable is to be set
* @param name Configuration variable name
* @param value Configuration variable value
* @param scope Scope in which the configuration variable is to be set
*/
// public static void set(JellyContext jc, String name, Object value,
// int scope) {
// switch (scope) {
// case JellyContext.PAGE_SCOPE:
// jc.setAttribute(name + PAGE_SCOPE_SUFFIX, value,
scope);
// break;
// case JellyContext.REQUEST_SCOPE:
// jc.setAttribute(name + REQUEST_SCOPE_SUFFIX, value,
scope);
// break;
// case JellyContext.SESSION_SCOPE:
// jc.setAttribute(name + SESSION_SCOPE_SUFFIX, value,
scope);
// break;
// case JellyContext.APPLICATION_SCOPE:
// jc.setAttribute(name + APPLICATION_SCOPE_SUFFIX,
value, scope);
// break;
// default:
// throw new IllegalArgumentException("unknown scope");
// }
// }
/**
* Sets the value of a configuration variable in the "request" scope.
*
* <p> Setting the value of a configuration variable is performed as if
* each scope had its own namespace, that is, the same configuration
* variable name in one scope does not replace one stored in a different
* scope.
*
* @param request Request object in which the configuration variable is to
* be set
* @param name Configuration variable name
* @param value Configuration variable value
*/
// public static void set(ServletRequest request, String name, Object value) {
// request.setAttribute(name + REQUEST_SCOPE_SUFFIX, value);
// }
/**
* Sets the value of a configuration variable in the "session" scope.
*
* <p> Setting the value of a configuration variable is performed as if
* each scope had its own namespace, that is, the same configuration
* variable name in one scope does not replace one stored in a different
* scope.
*
* @param session Session object in which the configuration variable is to
* be set
* @param name Configuration variable name
* @param value Configuration variable value
*/
// public static void set(HttpSession session, String name, Object value) {
// session.setAttribute(name + SESSION_SCOPE_SUFFIX, value);
// }
/**
* Sets the value of a configuration variable in the "application" scope.
*
* <p> Setting the value of a configuration variable is performed as if
* each scope had its own namespace, that is, the same configuration
* variable name in one scope does not replace one stored in a different
* scope.
*
* @param context Servlet context in which the configuration variable is to
* be set
* @param name Configuration variable name
* @param value Configuration variable value
*/
// public static void set(ServletContext context, String name, Object value) {
// context.setAttribute(name + APPLICATION_SCOPE_SUFFIX, value);
// }
/**
* Removes a configuration variable from the given scope.
*
* <p> Removing a configuration variable is performed as if each scope had
* its own namespace, that is, the same configuration variable name in one
* scope does not impact one stored in a different scope.
*
* @param jc Page context from which the configuration variable is to be
* removed
* @param name Configuration variable name
* @param scope Scope from which the configuration variable is to be
* removed
*/
// public static void remove(JellyContext jc, String name, int scope) {
// switch (scope) {
// case JellyContext.PAGE_SCOPE:
// jc.removeAttribute(name + PAGE_SCOPE_SUFFIX, scope);
// break;
// case JellyContext.REQUEST_SCOPE:
// jc.removeAttribute(name + REQUEST_SCOPE_SUFFIX, scope);
// break;
// case JellyContext.SESSION_SCOPE:
// jc.removeAttribute(name + SESSION_SCOPE_SUFFIX, scope);
// break;
// case JellyContext.APPLICATION_SCOPE:
// jc.removeAttribute(name + APPLICATION_SCOPE_SUFFIX,
scope);
// break;
// default:
// throw new IllegalArgumentException("unknown scope");
// }
// }
/**
* Removes a configuration variable from the "request" scope.
*
* <p> Removing a configuration variable is performed as if each scope had
* its own namespace, that is, the same configuration variable name in one
* scope does not impact one stored in a different scope.
*
* @param request Request object from which the configuration variable is
* to be removed
* @param name Configuration variable name
*/
// public static void remove(ServletRequest request, String name) {
// request.removeAttribute(name + REQUEST_SCOPE_SUFFIX);
// }
/**
* Removes a configuration variable from the "session" scope.
*
* <p> Removing a configuration variable is performed as if each scope had
* its own namespace, that is, the same configuration variable name in one
* scope does not impact one stored in a different scope.
*
* @param session Session object from which the configuration variable is
* to be removed
* @param name Configuration variable name
*/
// public static void remove(HttpSession session, String name) {
// session.removeAttribute(name + SESSION_SCOPE_SUFFIX);
// }
/**
* Removes a configuration variable from the "application" scope.
*
* <p> Removing a configuration variable is performed as if each scope had
* its own namespace, that is, the same configuration variable name in one
* scope does not impact one stored in a different scope.
*
* @param context Servlet context from which the configuration variable is
* to be removed
* @param name Configuration variable name
*/
// public static void remove(ServletContext context, String name) {
// context.removeAttribute(name + APPLICATION_SCOPE_SUFFIX);
// }
/**
* Finds the value associated with a specific configuration setting
* identified by its context initialization parameter name.
*
* <p> For each of the JSP scopes (page, request, session, application),
* get the value of the configuration variable identified by <tt>name</tt>
* using method <tt>get()</tt>. Return as soon as a non-null value is
* found. If no value is found, get the value of the context initialization
* parameter identified by <tt>name</tt>.
*
* @param jc Page context in which the configuration setting is to be
* searched
* @param name Context initialization parameter name of the configuration
* setting
*
* @return The <tt>java.lang.Object</tt> associated with the configuration
* setting identified by <tt>name</tt>, or null if it is not defined.
*/
// public static Object find(JellyContext jc, String name) {
// Object ret = jc.getVariable(name, JellyContext.PAGE_SCOPE);
// if (ret == null) {
// ret = get(jc, name, JellyContext.REQUEST_SCOPE);
// if (ret == null) {
// if (jc.getSession() != null) {
// // check session only if a session is present
// ret = get(jc, name,
JellyContext.SESSION_SCOPE);
// }
// if (ret == null) {
// ret = get(jc, name,
JellyContext.APPLICATION_SCOPE);
// if (ret == null) {
// ret =
jc.getServletContext().getInitParameter(name);
// }
// }
// }
// }
//
// return ret;
// }
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>