geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r571620 - in /geronimo/sandbox/gshell/trunk/gshell-i18n: ./ src/main/java/org/apache/geronimo/gshell/i18n/ src/test/java/org/apache/geronimo/gshell/i18n/ src/test/resources/org/apache/geronimo/gshell/i18n/
Date Fri, 31 Aug 2007 22:20:27 GMT
Author: jdillon
Date: Fri Aug 31 15:20:23 2007
New Revision: 571620

URL: http://svn.apache.org/viewvc?rev=571620&view=rev
Log:
Tidy up, re-introduce intf, fixed error reporting

Added:
    geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/MessageSource.java
    geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSource.java
  (contents, props changed)
      - copied, changed from r571563, geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/MessageSource.java
    geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/java/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSourceTest.java
  (contents, props changed)
      - copied, changed from r571563, geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/java/org/apache/geronimo/gshell/i18n/MessageSourceTest.java
    geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/resources/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSourceTest.properties
  (props changed)
      - copied unchanged from r571563, geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/resources/org/apache/geronimo/gshell/i18n/MessageSourceTest.properties
Removed:
    geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/java/org/apache/geronimo/gshell/i18n/MessageSourceTest.java
    geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/resources/org/apache/geronimo/gshell/i18n/MessageSourceTest.properties
Modified:
    geronimo/sandbox/gshell/trunk/gshell-i18n/pom.xml

Modified: geronimo/sandbox/gshell/trunk/gshell-i18n/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-i18n/pom.xml?rev=571620&r1=571619&r2=571620&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-i18n/pom.xml (original)
+++ geronimo/sandbox/gshell/trunk/gshell-i18n/pom.xml Fri Aug 31 15:20:23 2007
@@ -32,8 +32,18 @@
     
     <artifactId>gshell-i18n</artifactId>
     <name>GShell i18n</name>
-    
+
+    <description>
+        Internationalization support.
+    </description>
+
     <dependencies>
+        <dependency>
+            <groupId>org.apache.geronimo.gshell</groupId>
+            <artifactId>gshell-common</artifactId>
+            <version>${pom.version}</version>
+        </dependency>
+        
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>

Added: geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/MessageSource.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/MessageSource.java?rev=571620&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/MessageSource.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/MessageSource.java
Fri Aug 31 15:20:23 2007
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.geronimo.gshell.i18n;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public interface MessageSource
+{
+    String getMessage(String code);
+
+    String format(String code, Object... args);
+}

Copied: geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSource.java
(from r571563, geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/MessageSource.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSource.java?p2=geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSource.java&p1=geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/MessageSource.java&r1=571563&r2=571620&rev=571620&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/MessageSource.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSource.java
Fri Aug 31 15:20:23 2007
@@ -21,28 +21,30 @@
 
 import java.util.ResourceBundle;
 import java.util.MissingResourceException;
-
 import java.text.MessageFormat;
 
+import org.codehaus.plexus.util.StringUtils;
+
 /**
  * Message source backed up by one or more {@link ResourceBundle} instances for simple i18n
support.
  *
  * @version $Rev$ $Date$
  */
-public class MessageSource
+public class ResourceBundleMessageSource
+    implements MessageSource
 {
     private final String[] bundleNames;
 
     private ResourceBundle[] cachedBundles;
 
-    public MessageSource(final String[] names) {
+    public ResourceBundleMessageSource(final String[] names) {
         assert names != null;
         assert names.length != 0;
 
         this.bundleNames = names;
     }
 
-    public MessageSource(final String name) {
+    public ResourceBundleMessageSource(final String name) {
         this(new String[] { name });
     }
 
@@ -61,11 +63,11 @@
         return names;
     }
 
-    public MessageSource(final Class[] types) {
+    public ResourceBundleMessageSource(final Class[] types) {
         this(classNames(types));
     }
 
-    public MessageSource(final Class type) {
+    public ResourceBundleMessageSource(final Class type) {
         this(new String[] { type.getName() });
     }
 
@@ -74,7 +76,7 @@
 
         for (int i=0; i<bundleNames.length; i++) {
             assert bundleNames[i] != null;
-
+            
             bundles[i] = ResourceBundle.getBundle(bundleNames[i]);
         }
 
@@ -94,26 +96,14 @@
     public String getMessage(final String code) {
         assert code != null;
 
-        MissingResourceException error = null;
-
         for (ResourceBundle bundle : getBundles()) {
             try {
                 return bundle.getString(code);
             }
-            catch (MissingResourceException e) {
-                //
-                // FIXME: For now just save the first error, should really roll a new message
with all of the details
-                //
-
-                if (error != null) {
-                    error = e;
-                }
-            }
+            catch (MissingResourceException ignore) {}
         }
 
-        assert error != null;
-
-        throw error;
+        throw new ResourceNotFoundException(code);
     }
 
     /**
@@ -134,5 +124,21 @@
      */
     public Object getProperty(final String name) {
         return getMessage(name);
+    }
+
+    //
+    // ResourceNotFoundException
+    //
+
+    private static String notFoundMessage(final String code, final String[] bundleNames)
{
+        return "Resource not found for code: " + code + " in bundles: " + StringUtils.join(bundleNames,
", ");
+    }
+
+    public class ResourceNotFoundException
+        extends RuntimeException
+    {
+        public ResourceNotFoundException(final String code) {
+            super(notFoundMessage(code, bundleNames));
+        }
     }
 }

Propchange: geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSource.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-i18n/src/main/java/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSource.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/java/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSourceTest.java
(from r571563, geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/java/org/apache/geronimo/gshell/i18n/MessageSourceTest.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/java/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSourceTest.java?p2=geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/java/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSourceTest.java&p1=geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/java/org/apache/geronimo/gshell/i18n/MessageSourceTest.java&r1=571563&r2=571620&rev=571620&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/java/org/apache/geronimo/gshell/i18n/MessageSourceTest.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/java/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSourceTest.java
Fri Aug 31 15:20:23 2007
@@ -22,18 +22,18 @@
 import junit.framework.TestCase;
 
 /**
- * Unit tests for the {@link MessageSource} class.
+ * Unit tests for the {@link ResourceBundleMessageSource} class.
  *
  * @version $Id$
  * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
  */
-public class MessageSourceTest
+public class ResourceBundleMessageSourceTest
     extends TestCase
 {
     MessageSource messages;
 
     protected void setUp() throws Exception {
-        messages = new MessageSource(getClass());
+        messages = new ResourceBundleMessageSource(getClass());
     }
 
     public void testLoadAndGetMessage() {
@@ -48,5 +48,12 @@
 
         String f = messages.format("f", a, b, c);
         assertEquals("1 2 3", f);
+    }
+
+    public void testMissingResource() throws Exception {
+        try {
+            messages.getMessage("no-such-code");
+        }
+        catch (ResourceBundleMessageSource.ResourceNotFoundException expected) {}
     }
 }

Propchange: geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/java/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSourceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/java/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSourceTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/java/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSourceTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Propchange: geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/resources/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSourceTest.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/resources/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSourceTest.properties
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-i18n/src/test/resources/org/apache/geronimo/gshell/i18n/ResourceBundleMessageSourceTest.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message