Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: joist/java/org/joist/security UnsecureServlet.java

Project highlights: Architectural Overview

joist
Discussion topic

Hide all messages in topic

All messages in topic

CVS update: joist/java/org/joist/security UnsecureServlet.java

Author dlr
Full name Daniel Rall
Date 2001-04-17 16:09:19 PDT
Message User: dlr
  Date: 01/04/17 16:09:19

  Modified: java/org/joist/security UnsecureServlet.java
  Log:
  Removed WMServlet subclassing dependancy. The first step in the
  migration to Velocity.
  
  Revision Changes Path
  1.125 +121 -52 joist/java/org/joist​/security/UnsecureSe​rvlet.java
  
  Index: UnsecureServlet.java
  ====================​====================​====================​=======
  RCS file: /cvs/joist/java/org/​joist/security/Unsec​ureServlet.java,v
  retrieving revision 1.124
  retrieving revision 1.125
  diff -u -r1.124 -r1.125
  --- UnsecureServlet.java 2001/04/17 20:49:54 1.124
  +++ UnsecureServlet.java 2001/04/17 23:09:18 1.125
  @@ -59,14 +59,16 @@
   import org.webmacro.util.*;
   import org.webmacro.servlet.*;
   import org.webmacro.engine.*;
  -import org.webmacro.broker.*;
   import org.webmacro.resource.*;
   
   import com.workingdogs.vill​age.DataSetException​;
   
   import org.apache.turbine.util.Log;
  +import org.apache.turbine.u​til.RunData;
  +import org.apache.turbine.u​til.RunDataFactory;
   import org.apache.turbine.u​til.TurbineConfig;
   import org.apache.turbine.s​ervices.db.TurbineDB​;
  +import org.apache.turbine.s​ervices.webmacro.Tur​bineWebMacro;
   import org.apache.turbine.u​til.db.pool.DBConnec​tion;
   
   import org.joist.session.*;
  @@ -78,15 +80,15 @@
    * Adds connection management, default template loading, and properties file
    * loading to WebMacro servlets.
    *
  - * @author David C. Pellegrini <A HREF="mailto:davidp@​dataweb-systems.com"​>davidp@dataweb-s​ystems.com</A>​
  + * @author <a href="mailto:davidp@​dataweb-systems.com"​>David C. Pellegrini</a>
    * @author <a href="mailto:dlr@col​lab.net">Daniel Rall</a>
  - * @version $Revision: 1.124 $
  + * @version $Revision: 1.125 $
    *
    * Copyright (c) 1999 dataweb systems, inc.
    * Copyright (c) 1999-2001 CollabNet, Inc.
    */
   
  -public class UnsecureServlet extends WMServlet
  +public class UnsecureServlet extends HttpServlet
   {
       /**
        * Used to when internal redirects require making an old context
  @@ -198,25 +200,19 @@
   
       /**
        * Does connection management and other tasks common to all servlets.
  - * This implements the <code>handle()​</code> method specified in
  - * <code>WMServle​t</code>.
  - * All subclasses should invoke this early in their own <code>handle()
  - * <\code> methods that over-ride this.
        * This function performs actions such as recording the page hit,
        * servlet specific processing, and populating the template with
        * actual values.
        *
        * @param context The WebContext partially populated by WMServlet.
  - * @return The Template for formatting the WebContext data.
  + * @return The name of the template for formatting the {@link
  + * org.webmacro.servlet​.WebContext} data.
        *
        * @exception HandlerException Any runtime error.
  - *
  - * @see org.webmacro.servlet​.WMServlet#handle(or​g.webmacro.servlet.W​ebContext)
        */
  - public Template handle (WebContext context)
  + public String handle (WebContext context, HttpServletResponse res)
           throws HandlerException
       {
  - ResourceBroker broker = (ResourceBroker) getBroker();
           String templateName;
           Template template = null;
   
  @@ -275,20 +271,10 @@
                       redirectToError(context, e.getMessage());
                   }
   
  - // Retrieve the template
  - try
  - {
  - template = (Template)broker.get​Value(TemplateProvid​er.TYPE,
  - templateName);
  - }
  - catch (Exception e)
  - {
  - throw new HandlerException("Could not locate template: " +
  - templateName);
  - }
  -
                   // Process the template.
  - execute(template, context);
  + TurbineWebMacro.hand​leRequest(context, templateName,
  + res.getOutputStream());
  + //, res.getCharacterEncoding());
               }
               catch (RedirectURLException e)
               {
  @@ -374,7 +360,7 @@
                       Log.debug("Redirect class name: " +
                                 redirect.getClass().getName());
                   }
  - template = redirect.handle(context);
  + templateName = redirect.handle(context, res);
               }
           }
           catch (Exception e)
  @@ -436,6 +422,89 @@
       }
   
       /**
  + * This is the old-style init method, it just calls init(), after
  + * handing the ServletConfig object to the superclass
  + *
  + * @exception ServletException Servlet failed to initialize.
  + */
  + public final synchronized void init(ServletConfig sc)
  + throws ServletException
  + {
  + super.init(sc);
  + init();
  + }
  +
  + /**
  + * This method is called by the servlet runner--do not call it.
  + *
  + * @exception ServletException Servlet failed to initialize.
  + */
  + public final synchronized void init()
  + throws ServletException
  + {
  + start();
  + }
  +
  + /**
  + * Process an incoming GET request: Builds a WebContext up and then
  + * passes it to the handle() method. You can overide this if you want,
  + * though for most purposes you are expected to overide handle()
  + * instead.
  + * <p>
  + * @param req The request we got.
  + * @param res The response we are generating.
  + *
  + * @exception ServletException We can't get our configuration.
  + * @exception IOException We can't read/write to the streams we got.
  + */
  + protected void doGet(HttpServletRequest req, HttpServletResponse res)
  + throws ServletException, IOException
  + {
  + doRequest(req, res);
  + }
  +
  + /**
  + * Behaves exactly like doGet() except that it reads data from POST
  + * before doing exactly the same thing. This means that you can use
  + * GET and POST interchangeably with WebMacro. You can overide this if
  + * you want, though for most purposes you are expected to overide
  + * handle() instead.
  + * <p>
  + * @param req The request we got.
  + * @param res The response we are generating.
  + *
  + * @exception ServletException We can't get our configuration.
  + * @exception IOException We can't read/write to the streams we got.
  + */
  + protected void doPost(HttpServletRequest req, HttpServletResponse res)
  + throws ServletException, IOException
  + {
  + doRequest(req, res);
  + }
  +
  + private void doRequest(HttpServletRequest req, HttpServletResponse res)
  + {
  + try
  + {
  + RunData data = RunDataFactory.getRunData(req, res,
  + getServletConfig());
  + //Log.debug("RunDataFactory returned " + data);
  + WebContext context = TurbineWebMacro.getC​ontext(data);
  + String templateName = handle(context, res);
  + if (templateName != null)
  + {
  + TurbineWebMacro.hand​leRequest(context, templateName,
  + res.getOutputStream());
  + }
  + }
  + catch (Exception e)
  + {
  + Log.warn("Your handler was unable to successfully process the " +
  + "request", e);
  + }
  + }
  +
  + /**
        * Does whatever processing is necessary to fill the WebContext instance
        * with objects to be used to fill in the template. The value in the
        * WebContext keyed by the String "action" will always be filled by this
  @@ -1144,9 +1213,9 @@
        * Returns the data layer manager object for this session.
        *
        * @param context The WebContext partially populated by WMServlet.
  - * @return The data layer manager for this session.
  + * @return The data layer manager for this session.
        */
  - protected final DataManager getDataManager (WebContext context)
  + protected final DataManager getDataManager (WebContext context)
       {
           return getSessionManager(co​ntext).getDataManage​r();
       }
  @@ -1213,36 +1282,36 @@
       public void start()
           throws ServletException
       {
  - // Set up myProperties to supply values with the precedence:
  - // 1. servlet properties
  - // 2. application properties (future)
  - // 3. site properties
  - // 4. zone properties
  - // 5. System properties
  + // Set up myProperties to supply values with the precedence:
  + // 1. servlet properties
  + // 2. application properties (future)
  + // 3. site properties
  + // 4. zone properties
  + // 5. System properties
   
  - // Start by reading the initialization parameters into a Properties
  - // object. Make the System properties supply defaults.
  + // Start by reading the initialization parameters into a Properties
  + // object. Make the System properties supply defaults.
   
  - Properties initParameters = new Properties(System.ge​tProperties());
  - ServletConfig config = getServletConfig();
  + Properties initParameters = new Properties(System.ge​tProperties());
  + ServletConfig config = getServletConfig();
           if (config == null)
           {
               throw new ServletException("ServletConfig is null");
           }
  -
  - Enumeration parameterNames = config.getInitParameterNames();
  - String paramName;
  - while (parameterNames.hasM​oreElements())
  - {
  - paramName = (String)parameterNam​es.nextElement();
  - initParameters.put(paramName, config.getInitParame​ter(paramName));
  - }
   
  - // Get the name of the site properties file from the zone properties,
  - // then open the file and load the properties. Make the zone
  - // properties supply defaults.
  - Properties siteProperties = new Properties(initParameters);
  - String sitePropertiesFile =
  + Enumeration parameterNames = config.getInitParameterNames();
  + String paramName;
  + while (parameterNames.hasM​oreElements())
  + {
  + paramName = (String)parameterNam​es.nextElement();
  + initParameters.put(paramName, config.getInitParame​ter(paramName));
  + }
  +
  + // Get the name of the site properties file from the zone properties,
  + // then open the file and load the properties. Make the zone
  + // properties supply defaults.
  + Properties siteProperties = new Properties(initParameters);
  + String sitePropertiesFile =
               initParameters.getPr​operty("siteProperti​es");
   
           if (sitePropertiesFile != null)
Messages per page: