head	1.23;
access;
symbols
	TIGRIS_1_1_0RC2:1.15.6.1
	TIGRIS_1_1_0RC1:1.15.6.1
	TIGRIS_1_1:1.15.6.1.0.2
	TIGRIS_1_0_8:1.15.6.1
	TIGRIS_1_0_8RC3:1.15.6.1
	TIGRIS_1_0_8RC2:1.15.6.1
	TIGRIS_1_0_8RC1:1.15.6.1
	TIGRIS_1_0_7:1.15.6.1
	TIGRIS_1_0_7RC3:1.15.6.1
	TIGRIS_1_0_7RC2:1.15.6.1
	TIGRIS_1_0_7RC1:1.15.6.1
	TIGRIS_1_0_6:1.15.6.1
	TIGRIS_1_0_6RC5:1.15.6.1
	TIGRIS_1_0_6RC4:1.15.6.1
	TIGRIS_1_0_6RC3:1.15.6.1
	TIGRIS_1_0_6RC2:1.15.6.1
	TIGRIS_1_0_6RC1:1.15.6.1
	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.2.2.1
	TIGRIS_0_9_2_3:1.2
	HELM_PEER_PORT_BRANCH:1.1.1.1
	TURBINE_PEER:1.7
	TIGRIS_0_9_2_1:1.7
	TIGRIS_0_9_2:1.2.0.2;
locks; strict;
comment	@# @;


1.23
date	2001.07.16.02.23.42;	author jrobbins;	state dead;
branches;
next	1.22;

1.22
date	2001.06.05.01.47.16;	author elicia;	state Exp;
branches;
next	1.21;

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

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

1.19
date	2001.05.31.21.15.06;	author elicia;	state Exp;
branches;
next	1.18;

1.18
date	2001.05.31.19.12.28;	author elicia;	state Exp;
branches;
next	1.17;

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

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

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

1.14
date	2001.03.07.01.53.24;	author lucas;	state Exp;
branches;
next	1.13;

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

1.12
date	2001.02.21.01.08.23;	author dlr;	state Exp;
branches;
next	1.11;

1.11
date	2001.02.01.00.29.56;	author elicia;	state Exp;
branches;
next	1.10;

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

1.9
date	2001.01.30.02.38.13;	author elicia;	state Exp;
branches;
next	1.8;

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

1.7
date	2001.01.27.02.23.43;	author elicia;	state Exp;
branches
	1.7.2.1;
next	1.6;

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

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

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

1.3
date	2001.01.23.07.52.27;	author edk;	state Exp;
branches;
next	1.2;

1.2
date	2001.01.17.18.33.43;	author elicia;	state Exp;
branches
	1.2.2.1;
next	1.1;

1.1
date	2001.01.12.22.15.52;	author elicia;	state Exp;
branches
	1.1.1.1;
next	;

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

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

1.7.2.1
date	2001.01.28.01.02.18;	author dlr;	state dead;
branches;
next	1.7.2.2;

1.7.2.2
date	2001.02.17.01.09.55;	author elicia;	state Exp;
branches;
next	1.7.2.3;

1.7.2.3
date	2001.02.17.20.11.11;	author elicia;	state Exp;
branches;
next	1.7.2.4;

1.7.2.4
date	2001.02.20.01.37.29;	author dlr;	state Exp;
branches;
next	1.7.2.5;

1.7.2.5
date	2001.02.20.01.51.53;	author dlr;	state Exp;
branches;
next	;

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


desc
@@


1.23
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 COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */


package org.tigris.helm.project;

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

