head	1.22;
access;
symbols
	TIGRIS_1_1_0RC2:1.6.2.1.4.2
	TIGRIS_1_1_0RC1:1.6.2.1.4.2
	TIGRIS_1_1:1.6.2.1.4.2.0.2
	TIGRIS_1_0_8:1.6.2.1.4.2
	TIGRIS_1_0_8RC3:1.6.2.1.4.2
	TIGRIS_1_0_8RC2:1.6.2.1.4.2
	TIGRIS_1_0_8RC1:1.6.2.1.4.2
	TIGRIS_1_0_7:1.6.2.1.4.2
	TIGRIS_1_0_7RC3:1.6.2.1.4.2
	TIGRIS_1_0_7RC2:1.6.2.1.4.2
	TIGRIS_1_0_7RC1:1.6.2.1.4.2
	TIGRIS_1_0_6:1.6.2.1.4.1
	TIGRIS_1_0_6RC5:1.6.2.1.4.1
	TIGRIS_1_0_6RC4:1.6.2.1.4.1
	TIGRIS_1_0_6RC3:1.6.2.1.4.1
	TIGRIS_1_0_6RC2:1.6.2.1.4.1
	TIGRIS_1_0_6RC1:1.6.2.1.4.1
	TIGRIS_1_0_5:1.6.2.1.4.1
	TIGRIS_1_0_5RC6:1.6.2.1.4.1
	TIGRIS_1_0_5RC5:1.6.2.1.4.1
	TIGRIS_1_0_5RC4:1.6.2.1.4.1
	TIGRIS_1_0_5RC3:1.6.2.1.4.1
	TIGRIS_1_0_5RC2:1.6.2.1.4.1
	TIGRIS_1_0_5RC1:1.6.2.1.4.1
	TIGRIS_1_0_4:1.6.2.1.4.1
	TIGRIS_1_0_3:1.6.2.1
	TIGRIS_1_0_2:1.6.2.1
	TIGRIS_1_0_1:1.6.2.1
	TIGRIS_1_0:1.6.2.1.0.4
	TIGRIS_1_0_0:1.6.2.1
	TIGRIS_1_0_0_RC1:1.6.0.2
	TIGRIS_0_9_2_4:1.1
	TIGRIS_0_9_2_3:1.1
	HELM_PEER_PORT_BRANCH:1.3.0.2
	TURBINE_PEER:1.3
	TIGRIS_0_9_2_1:1.3
	TIGRIS_0_9_2:1.1.0.6
	TIGRIS_0_9_0:1.1.0.4
	TIGRIS_0_8_4:1.1.0.2;
locks; strict;
comment	@# @;


1.22
date	2001.08.28.17.45.18;	author leonardr;	state Exp;
branches;
next	1.21;

1.21
date	2001.08.28.17.13.33;	author leonardr;	state Exp;
branches;
next	1.20;

1.20
date	2001.08.11.09.08.07;	author dlr;	state Exp;
branches;
next	1.19;

1.19
date	2001.08.08.22.40.46;	author jrobbins;	state Exp;
branches;
next	1.18;

1.18
date	2001.07.19.19.28.53;	author dlr;	state Exp;
branches;
next	1.17;

1.17
date	2001.07.18.10.05.14;	author dlr;	state Exp;
branches;
next	1.16;

1.16
date	2001.06.21.19.49.59;	author dlr;	state Exp;
branches;
next	1.15;

1.15
date	2001.05.23.01.50.19;	author dlr;	state Exp;
branches;
next	1.14;

1.14
date	2001.05.04.07.29.55;	author stack;	state Exp;
branches;
next	1.13;

1.13
date	2001.04.30.23.34.33;	author stack;	state Exp;
branches;
next	1.12;

1.12
date	2001.04.25.18.12.54;	author leonardr;	state Exp;
branches;
next	1.11;

1.11
date	2001.04.21.17.47.24;	author stack;	state Exp;
branches;
next	1.10;

1.10
date	2001.04.21.00.16.03;	author stack;	state Exp;
branches;
next	1.9;

1.9
date	2001.04.15.23.40.00;	author stack;	state Exp;
branches;
next	1.8;

1.8
date	2001.04.04.20.53.08;	author dlr;	state Exp;
branches;
next	1.7;

1.7
date	2001.04.04.00.24.53;	author jrobbins;	state Exp;
branches;
next	1.6;

1.6
date	2001.03.27.07.02.31;	author jrobbins;	state Exp;
branches
	1.6.2.1;
next	1.5;

1.5
date	2001.03.23.22.05.50;	author leonardr;	state Exp;
branches;
next	1.4;

