roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r429485 - in /incubator/roller/branches/roller_3.0/src/org/apache/roller: ui/rendering/model/MessageModel.java util/MessageUtilities.java
Date Mon, 07 Aug 2006 21:35:16 GMT
Author: agilliland
Date: Mon Aug  7 14:35:16 2006
New Revision: 429485

URL: http://svn.apache.org/viewvc?rev=429485&view=rev
Log:
adding new MessageUtilities class to centralize access to the Roller resource bundle.  also
made MessageModel class use new MessageUtilities class.



Added:
    incubator/roller/branches/roller_3.0/src/org/apache/roller/util/MessageUtilities.java
Modified:
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/MessageModel.java

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/MessageModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/MessageModel.java?rev=429485&r1=429484&r2=429485&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/MessageModel.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/MessageModel.java
Mon Aug  7 14:35:16 2006
@@ -18,23 +18,18 @@
 
 package org.apache.roller.ui.rendering.model;
 
-import java.text.MessageFormat;
 import java.util.List;
 import java.util.Map;
-import java.util.ResourceBundle;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.roller.RollerException;
+import org.apache.roller.util.MessageUtilities;
+
 
 /**
  * Provides access to application resources required for I18N.
  * Uses model name 'text' because that's what the Velocity Tools did.
  */
-public class MessageModel implements Model {
+public class MessageModel implements Model {  
     
-    private static Log logger = LogFactory.getLog(MessageModel.class);
-    private static ResourceBundle bundle =
-            ResourceBundle.getBundle("ApplicationResources");        
     
     /** Template context name to be used for model */
     public String getModelName() {
@@ -44,25 +39,27 @@
     
     /** Init page model based on request */
     public void init(Map initData) throws RollerException {
-        
+        // no-op
     }
     
+    
     /** Return message string */
     public String get(String key) {
         try {
-            return bundle.getString(key);
+            return MessageUtilities.getString(key);
         } catch (Exception e) {
             return key;
         }
     }
     
+    
     /** Return parameterized message string */
     public String get(String key, List args) {
         try {
-            String msg = bundle.getString(key);
-            return MessageFormat.format(msg, args.toArray());
+            return MessageUtilities.getString(key, args);
         } catch (Exception e) {
             return key;
         }
-    }    
+    }
+    
 }

Added: incubator/roller/branches/roller_3.0/src/org/apache/roller/util/MessageUtilities.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/util/MessageUtilities.java?rev=429485&view=auto
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/util/MessageUtilities.java
(added)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/util/MessageUtilities.java
Mon Aug  7 14:35:16 2006
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.util;
+
+import java.text.MessageFormat;
+import java.util.List;
+import java.util.ResourceBundle;
+import org.apache.roller.RollerException;
+
+
+/**
+ * A utilities class for interacting with the Roller resource bundles.
+ */
+public class MessageUtilities {
+    
+    private static final ResourceBundle bundle =
+            ResourceBundle.getBundle("ApplicationResources");
+    
+    
+    // no instantiation
+    private MessageUtilities() {
+    }
+    
+    
+    /**
+     * Get a message from the bundle.
+     */
+    public static final String getString(String key) throws RollerException {
+        
+        try {
+            return bundle.getString(key);
+        } catch (Exception e) {
+            // wrap as RollerException and rethrow
+            throw new RollerException("Error getting key "+key, e);
+        }
+    }
+    
+    
+    /**
+     * Get a message from the bundle and substitute the given args into
+     * the message contents.
+     */
+    public static final String getString(String key, List args) 
+            throws RollerException {
+        
+        try {
+            String msg = bundle.getString(key);
+            return MessageFormat.format(msg, args.toArray());
+        } catch (Exception e) {
+            // wrap as RollerException and rethrow
+            throw new RollerException("Error getting key "+key, e);
+        }
+    }
+    
+}



Mime
View raw message