import org.apache.turbine.util.Log;
import org.apache.turbine.util.ParameterParser;
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.upload.FileItem;
import org.apache.turbine.util.StringUtils;
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.security.RedirectException;
import org.joist.util.*;

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

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

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

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

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

    /**
     * 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 = "sectionID";

    /**
     * Edits the document.
     */
    protected String processRequest(Context ctx)
        throws TurbineException, RedirectException
    {
        String templateName = super.processRequest(ctx);
    
        try
        {
            Project project = getCurrentProject(ctx);
            if (project == null) {
                redirectToError
                    (ctx, "ProjectDocumentEdit: No project specified");
            }

            String documentID = getParameter(ctx, "documentID");
            if (documentID == null) {
               appendToMessage(ctx, "No document specified");
            }
            ProjectDocument document = (ProjectDocument)
               ProjectDocumentPeer.getInstance(documentID);

            User user = getLoginUser(ctx);
            AccessControlList acl = user.getACL();
            String action = getAction(ctx);
            String name = null;
            String descrip = null;
            String status = null;
            File f = null;
            String url = null;
            String text = null;
            String isPublic = null;
            List missingFields = new ArrayList();
            List validationErrors = new ArrayList();
            String sectionID = Integer.toString(document.getSectionID());
            String htURL =
                URL.schemeAndServer(ContextAPI.getRequest(ctx))
                + "/servlets/"
                + getArtifactListServletName(sectionID);

            if (action != null && action.equals(SUBMIT_CHANGES_ACTION))
            {
                String fsPerms = 
                    myProperties.getProperty("filesystemPermissions");

                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();
                        if (fileName != null)
                        {
                            if (!isValidFileName(fileName))
                                validationErrors.add("Invalid file name '" +
                                                     fileName + '\'');

                            // Create path to file = [baseSaveDir]/[documentID]
                            String saveDir = getSaveDir(document.getID());
                            File dir = new File(saveDir);
                            if (!dir.exists()) dir.mkdirs();
                            String fullPath = (saveDir + File.separatorChar 
                                           + fileName);
                            f = new File(fullPath);

                            // Delete old file, if there was one
                            if (document.getFileName() != null)
                            {
                                document.deleteFromFilesystem(acl, htURL);
                            }
                       
                            // Write file to filesystem
                            filePart.writeTo(f);
                            setFilesystemPermissions(fsPerms, fullPath);
                        }
                    }

                    nextPart = parser.readNextPart();
                }
                      
                if (!haveValue(name))
                    missingFields.add("Document Name");

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

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

                 if (missingFields.isEmpty() &&
                    validationErrors.isEmpty())
                 {
                     // Edit document

                     document.edit(acl, name, status, descrip, 
                            url, text, sectionID, f, isPublic, htURL);
                     redirectToURL(ctx, getArtifactListServletName(sectionID));
  
                 } else {
                     // Report missing fields and errors
                     reportInvalidUserInput(ctx, missingFields, 
                                            validationErrors);
                 }
                    
            }

            ctx.put("name", name);
            ctx.put("status", status);
            ctx.put("description", descrip);
            ctx.put ("url", url);
            ctx.put("text", text);
            ctx.put(IS_PUBLIC, DBFlag.flagValueOf(isPublic));
            ctx.put("document", document);
            ctx.put("sectionID", sectionID);
        }
        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)
    {
        StringBuffer buf = new StringBuffer(
                           "ProjectDocumentList?rootSectionID=");
        buf.append(sectionID);
        return buf.toString();
    }
}
@


1.22
log
@added more field validation
@
text
@@


1.21
log
@minor formatting changes. checking for valid URL field.
@
text
@d61 1
d223 2
a224 1
                if (url != null && !url.equals("") && !URL.hasProtocol(url))
d226 8
@