1.4
date	2001.03.05.02.36.07;	author jrobbins;	state Exp;
branches;
next	1.3;

1.3
date	2001.01.26.18.29.07;	author edk;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	2001.01.26.05.24.07;	author edk;	state dead;
branches;
next	1.1;

1.1
date	2000.11.29.18.46.13;	author jrobbins;	state Exp;
branches;
next	;

1.3.2.1
date	2001.01.28.01.02.19;	author dlr;	state dead;
branches;
next	;

1.6.2.1
date	2001.04.04.20.54.46;	author dlr;	state Exp;
branches
	1.6.2.1.4.1;
next	;

1.6.2.1.4.1
date	2001.05.01.05.45.17;	author stack;	state Exp;
branches;
next	1.6.2.1.4.2;

1.6.2.1.4.2
date	2001.06.21.19.48.08;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.22
log
@More methods migrated to ContextAPI.
@
text
@/* ================================================================
 * Copyright (c) 2000 Collab.Net.  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 Collab.Net <http://www.Collab.Net/>."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 *
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 *
 * 5. Products derived from this software may not use the "Tigris" or
 * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
 * prior written permission of Collab.Net.
 *
 * 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 COLLAB.NET 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 Collab.Net.
 */
package org.tigris.helm.publish;

import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.commons.util.exception.NestableException;

import org.apache.velocity.context.Context;

import HTTPClient.*;

import org.tigris.helm.om.*;
import org.tigris.helm.publish.NoodleResources;
import org.tigris.helm.publish.ProxyModule;
import org.tigris.helm.security.*;
import org.tigris.helm.tool.ContextAPI;
import org.tigris.helm.tool.SessionManager;
import org.tigris.helm.tool.breadcrumbs.BreadCrumbElement;
import org.apache.turbine.util.Log;

/** 
 * Wraps static html pages in instance-specific 'branding'.
 * 
 * @@author <a href="mailto:jrobbins@@collab.net">Jason Robbins</a>
 * @@version $Id: ContentHelmNoodle.java,v 1.21 2001/08/28 17:13:33 leonardr Exp $
 * @@see HelmNoodle
 */
public class ContentHelmNoodle extends HelmNoodle
{
    /**
     * Turn debug log output on/off
     */
    private static final boolean DEBUG = false;

    /**
     * Process the request.
     *
     * @@param connection Connection to database
     * @@param context WebMacro context
     *
     * @@return The name of this template (?)
     *
     * @@exception HandlerException
     * @@exception RedirectException
     */
    protected String processRequest(Context ctx)
        throws NestableException, 
               RedirectException, 
               RedirectServletException, 
               ACLException
    {
        loggedInCheck( ctx );  // Saves query string if we're not logged in.

        String page = (String) ContextAPI.getParameter(ctx, "page");
        String servletName = getServletName();
        ctx.put("servletName", servletName);
        String requiredAction = myProperties.getProperty("permission");

        try 
        {
            loginAsGuestOrYourself(ctx);
            updateCurrentDomainAndProject(ctx, ContextAPI.getRequest(ctx));
            if (requiredAction != null)
            {
                AccessControlList acl = getACL(ctx);
                Project currentProject = getCurrentProject(ctx);
                if (DEBUG) 
                {
                    Log.debug("Checking permission for " + requiredAction);
                    Log.debug("project " + currentProject);
                }
                acl.assertPermission(requiredAction, page, currentProject);
            }
        }

        catch (ACLException aclEx)
        {
            SessionManager sMgr = getSessionManager(ctx);
            HttpSession session = sMgr.getSession();
            User loginUser = (User)session.getValue("loginUser");

            try
            {
                if (!loginUser.isAnonymous())
                {
                    declareInsufficientPermission(ctx);
                }
            }
            catch (Exception e)
            {
                Log.error("Error handling ACLException user message: " 
                          + e.getMessage());

            }
            setAsDetour(ctx);
            throw aclEx;
        }
        catch (RedirectException e)
        {
            throw e;
        }
        catch (Exception e)
        {
            throw new NestableException("Unhandled exception in " +
                                       "ContentHelmNoodle", e);
        }

        return super.processRequest(ctx);
    }

    /** 
     * Servlet start.
     * 
     * @@exception ServletException
     */
    public void start() throws ServletException
    {
        super.start( );
        ProxyModule.setServerName("localhost");
    }

    /**
     * Creates an instance of the data encapsulation fed to Noodle.
     */
    protected HelmNoodleData makeNoodleData(Context ctx) 
    {
        HelmNoodleData result = new HelmNoodleData(ContextAPI.getRequest(ctx),
                                                   ContextAPI.getResponse(ctx),
                                                   ctx);
        result.setPageTransforming(true);
        return result;
    }

