head	1.31;
access;
symbols
	TIGRIS_1_1_0RC2:1.15.6.4
	TIGRIS_1_1_0RC1:1.15.6.4
	TIGRIS_1_1:1.15.6.4.0.2
	TIGRIS_1_0_8:1.15.6.4
	TIGRIS_1_0_8RC3:1.15.6.4
	TIGRIS_1_0_8RC2:1.15.6.4
	TIGRIS_1_0_8RC1:1.15.6.4
	TIGRIS_1_0_7:1.15.6.4
	TIGRIS_1_0_7RC3:1.15.6.4
	TIGRIS_1_0_7RC2:1.15.6.4
	TIGRIS_1_0_7RC1:1.15.6.4
	TIGRIS_1_0_6:1.15.6.4
	TIGRIS_1_0_6RC5:1.15.6.4
	TIGRIS_1_0_6RC4:1.15.6.4
	TIGRIS_1_0_6RC3:1.15.6.4
	TIGRIS_1_0_6RC2:1.15.6.4
	TIGRIS_1_0_6RC1:1.15.6.4
	TIGRIS_1_0_5:1.15.6.1
	TIGRIS_1_0_5RC6:1.15.6.1
	TIGRIS_1_0_5RC5:1.15.6.1
	TIGRIS_1_0_5RC4:1.15.6.1
	TIGRIS_1_0_5RC3:1.15.6.1
	TIGRIS_1_0_5RC2:1.15.6.1
	TIGRIS_1_0_5RC1:1.15.6.1
	TIGRIS_1_0_4:1.15.6.1
	TIGRIS_1_0_3:1.15.6.1
	TIGRIS_1_0_2:1.15.6.1
	TIGRIS_1_0_1:1.15
	TIGRIS_1_0:1.15.0.6
	TIGRIS_1_0_0:1.15
	TIGRIS_1_0_0_RC1:1.15.0.2
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.3.2.1
	TIGRIS_0_9_2_3:1.3
	HELM_PEER_PORT_BRANCH:1.1.1.2
	TURBINE_PEER:1.8
	TIGRIS_0_9_2_1:1.8
	TIGRIS_0_9_2:1.3.0.2
	TIGRIS_0_9_0:1.1.1.1.0.4
	TIGRIS_0_8_4:1.1.1.1.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.31
date	2001.07.16.02.23.42;	author jrobbins;	state dead;
branches;
next	1.30;

1.30
date	2001.06.05.01.47.16;	author elicia;	state Exp;
branches;
next	1.29;

1.29
date	2001.06.04.01.32.45;	author dlr;	state Exp;
branches;
next	1.28;

1.28
date	2001.06.04.00.31.39;	author dlr;	state Exp;
branches;
next	1.27;

1.27
date	2001.06.03.23.31.22;	author dlr;	state Exp;
branches;
next	1.26;

1.26
date	2001.06.02.01.16.08;	author elicia;	state Exp;
branches;
next	1.25;

1.25
date	2001.06.02.00.14.21;	author dlr;	state Exp;
branches;
next	1.24;

1.24
date	2001.05.31.21.38.50;	author dlr;	state Exp;
branches;
next	1.23;

1.23
date	2001.05.31.21.37.39;	author dlr;	state Exp;
branches;
next	1.22;

1.22
date	2001.05.31.20.57.18;	author dlr;	state Exp;
branches;
next	1.21;

1.21
date	2001.05.31.19.12.28;	author elicia;	state Exp;
branches;
next	1.20;

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

1.19
date	2001.05.23.00.39.08;	author dlr;	state Exp;
branches;
next	1.18;

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

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

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

1.15
date	2001.03.08.03.53.49;	author dlr;	state Exp;
branches
	1.15.6.1;
next	1.14;

1.14
date	2001.02.21.01.08.23;	author dlr;	state Exp;
branches;
next	1.13;

1.13
date	2001.02.01.00.29.56;	author elicia;	state Exp;
branches;
next	1.12;

1.12
date	2001.01.31.00.20.33;	author elicia;	state Exp;
branches;
next	1.11;

1.11
date	2001.01.30.03.40.25;	author jrobbins;	state Exp;
branches;
next	1.10;

1.10
date	2001.01.30.02.37.47;	author elicia;	state Exp;
branches;
next	1.9;

1.9
date	2001.01.28.10.02.31;	author edk;	state Exp;
branches;
next	1.8;

1.8
date	2001.01.27.02.23.19;	author elicia;	state Exp;
branches
	1.8.2.1;
next	1.7;

1.7
date	2001.01.26.18.29.04;	author edk;	state Exp;
branches;
next	1.6;

1.6
date	2001.01.26.05.24.06;	author edk;	state dead;
branches;
next	1.5;

1.5
date	2001.01.26.02.01.31;	author elicia;	state Exp;
branches;
next	1.4;

1.4
date	2001.01.23.02.26.00;	author elicia;	state Exp;
branches;
next	1.3;

1.3
date	2001.01.17.18.33.43;	author elicia;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	2000.12.30.05.02.17;	author elicia;	state Exp;
branches;
next	1.1;

1.1
date	2000.11.12.21.15.59;	author dlr;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2000.11.12.21.15.59;	author dlr;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	2001.02.21.00.35.03;	author dlr;	state Exp;
branches;
next	;

1.3.2.1
date	2001.02.01.18.49.24;	author jrobbins;	state Exp;
branches;
next	;

1.8.2.1
date	2001.01.28.01.02.18;	author dlr;	state dead;
branches;
next	1.8.2.2;

1.8.2.2
date	2001.02.17.00.19.47;	author elicia;	state Exp;
branches;
next	1.8.2.3;

1.8.2.3
date	2001.02.17.00.40.16;	author elicia;	state Exp;
branches;
next	1.8.2.4;

1.8.2.4
date	2001.02.18.00.53.37;	author elicia;	state Exp;
branches;
next	1.8.2.5;

1.8.2.5
date	2001.02.20.01.24.12;	author dlr;	state Exp;
branches;
next	1.8.2.6;

1.8.2.6
date	2001.02.20.01.25.50;	author dlr;	state Exp;
branches;
next	1.8.2.7;

1.8.2.7
date	2001.02.20.23.44.17;	author elicia;	state Exp;
branches;
next	;

1.15.6.1
date	2001.04.24.20.57.40;	author dlr;	state Exp;
branches;
next	1.15.6.2;

1.15.6.2
date	2001.06.04.05.38.16;	author dlr;	state Exp;
branches;
next	1.15.6.3;

1.15.6.3
date	2001.06.04.05.48.06;	author dlr;	state Exp;
branches;
next	1.15.6.4;