1.20
log
@Super class was renamed.
@
text
@d192 9
a200 9
                        if (!isValidFileName(fileName))
                            validationErrors.add("Invalid file name '" +
                                                 fileName + '\'');

                        // Create path to file = [baseSaveDir]/[documentID]
                        String saveDir = getSaveDir(document.getID());
                        File dir = new File(saveDir);
                        if (!dir.exists()) dir.mkdirs();
                        String fullPath = (saveDir + File.separatorChar 
d202 1
a202 1
                        f = new File(fullPath);
d204 9
a212 4
                        // Delete old file, if there was one
                        if (document.getFileName() != null)
                        {
                            document.deleteFromFilesystem(acl, htURL);
a213 5
                       
                        // Write file to filesystem
                        filePart.writeTo(f);
                        setFilesystemPermissions(fsPerms, fullPath);
                         }
d222 3
d229 1
@


1.19
log
@passing htURL argument to deleteFromFilesystem method
@
text
@d75 1
a75 1
public class ProjectDocumentEdit extends ProjectFileArtifactAdd
@


1.18
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
@d153 4
d207 1
a207 1
                            document.deleteFromFilesystem(acl);
a225 4
                     String htURL =
                         URL.schemeAndServer(ContextAPI.getRequest(ctx))
                         + "/servlets/"
                         + getArtifactListServletName(sectionID);
@


1.17
log
@Ported Helm from WebMacro to Velocity.
@
text
@d63 3
d75 1
a75 1
public class ProjectDocumentEdit extends HelmServlet
d83 1
a83 1
     * The section name key.
d93 1
a93 1
     * The type key.
d95 1
a95 1
    private static final String TYPE = "type";
d108 5
d132 1
a138 2
            ctx.put("document", document);
            ctx.put("sectionID", Integer.toString(document.getSectionID()));
d145 1
a145 1
            String type = null;
d149 1
a149 1
            String sectionID = null;
d152 1
a155 5
                File saveDir = new File
                    (project.getUploadDirectory(getBaseSaveDir(), user));
                if (!saveDir.exists()) saveDir.mkdirs();
                int maxPostSize = Integer.parseInt
                    (myProperties.getProperty("maxPostSize"));
d159 3
a161 20
                // 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(ProjectFileArtifactAdd.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");
d163 2
a164 4
                if (!haveValue(type))
                    missingFields.add
                        ("Document Contents: Click a button to choose.");
                else
d166 1
a166 1
                    if (type.equals("url"))
d168 34
a201 13
                        if (!haveValue(url))
                            missingFields.add("REMOTEURL");
                        else if (!URL.hasProtocol(url))
                            validationErrors.add("Please provide a valid url");
                    }
                    else if (type.equals("text"))
                    {
                        if (!haveValue(text))
                            missingFields.add("Text");
                    }
                    else
                    {
                        if (fileUploaded)
d203 1
a203 3
                            f = files[0].getStoreLocation();
                            String fileName = f.getName().toString();
                            checkForOverwrite(ctx, project, fileName);
d205 5
d211 2
d214 3
d218 18
a235 19
                if (isValidUserInput(missingFields, validationErrors))
                {
                    // Edit document
                    document.edit(acl, name, descrip, type, url, text, 
                                  sectionID, f);
                    redirectToURL(ctx, "ProjectDocumentList");
                }
                else
                {
                    // Report missing fields and validation errors.
                    ctx.put("name", name);
                    ctx.put("description", descrip);
                    ctx.put("sectionID", sectionID);
                    ctx.put("type", type);
                    ctx.put("url", url);
                    ctx.put("text", text);
                    reportInvalidUserInput(ctx, missingFields,
                                           validationErrors);
                }
d237 9
d262 2
a263 6
    /**
     * Checks whether the upload overwrites a file by the same name.
     */
    private void checkForOverwrite(Context ctx, Project project,
                                   String fileName)
        throws ACLException, Exception
d265 1
a265 20
        User loginUser = getLoginUser(ctx);
        AccessControlList acl = loginUser.getACL();

        List uploadedDocs = project.getDocuments();
        int nbrDocs = uploadedDocs.size();
        for (int i = 0; i < nbrDocs; i++)
        {
            ProjectDocument dc = (ProjectDocument)uploadedDocs.get(i);
            if (project.getProjectId().equals(dc.getProjectId()) &&
                acl.getUser().getUserId().equals(dc.getProposedBy()) &&
                fileName.equals(dc.getFileName()))
            {
                String htURL = URL.schemeAndServer(getRequest(ctx))
                               + "/servlets/ProjectDocumentList";
                dc.delete(acl, false, htURL);
                appendToMessage(ctx, fileName + 
                                " was overwritten by your upload");
                break;
            }
        }
d268 1
a268 4
    /**
     * Macro to return the upload directory.
     */
    private final String getBaseSaveDir ()
d270 4
a273 1
        return myProperties.getProperty("baseSaveDir");
@


1.16
log
@Removed now unnecessary local var htURL (deprecated by the removal of
htURL from the signature of the edit() method).
@
text
@d58 4
d63 1
a63 3
import org.webmacro.servlet.*;

import com.oreilly.servlet.MultipartRequest;
d77 1
a77 1
    private static String SUBMIT_CHANGES_ACTION="Edit Document";
d112 2
a113 2
    protected String processRequest (Connection conn, WebContext ctx)
        throws HandlerException, RedirectException
d115 1
a115 1
        String templateName = super.processRequest(conn, ctx);
d124 1
a124 1
            String documentID = ctx.getForm("documentID");
d156 16
a171 12
                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);
d196 1
a196 1
                        if (!files.isEmpty())
d198 1
a198 1
                            f = (File)upload.getFiles().get(0);
d200 1
a200 1
                            checkForOverwrite(conn, ctx, project, fileName);
d235 1
a235 1
            throw new HandlerException(msg);
d244 2
a245 2
    private void checkForOverwrite (Connection conn, WebContext ctx,
                                    Project project, String fileName)