    protected void computeToolCrumbs(Context ctx, String page) 
    {
        Project currentProject = getCurrentProject(ctx);
        boolean inWWW = (currentProject != null &&
                         currentProject.getName().equals("www"));
        Vector toolCrumbs = new Vector();
        StringTokenizer st = new StringTokenizer(page, "/");
        String uri = "/";
        BreadCrumbElement bce;
        while (st.hasMoreElements()) {
            String name = st.nextToken();
            uri += name;
            if (st.hasMoreElements()) 
                uri += "/";
            else
                uri = "";
            if (name.endsWith(".html")) name = name.substring(0, name.length()-5);
            if (inWWW && name.equals("docs")) 
                bce = new BreadCrumbElement("On-line Help", "/servlets/HelpTOC");
            else
                bce = new BreadCrumbElement(name, uri);
            toolCrumbs.addElement(bce);
        }
        ctx.put("toolCrumbs", toolCrumbs);
    }

}
@


1.21
log
@Completed migration of more methods to ContextAPI.
@
text
@d71 1
a71 1
 * @@version $Id: ContentHelmNoodle.java,v 1.20 2001/08/11 09:08:07 dlr Exp $
d100 1
a100 1
        String page = (String) getParameter(ctx, "page");
@


1.20
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
text
@d71 1
a71 1
 * @@version $Id: ContentHelmNoodle.java,v 1.19 2001/08/08 22:40:46 jrobbins Exp $
d108 1
a108 1
            updateCurrentDomainAndProject(ctx, getRequest(ctx));
@


1.19
log
@adding better support for breadcrumbs
@
text
@d52 1
a52 3
import org.apache.turbine.util.Log;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.TurbineException;
d58 2
d61 2
a62 2
import org.tigris.helm.publish.NoodleResources;

d65 1
a65 2
import org.tigris.helm.security.*;
import org.tigris.helm.om.*;
d71 1
a71 1
 * @@version $Id: ContentHelmNoodle.java,v 1.18 2001/07/19 19:28:53 dlr Exp $
d93 1
a93 1
        throws TurbineException, 