1.15.6.4
date	2001.06.04.05.58.34;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.31
log
@factoring project documents out to project nidaba.tigris.org
@
text
@/* ================================================================
 * 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.util.*;
import java.io.*;
import java.net.InetAddress;
import java.net.URLEncoder;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.turbine.util.Log;
import org.apache.turbine.util.ParameterParser;
import org.apache.turbine.util.StringUtils;
import org.apache.turbine.util.TurbineException;
//import org.apache.turbine.util.upload.FileItem;
//import org.apache.turbine.services.upload.TurbineUpload;

import com.oreilly.servlet.*;
import com.oreilly.servlet.multipart.*;

import org.apache.velocity.context.Context;

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

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

public class ProjectDocumentAdd extends FileArtifactManipulate
{
    /**
     * The action which takes the user to the last step.
     */
    private static String SUBMIT_CHANGES_ACTION="Add Document";

    /**
     * The section name key.
     */
    private static final String DOCUMENT_NAME = "name";

    /**
     * The status key.
     */
    private static final String STATUS = "status";

    /**
     * The description key.
     */
    private static final String DESCRIPTION = "description";

    /**
     * The url where the document is located.
     */
    private static final String REMOTEURL = "url";

    /**
     * The text of the document.
     */
    private static final String TEXT = "text";

    /**
     * The public status of the document.
     */
    private static final String IS_PUBLIC = "isPublic";

    /**
     * The id of the section the document is filed under.
     */
    private static final String SECTION_ID = "rootSectionID";

    /**
     * Whether to log debugging information.
     */
    private static final boolean DEBUG = true;


    protected String processRequest(Context ctx)
        throws TurbineException, RedirectException
    {
        String templateName = super.processRequest(ctx);
    
        try
        {
            Project project = getCurrentProject(ctx);
            User user = getLoginUser(ctx);
            AccessControlList acl = user.getACL();
            String action = getAction(ctx);
            String name = null;
            String status = null;
            String descrip = null;
            String url = null;
            String text = null;
            String isPublic = null;
            ProjectSection section = null;

            String sectionID = ContextAPI.getParameter(ctx, SECTION_ID);
            if (!StringUtils.isValid(sectionID))
            {
                sectionID = "0";
            }

            if (!sectionID.equals("0"))
            {
                section = (ProjectSection)ProjectSectionPeer
                                          .getInstance(sectionID);
            }

            if (project == null)
            {
                redirectToError(ctx, "No project to add a document to " +
                                "specified");
                                
            }

            List missingFields = new ArrayList();
            List validationErrors = new ArrayList();

            if (DEBUG) Log.debug("action=" + action);
            if (action != null && action.equals(SUBMIT_CHANGES_ACTION))
            {
                ProjectDocument doc = null;
                File f = null;

                MultipartParser parser = 
                    new MultipartParser(ContextAPI.getRequest(ctx),
                                        getMaxPostSize());

                Part nextPart = parser.readNextPart();
                while (nextPart != null)
                {
                    if (nextPart.isParam())
                    {
                        String paramName = nextPart.getName();
                        String paramValue =
                            ((ParamPart)nextPart).getStringValue();

                        if (paramName.equals(DOCUMENT_NAME))
                            name = paramValue;
                        else if (paramName.equals(STATUS))
                            status =  paramValue;
                        else if (paramName.equals(DESCRIPTION))
                            descrip =  paramValue;
                        else if (paramName.equals(TEXT))
                            text =  paramValue;
                        else if (paramName.equals(REMOTEURL))
                            url =  paramValue;
                        else if (paramName.equals(IS_PUBLIC))
                            isPublic = paramValue;
                    }
                    else if (nextPart.isFile())
                    {
                        FilePart filePart = (FilePart) nextPart;
                        String fileName = filePart.getFileName();
                      
                        // File name is null when no file was uploaded.
                        if (fileName != null)
                        {
                            boolean validFileName = isValidFileName(fileName);

                            if (!validFileName)
                            {
                                validationErrors.add("Invalid file name '" +
                                                     fileName + '\'');
                            }

                            if (validFileName && haveValue(name))
                            {
                                // We have to add the document at this time to
                                // get its ID, which is in turn used as the
                                // final location of the uploaded file.
                                doc = ProjectDocument.add(acl, project, name,
                                                          status, descrip,
                                                          sectionID);

                                String fsPerms = myProperties.getProperty
                                    ("filesystemPermissions");
  
                                // Create path to file as
                                // [baseSaveDir]/[documentID]
                                String saveDir = getSaveDir(doc.getID());
                                File dir = new File(saveDir);
                                if (!dir.exists())
                                {
                                    dir.mkdirs();
                                }
                                if (DEBUG)
                                {
                                    Log.debug("saveDir= '" + saveDir +
                                              "' fsPerms= '" + fsPerms + '\'');
                                }
                                String fullPath = (saveDir + File.separatorChar 
                                                   + fileName);
                                f = new File(fullPath);

                                // Write file to filesystem
                                filePart.writeTo(f);
                                setFilesystemPermissions(fsPerms, fullPath);
                            }
                        }
                    }

                    nextPart = parser.readNextPart();
                }

                // Validate user input.
                if (!StringUtils.isValid(name))
                {
                    missingFields.add("Document name");
                }

                if (!StringUtils.isValid(status))
                {
                    missingFields.add("Document status");
                }

                if (!StringUtils.isEmpty(url) && !URL.hasProtocol(url))
                    validationErrors.add("Please provide a valid url.");

                if (doc == null)
                {
                    // Assure document content.
                    if ( (!StringUtils.isValid(url) || !URL.hasProtocol(url))
                         && StringUtils.isEmpty(text) )
                    {
                        missingFields.add("Either document URL or HTML " +
                                          "content must be provided");
                    }
                }

                // Do remaining processing.
                if (missingFields.isEmpty() && validationErrors.isEmpty())
                {
                    // Add the document or complete the processing of
                    // associated attachment.
                    if (doc != null)
                    { 
                        String htURL =
                            URL.schemeAndServer(ContextAPI.getRequest(ctx))
                            + "/servlets/"
                            + getArtifactListServletName(sectionID);
                        doc.edit(acl, name, status, descrip, url, text,
                                 sectionID, f, isPublic, htURL);
                    }
                    else
                    {
                        ProjectDocument.add (acl, project, name, 
                                             status, descrip,
                                             url, text, sectionID,
                                             isPublic);
                    }
                    redirectToURL(ctx, getArtifactListServletName());
                }
                else
                {
                    if (DEBUG)
                    {
                        Log.debug("ProjectDocuemntAdd: Invalid input");
                    }
                    reportInvalidUserInput(ctx, missingFields, 
                                           validationErrors);
                }
            }

            ctx.put("name", name != null ? name : "");
            ctx.put("status", status != null ? status : "");
            ctx.put("description", descrip != null ? descrip : "");
            ctx.put("url", url != null ? url : "");
            ctx.put("text", text != null ? text : "");
            if (isPublic != null) ctx.put(IS_PUBLIC, DBFlag.ON);
            ctx.put("section", section);
        }
        catch (RedirectException e)
        {
            throw e;
        }
        catch (Exception e)
        {
            Log.error(e);
            String msg = e.getMessage();
            appendToMessage(ctx, msg);
            throw new TurbineException(e);
        }
    
        return templateName;
    }

    protected final String getArtifactListServletName()
    {
        return "ProjectDocumentList";
    }

    protected final String getArtifactListServletName(String sectionID)
    {
        return ("ProjectDocumentList?rootSectionID=" + sectionID);
    }
}
@


1.30
log
@added more field validation
@
text
@@


1.29
log
@BaseHelmServlet's redirectToURL() method drops context data, which is
needed to pass along error messages and what not.  I played around
with removing redirectToURL() all together, but decided instead to
only call it when document addition is successful (which would've been
a necessary change in either case).
@
text
@d264 3
@


1.28
log
@Compensate for the fact that file name is null when no file is
uploaded.
@
text
@d296 1
a306 2

                redirectToURL(ctx, getArtifactListServletName(sectionID));
@


1.27
log
@Corrected broken input validation introduced by last commit and
expanded validation to cover document status and one of
file/url/content.
@
text
@d184 1
a196 1

d203 2
a204 3
                        boolean validFileName = isValidFileName(fileName);

                        if (!validFileName)
d206 1
a206 3
                            validationErrors.add("Invalid file name '" +
                                                 fileName + '\'');
                        }
