head	1.8;
access;
symbols
	TIGRIS_1_1_0RC2:1.1.2.1
	TIGRIS_1_1_0RC1:1.1.2.1
	TIGRIS_1_1:1.1.2.1.0.2
	TIGRIS_1_0_8:1.1.2.1
	TIGRIS_1_0_8RC3:1.1.2.1
	TIGRIS_1_0_8RC2:1.1.2.1
	TIGRIS_1_0_8RC1:1.1.2.1
	TIGRIS_1_0_7:1.1.2.1
	TIGRIS_1_0_7RC3:1.1.2.1
	TIGRIS_1_0_7RC2:1.1.2.1
	TIGRIS_1_0_7RC1:1.1.2.1
	TIGRIS_1_0_6:1.1.2.1
	TIGRIS_1_0_6RC5:1.1.2.1
	TIGRIS_1_0_6RC4:1.1.2.1
	TIGRIS_1_0_6RC3:1.1.2.1
	TIGRIS_1_0_6RC2:1.1.2.1
	TIGRIS_1_0_6RC1:1.1.2.1
	TIGRIS_1_0_5:1.1.2.1
	TIGRIS_1_0_5RC6:1.1.2.1
	TIGRIS_1_0_5RC5:1.1.2.1
	TIGRIS_1_0_5RC4:1.1.2.1
	TIGRIS_1_0_5RC3:1.1.2.1
	TIGRIS_1_0_5RC2:1.1.2.1
	TIGRIS_1_0_5RC1:1.1.2.1
	TIGRIS_1_0_4:1.1.2.1
	TIGRIS_1_0_3:1.1.2.1
	TIGRIS_1_0_2:1.1.2.1
	TIGRIS_1_0:1.1.0.2;
locks; strict;
comment	@# @;


1.8
date	2001.05.31.20.57.35;	author dlr;	state dead;
branches;
next	1.7;

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

1.6
date	2001.05.23.00.11.19;	author dlr;	state Exp;
branches;
next	1.5;

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

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

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

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

1.1
date	2001.04.24.02.44.47;	author dlr;	state Exp;
branches
	1.1.2.1;
next	;

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


desc
@@


