head	1.8;
access;
symbols
	TIGRIS_NOV_12_2000:1.7
	OLDHELM:1.7.0.4
	TIGRIS_NOV_11_2000:1.7
	TIGRIS_SEP_13_2000:1.7.0.2
	TIGRIS_BASELINE:1.7;
locks; strict;
comment	@# @;


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

1.7
date	2000.09.20.03.13.14;	author brian;	state Exp;
branches;
next	1.6;

1.6
date	2000.08.30.00.51.48;	author leonardr;	state Exp;
branches;
next	1.5;

1.5
date	2000.06.01.01.02.48;	author ed;	state Exp;
branches;
next	1.4;

1.4
date	2000.05.31.23.33.46;	author ed;	state Exp;
branches;
next	1.3;

1.3
date	2000.04.18.00.10.33;	author jrobbins;	state Exp;
branches;
next	1.2;

1.2
date	2000.02.03.04.21.31;	author jrobbins;	state Exp;
branches;
next	1.1;

1.1
date	2000.01.30.01.59.36;	author jrobbins;	state Exp;
branches;
next	;


desc
@@


1.8
log
@Does not exist--possibly only WRT this location--in newhelm.
@
text
@/* ================================================================
 * Copyright (c) 2000 Collab.Net.  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 Collab.Net.
 */


package org.tigris.helm.admin;

import org.webmacro.util.*;
import org.webmacro.servlet.*;
import org.webmacro.engine.*;
import org.webmacro.broker.*;

import javax.servlet.*;
import javax.servlet.http.*;

import com.sun.java.util.collections.ArrayList;
import com.sun.java.util.collections.Iterator;
import java.sql.*;
import gnu.regexp.RE;

import org.joist.security.PermissionSet;
import org.joist.security.RedirectException;
import org.joist.security.SecureServlet;
import org.tigris.helm.tool.TigrisUpdate;
import org.tigris.helm.tool.UpdateException;
import org.tigris.helm.tool.InnerNavPopulator;
import org.tigris.helm.tool.MailingList;

/**
 * Present a form for the editing of a mailing list
 */
public class ProjMailAdd extends SecureServlet {
    static private Log log = new Log("pmlAdd", "ProjMailAdd");
    static private boolean debug = true;

    static private RE listnameRE = null;
    static private RE emailRE = null;
    
    public void start() throws ServletException {
        super.start();
        try {
            emailRE = new RE("^[\\w\\-\\._=\\!#\\*\\+]+@@([\\w\\-]+\\.)+[a-zA-Z]{2,3}$");
            listnameRE= new RE("^[a-zA-Z0-9_]+$");
        }
        catch (gnu.regexp.REException e) {
            log.exception(e);
        }
    }

