You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by an...@apache.org on 2012/11/21 18:38:49 UTC

svn commit: r1412206 - in /myfaces/trinidad/trunk/trinidad-impl/src: main/java/org/apache/myfaces/trinidadinternal/resource/ test/java/org/apache/myfaces/trinidadinternal/resource/

Author: andys
Date: Wed Nov 21 17:38:45 2012
New Revision: 1412206

URL: http://svn.apache.org/viewvc?rev=1412206&view=rev
Log:
TRINIDAD-2340 LocaleElementsResourceLoader init dependency on request path

Avoid calling CoreRenderKitResourceLoader.getLocaleElementsURI() during resource loader initialization, as it is not safe to depend on the request uri at this time.  Fortunately, this call was entirely unnecessary, so we can simply remove it with no negative impact.

Added a small unit test that verifies that the CoreRenderKitResourceLoader (and thus the LocaleElementsResourceLoader) can be instantiated without access to a FacesContext (and thus is not dependent on any request-specific state).

Added:
    myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/resource/
    myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/resource/CoreRenderKitResourceLoaderTest.java
Modified:
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/resource/LocaleElementsResourceLoader.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/resource/TrTranslationsResourceLoader.java

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/resource/LocaleElementsResourceLoader.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/resource/LocaleElementsResourceLoader.java?rev=1412206&r1=1412205&r2=1412206&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/resource/LocaleElementsResourceLoader.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/resource/LocaleElementsResourceLoader.java Wed Nov 21 17:38:45 2012
@@ -116,7 +116,7 @@ public class LocaleElementsResourceLoade
   static private final ResourceLoader[] _ResourceLoaders =
   {
     new ClassLoaderResourceLoader(),
-    new TrTranslationsResourceLoader(CoreRenderKitResourceLoader.getLocaleElementsURI("Translations", false))
+    new TrTranslationsResourceLoader()
   };
   
   static private final String _NEWLINE_SEPARATOR = "\n";

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/resource/TrTranslationsResourceLoader.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/resource/TrTranslationsResourceLoader.java?rev=1412206&r1=1412205&r2=1412206&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/resource/TrTranslationsResourceLoader.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/resource/TrTranslationsResourceLoader.java Wed Nov 21 17:38:45 2012
@@ -29,6 +29,15 @@ import org.apache.myfaces.trinidad.skin.
 
 public class TrTranslationsResourceLoader extends TranslationsResourceLoader
 {
+  public TrTranslationsResourceLoader()
+  {
+    // The path that is passed up to the DynamicResourceLoader is never actually
+    // used. TranslationsResourceLoader overrides findResource(), the only method
+    // on DynamicResourceLoader that does anything with the path.  As such, the
+    // empty string is a perfectly fine value.
+    this("");
+  }
+
   /**
    * Constructs a dynamic resouce loader for this path which serves up translations
    * 

Added: myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/resource/CoreRenderKitResourceLoaderTest.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/resource/CoreRenderKitResourceLoaderTest.java?rev=1412206&view=auto
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/resource/CoreRenderKitResourceLoaderTest.java (added)
+++ myfaces/trinidad/trunk/trinidad-impl/src/test/java/org/apache/myfaces/trinidadinternal/resource/CoreRenderKitResourceLoaderTest.java Wed Nov 21 17:38:45 2012
@@ -0,0 +1,45 @@
+/*
+ * 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.myfaces.trinidadinternal.resource;
+
+import junit.framework.TestCase;
+
+public class CoreRenderKitResourceLoaderTest extends TestCase
+{
+  public CoreRenderKitResourceLoaderTest(String name)
+  {
+    super(name);
+  }
+
+  /**
+   * This test verifies that the CoreRenderKitResourceLoader can be constructed
+   * without requiring a dependency on the FacesContext.
+   * 
+   * See:
+   * 
+   * TRINIDAD-2340 LocaleElementsResourceLoader init dependency on request path
+   * 
+   * For details on why ResourceLoaders should not attempt to perform
+   * request-specific operations during construction.
+   */
+  public void testNoFacesContextDependencyAtConstruction()
+  {
+    new CoreRenderKitResourceLoader(null);
+  }
+}