1.8
log
@Renamed to FileArtifactManipulate.
@
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 CollabNet (http://www.collab.net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */


package org.tigris.helm.project;

import java.io.File;
import java.io.IOException;

import org.apache.turbine.util.FileUtils;

import org.apache.turbine.util.Log;
import org.apache.turbine.util.TurbineException;

import org.tigris.helm.security.*;
import org.tigris.helm.om.Attribute;
import org.tigris.helm.om.AttributeValue;
import org.tigris.helm.om.AttributeValuePeer;
import org.tigris.helm.om.Host;

/**
 * Support for project file artifact addition.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: ProjectFileArtifactAdd.java,v 1.7 2001/05/31 19:12:28 elicia Exp $
 */
abstract class ProjectFileArtifactAdd extends HelmServlet
{
    /**
     * The field name of the file field which contains the uploaded files.
     */
    protected static final String FILES_FIELD = "file";

    private static final char[] INVALID_FILE_NAME_CHARS =
    {
        '[',
        '?',
        '*'
    };

    /**
     * Returns the name of the servlet used to list artifacts of the
     * implementor's type.
     */
    protected abstract String getArtifactListServletName();

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

    /**
     * Determines whether the supplied file name is valid.
     *
     * @@param name The non-<code>null</code> name of the file.
     * @@return     The file name's validity.
     */
    protected final boolean isValidFileName(String name)
    {
        for (int i = 0; i < INVALID_FILE_NAME_CHARS.length; i++)
        {
            if (name.indexOf(INVALID_FILE_NAME_CHARS[i]) != -1)
            {
                return false;
            }
        }
        return true;
    }

    /**
     * Returns the maximum size in bytes for a HTTP POST which
     * includes a file upload.  Calculated using the host attribute
     * <code>maxUploadSize</code> plus a little extra for the
     * remaining HTTP request overhead.
     *
     * @@return A byte count.
     */
    protected int getMaxPostSize()
        throws Exception
    {
        AttributeValue attribVal = AttributeValuePeer.getInstanceByName
            (Attribute.HOST_TYPE, new Host().getSpecialProject().getID(),
             Attribute.MAX_UPLOAD_SIZE);
        return Integer.parseInt(attribVal.getValue()) + FileUtils.ONE_KB;
    }

    /**
     * Returns the path where the file upload should be saved
     * [baseSaveDirectory] / [documentID]
     */
    protected String getSaveDir(String id)
    {
        return (getBaseSaveDir() + File.separatorChar + id);
    }

    /**
     * Sets the file system permissions for uploaded, saved files.
     */
    public void setFilesystemPermissions (String perms, String path)
        throws InterruptedException, IOException, Exception
    {
        String[] cmd = { "chmod", perms, path };

        // Execute the command.
        try
        {
            Process p = Runtime.getRuntime().exec(cmd);
            if (p.waitFor() != 0)
            {
                // Command did not execute successfully.
                        throw new Exception
                            ("Could not change permissions for path '" +
                              path + '\'');
            }
        }
        catch (InterruptedException e)
        {
            Log.error(e);
            throw new Exception(e.getMessage());
        }
        catch (IOException e)
        {
            Log.error(e);
            throw new Exception(e.getMessage());
        }
    }
}
@


1.7
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
@d68 1
a68 1
 * @@version $Id: ProjectFileArtifactAdd.java,v 1.6 2001/05/23 00:11:19 dlr Exp $
@


1.6
log
@Added file name validity checking routine.
@
text
@d51 1
d68 1
a68 1
 * @@version $Id: ProjectFileArtifactAdd.java,v 1.5 2001/05/21 22:09:55 dlr Exp $
d131 41
@


1.5
log
@Removed unnecessary imports.
@
text
@d67 1
a67 1
 * @@version $Id: ProjectFileArtifactAdd.java,v 1.4 2001/05/21 21:58:54 dlr Exp $
d76 7
d95 18
@


1.4
log
@Added constant.
@
text
@a53 1
import org.apache.velocity.context.Context;
a55 3
import org.apache.turbine.util.TurbineException;

import org.joist.util.URL;
d67 1
a67 1
 * @@version $Id: ProjectFileArtifactAdd.java,v 1.3 2001/05/04 22:26:11 dlr Exp $
@


1.3
log
@Improved JavaDoc for getMaxPostSize() method.
@
text
@d54 1
a54 1
import org.webmacro.servlet.*;
d56 2
d71 1
a71 1
 * @@version $Id: ProjectFileArtifactAdd.java,v 1.2 2001/05/04 22:16:49 dlr Exp $
d75 5
@


1.2
log
@Added getMaxPostSize() method:

 Returns the maximum size in bytes for a HTTP POST which includes
 a file upload.  Calculated using the host attribute maxUploadSize
 plus a little extra for the remain HTTP request overhead.
@
text
@d69 1
a69 1
 * @@version $Id: ProjectFileArtifactAdd.java,v 1.1 2001/04/24 02:44:47 dlr Exp $
d90 4
a93 2
     * <code>maxUploadSize</code> plus a little extra for the remain
     * HTTP request overhead.
@


1.1
log
@Support for project file artifact addition.
@
text
@d52 2
d60 4
d69 1
a69 1
 * @@version $Id: ProjectFileArtifactAdd.java,v 1.7 2001/04/19 19:13:52 dlr Exp $
d85 15
@


1.1.2.1
log
@Refactored to not delete database entries, to make use of new ProjectFileArtifactAdd class, and to sync w/ changed APIs.
@
text
@d63 1
a63 1
 * @@version $Id: ProjectFileArtifactAdd.java,v 1.1 2001/04/24 02:44:47 dlr Exp $
@

