commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmitch...@apache.org
Subject svn commit: r161905 - jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl
Date Tue, 19 Apr 2005 15:38:43 GMT
Author: jmitchell
Date: Tue Apr 19 08:38:42 2005
New Revision: 161905

URL: http://svn.apache.org/viewcvs?view=rev&rev=161905
Log:
 * Add new base class WebappResourcesFactoryBase for easier instanceof condition where an
impl might not be part of this distribution, but relies on being handed the servletContext.
 * Pull servletContext and accessors up to WebappResourcesFactoryBase.
 * Add extra options for loading files if the resource was not found via servletContext.getResourceAsStream()

  


Added:
    jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappResourcesFactoryBase.java
  (with props)
Modified:
    jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappPropertyResources.java
    jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappPropertyResourcesFactory.java
    jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappXMLResourcesFactory.java

Modified: jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappPropertyResources.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappPropertyResources.java?view=diff&r1=161904&r2=161905
==============================================================================
--- jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappPropertyResources.java
(original)
+++ jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappPropertyResources.java
Tue Apr 19 08:38:42 2005
@@ -126,7 +126,9 @@
         }
 
         Properties props = new Properties();
-        String name = baseUrl + getLocaleSuffix(locale) + ".properties";
+        String name = baseUrl.replace('.', '/');
+        name += getLocaleSuffix(locale) + ".properties";
+        
         InputStream stream = null;
 
         try {
@@ -135,8 +137,22 @@
             if (log.isTraceEnabled()) {
                 log.trace("Complete path is '" + name + "'");
             }
-            stream = servletContext.getResourceAsStream(name);
-
+            try{
+                stream = servletContext.getResourceAsStream(name);
+            }
+            catch(Exception e){
+                // not found
+                // try ContextClassLoader
+            }
+            if (stream == null){
+                
+                ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+                if (classLoader == null) {
+                    classLoader = this.getClass().getClassLoader();
+                }
+                stream = classLoader.getResourceAsStream(name);
+            }
+            
             // Parse the input stream and populate the name-value mappings map
             if (stream != null) {
                 if (log.isTraceEnabled()) {

Modified: jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappPropertyResourcesFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappPropertyResourcesFactory.java?view=diff&r1=161904&r2=161905
==============================================================================
--- jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappPropertyResourcesFactory.java
(original)
+++ jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappPropertyResourcesFactory.java
Tue Apr 19 08:38:42 2005
@@ -47,13 +47,7 @@
  * default resources would be stored in
  * <code>/WEB-INF/resources/MyResources.properties</code>.</p>
  */
-public class WebappPropertyResourcesFactory extends ResourcesFactoryBase {
-
-    /**
-     * <p>The <code>ServletContext</code> instance for resolving
-     * our resources references.</p>
-     */
-    private ServletContext servletContext = null;
+public class WebappPropertyResourcesFactory extends WebappResourcesFactoryBase {
 
     /**
      * <p>Return the <code>ServletContext</code> instance for

Added: jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappResourcesFactoryBase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappResourcesFactoryBase.java?view=auto&rev=161905
==============================================================================
--- jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappResourcesFactoryBase.java
(added)
+++ jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappResourcesFactoryBase.java
Tue Apr 19 08:38:42 2005
@@ -0,0 +1,50 @@
+/*
+ * $Id$ 
+ *
+ * Copyright 2000-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.commons.resources.impl;
+
+import javax.servlet.ServletContext;
+
+public abstract class WebappResourcesFactoryBase extends ResourcesFactoryBase {
+
+    /**
+     * <p>The <code>ServletContext</code> instance for resolving
+     * our resources references.</p>
+     */
+    protected ServletContext servletContext = null;
+
+    /**
+     * <p>Return the <code>ServletContext</code> instance for
+     * resolving our resources references.</p>
+     */
+    public ServletContext getServletContext() {
+    
+        return (this.servletContext);
+    
+    }
+
+    /**
+     * <p>Set the <code>ServletContext</code> instance for
+     * resolving our resources references.</p>
+     */
+    public void setServletContext(ServletContext servletContext) {
+    
+        this.servletContext = servletContext;
+    
+    }
+
+}

Propchange: jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappResourcesFactoryBase.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappXMLResourcesFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappXMLResourcesFactory.java?view=diff&r1=161904&r2=161905
==============================================================================
--- jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappXMLResourcesFactory.java
(original)
+++ jakarta/commons/proper/resources/trunk/src/java/org/apache/commons/resources/impl/WebappXMLResourcesFactory.java
Tue Apr 19 08:38:42 2005
@@ -23,7 +23,6 @@
 
 package org.apache.commons.resources.impl;
 
-import javax.servlet.ServletContext;
 
 import org.apache.commons.resources.Resources;
 import org.apache.commons.resources.ResourcesException;
@@ -47,38 +46,7 @@
  * resources would be stored in
  * <code>/WEB-INF/resources/MyResources.xml</code>.</p>
  */
-public class WebappXMLResourcesFactory extends ResourcesFactoryBase {
-
-    /**
-     * <p>The <code>ServletContext</code> instance for resolving
-     * our resources references.</p>
-     */
-    private ServletContext servletContext = null;
-
-    /**
-     * <p>Return the <code>ServletContext</code> instance for
-     * resolving our resources references.</p>
-     */
-    public ServletContext getServletContext() {
-
-        return (this.servletContext);
-
-    }
-
-
-    /**
-     * <p>Set the <code>ServletContext</code> instance for
-     * resolving our resources references.</p>
-     */
-    public void setServletContext(ServletContext servletContext) {
-
-        this.servletContext = servletContext;
-
-    }
-
-
-    // ------------------------------------------------------ Protected Methods
-
+public class WebappXMLResourcesFactory extends WebappResourcesFactoryBase {
 
     /**
      * <p>Create and return a new {@link org.apache.commons.resources.Resources} instance
with the



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message