d208 1
a208 16
                        if (validFileName && haveValue(name))
                        {
                            // We have to add the document at this time to get
                            // its ID, which is in turn used as the final
                            // location of the uploaded file.
                            doc = ProjectDocument.add(acl, project, name,
                                                      status, descrip,
                                                      sectionID);

                            String fsPerms = myProperties.getProperty
                                ("filesystemPermissions");
  
                            // Create path to file = [baseSaveDir]/[documentID]
                            String saveDir = getSaveDir(doc.getID());
                            File dir = new File(saveDir);
                            if (!dir.exists())
d210 2
a211 1
                                dir.mkdirs();
d213 2
a214 1
                            if (DEBUG)
d216 30
a245 2
                                Log.debug("saveDir= '" + saveDir +
                                          "' fsPerms= '" + fsPerms + '\'');
a246 7
                            String fullPath = (saveDir + File.separatorChar 
                                               + fileName);
                            f = new File(fullPath);

                            // Write file to filesystem
                            filePart.writeTo(f);
                            setFilesystemPermissions(fsPerms, fullPath);
@


1.26
log
@checking for valid URL field
@
text
@d248 2
a249 1
                if (!haveValue(name))
d251 1
a251 1
                    missingFields.add("Document Name");
d254 1
a254 2
                if (url != null && !url.equals("")
                     && !URL.hasProtocol(url))
d256 1
a256 1
                   validationErrors.add("Please provide a valid url.");
d259 10
d270 1
@


1.25
log
@Refactored to properly deny file names unprotectable by .htaccess files.
@
text
@d253 6
a258 2
                // TODO: Validate remaining fields to provide meaningful user
                // feedback.
@


1.24
log
@Use implicit StringBuffer.
@
text
@a142 3
            FilePart filePart = null;
            File f = null;
            ProjectDocument dc = null;
a161 1
            if (DEBUG) Log.debug("action=" + action);
d166 1
d169 2
a170 2
                String fsPerms = 
                    myProperties.getProperty("filesystemPermissions");
d178 1
a178 1
                { 
d182 2
a183 1
                        String paramValue = ((ParamPart)nextPart).getStringValue();
d197 4
a200 2
                    } else if (nextPart.isFile()) {
                        filePart = (FilePart)nextPart;
a201 2
                        if (fileName != null)
                        {
d203 1
a203 3
                        // We now have name, description, status
                        // Check for missing fields (name is only required
                        // field)
d205 2
a206 5
                        if (!haveValue(name))
                            missingFields.add("Document Name");


                        if (!isValidFileName(fileName))
d209 1
d211 1
a211 2
                        if (missingFields.isEmpty() &&
                            validationErrors.isEmpty())
d213 9
a221 4
                            // Add document
                            dc = ProjectDocument.add
                                    (acl, project, name, status, descrip,
                                     sectionID);
d224 1
a224 1
                            String saveDir = getSaveDir(dc.getID());
d226 4
a229 1
                            if (!dir.exists()) dir.mkdirs();
d243 1
d245 2
a246 6
                        } else {
                            // Report missing fields and errors
                            reportInvalidUserInput(ctx, missingFields, 
                                                   validationErrors);
                        }
                    } 
d248 15
a262 6
                    nextPart = parser.readNextPart();
                  }
                     
                  if (f != null && f.exists())
                  { 
                       String htURL =
d266 23
a288 11
                       dc.edit(acl, name, status, descrip, 
                               url, text, sectionID, f, isPublic, htURL);
                   } else {
                       ProjectDocument.add (acl, project, name, 
                                            status, descrip,
                                            url, text, sectionID,
                                            isPublic);
                   }
                    
                   redirectToURL(ctx, getArtifactListServletName(sectionID));
           } 
d312 1
a312 1
  
@


1.23
log
@Debug trace cleanup.
@
text
@d301 1
a301 4
        StringBuffer buf = new StringBuffer(
                           "ProjectDocumentList?rootSectionID=");
        buf.append(sectionID);
        return buf.toString();
@


1.22
log
@Super class was renamed.
@
text
@d229 5
a233 1
                               Log.debug(" saveDir= " +saveDir + " fsPerms= " + fsPerms);
d241 1
a241 1
                            }
@


1.21
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
@d77 1
a77 1
public class ProjectDocumentAdd extends ProjectFileArtifactAdd
@


1.20
log
@Ported Helm from WebMacro to Velocity.
@
text
@d59 1
d61 5
a65 2
import org.apache.turbine.util.upload.FileItem;
import org.apache.turbine.services.upload.TurbineUpload;
d69 1
a70 1
import org.joist.util.*;
d73 1
d90 1
a90 1
     * The description key.
d92 1
a92 1
    private static final String DESCRIPTION = "description";
d95 1
a95 1
     * The type key.
d97 1
a97 1
    private static final String TYPE = "type";
d110 5
d117 1
a117 1
    private static final String SECTION_ID = "sectionID";
d137 1
a138 1
            String type = null;
d141 3
a143 1
            String sectionID = "0";
d145 13
a168 1
            ctx.put("sectionID", sectionID);
a171 3
                File saveDir = new File
                    (project.getUploadDirectory(getBaseSaveDir(), user));
                if (!saveDir.exists()) saveDir.mkdirs();
d175 6
a180 24
                // TODO: Duplicate getMaxPostSize() and fsPerms functionality
                // using Turbine's UploadService interface.
                ParameterParser params =
                    ContextAPI.getRunData(ctx).getParameters();
                TurbineUpload.parseRequest(ContextAPI.getRequest(ctx), params,
                                           saveDir.getAbsolutePath());
                FileItem[] files = params.getFileItems(FILES_FIELD);
                boolean fileUploaded = (files != null && files.length > 0);

                name = params.getString(DOCUMENT_NAME);
                descrip = params.getString(DESCRIPTION);
                type = params.getString(TYPE);
                text = params.getString(TEXT);
                url = params.getString(REMOTEURL);
                sectionID = params.getString(SECTION_ID);

                // Check for missing fields and duplicate types
                if (!haveValue(name))
                    missingFields.add("Document Name");

                if (!haveValue(type))
                    missingFields.add
                        ("Document Contents: Click a button to choose.");
                else
d182 1
a182 1
                    if (type.equals("url"))
d184 53
a236 47
                        // User chose to enter remote url
                        if (url == null || url.equals (""))
                            missingFields.add (REMOTEURL);
                        if (!URL.hasProtocol(url))
                            validationErrors.add("Please provide a valid url");
                        if (!text.equals("") || !fileUploaded)
                        {
                            validationErrors.add
                                ("For document context, please fill in only " +
                                 "one of the three fields");
                        }
                    }
                    else if (type.equals("text"))
                    {
                        // User chose to enter document text
                        if (text == null || text.equals(""))
                        {
                            missingFields.add("Text");
                        }
                        if (!url.equals("") || !fileUploaded)
                        {
                            validationErrors.add
                                ("For document content, please fill in only " +
                                 "one of the three fields");
                        }
                    }
                    else
                    {
                        // User chose to upload file
                        if (!fileUploaded)
                        {
                            missingFields.add("Uploaded File");
                        }
                        else if (!url.equals("") || !text.equals(""))
                        {
                            validationErrors.add
                                ("For document context, please fill in only " +
                                 "one of the three fields");
                        }
                        else
                        {
                            // Process file upload
                            f = files[0].getStoreLocation();
                            if (!isValidFileName(f.getName()))
                            {
                                validationErrors.add("Invalid file name '" +
                                                     f.getName() + '\'');
a237 3
                        }
                    }
                }
