fixed line endings
Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/b1588ddc Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/b1588ddc Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/b1588ddc Branch: refs/heads/master Commit: b1588ddc84d876a676bab66ad80ec34637e98536 Parents: a53deac Author: cnenning <cnenn...@apache.org> Authored: Mon Jan 25 13:50:45 2016 +0100 Committer: cnenning <cnenn...@apache.org> Committed: Mon Jan 25 13:50:45 2016 +0100 ---------------------------------------------------------------------- apps/showcase/src/main/webapp/WEB-INF/tiles.xml | 108 +++--- .../src/main/webapp/WEB-INF/tiles/body.jsp | 52 +-- .../apache/struts2/views/tiles/TilesResult.java | 326 +++++++++---------- 3 files changed, 243 insertions(+), 243 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/struts/blob/b1588ddc/apps/showcase/src/main/webapp/WEB-INF/tiles.xml ---------------------------------------------------------------------- diff --git a/apps/showcase/src/main/webapp/WEB-INF/tiles.xml b/apps/showcase/src/main/webapp/WEB-INF/tiles.xml index d644502..a74de1b 100644 --- a/apps/showcase/src/main/webapp/WEB-INF/tiles.xml +++ b/apps/showcase/src/main/webapp/WEB-INF/tiles.xml @@ -1,54 +1,54 @@ -<?xml version="1.0" encoding="ISO-8859-1" ?> -<!-- -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - * - */ ---> - -<!DOCTYPE tiles-definitions PUBLIC - "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" - "http://tiles.apache.org/dtds/tiles-config_3_0.dtd"> - -<tiles-definitions> - - <definition name="showcase.index" template="/WEB-INF/tiles/layout.jsp"> - <put-attribute name="title" value="Tiles Showcase"/> - <put-attribute name="header" value="/WEB-INF/tiles/header.jsp"/> - <put-attribute name="body" value="/WEB-INF/tiles/body.jsp"/> - </definition> - - <definition name="showcase.freemarker" template="/WEB-INF/tiles/layout.jsp"> - <put-attribute name="title" value="Tiles/Freemarker Showcase"/> - <put-attribute name="header" value="/WEB-INF/tiles/header.jsp"/> - <put-attribute name="body" value="/WEB-INF/tiles/body.ftl"/> - </definition> - - <definition name="showcase.freemarkerLayout" template="/WEB-INF/tiles/layout.ftl"> - <put-attribute name="title" value="Tiles/Freemarker Showcase"/> - <put-attribute name="header" value="/WEB-INF/tiles/header.jsp"/> - <put-attribute name="body" value="/WEB-INF/tiles/body.ftl"/> - </definition> - - <definition name="showcase.annotations" template="/WEB-INF/tiles/layout-annotations.jsp"> - <put-attribute name="title" value="Tiles Annotations Showcase"/> - <put-attribute name="header" value=".header"/> - <put-attribute name="body" value=".body"/> - </definition> - -</tiles-definitions> +<?xml version="1.0" encoding="ISO-8859-1" ?> +<!-- +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + * + */ +--> + +<!DOCTYPE tiles-definitions PUBLIC + "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" + "http://tiles.apache.org/dtds/tiles-config_3_0.dtd"> + +<tiles-definitions> + + <definition name="showcase.index" template="/WEB-INF/tiles/layout.jsp"> + <put-attribute name="title" value="Tiles Showcase"/> + <put-attribute name="header" value="/WEB-INF/tiles/header.jsp"/> + <put-attribute name="body" value="/WEB-INF/tiles/body.jsp"/> + </definition> + + <definition name="showcase.freemarker" template="/WEB-INF/tiles/layout.jsp"> + <put-attribute name="title" value="Tiles/Freemarker Showcase"/> + <put-attribute name="header" value="/WEB-INF/tiles/header.jsp"/> + <put-attribute name="body" value="/WEB-INF/tiles/body.ftl"/> + </definition> + + <definition name="showcase.freemarkerLayout" template="/WEB-INF/tiles/layout.ftl"> + <put-attribute name="title" value="Tiles/Freemarker Showcase"/> + <put-attribute name="header" value="/WEB-INF/tiles/header.jsp"/> + <put-attribute name="body" value="/WEB-INF/tiles/body.ftl"/> + </definition> + + <definition name="showcase.annotations" template="/WEB-INF/tiles/layout-annotations.jsp"> + <put-attribute name="title" value="Tiles Annotations Showcase"/> + <put-attribute name="header" value=".header"/> + <put-attribute name="body" value=".body"/> + </definition> + +</tiles-definitions> http://git-wip-us.apache.org/repos/asf/struts/blob/b1588ddc/apps/showcase/src/main/webapp/WEB-INF/tiles/body.jsp ---------------------------------------------------------------------- diff --git a/apps/showcase/src/main/webapp/WEB-INF/tiles/body.jsp b/apps/showcase/src/main/webapp/WEB-INF/tiles/body.jsp index ca9d10d..855a896 100644 --- a/apps/showcase/src/main/webapp/WEB-INF/tiles/body.jsp +++ b/apps/showcase/src/main/webapp/WEB-INF/tiles/body.jsp @@ -1,27 +1,27 @@ -<%@taglib prefix="s" uri="/struts-tags" %> -<div class="container-fluid"> - <div class="row"> - <div class="col-md-12"> - <div> - <p>This example illustrates the Struts/Tiles Plugin.</p> - - <p>Tiles 2 is an effort to extract the Tiles library from Struts. It is currently housed - in the Sandbox area of the Apache Struts Subversion repository.</p> - - <h4>Features</h4> - <ul> - <li> - <a href="freemarker.action">View FreeMarker Example</a> - </li> - <li> - <a href="freemarkerLayout.action">View Example with a FreeMarker Layout</a> - </li> - <li> - <a href="tiles-annotations.action">View Example with tiles configuration by annotating action</a> - </li> - </ul> - - </div> - </div> - </div> +<%@taglib prefix="s" uri="/struts-tags" %> +<div class="container-fluid"> + <div class="row"> + <div class="col-md-12"> + <div> + <p>This example illustrates the Struts/Tiles Plugin.</p> + + <p>Tiles 2 is an effort to extract the Tiles library from Struts. It is currently housed + in the Sandbox area of the Apache Struts Subversion repository.</p> + + <h4>Features</h4> + <ul> + <li> + <a href="freemarker.action">View FreeMarker Example</a> + </li> + <li> + <a href="freemarkerLayout.action">View Example with a FreeMarker Layout</a> + </li> + <li> + <a href="tiles-annotations.action">View Example with tiles configuration by annotating action</a> + </li> + </ul> + + </div> + </div> + </div> </div> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/struts/blob/b1588ddc/plugins/tiles/src/main/java/org/apache/struts2/views/tiles/TilesResult.java ---------------------------------------------------------------------- diff --git a/plugins/tiles/src/main/java/org/apache/struts2/views/tiles/TilesResult.java b/plugins/tiles/src/main/java/org/apache/struts2/views/tiles/TilesResult.java index da00765..4656f91 100644 --- a/plugins/tiles/src/main/java/org/apache/struts2/views/tiles/TilesResult.java +++ b/plugins/tiles/src/main/java/org/apache/struts2/views/tiles/TilesResult.java @@ -1,163 +1,163 @@ -/* - * $Id$ - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.struts2.views.tiles; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.lang3.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.struts2.ServletActionContext; -import org.apache.struts2.result.ServletDispatcherResult; -import org.apache.struts2.tiles.StrutsTilesAnnotationProcessor; -import org.apache.struts2.tiles.annotation.TilesDefinition; -import org.apache.tiles.Definition; -import org.apache.tiles.TilesContainer; -import org.apache.tiles.TilesException; - -import com.opensymphony.xwork2.ActionInvocation; -import org.apache.tiles.access.TilesAccess; -import org.apache.tiles.mgmt.MutableTilesContainer; -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.ServletUtil; - -/** - * <!-- START SNIPPET: description --> - * Renders a view using struts-tiles. - * <!-- END SNIPPET: description --> - * - * <!-- START SNIPPET: webxml --> - * In your web.xml file, you need to add a TilesListener. - * - * <listener> - * <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class> - * </listener> - * <!-- END SNIPPET: webxml --> - * - * <!-- START SNIPPET: strutsxml --> - * In struts.xml, use type="tiles" on your <result>. - * - * <action name="editUser" class="userAction" method="edit"> - * <result name="success" type="tiles">userForm</result> - * <result name="input" type="tiles">userList</result> - * </action> - * <!-- END SNIPPET: strutsxml --> - * - * - * <!-- START SNIPPET: packageconfig --> - * - * Making this result type the default for the current package. - * - * <result-types> - * <result-type name="tiles" - * class="org.apache.struts2.views.tiles.TilesResult" default="true" /> - * </result-types> - * <!-- END SNIPPET: packageconfig --> - * - * - * <!-- START SNIPPET: tilesconfig --> - * You have to configure tiles itself. Therefore you can add <code>tiles.xml</code> either - * to resources or WEB-INF. You may also use annotations like {@link TilesDefinition}. - * - * <!-- END SNIPPET: tilesconfig --> - * - */ -public class TilesResult extends ServletDispatcherResult { - - private static final long serialVersionUID = -3806939435493086244L; - - private static final Logger LOG = LogManager.getLogger(TilesResult.class); - - public TilesResult() { - super(); - } - - public TilesResult(String location) { - super(location); - } - - /** - * Dispatches to the given location. Does its forward via a RequestDispatcher. If the - * dispatch fails a 404 error will be sent back in the http response. - * - * @param location the location to dispatch to. - * @param invocation the execution state of the action - * @throws Exception if an error occurs. If the dispatch fails the error will go back via the - * HTTP request. - */ - public void doExecute(String location, ActionInvocation invocation) throws Exception { - StrutsTilesAnnotationProcessor annotationProcessor = new StrutsTilesAnnotationProcessor(); - TilesDefinition tilesDefinition = null; - Object action = invocation.getAction(); - String actionName = invocation.getInvocationContext().getName(); - - if (StringUtils.isEmpty(location)) { - // location not set -> action must have one @TilesDefinition - tilesDefinition = annotationProcessor.findAnnotation(action, null); - String tileName = StringUtils.isNotEmpty(tilesDefinition.name()) ? tilesDefinition.name() : actionName; - location = tileName; - LOG.debug("using new location name '{}' and @TilesDefinition '{}'", location, tilesDefinition); - } - setLocation(location); - - ServletContext servletContext = ServletActionContext.getServletContext(); - - ApplicationContext applicationContext = ServletUtil.getApplicationContext(servletContext); - TilesContainer container = TilesAccess.getContainer(applicationContext); - - HttpServletRequest httpRequest = ServletActionContext.getRequest(); - HttpServletResponse httpResponse = ServletActionContext.getResponse(); - - Request request = new ServletRequest(applicationContext, httpRequest, httpResponse); - - boolean definitionValid = false; - try { - LOG.debug("checking if tiles definition exists '{}'", location); - definitionValid = container.isValidDefinition(location, request); - } catch (TilesException e) { - LOG.warn("got TilesException while checking if definiton exists, ignoring it", e); - } - if (!definitionValid) { - if (tilesDefinition == null) { - // tilesDefinition not found yet, search in action - tilesDefinition = annotationProcessor.findAnnotation(action, location); - } - if (tilesDefinition != null) { - Definition definition = annotationProcessor.buildTilesDefinition(location, tilesDefinition); - if (container instanceof MutableTilesContainer) { - LOG.debug("registering tiles definition with name '{}'", definition.getName()); - ((MutableTilesContainer)container).register(definition, request); - } else { - LOG.error("cannot register tiles definition as tiles container is not mutable!"); - } - } else { - LOG.warn("could not find @TilesDefinition for action: {}", actionName); - } - } - - container.render(location, request); - } -} +/* + * $Id$ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.struts2.views.tiles; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.struts2.ServletActionContext; +import org.apache.struts2.result.ServletDispatcherResult; +import org.apache.struts2.tiles.StrutsTilesAnnotationProcessor; +import org.apache.struts2.tiles.annotation.TilesDefinition; +import org.apache.tiles.Definition; +import org.apache.tiles.TilesContainer; +import org.apache.tiles.TilesException; + +import com.opensymphony.xwork2.ActionInvocation; +import org.apache.tiles.access.TilesAccess; +import org.apache.tiles.mgmt.MutableTilesContainer; +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.ServletUtil; + +/** + * <!-- START SNIPPET: description --> + * Renders a view using struts-tiles. + * <!-- END SNIPPET: description --> + * + * <!-- START SNIPPET: webxml --> + * In your web.xml file, you need to add a TilesListener. + * + * <listener> + * <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class> + * </listener> + * <!-- END SNIPPET: webxml --> + * + * <!-- START SNIPPET: strutsxml --> + * In struts.xml, use type="tiles" on your <result>. + * + * <action name="editUser" class="userAction" method="edit"> + * <result name="success" type="tiles">userForm</result> + * <result name="input" type="tiles">userList</result> + * </action> + * <!-- END SNIPPET: strutsxml --> + * + * + * <!-- START SNIPPET: packageconfig --> + * + * Making this result type the default for the current package. + * + * <result-types> + * <result-type name="tiles" + * class="org.apache.struts2.views.tiles.TilesResult" default="true" /> + * </result-types> + * <!-- END SNIPPET: packageconfig --> + * + * + * <!-- START SNIPPET: tilesconfig --> + * You have to configure tiles itself. Therefore you can add <code>tiles.xml</code> either + * to resources or WEB-INF. You may also use annotations like {@link TilesDefinition}. + * + * <!-- END SNIPPET: tilesconfig --> + * + */ +public class TilesResult extends ServletDispatcherResult { + + private static final long serialVersionUID = -3806939435493086244L; + + private static final Logger LOG = LogManager.getLogger(TilesResult.class); + + public TilesResult() { + super(); + } + + public TilesResult(String location) { + super(location); + } + + /** + * Dispatches to the given location. Does its forward via a RequestDispatcher. If the + * dispatch fails a 404 error will be sent back in the http response. + * + * @param location the location to dispatch to. + * @param invocation the execution state of the action + * @throws Exception if an error occurs. If the dispatch fails the error will go back via the + * HTTP request. + */ + public void doExecute(String location, ActionInvocation invocation) throws Exception { + StrutsTilesAnnotationProcessor annotationProcessor = new StrutsTilesAnnotationProcessor(); + TilesDefinition tilesDefinition = null; + Object action = invocation.getAction(); + String actionName = invocation.getInvocationContext().getName(); + + if (StringUtils.isEmpty(location)) { + // location not set -> action must have one @TilesDefinition + tilesDefinition = annotationProcessor.findAnnotation(action, null); + String tileName = StringUtils.isNotEmpty(tilesDefinition.name()) ? tilesDefinition.name() : actionName; + location = tileName; + LOG.debug("using new location name '{}' and @TilesDefinition '{}'", location, tilesDefinition); + } + setLocation(location); + + ServletContext servletContext = ServletActionContext.getServletContext(); + + ApplicationContext applicationContext = ServletUtil.getApplicationContext(servletContext); + TilesContainer container = TilesAccess.getContainer(applicationContext); + + HttpServletRequest httpRequest = ServletActionContext.getRequest(); + HttpServletResponse httpResponse = ServletActionContext.getResponse(); + + Request request = new ServletRequest(applicationContext, httpRequest, httpResponse); + + boolean definitionValid = false; + try { + LOG.debug("checking if tiles definition exists '{}'", location); + definitionValid = container.isValidDefinition(location, request); + } catch (TilesException e) { + LOG.warn("got TilesException while checking if definiton exists, ignoring it", e); + } + if (!definitionValid) { + if (tilesDefinition == null) { + // tilesDefinition not found yet, search in action + tilesDefinition = annotationProcessor.findAnnotation(action, location); + } + if (tilesDefinition != null) { + Definition definition = annotationProcessor.buildTilesDefinition(location, tilesDefinition); + if (container instanceof MutableTilesContainer) { + LOG.debug("registering tiles definition with name '{}'", definition.getName()); + ((MutableTilesContainer)container).register(definition, request); + } else { + LOG.error("cannot register tiles definition as tiles container is not mutable!"); + } + } else { + LOG.warn("could not find @TilesDefinition for action: {}", actionName); + } + } + + container.render(location, request); + } +}