Author: jmitchell
Date: Tue Apr 19 10:56:57 2005
New Revision: 161936
URL: http://svn.apache.org/viewcvs?view=rev&rev=161936
Log:
initial check in of a new MessageResources subclass and plugin that uses the
subclass to wrap a configured instance of a Resources from commons-resources
Added:
struts/plugins/trunk/resources/README.txt (with props)
struts/plugins/trunk/resources/project.properties (with props)
struts/plugins/trunk/resources/project.xml (with props)
struts/plugins/trunk/resources/src/
struts/plugins/trunk/resources/src/conf/
struts/plugins/trunk/resources/src/java/
struts/plugins/trunk/resources/src/java/org/
struts/plugins/trunk/resources/src/java/org/apache/
struts/plugins/trunk/resources/src/java/org/apache/struts/
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/CommonsResources.java
(with props)
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/CommonsResourcesFactory.java
(with props)
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/ResourcesPlugin.java
(with props)
struts/plugins/trunk/resources/src/test/
struts/plugins/trunk/resources/src/test/org/
struts/plugins/trunk/resources/src/test/org/apache/
struts/plugins/trunk/resources/src/test/org/apache/struts/
struts/plugins/trunk/resources/src/test/org/apache/struts/plugins/
struts/plugins/trunk/resources/src/test/org/apache/struts/plugins/resources/
Added: struts/plugins/trunk/resources/README.txt
URL:
http://svn.apache.org/viewcvs/struts/plugins/trunk/resources/README.txt?view=auto&rev=161936
==============================================================================
--- struts/plugins/trunk/resources/README.txt (added)
+++ struts/plugins/trunk/resources/README.txt Tue Apr 19 10:56:57 2005
@@ -0,0 +1,104 @@
+
+ This project provides:
+ - alternate implementation of org.apache.struts.util.MessageResources
(and factory)
+ - Struts plugin that configures the specified subclass of
+ org.apache.struts.plugins.resources.CommonsResources (and factory)
+
+ See the user documentation for further details about commons-resources
beyond
+ what is provided here as a Plugin and Wrapper.
+
+ The Resources plugin provides a configured MessageResources impl "as if"
it
+ was specified above as a <message-resource ...
+
+ Available Properties and defaults:
+
+ Property Description Default
+ strutsPluginFactoryClass The factory class used to
org.apache.struts.plugins.resources.CommonsResourcesFactory
+ configure this Module.
+
+ implFactoryClass The Jakarta Commons
org.apache.commons.resources.impl.WebappPropertyResourcesFactory
+ Resources Factory to use.
+
+ implClass The Jakarta Commons
org.apache.commons.resources.impl.WebappPropertyResources
+ Resources implementaion
+ to use.
+
+ bundle The properties file to (bundle is required)
+ load.
+
+ returnNull Determines whether a null false
+ is returned if the
+ specified key is not found
+
+ key Used in combination with null (not needed if
null)
+ Struts internal constant
+ (Globals.MESSAGE_KEY) to
+ store the configured
+ MessageResources in the
+ ServletContext
+
+
+
+ Q. Why would I use this instead of the above?
+ A. Because with an overridden Factory and plugin of your own,
+ you can easily customize the default behaviour and unlike
+ the above, you will have direct access to the ActionServlet.
+
+
+
+ Below is an example of how to use this plugin with your Struts 1.1
+ implementation.
+
+
+ in your struts-config.xml....
+
+ (Note - the below is a direct copy from the modified struts-example.war
+ that demonstrates this plugin in action)
+
+...
+...
+ <!-- ========== Message Resources Definitions =========================== -->
+
+<!-- shown here using a subclass of MessageResources -->
+ <message-resources
+ factory="org.apache.struts.plugins.resources.CommonsResourcesFactory"
+ parameter="org.apache.struts.webapp.example.ApplicationResources"/>
+
+ <message-resources
+ factory="org.apache.struts.plugins.resources.CommonsResourcesFactory"
+ parameter="org.apache.struts.webapp.example.AlternateApplicationResources"
+ key="alternate"/>
+
+...
+
+
+
+(below is how you might do this with the plugin)
+
+ NOTE - the same rule applies where if you define multiple message-resources,
+ you must provide a unique key attribute or the later will overwrite
+ the former
+
+...
+ <!-- ========== Plug Ins Configuration ================================== -->
+...
+...
+ <plug-in className="org.apache.struts.plugins.resources.ResourcesPlugin">
+ <set-property property="bundle"
+ value="org.apache.struts.webapp.example.ApplicationResources"/>
+ </plug-in>
+
+ <plug-in className="org.apache.struts.plugins.resources.ResourcesPlugin">
+ <set-property property="strutsPluginFactoryClass"
+ value="org.apache.struts.plugins.resources.CommonsResourcesFactory"/>
+ <set-property property="implFactoryClass"
+
value="org.apache.commons.resources.impl.WebappPropertyResourcesFactory"/>
+ <set-property property="implClass"
+ value="org.apache.commons.resources.impl.WebappPropertyResources"/>
+ <set-property property="key"
+ value="alternate"/>
+ <set-property property="bundle"
+ value="org.apache.struts.webapp.example.AlternateApplicationResources"/>
+ </plug-in>
+...
+...
\ No newline at end of file
Propchange: struts/plugins/trunk/resources/README.txt
------------------------------------------------------------------------------
svn:executable = *
Added: struts/plugins/trunk/resources/project.properties
URL:
http://svn.apache.org/viewcvs/struts/plugins/trunk/resources/project.properties?view=auto&rev=161936
==============================================================================
--- struts/plugins/trunk/resources/project.properties (added)
+++ struts/plugins/trunk/resources/project.properties Tue Apr 19 10:56:57 2005
@@ -0,0 +1,18 @@
+# -------------------------------------------------------------------
+# Copyright 2001-2004 The Apache Software Foundation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# -------------------------------------------------------------------
+
+maven.changelog.factory = org.apache.maven.svnlib.SvnChangeLogFactory
+
Propchange: struts/plugins/trunk/resources/project.properties
------------------------------------------------------------------------------
svn:executable = *
Added: struts/plugins/trunk/resources/project.xml
URL:
http://svn.apache.org/viewcvs/struts/plugins/trunk/resources/project.xml?view=auto&rev=161936
==============================================================================
--- struts/plugins/trunk/resources/project.xml (added)
+++ struts/plugins/trunk/resources/project.xml Tue Apr 19 10:56:57 2005
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<project>
+<!--
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ -->
+
+
+ <extend>build/project.xml</extend>
+ <id>struts-resources-plugin</id>
+
+ <name>Struts Resources Plugin</name>
+
+ <package>org.apache.struts.plugins.resources</package>
+
+ <!-- ################################################################ -->
+ <!-- Project management section -->
+ <!-- ################################################################ -->
+
+
+ <shortDescription>
+ Plugin for providing MessageResources via commons-resources.
+ </shortDescription>
+
+ <description>
+ The Resources plugin allows any Struts-based web application (Struts
version 1.1 and higher)
+ to integrate their existing app with
+ commons-resources (http://jakarta.apache.org/commons/resources/).
+
+ </description>
+ <repository>
+
<connection>scm|svn|http|//svn.apache.org/repos/asf/struts/plugins/trunk</connection>
+
<developerConnection>scm|svn|https|//svn.apache.org/repos/asf/struts/plugins/trunk</developerConnection>
+ <url>http://svn.apache.org/repos/asf/struts/plugins/trunk</url>
+ </repository>
+
+ <versions />
+
+ <developers/>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>struts</groupId>
+ <artifactId>struts-core</artifactId>
+ <version>1.3.0-dev</version>
+ <properties>
+ <war.bundle>true</war.bundle>
+ <cactus.bundle>true</cactus.bundle>
+ </properties>
+ <url>http://struts.apache.org/</url>
+ </dependency>
+
+ </dependencies>
+
+
+
+</project>
Propchange: struts/plugins/trunk/resources/project.xml
------------------------------------------------------------------------------
svn:executable = *
Added:
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/CommonsResources.java
URL:
http://svn.apache.org/viewcvs/struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/CommonsResources.java?view=auto&rev=161936
==============================================================================
---
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/CommonsResources.java
(added)
+++
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/CommonsResources.java
Tue Apr 19 10:56:57 2005
@@ -0,0 +1,98 @@
+/*
+ * $Id$
+ *
+ * Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts.plugins.resources;
+
+import java.util.Locale;
+
+import javax.servlet.ServletContext;
+
+import org.apache.commons.resources.Resources;
+import org.apache.commons.resources.ResourcesFactory;
+import org.apache.commons.resources.impl.WebappResourcesFactoryBase;
+import org.apache.struts.util.MessageResources;
+import org.apache.struts.util.MessageResourcesFactory;
+import org.apache.struts.util.RequestUtils;
+
+/**
+ * Concrete subclass of <code>MessageResources</code> that wraps an
+ * instance of an impl of the supplied
+ * <code>org.apache.commons.resources.Resources</code> interface.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CommonsResources extends MessageResources{
+
+ protected Resources resources;
+
+ /**
+ * The default Locale for our environment.
+ */
+ protected Locale defaultLocale = Locale.getDefault();
+
+
+ public CommonsResources(MessageResourcesFactory factory,
+ ServletContext servletContext,
+ String implFactoryClass, String resourcesImpl,
+ String config, boolean returnNull) throws Exception{
+ super(factory, config, returnNull);
+
+ try {
+ ResourcesFactory commonsFactory =
+
(ResourcesFactory)RequestUtils.applicationInstance(implFactoryClass);
+ if (commonsFactory instanceof WebappResourcesFactoryBase) {
+ WebappResourcesFactoryBase factoryBase =
(WebappResourcesFactoryBase) commonsFactory;
+ factoryBase.setServletContext(servletContext);
+ }
+ resources = commonsFactory.getResources(resourcesImpl, config);
+
+ } catch (Exception e) {
+ // log output
+ log.debug(e.getMessage());
+ throw e;
+ }
+ }
+
+ public CommonsResources(MessageResourcesFactory factory,
+ String config, boolean returnNull) {
+
+ super(factory, config, returnNull);
+
+ }
+
+ public CommonsResources(MessageResourcesFactory factory,
+ String config) {
+
+ super(factory, config);
+
+ }
+
+ public String getMessage(Locale locale, String key) {
+
+ // explicitly clear the cached on each call
+ // we will cache them down in the impl
+ // such that any subclass may provide it's
+ // own reload capabilities
+ formats.clear();
+ return resources.getString(key, locale, null);
+
+
+ }
+
+
+
+}
Propchange:
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/CommonsResources.java
------------------------------------------------------------------------------
svn:executable = *
Added:
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/CommonsResourcesFactory.java
URL:
http://svn.apache.org/viewcvs/struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/CommonsResourcesFactory.java?view=auto&rev=161936
==============================================================================
---
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/CommonsResourcesFactory.java
(added)
+++
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/CommonsResourcesFactory.java
Tue Apr 19 10:56:57 2005
@@ -0,0 +1,63 @@
+/*
+ * $Id$
+ *
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.struts.plugins.resources;
+
+import javax.servlet.ServletContext;
+
+import org.apache.struts.util.MessageResources;
+import org.apache.struts.util.MessageResourcesFactory;
+
+
+/**
+ * Factory for <code>CommonsResources</code> instances. The
+ * configuration paramter for such instances is the base Java package
+ * name of the resources entries from which our keys and values will be
+ * loaded.
+ *
+ * @version $Rev$ $Date$
+ */
+
+public class CommonsResourcesFactory extends MessageResourcesFactory {
+
+
+ // --------------------------------------------------------- Public Methods
+
+
+ /**
+ * Create and return a newly instansiated <code>MessageResources</code>.
+ * This method must be implemented by concrete subclasses.
+ *
+ * @param config Configuration parameter(s) for the requested bundle
+ */
+ public MessageResources createResources(String config) {
+
+ return new CommonsResources(this, config, this.returnNull);
+
+ }
+
+ public MessageResources createResources(ServletContext servletContext,
+ String implFactoryClass, String resourcesImpl, String config)
throws Exception {
+
+ return new CommonsResources(this, servletContext, implFactoryClass,
resourcesImpl,
+ config, this.returnNull);
+
+ }
+
+
+}
Propchange:
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/CommonsResourcesFactory.java
------------------------------------------------------------------------------
svn:executable = *
Added:
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/ResourcesPlugin.java
URL:
http://svn.apache.org/viewcvs/struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/ResourcesPlugin.java?view=auto&rev=161936
==============================================================================
---
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/ResourcesPlugin.java
(added)
+++
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/ResourcesPlugin.java
Tue Apr 19 10:56:57 2005
@@ -0,0 +1,181 @@
+/*
+ * $Id$
+ *
+ * Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.struts.plugins.resources;
+
+import java.io.DataInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts.Globals;
+import org.apache.struts.action.ActionServlet;
+import org.apache.struts.action.PlugIn;
+import org.apache.struts.config.ModuleConfig;
+import org.apache.struts.util.MessageResources;
+import org.apache.struts.util.MessageResourcesFactory;
+
+
+/**
+ * <p>An implementation of <code>PlugIn</code> which
+ * can be configured to override the default Struts
+ * MessageResources implementation.
+ *
+ * This plugin was created after Struts 1.1, but is
+ * compatible with Struts 1.1 and Struts 1.2.
+ *
+ * @version $Rev$
+ * @see org.apache.struts.action.PlugIn
+ * @since Struts 1.2
+ */
+public class ResourcesPlugin implements PlugIn{
+
+ private static final Log log = LogFactory.getLog(ResourcesPlugin.class);
+
+ protected ActionServlet servlet = null;
+
+ protected ModuleConfig moduleConfig = null;
+
+ private String strutsPluginFactoryClass =
+ "org.apache.struts.plugins.resources.CommonsResourcesFactory";
+
+ private String implFactoryClass =
+ "org.apache.commons.resources.impl.WebappPropertyResourcesFactory";
+
+ private String implClass =
+ "org.apache.commons.resources.impl.WebappPropertyResources";
+
+ private String bundle;
+
+ private String key;
+
+ private boolean returnNull = false;
+
+
+ public boolean isReturnNull() {
+ return this.returnNull;
+ }
+
+
+ public void setReturnNull(boolean returnNull) {
+ this.returnNull = returnNull;
+ }
+
+
+ public void init(ActionServlet servlet, ModuleConfig config) {
+
+ this.servlet = servlet;
+ this.moduleConfig = config;
+
+ MessageResourcesFactory.setFactoryClass(this.strutsPluginFactoryClass);
+ MessageResourcesFactory factoryObject =
+ MessageResourcesFactory.createFactory();
+
+ MessageResources resources = null;
+ if (factoryObject instanceof CommonsResourcesFactory) {
+ CommonsResourcesFactory fctry =
+ (CommonsResourcesFactory) factoryObject;
+ try {
+ resources = fctry.createResources(servlet.getServletContext(),
+ this.implFactoryClass, this.implClass, bundle);
+ } catch (Exception e) {
+ // log output
+ log.debug(e.getMessage());
+ e.printStackTrace();
+ }
+ }else{
+ resources =
+ factoryObject.createResources(this.bundle);
+ }
+ resources.setReturnNull(this.returnNull);
+
+ String bundleKey = this.key;
+ bundleKey = (bundleKey == null ? "" : bundleKey);
+ String k = bundleKey + config.getPrefix();
+ if ("".equals(k))
+ k = Globals.MESSAGES_KEY;
+
+ servlet.getServletContext().setAttribute(k, resources);
+
+ }
+
+ public void destroy() {
+ this.servlet = null;
+ this.moduleConfig = null;
+ }
+
+ public String getImplFactoryClass() {
+ return this.implFactoryClass;
+ }
+
+
+ public void setImplFactoryClass(String implFactoryClass) {
+ this.implFactoryClass = implFactoryClass;
+ }
+
+
+ public String getStrutsPluginFactoryClass() {
+ return this.strutsPluginFactoryClass;
+ }
+
+
+ public void setStrutsPluginFactoryClass(String strutsPluginFactoryClass) {
+ this.strutsPluginFactoryClass = strutsPluginFactoryClass;
+ }
+
+
+ public String getBundle() {
+ return this.bundle;
+ }
+
+
+
+ public void setBundle(String bundle) {
+ this.bundle = bundle;
+ }
+
+
+
+ public String getKey() {
+ return this.key;
+ }
+
+
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+
+ public String getImplClass() {
+ return this.implClass;
+ }
+
+
+
+ public void setImplClass(String implClass) {
+ this.implClass = implClass;
+ }
+
+
+
+
+}
Propchange:
struts/plugins/trunk/resources/src/java/org/apache/struts/plugins/resources/ResourcesPlugin.java
------------------------------------------------------------------------------
svn:executable = *
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]