All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.js.ajax.SpringJavascriptAjaxHandler Maven / Gradle / Ivy

/*
 * 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.js.ajax;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.util.StringUtils;

/**
 * Ajax handler for Spring Javascript (Spring.js).
 *
 * @see AbstractAjaxHandler
 *
 * @author Jeremy Grelle
 * @author Keith Donald
 *
 * @deprecated as of version 2.4 Spring.js is deprecated
 */
public class SpringJavascriptAjaxHandler extends AbstractAjaxHandler {

	/**
	 * The response header to be set on an Ajax redirect
	 */
	public static final String REDIRECT_URL_HEADER = "Spring-Redirect-URL";

	/**
	 * The response header to be set on an redirect that should be issued from a popup window.
	 */
	public static final String POPUP_VIEW_HEADER = "Spring-Modal-View";

	/**
	 * The accept header value that signifies an Ajax request.
	 */
	public 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.
	 */
	public static final String AJAX_SOURCE_PARAM = "ajaxSource";

	/**
	 * Create a SpringJavascriptAjaxHandler that is not part of a chain of AjaxHandler's.
	 */
	public SpringJavascriptAjaxHandler() {
		this(null);
	}

	/**
	 * Create a SpringJavascriptAjaxHandler as part of a chain of AjaxHandler's.
	 */
	public SpringJavascriptAjaxHandler(AbstractAjaxHandler delegate) {
		super(delegate);
	}

	protected boolean isAjaxRequestInternal(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;
		}
	}

	protected void sendAjaxRedirectInternal(String targetUrl, HttpServletRequest request, HttpServletResponse response,
			boolean popup) throws IOException {
		if (popup) {
			response.setHeader(POPUP_VIEW_HEADER, "true");
		}
		response.setHeader(REDIRECT_URL_HEADER, response.encodeRedirectURL(targetUrl));
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy