From 5b0df65be41ef6778272898c4802e21764726240 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 6 Jan 2017 11:28:03 -0500 Subject: [PATCH] Fold spring-js + spring-js-tiles3 into spring-webflow Issue: SWF-1693 --- .gitignore | 1 - build.gradle | 80 +--- settings.gradle | 2 - .../faces/webflow/JsfAjaxHandler.java | 2 +- .../faces/webflow/JsfFlowHandlerAdapter.java | 4 +- .../webflow/JsfFlowHandlerAdapterTests.java | 6 +- .../js/ajax/tiles3/package-info.java | 21 - .../src/main/resources/.gitignore | 0 spring-js-tiles3/src/test/resources/log4j.xml | 48 -- .../springframework/js/ajax/package-info.java | 21 - .../js/resource/ResourceServlet.java | 423 ------------------ .../js/resource/package-info.java | 21 - spring-js/src/main/resources/.gitignore | 0 .../js/resource/ResourceServletTests.java | 98 ---- .../js/resource/TestResource1.js | 0 .../js/resource/TestResource2.js | 0 spring-js/src/test/resources/log4j.xml | 48 -- .../context/servlet}/AbstractAjaxHandler.java | 2 +- .../webflow/context/servlet}/AjaxHandler.java | 4 +- .../context/servlet/DefaultAjaxHandler.java | 69 ++- .../servlet/FilenameFlowUrlHandler.java | 5 +- .../webflow/mvc/servlet/FlowController.java | 2 +- .../mvc/servlet/FlowHandlerAdapter.java | 6 +- .../webflow/mvc/view/AjaxTiles3View.java | 12 +- .../mvc/view}/AjaxUrlBasedViewResolver.java | 6 +- .../webflow/mvc/view/FlowAjaxTiles3View.java | 10 +- .../servlet}/AbstractAjaxHandlerTests.java | 3 +- .../mvc/servlet/FlowControllerTests.java | 11 +- .../webflow/mvc/view/AjaxTiles3ViewTests.java | 48 +- .../webflow/mvc/view}/tiles-definitions.xml | 0 src/dist/readme.txt | 22 +- src/reference/overview.xml | 11 +- src/reference/spring-js.xml | 2 +- 33 files changed, 123 insertions(+), 865 deletions(-) delete mode 100644 spring-js-tiles3/src/main/java/org/springframework/js/ajax/tiles3/package-info.java delete mode 100644 spring-js-tiles3/src/main/resources/.gitignore delete mode 100644 spring-js-tiles3/src/test/resources/log4j.xml delete mode 100644 spring-js/src/main/java/org/springframework/js/ajax/package-info.java delete mode 100644 spring-js/src/main/java/org/springframework/js/resource/ResourceServlet.java delete mode 100644 spring-js/src/main/java/org/springframework/js/resource/package-info.java delete mode 100644 spring-js/src/main/resources/.gitignore delete mode 100644 spring-js/src/test/java/org/springframework/js/resource/ResourceServletTests.java delete mode 100644 spring-js/src/test/java/org/springframework/js/resource/TestResource1.js delete mode 100644 spring-js/src/test/java/org/springframework/js/resource/TestResource2.js delete mode 100644 spring-js/src/test/resources/log4j.xml rename {spring-js/src/main/java/org/springframework/js/ajax => spring-webflow/src/main/java/org/springframework/webflow/context/servlet}/AbstractAjaxHandler.java (96%) rename {spring-js/src/main/java/org/springframework/js/ajax => spring-webflow/src/main/java/org/springframework/webflow/context/servlet}/AjaxHandler.java (92%) rename spring-js/src/main/java/org/springframework/js/ajax/SpringJavascriptAjaxHandler.java => spring-webflow/src/main/java/org/springframework/webflow/context/servlet/DefaultAjaxHandler.java (50%) rename spring-js-tiles3/src/main/java/org/springframework/js/ajax/tiles3/AjaxTilesView.java => spring-webflow/src/main/java/org/springframework/webflow/mvc/view/AjaxTiles3View.java (95%) rename {spring-js/src/main/java/org/springframework/js/ajax => spring-webflow/src/main/java/org/springframework/webflow/mvc/view}/AjaxUrlBasedViewResolver.java (91%) rename {spring-js/src/test/java/org/springframework/js/ajax => spring-webflow/src/test/java/org/springframework/webflow/context/servlet}/AbstractAjaxHandlerTests.java (98%) rename spring-js-tiles3/src/test/java/org/springframework/js/ajax/tiles3/AjaxTilesViewTests.java => spring-webflow/src/test/java/org/springframework/webflow/mvc/view/AjaxTiles3ViewTests.java (79%) rename {spring-js-tiles3/src/test/java/org/springframework/js/ajax/tiles3 => spring-webflow/src/test/resources/org/springframework/webflow/mvc/view}/tiles-definitions.xml (100%) diff --git a/.gitignore b/.gitignore index 1f296998..00e7b2c5 100644 --- a/.gitignore +++ b/.gitignore @@ -26,5 +26,4 @@ out gradle-app.setting spring-binding/src/main/java/META-INF/ spring-faces/src/main/java/META-INF/ -spring-js/src/main/java/META-INF/ spring-webflow/src/main/java/META-INF/ diff --git a/build.gradle b/build.gradle index 419c7a17..8d65c165 100644 --- a/build.gradle +++ b/build.gradle @@ -147,43 +147,29 @@ project("spring-binding") { } } -project("spring-js") { - description = "Spring JS" +project("spring-webflow") { + description = "Spring Web Flow" dependencies { + compile(project(":spring-binding")) compile("commons-logging:commons-logging:1.1.1") + compile("opensymphony:ognl:2.6.11") compile("org.springframework:spring-beans:$springVersion") compile("org.springframework:spring-context:$springVersion") compile("org.springframework:spring-core:$springVersion") + compile("org.springframework:spring-expression:$springVersion") compile("org.springframework:spring-web:$springVersion") compile("org.springframework:spring-webmvc:$springVersion") + provided("javax.el:javax.el-api:2.2.5") provided("javax.servlet:javax.servlet-api:3.0.1") - testCompile("javax.servlet:jstl:1.2") { - exclude group: "org.slf4j", module: "jcl-over-slf4j" + provided("junit:junit:3.8.2") + optional("org.hibernate:hibernate-core:$hibernate5Version") { + exclude group: "org.slf4j", module: "slf4j-api" } - testCompile("log4j:log4j:$log4jVersion") { - exclude group: "javax.mail", module: "mail" - exclude group: "javax.jms", module: "jms" - exclude group: "com.sun.jdmk", module: "jmxtools" - exclude group: "com.sun.jmx", module: "jmxri" - } - testCompile("org.slf4j:jcl-over-slf4j:$slf4jVersion") - testCompile("org.slf4j:slf4j-api:$slf4jVersion") - testCompile("org.springframework:spring-test:$springVersion") - } -} - -project("spring-js-tiles3") { - description = "Spring JS Tiles 3 Integration" - merge.into = project(":spring-js") - - dependencies { - compile("commons-logging:commons-logging:1.1.1") - compile("org.springframework:spring-core:$springVersion") - compile("org.springframework:spring-webmvc:$springVersion") - optional("javax.el:javax.el-api:2.2.5") - optional("javax.servlet:javax.servlet-api:3.0.1") - optional("javax.servlet.jsp:javax.servlet.jsp-api:2.2.1") + optional("org.slf4j:slf4j-api:$slf4jVersion") + optional("org.springframework.security:spring-security-core:$springSecurityVersion") + optional("org.springframework:spring-orm:$springVersion") + optional("org.springframework:spring-tx:$springVersion") optional("org.apache.tiles:tiles-request-api:1.0.1") optional("org.apache.tiles:tiles-api:$tiles3Version") optional("org.apache.tiles:tiles-core:$tiles3Version") { @@ -203,37 +189,6 @@ project("spring-js-tiles3") { exclude group: "org.springframework", module: "spring-web" exclude group: "ognl", module: "ognl" } - testCompile("javax.servlet:jstl:1.2") - testCompile("org.slf4j:jcl-over-slf4j:$slf4jVersion") - testCompile("org.slf4j:slf4j-api:$slf4jVersion") - testCompile("org.springframework:spring-test:$springVersion") - } -} - -project("spring-webflow") { - description = "Spring Web Flow" - - dependencies { - compile(project(":spring-binding")) - compile(project(":spring-js")) - compile("commons-logging:commons-logging:1.1.1") - compile("opensymphony:ognl:2.6.11") - compile("org.springframework:spring-beans:$springVersion") - compile("org.springframework:spring-context:$springVersion") - compile("org.springframework:spring-core:$springVersion") - compile("org.springframework:spring-expression:$springVersion") - compile("org.springframework:spring-web:$springVersion") - compile("org.springframework:spring-webmvc:$springVersion") - provided("javax.el:javax.el-api:2.2.5") - provided("javax.servlet:javax.servlet-api:3.0.1") - provided("junit:junit:3.8.2") - optional("org.hibernate:hibernate-core:$hibernate5Version") { - exclude group: "org.slf4j", module: "slf4j-api" - } - optional("org.slf4j:slf4j-api:$slf4jVersion") - optional("org.springframework.security:spring-security-core:$springSecurityVersion") - optional("org.springframework:spring-orm:$springVersion") - optional("org.springframework:spring-tx:$springVersion") testCompile("javax.validation:validation-api:1.0.0.GA") testCompile("org.hibernate:hibernate-entitymanager:$hibernate5Version") { exclude group: "org.slf4j", module: "slf4j-api" @@ -244,6 +199,15 @@ project("spring-webflow") { testCompile("org.springframework:spring-aop:$springVersion") testCompile("org.springframework:spring-jdbc:$springVersion") testCompile("org.springframework:spring-test:$springVersion") + testCompile("javax.servlet.jsp:javax.servlet.jsp-api:2.2.1") + testCompile("javax.servlet:jstl:1.2") + testCompile("log4j:log4j:$log4jVersion") { + exclude group: "javax.mail", module: "mail" + exclude group: "javax.jms", module: "jms" + exclude group: "com.sun.jdmk", module: "jmxtools" + exclude group: "com.sun.jmx", module: "jmxri" + } + testCompile("org.slf4j:jcl-over-slf4j:$slf4jVersion") } } diff --git a/settings.gradle b/settings.gradle index 0765208c..ccb15f78 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,8 +2,6 @@ rootProject.name = 'webflow' include 'spring-binding' include 'spring-faces' -include 'spring-js' -include 'spring-js-tiles3' include 'spring-webflow' // Exposes gradle buildSrc 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 f3430a4a..53aa1c3a 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 @@ -27,7 +27,7 @@ import javax.faces.render.RenderKitFactory; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.springframework.js.ajax.AbstractAjaxHandler; +import org.springframework.webflow.context.servlet.AbstractAjaxHandler; /** * Ajax handler for JSF 2 requests that can identify JSF 2 Ajax requests and send redirect instructions back to the diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/JsfFlowHandlerAdapter.java b/spring-faces/src/main/java/org/springframework/faces/webflow/JsfFlowHandlerAdapter.java index 6e8f1a5f..4844b5ff 100644 --- a/spring-faces/src/main/java/org/springframework/faces/webflow/JsfFlowHandlerAdapter.java +++ b/spring-faces/src/main/java/org/springframework/faces/webflow/JsfFlowHandlerAdapter.java @@ -16,12 +16,10 @@ package org.springframework.faces.webflow; import javax.faces.context.FacesContext; -import javax.faces.context.PartialResponseWriter; -import javax.faces.lifecycle.Lifecycle; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.springframework.js.ajax.AjaxHandler; +import org.springframework.webflow.context.servlet.AjaxHandler; import org.springframework.web.servlet.ModelAndView; import org.springframework.webflow.mvc.servlet.FlowHandlerAdapter; diff --git a/spring-faces/src/test/java/org/springframework/faces/webflow/JsfFlowHandlerAdapterTests.java b/spring-faces/src/test/java/org/springframework/faces/webflow/JsfFlowHandlerAdapterTests.java index 3d530e63..60e78cc3 100644 --- a/spring-faces/src/test/java/org/springframework/faces/webflow/JsfFlowHandlerAdapterTests.java +++ b/spring-faces/src/test/java/org/springframework/faces/webflow/JsfFlowHandlerAdapterTests.java @@ -2,8 +2,8 @@ package org.springframework.faces.webflow; import junit.framework.TestCase; -import org.springframework.js.ajax.AjaxHandler; -import org.springframework.js.ajax.SpringJavascriptAjaxHandler; +import org.springframework.webflow.context.servlet.AjaxHandler; +import org.springframework.webflow.context.servlet.DefaultAjaxHandler; import org.springframework.mock.web.MockServletContext; import org.springframework.web.context.support.StaticWebApplicationContext; import org.springframework.webflow.context.ExternalContext; @@ -31,7 +31,7 @@ public class JsfFlowHandlerAdapterTests extends TestCase { } public void testAjaxHandlerProvided() throws Exception { - AjaxHandler myAjaxHandler = new SpringJavascriptAjaxHandler(); + AjaxHandler myAjaxHandler = new DefaultAjaxHandler(); this.handlerAdapter.setAjaxHandler(myAjaxHandler); this.handlerAdapter.afterPropertiesSet(); assertTrue(myAjaxHandler == this.handlerAdapter.getAjaxHandler()); diff --git a/spring-js-tiles3/src/main/java/org/springframework/js/ajax/tiles3/package-info.java b/spring-js-tiles3/src/main/java/org/springframework/js/ajax/tiles3/package-info.java deleted file mode 100644 index 517edd6c..00000000 --- a/spring-js-tiles3/src/main/java/org/springframework/js/ajax/tiles3/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2014 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. - */ - -/** - * The Ajax integration between Spring.js and the Tiles3 layout system. - */ -package org.springframework.js.ajax.tiles3; - diff --git a/spring-js-tiles3/src/main/resources/.gitignore b/spring-js-tiles3/src/main/resources/.gitignore deleted file mode 100644 index e69de29b..00000000 diff --git a/spring-js-tiles3/src/test/resources/log4j.xml b/spring-js-tiles3/src/test/resources/log4j.xml deleted file mode 100644 index b33a7753..00000000 --- a/spring-js-tiles3/src/test/resources/log4j.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-js/src/main/java/org/springframework/js/ajax/package-info.java b/spring-js/src/main/java/org/springframework/js/ajax/package-info.java deleted file mode 100644 index 7cbc1e8e..00000000 --- a/spring-js/src/main/java/org/springframework/js/ajax/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2004-2012 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. - */ - -/** - * Contains the server-side support for handling Spring.js Ajax requests. - */ -package org.springframework.js.ajax; - diff --git a/spring-js/src/main/java/org/springframework/js/resource/ResourceServlet.java b/spring-js/src/main/java/org/springframework/js/resource/ResourceServlet.java deleted file mode 100644 index 3506f925..00000000 --- a/spring-js/src/main/java/org/springframework/js/resource/ResourceServlet.java +++ /dev/null @@ -1,423 +0,0 @@ -/* - * Copyright 2004-2012 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.resource; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.zip.GZIPOutputStream; - -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.util.AntPathMatcher; -import org.springframework.util.ClassUtils; -import org.springframework.util.PathMatcher; -import org.springframework.util.StringUtils; -import org.springframework.web.servlet.HttpServletBean; - -/** - * Special resource servlet for efficiently resolving and rendering static resources from within a JAR file. - * - * @author Jeremy Grelle - * @author Scott Andrews - * - * @deprecated Deprecated in favor of the new resource handling mechanism available in Spring 3.0.4. See the - * documentation on the custom mvc namespace, specifically the new resources element. - */ -public class ResourceServlet extends HttpServletBean { - - private static final String HTTP_CONTENT_LENGTH_HEADER = "Content-Length"; - - private static final String HTTP_LAST_MODIFIED_HEADER = "Last-Modified"; - - private static final String HTTP_EXPIRES_HEADER = "Expires"; - - private static final String HTTP_CACHE_CONTROL_HEADER = "Cache-Control"; - - private static final Log log = LogFactory.getLog(ResourceServlet.class); - - private final String protectedPath = "/?WEB-INF/.*"; - - private String jarPathPrefix = "META-INF"; - - private String springJsJarPathPrefix = "META-INF/web-resources"; - - private boolean gzipEnabled = true; - - private Set allowedResourcePaths = new HashSet(); - { - allowedResourcePaths.add("/**/*.css"); - allowedResourcePaths.add("/**/*.gif"); - allowedResourcePaths.add("/**/*.ico"); - allowedResourcePaths.add("/**/*.jpeg"); - allowedResourcePaths.add("/**/*.jpg"); - allowedResourcePaths.add("/**/*.js"); - allowedResourcePaths.add("/**/*.png"); - allowedResourcePaths.add("META-INF/**/*.css"); - allowedResourcePaths.add("META-INF/**/*.gif"); - allowedResourcePaths.add("META-INF/**/*.ico"); - allowedResourcePaths.add("META-INF/**/*.jpeg"); - allowedResourcePaths.add("META-INF/**/*.jpg"); - allowedResourcePaths.add("META-INF/**/*.js"); - allowedResourcePaths.add("META-INF/**/*.png"); - }; - - private Map defaultMimeTypes = new HashMap(); - { - defaultMimeTypes.put(".css", "text/css"); - defaultMimeTypes.put(".gif", "image/gif"); - defaultMimeTypes.put(".ico", "image/vnd.microsoft.icon"); - defaultMimeTypes.put(".jpeg", "image/jpeg"); - defaultMimeTypes.put(".jpg", "image/jpeg"); - defaultMimeTypes.put(".js", "text/javascript"); - defaultMimeTypes.put(".png", "image/png"); - } - - private Set compressedMimeTypes = new HashSet(); - { - compressedMimeTypes.add("text/*"); - } - - private int cacheTimeout = 31556926; - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - - String rawResourcePath = request.getPathInfo(); - - if (log.isDebugEnabled()) { - log.debug("Attempting to GET resource: " + rawResourcePath); - } - - URL[] resources = getRequestResourceURLs(request); - - if (resources == null || resources.length == 0) { - if (log.isDebugEnabled()) { - log.debug("Resource not found: " + rawResourcePath); - } - response.sendError(HttpServletResponse.SC_NOT_FOUND); - return; - } - - prepareResponse(response, resources, rawResourcePath); - - OutputStream out = selectOutputStream(request, response); - - try { - for (URL resource : resources) { - URLConnection resourceConn = resource.openConnection(); - InputStream in = resourceConn.getInputStream(); - try { - byte[] buffer = new byte[1024]; - int bytesRead = -1; - while ((bytesRead = in.read(buffer)) != -1) { - out.write(buffer, 0, bytesRead); - } - } finally { - in.close(); - } - } - } finally { - out.close(); - } - } - - private OutputStream selectOutputStream(HttpServletRequest request, HttpServletResponse response) - throws IOException { - - String acceptEncoding = request.getHeader("Accept-Encoding"); - String mimeType = response.getContentType(); - - if (gzipEnabled && StringUtils.hasText(acceptEncoding) && acceptEncoding.indexOf("gzip") > -1 - && matchesCompressedMimeTypes(mimeType)) { - log.debug("Enabling GZIP compression for the current response."); - return new GZIPResponseStream(response); - } else { - return response.getOutputStream(); - } - } - - private boolean matchesCompressedMimeTypes(String mimeType) { - PathMatcher pathMatcher = new AntPathMatcher(); - for (String compressedMimeType : compressedMimeTypes) { - if (pathMatcher.match(compressedMimeType, mimeType)) { - return true; - } - } - return false; - } - - private void prepareResponse(HttpServletResponse response, URL[] resources, String rawResourcePath) - throws IOException { - long lastModified = -1; - int contentLength = 0; - String mimeType = null; - for (URL resource : resources) { - URLConnection resourceConn = resource.openConnection(); - if (resourceConn.getLastModified() > lastModified) { - lastModified = resourceConn.getLastModified(); - } - - String currentMimeType = getServletContext().getMimeType(resource.getPath()); - if (currentMimeType == null) { - String extension = resource.getPath().substring(resource.getPath().lastIndexOf('.')); - currentMimeType = defaultMimeTypes.get(extension); - } - if (mimeType == null) { - mimeType = currentMimeType; - } else if (!mimeType.equals(currentMimeType)) { - throw new MalformedURLException("Combined resource path: " + rawResourcePath - + " is invalid. All resources in a combined resource path must be of the same mime type."); - } - contentLength += resourceConn.getContentLength(); - } - - response.setContentType(mimeType); - response.setHeader(HTTP_CONTENT_LENGTH_HEADER, Long.toString(contentLength)); - response.setDateHeader(HTTP_LAST_MODIFIED_HEADER, lastModified); - if (cacheTimeout > 0) { - configureCaching(response, cacheTimeout); - } - } - - protected long getLastModified(HttpServletRequest request) { - if (log.isDebugEnabled()) { - log.debug("Checking last modified of resource: " + request.getPathInfo()); - } - URL[] resources; - try { - resources = getRequestResourceURLs(request); - } catch (MalformedURLException e) { - return -1; - } - - if (resources == null || resources.length == 0) { - return -1; - } - - long lastModified = -1; - - for (URL resource : resources) { - URLConnection resourceConn; - try { - resourceConn = resource.openConnection(); - } catch (IOException e) { - return -1; - } - if (resourceConn.getLastModified() > lastModified) { - lastModified = resourceConn.getLastModified(); - } - } - return lastModified; - } - - private URL[] getRequestResourceURLs(HttpServletRequest request) throws MalformedURLException { - - String rawResourcePath = request.getPathInfo(); - String appendedPaths = request.getParameter("appended"); - if (StringUtils.hasText(appendedPaths)) { - rawResourcePath = rawResourcePath + "," + appendedPaths; - } - String[] localResourcePaths = StringUtils.delimitedListToStringArray(rawResourcePath, ","); - URL[] resources = new URL[localResourcePaths.length]; - for (int i = 0; i < localResourcePaths.length; i++) { - String localResourcePath = localResourcePaths[i]; - if (!isAllowed(localResourcePath)) { - if (log.isWarnEnabled()) { - log.warn("An attempt to access a protected resource at " + localResourcePath + " was disallowed."); - } - return null; - } - URL resource = getServletContext().getResource(localResourcePath); - if (resource == null) { - resource = getJarResource(springJsJarPathPrefix, localResourcePath); - } - if (resource == null) { - resource = getJarResource(jarPathPrefix, localResourcePath); - } - if (resource == null) { - if (resources.length > 1) { - log.debug("Combined resource not found: " + localResourcePath); - } - return null; - } else { - resources[i] = resource; - } - } - return resources; - } - - private URL getJarResource(String jarPrefix, String resourcePath) { - String jarResourcePath = jarPrefix + resourcePath; - if (!isAllowed(jarResourcePath)) { - if (log.isWarnEnabled()) { - log.warn("An attempt to access a protected resource at " + jarResourcePath + " was disallowed."); - } - return null; - } - if (jarResourcePath.startsWith("/")) { - jarResourcePath = jarResourcePath.substring(1); - } - if (log.isDebugEnabled()) { - log.debug("Searching classpath for resource: " + jarResourcePath); - } - return ClassUtils.getDefaultClassLoader().getResource(jarResourcePath); - } - - private boolean isAllowed(String resourcePath) { - if (resourcePath.matches(protectedPath)) { - return false; - } - PathMatcher pathMatcher = new AntPathMatcher(); - for (String pattern : allowedResourcePaths) { - if (pathMatcher.match(pattern, resourcePath)) { - return true; - } - } - return false; - } - - /** - * Set HTTP headers to allow caching for the given number of seconds. - * @param seconds number of seconds into the future that the response should be cacheable for - */ - private void configureCaching(HttpServletResponse response, int seconds) { - // HTTP 1.0 header - response.setDateHeader(HTTP_EXPIRES_HEADER, System.currentTimeMillis() + seconds * 1000L); - // HTTP 1.1 header - response.setHeader(HTTP_CACHE_CONTROL_HEADER, "max-age=" + seconds); - } - - private class GZIPResponseStream extends ServletOutputStream { - - private ByteArrayOutputStream byteStream = null; - - private GZIPOutputStream gzipStream = null; - - private boolean closed = false; - - private HttpServletResponse response = null; - - private ServletOutputStream servletStream = null; - - public GZIPResponseStream(HttpServletResponse response) throws IOException { - super(); - closed = false; - this.response = response; - this.servletStream = response.getOutputStream(); - byteStream = new ByteArrayOutputStream(); - gzipStream = new GZIPOutputStream(byteStream); - } - - public void close() throws IOException { - if (closed) { - throw new IOException("This output stream has already been closed"); - } - gzipStream.finish(); - - byte[] bytes = byteStream.toByteArray(); - - response.setContentLength(bytes.length); - response.addHeader("Content-Encoding", "gzip"); - servletStream.write(bytes); - servletStream.flush(); - servletStream.close(); - closed = true; - } - - public void flush() throws IOException { - if (closed) { - throw new IOException("Cannot flush a closed output stream"); - } - gzipStream.flush(); - } - - public void write(int b) throws IOException { - if (closed) { - throw new IOException("Cannot write to a closed output stream"); - } - gzipStream.write((byte) b); - } - - public void write(byte b[]) throws IOException { - write(b, 0, b.length); - } - - public void write(byte b[], int off, int len) throws IOException { - if (closed) { - throw new IOException("Cannot write to a closed output stream"); - } - gzipStream.write(b, off, len); - } - } - - /** - * Set whether to apply gzip compression to resources if the requesting client supports it. - */ - public void setGzipEnabled(boolean gzipEnabled) { - this.gzipEnabled = gzipEnabled; - } - - /** - * Set allowed resources as an comma separated String of URL patterns, e.g. "META-INF/** /*.js", The paths may be - * any Ant-style pattern parsable by AntPathMatcher. - * - * @see AntPathMatcher - */ - public void setAllowedResourcePaths(String allowedResourcePaths) { - this.allowedResourcePaths = new HashSet(Arrays.asList(StringUtils.tokenizeToStringArray( - allowedResourcePaths, ",", true, true))); - } - - /** - * Set comma separated MIME types that should have gzip compression applied. Typically, gzip compression is only - * useful for text based content. Ant-style patterns are supported, e.g. "text/*". - * - * @see AntPathMatcher - */ - public void setCompressedMimeTypes(String compressedMimeTypes) { - this.compressedMimeTypes = new HashSet(Arrays.asList(StringUtils.tokenizeToStringArray( - compressedMimeTypes, ",", true, true))); - } - - /** - * Set the default path prefix to apply to resources being served from jar files. Default is "META-INF". - */ - public void setJarPathPrefix(String jarPathPrefix) { - this.jarPathPrefix = jarPathPrefix; - } - - /** - * Set the number of seconds resources should be cached by the client. Zero disables caching. Default is one year. - */ - public void setCacheTimeout(int cacheTimeout) { - this.cacheTimeout = cacheTimeout; - } - -} diff --git a/spring-js/src/main/java/org/springframework/js/resource/package-info.java b/spring-js/src/main/java/org/springframework/js/resource/package-info.java deleted file mode 100644 index 124c741c..00000000 --- a/spring-js/src/main/java/org/springframework/js/resource/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2004-2012 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. - */ - -/** - * Contains the generic ResourceServlet for serving web resources such as Javascript and CSS. - */ -package org.springframework.js.resource; - diff --git a/spring-js/src/main/resources/.gitignore b/spring-js/src/main/resources/.gitignore deleted file mode 100644 index e69de29b..00000000 diff --git a/spring-js/src/test/java/org/springframework/js/resource/ResourceServletTests.java b/spring-js/src/test/java/org/springframework/js/resource/ResourceServletTests.java deleted file mode 100644 index e170e9fa..00000000 --- a/spring-js/src/test/java/org/springframework/js/resource/ResourceServletTests.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.springframework.js.resource; - -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; - -import junit.framework.TestCase; - -import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.mock.web.MockServletConfig; -import org.springframework.mock.web.MockServletContext; - -@SuppressWarnings("deprecation") -public class ResourceServletTests extends TestCase { - - ServletContext servletContext = new ResourceTestMockServletContext(); - ServletConfig config = new MockServletConfig(servletContext); - MockHttpServletResponse response = new MockHttpServletResponse(); - MockHttpServletRequest request = new MockHttpServletRequest(); - - String[] requestElements; - - ResourceServlet servlet; - - protected void setUp() throws Exception { - servlet = new ResourceServlet(); - servlet.init(config); - } - - public final void testExecute() throws Exception { - - String requestPath = "/org/springframework/js/resource/TestResource1.js"; - request.setPathInfo(requestPath); - servlet.doGet(request, response); - - assertEquals(200, response.getStatus()); - assertNull(response.getHeader("Content-Encoding")); - } - - public final void testExecute_CombinedResources() throws Exception { - - String requestPath = "/org/springframework/js/resource/TestResource1.js"; - request.setPathInfo(requestPath); - Map params = new HashMap(); - params.put("appended", "/org/springframework/js/resource/TestResource2.js"); - request.setParameters(params); - servlet.doGet(request, response); - - assertEquals(200, response.getStatus()); - } - - public final void testExecute_CompressedResponse() throws Exception { - - String requestPath = "/org/springframework/js/resource/TestResource1.js"; - request.setPathInfo(requestPath); - request.addHeader("Accept-Encoding", "gzip"); - servlet.doGet(request, response); - - assertEquals(200, response.getStatus()); - assertEquals("gzip", response.getHeader("Content-Encoding")); - } - - public final void testExecute_ResourceNotFound() throws Exception { - - String requestPath = "/xxx/xxx.js"; - request.setPathInfo(requestPath); - servlet.doGet(request, response); - - assertEquals(404, response.getStatus()); - } - - public final void testExecute_ProtectedPath() throws Exception { - String requestPath = "/WEB-INF/web.xml"; - request.setPathInfo(requestPath); - servlet.doGet(request, response); - - assertEquals(404, response.getStatus()); - } - - public final void testExecute_DisallowedPath() throws Exception { - String requestPath = "/persistence.xml"; - request.setPathInfo(requestPath); - servlet.doGet(request, response); - - assertEquals(404, response.getStatus()); - } - - private class ResourceTestMockServletContext extends MockServletContext { - - public String getMimeType(String filePath) { - return null; - } - - } -} diff --git a/spring-js/src/test/java/org/springframework/js/resource/TestResource1.js b/spring-js/src/test/java/org/springframework/js/resource/TestResource1.js deleted file mode 100644 index e69de29b..00000000 diff --git a/spring-js/src/test/java/org/springframework/js/resource/TestResource2.js b/spring-js/src/test/java/org/springframework/js/resource/TestResource2.js deleted file mode 100644 index e69de29b..00000000 diff --git a/spring-js/src/test/resources/log4j.xml b/spring-js/src/test/resources/log4j.xml deleted file mode 100644 index b33a7753..00000000 --- a/spring-js/src/test/resources/log4j.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/spring-js/src/main/java/org/springframework/js/ajax/AbstractAjaxHandler.java b/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/AbstractAjaxHandler.java similarity index 96% rename from spring-js/src/main/java/org/springframework/js/ajax/AbstractAjaxHandler.java rename to spring-webflow/src/main/java/org/springframework/webflow/context/servlet/AbstractAjaxHandler.java index 637a9340..ec30153a 100644 --- a/spring-js/src/main/java/org/springframework/js/ajax/AbstractAjaxHandler.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/AbstractAjaxHandler.java @@ -1,4 +1,4 @@ -package org.springframework.js.ajax; +package org.springframework.webflow.context.servlet; import java.io.IOException; diff --git a/spring-js/src/main/java/org/springframework/js/ajax/AjaxHandler.java b/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/AjaxHandler.java similarity index 92% rename from spring-js/src/main/java/org/springframework/js/ajax/AjaxHandler.java rename to spring-webflow/src/main/java/org/springframework/webflow/context/servlet/AjaxHandler.java index 4dd4b52c..a1b58e83 100644 --- a/spring-js/src/main/java/org/springframework/js/ajax/AjaxHandler.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/AjaxHandler.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.js.ajax; +package org.springframework.webflow.context.servlet; import java.io.IOException; @@ -41,7 +41,7 @@ public interface AjaxHandler { * @param request the current request * @param response the current response * @param targetUrl the target url to redirect to - * @param popup wheter the redirect should be sent from a new popup dialog window + * @param popup whether the redirect should be sent from a new popup dialog window */ void sendAjaxRedirect(String targetUrl, HttpServletRequest request, HttpServletResponse response, boolean popup) throws IOException; diff --git a/spring-js/src/main/java/org/springframework/js/ajax/SpringJavascriptAjaxHandler.java b/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/DefaultAjaxHandler.java similarity index 50% rename from spring-js/src/main/java/org/springframework/js/ajax/SpringJavascriptAjaxHandler.java rename to spring-webflow/src/main/java/org/springframework/webflow/context/servlet/DefaultAjaxHandler.java index 2ddb7f06..0b8edfda 100644 --- a/spring-js/src/main/java/org/springframework/js/ajax/SpringJavascriptAjaxHandler.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/DefaultAjaxHandler.java @@ -13,73 +13,66 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.js.ajax; - -import java.io.IOException; +package org.springframework.webflow.context.servlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.http.HttpHeaders; import org.springframework.util.StringUtils; /** - * Ajax handler for Spring Javascript (Spring.js). + * Default {@link AjaxHandler} implementation. * - * @see AbstractAjaxHandler + *

Detects Ajax requests through an "Accept" header with the value + * {@link #AJAX_ACCEPT_CONTENT_TYPE} or a request parameter with the name + * {@link #AJAX_SOURCE_PARAM}. * - * @author Jeremy Grelle - * @author Keith Donald + *

Also for a redirect during an Ajax request it sets the response headers + * {@link #REDIRECT_URL_HEADER} and {@link #POPUP_VIEW_HEADER}. The latter is + * set if the redirect occurs on a view state with popup="true". * - * @deprecated as of version 2.4 Spring.js is deprecated + * @author Rossen Stoyanchev + * @since 2.5 */ -public class SpringJavascriptAjaxHandler extends AbstractAjaxHandler { +public class DefaultAjaxHandler 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. - */ + /** "Accept" header value that indicates 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. - */ + /** Request parameter alternative that indicate an Ajax request. */ public static final String AJAX_SOURCE_PARAM = "ajaxSource"; + /** Response header to be set on an Ajax redirect with the redirect location */ + public static final String REDIRECT_URL_HEADER = "Spring-Redirect-URL"; + + /** Response header to be set on a redirect that should be issued from a popup window. */ + public static final String POPUP_VIEW_HEADER = "Spring-Modal-View"; + + /** - * Create a SpringJavascriptAjaxHandler that is not part of a chain of AjaxHandler's. + * Create a DefaultAjaxHandler that is not part of a chain of AjaxHandler's. */ - public SpringJavascriptAjaxHandler() { + public DefaultAjaxHandler() { this(null); } /** - * Create a SpringJavascriptAjaxHandler as part of a chain of AjaxHandler's. + * Create a DefaultAjaxHandler as part of a chain of AjaxHandler's. */ - public SpringJavascriptAjaxHandler(AbstractAjaxHandler delegate) { + public DefaultAjaxHandler(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; - } + String header = request.getHeader(HttpHeaders.ACCEPT); + String param = request.getParameter(AJAX_SOURCE_PARAM); + return AJAX_ACCEPT_CONTENT_TYPE.equals(header) || StringUtils.hasText(param); } - protected void sendAjaxRedirectInternal(String targetUrl, HttpServletRequest request, HttpServletResponse response, - boolean popup) throws IOException { + protected void sendAjaxRedirectInternal(String targetUrl, HttpServletRequest request, + HttpServletResponse response, boolean popup) { + if (popup) { response.setHeader(POPUP_VIEW_HEADER, "true"); } diff --git a/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/FilenameFlowUrlHandler.java b/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/FilenameFlowUrlHandler.java index 11bcdcae..732f30c3 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/FilenameFlowUrlHandler.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/FilenameFlowUrlHandler.java @@ -20,13 +20,12 @@ import javax.servlet.http.HttpServletRequest; import org.springframework.util.StringUtils; import org.springframework.web.util.UrlPathHelper; import org.springframework.webflow.core.collection.AttributeMap; -import org.springframework.webflow.mvc.servlet.FlowController; /** * A file name based {@link FlowUrlHandler} implementation that is an alternative to the standard * {@link DefaultFlowUrlHandler}. Treats the filename of a request without the URL suffix and/or prefix as the flow id. - * Used by the {@link FlowController} implementation as a default implementation to preserve compatibility with existing - * Web Flow 2 applications. + * Used by the {@link org.springframework.webflow.mvc.servlet.FlowController} implementation as a default + * implementation to preserve compatibility with existing Web Flow 2 applications. * *

* This implementation extracts the filename and removes the file extension from the request URL. The results will be diff --git a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowController.java b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowController.java index acc5e625..aaced904 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowController.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowController.java @@ -25,7 +25,7 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.js.ajax.AjaxHandler; +import org.springframework.webflow.context.servlet.AjaxHandler; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import org.springframework.webflow.context.servlet.FilenameFlowUrlHandler; diff --git a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java index 66fbd8d1..3f436b22 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java @@ -25,8 +25,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.http.HttpStatus; -import org.springframework.js.ajax.AjaxHandler; -import org.springframework.js.ajax.SpringJavascriptAjaxHandler; +import org.springframework.webflow.context.servlet.AjaxHandler; +import org.springframework.webflow.context.servlet.DefaultAjaxHandler; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -234,7 +234,7 @@ public class FlowHandlerAdapter extends WebContentGenerator implements HandlerAd flowUrlHandler = new DefaultFlowUrlHandler(); } if (ajaxHandler == null) { - ajaxHandler = new SpringJavascriptAjaxHandler(); + ajaxHandler = new DefaultAjaxHandler(); } } diff --git a/spring-js-tiles3/src/main/java/org/springframework/js/ajax/tiles3/AjaxTilesView.java b/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/AjaxTiles3View.java similarity index 95% rename from spring-js-tiles3/src/main/java/org/springframework/js/ajax/tiles3/AjaxTilesView.java rename to spring-webflow/src/main/java/org/springframework/webflow/mvc/view/AjaxTiles3View.java index 2216ab3f..88c018c4 100644 --- a/spring-js-tiles3/src/main/java/org/springframework/js/ajax/tiles3/AjaxTilesView.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/AjaxTiles3View.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.js.ajax.tiles3; +package org.springframework.webflow.mvc.view; import java.util.HashMap; import java.util.HashSet; @@ -33,8 +33,8 @@ import org.apache.tiles.impl.BasicTilesContainer; import org.apache.tiles.request.ApplicationContext; import org.apache.tiles.request.Request; import org.apache.tiles.request.servlet.ServletRequest; -import org.springframework.js.ajax.AjaxHandler; -import org.springframework.js.ajax.SpringJavascriptAjaxHandler; +import org.springframework.webflow.context.servlet.AjaxHandler; +import org.springframework.webflow.context.servlet.DefaultAjaxHandler; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.servlet.support.JstlUtils; @@ -45,7 +45,7 @@ import org.springframework.web.servlet.view.tiles3.TilesView; * Tiles 3 view implementation that is able to handle partial rendering for Spring * Javascript Ajax requests. * - *

This implementation uses the {@link SpringJavascriptAjaxHandler} by default + *

This implementation uses the {@link DefaultAjaxHandler} by default * to determine whether the current request is an Ajax request. On an Ajax request, * a "fragments" parameter will be extracted from the request in order to * determine which attributes to render from the current tiles view. @@ -53,11 +53,11 @@ import org.springframework.web.servlet.view.tiles3.TilesView; * @author Rossen Stoyanchev * @since 2.4 */ -public class AjaxTilesView extends TilesView { +public class AjaxTiles3View extends TilesView { private static final String FRAGMENTS_PARAM = "fragments"; - private AjaxHandler ajaxHandler = new SpringJavascriptAjaxHandler(); + private AjaxHandler ajaxHandler = new DefaultAjaxHandler(); public AjaxHandler getAjaxHandler() { diff --git a/spring-js/src/main/java/org/springframework/js/ajax/AjaxUrlBasedViewResolver.java b/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/AjaxUrlBasedViewResolver.java similarity index 91% rename from spring-js/src/main/java/org/springframework/js/ajax/AjaxUrlBasedViewResolver.java rename to spring-webflow/src/main/java/org/springframework/webflow/mvc/view/AjaxUrlBasedViewResolver.java index 986ce57b..f60b5481 100644 --- a/spring-js/src/main/java/org/springframework/js/ajax/AjaxUrlBasedViewResolver.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/AjaxUrlBasedViewResolver.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.js.ajax; +package org.springframework.webflow.mvc.view; import java.io.IOException; import java.util.Locale; @@ -24,6 +24,8 @@ import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.View; import org.springframework.web.servlet.view.RedirectView; import org.springframework.web.servlet.view.UrlBasedViewResolver; +import org.springframework.webflow.context.servlet.AjaxHandler; +import org.springframework.webflow.context.servlet.DefaultAjaxHandler; /** * View resolver that provides special view resolution for Spring Javascript Ajax requests. @@ -54,7 +56,7 @@ public class AjaxUrlBasedViewResolver extends UrlBasedViewResolver { private class AjaxRedirectView extends RedirectView implements View { - private AjaxHandler ajaxHandler = new SpringJavascriptAjaxHandler(); + private AjaxHandler ajaxHandler = new DefaultAjaxHandler(); public AjaxRedirectView(String redirectUrl, boolean redirectContextRelative, boolean redirectHttp10Compatible) { super(redirectUrl, redirectContextRelative, redirectHttp10Compatible); diff --git a/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/FlowAjaxTiles3View.java b/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/FlowAjaxTiles3View.java index 9b63e7db..69042c3e 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/FlowAjaxTiles3View.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/FlowAjaxTiles3View.java @@ -16,11 +16,10 @@ package org.springframework.webflow.mvc.view; import java.util.Map; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.springframework.js.ajax.tiles3.AjaxTilesView; +import org.springframework.webflow.context.servlet.DefaultAjaxHandler; import org.springframework.webflow.execution.RequestContext; import org.springframework.webflow.execution.RequestContextHolder; import org.springframework.webflow.execution.View; @@ -29,17 +28,16 @@ import org.springframework.webflow.execution.View; * Tiles view implementation that is able to handle partial rendering for Spring * Javascript Ajax requests. * - *

This implementation uses the {@link org.springframework.js.ajax.SpringJavascriptAjaxHandler} + *

This implementation uses the {@link DefaultAjaxHandler} * by default to determine whether the current request is an Ajax request. On an * Ajax request for an active flow execution, the fragments set by a {@code } - * action will be respected, otherwise the parent - * {@link org.springframework.js.ajax.tiles2.AjaxTilesView}'s resolution algorithm + * action will be respected, otherwise the parent {@link AjaxTiles3View}'s resolution algorithm * will be applied. * * @author Rossen Stoyanchev * @since 2.4 */ -public class FlowAjaxTiles3View extends AjaxTilesView { +public class FlowAjaxTiles3View extends AjaxTiles3View { protected String[] getRenderFragments(Map model, HttpServletRequest request, diff --git a/spring-js/src/test/java/org/springframework/js/ajax/AbstractAjaxHandlerTests.java b/spring-webflow/src/test/java/org/springframework/webflow/context/servlet/AbstractAjaxHandlerTests.java similarity index 98% rename from spring-js/src/test/java/org/springframework/js/ajax/AbstractAjaxHandlerTests.java rename to spring-webflow/src/test/java/org/springframework/webflow/context/servlet/AbstractAjaxHandlerTests.java index 229488ea..d82d6220 100644 --- a/spring-js/src/test/java/org/springframework/js/ajax/AbstractAjaxHandlerTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/context/servlet/AbstractAjaxHandlerTests.java @@ -1,7 +1,6 @@ -package org.springframework.js.ajax; +package org.springframework.webflow.context.servlet; import java.io.IOException; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/spring-webflow/src/test/java/org/springframework/webflow/mvc/servlet/FlowControllerTests.java b/spring-webflow/src/test/java/org/springframework/webflow/mvc/servlet/FlowControllerTests.java index 4f8d94e4..4d2cb2cf 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/mvc/servlet/FlowControllerTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/mvc/servlet/FlowControllerTests.java @@ -9,7 +9,8 @@ import javax.servlet.http.HttpServletResponse; import junit.framework.TestCase; import org.easymock.EasyMock; -import org.springframework.js.ajax.SpringJavascriptAjaxHandler; + +import org.springframework.webflow.context.servlet.DefaultAjaxHandler; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockServletContext; @@ -165,9 +166,9 @@ public class FlowControllerTests extends TestCase { ModelAndView mv = controller.handleRequest(request, response); assertNull(mv); assertEquals(null, response.getRedirectedUrl()); - assertEquals("true", response.getHeader(SpringJavascriptAjaxHandler.POPUP_VIEW_HEADER)); + assertEquals("true", response.getHeader(DefaultAjaxHandler.POPUP_VIEW_HEADER)); assertEquals("/springtravel/app/foo?execution=12345", - response.getHeader(SpringJavascriptAjaxHandler.REDIRECT_URL_HEADER)); + response.getHeader(DefaultAjaxHandler.REDIRECT_URL_HEADER)); EasyMock.verify(new Object[] { executor }); } @@ -189,9 +190,9 @@ public class FlowControllerTests extends TestCase { ModelAndView mv = controller.handleRequest(request, response); assertNull(mv); assertEquals(null, response.getRedirectedUrl()); - assertEquals(null, response.getHeader(SpringJavascriptAjaxHandler.POPUP_VIEW_HEADER)); + assertEquals(null, response.getHeader(DefaultAjaxHandler.POPUP_VIEW_HEADER)); assertEquals("/springtravel/app/foo?execution=12345", - response.getHeader(SpringJavascriptAjaxHandler.REDIRECT_URL_HEADER)); + response.getHeader(DefaultAjaxHandler.REDIRECT_URL_HEADER)); EasyMock.verify(new Object[] { executor }); } diff --git a/spring-js-tiles3/src/test/java/org/springframework/js/ajax/tiles3/AjaxTilesViewTests.java b/spring-webflow/src/test/java/org/springframework/webflow/mvc/view/AjaxTiles3ViewTests.java similarity index 79% rename from spring-js-tiles3/src/test/java/org/springframework/js/ajax/tiles3/AjaxTilesViewTests.java rename to spring-webflow/src/test/java/org/springframework/webflow/mvc/view/AjaxTiles3ViewTests.java index 881fec0f..e0b1bbff 100644 --- a/spring-js-tiles3/src/test/java/org/springframework/js/ajax/tiles3/AjaxTilesViewTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/mvc/view/AjaxTiles3ViewTests.java @@ -1,11 +1,9 @@ -package org.springframework.js.ajax.tiles3; +package org.springframework.webflow.mvc.view; import java.util.HashMap; import java.util.Map; -import junit.framework.Assert; import junit.framework.TestCase; - import org.apache.tiles.Attribute; import org.apache.tiles.AttributeContext; import org.apache.tiles.Definition; @@ -16,8 +14,8 @@ import org.apache.tiles.request.ApplicationContext; import org.apache.tiles.request.Request; import org.apache.tiles.request.servlet.ServletRequest; import org.apache.tiles.request.servlet.wildcard.WildcardServletApplicationContext; -import org.springframework.js.ajax.SpringJavascriptAjaxHandler; -import org.springframework.js.ajax.tiles3.AjaxTilesView; + +import org.springframework.webflow.context.servlet.DefaultAjaxHandler; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockServletContext; @@ -26,9 +24,9 @@ import org.springframework.web.servlet.support.RequestContext; import org.springframework.web.servlet.view.tiles3.TilesConfigurer; -public class AjaxTilesViewTests extends TestCase { +public class AjaxTiles3ViewTests extends TestCase { - private AjaxTilesView ajaxTilesView; + private AjaxTiles3View ajaxTilesView; private MockHttpServletRequest request; @@ -39,18 +37,18 @@ public class AjaxTilesViewTests extends TestCase { protected void setUp() throws Exception { - servletContext = new MockServletContext("/org/springframework/js/ajax/tiles3/"); + servletContext = new MockServletContext("/org/springframework/webflow/mvc/view/"); request = new MockHttpServletRequest(servletContext); response = new MockHttpServletResponse(); TilesConfigurer tc = new TilesConfigurer(); - tc.setDefinitions(new String[] { "tiles-definitions.xml" }); + tc.setDefinitions("tiles-definitions.xml"); tc.setValidateDefinitions(true); tc.setServletContext(servletContext); tc.setUseMutableTilesContainer(false); tc.afterPropertiesSet(); - ajaxTilesView = new AjaxTilesView(); + ajaxTilesView = new AjaxTiles3View(); } private void setupStaticWebApplicationContext() { @@ -65,46 +63,46 @@ public class AjaxTilesViewTests extends TestCase { setupStaticWebApplicationContext(); ajaxTilesView.setUrl("search"); ajaxTilesView.afterPropertiesSet(); - ajaxTilesView.renderMergedOutputModel(new HashMap(), request, response); + ajaxTilesView.renderMergedOutputModel(new HashMap<>(), request, response); assertEquals("/WEB-INF/layout.jsp", response.getForwardedUrl()); } public void testAjaxRequestNoFragments() throws Exception { setupStaticWebApplicationContext(); - request.addHeader("Accept", SpringJavascriptAjaxHandler.AJAX_ACCEPT_CONTENT_TYPE); + request.addHeader("Accept", DefaultAjaxHandler.AJAX_ACCEPT_CONTENT_TYPE); ajaxTilesView.setUrl("search"); ajaxTilesView.afterPropertiesSet(); - ajaxTilesView.renderMergedOutputModel(new HashMap(), request, response); + ajaxTilesView.renderMergedOutputModel(new HashMap<>(), request, response); assertEquals("/WEB-INF/layout.jsp", response.getForwardedUrl()); } public void testRenderFragment_Template() throws Exception { setupStaticWebApplicationContext(); - request.addHeader("Accept", SpringJavascriptAjaxHandler.AJAX_ACCEPT_CONTENT_TYPE); + request.addHeader("Accept", DefaultAjaxHandler.AJAX_ACCEPT_CONTENT_TYPE); request.addParameter("fragments", "searchResults"); ajaxTilesView.setUrl("search"); ajaxTilesView.afterPropertiesSet(); - ajaxTilesView.renderMergedOutputModel(new HashMap(), request, response); + ajaxTilesView.renderMergedOutputModel(new HashMap<>(), request, response); assertEquals("/WEB-INF/searchResults.jsp", response.getForwardedUrl()); } public void testRenderFragment_Definition() throws Exception { setupStaticWebApplicationContext(); - request.addHeader("Accept", SpringJavascriptAjaxHandler.AJAX_ACCEPT_CONTENT_TYPE); + request.addHeader("Accept", DefaultAjaxHandler.AJAX_ACCEPT_CONTENT_TYPE); request.addParameter("fragments", "body"); ajaxTilesView.setUrl("search"); ajaxTilesView.afterPropertiesSet(); - ajaxTilesView.renderMergedOutputModel(new HashMap(), request, response); + ajaxTilesView.renderMergedOutputModel(new HashMap<>(), request, response); assertEquals("/WEB-INF/search.jsp", response.getForwardedUrl()); } public void testRenderFragment_CascadedAttribute() throws Exception { setupStaticWebApplicationContext(); - request.addHeader("Accept", SpringJavascriptAjaxHandler.AJAX_ACCEPT_CONTENT_TYPE); + request.addHeader("Accept", DefaultAjaxHandler.AJAX_ACCEPT_CONTENT_TYPE); request.addParameter("fragments", "searchNavigation"); ajaxTilesView.setUrl("search"); ajaxTilesView.afterPropertiesSet(); - ajaxTilesView.renderMergedOutputModel(new HashMap(), request, response); + ajaxTilesView.renderMergedOutputModel(new HashMap<>(), request, response); assertEquals("/WEB-INF/searchNavigation.jsp", response.getForwardedUrl()); } @@ -115,11 +113,11 @@ public class AjaxTilesViewTests extends TestCase { Definition definition = container.getDefinitionsFactory().getDefinition("search.body", tilesRequest); definition.setPreparer(AttributeTestingPreparer.class.getName()); setupStaticWebApplicationContext(); - request.addHeader("Accept", SpringJavascriptAjaxHandler.AJAX_ACCEPT_CONTENT_TYPE); + request.addHeader("Accept", DefaultAjaxHandler.AJAX_ACCEPT_CONTENT_TYPE); request.addParameter("fragments", "body"); ajaxTilesView.setUrl("search"); ajaxTilesView.afterPropertiesSet(); - ajaxTilesView.renderMergedOutputModel(new HashMap(), request, response); + ajaxTilesView.renderMergedOutputModel(new HashMap<>(), request, response); assertTrue(AttributeTestingPreparer.invoked); } @@ -138,11 +136,11 @@ public class AjaxTilesViewTests extends TestCase { public void testRenderFragment_Multiple() throws Exception { setupStaticWebApplicationContext(); - request.addHeader("Accept", SpringJavascriptAjaxHandler.AJAX_ACCEPT_CONTENT_TYPE); + request.addHeader("Accept", DefaultAjaxHandler.AJAX_ACCEPT_CONTENT_TYPE); request.addParameter("fragments", "body,searchNavigation"); ajaxTilesView.setUrl("search"); ajaxTilesView.afterPropertiesSet(); - ajaxTilesView.renderMergedOutputModel(new HashMap(), request, response); + ajaxTilesView.renderMergedOutputModel(new HashMap<>(), request, response); assertTrue("Multiple fragments should result in include, not forward", response.getIncludedUrls().size() == 2); assertEquals("/WEB-INF/search.jsp", response.getIncludedUrls().get(0)); assertEquals("/WEB-INF/searchNavigation.jsp", response.getIncludedUrls().get(1)); @@ -162,7 +160,7 @@ public class AjaxTilesViewTests extends TestCase { } public void testGetRenderFragments() throws Exception { - Map model = new HashMap(); + Map model = new HashMap<>(); request.setParameter("fragments", "f1,f2, f3"); String[] fragments = ajaxTilesView.getRenderFragments(model, request, response); assertEquals("f1", fragments[0]); @@ -177,7 +175,7 @@ public class AjaxTilesViewTests extends TestCase { public void execute(Request tilesContext, AttributeContext attributeContext) { invoked = true; - Assert.assertTrue(attributeContext.getAttribute("searchNavigation") != null); + assertTrue(attributeContext.getAttribute("searchNavigation") != null); } } diff --git a/spring-js-tiles3/src/test/java/org/springframework/js/ajax/tiles3/tiles-definitions.xml b/spring-webflow/src/test/resources/org/springframework/webflow/mvc/view/tiles-definitions.xml similarity index 100% rename from spring-js-tiles3/src/test/java/org/springframework/js/ajax/tiles3/tiles-definitions.xml rename to spring-webflow/src/test/resources/org/springframework/webflow/mvc/view/tiles-definitions.xml diff --git a/src/dist/readme.txt b/src/dist/readme.txt index d427c8f6..f4b5b90a 100644 --- a/src/dist/readme.txt +++ b/src/dist/readme.txt @@ -50,25 +50,19 @@ SpringSource repository. Add the following repository to your Maven pom.xml: Then declare the following dependencies (note that many times it's sufficient -to include spring-webflow only, which will give you spring-binding and spring-js +to include spring-webflow only, which will give you spring-binding via transitive dependencies): org.springframework.webflow org.springframework.binding - 2.4.4.RELEASE - - - - org.springframework.webflow - org.springframework.js - 2.4.4.RELEASE + x.y.z.RELEASE org.springframework.webflow org.springframework.webflow - 2.4.4.RELEASE + x.y.z.RELEASE If using JSF all you need to include is: @@ -76,7 +70,7 @@ If using JSF all you need to include is: org.springframework.webflow org.springframework.faces - 2.4.4.RELEASE + x.y.z.RELEASE To access jars using Ivy, add the following repositories to your Ivy config: @@ -93,13 +87,13 @@ To access jars using Ivy, add the following repositories to your Ivy config: Then declare the following dependencies in your ivy.xml: - - - + + + If using JavaServerFaces: - + For more information see the reference documentation and the SpringSource Repository FAQ: https://github.com/spring-projects/spring-framework/wiki/Spring-repository-FAQ diff --git a/src/reference/overview.xml b/src/reference/overview.xml index fd083515..ecfe2752 100644 --- a/src/reference/overview.xml +++ b/src/reference/overview.xml @@ -49,7 +49,7 @@ To access Web Flow jars from Maven Central, declare the following dependency in your pom (includes - transitive dependencies "spring-binding" and "spring-js"): + transitive dependencies "spring-binding"): @@ -60,7 +60,8 @@ ]]> - If using JavaServer Faces, declare the following dependency in your pom (includes transitive dependencies "spring-binding", "spring-webflow" and "spring-js"): + If using JavaServer Faces, declare the following dependency in your pom + (includes transitive dependencies "spring-binding", "spring-webflow"): @@ -148,12 +149,6 @@ x.y.z.BUILD-SNAPSHOT - - org.springframework.webflow - spring-js - x.y.z.BUILD-SNAPSHOT - - org.springframework.webflow spring-webflow diff --git a/src/reference/spring-js.xml b/src/reference/spring-js.xml index 5a5d01c9..11b0690d 100644 --- a/src/reference/spring-js.xml +++ b/src/reference/spring-js.xml @@ -48,7 +48,7 @@ (note that these extensions require the use of Tiles for templating): + ]]>