d150 1
a150 1
            throw new TurbineException("Unhandled exception in " +
d173 2
a174 3
        RunData runData = getRunData(ctx);
        HelmNoodleData result = new HelmNoodleData(runData.getRequest(),
                                                   runData.getResponse(),
@


1.18
log
@Removed Joist references.
@
text
@d48 1
d64 1
d72 1
a72 1
 * @@version $Id: ContentHelmNoodle.java,v 1.17 2001/07/18 10:05:14 dlr Exp $
d181 27
@


1.17
log
@Ported Joist Redirect*Exception to Helm.
@
text
@d59 2
a60 2
import org.joist.publish.ProxyModule;
import org.joist.publish.NoodleResources;
d70 1
a70 1
 * @@version $Id: ContentHelmNoodle.java,v 1.16 2001/06/21 19:49:59 dlr Exp $
@


1.16
log
@Formatting cleanup--zero functional change.
@
text
@a47 1
// Java Servlet Classes
a53 1
import org.apache.turbine.util.TurbineException;
a60 1
import org.joist.security.*;
d67 6
a72 6
* Wrap static html pages in 'branding'.
* 
* @@author <a href="mailto:jrobbins@@collab.net">jrobbins</a>
* @@version $Id: ContentHelmNoodle.java,v 1.15 2001/05/23 01:50:19 dlr Exp $
* @@see HelmNoodle
*/
@


1.15
log
@Ported Helm from WebMacro to Velocity.
@
text
@d73 1
a73 1
* @@version $Id: ContentHelmNoodle.java,v 1.14 2001/05/04 07:29:55 stack Exp $
d83 11
a93 10
    /** Process the request.
    *
    * @@param connection Connection to database
    * @@param context WebMacro context
    *
    * @@return The name of this template (?)
    *
    * @@exception HandlerException
    * @@exception RedirectException
    */
d96 3
a98 3
                RedirectException, 
                RedirectServletException, 
                ACLException
a136 1

d140 1
a140 1
                    + e.getMessage());
d170 3
d176 3
a178 4
        HelmNoodleData result 
            = new HelmNoodleData(runData.getRequest(),
                                 runData.getResponse(),
                                 ctx);
@


1.14
log
@Remove code that wrote Expires, Cache-Control and Last-Modified headers.
The proxy-caching solution that this code was part of doesn't work.
@
text
@d52 6
a57 2
// Java Core Classes
import java.sql.*;
a58 4
import org.apache.turbine.util.Log;
import org.webmacro.util.*;
import org.webmacro.servlet.*;
import org.joist.security.*;
d61 2
d64 2
a65 1
import org.joist.session.*;
a67 3
import org.joist.publish.ProxyModule;
import org.joist.publish.NoodleResources;

d73 1
a73 1
* @@version $Id: ContentHelmNoodle.java,v 1.13 2001/04/30 23:34:33 stack Exp $
d93 2
a94 2
    protected String processRequest( Connection connection, WebContext ctx )
        throws HandlerException, 
d101 1
a101 1
        String page = (String) ctx.getForm("page");
d109 1
a109 1
            updateCurrentDomainAndProject(ctx, ctx.getRequest());
a145 1

d150 1
a150 2

        catch (Exception e2)
d152 2
a153 5
            Log.error("Unhandled exception encountered by ContentHelmNoodle", 
                e2);
            // NOTE: UnsecureServlet calls appendToError() to display a
            // reasonable description of the error message to the user.
            throw new HandlerException(e2.getMessage());
d156 1
a156 10
        return super.processRequest( connection, ctx );
    }
    
    /** 
    * Noodle Servlet
    * @@return String name of this servlet.
    */
    public String getServletInfo()
    {
        return "ContentHelmNoodle Servlet: $Id$";
d170 1
a170 1
    protected HelmNoodleData makeNoodleData(WebContext ctx) 
d172 1
d174 2
a175 2
            = new HelmNoodleData(ctx.getRequest(),
                                 ctx.getResponse(),
a180 2


@


1.13
log
@CHN was preempting HNs saving of the query string across the joist
internal redirect (Joist internal redirect drops the query string).
Broke out the query string saving as a method for CHN to call on
entrance.
@
text
@a45 1

a47 1

a53 3
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.SimpleTimeZone;
a60 1

a68 2


d70 1
a70 3
* Wrap static html pages in branding and add Titles if missing.
*
* Mostly just calls the parent.
d73 1
a73 1
* @@version $Id: ContentHelmNoodle.java,v 1.12 2001/04/25 18:12:54 leonardr Exp $
a74 1
* @@see <a href="http://projects.collab.net/project/eng/stack/projects/securenoodle/">SecureNoodle: Problem Statement, Requirements, Survey, Decisions and Testing</a>
d81 1
a81 91
    private static final boolean DEBUG = true;

    /**
     * Last-modified header in milliseconds.  
     *
     * CHN can write out a last-modified and an expires header so 
     * a proxy-caching server will cache and expire CHN produced 
     * content.  Keep in this static the date, in milliseconds, 
     * that CHN uses writing the Last-Modified header (The 
     * Expires header is calculated using this value plus the
     * lastModifiedUpdateInterval).  Update this value whenever 
     * the last modified value is older than a time specified 
     * in the CHN properties file.  Reads and updates of this value 
     * should be from inside a synchronized block (Read of longs is
     * non-atomic.
     */
    private static long lastModified = 0;

    /** 
     * Update last-modified contents on this interval.
     *
     * This value's contents are pulled from the CHN properties 
     * file.  If setting is 0, we do never write a Last-Modified
     * header.  If its equal to -1, then we never update the
     * Last-Modified contents subsequent to initial calculation.
     * Have the default setting be 0.  This value is in seconds.
     */
    private int lastModifiedUpdateInterval = 0;

    /**
     * Key to pull from CHN property file the interval on which 
     * we update last-modified header.  
     */
    private final static String keyLastModifiedUpdateInterval
        = "lastModifiedUpdateIntervalInSeconds";

    /**
     * HTTP RFC1123-date formatter object.
     *
     * These things are really expensive to construct so keep it
     * around.  Here is a sample date: "Thu, 22 Mar 2001 18:02:49 GMT".
     * Use of this object should be from inside of a synchronized block.
     */
    private static SimpleDateFormat dateFormatter = null;

    /**
     * HTTP RFC1123-date format string for SimpleDateFormat.
     */
    private final static String dateFormat = "EEE, dd MMM yyyy HH:mm:ss zzz"; 

    /**
     * Cached Last-Modified header content.
     *
     * Making one of these w/ the calendar object takes for ages
     * so once made, keep it around.  Updates of this member need
     * to be synchronized. Here is an example of a  last-modified 
     * header:
     * <pre>
     *  Last-Modified:Thu, 22 Mar 2001 18:02:49 GMT
     * </pre>
     */
    private static String lastModifiedAsStr = null;

    /**
     * Last-Modified header label.
     */
    private final static String LAST_MODIFIED_HEADER_LABEL = "Last-Modified";

    /**
     * Cached Expires header content.
     *
     * Making one of these w/ the calendar object takes for ages
     * so once made, keep it around.  Updates of this member need
     * to be synchronized. Here is an example of an Expires
     * header:
     * <pre>
     *  Expires: Thu, 01 Dec 1994 16:00:00 GMT
     * </pre>
     */
    private static String expiresAsStr = null;

    /**
     * Expires header label.
     */
    private final static String EXPIRES_HEADER_LABEL = "Expires";

    /**
     * Cache-Control header label.
     */
    private final static String CACHE_CONTROL_HEADER_LABEL = "Cache-Control";

a84 2
    * Does little but call parent method.
    *
d93 1
a93 2
    protected String processRequest( Connection connection,
                                        WebContext ctx )
d99 2
a101 3
        loggedInCheck( ctx );
        // ctx.put("resource", page);

d104 1
a104 3

        String requiredAction = null;
        requiredAction = myProperties.getProperty("permission");
d121 1
a121 1
         }
d136 1
d154 2
a155 1
            Log.error("Unhandled exception encountered by ContentHelmNoodle", e2);
d161 1
a161 122

        String templateName = super.processRequest( connection, ctx );

        // Add Last-Modified and Expires headers to CHN content.
        //
        addCachingHeaders( ctx.getResponse( ) );

        return templateName; 
    }

    /**
     * Add a Last-Modified and an Expires header to the http response if 
     * they aren't there currently.
     * 
     * CHN serves static html.  W/o a last-modified/expires header combination,
     * when CHN sits behind a caching-proxy, its output is never cached.  
     * Every access of a page served by CHN results in 3 server 
     * hits (one to the proxy-caching server, one to the remote origin server, 
     * and then the request that is done by CHN itself). We can reduced these
     * three hits to one if the caching-proxy is triggered to cache CHN output. 
     * <p> 
     * In this method, we check the state of our cached header content strings.  
     * If out-of-date, update the cache.  Use what is in cache to add 
     * a 'Last-Modified' and 'Expires' header to the HTTP response.  If
     * the lastModifiedUpdateInterval is '-1', do not write an expires
     * header after initial update.   If lastModifiedUpdateInterval is
     * zero, never write a Last-Modified or Expires header.
     * 
     * @@param inResponse The HTTP response.  Add header to this. 
     */
    private void addCachingHeaders( HttpServletResponse inResponse )
    {
        if( ! inResponse.containsHeader( LAST_MODIFIED_HEADER_LABEL ) 
            && ( lastModifiedUpdateInterval != 0 ) ) 
        {
            checkCachedHeaders( );
            inResponse.setHeader( LAST_MODIFIED_HEADER_LABEL, 
                lastModifiedAsStr );        

            if( ! inResponse.containsHeader( EXPIRES_HEADER_LABEL ) )
            {
                inResponse.setHeader( EXPIRES_HEADER_LABEL, expiresAsStr ); 
            }

            if( ! inResponse.containsHeader( CACHE_CONTROL_HEADER_LABEL ) )
            {
                String interval 
                    = Integer.toString( lastModifiedUpdateInterval );
                inResponse.setHeader( CACHE_CONTROL_HEADER_LABEL, 
                    "max-age=" + interval + ", must-revalidate" ); 
            }
        }
    }

    /** 
     * Check our cached values for last-modified and expires headers.
     * 
     * If the cache is unitialized (lastModified == 0) OR if the total of our
     * update interval and the last modified time is less than the current time
     * then update our cache.  Make exception if the update interval is -1.  In
     * this case -- don't update cache ever, once its been initialized.
     */
    private void checkCachedHeaders( )
    {
        long now  = System.currentTimeMillis( );

        // Convert int to long and seconds to ms.
        //
        long interval = lastModifiedUpdateInterval * 1000;

        // Reads of longs is non-atomic.  Read lastModified inside of a 
        // synchronized block.
        //
        long safeLastModified; 
        synchronized( this )
        {
            safeLastModified = lastModified;
        }
        
        if( ( safeLastModified <= 0 )
            || ( ( lastModifiedUpdateInterval != -1 ) 
                && ( ( safeLastModified + interval  ) < now ) ) )
        {
            updateCachedHeaders( lastModifiedUpdateInterval ); 
            Log.debug( "Updated cached Last-Modified/Expires." );
        }
    }

    /** 
     * Update our out-of-date cached last-modified and expires header 
     * values.
     * 
     * Set the expires header to be the last-modified time plus
     * lastModifiedUpdateInterval.  
     *
     * This is an expensive method.  Its a synchronized static. 
     * 
     * @@param inInterval The interval in seconds at which we update 
     * the last-modified and expires headers.  Set the expires time to be
     * the current time plus this interval.  Can be -1 for case that
     * we're never to update after initial setting.  Check for this 
     * case and set the update to be a year in the future at the suggestion
     * of the HTTP 1.1. RFC.
     */
    private synchronized static void updateCachedHeaders( long inInterval ) 
    {
        Date now = new Date( );
        lastModified = now.getTime( );
        lastModifiedAsStr = dateFormatter.format( now );
        long expiresTime;
        if( inInterval != -1 )
        {
            expiresTime = lastModified + ( inInterval * 1000 );
        }
        else
        {
            expiresTime 
                = lastModified + ( 1000 * 60 * 60 * 24 * 365 );
        } 

        now.setTime( expiresTime );
        expiresAsStr = dateFormatter.format( now );
d170 1
a170 1
        return "ContentHelmNoodle Servlet";
d181 1
a181 21

	    ProxyModule.setServerName("localhost");


        // Read property for how long we cache last-modified date string.
        // 
        String intervalProperty 
            =  myProperties.getProperty( keyLastModifiedUpdateInterval );
        lastModifiedUpdateInterval = Integer.parseInt( intervalProperty );
        Log.info( "Read Last-Modified update interval property: "  
                    + intervalProperty );
   
        
        synchronized( this )
        {
            if( dateFormatter == null )
            {
                dateFormatter = new SimpleDateFormat( dateFormat );
                dateFormatter.setTimeZone( new SimpleTimeZone( 0, "GMT" ) );
            } 
        }
@


1.12
log
@Give RedirectExceptions to the superclass to handle, rather than barfing on them.
@
text
@d83 1
a83 1
* @@version $Id: ContentHelmNoodle.java,v 1.11 2001/04/21 17:47:24 stack Exp $
d204 2
a205 1
        ctx.put("resource", page);
@


1.11
log
@Also write a HTTP 1.1 Cache-Control header, along w/ the Expires and
Last-Modified headers, whenever lastModifiedUpdateInterval is non-null.
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d83 1
a83 1
* @@version $Id: ContentHelmNoodle.java,v 1.10 2001/04/21 00:16:03 stack Exp $
d252 5
d259 1
a259 1
            Log.error("Unhandled exception encountered by HelmServlet", e2);
@


1.10
log
@Setting default behavior to NOT write Last-Modified/Expires headers.
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d83 1
a83 1
* @@version $Id: ContentHelmNoodle.java,v 1.9 2001/04/15 23:40:00 stack Exp $
d178 5
d198 4
a201 1
        throws HandlerException, RedirectException, ACLException
d299 6
a304 2
            if( ( lastModifiedUpdateInterval != -1 )
                && ( ! inResponse.containsHeader( EXPIRES_HEADER_LABEL ) ) )
d306 4
a309 1
                inResponse.setHeader( EXPIRES_HEADER_LABEL, expiresAsStr );        
@


1.9
log
@Write Last-Modified and Expires headers.  Reset last-modified and
expires header content on an interval specified in the CHN.properties
file.
@
text
@d80 1
a80 1
* Does little but call it's parent.
d83 1
a83 1
* @@version $Id: ContentHelmNoodle.java,v 1.8 2001/04/04 20:53:08 dlr Exp $
d97 1
a97 1
     * CHN writes out a last-modified and an expires header so 
d103 1
a103 1
     * the the last modified value is older than a time specified 
d114 2
a115 1
     * file.  If its equal to -1, then we never update the
d117 1
a117 1
     * Have the default setting be -1.  This value is in seconds.
d119 1
a119 1
    private int lastModifiedUpdateInterval = -1;
a142 6
     * A GMT SimpleTimeZone object.
     */
    private final static SimpleTimeZone gmt_timezone 
        = new SimpleTimeZone( 0, "GMT" );
       
    /**
d277 2
a278 1
     * header.
d284 2
a285 1
        if( ! inResponse.containsHeader( LAST_MODIFIED_HEADER_LABEL ) ) 
d404 1
a404 1
                dateFormatter.setTimeZone( gmt_timezone );
@


1.8
log
@Removed useless versionID member.
@
text
@d56 3
d77 2
a78 1
/** An Issuezilla specialization on HelmNoodle.
d83 1
a83 1
* @@version $Id: ContentHelmNoodle.java,v 1.7 2001/04/04 00:24:53 jrobbins Exp $
d92 90
a181 1
    private static final boolean DEBUG = false;
a182 1
    
d203 2
a204 2
	String servletName = getServletName();
	ctx.put("servletName", servletName);
d209 2
a210 1
        try {
d214 10
a223 9
                 {
                     AccessControlList acl = getACL(ctx);
                     Project currentProject = getCurrentProject(ctx);
                     if (DEBUG) {
                         Log.debug("Checking permission for " + requiredAction);
                         Log.debug("project " + currentProject);
                     }
                     acl.assertPermission(requiredAction, page, currentProject);
                 }
d225 1
d241 3
a243 2
                Log.error("Error handling ACLException user message: " +
                          e.getMessage());
d248 1
d257 113
a369 1
        return super.processRequest( connection, ctx );
d372 2
a373 2

    /** Noodle Servlet
d381 10
d392 18
a409 3
    public void start() throws ServletException {
	super.start();
	ProxyModule.setServerName("localhost");
a420 2


@


1.7
log
@PR: 3412. Since ContentHelmNoodle does specific resource permission checking before hitting the actual page, it needs to do some more of what HelmServlet does. Broke out the guest login and/or redirect login as a method I can call.
@
text
@d79 1
a79 1
* @@version $Id: ContentHelmNoodle.java,v 1.6 2001/03/27 07:02:31 jrobbins Exp $
a84 6
    /** Class version string
    */
    private static final String versionID
        = "$Id: ContentHelmNoodle.java,v 1.6 2001/03/27 07:02:31 jrobbins Exp $";

    
@


1.6
log
@content noodle resource checking
@
text
@d79 1
a79 1
* @@version $Id: ContentHelmNoodle.java,v 1.5 2001/03/23 22:05:50 leonardr Exp $
d88 1
a88 1
        = "$Id: ContentHelmNoodle.java,v 1.5 2001/03/23 22:05:50 leonardr Exp $";
d124 1
@


1.6.2.1
log
@Merging in Jason's bug fix to the HEAD:

PR: 3412. Since ContentHelmNoodle does specific resource permission
checking before hitting the actual page, it needs to do some more of
what HelmServlet does. Broke out the guest login and/or redirect login
as a method I can call.
@
text
@d79 1
a79 1
* @@version $Id: ContentHelmNoodle.java,v 1.8 2001/04/04 20:53:08 dlr Exp $
d85 6
a123 1
            loginAsGuestOrYourself(ctx);
@


1.6.2.1.4.1
log
@CHN was preempting its parents' saving of query string.  This code breaks
out the parent, HN, query-saving as a method for CHN to call upon entrance.

Joist internal redirects drop query strings.  Whenever a user is forced to
login before they can access a page, they are allowed access only via a
login managed by an joist internal redirect.  The argument of what to
proxy is carried in the query string.  When dropped by the joist internal
redirect, Noodle was throwing NPEs not knowing what to proxy.

Also commited the leonardr fix that stops CHN catching redirect exceptions.
Joist does redirects w/ exceptions.  CHN was catching these redirects as
real 'exceptions' rather than letting them propagate up the stack for
later processing by joist.

Reviewed by: Reviewed and tested by JRobbins
@
text
@d79 1
a79 1
* @@version $Id: ContentHelmNoodle.java,v 1.6.2.1 2001/04/04 20:54:46 dlr Exp $
d109 1
a109 2
        loggedInCheck( ctx );
        // ctx.put("resource", page);
a151 6

        catch (RedirectException e)
        {
            throw e;
        }

@


1.6.2.1.4.2
log
@Formatting cleanup--zero functional change.
@
text
@d74 9
a82 10
/**
 * A specialization on HelmNoodle for content.
 *
 * Does little but call it's parent.
 * 
 * @@author <a href="mailto:jrobbins@@collab.net">jrobbins</a>
 * @@version $Id: ContentHelmNoodle.java,v 1.6.2.1.4.1 2001/05/01 05:45:17 stack Exp $
 * @@see HelmNoodle
 * @@see <a href="http://projects.collab.net/project/eng/stack/projects/securenoodle/">SecureNoodle: Problem Statement, Requirements, Survey, Decisions and Testing</a>
 */
d90 14
a103 13
    /**
     * Process the request.
     *
     * Does little but call parent method.
     *
     * @@param connection Connection to database
     * @@param context WebMacro context
     *
     * @@return The name of this template (?)
     *
     * @@exception HandlerException
     * @@exception RedirectException
     */
d110 1
d112 2
a113 2
        String servletName = getServletName();
        ctx.put("servletName", servletName);
d118 1
a118 2
        try
        {
d122 10
a131 10
            {
                AccessControlList acl = getACL(ctx);
                Project currentProject = getCurrentProject(ctx);
                if (DEBUG) {
                    Log.debug("Checking permission for " + requiredAction);
                    Log.debug("project " + currentProject);
                }
                acl.assertPermission(requiredAction, page, currentProject);
            }
        }
d153 1
d158 1
d169 1
d171 3
a173 4
    /**
     * Noodle Servlet
     * @@return String name of this servlet.
     */
d179 4
a182 7
    /**
     * Performs initialiation.
     */
    public void start() throws ServletException
    {
        super.start();
        ProxyModule.setServerName("localhost");
a184 3
    /**
     * Creates an instance of the data encapsulation fed to Noodle.
     */
d187 4
a190 3
        HelmNoodleData result = new HelmNoodleData(ctx.getRequest(),
                                                   ctx.getResponse(),
                                                   ctx);
d194 2
d197 2
@


1.5
log
@Begone annoying debug statement!
@
text
@d63 3
d79 1
a79 1
* @@version $Id: ContentHelmNoodle.java,v 1.4 2001/03/05 02:36:07 jrobbins Exp $
d88 1
a88 1
        = "$Id: ContentHelmNoodle.java,v 1.4 2001/03/05 02:36:07 jrobbins Exp $";
d91 4
d96 1
d111 2
a112 2
                                        WebContext context )
        throws HandlerException, RedirectException
d114 50
a163 29
        String page = (String) context.getForm("page");
        //        Log.debug("page=" + page);
        context.put("resource", page);

//         String requiredAction = null;
//         requiredAction = myProperties.getProperty("permission");

//         try {
//             if (requiredAction != null)
//                 {
//                     AccessControlList acl = getACL(context);
//                     Project currentProject = getCurrentProject(context);
//                     Log.debug("Checking permission for " + requiredAction);
//                     Log.debug("project " + currentProject);
//                     Log.debug("one more line");
//                     acl.assertPermission(requiredAction, page, currentProject);
//                 }
//         }
//         catch (ACLException e) {
//             setAsDetour(context);
//             throw e;
//         }
//         catch (Exception e2)
//         {
//             Log.error("Unhandled exception encountered by HelmServlet", e2);
//             // NOTE: UnsecureServlet calls appendToError() to display a
//             // reasonable description of the error message to the user.
//             throw new HandlerException(e2.getMessage());
//         }
d165 1
a165 1
        return super.processRequest( connection, context );
d183 1
a183 1
    protected HelmNoodleData makeNoodleData(WebContext context) 
d186 3
a188 3
            = new HelmNoodleData( context.getRequest( ),
                context.getResponse( ),
                context );
@


1.4
log
@updated to use new logging, added checking of permission resources
@
text
@d76 1
a76 1
* @@version $Id: ContentHelmNoodle.java,v 1.3 2001/01/26 18:29:07 edk Exp $
d85 1
a85 1
        = "$Id: ContentHelmNoodle.java,v 1.3 2001/01/26 18:29:07 edk Exp $";
d107 1
a107 1
        Log.debug("page=" + page);
@


1.3
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d57 1
d63 2
a64 1
import org.tigris.helm.security.HelmServlet;
d76 1
a76 1
* @@version $Id: ContentHelmNoodle.java,v 1.1 2000/11/29 18:46:13 jrobbins Exp $
d85 1
a85 1
        = "$Id: ContentHelmNoodle.java,v 1.1 2000/11/29 18:46:13 jrobbins Exp $";
a87 3
    /** Logging object
    */
    static private Log log = new Log( "ContNdl", "ContentHelmNoodle" );
d104 1
a104 2
        throws HandlerException,
                RedirectException
d106 30
d138 1
a138 1

@


1.3.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d74 1
a74 1
* @@version $Id: ContentHelmNoodle.java,v 1.3 2001/01/26 18:29:07 edk Exp $
d83 1
a83 1
        = "$Id: ContentHelmNoodle.java,v 1.3 2001/01/26 18:29:07 edk Exp $";
@


1.2
log
@revert this stuff to its state as of 2001/01/24 12:42:00 GMT -- with
the following exceptions, which have some different modifications so
they'll work with changes which have happened in joist:

ProjectNewsEdit.java
SkinManager.java
SkinStyleElementValueManager.java
StyleElementManager.java
StyleManager.java

it compiles.  i dunno if it works, though.
@
text
@@


1.1
log
@added ContentHelmNoodle and all of its associated files, also had to add a hook for ProxyModule to transform page name and support for alternative master templates
@
text
@d74 1
a74 1
* @@version $Id: IssuezillaHelmNoodle.java,v 1.1.1.1 2000/11/12 21:16:25 dlr Exp $
d83 1
a83 1
        = "$Id: IssuezillaHelmNoodle.java,v 1.1.1.1 2000/11/12 21:16:25 dlr Exp $";
@

