tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r924061 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/internal/services/ main/java/org/apache/tapestry5/internal/services/messages/ main/java/org/apache/tapestry5/services/ main/java/org/apache/tapestry5/s...
Date Tue, 16 Mar 2010 23:49:41 GMT
Author: hlship
Date: Tue Mar 16 23:49:40 2010
New Revision: 924061

URL: http://svn.apache.org/viewvc?rev=924061&view=rev
Log:
TAP5-1055: Add a service used to read a properties file, used by MessagesSource

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/messages/
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/messages/PropertiesFileParserImpl.java
  (with props)
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/messages/
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/messages/PropertiesFileParser.java
  (with props)
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/messages/
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/messages/PropertiesFileParserImplTest.java
  (with props)
    tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/messages/
    tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/messages/utf8.properties
  (contents, props changed)
      - copied, changed from r924060, tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/utf8.properties
Removed:
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/MessagesSourceImplTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/utf8.properties
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImplTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImpl.java?rev=924061&r1=924060&r2=924061&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImpl.java
Tue Mar 16 23:49:40 2010
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2010 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
+// 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,
@@ -23,6 +23,7 @@ import org.apache.tapestry5.ioc.services
 import org.apache.tapestry5.model.ComponentModel;
 import org.apache.tapestry5.services.InvalidationEventHub;
 import org.apache.tapestry5.services.UpdateListener;
+import org.apache.tapestry5.services.messages.PropertiesFileParser;
 
 import java.util.Locale;
 
@@ -58,26 +59,28 @@ public class ComponentMessagesSourceImpl
         {
             ComponentModel parentModel = model.getParentModel();
 
-            if (parentModel == null) return rootBundle;
+            if (parentModel == null)
+                return rootBundle;
 
             return new ComponentModelBundle(parentModel, rootBundle);
         }
     }
 
-    public ComponentMessagesSourceImpl(
-            @Symbol(SymbolConstants.APPLICATION_CATALOG)
-            Resource appCatalogResource,
+    public ComponentMessagesSourceImpl(@Symbol(SymbolConstants.APPLICATION_CATALOG)
+    Resource appCatalogResource,
 
-            ClasspathURLConverter classpathURLConverter)
+    PropertiesFileParser parser,
+
+    ClasspathURLConverter classpathURLConverter)
     {
-        this(appCatalogResource, new URLChangeTracker(classpathURLConverter));
+        this(appCatalogResource, parser, new URLChangeTracker(classpathURLConverter));
     }
 
-    ComponentMessagesSourceImpl(Resource appCatalogResource, URLChangeTracker tracker)
+    ComponentMessagesSourceImpl(Resource appCatalogResource, PropertiesFileParser parser,
URLChangeTracker tracker)
     {
         this.appCatalogResource = appCatalogResource;
 
-        messagesSource = new MessagesSourceImpl(tracker);
+        messagesSource = new MessagesSourceImpl(tracker, parser);
     }
 
     public void checkForUpdates()
