You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2015/02/18 20:05:14 UTC

svn commit: r1660699 - in /myfaces/tobago/trunk/tobago-core/src: main/java/org/apache/myfaces/tobago/internal/util/ test/java/org/apache/myfaces/tobago/internal/config/ test/java/org/apache/myfaces/tobago/internal/util/ test/resources/

Author: lofwyr
Date: Wed Feb 18 19:05:14 2015
New Revision: 1660699

URL: http://svn.apache.org/r1660699
Log:
TOBAGO-1433: Supported resource types should be configurable

Added:
    myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-for-unit-tests.xml
      - copied, changed from r1660683, myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-2.0.xml
Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/MimeTypeUtils.java
    myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/AbstractTobagoTestBase.java
    myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigMergingUnitTest.java
    myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/util/MimeTypeUtilsUnitTest.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/MimeTypeUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/MimeTypeUtils.java?rev=1660699&r1=1660698&r2=1660699&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/MimeTypeUtils.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/MimeTypeUtils.java Wed Feb 18 19:05:14 2015
@@ -79,11 +79,17 @@ public final class MimeTypeUtils {
       }
     }
 
-    if(ADDITIONAL_MIME_TYPES == null) {
+    if (ADDITIONAL_MIME_TYPES == null) {
       final TobagoConfig tobagoConfig = TobagoConfig.getInstance(FacesContext.getCurrentInstance());
       ADDITIONAL_MIME_TYPES = tobagoConfig.getMimeTypes();
     }
 
+    final int index = file.lastIndexOf('.');
+    if (index > -1) {
+      String extension = file.substring(index + 1);
+      return ADDITIONAL_MIME_TYPES.get(extension);
+    }
+
     return null;
   }
 }

Modified: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/AbstractTobagoTestBase.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/AbstractTobagoTestBase.java?rev=1660699&r1=1660698&r2=1660699&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/AbstractTobagoTestBase.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/AbstractTobagoTestBase.java Wed Feb 18 19:05:14 2015
@@ -70,7 +70,7 @@ public abstract class AbstractTobagoTest
 
     // Tobago specific extensions
 
-    final TobagoConfigImpl tobagoConfig = new TobagoConfigImpl();
+    final TobagoConfigImpl tobagoConfig = TobagoConfigMergingUnitTest.loadAndMerge("tobago-config-for-unit-tests.xml");
     final Theme theme = new MockTheme("default", "Default Mock Theme", Collections.<Theme>emptyList());
     final Theme one = new MockTheme("one", "Mock Theme One", Arrays.asList(theme));
     final Map<String, Theme> availableThemes = new HashMap<String, Theme>();

Modified: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigMergingUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigMergingUnitTest.java?rev=1660699&r1=1660698&r2=1660699&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigMergingUnitTest.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigMergingUnitTest.java Wed Feb 18 19:05:14 2015
@@ -117,13 +117,13 @@ public class TobagoConfigMergingUnitTest
     Assert.assertEquals("test/three", mimeTypes.get("test-3"));
   }
 