    protected String processRequest(Connection connection, WebContext context)
            throws HandlerException, RedirectException {
        String templateName = super.processRequest(connection, context);
        // super sets $UserName, Cancel

        // Get the userID and permissions of the person who logged in.
        String loginUserID = (String)context.get("loginUserID");
        PermissionSet userPerms = (PermissionSet)context.get("UserPermissions");

        ArrayList missingFields = new ArrayList();
        ArrayList validationErrors = new ArrayList();
        boolean listExists = false;

        String project = context.getForm("project");
        if (project == null)
            redirectToError(context, "ProjMailAdd: No project specified");
        context.put("project", project);
	InnerNavPopulator.Populate(connection,context,false);

        context.put("listname", "");
        context.put("owner", "");
        context.put("sublist", "");

        // Determine which button was pushed
        String action = (String) context.get("action");

        try {
            if (action.equals("Create List")) {
                String list = context.getForm("listname");
                if (list == null || list.equals(""))
                    missingFields.add("List name");
                else {
                    context.put("listname", list);
                    if (!listnameRE.isMatch(list)) {
                        validationErrors.add("List Name must be one word");
                    }
                }

                String owner = context.getForm("owner");
                if (emailRE.isMatch(owner)) {
                    context.put("owner", owner);
                } else if (owner != null && !owner.equals("")) {
                    validationErrors.add("Invalid Owner Email Address");
                }

                String sublist = context.getForm("sublist");
                if (sublist != null && sublist.equals(""))
                    sublist = null;
                context.put("sublist", sublist);

                if (missingFields.isEmpty() && validationErrors.isEmpty()) {
                    try {
                        MailingList.addMailingList(connection, project, list,
                                false);
                        MailingList mList = new MailingList(connection, project,
                                list);
                        Iterator i = mList.getPrivNames().iterator();
                        while (i.hasNext()) {
                            String priv = (String)i.next();
                            mList.setPrivilege(priv,
                                    context.getForm(priv) != null);
                        }
                        mList.setOwner(owner);
                        mList.setSubList(sublist);
                        TigrisUpdate.update(connection);
                        redirectTo("ProjectEdit");
                    }
                    catch (MailingList.AlreadyExists e) {
                        listExists = true;
                        // Fall through to the standard template
                    }
                    catch (MailingList.DoesNotExist e) {
                        redirectToError(context, "ProjMailAdd: Huh? " +
                                "Something odd happened.  The mailing list " +
                                "we just created does not exist.");
                    }
                }
            }
        }
        catch (UpdateException e) {
            log.exception(e);
            String message = "ProjMailAdd: " + e.getMessage();
            if (debug) log.debug(message);
                throw new HandlerException(e.getMessage());
            }
            catch (SQLException e) {
                log.exception(e);
                String message = "ProjMailAdd: " + e.getMessage();
                if (debug) log.debug(message);
                throw new HandlerException(e.getMessage());
            }

            String level = (String) context.getForm("level");
            // For now, we always specify the default options - getting
            // the currently-specified ones is a pain
            if ("Advanced".equals(level)) {
                context.put("options", MailingList.getDefaultValuesArray(
                            MailingList.DISPLAY_ADVANCED));
                context.put("alternate_level", "Simple");
            } else {
                context.put("options", MailingList.getDefaultValuesArray(
                            MailingList.DISPLAY_BEGINER));
                context.put("alternate_level", "Advanced");
            }

            context.put("missingFields", missingFields);
            context.put("validationErrors", validationErrors);
            context.put("listExists", new Boolean(listExists));
            context.put("warnChanged", new Boolean(listExists
                        || !missingFields.isEmpty()));

        return templateName;
    }
} /* end class ProjMailAdd */
@


1.7
log
@
Obtained from:
Submitted by:
Reviewed by:

Moved from org.helm to org.tigris.helm
Moved from org/helm to org/tigris/helm

perl -pi.bak -e, how I love thee

note: this update was done POST-CVS-REPOSITORY surgury.  In order to
get this right, you may need to remove the directories

$CVSROOT/helm/java/org/helm
$CVSROOT/helm/data/htdoc/look/www/org/helm
$CVSROOT/helm/templates/org/helm

before doing the "CVS update" call, since those directories don't
exist anymore and CVS will try to create lockfiles for you in them,
giving you an error.
@
text
@@


1.6
log
@Initial commit.
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d48 1
a48 1
package org.helm.admin;
d66 4
a69 4
import org.helm.tool.TigrisUpdate;
import org.helm.tool.UpdateException;
import org.helm.tool.InnerNavPopulator;
import org.helm.tool.MailingList;
@


1.5
log
@standardize formatting, and don't require user to specify an owner
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d68 1
d109 1
@


1.4
log
@These have been updated to allow either Simple or Advanced editing.

Indentation has been standardized (and tabs removed) in them.  In
ProjMailEdit, I changed the indentation to the style I prefer: 4 spaces.

ProjMailAdd has been changed to validate the owner e-mail address in the
same way that ProjMailEdit does.
PR:
Obtained from:
Submitted by:	Ed Korthof <ed@@apache.org>
Reviewed by:
@
text
@d74 2
a75 2
  static private Log log = new Log("pmlAdd", "ProjMailAdd");
  static private boolean debug = true;
