head	1.12;
access;
symbols
	TIGRIS_1_1_0RC2:1.3.6.2
	TIGRIS_1_1_0RC1:1.3.6.2
	TIGRIS_1_1:1.3.6.2.0.2
	TIGRIS_1_0_8:1.3.6.2
	TIGRIS_1_0_8RC3:1.3.6.2
	TIGRIS_1_0_8RC2:1.3.6.2
	TIGRIS_1_0_8RC1:1.3.6.2
	TIGRIS_1_0_7:1.3.6.2
	TIGRIS_1_0_7RC3:1.3.6.2
	TIGRIS_1_0_7RC2:1.3.6.2
	TIGRIS_1_0_7RC1:1.3.6.2
	TIGRIS_1_0_6:1.3.6.2
	TIGRIS_1_0_6RC5:1.3.6.2
	TIGRIS_1_0_6RC4:1.3.6.2
	TIGRIS_1_0_6RC3:1.3.6.2
	TIGRIS_1_0_6RC2:1.3.6.2
	TIGRIS_1_0_6RC1:1.3.6.2
	TIGRIS_1_0_5:1.3.6.1
	TIGRIS_1_0_5RC6:1.3.6.1
	TIGRIS_1_0_5RC5:1.3.6.1
	TIGRIS_1_0_5RC4:1.3.6.1
	TIGRIS_1_0_5RC3:1.3.6.1
	TIGRIS_1_0_5RC2:1.3.6.1
	TIGRIS_1_0_5RC1:1.3.6.1
	TIGRIS_1_0_4:1.3.6.1
	TIGRIS_1_0_3:1.3.6.1
	TIGRIS_1_0_2:1.3.6.1
	TIGRIS_1_0_1:1.3
	TIGRIS_1_0:1.3.0.6
	TIGRIS_1_0_0:1.3
	TIGRIS_1_0_0_RC1:1.3.0.2
	dlr:1.1.1
	HELM_PEER_PORT_BRANCH:1.1.1.1;
locks; strict;
comment	@# @;


1.12
date	2001.07.16.02.23.42;	author jrobbins;	state dead;
branches;
next	1.11;

1.11
date	2001.06.06.23.55.52;	author dlr;	state Exp;
branches;
next	1.10;

1.10
date	2001.06.06.21.55.53;	author dlr;	state Exp;
branches;
next	1.9;

1.9
date	2001.06.04.06.39.27;	author dlr;	state Exp;
branches;
next	1.8;

1.8
date	2001.05.31.19.12.28;	author elicia;	state Exp;
branches;
next	1.7;

1.7
date	2001.05.23.01.50.15;	author dlr;	state Exp;
branches;
next	1.6;

1.6
date	2001.05.08.21.48.52;	author elicia;	state Exp;
branches;
next	1.5;

1.5
date	2001.04.19.19.13.12;	author dlr;	state Exp;
branches;
next	1.4;

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

1.3
date	2001.03.07.01.53.24;	author lucas;	state Exp;
branches
	1.3.6.1;
next	1.2;

1.2
date	2001.02.21.03.02.29;	author edk;	state Exp;
branches;
next	1.1;

1.1
date	2001.02.14.00.18.43;	author elicia;	state dead;
branches
	1.1.1.1
	1.1.2.1;
next	;

1.1.1.1
date	2001.02.21.00.34.59;	author dlr;	state Exp;
branches;
next	;

1.1.2.1
date	2001.02.14.00.18.43;	author elicia;	state Exp;
branches;
next	1.1.2.2;

1.1.2.2
date	2001.02.15.20.50.42;	author leonardr;	state Exp;
branches;
next	1.1.2.3;

1.1.2.3
date	2001.02.16.03.01.34;	author dlr;	state Exp;
branches;
next	1.1.2.4;

1.1.2.4
date	2001.02.17.00.15.01;	author elicia;	state Exp;
branches;
next	;

1.3.6.1
date	2001.04.20.21.46.30;	author edk;	state Exp;
branches;
next	1.3.6.2;

1.3.6.2
date	2001.06.04.06.47.46;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.12
log
@factoring project documents out to project nidaba.tigris.org
@
text
@/* ================================================================
 * Copyright (c) 2000-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 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" name
 * nor may "Tigris" 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 CollabNet.
 */


package org.tigris.helm.project;

import java.io.*;
import java.sql.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.turbine.util.Log;
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.TurbineException;
import org.apache.velocity.context.Context;

import org.joist.security.*;
import org.joist.util.URL;

import org.tigris.helm.om.*;
import org.tigris.helm.tool.MDACookie;
import org.tigris.helm.security.*;