-  private TobagoConfigImpl loadAndMerge(final String... names)
+  public static TobagoConfigImpl loadAndMerge(final String... names)
       throws IOException, SAXException, ParserConfigurationException, URISyntaxException {
 
     final List<TobagoConfigFragment> list = new ArrayList<TobagoConfigFragment>();
 
     for (final String name : names) {
-      final URL url = getClass().getClassLoader().getResource(name);
+      final URL url = TobagoConfigMergingUnitTest.class.getClassLoader().getResource(name);
       final TobagoConfigParser parser = new TobagoConfigParser();
       list.add(parser.parse(url));
     }

Modified: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/util/MimeTypeUtilsUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/util/MimeTypeUtilsUnitTest.java?rev=1660699&r1=1660698&r2=1660699&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/util/MimeTypeUtilsUnitTest.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/util/MimeTypeUtilsUnitTest.java Wed Feb 18 19:05:14 2015
@@ -46,6 +46,7 @@ public class MimeTypeUtilsUnitTest exten
   public static final String UNKNOWN2 = "http:///localhost:8080/demo/demo.ggif";
   public static final String UNKNOWN3 = "http:///localhost:8080/demo/demos.ppg";
   public static final String UNKNOWN4 = "http:///localhost:8080/demo/demos.pngx";
+  public static final String UNKNOWN5 = "http:///localhost:8080/demo/demos.png.";
 
   @Test
   public void testMimeTypes() {
@@ -72,15 +73,14 @@ public class MimeTypeUtilsUnitTest exten
     Assert.assertEquals(null, MimeTypeUtils.getMimeTypeForFile(UNKNOWN2));
     Assert.assertEquals(null, MimeTypeUtils.getMimeTypeForFile(UNKNOWN3));
     Assert.assertEquals(null, MimeTypeUtils.getMimeTypeForFile(UNKNOWN4));
+    Assert.assertEquals(null, MimeTypeUtils.getMimeTypeForFile(UNKNOWN5));
   }
 
-/*
   @Test
   public void testMimeTypesConfigured() {
 
     Assert.assertEquals("application/vnd.oasis.opendocument.text", MimeTypeUtils.getMimeTypeForFile(ODT));
   }
-*/
 
 //  @Test
   public void testPerformance() {

Copied: myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-for-unit-tests.xml (from r1660683, myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-2.0.xml)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-for-unit-tests.xml?p2=myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-for-unit-tests.xml&p1=myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-2.0.xml&r1=1660683&r2=1660699&rev=1660699&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-2.0.xml (original)
+++ myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-for-unit-tests.xml Wed Feb 18 19:05:14 2015
@@ -20,83 +20,14 @@
 <tobago-config
     xmlns="http://myfaces.apache.org/tobago/tobago-config"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="http://myfaces.apache.org/tobago/tobago-config http://myfaces.apache.org/tobago/tobago-config-2.0.xsd"
-    version="2.0">
+    xsi:schemaLocation="http://myfaces.apache.org/tobago/tobago-config http://myfaces.apache.org/tobago/tobago-config-2.0.6.xsd"
+    version="2.0.6">
 
-  <name>my-name</name>
-
-  <ordering>
-    <after>
-      <name>my-after</name>
-    </after>
-    <before>
-      <name>my-before-1</name>
-      <name>my-before-2</name>
-    </before>
-  </ordering>
-
-  <theme-config>
-    <default-theme>speyside</default-theme>
-    <supported-theme>scarborough</supported-theme>
-    <supported-theme>standard</supported-theme>
-  </theme-config>
-
-  <resource-dir>my-resource-1</resource-dir>
-  <resource-dir>my-resource-2</resource-dir>
-
-  <create-session-secret>false</create-session-secret>
-  <check-session-secret>false</check-session-secret>
-  <prevent-frame-attacks>false</prevent-frame-attacks>
-  <set-nosniff-header>false</set-nosniff-header>
-
-  <content-security-policy mode="on">
-    <directive>default-src 'self'</directive>
-    <directive>frame-src http://apache.org</directive>
-  </content-security-policy>
-
-  <renderers>
-    <renderer>
-      <name>MyRenderer-1</name>
-      <supported-markup>
-        <markup>my-markup-1</markup>
-      </supported-markup>
-    </renderer>
-    <renderer>
-      <name>MyRenderer-2</name>
-      <supported-markup>
-        <markup>my-markup-2-1</markup>
-        <markup>my-markup-2-2</markup>
-      </supported-markup>
-    </renderer>
-  </renderers>
-
-  <theme-definitions>
-    <theme-definition>
-      <name>my-theme-1</name>
-      <display-name>My Theme 1</display-name>
-      <resource-path>/my/path-1</resource-path>
-      <versioned>true</versioned>
-      <renderers>
-        <renderer>
-          <name>ThemeRenderer</name>
-          <supported-markup>
-            <markup>theme-markup</markup>
-          </supported-markup>
-        </renderer>
-      </renderers>
-      <resources production="true">
-        <script name="script.js"/>
-        <style name="style.css"/>
-      </resources>
-    </theme-definition>
-
-    <theme-definition>
-      <name>my-theme-2</name>
-      <resource-path>/my/path-2</resource-path>
-      <fallback>my-theme-1</fallback>
-      <resources production="false"/>
-    </theme-definition>
-
-  </theme-definitions>
+  <mime-types>
+    <mime-type>
+      <extension>odt</extension>
+      <type>application/vnd.oasis.opendocument.text</type>
+    </mime-type>
+  </mime-types>
 
 </tobago-config>