d91 21
a111 37
  protected String processRequest(Connection connection, WebContext context)
    throws HandlerException, RedirectException
  {
    String templateName = super.processRequest(connection, context);
    // super sets $UserName, Cancel

    // Get the userID and permissions of the person who logged in.
    String loginUserID = (String)context.get("loginUserID");
    PermissionSet userPerms = (PermissionSet)context.get("UserPermissions");

    ArrayList missingFields = new ArrayList();
    ArrayList validationErrors = new ArrayList();
    boolean listExists = false;

    String project = context.getForm("project");
    if (project == null)
      redirectToError(context, "ProjMailAdd: No project specified");
    context.put("project", project);

    context.put("listname", "");
    context.put("owner", "");
    context.put("sublist", "");

    // Determine which button was pushed
    String action = (String) context.get("action");

    try {
      if (action.equals("Create List")) {
        String list = context.getForm("listname");
        if (list == null || list.equals(""))
          missingFields.add("List name");
        else {
          context.put("listname", list);
          if (!listnameRE.isMatch(list)) {
            validationErrors.add("List Name must be one word");
          }
        }
d113 2
a114 8
        String owner = context.getForm("owner");
        if (owner != null && owner.equals("")) {
          missingFields.add("Owner");
        } else if (!emailRE.isMatch(owner)) {
          validationErrors.add("Owner Email Address");
        } else {
          context.put("owner", owner);
        }
d116 51
a166 13
        String sublist = context.getForm("sublist");
        if (sublist != null && sublist.equals(""))
          sublist = null;
        context.put("sublist", sublist);

        if (missingFields.isEmpty() && validationErrors.isEmpty()) {
          try {
            MailingList.addMailingList(connection, project, list, false);
            MailingList mList = new MailingList(connection, project, list);
            Iterator i = mList.getPrivNames().iterator();
            while (i.hasNext()) {
              String priv = (String)i.next();
              mList.setPrivilege(priv, context.getForm(priv) != null);
a167 14
            mList.setOwner(owner);
            mList.setSubList(sublist);
            TigrisUpdate.update(connection);
            redirectTo("ProjectEdit");
          }
          catch (MailingList.AlreadyExists e) {
            listExists = true;
            // Fall through to the standard template
          }
          catch (MailingList.DoesNotExist e) {
            redirectToError(context, "ProjMailAdd: Huh? Something odd happened. "
                            + "The mailing list we just created does "
                            + "not exist.");
          }
d169 12
a180 14
      }
    }
    catch (UpdateException e) {
      log.exception(e);
      String message = "ProjMailAdd: " + e.getMessage();
      if (debug) log.debug(message);
      throw new HandlerException(e.getMessage());
    }
    catch (SQLException e) {
      log.exception(e);
      String message = "ProjMailAdd: " + e.getMessage();
      if (debug) log.debug(message);
      throw new HandlerException(e.getMessage());
    }
d182 12
a193 12
    String level = (String) context.getForm("level");
    // For now, we always specify the default options - getting
    // the currently-specified ones is a pain
    if ("Advanced".equals(level)) {
        context.put("options", MailingList.getDefaultValuesArray(
                    MailingList.DISPLAY_ADVANCED));
        context.put("alternate_level", "Simple");
    } else {
        context.put("options", MailingList.getDefaultValuesArray(
                    MailingList.DISPLAY_BEGINER));
        context.put("alternate_level", "Advanced");
    }
d195 5
a199 5
    context.put("missingFields", missingFields);
    context.put("validationErrors", validationErrors);
    context.put("listExists", new Boolean(listExists));
    context.put("warnChanged", new Boolean(listExists
                                           || !missingFields.isEmpty()));
d201 2
a202 3
    return templateName;
  }
    
@


1.3
log
@switched from collections2.jar to collections.jar
@
text
@d78 1
d81 8
a88 7
	super.start();
	try {
	    listnameRE= new RE("^[a-zA-Z0-9_]+$");
	}
	catch (gnu.regexp.REException e) {
	    log.exception(e);
	}
d107 1
a107 1
	    redirectToError(context, "ProjMailAdd: No project specified");
d124 3
a126 3
	  if (!listnameRE.isMatch(list)) {
	      validationErrors.add("List Name must be one word");
	  }
d130 7
a136 3
        if (owner != null && owner.equals(""))
          owner = null;
        context.put("owner", owner);
d182 1
d185 9
a193 1
    context.put("options", MailingList.getDefaultValuesArray());
@


1.2
log
@Added tigris.org license
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d58 2
a59 2
import java.util.ArrayList;
import java.util.Iterator;
@


1.1
log
@initial checking
@
text
@d1 46
a46 1
// Copyright (c) 2000 Collab.Net, Inc. All Rights Reserved.
@