@@ -89,8 +92,7 @@ public class ComponentMessagesSourceImpl
     {
         // If the application catalog exists, set it up as the root, otherwise use null.
 
-        MessagesBundle appCatalogBundle = !appCatalogResource.exists() ? null
-                                                                       : rootBundle();
+        MessagesBundle appCatalogBundle = !appCatalogResource.exists() ? null : rootBundle();
 
         MessagesBundle bundle = new ComponentModelBundle(componentModel, appCatalogBundle);
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java?rev=924061&r1=924060&r2=924061&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MessagesSourceImpl.java
Tue Mar 16 23:49:40 2010
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2010 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
+// 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,
@@ -14,22 +14,25 @@
 
 package org.apache.tapestry5.internal.services;
 
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
 import org.apache.tapestry5.internal.event.InvalidationEventHubImpl;
 import org.apache.tapestry5.internal.util.MultiKey;
 import org.apache.tapestry5.internal.util.URLChangeTracker;
 import org.apache.tapestry5.ioc.Messages;
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
-import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.ioc.internal.util.LocalizedNameGenerator;
-
-import java.io.*;
-import java.util.*;
+import org.apache.tapestry5.services.messages.PropertiesFileParser;
 
 /**
  * A utility class that encapsulates all the logic for reading properties files and assembling
{@link Messages} from
- * them, in accordance with extension rules and locale. This represents code that was refactored
out of {@link
- * ComponentMessagesSourceImpl}. This class can be used as a base class, though the existing
code base uses it as a
+ * them, in accordance with extension rules and locale. This represents code that was refactored
out of
+ * {@link ComponentMessagesSourceImpl}. This class can be used as a base class, though the
existing code base uses it as
+ * a
  * utility. Composition trumps inheritance!
  * <p/>
  * The message catalog for a component is the combination of all appropriate properties files
for the component, plus
@@ -43,13 +46,15 @@ public class MessagesSourceImpl extends 
 {
     private final URLChangeTracker tracker;
 
+    private final PropertiesFileParser propertiesFileParser;
+
     /**
      * Keyed on bundle id and locale.
      */
     private final Map<MultiKey, Messages> messagesByBundleIdAndLocale = CollectionFactory.newConcurrentMap();
 
     /**
-     * Keyed on bundle id and locale, the coooked properties include properties inherited
from less locale-specific
+     * Keyed on bundle id and locale, the cooked properties include properties inherited
from less locale-specific
      * properties files, or inherited from parent bundles.
      */
     private final Map<MultiKey, Map<String, String>> cookedProperties = CollectionFactory.newConcurrentMap();
@@ -61,19 +66,10 @@ public class MessagesSourceImpl extends 
 
     private final Map<String, String> emptyMap = Collections.emptyMap();
 
-    /**
-     * Charset used when reading a properties file.
-     */
-    private static final String CHARSET = "UTF-8";
-
-    /**
-     * Buffer size used when reading a properties file.
-     */
-    private static final int BUFFER_SIZE = 2000;
-
-    public MessagesSourceImpl(URLChangeTracker tracker)
+    public MessagesSourceImpl(URLChangeTracker tracker, PropertiesFileParser propertiesFileParser)
     {
         this.tracker = tracker;
+        this.propertiesFileParser = propertiesFileParser;
     }
 
     public void checkForUpdates()
@@ -119,13 +115,15 @@ public class MessagesSourceImpl extends 
      */
     private Map<String, String> findBundleProperties(MessagesBundle bundle, Locale
locale)
     {
-        if (bundle == null) return emptyMap;
+        if (bundle == null)
+            return emptyMap;
 
         MultiKey key = new MultiKey(bundle.getId(), locale);
 
         Map<String, String> existing = cookedProperties.get(key);
 
-        if (existing != null) return existing;
+        if (existing != null)
+            return existing;
 
         // What would be cool is if we could maintain a cache of bundle id + locale -->
         // Resource. That would optimize quite a bit of this; may need to use an alternative
to
@@ -172,7 +170,8 @@ public class MessagesSourceImpl extends 
      */
     private Map<String, String> extend(Map<String, String> base, Map<String,
String> rawProperties)
     {
-        if (rawProperties.isEmpty()) return base;
+        if (rawProperties.isEmpty())
+            return base;
 
         // Make a copy of the base Map
 
@@ -204,13 +203,14 @@ public class MessagesSourceImpl extends 
      */
     private Map<String, String> readProperties(Resource resource)
     {
-        if (!resource.exists()) return emptyMap;
+        if (!resource.exists())
+            return emptyMap;
 
         tracker.add(resource.toURL());
 
         try
         {
-            return readPropertiesFromStream(resource.openStream());
+            return propertiesFileParser.parsePropertiesFile(resource);
         }
         catch (Exception ex)
         {
@@ -218,80 +218,4 @@ public class MessagesSourceImpl extends 
         }
     }
 
-    static Map<String, String> readPropertiesFromStream(InputStream propertiesFileStream)
throws IOException
-    {
-        Map<String, String> result = CollectionFactory.newCaseInsensitiveMap();
-
-        Properties p = new Properties();
-        InputStream is = null;
-
-        try
-        {
-
-            is = readUTFStreamToEscapedASCII(propertiesFileStream);
-
-            // Ok, now we have the content read into memory as UTF-8, not ASCII.
-
-            p.load(is);
-
-            is.close();
-
-            is = null;
-        }
-        finally
-        {
-            InternalUtils.close(is);
-        }
-
-        for (Map.Entry e : p.entrySet())
-        {
-            String key = e.getKey().toString();
-
-            String value = p.getProperty(key);
-
-            result.put(key, value);
-        }
-
-        return result;
-    }
-
-
-    /**
-     * Reads a UTF-8 stream, performing a conversion to ASCII (i.e., ISO8859-1 encoding).
Characters outside the normal
-     * range for ISO8859-1 are converted to unicode escapes. In effect, Tapestry is performing
native2ascii on the
-     * files, on the fly.
-     */
-    private static InputStream readUTFStreamToEscapedASCII(InputStream is) throws IOException
-    {
-        Reader reader = new InputStreamReader(is, CHARSET);
-
-        StringBuilder builder = new StringBuilder(BUFFER_SIZE);
-        char[] buffer = new char[BUFFER_SIZE];
-
-        while (true)
-        {
-            int length = reader.read(buffer);
-
-            if (length < 0) break;
-
-            for (int i = 0; i < length; i++)
-            {
-                char ch = buffer[i];
-
-                if (ch <= '\u007f')
-                {
-                    builder.append(ch);
-                    continue;
-                }
-
-                builder.append(String.format("\\u%04x", (int) ch));
-            }
-        }
-
-        reader.close();
-
-        byte[] resourceContent = builder.toString().getBytes();
-
-        return new ByteArrayInputStream(resourceContent);
-    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImpl.java?rev=924061&r1=924060&r2=924061&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImpl.java
Tue Mar 16 23:49:40 2010
@@ -4,7 +4,7 @@
 // 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
+// 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,
@@ -22,6 +22,7 @@ import org.apache.tapestry5.ioc.internal
 import org.apache.tapestry5.ioc.services.ClasspathURLConverter;
 import org.apache.tapestry5.services.UpdateListener;
 import org.apache.tapestry5.services.ValidationMessagesSource;
+import org.apache.tapestry5.services.messages.PropertiesFileParser;
 
 import java.util.List;
 import java.util.Locale;
@@ -108,14 +109,16 @@ public class ValidationMessagesSourceImp
         }
     }
 
-    public ValidationMessagesSourceImpl(List<String> bundles, Resource classpathRoot,
ClasspathURLConverter classpathURLConverter)
+    public ValidationMessagesSourceImpl(List<String> bundles, Resource classpathRoot,
PropertiesFileParser parser,
+            ClasspathURLConverter classpathURLConverter)
     {
-        this(bundles, classpathRoot, new URLChangeTracker(classpathURLConverter));
+        this(bundles, classpathRoot, parser, new URLChangeTracker(classpathURLConverter));
     }
 
-    ValidationMessagesSourceImpl(List<String> bundles, Resource classpathRoot, URLChangeTracker
tracker)
+    ValidationMessagesSourceImpl(List<String> bundles, Resource classpathRoot, PropertiesFileParser
parser,
+            URLChangeTracker tracker)
     {
-        messagesSource = new MessagesSourceImpl(tracker);
+        messagesSource = new MessagesSourceImpl(tracker, parser);
 
         MessagesBundle parent = null;
 

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/messages/PropertiesFileParserImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/messages/PropertiesFileParserImpl.java?rev=924061&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/messages/PropertiesFileParserImpl.java
(added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/messages/PropertiesFileParserImpl.java
Tue Mar 16 23:49:40 2010
@@ -0,0 +1,118 @@
+// Copyright 2010 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.tapestry5.internal.services.messages;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.tapestry5.ioc.Resource;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+import org.apache.tapestry5.services.messages.PropertiesFileParser;
+
+public class PropertiesFileParserImpl implements PropertiesFileParser
+{
+    /**
+     * Charset used when reading a properties file.
+     */
+    private static final String CHARSET = "UTF-8";
+
+    /**
+     * Buffer size used when reading a properties file.
+     */
+    private static final int BUFFER_SIZE = 2000;
+
+    public Map<String, String> parsePropertiesFile(Resource resource) throws IOException
+    {
+        Map<String, String> result = CollectionFactory.newCaseInsensitiveMap();
+
+        Properties p = new Properties();
+        InputStream is = null;
+
+        try
+        {
+
+            is = readUTFStreamToEscapedASCII(resource.openStream());
+
+            // Ok, now we have the content read into memory as UTF-8, not ASCII.
+
+            p.load(is);
+
+            is.close();
+
+            is = null;
+        }
+        finally
+        {
+            InternalUtils.close(is);
+        }
+
+        for (Map.Entry e : p.entrySet())
+        {
+            String key = e.getKey().toString();
+
+            String value = p.getProperty(key);
+
+            result.put(key, value);
+        }
+
+        return result;
+    }
+
+    /**
+     * Reads a UTF-8 stream, performing a conversion to ASCII (i.e., ISO8859-1 encoding).
Characters outside the normal
+     * range for ISO8859-1 are converted to unicode escapes. In effect, Tapestry is performing
native2ascii on the
+     * files, on the fly.
+     */
+    private static InputStream readUTFStreamToEscapedASCII(InputStream is) throws IOException
+    {
+        Reader reader = new InputStreamReader(is, CHARSET);
+
+        StringBuilder builder = new StringBuilder(BUFFER_SIZE);
+        char[] buffer = new char[BUFFER_SIZE];
+
+        while (true)
+        {
+            int length = reader.read(buffer);
+
+            if (length < 0)
+                break;
+
+            for (int i = 0; i < length; i++)
+            {
+                char ch = buffer[i];
+
+                if (ch <= '\u007f')
+                {
+                    builder.append(ch);
+                    continue;
+                }
+
+                builder.append(String.format("\\u%04x", (int) ch));
+            }
+        }
+
+        reader.close();
+
+        byte[] resourceContent = builder.toString().getBytes();
+
+        return new ByteArrayInputStream(resourceContent);
+    }
+}

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/messages/PropertiesFileParserImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=924061&r1=924060&r2=924061&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
Tue Mar 16 23:49:40 2010
@@ -74,6 +74,7 @@ import org.apache.tapestry5.internal.ren
 import org.apache.tapestry5.internal.renderers.RequestRenderer;
 import org.apache.tapestry5.internal.services.*;
 import org.apache.tapestry5.internal.services.javascript.JavascriptSupportImpl;
+import org.apache.tapestry5.internal.services.messages.PropertiesFileParserImpl;
 import org.apache.tapestry5.internal.transform.*;
 import org.apache.tapestry5.internal.translator.NumericTranslator;
 import org.apache.tapestry5.internal.translator.NumericTranslatorSupport;
@@ -99,6 +100,7 @@ import org.apache.tapestry5.runtime.Rend
 import org.apache.tapestry5.runtime.RenderQueue;
 import org.apache.tapestry5.services.ajax.MultiZoneUpdateEventResultProcessor;
 import org.apache.tapestry5.services.javascript.JavascriptSupport;
+import org.apache.tapestry5.services.messages.PropertiesFileParser;
 import org.apache.tapestry5.util.StringToEnumCoercion;
 import org.apache.tapestry5.validator.Email;
 import org.apache.tapestry5.validator.Max;
@@ -353,6 +355,7 @@ public final class TapestryModule
         binder.bind(AssetPathAuthorizer.class, WhitelistAuthorizer.class).withId("WhitelistAuthorizer");
         binder.bind(AssetPathAuthorizer.class, RegexAuthorizer.class).withId("RegexAuthorizer");
         binder.bind(ValidatorMacro.class, ValidatorMacroImpl.class);
+        binder.bind(PropertiesFileParser.class, PropertiesFileParserImpl.class);
     }
 
     // ========================================================================
@@ -1271,10 +1274,12 @@ public final class TapestryModule
     @ClasspathProvider
     AssetFactory classpathAssetFactory,
 
+    PropertiesFileParser parser,
+
     ClasspathURLConverter classpathURLConverter)
     {
         ValidationMessagesSourceImpl service = new ValidationMessagesSourceImpl(configuration,
classpathAssetFactory
-                .getRootResource(), classpathURLConverter);
+                .getRootResource(), parser, classpathURLConverter);
         updateListenerHub.addUpdateListener(service);
 
         return service;

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/messages/PropertiesFileParser.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/messages/PropertiesFileParser.java?rev=924061&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/messages/PropertiesFileParser.java
(added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/messages/PropertiesFileParser.java
Tue Mar 16 23:49:40 2010
@@ -0,0 +1,38 @@
+// Copyright 2010 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.tapestry5.services.messages;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.tapestry5.ioc.Messages;
+import org.apache.tapestry5.ioc.Resource;
+import org.apache.tapestry5.ioc.util.CaseInsensitiveMap;
+
+/**
+ * Used when constructing a component's {@link Messages} object. Responsible for reading
the
+ * contents of an individual {@link Resource}.
+ * 
+ * @since 5.2.0
+ */
+public interface PropertiesFileParser
+{
+    /**
+     * Read the contents of the file (which is expected to exist) and return it as
+     * a Map of string keys and values (as {@link CaseInsensitiveMap} should be used. The
implementation should not
+     * attempt to cache any values (caching occurs at a higher level, as does reload logic).
+     */
+    Map<String, String> parsePropertiesFile(Resource resource) throws IOException;
+}

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/messages/PropertiesFileParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml?rev=924061&r1=924060&r2=924061&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/conf/testng.xml Tue Mar 16 23:49:40 2010
@@ -39,6 +39,7 @@
       <package name="org.apache.tapestry5.internal.model"/>
       <package name="org.apache.tapestry5.internal.pageload"/>
       <package name="org.apache.tapestry5.internal.services"/>
+      <package name="org.apache.tapestry5.internal.services.messages"/>
       <package name="org.apache.tapestry5.internal.structure"/>
       <package name="org.apache.tapestry5.internal.test"/>
       <package name="org.apache.tapestry5.internal.transform"/>

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImplTest.java?rev=924061&r1=924060&r2=924061&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImplTest.java
Tue Mar 16 23:49:40 2010
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007, 2009 The Apache Software Foundation
+// Copyright 2006, 2007, 2009, 2010 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
+// 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,
@@ -14,6 +14,9 @@
 
 package org.apache.tapestry5.internal.services;
 
+import java.util.Locale;
+
+import org.apache.tapestry5.internal.services.messages.PropertiesFileParserImpl;
 import org.apache.tapestry5.internal.test.InternalBaseTestCase;
 import org.apache.tapestry5.internal.util.URLChangeTracker;
 import org.apache.tapestry5.ioc.Messages;
@@ -24,13 +27,11 @@ import org.apache.tapestry5.ioc.services
 import org.apache.tapestry5.model.ComponentModel;
 import org.testng.annotations.Test;
 
-import java.util.Locale;
-
 /**
  * Tests {@link ComponentMessagesSourceImpl} as well as {@link MessagesSourceImpl} (which
contains code refactored out
  * of CMSI).
  */
-@Test(sequential = true)
+@Test
 public class ComponentMessagesSourceImplTest extends InternalBaseTestCase
 {
     // With control of the tracker, we can force changes as if underlying files were changed.
@@ -44,8 +45,8 @@ public class ComponentMessagesSourceImpl
     private final Resource simpleComponentResource = new ClasspathResource(
             "org/apache/tapestry5/internal/services/SimpleComponent.class");
 
-    private final ComponentMessagesSourceImpl source = new ComponentMessagesSourceImpl(
-            simpleComponentResource.forFile("AppCatalog.properties"), tracker);
+    private final ComponentMessagesSourceImpl source = new ComponentMessagesSourceImpl(simpleComponentResource
+            .forFile("AppCatalog.properties"), new PropertiesFileParserImpl(), tracker);
 
     @Test
     public void simple_component()
@@ -145,9 +146,7 @@ public class ComponentMessagesSourceImpl
         ComponentModel model = mockComponentModel();
         ComponentModel parent = mockComponentModel();
 
-        train_getComponentClassName(
-                model,
-                "org.apache.tapestry5.internal.services.SubclassComponent");
+        train_getComponentClassName(model, "org.apache.tapestry5.internal.services.SubclassComponent");
 
         train_getBaseResource(model, new ClasspathResource(
                 "org/apache/tapestry5/internal/services/SubclassComponent.class"));
@@ -189,9 +188,7 @@ public class ComponentMessagesSourceImpl
         ComponentModel model = mockComponentModel();
         ComponentModel parent = mockComponentModel();
 
-        train_getComponentClassName(
-                model,
-                "org.apache.tapestry5.internal.services.SubclassComponent");
+        train_getComponentClassName(model, "org.apache.tapestry5.internal.services.SubclassComponent");
 
         train_getBaseResource(model, new ClasspathResource(
                 "org/apache/tapestry5/internal/services/SubclassComponent.class"));
@@ -208,8 +205,8 @@ public class ComponentMessagesSourceImpl
 
         forceCacheClear();
 
-        ComponentMessagesSource source = new ComponentMessagesSourceImpl(
-                simpleComponentResource.forFile("NoSuchAppCatalog.properties"), converter);
+        ComponentMessagesSource source = new ComponentMessagesSourceImpl(simpleComponentResource
+                .forFile("NoSuchAppCatalog.properties"), new PropertiesFileParserImpl(),
converter);
 
         Messages messages = source.getMessages(model, Locale.ENGLISH);
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImplTest.java?rev=924061&r1=924060&r2=924061&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImplTest.java
Tue Mar 16 23:49:40 2010
@@ -1,10 +1,10 @@
-// Copyright 2006, 2008 The Apache Software Foundation
+// Copyright 2006, 2008, 2010 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
+// 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,
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry5.internal.services;
 
+import org.apache.tapestry5.internal.services.messages.PropertiesFileParserImpl;
 import org.apache.tapestry5.ioc.MessageFormatter;
 import org.apache.tapestry5.ioc.Messages;
 import org.apache.tapestry5.ioc.Resource;
@@ -35,10 +36,8 @@ public class ValidationMessagesSourceImp
     public void setup()
     {
         Resource rootResource = new ClasspathResource("/");
-        source = new ValidationMessagesSourceImpl(Arrays.asList(
-                "org/apache/tapestry5/internal/ValidationMessages",
-                "org/apache/tapestry5/internal/ValidationTestMessages"), 
-                rootResource,
+        source = new ValidationMessagesSourceImpl(Arrays.asList("org/apache/tapestry5/internal/ValidationMessages",
+                "org/apache/tapestry5/internal/ValidationTestMessages"), rootResource, new
PropertiesFileParserImpl(),
                 new ClasspathURLConverterImpl());
     }
 
@@ -47,12 +46,9 @@ public class ValidationMessagesSourceImp
     {
         Messages messages = source.getValidationMessages(Locale.ENGLISH);
 
-        assertEquals(
-                messages.format("required", "My Field"),
-                "You must provide a value for My Field.");
+        assertEquals(messages.format("required", "My Field"), "You must provide a value for
My Field.");
     }
 
-
     @Test
     public void overriden_message()
     {
@@ -74,9 +70,7 @@ public class ValidationMessagesSourceImp
     {
         Messages messages = source.getValidationMessages(Locale.ENGLISH);
 
-        assertEquals(
-                messages.get("contributed"),
-                "This message was contributed inside ValidationTestMessages.");
+        assertEquals(messages.get("contributed"), "This message was contributed inside ValidationTestMessages.");
     }
 
     @Test

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/messages/PropertiesFileParserImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/messages/PropertiesFileParserImplTest.java?rev=924061&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/messages/PropertiesFileParserImplTest.java
(added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/messages/PropertiesFileParserImplTest.java
Tue Mar 16 23:49:40 2010
@@ -0,0 +1,39 @@
+// Copyright 2008, 2010 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.tapestry5.internal.services.messages;
+
+import java.util.Map;
+
+import org.apache.tapestry5.internal.test.InternalBaseTestCase;
+import org.apache.tapestry5.ioc.Resource;
+import org.apache.tapestry5.ioc.internal.util.ClasspathResource;
+import org.apache.tapestry5.services.messages.PropertiesFileParser;
+import org.testng.annotations.Test;
+
+public class PropertiesFileParserImplTest extends InternalBaseTestCase
+{
+    @Test
+    public void read_utf() throws Exception
+    {
+        Resource utf8 = new ClasspathResource("org/apache/tapestry5/internal/services/messages/utf8.properties");
+
+        PropertiesFileParser parser = getService(PropertiesFileParser.class);
+
+        Map<String, String> properties = parser.parsePropertiesFile(utf8);
+
+        assertEquals(properties.get("tapestry"), "\u30bf\u30da\u30b9\u30c8\u30ea\u30fc");
+        assertEquals(properties.get("version"), "5");
+    }
+}

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/messages/PropertiesFileParserImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/messages/utf8.properties
(from r924060, tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/utf8.properties)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/messages/utf8.properties?p2=tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/messages/utf8.properties&p1=tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/utf8.properties&r1=924060&r2=924061&rev=924061&view=diff
==============================================================================
    (empty)

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/messages/utf8.properties
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message