d239 27
a265 32
                // HELP: Why is this block outside the catchall else "type"
                // block above?
                if (missingFields.isEmpty() && validationErrors.isEmpty())
                {
                    // Add document
                    String htURL = URL.schemeAndServer(getRequest(ctx))
                        + "/servlets/" + getArtifactListServletName();
                    String fileName = (f == null ? null : f.getName());
                    ProjectDocument artifact = ProjectDocumentPeer
                        .getInstanceByFileName(project, user, fileName);
                    if (artifact == null)
                    {
                        ProjectDocument.add(acl, project, name, descrip, type,
                                            f, url, text, sectionID, htURL);
                    }
                    else
                    {
                        // Replaced existing artifact file.
                        appendToMessage(ctx, fileName + 
                                        " was overwritten by your upload");
                        artifact.edit(acl, name, descrip, type, url, text,
                                      sectionID, f);
                    }
                    redirectToURL(ctx, getArtifactListServletName());
                } 
                else
                {
                    // Report missing fields and errors
                    reportInvalidUserInput(ctx, missingFields, 
                                           validationErrors);
                }
            } 
d268 1
d272 2
a273 2
            ctx.put("type", type != null ? type : "");
            ctx.put("sectionID", sectionID != null ? sectionID : "");
d293 8
@


1.19
log
@Check for valid file name (IZ #3588).
@
text
@d58 4
a61 1
import org.webmacro.servlet.*;
d63 1
a63 1
import com.oreilly.servlet.MultipartRequest;
d70 1
d115 2
a116 2
    protected String processRequest (Connection conn, WebContext ctx)
        throws HandlerException, RedirectException
d118 1
a118 1
        String templateName = super.processRequest(conn, ctx);
d154 15
a168 12
                FileUpload upload = 
                    new FileUpload(conn, ctx, getMaxPostSize(),
                                   saveDir.getAbsolutePath(), fsPerms);
                List files = upload.getFiles(); 

                MultipartRequest mreq = upload.getMultipartRequest();
                name = mreq.getParameter(DOCUMENT_NAME);
                descrip = mreq.getParameter(DESCRIPTION);
                type = mreq.getParameter(TYPE);
                text = mreq.getParameter(TEXT);
                url = mreq.getParameter(REMOTEURL);
                sectionID = mreq.getParameter(SECTION_ID);
d186 1
a186 1
                        if (!text.equals("") || !files.isEmpty())
d196 1
a196 1
                        if (text == null || text.equals (""))
d200 1
a200 1
                        if (!url.equals("") || !files.isEmpty())
d210 1
a210 1
                        if (upload.getFiles().isEmpty())
d223 1
a223 1
                            f = (File) upload.getFiles().get(0);
d238 1
a238 1
                    String htURL = URL.schemeAndServer(ctx)
d282 1
a282 1
            throw new HandlerException(msg);
@


1.18
log
@Leveraged getMaxPostSize() method I'm adding to ProjectFileArtifactAdd
super class which makes use of the new attribute stuff.
@
text
@d217 5
@


1.17
log
@* Removed commented out reference to FileUtility (whatever that is!).

* Cleaned up initial sanity for project.

* Reformatted type/file checks.

* Removed call to checkForOverwrite (and in fact, the entire
method. impl as well).  This now happens in the following block.

* Made use of ProjectDocumentPeer.getInstanceByFileName to determine
add vs. replace.
@
text
@a146 2
                int maxPostSize = Integer.parseInt
                    (myProperties.getProperty("maxPostSize"));
d151 1
a151 1
                    new FileUpload(conn, ctx, maxPostSize, 
@


1.16
log
@Extended abstract ProjectFileArtifactAdd servlet.
@
text
@a128 1
            //FileUtility fileUtil = new FileUtility();
d131 5
a135 1
                redirectToError(ctx, "ProjectDocumentAdd: No project specified");
d180 1
a180 1
                            validationErrors.add ("Please provide a valid url.");
d182 5
a186 1
                            validationErrors.add ("For document context, please fill in only one of the three fields.");
d192 3
a194 1
                            missingFields.add ("Text");
d196 5
a200 1
                            validationErrors.add ("For document content, please fill in only one of the three fields.");
d206 1
d208 1
d210 5
a214 1
                            validationErrors.add ("For document context, please fill in only one of the three fields.");
d218 1
a218 3
                            f = (File)upload.getFiles().get(0);
                            String fileName = f.getName().toString();
                            checkForOverwrite(conn, ctx, project, fileName);
d223 2
d230 16
a245 2
                    ProjectDocument.add(acl, project, name, descrip, 
                                        type, f, url, text, sectionID, htURL);
a277 30
    /**
     * Checks whether the upload overwrites a file by the same name.
     */
    private void checkForOverwrite(Connection conn, WebContext ctx,
                                   Project project, String fileName)
        throws ACLException, Exception
    {
        User user = getLoginUser(ctx);
        AccessControlList acl = user.getACL();

        List uploadedDocs = project.getDocuments();
        int nbrDocs = uploadedDocs.size();
        for (int i = 0; i < nbrDocs; i++)
        {
            ProjectDocument dc = (ProjectDocument)uploadedDocs.get(i);
            if (project.getID().equals(dc.getProject().getID()) &&
                acl.getUser().getUserId().equals(dc.getProposedBy()) &&
                fileName.equals(dc.getFileName()))
            {
                String htURL = URL.schemeAndServer(ctx)
                    + "/servlets/" + getArtifactListServletName();
                dc.delete(acl, false, htURL);
                appendToMessage(ctx, fileName + 
                                " was overwritten by your upload");
                break;
            }
        }

    }

@


1.15
log
@* Use equals() instead of == for SimpleKey instances.  Memory address
comparisons no longer work since primary key change from int to
ObjectKey.
* Switched to modern haveValue() call.
@
text
@d17 1
a17 1
 * software developed by Collab.Net (http://www.Collab.Net/)."
a46 1

a64 1
//import org.tigris.helm.tool.FileUtility;
d68 1
a68 1
public class ProjectDocumentAdd extends HelmServlet
a69 1

d210 1
a210 1
                                   + "/servlets/ProjectDocumentList";
d213 1
a213 1
                    redirectToURL(ctx, "ProjectDocumentList");
d265 1
a265 1
                               + "/servlets/ProjectDocumentList";
d275 1
a275 4
    /**
     * Macro to return the upload directory.
     */
    private final String getBaseSaveDir()
d277 1
a277 1
        return myProperties.getProperty("baseSaveDir");
@


1.15.6.1
log
@Refactored to not delete database entries, to make use of new ProjectFileArtifactAdd class, and to sync w/ changed APIs.
@
text
@d17 1
a17 1
 * software developed by Collab.Net (http://www.collab.net/)."
d47 1
d66 1
d70 1
a70 1
public class ProjectDocumentAdd extends ProjectFileArtifactAdd
d72 1
d132 1
d135 1
a135 5
            {
                redirectToError(ctx, "No project to add a document to " +
                                "specified");
                                
            }
d180 1
a180 1
                            validationErrors.add("Please provide a valid url");
d182 1
a182 5
                        {
                            validationErrors.add
                                ("For document context, please fill in only " +
                                 "one of the three fields");
                        }
d188 1
a188 3
                        {
                            missingFields.add("Text");
                        }
d190 1
a190 5
                        {
                            validationErrors.add
                                ("For document content, please fill in only " +
                                 "one of the three fields");
                        }
a195 1
                        {
a196 1
                        }
d198 1
a198 5
                        {
                            validationErrors.add
                                ("For document context, please fill in only " +
                                 "one of the three fields");
                        }
d202 3
a204 1
                            f = (File) upload.getFiles().get(0);
a208 2
                // HELP: Why is this block outside the catchall else "type"
                // block above?
d213 4
a216 18
                        + "/servlets/" + getArtifactListServletName();
                    String fileName = (f == null ? null : f.getName());
                    ProjectDocument artifact = ProjectDocumentPeer
                        .getInstanceByFileName(project, user, fileName);
                    if (artifact == null)
                    {
                        ProjectDocument.add(acl, project, name, descrip, type,
                                            f, url, text, sectionID, htURL);
                    }
                    else
                    {
                        // Replaced existing artifact file.
                        appendToMessage(ctx, fileName + 
                                        " was overwritten by your upload");
                        artifact.edit(acl, name, descrip, type, url, text,
                                      sectionID, f);
                    }
                    redirectToURL(ctx, getArtifactListServletName());
d248 34
a281 1
    protected final String getArtifactListServletName()
d283 1
a283 1
        return "ProjectDocumentList";
@


1.15.6.2
log
@ProjectFileArtifactAdd renamed to FileArtifactManipulate--changed
super class as appropriate.
@
text
@d68 1
a68 1
public class ProjectDocumentAdd extends FileArtifactManipulate
@


1.15.6.3
log
@Validate the file name as per the new rules.
@
text
@a218 6
                            String fileName = f.getName();
                            if (!isValidFileName(fileName))
                            {
                                validationErrors.add("Invalid file name '" +
                                                     fileName + '\'');
                            }
@


1.15.6.4
log
@Delete the upload that was written to disk if there is an input
validation problem.
@
text
@a57 1

a223 1
                                f.delete();
@


1.14
log
@This is the highest revision from the HELM_PEER_PORT_BRANCH.  The previous import caused too many conflicts to resolve manually
@
text
@d166 2
a167 2
	            if (name == null || name.equals (""))
	                missingFields.add ("Document Name");
d169 3
a171 2
	            if (type == null || type.equals (""))
	                missingFields.add ("Document Contents: Click a button to choose.");
d264 1
a264 1
                acl.getUser().getUserId() == dc.getProposedBy() &&
@


1.13
log
@passing context to Document to determine url for .htaccess file
@
text
@d58 1
a58 1
import org.webmacro.util.Log;
a62 1
import org.tigris.helm.security.HelmServlet;
a63 1
import org.joist.database.DataManager;
d66 2
a68 3
import org.tigris.helm.domain.User;
//import org.tigris.helm.tool.FileUtility;
import org.tigris.helm.project.Project;
a71 1
    public static final  String versionID = "$Id: ProjectDocumentAdd.java,v 1.12 2001/01/31 00:20:33 elicia Exp $";
a107 4
    /** Open the log file.
     */
    private static Log log = new Log("projDocAdd", "ProjectDocumentAdd");

d111 1
a111 1
    private static boolean debug = true;
a116 1
        if (debug) log.info("started");
d123 1
a123 1
            AccessControlList acl = getACL(ctx, conn);
d130 1
a130 1
            String sectionID = null;
d136 1
a136 1
            if (debug) log.info("action=" + action);
d140 1
d176 2
a177 2
	                    if (url == null || url.equals (""))
	                        missingFields.add (REMOTEURL);
d186 2
a187 2
	                    if (text == null || text.equals (""))
	                       missingFields.add ("Text");
d189 1
a189 1
                           validationErrors.add ("For document content, please fill in only one of the three fields.");
d203 1
a203 2
                            checkForOverwrite(conn, ctx, project, 
                                              fileName);
d212 4
a215 4
                                   + "/servlets/ProjectDocuments";
                    project.addDocument(acl, name, descrip, type, f, url, 
                                        text, sectionID, htURL);
                    redirectToURL(ctx, "ProjectDocuments");
d238 1
a238 1
            log.exception(e);
d250 2
a251 2
    private void checkForOverwrite (Connection conn, WebContext ctx,
                                    Project project, String fileName)
d254 2
a255 1
        AccessControlList acl = getACL(ctx, conn);
d261 4
a264 4
            Document dc = (Document)uploadedDocs.get(i);
            if (project.getID().equals(dc.getProjectID()) &&
                acl.getUserID().equals(dc.getSuggestedBy().getID()) &&
                fileName.equals(dc.getFilename()))
d266 3
a268 1
                dc.delete(acl, false, ctx);
d280 1
a280 1
    private final String getBaseSaveDir ()
d284 1
a284 2

} /* end class ProjectDocumentAdd */
@


1.12
log
@added url for .htaccess file
@
text
@d75 1
a75 1
    public static final  String versionID = "$Id: ProjectDocumentAdd.java,v 1.11 2001/01/30 03:40:25 jrobbins Exp $";
a139 1
            String htURL = URL.schemeAndServer(ctx) + "/servlets/ProjectDocuments";
d212 1
a212 1
                                              fileName, htURL);
d220 2
d260 1
a260 2
                                    Project project, String fileName,
                                    String htURL)
d274 1
a274 1
                dc.delete(acl, false, htURL);
@


1.11
log
@filled in missing argument to make this code compile
@
text
@d75 1
a75 1
    public static final  String versionID = "$Id: ProjectDocumentAdd.java,v 1.10 2001/01/30 02:37:47 elicia Exp $";
d212 2
a213 1
                            checkForOverwrite(conn, ctx, project, fileName);
d259 2
a260 1
                                    Project project, String fileName)
