struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hus...@apache.org
Subject cvs commit: jakarta-struts/contrib/scaffold/src/java/org/apache/struts/scaffold MenuRelayAction.java SnoopAction.java
Date Thu, 02 Jan 2003 19:42:45 GMT
husted      2003/01/02 11:42:45

  Added:       contrib/scaffold/src/java/org/apache/struts/scaffold
                        MenuRelayAction.java SnoopAction.java
  Log:
  + Add MenuRelayAction, for returning to submenu after workflow.
  + Add SnoopAction.
  
  Revision  Changes    Path
  1.1                  jakarta-struts/contrib/scaffold/src/java/org/apache/struts/scaffold/MenuRelayAction.java
  
  Index: MenuRelayAction.java
  ===================================================================
  package org.apache.struts.scaffold;
  
  import org.apache.commons.scaffold.lang.Tokens;
  import org.apache.commons.scaffold.text.ConvertUtils;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionForward;
  import org.apache.struts.action.ActionMapping;
  import org.apache.struts.scaffold.BaseAction;
  import org.apache.struts.scaffold.BaseForm;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  
  /**
   * Standard Action to forward control to another mapping
   * given as a runtime parameter (?dispatch=),
   * after running any model classes.
   *
   * @author Ted Husted
   * @version $Revision: 1.1 $ $Date: 2003/01/02 19:42:45 $
   */
  public final class MenuRelayAction extends BaseAction {
  
  
      /**
       * Looks for a runtime parameter named "dispatch",
       * and uses its value to search for an ActionForward.
       * If a "dispatch" parameter is not available,
       * and the form is a BaseForm istance, then the
       * dispatch property is checked.
       * If dispatch is blank, the mapping parameter is
       * checked.
       * Finally, if all of these are blank,
       * MenuRelayAction looks for a "menu" forward.
       * <p>
       * This is useful for returning to a submenu when
       * a MenuForm is kept in the session for each user.
       *
       * @param mapping The ActionMapping used to select this instance
       * @param form The optional ActionForm bean for this request (if any)
       * @param request The HTTP request we are processing
       * @param response The response we are creating
       */
     protected ActionForward findSuccess(
              ActionMapping mapping,
              ActionForm form,
              HttpServletRequest request,
              HttpServletResponse response) {
  
          String forward = request.getParameter(Tokens.DISPATCH);
          if ((ConvertUtils.blank(forward)) && (form instanceof BaseForm)) {
              BaseForm baseForm = (BaseForm) form;
              forward = baseForm.getDispatch();
          }
          if (ConvertUtils.blank(forward)) forward = mapping.getParameter();
          if (ConvertUtils.blank(forward)) forward = Tokens.MENU;
          return mapping.findForward(forward);
      }
  
  } // end RelayHelperAction
  
  
  /*
   * $Header: /home/cvs/jakarta-struts/contrib/scaffold/src/java/org/apache/struts/scaffold/MenuRelayAction.java,v
1.1 2003/01/02 19:42:45 husted Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/02 19:42:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Scaffold", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  
  
  
  
  
  1.1                  jakarta-struts/contrib/scaffold/src/java/org/apache/struts/scaffold/SnoopAction.java
  
  Index: SnoopAction.java
  ===================================================================
  /**
   * Derived from the Jetty SnoopServlet
   * <http://www.thecortex.net/clover/eg/jetty/report/default-pkg/SnoopServlet.html>
   * and distributed under its open source license
   * <http://jetty.mortbay.org/jetty/LICENSE.html>.
   * The only modifications were to change the method
   * signatures to make the servlet an Action.
   */
  
  package org.apache.struts.scaffold;
  
  import org.apache.struts.action.*;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.Enumeration;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   *
   * @author James Duncan Davidson <duncan@eng.sun.com>
   * @author Jason Hunter <jch@eng.sun.com>
   * @author Ted Husted <husted@apache.org>
   */
  
  public final class SnoopAction extends Action {
  
      public ActionForward perform(ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response)
              throws IOException, ServletException {
          ActionServlet servlet = getServlet();
          PrintWriter out = response.getWriter();
          response.setContentType("text/plain");
          out.println("Snoop Servlet");
          out.println();
          out.println("Servlet init parameters:");
          Enumeration e = servlet.getInitParameterNames();
          while (e.hasMoreElements()) {
              String key = (String) e.nextElement();
              String value = servlet.getInitParameter(key);
              out.println("   " + key + " = " + value);
          }
          out.println();
  
          out.println("Context init parameters:");
          ServletContext context = servlet.getServletContext();
          Enumeration enum = context.getInitParameterNames();
          while (enum.hasMoreElements()) {
              String key = (String) enum.nextElement();
              Object value = context.getInitParameter(key);
              out.println("   " + key + " = " + value);
          }
          out.println();
  
          out.println("Context attributes:");
          enum = context.getAttributeNames();
          while (enum.hasMoreElements()) {
              String key = (String) enum.nextElement();
              Object value = context.getAttribute(key);
              out.println("   " + key + " = " + value);
          }
          out.println();
  
          out.println("Request attributes:");
          e = request.getAttributeNames();
          while (e.hasMoreElements()) {
              String key = (String) e.nextElement();
              Object value = request.getAttribute(key);
              out.println("   " + key + " = " + value);
          }
          out.println();
  
          out.println("Servlet Name: " + servlet.getServletName());
          out.println("Protocol: " + request.getProtocol());
          out.println("Scheme: " + request.getScheme());
          out.println("Server Name: " + request.getServerName());
          out.println("Server Port: " + request.getServerPort());
          out.println("Server Info: " + context.getServerInfo());
          out.println("Remote Addr: " + request.getRemoteAddr());
          out.println("Remote Host: " + request.getRemoteHost());
          out.println("Character Encoding: " + request.getCharacterEncoding());
          out.println("Content Length: " + request.getContentLength());
          out.println("Content Type: " + request.getContentType());
          out.println("Locale: " + request.getLocale());
          out.println("Default Response Buffer: " + response.getBufferSize());
          out.println();
  
          out.println("Parameter names in this request:");
          e = request.getParameterNames();
          while (e.hasMoreElements()) {
              String key = (String) e.nextElement();
              String[] values = request.getParameterValues(key);
              out.print("   " + key + " = ");
              for (int i = 0; i < values.length; i++) {
                  out.print(values[i] + " ");
              }
              out.println();
          }
          out.println();
  
          out.println("Headers in this request:");
          e = request.getHeaderNames();
          while (e.hasMoreElements()) {
              String key = (String) e.nextElement();
              String value = request.getHeader(key);
              out.println("   " + key + ": " + value);
          }
          out.println();
  
          out.println("Cookies in this request:");
          Cookie[] cookies = request.getCookies();
          if (cookies != null) {
              for (int i = 0; i < cookies.length; i++) {
                  Cookie cookie = cookies[i];
                  out.println("   " + cookie.getName() + " = "
                          + cookie.getValue());
              }
          }
          out.println();
  
          out.println("Request Is Secure: " + request.isSecure());
          out.println("Auth Type: " + request.getAuthType());
          out.println("HTTP Method: " + request.getMethod());
          out.println("Remote User: " + request.getRemoteUser());
          out.println("Request URI: " + request.getRequestURI());
          out.println("Context Path: " + request.getContextPath());
          out.println("Servlet Path: " + request.getServletPath());
          out.println("Path Info: " + request.getPathInfo());
          out.println("Path Trans: " + request.getPathTranslated());
          out.println("Query String: " + request.getQueryString());
          out.println();
  
          HttpSession session = request.getSession();
          out.println("Requested Session Id: " +
                  request.getRequestedSessionId());
          out.println("Current Session Id: " + session.getId());
          out.println("Session Created Time: " + session.getCreationTime());
          out.println("Session Last Accessed Time: " +
                  session.getLastAccessedTime());
          out.println("Session Max Inactive Interval Seconds: " +
                  session.getMaxInactiveInterval());
          out.println();
  
          out.println("Session values: ");
          Enumeration names = session.getAttributeNames();
          while (names.hasMoreElements()) {
              String name = (String) names.nextElement();
              out.println("   " + name + " = " + session.getAttribute(name));
          }
          out.println("###");
  
      return null;
  
      }
  }
  
  
  
  

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


Mime
View raw message