d260 1
a260 1
                String htURL = URL.schemeAndServer(ctx)
@


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
@a142 2
            String htURL = URL.schemeAndServer(ctx)
                           + "/servlets/ProjectDocumentList";
d203 1
a203 1
                                  sectionID, f, htURL);
@


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
@d143 2
d205 1
a205 1
                                  sectionID, f);
@


1.14
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@d170 2
a171 2
	            if (name == null || name.equals (""))
	                missingFields.add ("Document Name");
d173 3
a175 2
	            if (type == null || type.equals (""))
	                missingFields.add ("Document Contents: Click a button to choose.");
d180 2
a181 2
	                    if (url == null || url.equals (""))
	                        missingFields.add ("REMOTEURL");
d183 1
a183 1
                            validationErrors.add ("Please provide a valid url.");
d187 2
a188 2
	                    if (text == null || text.equals (""))
	                       missingFields.add ("Text");
d252 2
a253 2
            if (project.getProjectId() == dc.getProjectId() &&
                acl.getUser().getUserId() == dc.getProposedBy() &&
@


1.13
log
@putting sectionID into context for pre-populating of sectionID radio button
@
text
@a67 1
import org.tigris.helm.om.peer.*;
@


1.12
log
@This is the highest revision from the HELM_PEER_PORT_BRANCH.  The previous import caused too many conflicts to resolve manually
@
text
@d130 1
@


1.11
log
@passing context to Document to determine url for .htaccess file
@
text
@d2 1
a2 1
 * Copyright (c) 2000 CollabNet.  All rights reserved.
d17 1
a17 1
 * software developed by Collab.Net (http://www.Collab.Net/)."
d32 1
a32 1
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d57 2
a58 1
import org.webmacro.util.Log;
a62 1
import org.tigris.helm.security.HelmServlet;
a63 1
import org.joist.database.DataManager;
d67 2
a68 1
import org.tigris.helm.domain.User;
a69 3
//import org.tigris.helm.tool.FileUtility;
import org.tigris.helm.database.ProjectDocumentManager;
import org.tigris.helm.database.ProjectDocumentSectionManager;
a72 2
    public static final  String versionID = "$Id: ProjectDocumentEdit.java,v 1.10 2001/01/30 02:59:47 elicia Exp $";

a107 4
    /** Open the log file.
     */
    private static Log log = new Log("projDocEdit", "ProjectDocumentEdit");

d109 1
a109 1
     * Whether to log debugging information.
a110 3
    private static boolean debug = true;


a113 1
        if (debug) log.info("started");
d119 4
a122 2
            if (project == null)
                redirectToError(ctx, "ProjectDocumentEdit: No project specified");
d124 1
a124 1
            if (documentID == null)
d126 3
a128 1
            Document document = new Document(conn, dMgr, documentID);
d132 1
a132 1
            AccessControlList acl = getACL(ctx, conn);
d143 2
a155 2
                //FileUtility fileUtil = new FileUtility();

d204 5
a208 3
                                  sectionID, f, ctx);
                    redirectToURL(ctx, "ProjectDocuments");
                } else {
d227 1
a227 1
            log.exception(e);
d243 2
a244 1
        AccessControlList acl = getACL(ctx, conn);
d250 4
a253 4
            Document dc = (Document)uploadedDocs.get(i);
            if (project.getID().equals(dc.getProjectID()) &&
                acl.getUserID().equals(dc.getSuggestedBy().getID()) &&
                fileName.equals(dc.getFilename()))
d255 3
a257 1
                dc.delete(acl, false, ctx);
a262 1

d272 1
a272 2

} /* end class ProjectDocumentEdit */
@


1.10
log
@added editing of .htaccess file on edit and deleting of a file
@
text
@d76 1
a76 1
    public static final  String versionID = "$Id: ProjectDocumentEdit.java,v 1.9 2001/01/30 02:38:13 elicia Exp $";
a149 2
            String htURL = URL.schemeAndServer(ctx) +
               "/servlets/ProjectDocuments";
d204 1
a204 2
                            checkForOverwrite(conn, ctx, 
                                              project, fileName, htURL);
d213 1
a213 1
                                  sectionID, f, htURL);
d247 1
a247 2
                                    Project project, String fileName,
                                    String htURL)
d261 1
a261 1
                dc.delete(acl, false, htURL);
@