d274 1
a274 1
                dc.delete(acl, false, null);
@


1.10
log
@putting pre=error entered values into the context
@
text
@d75 1
a75 1
    public static final  String versionID = "$Id: ProjectDocumentAdd.java,v 1.9 2001/01/28 10:02:31 edk Exp $";
d272 1
a272 1
                dc.delete(acl, false);
@


1.9
log
@comment out code which references FileUtility, since that file hasn't
been added to cvs yet.
@
text
@d75 1
a75 1
    public static final  String versionID = "$Id: ProjectDocumentAdd.java,v 1.8 2001/01/27 02:23:19 elicia Exp $";
d107 5
a136 1
            File f = null;
d141 2
a142 1
//            FileUtility fileUtil = new FileUtility();
d164 1
d172 1
a172 2
                sectionID = mreq.getParameter("section_id");
                List files = upload.getFiles(); 
d184 1
d194 1
d202 1
d209 1
d212 1
a212 1
//                            fileUtil.checkForOverwrite(project, acl.getUserID(), fileName);
d226 3
a228 3
                    // Report missing fields 
                    appendToMessage (ctx, "Missing Fields", missingFields);
                    appendToMessage (ctx, "Validation Errors", validationErrors);
d232 6
a237 6
        ctx.put("name", name != null ? name : "");
        ctx.put("description", descrip != null ? descrip : "");
        ctx.put("url", url != null ? url : "");
        ctx.put("text", text != null ? text : "");
        ctx.put("type", type != null ? type : "");
        ctx.put("sectionID", sectionID != null ? sectionID : "");
d258 1
a258 1
                                    Project project, File f)
a261 1
        String fileName = f.getName().toString();
@


1.8
log
@added validation checking for urls
@
text
@d70 1
a70 1
import org.tigris.helm.tool.FileUtility;
d75 1
a75 1
    public static final  String versionID = "$Id: ProjectDocumentAdd.java,v 1.5 2001/01/26 02:01:31 elicia Exp $";
d137 1
a137 1
            FileUtility fileUtil = new FileUtility();
d203 1
a203 1
                            fileUtil.checkForOverwrite(project, acl.getUserID(), fileName);
@


1.8.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d75 1
a75 1
    public static final  String versionID = "$Id: ProjectDocumentAdd.java,v 1.8 2001/01/27 02:23:19 elicia Exp $";
@