public class ProjectDocumentList extends HelmServlet
{
    private static final boolean DEBUG = true;

    /**
     * The action key for downloading an existing file.
     */
    private static final String DO_DOWNLOAD = "download";

    /**
     * The database key of the document
     */
    private static final String DOCUMENT_ID = "dcID";

    /**
     * The ID of the section to use as the root of the tree.
     */
    private static final String ROOT_SECTION_ID = "rootSectionID";


    protected String processRequest(Context ctx)
        throws TurbineException, RedirectException
    {
        String templateName = super.processRequest(ctx);
        HttpServletRequest req = getRequest(ctx);
        String action = getAction(ctx);
        Project project = getCurrentProject(ctx);
        User user = getLoginUser(ctx);
        String rootSectionID = processField(ctx, ROOT_SECTION_ID);

        if (!rootSectionID.equals("") && !rootSectionID.equals("0"))
        {
            try
            {
                ProjectSection rootSection = (ProjectSection)ProjectSectionPeer
                                             .getInstance(rootSectionID);
                ctx.put("rootSection", rootSection);
            }
            catch (Exception e)
            {
                String msg = "Error getting section with id " + rootSectionID +
                    ": " + e.getMessage();
                appendToError(ctx, msg);
                throw new TurbineException(msg);
            }
        }
        else
        {
            ctx.put("rootSectionID", "0");
        }

        if (action.equals(DO_DOWNLOAD))
        {
            try
            {
                AccessControlList acl = user.getACL();
                // Authorize the download and redirect to the file server.
                String dcID = req.getParameter(DOCUMENT_ID);
                if (DEBUG) Log.debug("ProjectDocumentList: dcID=" + dcID);
                ProjectDocument dc =
                    (ProjectDocument) ProjectDocumentPeer.getInstance (dcID);

                if (dc.isViewableBy(acl))
                {
                    Log.debug("ProjectDocumentList: Authorizing download");
                    MDACookie.write (myProperties.getProperty ("fileServer"),
                                     project, user, dc.isPublic(), req,
                                     getRunData(ctx).getResponse());
                    StringBuffer dcURL = new StringBuffer(req.getScheme())
                        .append("://")
                        .append(myProperties.getProperty("fileServer"));
                    if (req.getServerPort() != URL.HTTP_PORT &&
                        req.getServerPort() != URL.HTTPS_PORT)
                    {
                        dcURL.append(':').append(req.getServerPort());
                    }
                    dcURL.append("/files/documents/")
                        .append(dcID)
                        .append('/')
                        .append(URL.encode(dc.getFileName()));
                    redirectToURL(ctx, dcURL.toString());
                }
                else
                {
                    appendToMessage(ctx, "No permission to access requested " +
                                    "file '" + dc.getFileName() + '\'');
                }
            }
            catch (RedirectURLException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                Log.error(e);
                throw new TurbineException(e);
            }
        }

        String msg = getParameter(ctx, Project.MESSAGE);
        if (haveValue(msg)) appendToMessage(ctx, msg);

        return templateName;
    }
}
@


1.11
log
@Use constant for conditional compilation debug flag.
@
text
@@


1.10
log
@Cleaned up error handling.
@
text
@d70 1
a70 1
    private static boolean debug = true;
d116 1
a116 1
               ctx.put("rootSectionID", "0");
d126 1
a126 1
                if (debug) Log.debug("dcID=" + dcID);
d132 1
@


1.9
log
@* Removed low value authDownload() method in favor of inling the
coding directly.