1.9
log
@putting pre-error entered data into context
@
text
@d76 1
a76 1
    public static final  String versionID = "$Id: ProjectDocumentEdit.java,v 1.8 2001/01/28 10:02:31 edk Exp $";
d206 2
a207 1
                            checkForOverwrite(conn, ctx, project, fileName);
a214 1
                   log.info("sectionID=" + sectionID);
d216 1
a216 1
                                  sectionID, f);
d250 2
a251 1
                                    Project project, String fileName)
d265 1
a265 1
                dc.delete(acl, false);
@


1.8
log
@comment out code which references FileUtility, since that file hasn't
been added to cvs yet.
@
text
@d76 1
a76 1
    public static final  String versionID = "$Id: ProjectDocumentEdit.java,v 1.7 2001/01/27 02:23:43 elicia Exp $";
d108 5
d165 1
a165 1
//                FileUtility fileUtil = new FileUtility();
d170 1
d178 1
a178 2
                sectionID = mreq.getParameter("section_id");
                List files = upload.getFiles(); 
d206 1
a206 1
//                            fileUtil.checkForOverwrite(project, acl.getUserID(), fileName);
d214 1
d220 6
d246 27
@


1.7
log
@added file upload
@
text
@d70 1
d76 1
a76 1
    public static final  String versionID = "$Id: ProjectDocumentEdit.java,v 1.4 2001/01/26 02:01:31 elicia Exp $";
d160 1
a160 1
                FileUtility fileUtil = new FileUtility();
d201 1
a201 1
                            fileUtil.checkForOverwrite(project, acl.getUserID(), fileName);
@


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


1.7.2.2
log
@ported to turbine
@
text
@d57 1
a57 1
import org.apache.turbine.util.Log;
d62 1
d64 1
d68 1
a68 2
import org.tigris.helm.om.*;
import org.tigris.helm.om.peer.*;
d70 2
d75 1
a75 1
    public static final  String versionID = "$Id: ProjectDocumentEdit.java,v 1.11 2001/02/01 00:29:56 elicia Exp $";