1.8.2.2
log
@ported to turbine
@
text
@d58 1
a58 1
import org.apache.turbine.util.Log;
d63 1
d65 1
a67 2
//import org.tigris.helm.tool.FileUtility;
import org.tigris.helm.om.*;
d69 3
d75 1
d107 1
a107 2
    /**
     * The id of the section the document is filed under.
d109 1
a109 1
    private static final String SECTION_ID = "section_id";
d120 1
a120 1
        if (debug) Log.debug("started");
d127 1
a127 1
            AccessControlList acl = user.getACL();
d132 1
d136 2
a137 2
            File f = null;
            //FileUtility fileUtil = new FileUtility();
d141 1
a141 1
            if (debug) Log.debug("action=" + action);
a158 1
                List files = upload.getFiles(); 
d166 2
a167 1
                sectionID = mreq.getParameter(SECTION_ID);
a178 1
                        // User chose to enter remote url
a187 1
                        // User chose to enter document text
a194 1
                        // User chose to upload file
a200 1
                            // Process file upload
d203 1
a203 2
                            checkForOverwrite(conn, ctx, project, 
                                              fileName);
d211 3
a213 5
                    String htURL = URL.schemeAndServer(ctx)
                                   + "/servlets/ProjectDocumentList";
                    ProjectDocument.add(acl, project, name, descrip, 
                                        type, f, url, text, sectionID, htURL);
                    redirectToURL(ctx, "ProjectDocumentList");
d217 3
a219 3
                    // Report missing fields and errors
                    reportInvalidUserInput(ctx, missingFields, 
                                           validationErrors);
d223 6
a228 6
            ctx.put("name", name != null ? name : "");
            ctx.put("description", descrip != null ? descrip : "");
            ctx.put("url", url != null ? url : "");
            ctx.put("text", text != null ? text : "");
            ctx.put("type", type != null ? type : "");
            ctx.put("sectionID", sectionID != null ? sectionID : "");
d236 1
a236 1
            Log.error(e);
d249 1
a249 1
                                    Project project, String fileName)
d252 2
a253 2
        User user = getLoginUser(ctx);
        AccessControlList acl = user.getACL();
d259 4
a262 4
            ProjectDocument dc = (ProjectDocument)uploadedDocs.get(i);
            if (project.getID().equals(dc.getProject().getID()) &&
                acl.getUser().getUserId() == dc.getProposedBy() &&
                fileName.equals(dc.getFileName()))
d264 1
a264 1
                dc.delete(acl, false, ctx);
@


1.8.2.3
log
@passing URL to which to write .htaccess file
@
text
@d267 1
a267 3
                String htURL = URL.schemeAndServer(ctx)
                               + "/servlets/ProjectDocumentList";
                dc.delete(acl, false, htURL);
@


1.8.2.4
log
@changed name of sectionID key
@
text
@d106 1
a106 1
    private static final String SECTION_ID = "sectionID";
@


1.8.2.5
log
@Clean up.
@
text
@d111 1
a111 1
    private static final boolean DEBUG = true;
d117 1
d137 1
a137 1
            if (DEBUG) Log.debug("action=" + action);
d176 2
a177 2
                        if (url == null || url.equals (""))
                            missingFields.add (REMOTEURL);
d186 2
a187 2
                        if (text == null || text.equals (""))
                            missingFields.add ("Text");
d189 1
a189 1
                            validationErrors.add ("For document content, please fill in only one of the three fields.");
d251 2
a252 2
    private void checkForOverwrite(Connection conn, WebContext ctx,
                                   Project project, String fileName)
d281 1
a281 1
    private final String getBaseSaveDir()
d285 2
a286 1
}
@


1.8.2.6
log
@Further minor clean up.
@
text
@d202 2
a203 1
                            checkForOverwrite(conn, ctx, project, fileName);
@


1.8.2.7
log
@gave template a starting value for section ID
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d130 1
a130 1
            String sectionID = "0";
a139 1
            ctx.put("sectionID", sectionID);
@


1.7
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d70 1
d75 1
a75 1
    public static final  String versionID = "$Id: ProjectDocumentAdd.java,v 1.4 2001/01/23 02:26:00 elicia Exp $";
d137 1
d180 3
a182 1
	                        missingFields.add ("REMOTEURL");
d202 2
a203 1
                            checkForOverwrite(conn, ctx, project, f);
d228 1
@


1.6
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
@a69 1
import org.tigris.helm.tool.FileUtility;
d74 1
a74 1
    public static final  String versionID = "$Id: ProjectDocumentAdd.java,v 1.5 2001/01/26 02:01:31 elicia Exp $";
a135 1
            FileUtility fileUtil = new FileUtility();
d178 1
a178 3
	                        missingFields.add (REMOTEURL);
                        if (!URL.hasProtocol(url))
                            validationErrors.add ("Please provide a valid url.");
d198 1
a198 2
                            String fileName = f.getName().toString();
                            fileUtil.checkForOverwrite(project, acl.getUserID(), fileName);
@


1.5
log
@no longer passing connection
@
text
@d75 1
a75 1
    public static final  String versionID = "$Id: ProjectDocumentAdd.java,v 1.4 2001/01/23 02:26:00 elicia Exp $";
@


1.4
log
@added error checking for missing fields, or if user tries to provide more than one location for the file

enabled checking to see if this file is overwriting an old one
@
text
@d70 1
d75 1
a75 1
    public static final  String versionID = "$Id: ProjectDocumentAdd.java,v 1.3 2001/01/17 18:33:43 elicia Exp $";
d137 1
d180 3
a182 1
	                        missingFields.add ("REMOTEURL");
d202 2
a203 1
                            checkForOverwrite(conn, ctx, project, f);
@


1.3
log
@added upload capability
@
text
@d53 1
d74 1
a74 1
    public static final  String versionID = "$Id: ProjectDocumentAdd.java,v 1.2 2000/12/30 05:02:17 elicia Exp $";
d92 1
a92 1
     * The location key.
d94 1
a94 1
    private static final String LOCATION = "location";
d99 1
a99 1
    private static final String URL = "url";
d130 2
a131 2
            String location = null;
            String fileName = null;
d135 1
d142 1
a145 1
                log.info("base save dir" + getBaseSaveDir());
d157 1
d161 3
d165 1
a165 1
                location = mreq.getParameter("location");
d167 1
a167 1
                // Check for missing fields
d171 2
a172 2
	            if (location == null || location.equals (""))
	                missingFields.add ("Document Contexts: Click a button to choose.");
d175 26
a200 5
                if (location.equals("url"))
                {
                   url = mreq.getParameter(URL);
	               if (url == null || url.equals (""))
	                  missingFields.add ("URL");
d202 2
a203 18
                else if (location.equals("text"))
                {
                   text = mreq.getParameter(TEXT);
	               if (text == null || text.equals (""))
	                  missingFields.add ("Text");
                }
                else
                {
                   if (upload.getFiles().isEmpty())
                   {
                       missingFields.add("Uploaded File");
                   } else {
                       File f = (File)upload.getFiles().get(0);
                       fileName = f.getName().toString();
                   }
                }
             }
                if (missingFields.isEmpty())
d206 3
a208 4
                    project.addDocument(acl, name, descrip,
                                        location, url, text, 
                                        sectionID);
                    //redirectToURL(ctx, "ProjectDocuments");
d214 1
d222 1
a222 1
        ctx.put("location", location != null ? location : "");
d240 1
a240 1
     * Processes a single uploaded file.
d242 2
a243 2
    private void processUpload (Connection conn, WebContext ctx,
                                Project project, File fileToAdd)
d247 1
a247 2
        /*
        String url = URL.schemeAndServer(ctx) + "/servlets/ProjectDownload";
d249 1
a249 5
        // Check for overwritten files.
        String fileName = fileToAdd.getName();
        String filePath = Document.extractLocation(fileToAdd);
        if (debug) log.info("fileName=" + fileName);
        List uploadedDocs = project.getUploadedDocs();
d254 3
a256 3
            if (debug) log.info("dc.getName()=" + dc.getName());
            if (filePath.equals(dc.getLocation()) &&
                fileName.equals(dc.getName()))
d258 1
a258 3
                // The file has already been overwritten--no need to delete it
                // from disk.                
                dc.delete(acl, url, false);
a263 1
        */
