You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by mr...@apache.org on 2005/08/26 07:46:58 UTC

svn commit: r240168 [9/30] - in /struts/sandbox/trunk/ti: ./ core/src/java/org/apache/ti/ core/src/java/org/apache/ti/config/ core/src/java/org/apache/ti/config/mapper/ core/src/java/org/apache/ti/core/ core/src/java/org/apache/ti/core/factory/ core/sr...

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/HandlerConfig.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/HandlerConfig.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/HandlerConfig.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/HandlerConfig.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.handler;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Class for encapsulating configuration properties associated with a {@link Handler}.
+ */
+public class HandlerConfig
+        implements Serializable {
+
+    private Map/*< String, String >*/ _customProperties = new HashMap/*< String, String >*/();
+    private String _handlerClass;
+
+    public HandlerConfig(String handlerClass) {
+        _handlerClass = handlerClass;
+    }
+
+    public Map/*< String, String >*/ getCustomProperties() {
+        return _customProperties;
+    }
+
+    void addCustomProperty(String name, String value) {
+        _customProperties.put(name, value);
+    }
+
+    public String getCustomProperty(String name) {
+        return (String) _customProperties.get(name);
+    }
+
+    public String getHandlerClass() {
+        return _handlerClass;
+    }
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/Handlers.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/Handlers.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/Handlers.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/Handlers.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,254 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.handler;
+
+import com.opensymphony.xwork.ActionContext;
+import org.apache.ti.pageflow.internal.DefaultHandler;
+import org.apache.ti.pageflow.internal.InternalConstants;
+import org.apache.ti.schema.config.CustomProperty;
+import org.apache.ti.schema.config.NetuiConfigDocument;
+import org.apache.ti.schema.config.PageflowHandlers;
+import org.apache.ti.util.config.ConfigUtil;
+import org.apache.ti.util.internal.DiscoveryUtils;
+import org.apache.ti.util.logging.Logger;
+
+import java.io.Serializable;
+import java.util.Map;
+
+/**
+ * ServletContext-scoped container for various Page Flow {@link Handler} instances.
+ */
+public class Handlers
+        implements Serializable {
+
+    private static final long serialVersionUID = 1;
+    private static final Logger _log = Logger.getInstance(Handlers.class);
+
+    private static final String CONTEXT_ATTR = InternalConstants.ATTR_PREFIX + "_handlers";
+
+    private ExceptionsHandler _exceptionsHandler = null;
+    private ForwardRedirectHandler _forwardRedirectHandler = null;
+    private LoginHandler _loginHandler = null;
+    private StorageHandler _storageHandler = null;
+    private ReloadableClassHandler _reloadableClassHandler = null;
+    private ModuleRegistrationHandler _moduleRegistrationHandler = null;
+    private AnnotationHandler _annotationHandler = null;
+
+    private DefaultHandler _defaultExceptionsHandler;
+    private DefaultHandler _defaultForwardRedirectHandler;
+    private DefaultHandler _defaultLoginHandler;
+    private DefaultHandler _defaultStorageHandler;
+    private DefaultHandler _defaultReloadableClassHandler;
+    private DefaultHandler _defaultModuleRegistrationHandler;
+    private DefaultHandler _defaultAnnotationHandler;
+
+    public static Handlers get() {
+        ActionContext actionContext = ActionContext.getContext();
+        Handlers handlers = (Handlers) actionContext.getApplication().get(CONTEXT_ATTR);
+        assert handlers != null : "Page Flow Handlers not initialized.";
+        return handlers;
+    }
+
+    public void initApplication(Map appScope) {
+        //
+        // Load/create Handlers.
+        //
+        NetuiConfigDocument.NetuiConfig netuiConfig = ConfigUtil.getConfig();
+        PageflowHandlers handlers = netuiConfig.getPageflowHandlers();
+
+        _exceptionsHandler = (ExceptionsHandler)
+                adaptHandler(handlers != null ? handlers.getExceptionsHandlerArray() : null, _defaultExceptionsHandler,
+                        ExceptionsHandler.class);
+
+        _forwardRedirectHandler = (ForwardRedirectHandler)
+                adaptHandler(handlers != null ? handlers.getForwardRedirectHandlerArray() : null,
+                        _defaultForwardRedirectHandler, ForwardRedirectHandler.class);
+
+        _loginHandler = (LoginHandler)
+                adaptHandler(handlers != null ? handlers.getLoginHandlerArray() : null, _defaultLoginHandler,
+                        LoginHandler.class);
+
+        _storageHandler = (StorageHandler)
+                adaptHandler(handlers != null ? handlers.getStorageHandlerArray() : null, _defaultStorageHandler,
+                        StorageHandler.class);
+
+        _reloadableClassHandler = (ReloadableClassHandler)
+                adaptHandler(handlers != null ? handlers.getReloadableClassHandlerArray() : null,
+                        _defaultReloadableClassHandler, ReloadableClassHandler.class);
+
+        _moduleRegistrationHandler = (ModuleRegistrationHandler)
+                adaptHandler(handlers != null ? handlers.getModuleRegistrationHandlerArray() : null,
+                        _defaultModuleRegistrationHandler, ModuleRegistrationHandler.class);
+
+        _annotationHandler = (AnnotationHandler)
+                adaptHandler(handlers != null ? handlers.getAnnotationHandlerArray() : null,
+                        _defaultAnnotationHandler, AnnotationHandler.class);
+
+        appScope.put(CONTEXT_ATTR, this);
+    }
+
+    public ExceptionsHandler getExceptionsHandler() {
+        return _exceptionsHandler;
+    }
+
+    public ForwardRedirectHandler getForwardRedirectHandler() {
+        return _forwardRedirectHandler;
+    }
+
+    public LoginHandler getLoginHandler() {
+        return _loginHandler;
+    }
+
+    public StorageHandler getStorageHandler() {
+        return _storageHandler;
+    }
+
+    public ReloadableClassHandler getReloadableClassHandler() {
+        return _reloadableClassHandler;
+    }
+
+    public ModuleRegistrationHandler getModuleRegistrationHandler() {
+        return _moduleRegistrationHandler;
+    }
+
+    public AnnotationHandler getAnnotationHandler() {
+        return _annotationHandler;
+    }
+
+    private static Handler adaptHandler(org.apache.ti.schema.config.Handler[] handlerBeanConfigs,
+                                        DefaultHandler defaultHandler, Class baseClassOrInterface) {
+        Handler retVal = defaultHandler;
+
+        if (handlerBeanConfigs != null) {
+            for (int i = 0; i < handlerBeanConfigs.length; i++) {
+                String handlerClass = handlerBeanConfigs[i].getHandlerClass();
+                CustomProperty[] props = handlerBeanConfigs[i].getCustomPropertyArray();
+                Handler handler = createHandler(handlerClass, baseClassOrInterface, retVal);
+
+                if (handler != null) {
+                    HandlerConfig config = new HandlerConfig(handlerClass);
+
+                    for (int j = 0; j < props.length; j++) {
+                        CustomProperty prop = props[j];
+                        config.addCustomProperty(prop.getName(), prop.getValue());
+                    }
+
+                    handler.init(config, retVal);
+                    retVal = handler;
+                }
+            }
+        }
+
+        defaultHandler.init(null, null);
+        defaultHandler.setRegisteredHandler(retVal);
+        return retVal;
+    }
+
+    /**
+     * Instantiates a handler, based on the class name in the given HandlerConfig.
+     *
+     * @param className            the class name of the desired Handler.
+     * @param baseClassOrInterface the required base class or interface.  May be <code>null</code>.
+     * @return an initialized Handler.
+     */
+    private static Handler createHandler(String className, Class baseClassOrInterface, Handler previousHandler) {
+        assert Handler.class.isAssignableFrom(baseClassOrInterface)
+                : baseClassOrInterface.getName() + " cannot be assigned to " + Handler.class.getName();
+
+        ClassLoader cl = DiscoveryUtils.getClassLoader();
+
+        try {
+            Class handlerClass = cl.loadClass(className);
+
+            if (!baseClassOrInterface.isAssignableFrom(handlerClass)) {
+                _log.error("Handler " + handlerClass.getName() + " does not implement or extend "
+                        + baseClassOrInterface.getName());
+                return null;
+            }
+
+            Handler handler = (Handler) handlerClass.newInstance();
+            // TODO: add a way to set custom props on HandlerConfig
+            handler.init(new HandlerConfig(className), previousHandler);
+            return handler;
+        } catch (ClassNotFoundException e) {
+            _log.error("Could not find Handler class " + className, e);
+        } catch (InstantiationException e) {
+            _log.error("Could not instantiate Handler class " + className, e);
+        } catch (IllegalAccessException e) {
+            _log.error("Could not instantiate Handler class " + className, e);
+        }
+
+        return null;
+    }
+
+    public DefaultHandler getDefaultExceptionsHandler() {
+        return _defaultExceptionsHandler;
+    }
+
+    public void setDefaultExceptionsHandler(DefaultHandler defaultExceptionsHandler) {
+        _defaultExceptionsHandler = defaultExceptionsHandler;
+    }
+
+    public DefaultHandler getDefaultForwardRedirectHandler() {
+        return _defaultForwardRedirectHandler;
+    }
+
+    public void setDefaultForwardRedirectHandler(DefaultHandler defaultForwardRedirectHandler) {
+        _defaultForwardRedirectHandler = defaultForwardRedirectHandler;
+    }
+
+    public DefaultHandler getDefaultLoginHandler() {
+        return _defaultLoginHandler;
+    }
+
+    public void setDefaultLoginHandler(DefaultHandler defaultLoginHandler) {
+        _defaultLoginHandler = defaultLoginHandler;
+    }
+
+    public DefaultHandler getDefaultStorageHandler() {
+        return _defaultStorageHandler;
+    }
+
+    public void setDefaultStorageHandler(DefaultHandler defaultStorageHandler) {
+        _defaultStorageHandler = defaultStorageHandler;
+    }
+
+    public DefaultHandler getDefaultReloadableClassHandler() {
+        return _defaultReloadableClassHandler;
+    }
+
+    public void setDefaultReloadableClassHandler(DefaultHandler defaultReloadableClassHandler) {
+        _defaultReloadableClassHandler = defaultReloadableClassHandler;
+    }
+
+    public DefaultHandler getDefaultModuleRegistrationHandler() {
+        return _defaultModuleRegistrationHandler;
+    }
+
+    public void setDefaultModuleRegistrationHandler(DefaultHandler defaultModuleRegistrationHandler) {
+        _defaultModuleRegistrationHandler = defaultModuleRegistrationHandler;
+    }
+
+    public DefaultHandler getDefaultAnnotationHandler() {
+        return _defaultAnnotationHandler;
+    }
+
+    public void setDefaultAnnotationHandler(DefaultHandler defaultAnnotationHandler) {
+        _defaultAnnotationHandler = defaultAnnotationHandler;
+    }
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/LoginHandler.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/LoginHandler.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/LoginHandler.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/LoginHandler.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.handler;
+
+import javax.security.auth.login.LoginException;
+import java.security.Principal;
+
+
+/**
+ * Handler for login/logout/roles.
+ */
+public interface LoginHandler
+        extends Handler {
+
+    /**
+     * Log in the given user.
+     *
+     * @param username the user to log in.
+     * @param password the user's password.
+     * @throws LoginException if the login fails.
+     */
+    public void login(String username, String password)
+            throws LoginException;
+
+    /**
+     * Log out the current user.
+     *
+     * @param invalidateSessions if <code>true</code>, current sessions associated with the current
+     *                           logged-in user will be invalidated.
+     */
+    public void logout(boolean invalidateSessions);
+
+
+    /**
+     * Tell whether the current user is in a given role.
+     *
+     * @param roleName the role to check.
+     * @return <code>true</code> if there is a current logged-in user who is in the given role.
+     */
+    public boolean isUserInRole(String roleName);
+
+    /**
+     * Get the current user.
+     *
+     * @return a {@link Principal} that represents the current logged-in user, or <code>null</code> if there is no
+     *         logged-in user.
+     */
+    public Principal getUserPrincipal();
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/ModuleRegistrationHandler.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/ModuleRegistrationHandler.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/ModuleRegistrationHandler.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/ModuleRegistrationHandler.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.handler;
+
+import org.apache.ti.pageflow.ModuleConfig;
+import org.apache.ti.pageflow.ModuleConfigLocator;
+
+import java.net.URL;
+
+public interface ModuleRegistrationHandler extends Handler {
+
+    /**
+     * Get the ModuleConfig for the given namespace (registering the module dynamically if necessary).
+     *
+     * @param namespace the namespace of the desired module.
+     * @return the ModuleConfig that corresponds with <code>namespace</code>.
+     */
+    public ModuleConfig getModuleConfig(String namespace);
+
+    /**
+     * Clear all registered modules.
+     */
+    public void clearRegisteredModules();
+
+    /**
+     * Get the current list of registered ModuleConfigLocators.
+     *
+     * @return an array of registered ModuleConfigLocators.
+     */
+    public ModuleConfigLocator[] getModuleConfigLocators();
+
+    /**
+     * Get the resource URL the Struts module configration file for a given namespace.
+     * based on registered ModuleConfigLocators.
+     *
+     * @param namespace the namespace of the module.
+     * @return a String that is the path to the Struts configuration file, relative to the web application root,
+     *         or <code>null</code> if no appropriate configuration file is found.
+     */
+    public URL getModuleConfURL(String namespace);
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/ReloadableClassHandler.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/ReloadableClassHandler.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/ReloadableClassHandler.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/ReloadableClassHandler.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.handler;
+
+
+/**
+ * Handler for loading and reloading classes.
+ */
+public interface ReloadableClassHandler
+        extends Handler {
+
+    Object newInstance(String className)
+            throws ClassNotFoundException, InstantiationException, IllegalAccessException;
+
+    Class loadClass(String className)
+            throws ClassNotFoundException;
+
+    Class loadCachedClass(String className);
+
+    void reloadClasses();
+
+    ClassLoader getClassLoader();
+
+    boolean isReloadEnabled();
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/StorageHandler.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/StorageHandler.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/StorageHandler.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/handler/StorageHandler.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.handler;
+
+
+/**
+ * Handler for storing Page Flow objects.
+ */
+public interface StorageHandler
+        extends Handler {
+
+    /**
+     * Set a named attribute.
+     *
+     * @param attributeName the name of the attribute to set.
+     * @param value         the attribute value.
+     */
+    public void setAttribute(String attributeName, Object value);
+
+    /**
+     * Remove a named attribute.
+     *
+     * @param attributeName the name of the attribute to remove.
+     */
+    public void removeAttribute(String attributeName);
+
+    /**
+     * Get a named attribute.
+     *
+     * @param attributeName the name of the attribute to get.
+     * @return the attribute, or <code>null</code> if there is no such named attribute.
+     */
+    public Object getAttribute(String attributeName);
+
+    /**
+     * Ensure that the given named attribute is replicated in a cluster for session failover, if appropriate.
+     *
+     * @param attributeName the name of the attribute for which failover should be ensured.
+     * @param value         the value of the attribute for which failover should be ensured.
+     */
+    public void ensureFailover(String attributeName, Object value);
+
+    /**
+     * Tell whether a given binding event should be allowed to occur.  This is mainly useful in cases when this
+     * handler writes data to some underlying storage (like the <code>HttpSession</code>) at some time other than
+     * when {@link #setAttribute} is called, in which case a binding event would be misleading.  Only
+     * {@link org.apache.ti.pageflow.PageFlowManagedObject}s pay attention to this.
+     *
+     * @param event the binding event, e.g., <code>javax.servlet.http.HttpSessionBindingEvent</code>
+     * @return <code>true</code> if the event should be processed.
+     */
+    public boolean allowBindingEvent(Object event);
+
+    public Object getStorageLocation();
+
+    /**
+     * Apply any deferred changes, at the end of a chain of requests.
+     */
+    public void applyChanges();
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/HttpServletPageFlowController.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/HttpServletPageFlowController.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/HttpServletPageFlowController.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/HttpServletPageFlowController.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.httpservlet;
+
+import org.apache.ti.pageflow.PageFlowController;
+
+import javax.servlet.http.HttpServletRequest;
+
+public class HttpServletPageFlowController extends PageFlowController {
+
+    protected HttpServletRequest getRequest() {
+        throw new UnsupportedOperationException("NYI"); // TODO: NYI
+    }
+
+    protected boolean sessionExists() {
+        return getRequest().getSession(false) != null;
+    }
+
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/DefaultServletForwardRedirectHandler.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/DefaultServletForwardRedirectHandler.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/DefaultServletForwardRedirectHandler.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/DefaultServletForwardRedirectHandler.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.httpservlet.internal;
+
+import org.apache.commons.chain.web.WebContext;
+import org.apache.commons.chain.web.servlet.ServletWebContext;
+import org.apache.ti.pageflow.PageFlowException;
+import org.apache.ti.pageflow.internal.DefaultForwardRedirectHandler;
+import org.apache.ti.pageflow.xwork.PageFlowActionContext;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+
+public class DefaultServletForwardRedirectHandler extends DefaultForwardRedirectHandler {
+
+    public void redirect(String uri) throws PageFlowException {
+        try {
+            WebContext webContext = PageFlowActionContext.get().getWebContext();
+            assert webContext instanceof ServletWebContext : webContext.getClass().getName();
+            ServletWebContext servletWebContext = (ServletWebContext) webContext;
+            servletWebContext.getResponse().sendRedirect(uri);
+        } catch (IOException e) {
+            throw new PageFlowException(e);
+        }
+    }
+
+    protected void doForward(String uri) throws PageFlowException {
+        //
+        // Note that we get a RequestDispatcher from the request, not from the ServletContext.
+        // The request may be a ScopedRequest, which provides a special RequestDispatcher.
+        //
+        try {
+            WebContext webContext = PageFlowActionContext.get().getWebContext();
+            assert webContext instanceof ServletWebContext : webContext.getClass().getName();
+            ServletWebContext servletWebContext = (ServletWebContext) webContext;
+            HttpServletRequest request = servletWebContext.getRequest();
+            request.getRequestDispatcher(uri).forward(request, servletWebContext.getResponse());
+        } catch (IOException e) {
+            throw new PageFlowException(e);
+        } catch (ServletException e) {
+            throw new PageFlowException(e);
+        }
+    }
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/DefaultServletLoginHandler.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/DefaultServletLoginHandler.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/DefaultServletLoginHandler.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/DefaultServletLoginHandler.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.httpservlet.internal;
+
+import org.apache.commons.chain.web.servlet.ServletWebContext;
+import org.apache.ti.pageflow.internal.DefaultLoginHandler;
+import org.apache.ti.pageflow.xwork.PageFlowActionContext;
+
+import javax.servlet.http.HttpServletRequest;
+import java.security.Principal;
+
+public class DefaultServletLoginHandler extends DefaultLoginHandler {
+
+    public boolean isUserInRole(String roleName) {
+        HttpServletRequest req = ((ServletWebContext) PageFlowActionContext.get().getWebContext()).getRequest();
+        return req.isUserInRole(roleName);
+    }
+
+    public Principal getUserPrincipal() {
+        HttpServletRequest req = ((ServletWebContext) PageFlowActionContext.get().getWebContext()).getRequest();
+        return req.getUserPrincipal();
+    }
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/DefaultServletTemplatedURLFormatter.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/DefaultServletTemplatedURLFormatter.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/DefaultServletTemplatedURLFormatter.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/DefaultServletTemplatedURLFormatter.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.httpservlet.internal;
+
+import org.apache.commons.chain.web.servlet.ServletWebContext;
+import org.apache.ti.core.urls.MutableURI;
+import org.apache.ti.core.urls.TemplatedURLFormatter;
+import org.apache.ti.core.urls.URIContext;
+import org.apache.ti.core.urltemplates.URLTemplate;
+import org.apache.ti.core.urltemplates.URLTemplatesFactory;
+import org.apache.ti.pageflow.xwork.PageFlowActionContext;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+/**
+ * Default implementation of TemplatedURLFormatter for formatting URLs
+ * based on templates from a URL template config file.
+ * <p/>
+ * <p/>
+ * Used by URLRewriterService to apply any relevant templates to a URL,
+ * after all other rewriting has been done on the URL.
+ * </p>
+ */
+public class DefaultServletTemplatedURLFormatter extends TemplatedURLFormatter {
+
+    /**
+     * Format the given URL using a URL template, if defined in a URL
+     * template config file. The {@link org.apache.ti.core.urls.URIContext}
+     * encapsulates some additional data needed to write out the string form.
+     * E.g. It defines if the &quot;&amp;amp;&quot; entity or the
+     * '&amp;' character should be used to separate quary parameters.
+     *
+     * @param uri        the MutableURI to be formatted into a String.
+     * @param key        key for the URL template type to use for formatting the URI
+     * @param uriContext data required to write out the string form.
+     * @return the URL as a <code>String</code>
+     */
+    public String getTemplatedURL(MutableURI uri, String key, URIContext uriContext) {
+        // Look for the template config and get the right template.
+        // If it is found, apply the value to the template.
+        String result;
+        URLTemplate template = null;
+        URLTemplatesFactory factory = URLTemplatesFactory.getURLTemplatesFactory();
+
+        if (factory != null) {
+            String templateName = factory.getTemplateNameByRef(DEFAULT_TEMPLATE_REF, key);
+
+            if (templateName != null) {
+                template = factory.getURLTemplate(templateName);
+            }
+        }
+
+        if (template != null) {
+            result = formatURIWithTemplate(uri, uriContext, template);
+        } else {
+            // no template found, just return the uri as a String...
+            result = uri.getURIString(uriContext);
+        }
+
+        return result;
+    }
+
+    private String formatURIWithTemplate(MutableURI uri, URIContext uriContext, URLTemplate template) {
+        ServletWebContext webContext = (ServletWebContext) PageFlowActionContext.get().getWebContext();
+
+        String scheme = uri.getScheme();
+        String host = uri.getHost();
+        int port = uri.getPort();
+        HttpServletRequest request = webContext.getRequest();
+
+        if (scheme == null || scheme.length() == 0) {
+            scheme = request.getScheme();
+        }
+
+        if (host == null || host.length() == 0) {
+            host = request.getServerName();
+        }
+
+        if (port < 0) {
+            port = request.getServerPort();
+        }
+
+        template.substitute(TemplatedURLFormatter.SCHEME_TOKEN, scheme);
+        template.substitute(TemplatedURLFormatter.DOMAIN_TOKEN, host);
+        template.substitute(TemplatedURLFormatter.PORT_TOKEN, port);
+        template.substitute(TemplatedURLFormatter.PATH_TOKEN, uri.getPath());
+
+        String query;
+        query = uri.getQuery(uriContext);
+
+        if (query == null) {
+            query = "";
+        }
+
+        template.substitute(TemplatedURLFormatter.QUERY_STRING_TOKEN, query);
+
+        String fragment = uri.getFragment();
+
+        if (fragment == null) {
+            fragment = "";
+        }
+
+        template.substitute(TemplatedURLFormatter.FRAGMENT_TOKEN, fragment);
+
+        return template.format();
+    }
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/DefaultServletURLRewriter.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/DefaultServletURLRewriter.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/DefaultServletURLRewriter.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/DefaultServletURLRewriter.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.httpservlet.internal;
+
+import org.apache.commons.chain.web.servlet.ServletWebContext;
+import org.apache.ti.core.urls.MutableURI;
+import org.apache.ti.core.urls.URLRewriter;
+import org.apache.ti.core.urls.URLType;
+import org.apache.ti.pageflow.ContainerAdapter;
+import org.apache.ti.pageflow.internal.AdapterManager;
+import org.apache.ti.pageflow.internal.DefaultURLRewriter;
+import org.apache.ti.pageflow.internal.InternalConstants;
+import org.apache.ti.pageflow.xwork.PageFlowActionContext;
+import org.apache.ti.util.logging.Logger;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+public class DefaultServletURLRewriter extends URLRewriter {
+
+    private static final Logger _log = Logger.getInstance(DefaultURLRewriter.class);
+
+    public String getNamePrefix(String name) {
+        return "";
+    }
+
+    public void rewriteURL(MutableURI url, URLType type, boolean needsToBeSecure) {
+        ContainerAdapter containerAdapter = AdapterManager.getContainerAdapter();
+        ServletWebContext webContext = (ServletWebContext) PageFlowActionContext.get().getWebContext();
+        HttpServletRequest request = webContext.getRequest();
+
+        // If url is not absolute, then do default secure/unsecure rewriting
+        if (!url.isAbsolute()) {
+            if (needsToBeSecure) {
+                if (!request.isSecure()) {
+                    int securePort = containerAdapter.getSecureListenPort();
+
+                    if (securePort != -1) {
+                        internalRewriteUrl(url, "https", securePort, request.getServerName());
+                    } else {
+                        if (_log.isWarnEnabled()) {
+                            _log.warn("Could not rewrite URL " + url.getURIString(null) + " to be secure because" +
+                                    " a secure port was not provided by the ContainerAdapter.");
+                        }
+                    }
+                }
+            } else {
+                if (request.isSecure()) {
+                    int listenPort = containerAdapter.getListenPort();
+
+                    if (listenPort != -1) {
+                        internalRewriteUrl(url, "http", listenPort, request.getServerName());
+                    } else {
+                        if (_log.isWarnEnabled()) {
+                            _log.warn("Could not rewrite URL " + url.getURIString(null) + " to be non-secure" +
+                                    " because a port was not provided by the ContainerAdapter.");
+                        }
+                    }
+                }
+            }
+        }
+
+        //
+        // If the current request has a special parameter that addresses a named 'scope',
+        // add the parameter to the URL.
+        //
+        String scopeID = (String) PageFlowActionContext.get().getParameters().get(InternalConstants.SCOPE_ID_PARAM);
+        if (scopeID != null) {
+            // check to see if the param is already there.
+            if (url.getParameter(InternalConstants.SCOPE_ID_PARAM) == null) {
+                url.addParameter(InternalConstants.SCOPE_ID_PARAM, scopeID, true);
+            }
+        }
+    }
+
+    private static void internalRewriteUrl(MutableURI url, String protocol, int port, String serverName) {
+        // Need to build up the url
+        url.setScheme(protocol);
+        url.setHost(serverName);
+        url.setPort(port);
+    }
+
+    /**
+     * Determines if the passed-in Object is equivalent to this DefaultURLRewriter.
+     * Since there is no member data for this class they will all be equal.
+     *
+     * @param object the Object to test for equality.
+     * @return true if object is another instance of DefaultURLRewriter.
+     */
+
+    public boolean equals(Object object) {
+        if (object == this) {
+            return true;
+        }
+
+        if (object == null || !object.getClass().equals(getClass())) {
+            return false;
+        }
+
+        return true;
+    }
+
+    /**
+     * Returns a hash code value for the object.
+     * Implemented in conjunction with equals() override.
+     * Since there is no member data for this class we
+     * always return the same value.
+     *
+     * @return a hash code value for this object.
+     */
+
+    public int hashCode() {
+        return 0;
+    }
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/PageFlowActionMapper.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/PageFlowActionMapper.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/PageFlowActionMapper.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/PageFlowActionMapper.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.httpservlet.internal;
+
+import org.apache.commons.chain.web.WebContext;
+import org.apache.commons.chain.web.servlet.ServletWebContext;
+import org.apache.ti.config.mapper.ActionMapping;
+import org.apache.ti.config.mapper.ServletActionMapper;
+import org.apache.ti.pageflow.PageFlowConstants;
+import org.apache.ti.pageflow.internal.InternalConstants;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Enumeration;
+import java.util.HashMap;
+
+public class PageFlowActionMapper extends ServletActionMapper {
+
+    private static final String ALREADY_OVERRODE_ACTION_ATTR = InternalConstants.ATTR_PREFIX + "overrodeAction";
+
+    public ActionMapping getMapping(WebContext ctx) {
+        ActionMapping mapping = super.getMapping(ctx);
+        
+        // *.jpf automatically gets translated to action "begin"
+        if (mapping.getExternalMapping().endsWith(PageFlowConstants.PAGEFLOW_EXTENSION)) {
+            mapping = new ActionMapping(PageFlowConstants.BEGIN_ACTION_NAME, mapping.getNamespace(),
+                    mapping.getExternalMapping(), mapping.getParams());
+        }
+
+        HttpServletRequest request = ((ServletWebContext) ctx).getRequest();
+        if (request.getAttribute(ALREADY_OVERRODE_ACTION_ATTR) == null) {
+            String actionOverride = getActionOverride(request);
+
+            if (actionOverride != null) {
+                HashMap params = new HashMap();
+                params.put(InternalConstants.ORIGINAL_ACTION_KEY, mapping.getName());
+                if (mapping.getParams() != null) {
+                    params.putAll(mapping.getParams());
+                }
+                mapping = new ActionMapping(actionOverride, mapping.getNamespace(), mapping.getExternalMapping(), params);
+                request.setAttribute(ALREADY_OVERRODE_ACTION_ATTR, Boolean.TRUE);
+            }
+        }
+
+        return mapping;
+    }
+
+    protected String getActionOverride(HttpServletRequest request) {
+
+        for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
+            String paramName = (String) e.nextElement();
+            if (paramName.startsWith(PageFlowConstants.ACTION_OVERRIDE_PARAM_PREFIX)) {
+                return paramName.substring(PageFlowConstants.ACTION_OVERRIDE_PARAM_PREFIX.length());
+            }
+        }
+
+        return null;
+    }
+
+
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/PopulatePageFlowContext.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/PopulatePageFlowContext.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/PopulatePageFlowContext.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/PopulatePageFlowContext.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.httpservlet.internal;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.commons.chain.web.servlet.ServletWebContext;
+import org.apache.ti.config.mapper.ActionMapper;
+import org.apache.ti.config.mapper.ActionMapping;
+import org.apache.ti.pageflow.xwork.PageFlowActionContext;
+
+import javax.servlet.http.HttpServletRequest;
+
+public class PopulatePageFlowContext implements Command {
+
+    public boolean execute(Context context) throws Exception {
+        PageFlowActionContext actionContext = PageFlowActionContext.get();
+        ServletWebContext swc = (ServletWebContext) actionContext.getWebContext();
+        HttpServletRequest request = swc.getRequest();
+        
+        
+        
+        // First try to construct the request path from the ActionMapper.
+        ActionMapping mapping = actionContext.getActionMapping();
+
+        if (mapping != null) {
+            ActionMapper mapper = actionContext.getActionMapper();
+            actionContext.setRequestPath(mapper.getUriFromActionMapping(mapping));
+        } else {
+            // If there was no ActionMapping (this is not an action request), just use the Servlet path.
+            // TODO: re-add the ignoreIncludeServletPath() check, for page template support
+            // if ( ignoreIncludeServletPath() ) return request.getServletPath();
+            String servletIncludePath = (String) request.getAttribute("javax.servlet.include.servlet_path");
+            actionContext.setRequestPath(servletIncludePath != null ? servletIncludePath : request.getServletPath());
+        }
+
+        actionContext.setRequestContextPath(request.getContextPath());
+        actionContext.setRequestQueryString(request.getQueryString());
+        actionContext.setRequestSecure(request.isSecure());
+        return false;
+    }
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/ServletDeferredSessionStorageHandler.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/ServletDeferredSessionStorageHandler.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/ServletDeferredSessionStorageHandler.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/ServletDeferredSessionStorageHandler.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.httpservlet.internal;
+
+import org.apache.commons.chain.web.servlet.ServletWebContext;
+import org.apache.ti.pageflow.internal.DeferredSessionStorageHandler;
+import org.apache.ti.pageflow.xwork.PageFlowActionContext;
+
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
+
+public class ServletDeferredSessionStorageHandler extends DeferredSessionStorageHandler {
+
+    protected void raiseRemoveEvent(String attrName, Object value) {
+        if (value instanceof HttpSessionBindingListener) {
+            ServletWebContext webContext = (ServletWebContext) PageFlowActionContext.get().getWebContext();
+            HttpSession session = webContext.getRequest().getSession();
+            HttpSessionBindingEvent event = new SessionBindingEvent(session, attrName, value);
+            ((HttpSessionBindingListener) value).valueUnbound(event);
+        }
+    }
+
+    public Object getStorageLocation() {
+        ServletWebContext webContext = (ServletWebContext) PageFlowActionContext.get().getWebContext();
+        return webContext.getRequest().getSession();
+    }
+
+    private static final class SessionBindingEvent
+            extends HttpSessionBindingEvent {
+
+        public SessionBindingEvent(HttpSession httpSession, String attrName) {
+            super(httpSession, attrName);
+        }
+
+        public SessionBindingEvent(HttpSession httpSession, String attrName, Object attrVal) {
+            super(httpSession, attrName, attrVal);
+        }
+    }
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/ServletPageFlowResult.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/ServletPageFlowResult.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/ServletPageFlowResult.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/httpservlet/internal/ServletPageFlowResult.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,302 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.httpservlet.internal;
+
+import org.apache.commons.chain.web.servlet.ServletWebContext;
+import org.apache.ti.pageflow.PageFlowException;
+import org.apache.ti.pageflow.xwork.PageFlowActionContext;
+import org.apache.ti.util.logging.Logger;
+
+import javax.servlet.FilterChain;
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Enumeration;
+
+public class ServletPageFlowResult /*extends PageFlowResult*/ {
+
+    private static final Logger _log = Logger.getInstance(ServletPageFlowResult.class);
+    
+    /* TODO: re-add this
+    protected boolean changeScheme( String webappRelativeURI, String scheme, int port, 
+    FlowControllerHandlerContext context )
+    throws URISyntaxException, IOException, ServletException
+    {
+    if ( port == -1 )
+    {
+    if ( _log.isWarnEnabled() )
+    {
+    _log.warn( "Could not change the scheme to " + scheme + " because the relevant port was not provided "
+    + "by the ContainerAdapter." );
+    return false;
+    }
+    }
+    
+    //
+    // First put all request attributes into the session, so they can be added to the
+    // redirected request.
+    //
+    Map attrs = new HashMap();
+    String queryString = null;
+    ServletContext servletContext = getServletContext();
+    HttpServletRequest request = ( ( RequestContext ) context ).getHttpRequest();
+    
+    for ( Enumeration e = request.getAttributeNames(); e.hasMoreElements(); )
+    {
+    String name = ( String ) e.nextElement();
+    attrs.put( name, request.getAttribute( name ) );
+    }
+    
+    if ( ! attrs.isEmpty() )
+    {
+    String hash = Integer.toString( request.hashCode() );
+    String key = makeRedirectedRequestAttrsKey( webappRelativeURI, hash );
+    request.getSession().setAttribute( key, attrs );
+    queryString = URLRewriterService.getNamePrefix( servletContext, request, REDIRECT_REQUEST_ATTRS_PARAM )
+    + REDIRECT_REQUEST_ATTRS_PARAM + '=' + hash;
+    }
+    
+    
+    //
+    // Now do the redirect.
+    //
+    URI redirectURI = new URI( scheme, null, request.getServerName(), port,
+    request.getContextPath() + webappRelativeURI,
+    queryString, null );
+    
+    ForwardRedirectHandler fwdRedirectHandler = _handlers.getForwardRedirectHandler();
+    fwdRedirectHandler.redirect( context, redirectURI.toString() );
+    
+    if ( _log.isDebugEnabled() )
+    {
+    _log.debug( "Redirected to " + redirectURI );
+    }
+    
+    return true;
+    }
+    */
+    
+    protected void doForward(String path)
+            throws PageFlowException {
+        boolean securityRedirected = false;
+        
+        /* TODO: re-add
+        //
+        // As in the TilesRequestProcessor.doForward(), if the response has already been commited,
+        // do an include instead.
+        //
+        if ( response.isCommitted() )
+        {
+            doInclude( path, request, response );
+            return;
+        }
+        
+        PageFlowActionContext actionContext = PageFlowActionContext.getContext();        
+        FlowController fc = actionContext.getFlowController();
+        FlowControllerHandlerContext context = new FlowControllerHandlerContext( fc );
+        
+        PageflowConfig pageflowConfig = ConfigUtil.getConfig().getPageflowConfig();
+        boolean secureForwards = pageflowConfig != null && pageflowConfig.getEnsureSecureForwards();
+        
+        if ( secureForwards )
+        {
+            SecurityProtocol sp = PageFlowUtils.getSecurityProtocol( path);
+            
+            if ( ! sp.equals( SecurityProtocol.UNSPECIFIED ) )
+            {
+                try
+                {
+                    if ( request.isSecure() )
+                    {
+                        if ( sp.equals( SecurityProtocol.UNSECURE ) )
+                        {
+                            int listenPort = _containerAdapter.getListenPort( request );
+                            securityRedirected = changeScheme( path, SCHEME_UNSECURE, listenPort, context );
+                        }
+                    }
+                    else
+                    {
+                        if ( sp.equals( SecurityProtocol.SECURE ) )
+                        {
+                            int secureListenPort = _containerAdapter.getSecureListenPort( request );
+                            securityRedirected = changeScheme( path, SCHEME_SECURE, secureListenPort, context );
+                        }
+                    }
+                }
+                catch ( URISyntaxException e )
+                {
+                    _log.error( "Bad forward URI " + path, e );
+                }
+            }
+        }
+        
+        if ( ! securityRedirected )
+        {
+            super.doForward( path );
+        }
+        */
+    }
+
+    /**
+     * An opportunity to process a page forward in a different way than performing a server forward.  The default
+     * implementation looks for a file on classpath called
+     * META-INF/pageflow-page-servlets/<i>path-to-page</i>.properties (e.g.,
+     * "/META-INF/pageflow-page-servlets/foo/bar/hello.jsp.properties").  This file contains mappings from
+     * <i>platform-name</i> (the value returned by {@link org.apache.ti.pageflow.ContainerAdapter#getPlatformName}) to the name of a Servlet
+     * class that will process the page request.  If the current platform name is not found, the value "default" is
+     * tried.  An example file might look like this:
+     * <pre>
+     *     tomcat=org.apache.jsp.foo.bar.hello_jsp
+     *     default=my.servlets.foo.bar.hello
+     * </pre>
+     *
+     * @param pagePath the webapp-relative path to the page, e.g., "/foo/bar/hello.jsp"
+     * @return <code>true</code> if the method handled the request, in which case it should not be forwarded.
+     */
+    protected boolean processPageForward(String pagePath)
+            throws PageFlowException {
+        /* TODO: re-add this
+        Class pageServletClass = ( Class ) _pageServletClasses.get( pagePath );
+        
+        if ( pageServletClass == null )
+        {
+            pageServletClass = Void.class;
+            ClassLoader cl = DiscoveryUtils.getClassLoader();
+            String path = "META-INF/pageflow-page-servlets" + pagePath + ".properties";
+            InputStream in = cl.getResourceAsStream( path );
+            
+            if ( in != null )
+            {
+                String className = null;
+                
+                try
+                {
+                    Properties props = new Properties();
+                    props.load( in );
+                    className = props.getProperty( _containerAdapter.getPlatformName() );
+                    if ( className == null ) className = props.getProperty( "default" );
+                    
+                    if ( className != null )
+                    {
+                        pageServletClass = cl.loadClass( className );
+                        
+                        if ( Servlet.class.isAssignableFrom( pageServletClass ) )
+                        {
+                            if ( _log.isInfoEnabled() )
+                            {
+                                _log.info( "Loaded page Servlet class " + className + " for path " + pagePath );
+                            }
+                        }
+                        else
+                        {
+                            pageServletClass = Void.class;
+                            _log.error( "Page Servlet class " + className + " for path " + pagePath
+                                    + " does not extend " + Servlet.class.getName() );
+                        }
+                    }
+                }
+                catch ( IOException e )
+                {
+                    _log.error( "Error while reading " + path, e );
+                }
+                catch ( ClassNotFoundException e )
+                {
+                    _log.error( "Error while loading page Servlet class " + className, e );
+                }
+            }
+            
+            _pageServletClasses.put( pagePath, pageServletClass );
+        }
+        
+        if ( pageServletClass.equals( Void.class ) )
+        {
+            return false;
+        }
+        
+        try
+        {
+            Servlet pageServlet = ( Servlet ) pageServletClass.newInstance();
+            pageServlet.init( new PageServletConfig( pagePath ) );
+            _pageServletFilter.doFilter( request, response, new PageServletFilterChain( pageServlet ) );
+            return true;
+        }
+        catch ( InstantiationException e )
+        {
+            _log.error( "Error while instantiating page Servlet of type " + pageServletClass.getName(), e );
+        }
+        catch ( IllegalAccessException e )
+        {
+            _log.error( "Error while instantiating page Servlet of type " + pageServletClass.getName(), e );
+        }
+        
+        */
+        return false;
+    }
+
+    /**
+     * Used by {@link org.apache.ti.pageflow.PageFlowRequestProcessor#processPageForward} to run a page Servlet.
+     */
+    private static class PageServletFilterChain implements FilterChain {
+
+        private Servlet _pageServlet;
+
+        public PageServletFilterChain(Servlet pageServlet) {
+            _pageServlet = pageServlet;
+        }
+
+        public void doFilter(ServletRequest request, ServletResponse response)
+                throws IOException, ServletException {
+            _pageServlet.service(request, response);
+        }
+    }
+
+    /**
+     * Used by {@link org.apache.ti.pageflow.PageFlowRequestProcessor#processPageForward} to initialize a page Servlet.
+     */
+    private class PageServletConfig implements ServletConfig {
+
+        private String _pagePath;
+
+        public PageServletConfig(String pagePath) {
+            _pagePath = pagePath;
+        }
+
+        public String getServletName() {
+            return _pagePath;
+        }
+
+        public ServletContext getServletContext() {
+            ServletWebContext webContext = (ServletWebContext) PageFlowActionContext.get().getWebContext();
+            return webContext.getContext();
+        }
+
+        public String getInitParameter(String s) {
+            return null;
+        }
+
+        public Enumeration getInitParameterNames() {
+            return Collections.enumeration(Collections.EMPTY_LIST);
+        }
+    }
+
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/AbstractInterceptor.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/AbstractInterceptor.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/AbstractInterceptor.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/AbstractInterceptor.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor;
+
+import java.io.Serializable;
+
+public abstract class AbstractInterceptor
+        implements Interceptor, Serializable {
+
+    private InterceptorConfig _config;
+
+    /**
+     * Called when this interceptor is being initialized.
+     *
+     * @param config the configuration object associated with this interceptor.
+     */
+    public void init(InterceptorConfig config) {
+        _config = config;
+    }
+
+    /**
+     * Get the configuration object associated with this interceptor.
+     *
+     * @return the configuration object associated with this interceptor.
+     */
+    public InterceptorConfig getConfig() {
+        return _config;
+    }
+
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/Interceptor.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/Interceptor.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/Interceptor.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/Interceptor.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor;
+
+/**
+ * Base class for all interceptors.
+ */
+public interface Interceptor {
+
+    public void init(InterceptorConfig config);
+
+    public void preInvoke(InterceptorContext context, InterceptorChain chain)
+            throws InterceptorException;
+
+    public void postInvoke(InterceptorContext context, InterceptorChain chain)
+            throws InterceptorException;
+}
+

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/InterceptorChain.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/InterceptorChain.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/InterceptorChain.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/InterceptorChain.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Base class for all chains of {@link Interceptor}s.
+ */
+public abstract class InterceptorChain {
+
+    private LinkedList/*< Interceptor >*/ _chain = new LinkedList/*< Interceptor >*/();
+    private InterceptorContext _context;
+
+    protected InterceptorChain(InterceptorContext context, List/*< Interceptor >*/ interceptors) {
+        _context = context;
+        _chain.addAll(interceptors);
+    }
+
+    public Object continueChain()
+            throws InterceptorException {
+        if (!_chain.isEmpty()) {
+            return invoke((Interceptor) _chain.removeFirst());
+        } else {
+            return null;
+        }
+    }
+
+    protected abstract Object invoke(Interceptor interceptor) throws InterceptorException;
+
+    public InterceptorContext getContext() {
+        return _context;
+    }
+
+    public boolean isEmpty() {
+        return _chain.isEmpty();
+    }
+
+    protected Interceptor removeFirst() {
+        return (Interceptor) _chain.removeFirst();
+    }
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/InterceptorConfig.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/InterceptorConfig.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/InterceptorConfig.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/InterceptorConfig.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Class to hold configuration parameters for registered {@link Interceptor}s.
+ */
+public class InterceptorConfig
+        implements Serializable {
+
+    private String _interceptorClass;
+    private Map/*< String, String >*/ _customProperties = new HashMap/*< String, String >*/();
+
+    protected InterceptorConfig() {
+    }
+
+    protected InterceptorConfig(String interceptorClass) {
+        _interceptorClass = interceptorClass;
+    }
+
+    public String getInterceptorClass() {
+        return _interceptorClass;
+    }
+
+    public void setInterceptorClass(String interceptorClass) {
+        _interceptorClass = interceptorClass;
+    }
+
+    public Map/*< String, String >*/ getCustomProperties() {
+        return _customProperties;
+    }
+
+    void addCustomProperty(String name, String value) {
+        _customProperties.put(name, value);
+    }
+
+    public String getCustomProperty(String name) {
+        return (String) _customProperties.get(name);
+    }
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/InterceptorContext.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/InterceptorContext.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/InterceptorContext.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/InterceptorContext.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor;
+
+import org.apache.ti.schema.config.CustomProperty;
+import org.apache.ti.util.internal.DiscoveryUtils;
+import org.apache.ti.util.logging.Logger;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Base context for callbacks on {@link Interceptor}s.
+ */
+public class InterceptorContext
+        implements Serializable {
+
+    private static final Logger _log = Logger.getInstance(InterceptorContext.class);
+
+    private Object _resultOverride;
+    private Interceptor _overridingInterceptor;
+
+    public void setResultOverride(Object newResult, Interceptor interceptor) {
+        _resultOverride = newResult;
+        _overridingInterceptor = interceptor;
+    }
+
+    public boolean hasResultOverride() {
+        return _overridingInterceptor != null;
+    }
+
+    public Object getResultOverride() {
+        return _resultOverride;
+    }
+
+    public Interceptor getOverridingInterceptor() {
+        return _overridingInterceptor;
+    }
+
+    protected static void addInterceptors(org.apache.ti.schema.config.Interceptor[] configBeans,
+                                          List/*< Interceptor >*/ interceptorsList, Class baseClassOrInterface) {
+        if (configBeans != null) {
+            for (int i = 0; i < configBeans.length; i++) {
+                org.apache.ti.schema.config.Interceptor configBean = configBeans[i];
+                String className = configBean.getInterceptorClass();
+                InterceptorConfig config = new InterceptorConfig(className);
+                CustomProperty[] customProps = configBean.getCustomPropertyArray();
+
+                if (customProps != null) {
+                    for (int j = 0; j < customProps.length; j++) {
+                        CustomProperty customProp = customProps[j];
+                        config.addCustomProperty(customProp.getName(), customProp.getValue());
+                    }
+                }
+
+                addInterceptor(config, baseClassOrInterface, interceptorsList);
+            }
+        }
+    }
+
+    /**
+     * Instantiates an interceptor, based on the class name in the given InterceptorConfig, and adds it to the
+     * given collection of interceptors.
+     *
+     * @param config               the InterceptorConfig used to determine the interceptor class.
+     * @param baseClassOrInterface the required base class or interface.  May be <code>null</code>.
+     * @param interceptors         the List of interceptors to which to add.
+     * @return an initialized Interceptor, or <code>null</code> if an error occurred.
+     */
+    protected static Interceptor addInterceptor(InterceptorConfig config, Class baseClassOrInterface,
+                                                List/*< Interceptor >*/ interceptors) {
+        Interceptor interceptor = createInterceptor(config, baseClassOrInterface);
+        if (interceptor != null) interceptors.add(interceptor);
+        return interceptor;
+    }
+
+    /**
+     * Instantiates an interceptor, based on the class name in the given InterceptorConfig.
+     *
+     * @param config               the InterceptorConfig used to determine the interceptor class.
+     * @param baseClassOrInterface the required base class or interface.  May be <code>null</code>.
+     * @return an initialized Interceptor, or <code>null</code> if an error occurred.
+     */
+    protected static Interceptor createInterceptor(InterceptorConfig config, Class baseClassOrInterface) {
+        assert Interceptor.class.isAssignableFrom(baseClassOrInterface)
+                : baseClassOrInterface.getName() + " cannot be assigned to " + Interceptor.class.getName();
+
+        ClassLoader cl = DiscoveryUtils.getClassLoader();
+        String className = config.getInterceptorClass();
+
+        try {
+            Class interceptorClass = cl.loadClass(className);
+
+            if (!baseClassOrInterface.isAssignableFrom(interceptorClass)) {
+                _log.error("Interceptor " + interceptorClass.getName() + " does not implement or extend "
+                        + baseClassOrInterface.getName());
+                return null;
+            }
+
+            Interceptor interceptor = (Interceptor) interceptorClass.newInstance();
+            interceptor.init(config);
+            return interceptor;
+        } catch (ClassNotFoundException e) {
+            _log.error("Could not find interceptor class " + className, e);
+        } catch (InstantiationException e) {
+            _log.error("Could not instantiate interceptor class " + className, e);
+        } catch (IllegalAccessException e) {
+            _log.error("Could not instantiate interceptor class " + className, e);
+        }
+
+        return null;
+    }
+
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/InterceptorException.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/InterceptorException.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/InterceptorException.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/InterceptorException.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor;
+
+/**
+ * Exception thrown during callbacks on {@link Interceptor}s.
+ */
+public class InterceptorException
+        extends Exception {
+
+    public InterceptorException(String message) {
+        super(message);
+    }
+
+    public InterceptorException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public InterceptorException(Throwable cause) {
+        super(cause);
+    }
+}

Added: struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/Interceptors.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/Interceptors.java?rev=240168&view=auto
==============================================================================
--- struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/Interceptors.java (added)
+++ struts/sandbox/trunk/ti/core/src/java/org/apache/ti/pageflow/interceptor/Interceptors.java Thu Aug 25 22:46:03 2005
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.ti.pageflow.interceptor;
+
+
+import java.util.List;
+
+public class Interceptors {
+
+    public static void doPreIntercept(InterceptorContext context, List/*< Interceptor >*/ interceptors)
+            throws InterceptorException {
+        if (interceptors != null) {
+            PreInvokeInterceptorChain chain = new PreInvokeInterceptorChain(context, interceptors);
+            chain.continueChain();
+        }
+    }
+
+    public static void doPostIntercept(InterceptorContext context, List/*< Interceptor >*/ interceptors)
+            throws InterceptorException {
+        if (interceptors != null) {
+            PostInvokeInterceptorChain chain = new PostInvokeInterceptorChain(context, interceptors);
+            chain.continueChain();
+        }
+    }
+
+    private static final class PreInvokeInterceptorChain
+            extends InterceptorChain {
+
+        public PreInvokeInterceptorChain(InterceptorContext context, List/*< Interceptor >*/ interceptors) {
+            super(context, interceptors);
+        }
+
+        protected Object invoke(Interceptor interceptor)
+                throws InterceptorException {
+            interceptor.preInvoke(getContext(), this);
+            return null;
+        }
+    }
+
+    private static final class PostInvokeInterceptorChain
+            extends InterceptorChain {
+
+        public PostInvokeInterceptorChain(InterceptorContext context, List/*< Interceptor >*/ interceptors) {
+            super(context, interceptors);
+        }
+
+        protected Object invoke(Interceptor interceptor)
+                throws InterceptorException {
+            interceptor.postInvoke(getContext(), this);
+            return null;
+        }
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org