d107 1
a107 2
    /**
     * The id of the section the document is filed under.
d109 1
a109 1
    private static final String SECTION_ID = "sectionID";
d120 1
a120 1
        if (debug) Log.debug("started");
d131 1
a131 2
            ProjectDocument document = (ProjectDocument)
               ProjectDocumentPeer.getInstance(documentID);
d135 1
a135 1
            AccessControlList acl = user.getACL();
d144 2
d159 1
a159 1
                //FileUtility fileUtil = new FileUtility();
a163 1
                List files = upload.getFiles(); 
d171 2
a172 1
                sectionID = mreq.getParameter(SECTION_ID);
d200 1
a200 1
                            checkForOverwrite(conn, ctx, project, fileName);
d208 2
a209 3
                    // TODO: Add edit method to om
                    //document.edit(acl, name, descrip, type, url, text, 
                    //              sectionID, f, ctx);
a212 6
                    ctx.put("name", name);
                    ctx.put("description", descrip);
                    ctx.put("sectionID", sectionID);
                    ctx.put("type", type);
                    ctx.put("url", url);
                    ctx.put("text", text);
d224 1
a224 1
            Log.error(e);
a232 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 loginUser = getLoginUser(ctx);
        AccessControlList acl = loginUser.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(Integer.toString(dc.getProjectId())) &&
                acl.getUser().getID().equals(Integer.toString(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;
            }
        }

    }

@


1.7.2.3
log
@added call to edit method. changed name of list servlet to redirect to.
@
text
@d72 1
a72 1
    public static final  String versionID = "$Id: ProjectDocumentEdit.java,v 1.7.2.2 2001/02/17 01:09:55 elicia Exp $";
a144 2
            String htURL = URL.schemeAndServer(ctx)
                           + "/servlets/ProjectDocumentList";
d156 2
d205 4
a208 3
                    document.edit(acl, name, descrip, type, url, text, 
                                  sectionID, f, htURL);
                    redirectToURL(ctx, "ProjectDocumentList");
@


1.7.2.4
log
@Clean up.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d17 1
a17 1
 * software developed by Collab.Net (http://www.collab.net/)."
d32 1
a32 1
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
a57 1

d72 2
d110 1
a110 1
     * Edits the document.
d112 3
d118 1
d124 2
a125 4
            if (project == null) {
                redirectToError
                    (ctx, "ProjectDocumentEdit: No project specified");
            }
d127 1
a127 1
            if (documentID == null) {
a128 1
            }
d251 2
a252 2
            if (project.getProjectId() == dc.getProjectId() &&
                acl.getUser().getUserId() == dc.getProposedBy() &&
d263 1
d273 2
a274 1
}
@


1.7.2.5
log
@Formatting fix for start and close of different code blocks on the same
line.
@
text
@d206 1
a206 3
                }
                else
                {
@


1.6
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d52 2
d60 2
d65 1
d68 2
d75 1
a75 1
    public static final  String versionID = "$Id: ProjectDocumentEdit.java,v 1.3 2001/01/23 07:52:27 edk Exp $";
d93 1
a93 1
     * The location key.
d95 1
a95 1
    private static final String LOCATION = "location";
d100 1
a100 1
    private static final String URL = "url";
d125 3
a127 2
            Project currentProject = getCurrentProject(ctx);
            AccessControlList acl = getACL(ctx, conn);
d134 2
a135 8
            ProjectDocumentManager docMgr = (ProjectDocumentManager)
               getDataManager (ctx).getManager
               ("org.tigris.helm.database.ProjectDocumentManager");
            ProjectDocumentSectionManager pdsMgr = 
               (ProjectDocumentSectionManager)getDataManager (ctx).getManager
               ("org.tigris.helm.database.ProjectDocumentSectionManager");
            String secID =document.getSectionID() ;

d137 9
a145 5
            if (debug) log.info("action=" + action);

            if (currentProject == null)
                redirectToError(ctx, "ProjectDocumentEdit: No project specified");

a147 9
            String name = processField(ctx, DOCUMENT_NAME,
                                       "Document 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");
d151 54
d208 2
a209 5
                    // TODO : the last argument is a File.  what does it mean,
                    // where does it come from?  none of the javadocs explain.
                    // but it should probably be something other than null.
                    document.edit(acl, name, descrip, location, url, text, 
                                  sectionID, null);
d233 8
@


1.5
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
@a51 2
import java.io.*;
import java.net.URLEncoder;
a57 2
import com.oreilly.servlet.MultipartRequest;

a60 1
import org.joist.util.*;
a62 2
import org.tigris.helm.domain.User;
import org.tigris.helm.tool.*;
d68 1
a68 1
    public static final  String versionID = "$Id: ProjectDocumentEdit.java,v 1.4 2001/01/26 02:01:31 elicia Exp $";
d86 1
a86 1
     * The type key.
d88 1
a88 1
    private static final String TYPE = "type";
d93 1
a93 1
    private static final String REMOTEURL = "url";
d118 2
a119 3
            Project project = getCurrentProject(ctx);
            if (project == null)
                redirectToError(ctx, "ProjectDocumentEdit: No project specified");
d125 10
d137 3
a139 12
            User user = getLoginUser(ctx);
            AccessControlList acl = getACL(ctx, conn);
            String action = getAction(ctx);
            String name = null;
            String descrip = null;
            String type = null;
            File f = null;
            String url = null;
            String text = null;
            String sectionID = null;
            String htURL = URL.schemeAndServer(ctx) +
               "/servlets/ProjectDocuments";
d142 9
a153 60
                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");

                FileUtility fileUtil = new FileUtility();

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

                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");
                List files = upload.getFiles(); 

                // 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"))
                    {
	                    if (url == null || url.equals (""))
	                        missingFields.add ("REMOTEURL");
                        else if (!url.equals("") || !text.equals(""))
                            validationErrors.add ("For document context, please fill in only one of the three fields.");
                        if (!text.equals("") || !files.isEmpty())
                            validationErrors.add ("For document context, please fill in only one of the three fields.");
                    }
                    else if (type.equals("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
                    {
                        if (!url.equals("") || !text.equals(""))
                            validationErrors.add ("For document context, please fill in only one of the three fields.");
                        else if (!files.isEmpty())
                        {
                            f = (File)upload.getFiles().get(0);
                            String fileName = f.getName().toString();
                            fileUtil.checkForOverwrite(project, acl.getUserID(), fileName);
                        }
                    }
                }

d157 5
a161 2
                    document.edit(acl, name, descrip, type, url, text, 
                                  sectionID, f);
a184 8
    /**
     * Macro to return the upload directory.
     */
    private final String getBaseSaveDir ()
    {
        return myProperties.getProperty("baseSaveDir");
    }

@


1.4
log
@no longer passing connection
@
text
@d75 1
a75 1
    public static final  String versionID = "$Id: ProjectDocumentEdit.java,v 1.3 2001/01/23 07:52:27 edk Exp $";