@


1.3.2.1
log
@moved changed from HEAD for ProjectDocuments and ProjectDownloads
@
text
@a52 1
import java.net.URLEncoder;
a68 1
//import org.tigris.helm.tool.FileUtility;
d73 1
a73 1
    public static final  String versionID = "$Id: ProjectDocumentAdd.java,v 1.13 2001/02/01 00:29:56 elicia Exp $";
d91 1
a91 1
     * The type key.
d93 1
a93 1
    private static final String TYPE = "type";
d98 1
a98 1
    private static final String REMOTEURL = "url";
a104 5
    /**
     * The id of the section the document is filed under.
     */
    private static final String SECTION_ID = "sectionID";

d129 2
a130 1
            String type = null;
a133 2
            File f = null;
            //FileUtility fileUtil = new FileUtility();
a139 1
            List validationErrors = new ArrayList();
d143 1
a154 2
                List files = upload.getFiles(); 

d158 2
a159 4
                type = mreq.getParameter(TYPE);
                text = mreq.getParameter(TEXT);
                url = mreq.getParameter(REMOTEURL);
                sectionID = mreq.getParameter(SECTION_ID);
d161 1
a161 1
                // Check for missing fields and duplicate types
d165 2
a166 2
	            if (type == null || type.equals (""))
	                missingFields.add ("Document Contents: Click a button to choose.");
d169 5
a173 34
                    if (type.equals("url"))
                    {
                        // User chose to enter remote url
	                    if (url == null || url.equals (""))
	                        missingFields.add (REMOTEURL);
                        if (!URL.hasProtocol(url))
                            validationErrors.add ("Please provide a valid url.");
                        if (!text.equals("") || !files.isEmpty())
                            validationErrors.add ("For document context, please fill in only one of the three fields.");
                    }
                    else if (type.equals("text"))
                    {
                        // User chose to enter document text
	                    if (text == null || text.equals (""))
	                       missingFields.add ("Text");
                        if (!url.equals("") || !files.isEmpty())
                           validationErrors.add ("For document content, please fill in only one of the three fields.");
                    }
                    else
                    {
                        // User chose to upload file
                        if (upload.getFiles().isEmpty())
                            missingFields.add("Uploaded File");
                        else if (!url.equals("") || !text.equals(""))
                            validationErrors.add ("For document context, please fill in only one of the three fields.");
                        else
                        {
                            // Process file upload
                            f = (File)upload.getFiles().get(0);
                            String fileName = f.getName().toString();
                            checkForOverwrite(conn, ctx, project, 
                                              fileName);
                        }
                    }
d175 18
a192 2

                if (missingFields.isEmpty() && validationErrors.isEmpty())
d195 4
a198 5
                    String htURL = URL.schemeAndServer(ctx)
                                   + "/servlets/ProjectDocuments";
                    project.addDocument(acl, name, descrip, type, f, url, 
                                        text, sectionID, htURL);
                    redirectToURL(ctx, "ProjectDocuments");
d202 2
a203 3
                    // Report missing fields and errors
                    reportInvalidUserInput(ctx, missingFields, 
                                           validationErrors);
d207 5
a211 6
            ctx.put("name", name != null ? name : "");
            ctx.put("description", descrip != null ? descrip : "");
            ctx.put("url", url != null ? url : "");
            ctx.put("text", text != null ? text : "");
            ctx.put("type", type != null ? type : "");
            ctx.put("sectionID", sectionID != null ? sectionID : "");
d229 1
a229 1
     * Checks whether the upload overwrites a file by the same name.
d231 2
a232 2
    private void checkForOverwrite (Connection conn, WebContext ctx,
                                    Project project, String fileName)
d236 2
d239 5
a243 1
        List uploadedDocs = project.getDocuments();
d248 3
a250 3
            if (project.getID().equals(dc.getProjectID()) &&
                acl.getUserID().equals(dc.getSuggestedBy().getID()) &&
                fileName.equals(dc.getFilename()))
d252 3
a254 1
                dc.delete(acl, false, ctx);
d260 1
@


1.2
log
@made functional
@
text
@d51 2
d60 2
d65 1
d68 2
d73 1
a73 1
    public static final  String versionID = "$Id: ProjectDocumentSectionAdd.java,v 1.1.1.1 2000/11/12 21:16:02 dlr Exp $";
d123 2
a124 1
            Project currentProject = getCurrentProject(ctx);
d127 7
d135 1
a135 1
            if (currentProject == null)
a136 1

a139 10
            List validationErrors = new ArrayList();
            String name = processField(ctx, DOCUMENT_NAME,
                                       "Section Name",
                                        missingFields);

            String location = processField(ctx, LOCATION);
            String url = processField(ctx, URL);
            String text = processField(ctx, TEXT);
            String descrip = processField(ctx, DESCRIPTION);
            String sectionID = ctx.getForm("section_id");
d143 33
a175 1
                if (isValidUserInput(missingFields, validationErrors))
d177 3
a179 8
                    // Add section
                    currentProject.addDocument(acl, name, location, 
                                               descrip, sectionID);
                    redirectToURL(ctx, "ProjectDocuments");
                } else {
                    // Report missing fields and validation errors.
                    reportInvalidUserInput(ctx, missingFields,
                                           validationErrors);
d181 31
a211 1
            }
d228 44
@


1.1
log
@Initial revision
@
text
@a49 1
import java.io.*;
d55 1
a55 1
import org.webmacro.util.*;
a56 7
import org.webmacro.engine.*;
import org.webmacro.broker.*;
import org.webmacro.resource.*;

