head	1.5;
access;
symbols;
locks; strict;
comment	@# @;


1.5
date	2001.08.28.22.24.07;	author dlr;	state dead;
branches;
next	1.4;

1.4
date	2001.08.11.09.08.07;	author dlr;	state Exp;
branches;
next	1.3;

1.3
date	2001.07.18.10.05.14;	author dlr;	state Exp;
branches;
next	1.2;

1.2
date	2001.05.25.20.58.24;	author dlr;	state Exp;
branches;
next	1.1;

1.1
date	2001.05.25.20.57.27;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.5
log
@jrobbins indicates that this servlet is dead
@
text
@/* ================================================================
 * Copyright (c) 1999-2001 CollabNet.  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 CollabNet (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" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * 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 COLLABNET 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 CollabNet.
 */

package org.tigris.helm.publish;

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

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

import org.apache.velocity.context.Context;

import org.tigris.helm.security.RedirectException;

import org.tigris.helm.security.BaseHelmServlet;
import org.tigris.helm.tool.ContextAPI;

/**
 * Wrap an external page or CGI with the standard branding template.
 */
public class Wrap extends BaseHelmServlet
{
    private static final boolean DEBUG = false;
   
    /**
     * Displays the page after pre-processing it to make it
     * template-friendly. Used for wrapping HTML and CGIs external to
     * the system.
     */
    protected String processRequest(Context context)
        throws NestableException, RedirectException
    {
        try
        {
            // Let the superclass do it's part.
            String templateName =  super.processRequest(context);
            if (DEBUG) Log.debug("Wrap template name: " + templateName);

            // Now let's grab the URL and do any necessary pre-processing.
            URL baseURL = new URL(HttpUtils.getRequestURL
                                  (ContextAPI.getRequest(context)).toString());
            if (DEBUG) Log.debug("Wrap baseURL: " + baseURL.toString());
            URL url = new URL(baseURL,
                              ContextAPI.getParameter(context, "page"));
            if (DEBUG) Log.debug("Wrap URL: " + url.toString());
            String page = wrap(url);
        
            // Refer to the new page and go on.
            context.put("page", page);
            if (DEBUG) Log.debug("Wrap page: " + url);

            return templateName;
        }
        catch (IOException e)
        {
            throw new NestableException(e);
        }
    }

    /**
     *  Reads the contents fo the URL and modifies as necessary.
     *  We currently only handle HTML content. Non-html content
     *  is considered an error.
     * @@param url The URL to wrap.
     * @@return The wrapped URL as text.
     * @@exception IOException Error reading content from URL.
     */
    private String wrap(URL url)
        throws IOException
    {
        // Read the page in line by line.
        StringBuffer buf = new StringBuffer(2048);
        BufferedReader is =
            new BufferedReader(new InputStreamReader(url.openStream()));
        String line;
        while ((line = is.readLine()) != null)
        {
            // Scan line and replace as necessary.
            buf.append(line).append('\n');
        }
        is.close();
        if (DEBUG) Log.debug ("Wrap Data: " + buf.toString() );
        return buf.toString();
    }
}
@


1.4
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
text
@@


1.3
log
@Ported Joist Redirect*Exception to Helm.
@
text
@d55 1
a55 1
import org.apache.turbine.util.TurbineException;
d77 1
a77 1
        throws TurbineException, RedirectException
d102 1
a102 1
            throw new TurbineException(e);
@


1.2
log
@cleanup
@
text
@d59 1
a59 1
import org.joist.security.RedirectException;
@


1.1
log
@Ported Joist's Wrap servlet into Helm.
@
text
@d61 1
a62 1
import org.tigris.helm.security.BaseHelmServlet;
d72 3
a74 3
     *  Displays the page after pre-processing it to make
     *  it webmacro-happy. This is used for wrapping html
     *  and CGIs external to the system.
@