@


1.3
log
@Document.edit requires an additional parameter -- a File.  None of the
javadocs which I saw explain what it's for ... so I'm passing in null,
which might work (it's handled as a possible case by code down the
line).  Anyway -- at least it compiles.  But someone who knows this
servlet should make it work correctly.
@
text
@d52 2
d60 2
d65 1
d68 2
d75 1
a75 1
    public static final  String versionID = "$Id: ProjectDocumentEdit.java,v 1.2 2001/01/17 18:33:43 elicia Exp $";
d93 1
a93 1
     * The location key.
d95 1
a95 1
    private static final String LOCATION = "location";
d100 1
a100 1
    private static final String URL = "url";
d125 3
a127 2
            Project currentProject = getCurrentProject(ctx);
            AccessControlList acl = getACL(ctx, conn);
d133 1
d135 2
a136 8
            ProjectDocumentManager docMgr = (ProjectDocumentManager)
               getDataManager (ctx).getManager
               ("org.tigris.helm.database.ProjectDocumentManager");
            ProjectDocumentSectionManager pdsMgr = 
               (ProjectDocumentSectionManager)getDataManager (ctx).getManager
               ("org.tigris.helm.database.ProjectDocumentSectionManager");
            String secID =document.getSectionID() ;

d138 9
a146 5
            if (debug) log.info("action=" + action);

            if (currentProject == null)
                redirectToError(ctx, "ProjectDocumentEdit: No project specified");

a148 9
            String name = processField(ctx, DOCUMENT_NAME,
                                       "Document 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");
d152 60
d215 2
a216 5
                    // TODO : the last argument is a File.  what does it mean,
                    // where does it come from?  none of the javadocs explain.
                    // but it should probably be something other than null.
                    document.edit(acl, name, descrip, location, url, text, 
                                  sectionID, null);
d240 8
@


1.2
log
@added upload capability
@
text
@d68 1
a68 1
    public static final  String versionID = "$Id: ProjectDocumentEdit.java,v 1.1 2001/01/12 22:15:52 elicia Exp $";
d157 3
d161 1
a161 1
                                  sectionID);
@


1.2.2.1
log
@moved changed from HEAD for ProjectDocuments and ProjectDownloads
@
text
@a51 2
import java.io.*;
import java.net.URLEncoder;
a57 2
import com.oreilly.servlet.MultipartRequest;

a60 1
import org.joist.util.*;
a62 3
import org.tigris.helm.domain.User;
import org.tigris.helm.tool.*;
//import org.tigris.helm.tool.FileUtility;
d68 1
a68 1
    public static final  String versionID = "$Id: ProjectDocumentEdit.java,v 1.11 2001/02/01 00:29:56 elicia Exp $";
d86 1
a86 1
     * The type key.
d88 1
a88 1
    private static final String TYPE = "type";
d93 1
a93 1
    private static final String REMOTEURL = "url";
a99 5
    /**
     * The id of the section the document is filed under.
     */
    private static final String SECTION_ID = "sectionID";

d118 2
a119 3
            Project project = getCurrentProject(ctx);
            if (project == null)
                redirectToError(ctx, "ProjectDocumentEdit: No project specified");
d126 8
a133 2
            User user = getLoginUser(ctx);
            AccessControlList acl = getACL(ctx, conn);
d135 5
a139 7
            String name = null;
            String descrip = null;
            String type = null;
            File f = null;
            String url = null;
            String text = null;
            String sectionID = null;
d142 9
a153 54
                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");

                //FileUtility fileUtil = new FileUtility();

                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"))
                    {
	                    if (url == null || url.equals (""))
	                        missingFields.add ("REMOTEURL");
                        else if (!URL.hasProtocol(url))
                            validationErrors.add ("Please provide a valid url.");
                    }
                    else if (type.equals("text"))
                    {
	                    if (text == null || text.equals (""))
	                       missingFields.add ("Text");
                    }
                    else
                    {
                        if (!files.isEmpty())
                        {
                            f = (File)upload.getFiles().get(0);
                            String fileName = f.getName().toString();
                            checkForOverwrite(conn, ctx, project, fileName);
                        }
                    }
                }

d157 2
a158 2
                    document.edit(acl, name, descrip, type, url, text, 
                                  sectionID, f, ctx);