import org.joist.*;
import org.joist.util.*;
import org.joist.session.*;
d62 1
d64 3
d68 9
d78 9
a86 4
public class ProjectDocumentAdd extends org.tigris.helm.security.HelmServlet {
    public static final  String versionID = "$Id: ProjectDocumentAdd.java,v 1.4 2000/11/06 06:15:31 edk Exp $";
    private static Log log = new Log("ProjectDocumentAdd", "Tigris StartPage");
    private static boolean debug = true;
d89 1
a89 1
     *  Display and process the login screen.
d91 1
a91 5
    protected String
	processRequest (Connection connection, WebContext context)
	throws HandlerException, RedirectException
    {
	if (debug) log.debug("ProjectDocumentAdd: started!");
d93 4
a96 2
	String templateName = super.processRequest(connection, context);
	
d98 3
a100 1
	if (debug) log.debug("ProjectDocumentAdd: step 1");
d102 4
a105 27
	HttpServletRequest request = context.getRequest();
	HttpServletResponse response = context.getResponse();
	HttpSession session = context.getSession();
	SessionManager sMgr = getSessionManager(context);
	DataManager dMgr = sMgr.getDataManager();

	if (debug) log.debug("ProjectDocumentAdd: step 2");

	String action = (String)context.get("action");

        if (debug) log.debug("ProjectDocumentAdd: step 3");

	try {
	    String userID = sMgr.getUserID();
	    if (debug) log.debug("ProjectDocumentAdd: userID=" + userID );
	    String loginID = sMgr.getLoginID();
	    context.put("loginID", loginID);
	    if (debug) log.debug("ProjectDocumentAdd: loginID=" + loginID );
	}
	catch (Exception e) {
	    log.exception(e);
	    String message = "ProjectDocumentAdd: " + e.getMessage();
	    if (debug) log.debug(message);
	    context.put("message", message);
	}	
	
	if (debug) log.debug("ProjectDocumentAdd: action=" + action );
a106 1
	if (debug) log.debug("ProjectDocumentAdd:  done");
d108 56
@


1.1.1.1
log
@Merging newhelm tree into helm, as per IZ issue #557.  Previous major version of helm is tagged TIGRIS_NOV_11_2000.
@
text
@@


1.1.1.2
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@d50 1
a51 3
import java.io.*;
import java.net.InetAddress;
import java.net.URLEncoder;
d56 1
a56 1
import org.apache.turbine.util.Log;
d58 3
d62 3
a64 1
import com.oreilly.servlet.MultipartRequest;
d66 1
d68 1
a68 1
import org.joist.util.*;
a69 3
//import org.tigris.helm.tool.FileUtility;
import org.tigris.helm.om.*;
import org.tigris.helm.security.*;
a70 2
public class ProjectDocumentAdd extends HelmServlet
{
a71 4
    /**
     * The action which takes the user to the last step.
     */
    private static String SUBMIT_CHANGES_ACTION="Add Document";
d73 4
a76 4
    /**
     * The section name key.
     */
    private static final String DOCUMENT_NAME = "name";
d79 1
a79 1
     * The description key.
d81 5
a85 1
    private static final String DESCRIPTION = "description";
d87 2
a88 4
    /**
     * The type key.
     */
    private static final String TYPE = "type";
d90 1
a90 4
    /**
     * The url where the document is located.
     */
    private static final String REMOTEURL = "url";
d92 27
a118 4
    /**
     * The text of the document.
     */
    private static final String TEXT = "text";
d120 1
a120 4
    /**
     * The id of the section the document is filed under.
     */
    private static final String SECTION_ID = "sectionID";
a121 136
    /**
     * Whether to log debugging information.
     */
    private static final boolean DEBUG = true;


    protected String processRequest (Connection conn, WebContext ctx)
        throws HandlerException, RedirectException
    {
        String templateName = super.processRequest(conn, ctx);
    
        try
        {
            Project project = getCurrentProject(ctx);
            User user = getLoginUser(ctx);
            AccessControlList acl = user.getACL();
            String action = getAction(ctx);
            String name = null;
            String descrip = null;
            String type = null;
            String url = null;
            String text = null;
            String sectionID = "0";
            File f = null;
            //FileUtility fileUtil = new FileUtility();

            if (project == null)
                redirectToError(ctx, "ProjectDocumentAdd: No project specified");
            if (DEBUG) Log.debug("action=" + action);

            List missingFields = new ArrayList();
            List validationErrors = new ArrayList();
            ctx.put("sectionID", sectionID);

            if (action != null && action.equals(SUBMIT_CHANGES_ACTION))
            {
                File saveDir = new File
                    (project.getUploadDirectory(getBaseSaveDir(), user));
                if (!saveDir.exists()) saveDir.mkdirs();
                int maxPostSize = Integer.parseInt
                    (myProperties.getProperty("maxPostSize"));
                String fsPerms = 
                    myProperties.getProperty("filesystemPermissions");

                FileUpload upload = 
                    new FileUpload(conn, ctx, maxPostSize, 
                                   saveDir.getAbsolutePath(), fsPerms);
                List files = upload.getFiles(); 

                MultipartRequest mreq = upload.getMultipartRequest();
                name = mreq.getParameter(DOCUMENT_NAME);
                descrip = mreq.getParameter(DESCRIPTION);
                type = mreq.getParameter(TYPE);
                text = mreq.getParameter(TEXT);
                url = mreq.getParameter(REMOTEURL);
                sectionID = mreq.getParameter(SECTION_ID);

                // Check for missing fields and duplicate types
	            if (name == null || name.equals (""))
	                missingFields.add ("Document Name");

	            if (type == null || type.equals (""))
	                missingFields.add ("Document Contents: Click a button to choose.");
                else
                { 
                    if (type.equals("url"))
                    {
                        // User chose to enter remote url
                        if (url == null || url.equals (""))
                            missingFields.add (REMOTEURL);
                        if (!URL.hasProtocol(url))
                            validationErrors.add ("Please provide a valid url.");
                        if (!text.equals("") || !files.isEmpty())
                            validationErrors.add ("For document context, please fill in only one of the three fields.");
                    }
                    else if (type.equals("text"))
                    {
                        // User chose to enter document text
                        if (text == null || text.equals (""))
                            missingFields.add ("Text");
                        if (!url.equals("") || !files.isEmpty())
                            validationErrors.add ("For document content, please fill in only one of the three fields.");
                    }
                    else
                    {
                        // User chose to upload file
                        if (upload.getFiles().isEmpty())
                            missingFields.add("Uploaded File");
                        else if (!url.equals("") || !text.equals(""))
                            validationErrors.add ("For document context, please fill in only one of the three fields.");
                        else
                        {
                            // Process file upload
                            f = (File)upload.getFiles().get(0);
                            String fileName = f.getName().toString();
                            checkForOverwrite(conn, ctx, project, fileName);
                        }
                    }
                }

                if (missingFields.isEmpty() && validationErrors.isEmpty())
                {
                    // Add document
                    String htURL = URL.schemeAndServer(ctx)
                                   + "/servlets/ProjectDocumentList";
                    ProjectDocument.add(acl, project, name, descrip, 
                                        type, f, url, text, sectionID, htURL);
                    redirectToURL(ctx, "ProjectDocumentList");
                } 
                else
                {
                    // Report missing fields and errors
                    reportInvalidUserInput(ctx, missingFields, 
                                           validationErrors);
                }
            } 

            ctx.put("name", name != null ? name : "");
            ctx.put("description", descrip != null ? descrip : "");
            ctx.put("url", url != null ? url : "");
            ctx.put("text", text != null ? text : "");
            ctx.put("type", type != null ? type : "");
            ctx.put("sectionID", sectionID != null ? sectionID : "");
        }
        catch (RedirectException e)
        {
            throw e;
        }
        catch (Exception e)
        {
            Log.error(e);
            String msg = e.getMessage();
            appendToMessage(ctx, msg);
            throw new HandlerException(msg);
        }
    
d125 1
a125 38
    /**
     * Checks whether the upload overwrites a file by the same name.
     */
    private void checkForOverwrite(Connection conn, WebContext ctx,
                                   Project project, String fileName)
        throws ACLException, Exception
    {
        User user = getLoginUser(ctx);
        AccessControlList acl = user.getACL();

        List uploadedDocs = project.getDocuments();
        int nbrDocs = uploadedDocs.size();
        for (int i = 0; i < nbrDocs; i++)
        {
            ProjectDocument dc = (ProjectDocument)uploadedDocs.get(i);
            if (project.getID().equals(dc.getProject().getID()) &&
                acl.getUser().getUserId() == dc.getProposedBy() &&
                fileName.equals(dc.getFileName()))
            {
                String htURL = URL.schemeAndServer(ctx)
                               + "/servlets/ProjectDocumentList";
                dc.delete(acl, false, htURL);
                appendToMessage(ctx, fileName + 
                                " was overwritten by your upload");
                break;
            }
        }

    }

    /**
     * Macro to return the upload directory.
     */
    private final String getBaseSaveDir()
    {
        return myProperties.getProperty("baseSaveDir");
    }
}
@

