SWF-1378 Create FlowResourceResolver for JSF 1.2 and 2.0 environments
This commit is contained in:
@@ -29,5 +29,6 @@
|
||||
<classpathentry kind="var" path="IVY_CACHE/org.springframework/org.springframework.test/3.0.3.RELEASE/org.springframework.test-3.0.3.RELEASE.jar" sourcepath="IVY_CACHE/org.springframework/org.springframework.test/3.0.3.RELEASE/org.springframework.test-sources-3.0.3.RELEASE.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/org.springframework/org.springframework.web/3.0.3.RELEASE/org.springframework.web-3.0.3.RELEASE.jar" sourcepath="IVY_CACHE/org.springframework/org.springframework.web/3.0.3.RELEASE/org.springframework.web-sources-3.0.3.RELEASE.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/org.springframework/org.springframework.web.servlet/3.0.3.RELEASE/org.springframework.web.servlet-3.0.3.RELEASE.jar" sourcepath="IVY_CACHE/org.springframework/org.springframework.web.servlet/3.0.3.RELEASE/org.springframework.web.servlet-sources-3.0.3.RELEASE.jar"/>
|
||||
<classpathentry kind="var" path="IVY_CACHE/com.sun.facelets/com.springsource.com.sun.facelets/1.1.14/com.springsource.com.sun.facelets-1.1.14.jar" sourcepath="/IVY_CACHE/com.sun.facelets/com.springsource.com.sun.facelets/1.1.14/com.springsource.com.sun.facelets-sources-1.1.14.jar"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
||||
@@ -19,16 +19,29 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.faces.FacesException;
|
||||
import javax.faces.view.facelets.ResourceResolver;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.RequestContextHolder;
|
||||
|
||||
import com.sun.faces.facelets.impl.DefaultResourceResolver;
|
||||
import com.sun.facelets.impl.DefaultResourceResolver;
|
||||
import com.sun.facelets.impl.ResourceResolver;
|
||||
|
||||
public class FlowResourceResolver extends ResourceResolver {
|
||||
/**
|
||||
* Resolves Facelets templates using Spring Resource paths such as "classpath:foo.xhtml". Configure it via a context
|
||||
* parameter in web.xml:
|
||||
*
|
||||
* <pre>
|
||||
* <context-param/>
|
||||
* <param-name>facelets.RESOURCE_RESOLVER</param-name>
|
||||
* <param-value>org.springframework.faces.webflow.FlowResourceResolver</param-value>
|
||||
* </context-param>
|
||||
* </pre>
|
||||
*
|
||||
* @see Jsf2FlowResourceResolver
|
||||
*/
|
||||
public class FlowResourceResolver implements ResourceResolver {
|
||||
|
||||
ResourceResolver delegateResolver = new DefaultResourceResolver();
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2004-2010 the original author or authors.
|
||||
*
|
||||
* 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.springframework.faces.webflow;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.faces.FacesException;
|
||||
import javax.faces.view.facelets.ResourceResolver;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.RequestContextHolder;
|
||||
|
||||
import com.sun.faces.facelets.impl.DefaultResourceResolver;
|
||||
|
||||
/**
|
||||
* Resolves Facelets templates using Spring Resource paths such as "classpath:foo.xhtml". Configure it via a context
|
||||
* parameter in web.xml:
|
||||
*
|
||||
* <pre>
|
||||
* <context-param/>
|
||||
* <param-name>facelets.RESOURCE_RESOLVER</param-name>
|
||||
* <param-value>org.springframework.faces.webflow.FlowResourceResolver</param-value>
|
||||
* </context-param>
|
||||
* </pre>
|
||||
*/
|
||||
public class Jsf2FlowResourceResolver extends ResourceResolver {
|
||||
|
||||
ResourceResolver delegateResolver = new DefaultResourceResolver();
|
||||
|
||||
public URL resolveUrl(String path) {
|
||||
|
||||
if (!JsfUtils.isFlowRequest()) {
|
||||
return delegateResolver.resolveUrl(path);
|
||||
}
|
||||
|
||||
try {
|
||||
RequestContext context = RequestContextHolder.getRequestContext();
|
||||
ApplicationContext flowContext = context.getActiveFlow().getApplicationContext();
|
||||
if (flowContext == null) {
|
||||
throw new IllegalStateException("A Flow ApplicationContext is required to resolve Flow View Resources");
|
||||
}
|
||||
|
||||
ApplicationContext appContext = flowContext.getParent();
|
||||
Resource viewResource = appContext.getResource(path);
|
||||
if (viewResource.exists()) {
|
||||
return viewResource.getURL();
|
||||
} else {
|
||||
return delegateResolver.resolveUrl(path);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new FacesException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user