a161 6
                    ctx.put("name", name);
                    ctx.put("description", descrip);
                    ctx.put("sectionID", sectionID);
                    ctx.put("type", type);
                    ctx.put("url", url);
                    ctx.put("text", text);
a181 35
    /**
     * 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
    {
        AccessControlList acl = getACL(ctx, conn);

        List uploadedDocs = project.getDocuments();
        int nbrDocs = uploadedDocs.size();
        for (int i = 0; i < nbrDocs; i++)
        {
            Document dc = (Document)uploadedDocs.get(i);
            if (project.getID().equals(dc.getProjectID()) &&
                acl.getUserID().equals(dc.getSuggestedBy().getID()) &&
                fileName.equals(dc.getFilename()))
            {
                dc.delete(acl, false, ctx);
                appendToMessage(ctx, fileName + 
                                " was overwritten by your upload");
                break;
            }
        }

    }

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

@


1.1
log
@
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d68 1
a68 1
    public static final  String versionID = "$Id: ProjectDocumentEdit.java,v 1.2 2000/12/30 05:02:17 elicia Exp $";
d157 2
a158 2
                    document.edit(acl, name, location, 
                                  descrip, sectionID);
@


1.1.1.1
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d17 1
a17 1
 * software developed by Collab.Net (http://www.collab.net/)."
d32 1
a32 1
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
a51 2
import java.io.*;
import java.net.URLEncoder;
d55 1
a55 2
import org.apache.turbine.util.Log;

d58 1
a58 2
import com.oreilly.servlet.MultipartRequest;

d60 1
a60 1
import org.joist.util.*;
d63 2
a64 3
import org.tigris.helm.om.*;
import org.tigris.helm.om.peer.*;
import org.tigris.helm.tool.*;
d68 2
d86 1
a86 1
     * The type key.
d88 1
a88 1
    private static final String TYPE = "type";
d93 1
a93 1
    private static final String REMOTEURL = "url";
d100 1
a100 2
    /**
     * The id of the section the document is filed under.
d102 1
a102 1
    private static final String SECTION_ID = "sectionID";
d105 1
a105 1
     * Edits the document.
d107 3
d113 1
d118 2
a119 5
            Project project = getCurrentProject(ctx);
            if (project == null) {
                redirectToError
                    (ctx, "ProjectDocumentEdit: No project specified");
            }
d121 1
a121 1
            if (documentID == null) {
d123 1
a123 3
            }
            ProjectDocument document = (ProjectDocument)
               ProjectDocumentPeer.getInstance(documentID);
d126 8
a133 2
            User user = getLoginUser(ctx);
            AccessControlList acl = user.getACL();
d135 5
a139 7
            String name = null;
            String descrip = null;
            String type = null;
            File f = null;
            String url = null;
            String text = null;
            String sectionID = null;
d142 9
a150 2
            String htURL = URL.schemeAndServer(ctx)
                           + "/servlets/ProjectDocumentList";
a153 52
                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"))
                    {
	                    if (url == null || url.equals (""))
	                        missingFields.add ("REMOTEURL");
                        else if (!URL.hasProtocol(url))
                            validationErrors.add ("Please provide a valid url.");
                    }
                    else if (type.equals("text"))
                    {
	                    if (text == null || text.equals (""))
	                       missingFields.add ("Text");
                    }
                    else
                    {
                        if (!files.isEmpty())
                        {
                            f = (File)upload.getFiles().get(0);
                            String fileName = f.getName().toString();
                            checkForOverwrite(conn, ctx, project, fileName);
                        }
                    }
                }

d157 4
a160 6
                    document.edit(acl, name, descrip, type, url, text, 
                                  sectionID, f, htURL);
                    redirectToURL(ctx, "ProjectDocumentList");
                }
                else
                {
a161 6
                    ctx.put("name", name);
                    ctx.put("description", descrip);
                    ctx.put("sectionID", sectionID);
                    ctx.put("type", type);
                    ctx.put("url", url);
                    ctx.put("text", text);
d173 1
a173 1
            Log.error(e);
d182 1
a182 37
    /**
     * 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 loginUser = getLoginUser(ctx);
        AccessControlList acl = loginUser.getACL();

        List uploadedDocs = project.getDocuments();
        int nbrDocs = uploadedDocs.size();
        for (int i = 0; i < nbrDocs; i++)
        {
            ProjectDocument dc = (ProjectDocument)uploadedDocs.get(i);
            if (project.getProjectId() == dc.getProjectId() &&
                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");
    }
}
@


