-Moving AjaxHandler to spring-js

-Polishing Spring.js API
-Refactoring spring-faces components to match Spring.js API changes.
This commit is contained in:
Jeremy Grelle
2008-04-22 22:28:11 +00:00
parent 0f3d983587
commit 7d3e1d611b
23 changed files with 308 additions and 215 deletions

View File

@@ -39,5 +39,6 @@
<classpathentry kind="var" path="IVY_CACHE/org.springframework/spring-webmvc-portlet/spring-webmvc-portlet-2.5.3.jar" sourcepath="IVY_CACHE/org.springframework/spring-webmvc-portlet/spring-webmvc-portlet-sources-2.5.3.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.springframework.security/spring-security-core/spring-security-core-2.0.0.m2.jar" sourcepath="IVY_CACHE/org.springframework.security/spring-security-core/spring-security-core-sources-2.0.0.m2.jar"/>
<classpathentry kind="var" path="IVY_CACHE/edu.emory.mathcs/backport-util-concurrent/backport-util-concurrent-3.0.0.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/spring-js"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -28,6 +28,7 @@
<dependency org="org.springframework" name="spring-web" rev="2.5.3" conf="compile->default"/>
<dependency org="org.springframework" name="spring-webmvc" rev="2.5.3" conf="compile->default"/>
<dependency org="org.springframework.webflow" name="spring-binding" rev="latest.integration" conf="compile->compile"/>
<dependency org="org.springframework.webflow" name="spring-js" rev="latest.integration" conf="compile->compile"/>
<!-- testing support only dependencies -->
<dependency org="org.junit" name="junit" rev="3.8.2" conf="compile, test->default" />

View File

@@ -1,46 +0,0 @@
/*
* Copyright 2004-2008 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.webflow.mvc.servlet;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Strategy interface that encapsulates knowledge about a client-side ajax system and how to communicate with that
* system.
* @author Keith Donald
*/
public interface AjaxHandler {
/**
* Is the current request an Ajax request?
* @param request the current request
*/
public boolean isAjaxRequest(ServletContext context, HttpServletRequest request, HttpServletResponse response);
/**
* Send a redirect request to the Ajax client. This should cause the client-side agent to send a new request to the
* specified target url.
* @param response the response object
* @param targetUrl the target url to redirect to
* @param popup wheter the redirect should be sent from a new popup dialog window
*/
public void sendAjaxRedirect(ServletContext context, HttpServletRequest request, HttpServletResponse response,
String targetUrl, boolean popup) throws IOException;
}

View File

@@ -25,6 +25,8 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.js.mvc.servlet.AjaxHandler;
import org.springframework.js.mvc.servlet.SpringJavascriptAjaxHandler;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import org.springframework.web.servlet.view.RedirectView;

View File

@@ -24,6 +24,8 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.js.mvc.servlet.AjaxHandler;
import org.springframework.js.mvc.servlet.SpringJavascriptAjaxHandler;
import org.springframework.web.context.support.WebApplicationObjectSupport;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.ModelAndView;

View File

@@ -1,72 +0,0 @@
/*
* Copyright 2004-2008 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.webflow.mvc.servlet;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.util.StringUtils;
/**
* Ajax handler for Spring Javascript (Spring.js).
*
* @author Jeremy Grelle
* @author Keith Donald
*/
public class SpringJavascriptAjaxHandler implements AjaxHandler {
/**
* The response header to be set on an Ajax redirect
*/
private static final String FLOW_REDIRECT_URL_HEADER = "Flow-Redirect-URL";
/**
* The response header to be set on an redirect that should be issued from a popup window.
*/
private static final String POPUP_VIEW_HEADER = "Flow-Modal-View";
/**
* The accept header value that signifies an Ajax request.
*/
private static final String AJAX_ACCEPT_CONTENT_TYPE = "text/html;type=ajax";
/**
* Alternate request parameter to indicate an Ajax request for cases when control of the header is not available.
*/
private static final String AJAX_SOURCE_PARAM = "ajaxSource";
public boolean isAjaxRequest(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
String acceptHeader = request.getHeader("Accept");
String ajaxParam = request.getParameter(AJAX_SOURCE_PARAM);
if (AJAX_ACCEPT_CONTENT_TYPE.equals(acceptHeader) || StringUtils.hasText(ajaxParam)) {
return true;
} else {
return false;
}
}
public void sendAjaxRedirect(ServletContext context, HttpServletRequest request, HttpServletResponse response,
String targetUrl, boolean popup) throws IOException {
if (popup) {
response.setHeader(POPUP_VIEW_HEADER, "true");
}
response.setHeader(FLOW_REDIRECT_URL_HEADER, response.encodeRedirectURL(targetUrl));
}
}

View File

@@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletResponse;
import junit.framework.TestCase;
import org.easymock.EasyMock;
import org.springframework.js.mvc.servlet.SpringJavascriptAjaxHandler;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletContext;