You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by bl...@apache.org on 2005/09/30 17:29:18 UTC

svn commit: r292770 - in /cocoon/trunk/src/java/org/apache/cocoon/i18n: XMLResourceBundleFactory.java XMLResourceBundleNotFoundException.java

Author: bloritsch
Date: Fri Sep 30 08:29:15 2005
New Revision: 292770

URL: http://svn.apache.org/viewcvs?rev=292770&view=rev
Log:
update XMLResourceBundle, and hopefully avoid a possible memory leak

Added:
    cocoon/trunk/src/java/org/apache/cocoon/i18n/XMLResourceBundleNotFoundException.java
Modified:
    cocoon/trunk/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java

Modified: cocoon/trunk/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java?rev=292770&r1=292769&r2=292770&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java Fri Sep 30 08:29:15 2005
@@ -22,7 +22,6 @@
 import java.util.Locale;
 import java.util.Map;
 
-import org.apache.avalon.framework.CascadingRuntimeException;
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
@@ -371,10 +370,11 @@
     protected String getFileName(String base, String name, Locale locale) {
         StringBuffer sb = new StringBuffer();
         if (base == null || base.length() == 0) {
-            // FIXME (SW): can this happen?
+            throw new IllegalArgumentException("'base' cannot be empty or null.");
         } else {
+	    Source src = null;
             try {
-                Source src = this.resolver.resolveURI(base);
+                src = this.resolver.resolveURI(base);
                 String uri = src.getURI();
                 sb.append(uri);
                 if (!uri.endsWith("/")) {
@@ -382,7 +382,9 @@
                 }
                 this.resolver.release(src);
             } catch(IOException ioe) {
-                throw new CascadingRuntimeException("Cannot resolve " + base, ioe);
+                throw new XMLResourceBundleNotFoundException("Cannot resolve " + base, ioe);
+            } finally {
+                this.resolver.release(src);
             }
         }
 

Added: cocoon/trunk/src/java/org/apache/cocoon/i18n/XMLResourceBundleNotFoundException.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/i18n/XMLResourceBundleNotFoundException.java?rev=292770&view=auto
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/i18n/XMLResourceBundleNotFoundException.java (added)
+++ cocoon/trunk/src/java/org/apache/cocoon/i18n/XMLResourceBundleNotFoundException.java Fri Sep 30 08:29:15 2005
@@ -0,0 +1,31 @@
+/*
+ * Copyright 1999-2005 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.cocoon.i18n;
+
+import org.apache.avalon.framework.CascadingRuntimeException;
+
+public final class XMLResourceBundleNotFoundException extends CascadingRuntimeException
+{
+    public XMLResourceBundleNotFoundException(String message)
+    {
+        super(message, null);
+    }
+
+    public XMLResourceBundleNotFoundException(String message, Throwable cause)
+    {
+        super(message, cause);
+    }
+}



Re: FYI New Exception thrown (was Re: svn commit: r292770 - in /cocoon/trunk/src/java/org/apache/cocoon/i18n: XMLResourceBundleFactory.java XMLResourceBundleNotFoundException.java)

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Sylvain Wallez wrote:
> Berin Loritsch wrote:
> 
>> I changed the "FIXME" comment that had a question with a runtime 
>> exception.  This should answer the question quite well.  Before we 
>> simply ignored XMLBundles with no base URL--now we force the system to 
>> deal with it.  It should also help tighten up some code.
> 
> We did not ignored XMLBundles with no base URL, but on the contrary we 
> allowed them, despite not being sure the case was actually really 
> happening with the I18nTransformer.

With XMLResourceBundleFactory, directory was allowed to be empty, in configure() 
method. So empty base seems like valid scenario.

OTOH, null should not be there and it either should result in NPE or be treated 
as empty base. I chose latter...

Vadim