⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multipledelegatingtilesrequestprocessor.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
 * This code is licensed under the GPL 2.0 license, availible at the root
 * application directory.
 */
package org.vfny.geoserver.config.web.tiles;

import org.apache.struts.action.ActionMapping;
import org.apache.struts.config.ForwardConfig;
import org.apache.struts.tiles.ComponentContext;
import org.apache.struts.tiles.ComponentDefinition;
import org.apache.struts.tiles.Controller;
import org.apache.struts.tiles.DefinitionsFactoryException;
import org.apache.struts.tiles.DefinitionsUtil;
import org.apache.struts.tiles.NoSuchDefinitionException;
import org.apache.struts.upload.MultipartRequestWrapper;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.struts.DelegatingActionProxy;
import org.springframework.web.struts.DelegatingActionUtils;
import org.springframework.web.struts.DelegatingRequestProcessor;
import org.springframework.web.struts.DelegatingTilesRequestProcessor;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Subclass of Struts' TilesRequestProcessor that looks up Spring-managed
 * Struts 1.1 Actions defined in ContextLoaderPlugIn's WebApplicationContext.
 *
 * <p>Behaves like
 * {@link DelegatingRequestProcessor DelegatingRequestProcessor},
 * but also provides the Tiles functionality of the original TilesRequestProcessor.
 * As there's just a single central class to customize in Struts, we have to provide
 * another subclass here, covering both the Tiles and the Spring delegation aspect.
 *
 * <p>The default implementation delegates to the DelegatingActionUtils
 * class as fas as possible, to reuse as much code as possible despite
 * the need to provide two RequestProcessor subclasses. If you need to
 * subclass yet another RequestProcessor, take this class as a template,
 * delegating to DelegatingActionUtils just like it.
 *
 * @author Juergen Hoeller
 * @since 1.0.2
 * @see DelegatingRequestProcessor
 * @see DelegatingActionProxy
 * @see DelegatingActionUtils
 */
public class MultipleDelegatingTilesRequestProcessor extends DelegatingTilesRequestProcessor {
    /**
     * Overloaded method from Struts' RequestProcessor.
     * Forward or redirect to the specified destination by the specified
     * mechanism.
     * This method catches the Struts' actionForward call. It checks if the
     * actionForward is done on a Tiles definition name. If true, process the
     * definition and insert it. If false, call the original parent's method.
     * @param request The servlet request we are processing.
     * @param response The servlet response we are creating.
     * @param forward The ActionForward controlling where we go next.
     *
     * @exception IOException if an input/output error occurs.
     * @exception ServletException if a servlet exception occurs.
     */
    protected void processForwardConfig(HttpServletRequest request, HttpServletResponse response,
        ForwardConfig forward) throws IOException, ServletException {
        // Required by struts contract
        if (forward == null) {
            return;
        }

        if (log.isDebugEnabled()) {
            log.debug("processForwardConfig(" + forward.getPath() + ", "
                + forward.getContextRelative() + ")");
        }

        // Try to process the definition.
        if (processTilesDefinition(forward.getPath(), /*forward.getContextRelative()*/
                    false, request, response)) {
            if (log.isDebugEnabled()) {
                log.debug("  '" + forward.getPath() + "' - processed as definition");
            }

            return;
        }

        if (log.isDebugEnabled()) {
            log.debug("  '" + forward.getPath() + "' - processed as uri");
        }

        // forward doesn't contain a definition, let parent do processing
        super.processForwardConfig(request, response, forward);
    }

    /**
     * Process a Tile definition name.
     * This method tries to process the parameter <code>definitionName</code> as a definition name.
     * It returns <code>true</code> if a definition has been processed, or <code>false</code> otherwise.
     * Parameter <code>contextRelative</code> is not used in this implementation.
     *
     * @param definitionName Definition name to insert.
     * @param contextRelative Is the definition marked contextRelative ?
     * @param request Current page request.
     * @param response Current page response.
     * @return <code>true</code> if the method has processed uri as a definition name, <code>false</code> otherwise.
     */
    protected boolean processTilesDefinition(String definitionName, boolean contextRelative,
        HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
        // Do we do a forward (original behavior) or an include ?
        boolean doInclude = false;

        // Controller associated to a definition, if any
        Controller controller = null;

        // Computed uri to include
        String uri = null;

        ComponentContext tileContext = null;

        try {
            // Get current tile context if any.
            // If context exist, we will do an include
            tileContext = ComponentContext.getContext(request);
            doInclude = (tileContext != null);

            ComponentDefinition definition = null;

            // Process tiles definition names only if a definition factory exist,
            // and definition is found.
            if (definitionsFactory != null) {
                // Get definition of tiles/component corresponding to uri.
                try {
                    definition = definitionsFactory.getDefinition(definitionName, request,
                            getServletContext());
                } catch (NoSuchDefinitionException ex) {
                    // Ignore not found
                    log.debug("NoSuchDefinitionException " + ex.getMessage());
                }

                if (definition != null) { // We have a definition.
                                          // We use it to complete missing attribute in context.
                                          // We also get uri, controller.
                    uri = definition.getPath();
                    controller = definition.getOrCreateController();

                    if (tileContext == null) {
                        tileContext = new ComponentContext(definition.getAttributes());
                        ComponentContext.setContext(tileContext, request);
                    } else {
                        tileContext.addMissing(definition.getAttributes());
                    }
                }
            }

            // Process definition set in Action, if any.
            definition = DefinitionsUtil.getActionDefinition(request);

            if (definition != null) { // We have a definition.
                                      // We use it to complete missing attribute in context.
                                      // We also overload uri and controller if set in definition.

                if (definition.getPath() != null) {
                    uri = definition.getPath();
                }

                if (definition.getOrCreateController() != null) {
                    controller = definition.getOrCreateController();
                }

                if (tileContext == null) {
                    tileContext = new ComponentContext(definition.getAttributes());
                    ComponentContext.setContext(tileContext, request);
                } else {
                    tileContext.addMissing(definition.getAttributes());
                }
            }
        } catch (java.lang.InstantiationException ex) {
            log.error("Can't create associated controller", ex);

            throw new ServletException("Can't create associated controller", ex);
        } catch (DefinitionsFactoryException ex) {
            throw new ServletException(ex);
        }

        // Have we found a definition ?

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -