From 7b2ab7587c66683002fc51058352e881a55a96f3 Mon Sep 17 00:00:00 2001
From: Rossen Stoyanchev
Date: Tue, 21 Sep 2010 12:10:47 +0000
Subject: [PATCH] Fixes after testing with Apache MyFaces 2
---
.../SpringSecurityJsf12TagLibrary.java | 53 -------------------
.../security/SpringSecurityTagLibrary.java | 53 -------------------
.../faces/webflow/FlowRenderKit.java | 6 ++-
.../faces/webflow/FlowViewStateManager.java | 6 +--
.../faces/webflow/JsfAjaxHandler.java | 46 +++++++---------
.../faces/webflow/JsfRuntimeInformation.java | 7 +++
.../webapp/WEB-INF/springsecurity.taglib.xml | 21 +++++++-
.../src/main/webapp/WEB-INF/web.xml | 10 ++++
8 files changed, 62 insertions(+), 140 deletions(-)
delete mode 100644 spring-faces/src/main/java/org/springframework/faces/security/SpringSecurityJsf12TagLibrary.java
delete mode 100644 spring-faces/src/main/java/org/springframework/faces/security/SpringSecurityTagLibrary.java
diff --git a/spring-faces/src/main/java/org/springframework/faces/security/SpringSecurityJsf12TagLibrary.java b/spring-faces/src/main/java/org/springframework/faces/security/SpringSecurityJsf12TagLibrary.java
deleted file mode 100644
index ceebc911..00000000
--- a/spring-faces/src/main/java/org/springframework/faces/security/SpringSecurityJsf12TagLibrary.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.security;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-
-import com.sun.facelets.tag.AbstractTagLibrary;
-
-/**
- * Registers a tag handler for the <authorize> tag and several EL functions that can be used on any component that
- * accepts EL expressions in its attributes. For details on the EL functions see {@link Jsf12FaceletsAuthorizeTagUtils}.
- *
- * @author Rossen Stoyanchev
- * @since 2.2.0
- * @see Jsf12FaceletsAuthorizeTagHandler
- * @see Jsf12FaceletsAuthorizeTagUtils
- */
-public class SpringSecurityJsf12TagLibrary extends AbstractTagLibrary {
-
- public static final String NAMESPACE = "http://www.springframework.org/security/tags";
-
- public SpringSecurityJsf12TagLibrary() {
- super(NAMESPACE);
-
- this.addTagHandler("authorize", Jsf12FaceletsAuthorizeTagHandler.class);
-
- try {
- Method[] methods = Jsf12FaceletsAuthorizeTagUtils.class.getMethods();
- for (int i = 0; i < methods.length; i++) {
- if (Modifier.isStatic(methods[i].getModifiers())) {
- this.addFunction(methods[i].getName(), methods[i]);
- }
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
-}
diff --git a/spring-faces/src/main/java/org/springframework/faces/security/SpringSecurityTagLibrary.java b/spring-faces/src/main/java/org/springframework/faces/security/SpringSecurityTagLibrary.java
deleted file mode 100644
index b874b5db..00000000
--- a/spring-faces/src/main/java/org/springframework/faces/security/SpringSecurityTagLibrary.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.security;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-
-import com.sun.faces.facelets.tag.AbstractTagLibrary;
-
-/**
- * Registers a tag handler for the <authorize> tag and several EL functions that can be used on any component that
- * accepts EL expressions in its attributes. For details on the EL functions see {@link FaceletsAuthorizeTagUtils}.
- *
- * @author Rossen Stoyanchev
- * @since 2.2.0
- * @see FaceletsAuthorizeTagHandler
- * @see FaceletsAuthorizeTagUtils
- */
-public class SpringSecurityTagLibrary extends AbstractTagLibrary {
-
- public static final String NAMESPACE = "http://www.springframework.org/security/tags";
-
- public SpringSecurityTagLibrary() {
- super(NAMESPACE);
-
- this.addTagHandler("authorize", FaceletsAuthorizeTagHandler.class);
-
- try {
- Method[] methods = FaceletsAuthorizeTagUtils.class.getMethods();
- for (int i = 0; i < methods.length; i++) {
- if (Modifier.isStatic(methods[i].getModifiers())) {
- this.addFunction(methods[i].getName(), methods[i]);
- }
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
-}
diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowRenderKit.java b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowRenderKit.java
index bcf3420b..98f53dcd 100644
--- a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowRenderKit.java
+++ b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowRenderKit.java
@@ -20,6 +20,9 @@ package org.springframework.faces.webflow;
* writing JSF state and manages that in Web Flow's view scope. The FlowViewResponseStateManager is plugged in only in a
* JSF 2 environment.
*
+ * Note that partial state saving in Apache MyFaces is not yet supported. Use the javax.faces.PARTIAL_STATE_SAVING context
+ * parameter in web.xml to disable it.
+ *
* @author Rossen Stoyanchev
* @since 2.2.0
*/
@@ -49,7 +52,8 @@ public class FlowRenderKit extends RenderKitWrapper {
* ResponseStateManager instance otherwise.
*/
public ResponseStateManager getResponseStateManager() {
- return (JsfRuntimeInformation.isAtLeastJsf20()) ? responseStateManager : delegate.getResponseStateManager();
+ return (JsfRuntimeInformation.isPartialStateSavingSupported()) ? responseStateManager : delegate
+ .getResponseStateManager();
}
}
diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowViewStateManager.java b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowViewStateManager.java
index fcbacb15..74037264 100644
--- a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowViewStateManager.java
+++ b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowViewStateManager.java
@@ -15,8 +15,6 @@
*/
package org.springframework.faces.webflow;
-import static org.springframework.faces.webflow.JsfRuntimeInformation.isAtLeastJsf20;
-
import java.io.IOException;
import javax.faces.application.StateManager;
@@ -165,7 +163,7 @@ public class FlowViewStateManager extends StateManager {
if (context.getViewRoot().isTransient()) {
return null;
}
- if ((!JsfUtils.isFlowRequest()) || isAtLeastJsf20()) {
+ if ((!JsfUtils.isFlowRequest()) || JsfRuntimeInformation.isPartialStateSavingSupported()) {
return delegate.saveView(context);
} else {
RequestContext requestContext = RequestContextHolder.getRequestContext();
@@ -188,7 +186,7 @@ public class FlowViewStateManager extends StateManager {
*
*/
public UIViewRoot restoreView(FacesContext context, String viewId, String renderKitId) {
- if ((!JsfUtils.isFlowRequest()) || isAtLeastJsf20()) {
+ if ((!JsfUtils.isFlowRequest()) || JsfRuntimeInformation.isPartialStateSavingSupported()) {
return delegate.restoreView(context, viewId, renderKitId);
} else {
UIViewRoot viewRoot = restoreTreeStructure(context, viewId, renderKitId);
diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/JsfAjaxHandler.java b/spring-faces/src/main/java/org/springframework/faces/webflow/JsfAjaxHandler.java
index 4f2102f9..58f37c26 100644
--- a/spring-faces/src/main/java/org/springframework/faces/webflow/JsfAjaxHandler.java
+++ b/spring-faces/src/main/java/org/springframework/faces/webflow/JsfAjaxHandler.java
@@ -16,11 +16,13 @@
package org.springframework.faces.webflow;
import java.io.IOException;
+import java.io.Writer;
import javax.faces.FactoryFinder;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
-import javax.faces.context.FacesContextWrapper;
import javax.faces.context.PartialResponseWriter;
+import javax.faces.context.ResponseWriter;
import javax.faces.render.RenderKit;
import javax.faces.render.RenderKitFactory;
import javax.servlet.http.HttpServletRequest;
@@ -28,8 +30,6 @@ import javax.servlet.http.HttpServletResponse;
import org.springframework.js.ajax.AbstractAjaxHandler;
-import com.sun.faces.context.PartialViewContextImpl;
-
/**
* Ajax handler for JSF 2 requests that can identify JSF 2 Ajax requests and send redirect instructions back to the
* client by including a redirect instruction in the content of the response.
@@ -66,9 +66,7 @@ public class JsfAjaxHandler extends AbstractAjaxHandler {
FacesContextHelper helper = new FacesContextHelper();
try {
FacesContext facesContext = helper.getFacesContext(getServletContext(), request, response);
- facesContext = new FixedRenderKitFacesContext(facesContext, determineRenderKitId(request, response));
- PartialViewContextImpl partialViewContext = new PartialViewContextImpl(facesContext);
- PartialResponseWriter writer = partialViewContext.getPartialResponseWriter();
+ PartialResponseWriter writer = createPartialResponseWriter(facesContext);
writer.startDocument();
writer.redirect(targetUrl);
writer.endDocument();
@@ -77,29 +75,21 @@ public class JsfAjaxHandler extends AbstractAjaxHandler {
}
}
- protected String determineRenderKitId(HttpServletRequest request, HttpServletResponse response) {
- return RenderKitFactory.HTML_BASIC_RENDER_KIT;
- }
-
- private class FixedRenderKitFacesContext extends FacesContextWrapper {
-
- private FacesContext delegate;
- private String renderKitId;
-
- public FixedRenderKitFacesContext(FacesContext delegate, String renderKitId) {
- this.delegate = delegate;
- this.renderKitId = renderKitId;
- }
-
- @Override
- public FacesContext getWrapped() {
- return this.delegate;
- }
-
- @Override
- public RenderKit getRenderKit() {
+ private PartialResponseWriter createPartialResponseWriter(FacesContext context) throws IOException {
+ ExternalContext externalContext = context.getExternalContext();
+ String encoding = externalContext.getRequestCharacterEncoding();
+ externalContext.setResponseCharacterEncoding(encoding);
+ ResponseWriter responseWriter = null;
+ Writer out = externalContext.getResponseOutputWriter();
+ if (out != null) {
RenderKitFactory factory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- return factory.getRenderKit(this, renderKitId);
+ RenderKit renderKit = factory.getRenderKit(context, RenderKitFactory.HTML_BASIC_RENDER_KIT);
+ responseWriter = renderKit.createResponseWriter(out, "text/xml", encoding);
+ }
+ if (responseWriter instanceof PartialResponseWriter) {
+ return (PartialResponseWriter) responseWriter;
+ } else {
+ return new PartialResponseWriter(responseWriter);
}
}
diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/JsfRuntimeInformation.java b/spring-faces/src/main/java/org/springframework/faces/webflow/JsfRuntimeInformation.java
index 23813c08..84b5042e 100644
--- a/spring-faces/src/main/java/org/springframework/faces/webflow/JsfRuntimeInformation.java
+++ b/spring-faces/src/main/java/org/springframework/faces/webflow/JsfRuntimeInformation.java
@@ -77,4 +77,11 @@ public class JsfRuntimeInformation {
"getPortletContextName"));
}
+ /**
+ * Returns true if Web Flow supports partial state saving in the current runtime environment.
+ */
+ public static boolean isPartialStateSavingSupported() {
+ return (JsfRuntimeInformation.isAtLeastJsf20() && (!JsfRuntimeInformation.isMyFacesPresent()));
+ }
+
}
\ No newline at end of file
diff --git a/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/springsecurity.taglib.xml b/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/springsecurity.taglib.xml
index 5455cb2f..66652c00 100644
--- a/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/springsecurity.taglib.xml
+++ b/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/springsecurity.taglib.xml
@@ -3,5 +3,24 @@
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
- org.springframework.faces.security.SpringSecurityTagLibrary
+ http://www.springframework.org/security/tags
+
+ authorize
+ org.springframework.faces.security.FaceletsAuthorizeTagHandler
+
+
+ areAllGranted
+ org.springframework.faces.security.FaceletsAuthorizeTagUtils
+ boolean areAllGranted(java.lang.String)
+
+
+ areAnyGranted
+ org.springframework.faces.security.FaceletsAuthorizeTagUtils
+ boolean areAnyGranted(java.lang.String)
+
+
+ areNotGranted
+ org.springframework.faces.security.FaceletsAuthorizeTagUtils
+ boolean areNotGranted(java.lang.String)
+
\ No newline at end of file
diff --git a/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/web.xml b/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/web.xml
index fc605504..780b2d1b 100755
--- a/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/web.xml
+++ b/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/web.xml
@@ -29,6 +29,16 @@
javax.faces.FACELETS_REFRESH_PERIOD
1
+
+
+
+
+ javax.faces.PARTIAL_STATE_SAVING
+ false
+
+