You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2018/01/10 09:59:16 UTC
svn commit: r1820727 - in /myfaces/core/branches/2.3.x/impl/src:
main/java/org/apache/myfaces/resource/
test/java/org/apache/myfaces/view/facelets/
test/resources/org/apache/myfaces/view/facelets/
test/resources/org/apache/myfaces/view/facelets/resourc...
Author: tandraschko
Date: Wed Jan 10 09:59:16 2018
New Revision: 1820727
URL: http://svn.apache.org/viewvc?rev=1820727&view=rev
Log:
MYFACES-4175 template XHTML file fails to load when in /resources dir
Added:
myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/view/facelets/TemplateInResourcesDirTestCase.java
myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/resources/
myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/resources/templates/
myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/resources/templates/basicTemplate.xhtml
myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/templateInResourcesDir.xhtml
Modified:
myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/resource/RootExternalContextResourceLoader.java
Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/resource/RootExternalContextResourceLoader.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/resource/RootExternalContextResourceLoader.java?rev=1820727&r1=1820726&r2=1820727&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/resource/RootExternalContextResourceLoader.java (original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/resource/RootExternalContextResourceLoader.java Wed Jan 10 09:59:16 2018
@@ -21,7 +21,6 @@ package org.apache.myfaces.resource;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import javax.faces.application.ResourceHandler;
@@ -66,12 +65,7 @@ public class RootExternalContextResource
protected Set<String> getResourcePaths(String path)
{
String correctedPath = path.startsWith("/") ? path : '/' + path;
-
- if (correctedPath.startsWith(contractsDirectory) || correctedPath.startsWith(resourcesDirectory))
- {
- // Resources under this directory should be accesed by other ContractResourceLoader
- return Collections.emptySet();
- }
+
return FacesContext.getCurrentInstance().getExternalContext().getResourcePaths(correctedPath);
}
@@ -93,16 +87,10 @@ public class RootExternalContextResource
try
{
String correctedResourceId = resourceId.startsWith("/") ? resourceId : "/"+resourceId;
- if (correctedResourceId.startsWith(contractsDirectory) ||
- correctedResourceId.startsWith(resourcesDirectory))
- {
- return null;
- }
- else
- {
- return FacesContext.getCurrentInstance().getExternalContext().getResource(
- correctedResourceId);
- }
+
+ return FacesContext.getCurrentInstance().getExternalContext().getResource(
+ correctedResourceId);
+
}
catch (MalformedURLException e)
{
@@ -127,10 +115,7 @@ public class RootExternalContextResource
{
String resourceId = resourceMeta.getResourceIdentifier();
String correctedResourceId = resourceId.startsWith("/") ? resourceId : "/"+resourceId;
- if (correctedResourceId.startsWith(contractsDirectory) || correctedResourceId.startsWith(resourcesDirectory))
- {
- return null;
- }
+
return FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream(correctedResourceId);
}
Added: myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/view/facelets/TemplateInResourcesDirTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/view/facelets/TemplateInResourcesDirTestCase.java?rev=1820727&view=auto
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/view/facelets/TemplateInResourcesDirTestCase.java (added)
+++ myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/view/facelets/TemplateInResourcesDirTestCase.java Wed Jan 10 09:59:16 2018
@@ -0,0 +1,65 @@
+/*
+ * 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.view.facelets;
+
+import javax.el.ExpressionFactory;
+
+import org.apache.myfaces.mc.test.core.AbstractMyFacesRequestTestCase;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test cases for issue MYFACES-4175.
+ *
+ * @author Jay Sartoris
+ */
+
+public class TemplateInResourcesDirTestCase extends AbstractMyFacesRequestTestCase
+{
+
+ @Override
+ protected boolean isScanAnnotations()
+ {
+ return true;
+ }
+
+ @Override
+ protected void setUpWebConfigParams() throws Exception
+ {
+ super.setUpWebConfigParams();
+ servletContext.addInitParameter("org.apache.myfaces.annotation.SCAN_PACKAGES","org.apache.myfaces.view.facelets");
+ }
+
+ protected ExpressionFactory createExpressionFactory()
+ {
+ return new org.apache.el.ExpressionFactoryImpl();
+ }
+
+ @Test
+ public void testFaceletWithTemplateInResourcesDir() throws Exception
+ {
+ startViewRequest("/templateInResourcesDir.xhtml");
+ processLifecycleExecuteAndRender();
+
+ String text = getRenderedContent(facesContext);
+ Assert.assertTrue(text.contains("This template is working as expected!"));
+
+ endRequest();
+ }
+}
Added: myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/resources/templates/basicTemplate.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/resources/templates/basicTemplate.xhtml?rev=1820727&view=auto
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/resources/templates/basicTemplate.xhtml (added)
+++ myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/resources/templates/basicTemplate.xhtml Wed Jan 10 09:59:16 2018
@@ -0,0 +1,37 @@
+<!--
+ 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.
+
+ $Id: basicTemplate.xhtml
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://xmlns.jcp.org/jsf/html"
+ xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
+
+<h:head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <title>Facelets Template</title>
+</h:head>
+<h:body>
+ <div id="title" class="title">
+ <ui:insert name="title">Title</ui:insert>
+ </div>
+ <div id="content" class="center_content">
+ <ui:insert name="content">Content</ui:insert>
+ </div>
+ <div id="info" class="info">
+ <ui:insert name="info">Content</ui:insert>
+ </div>
+</h:body>
+</html>
Added: myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/templateInResourcesDir.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/templateInResourcesDir.xhtml?rev=1820727&view=auto
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/templateInResourcesDir.xhtml (added)
+++ myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/templateInResourcesDir.xhtml Wed Jan 10 09:59:16 2018
@@ -0,0 +1,36 @@
+<!--
+ 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.
+
+ $Id: templateInResourcesDir.xhtml
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://xmlns.jcp.org/jsf/html"
+ xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
+
+<h:head>
+ <title>MyFaces test for using a template in the resources directory</title>
+</h:head>
+<h:body>
+ <!-- Testing that a template file cannot be located in the resources dir -->
+ <ui:composition template="/resources/templates/basicTemplate.xhtml">
+ <ui:define name="title">
+ Using a template inside /resources/templates
+ </ui:define>
+ <ui:define name="content">
+ This template is working as expected!
+ </ui:define>
+ </ui:composition>
+</h:body>
+</html>
\ No newline at end of file