* Present MDA cryptographic token only to users with sufficient
permission.
@
text
@d100 2
a101 1
            try {
d105 6
a110 4
            } catch (Exception e) {
                String msg = "Error getting section with id " + rootSectionID + ":" + e.getMessage();
                Log.error(msg, e);
                appendToMessage(ctx, msg);
d113 3
a115 1
        } else {
@


1.8
log
@Many changes to the Project Documents component.  It is now replacing ProjectDownloads (will remove it from cvs after a while). Took out the "type" variable so that a Document can have a file upload attachment and/or a remote URL and/or pasted text, instead of only one of the three. Added fields for modified by and modified date. Also added isPublic field for file uploads, and a status field.

Document file uploads are now being saved in helm/data/fileserv/documents/[document_id]. Refactored htAccess file code to reflect that and to fix other bugs.
Dropped $type parameter from URL arguments."

UI has changed: ProjectDocumentList now has a 2-pane UI with a folder tree on the left pane and the document list on the right.  When in the list you have a "root folder" that is the root of the tree.  Folders can now be infinitely nested instead of just two levels deep.  You add a document or subfolder directly to the root section.
@
text
@d124 25
a148 11
                authDownload(project, user, dc.isPublic(), req,
                             getRunData(ctx).getResponse());
                String dcURL = req.getScheme()
                    + "://"
                    + myProperties.getProperty("fileServer")
                    + ((req.getServerPort () == 80 || req.getServerPort () == 443)
                       ? "" : ":" + req.getServerPort ())
                    + "/files/documents/"
                    + dcID + '/'
                    + URL.encode(dc.getFileName());
                redirectToURL (ctx, dcURL);
a164 22
    }

    /**
     * Cookies the user with a ticket that authorizes download of a specific
     * file.
     */
    private void authDownload (Project project, User user, 
                               boolean isPublic,
                               HttpServletRequest req,
                               HttpServletResponse res)
        throws TurbineException
    {
        try
        {
            MDACookie.write (myProperties.getProperty ("fileServer"), project,
                             user, isPublic, req, res);
        }
        catch (Exception e)
        {
            Log.error(e);
            throw new TurbineException(e);
        }
@


1.7
log
@Ported Helm from WebMacro to Velocity.
@
text
@d82 5
d96 17
d132 1
a132 2
                    + project.getID ()
                    + '/' + dc.getProposedBy() + '/' 
@


1.6
log
@encoding URL for document filename so that filenames with spaces will work (using ms' joist.util.URL class)
@
text
@d56 3
a58 1
import org.webmacro.servlet.*;
d83 2
a84 2
    protected String processRequest (Connection conn, WebContext ctx)
        throws HandlerException, RedirectException
d86 2
a87 2
        String templateName = super.processRequest (conn, ctx);
        HttpServletRequest req = ctx.getRequest();
d102 2
a103 1
                authDownload(project, user, dc.isPublic(), req, ctx.getResponse());
d122 1
a122 1
                throw new HandlerException(e.getMessage ());
d126 1
a126 1
        String msg = ctx.getForm(Project.MESSAGE);
d140 1
a140 1
        throws HandlerException
d150 1
a150 1
            throw new HandlerException(e.getMessage());
@


1.5
log
@Someone forgot to include the mod_auth_mda message when refactoring.
@
text
@d59 1
d108 2
a109 1
                    + '/' + dc.getProposedBy() + '/' + dc.getFileName();
@


1.4
log
@Formatting fixes (no functional change).
@
text
@d121 3
@


1.3
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@d80 8
a87 8
  protected String processRequest (Connection conn, WebContext ctx)
    throws HandlerException, RedirectException
  {
    String templateName = super.processRequest (conn, ctx);
    HttpServletRequest req = ctx.getRequest();
    String action = getAction(ctx);
    Project project = getCurrentProject(ctx);
    User user = getLoginUser(ctx);
d89 30
a118 19
    if (action.equals(DO_DOWNLOAD))
    {
       try
       {
           AccessControlList acl = user.getACL();
           // Authorize the download and redirect to the file server.
           String dcID = req.getParameter(DOCUMENT_ID);
           if (debug) Log.debug("dcID=" + dcID);
           ProjectDocument dc = (ProjectDocument)ProjectDocumentPeer.getInstance (dcID);
           authDownload (project, user, dc.isPublic(), req, ctx.getResponse ());
           String dcURL = req.  getScheme ()
             + "://"
             + myProperties.getProperty ("fileServer")
             + ((req.getServerPort () == 80 || req.getServerPort () == 443)
                 ? "" : ":" + req.getServerPort ())
             + "/files/documents/"
             + project.getID ()
             + '/' + dc.getProposedBy() + '/' + dc.getFileName();
           redirectToURL (ctx, dcURL);
d121 14
a134 1
        catch (RedirectURLException e)
d136 2
a137 1
          throw e;
a138 1

d141 2
a142 2
          Log.error (e);
          throw new HandlerException (e.getMessage ());
a144 2

    return templateName;
a145 23

  /**
   * Cookies the user with a ticket that authorizes download of a specific
   * file.
   */
        private void authDownload (Project project, User user, 
                                   boolean isPublic,
                                   HttpServletRequest req,
                                   HttpServletResponse res)
     throws HandlerException
     {
       try
       {
	       MDACookie.write (myProperties.getProperty ("fileServer"), project,
		               	    user, isPublic, req, res);
       }
       catch (Exception e)
       {
            Log.error(e);
            throw new HandlerException(e.getMessage());
        }
     }
} /* end class ProjectDocumentList */
@


1.3.6.1
log
@Port some of dlr's bug fixes back to the branch.
@
text
@d80 10
a89 2
    protected String processRequest (Connection conn, WebContext ctx)
        throws HandlerException, RedirectException
d91 18
a108 5
        String templateName = super.processRequest (conn, ctx);
        HttpServletRequest req = ctx.getRequest();
        String action = getAction(ctx);
        Project project = getCurrentProject(ctx);
        User user = getLoginUser(ctx);
d110 1
a110 1
        if (action.equals(DO_DOWNLOAD))
d112 1
a112 28
            try
            {
                AccessControlList acl = user.getACL();
                // Authorize the download and redirect to the file server.
                String dcID = req.getParameter(DOCUMENT_ID);
                if (debug) Log.debug("dcID=" + dcID);
                ProjectDocument dc =
                    (ProjectDocument) ProjectDocumentPeer.getInstance (dcID);
                authDownload(project, user, dc.isPublic(), req, ctx.getResponse());
                String dcURL = req.getScheme()
                    + "://"
                    + myProperties.getProperty("fileServer")
                    + ((req.getServerPort () == 80 || req.getServerPort () == 443)
                       ? "" : ":" + req.getServerPort ())
                    + "/files/documents/"
                    + project.getID ()
                    + '/' + dc.getProposedBy() + '/' + dc.getFileName();
                redirectToURL (ctx, dcURL);
            }
            catch (RedirectURLException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                Log.error(e);
                throw new HandlerException(e.getMessage ());
            }
d115 6
a120 2
        String msg = ctx.getForm(Project.MESSAGE);
        if (haveValue(msg)) appendToMessage(ctx, msg);
d122 2
a123 2
        return templateName;
    }
d125 17
a141 17
    /**
     * Cookies the user with a ticket that authorizes download of a specific
     * file.
     */
    private void authDownload (Project project, User user, 
                               boolean isPublic,
                               HttpServletRequest req,
                               HttpServletResponse res)
        throws HandlerException
    {
        try
        {
            MDACookie.write (myProperties.getProperty ("fileServer"), project,
                             user, isPublic, req, res);
        }
        catch (Exception e)
        {
d145 2
a146 2
    }
}
@


1.3.6.2
log
@* Removed low value authDownload() method in favor of inling the
coding directly.

* Present MDA cryptographic token only to users with sufficient
permission.
@
text
@a57 1
import org.joist.util.URL;
d99 10
a108 25

                if (dc.isViewableBy(acl))
                {
                    MDACookie.write(myProperties.getProperty ("fileServer"),
                                    project, user, dc.isPublic(), req,
                                    ctx.getResponse());

                    StringBuffer dcURL = new StringBuffer(req.getScheme());
                    dcURL.append("://")
                        .append(myProperties.getProperty("fileServer"));
                    if (req.getServerPort() != URL.HTTP_PORT &&
                        req.getServerPort() != URL.HTTPS_PORT)
                    {
                        dcURL.append(':').append(req.getServerPort());
                    }
                    dcURL.append("/files/documents/").append(project.getID())
                        .append('/').append(dc.getProposedBy()).append('/')
                        .append(URL.encode(dc.getFileName()));
                    redirectToURL (ctx, dcURL.toString());
                }
                else
                {
                    appendToMessage(ctx, "No permission to access requested " +
                                    "file '" + dc.getFileName() + '\'');
                }
d125 22
@


1.2
log
@adding files from the branch to the head
@
text
@a60 2
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;
@


1.1
log
@file ProjectDocumentList.java was initially added on branch HELM_PEER_PORT_BRANCH.
@
text
@d1 148
@


1.1.1.1
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@a0 148
/* ================================================================
 * Copyright (c) 2000-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 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" name
 * nor may "Tigris" 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 CollabNet.
 */


package org.tigris.helm.project;

import java.io.*;
import java.sql.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.turbine.util.Log;
import org.webmacro.servlet.*;

import org.joist.security.*;

import org.tigris.helm.om.*;
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;
import org.tigris.helm.tool.MDACookie;
import org.tigris.helm.security.*;


public class ProjectDocumentList extends HelmServlet
{
    private static boolean debug = true;

    /**
     * The action key for downloading an existing file.
     */
    private static final String DO_DOWNLOAD = "download";

    /**
     * The database key of the document
     */
    private static final String DOCUMENT_ID = "dcID";


  protected String processRequest (Connection conn, WebContext ctx)
    throws HandlerException, RedirectException
  {
    String templateName = super.processRequest (conn, ctx);
    HttpServletRequest req = ctx.getRequest();
    String action = getAction(ctx);
    Project project = getCurrentProject(ctx);
    User user = getLoginUser(ctx);

    if (action.equals(DO_DOWNLOAD))
    {
       try
       {
           AccessControlList acl = user.getACL();
           // Authorize the download and redirect to the file server.
           String dcID = req.getParameter(DOCUMENT_ID);
           if (debug) Log.debug("dcID=" + dcID);
           ProjectDocument dc = (ProjectDocument)ProjectDocumentPeer.getInstance (dcID);
           authDownload (project, user, dc.isPublic(), req, ctx.getResponse ());
           String dcURL = req.  getScheme ()
             + "://"
             + myProperties.getProperty ("fileServer")
             + ((req.getServerPort () == 80 || req.getServerPort () == 443)
                 ? "" : ":" + req.getServerPort ())
             + "/files/documents/"
             + project.getID ()
             + '/' + dc.getProposedBy() + '/' + dc.getFileName();
           redirectToURL (ctx, dcURL);
        }

        catch (RedirectURLException e)
        {
          throw e;
        }

        catch (Exception e)
        {
          Log.error (e);
          throw new HandlerException (e.getMessage ());
        }
    }

    return templateName;
}

  /**
   * Cookies the user with a ticket that authorizes download of a specific
   * file.
   */
        private void authDownload (Project project, User user, 
                                   boolean isPublic,
                                   HttpServletRequest req,
                                   HttpServletResponse res)
     throws HandlerException
     {
       try
       {
	       MDACookie.write (myProperties.getProperty ("fileServer"), project,
		               	    user, isPublic, req, res);
       }
       catch (Exception e)
       {
            Log.error(e);
            throw new HandlerException(e.getMessage());
        }
     }
} /* end class ProjectDocumentList */
@


1.1.2.1
log
@ported to turbine
@
text
@a0 147
/* ================================================================
 * Copyright (c) 2000 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 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" name
 * nor may "Tigris" 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 CollabNet.
 */


package org.tigris.helm.project;

import java.io.*;
import java.sql.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.turbine.util.Log;
import org.webmacro.servlet.*;

import org.joist.security.*;

import org.tigris.helm.om.*;
import org.tigris.helm.om.peer.*;
import org.tigris.helm.tool.MDACookie;
import org.tigris.helm.security.*;


public class ProjectDocumentList extends HelmServlet
{
    private static boolean debug = true;

    /**
     * The action key for downloading an existing file.
     */
    private static final String DO_DOWNLOAD = "download";

    /**
     * The database key of the document
     */
    private static final String DOCUMENT_ID = "dcID";


  protected String processRequest (Connection conn, WebContext ctx)
    throws HandlerException, RedirectException
  {
    String templateName = super.processRequest (conn, ctx);
    HttpServletRequest req = ctx.getRequest();
    String action = getAction(ctx);
    Project project = getCurrentProject(ctx);
    User user = getLoginUser(ctx);

    if (action.equals(DO_DOWNLOAD))
    {
       try
       {
           AccessControlList acl = user.getACL();
           // Authorize the download and redirect to the file server.
           String dcID = req.getParameter(DOCUMENT_ID);
           if (debug) Log.debug("dcID=" + dcID);
           ProjectDocument dc = (ProjectDocument)ProjectDocumentPeer.getInstance (dcID);
           authDownload (project, user, dc.isPublic(), req, ctx.getResponse ());
           String dcURL = req.  getScheme ()
             + "://"
             + myProperties.getProperty ("fileServer")
             + ((req.getServerPort () == 80 || req.getServerPort () == 443)
                 ? "" : ":" + req.getServerPort ())
             + "/files/documents/"
             + project.getID ()
             + '/' + dc.getProposedBy() + '/' + dc.getFileName();
           redirectToURL (ctx, dcURL);
        }

        catch (RedirectURLException e)
        {
          throw e;
        }

        catch (Exception e)
        {
          Log.error (e);
          throw new HandlerException (e.getMessage ());
        }
    }

    return templateName;
}

  /**
   * Cookies the user with a ticket that authorizes download of a specific
   * file.
   */
        private void authDownload (Project project, User user, 
                                   boolean isPublic,
                                   HttpServletRequest req,
                                   HttpServletResponse res)
     throws HandlerException
     {
       try
       {
	       MDACookie.write (myProperties.getProperty ("fileServer"), project,
		               	    user, isPublic, req, res);
       }
       catch (Exception e)
       {
            Log.error(e);
            throw new HandlerException(e.getMessage());
        }
     }
} /* end class ProjectDocuments */
@


1.1.2.2
log
@Normalized copyright dates.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
@


1.1.2.3
log
@Added new imports necessitated by Torque.
@
text
@a61 1
import org.tigris.helm.om.base.*;
@


1.1.2.4
log
@minor name change
@
text
@d148 1
a148 1
} /* end class ProjectDocumentList */
@


