head	1.2;
access;
symbols
	TIGRIS_0_9_2_4:1.1.1.1
	TIGRIS_0_9_2_3:1.1.1.1
	TIGRIS_0_9_2:1.1.1.1.0.6
	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.2
date	2001.01.26.01.40.49;	author elicia;	state dead;
branches;
next	1.1;

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

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


desc
@@


1.2
log
@this file was not intended to be checked in
@
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.io.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

import com.workingdogs.village.*;

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

import org.joist.*;
import org.joist.util.*;
import org.joist.session.*;

import org.tigris.helm.security.HelmServlet;
import org.tigris.helm.database.ProjectNewsManager;
import org.joist.security.RedirectException;
import org.tigris.helm.security.AccessControlList;
import org.tigris.helm.domain.NewsItem;


public class ProjectNewsEdit extends org.tigris.helm.security.HelmServlet
{
  public static final String versionID =
    "$Id: ProjectNewsEdit.java.sav,v 1.1 2000/11/12 21:16:17 dlr Exp $";
  private static Log log = new Log ("ProjectNewsEdit", "Tigris StartPage");
  private static boolean debug = true;

    /**
     *  Display and process the login screen.
     */
  protected String
    processRequest (Connection connection, WebContext context)
    throws HandlerException, RedirectException
  {
    if (debug)
      log.debug ("ProjectNewsEdit: started!");

    String templateName = super.processRequest (connection, context);
    String action = (String) context.get ("action");

    String newsID = context.getForm ("newsID");
    String projectName = null;

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

    ProjectNewsManager newsMgr = (ProjectNewsManager)
      getDataManager (context).getManager
      ("org.tigris.helm.database.ProjectNewsManager");

    // Get the userID of the person who logged in.
    String loginUserID = (String) context.get ("loginUserID");

    if (debug)
        log.debug ("ProjectNewsEdit: action=" + action);

    // If we are returning to this page as a result of an error, we just
    // want to refresh the display, without doing any further action.
    String errorMessage = (String) context.get ("Error");
    if (errorMessage != null)
    {
        action = "none";
	appendToMessage (context, errorMessage);
    }

    try
    {
      // Get project name for context
      Project currentProject = (Project) context.get ("currentProject");
      projectName = (String) currentProject.getName ();

      DataSet newsItemSet = newsMgr.getNewsItem(connection, newsID);
      Record r = newsItemSet.getRecord(0);
      NewsItem newsItem = new NewsItem(connection, dMgr, r);
      context.put("newsItem", newsItem);

      if (action.equals ("Edit"))
      {
	String month = context.getForm ("month");
	String day = context.getForm ("day");
	String year = context.getForm ("year");
	java.text.DateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
	StringBuffer dateBuf = new StringBuffer();
	dateBuf.append(year).append("-").append(month).append("-").append(day);
	Date eventDate = myFormat.parse(dateBuf.toString());

	String projectID = context.getForm ("projectID");
        context.put ("projectID", projectID);

	String headline = context.getForm ("headline");
	if (headline == null || headline.equals (""))
	    missingFields.add ("headline");
	else
	    context.put ("headline", headline);

	String body = context.getForm ("body");
	if (body == null || body.equals (""))
	    missingFields.add ("body");
	else
	    context.put ("body", body);

	AccessControlList acl = getACL (context);
	if (!missingFields.isEmpty ())
	{
	  appendToMessage (context, "Missing Fields", missingFields);
	  if (debug)
	    log.debug ("Missing Fields: " + missingFields.toString ());
	}
	else if (!validationErrors.isEmpty ())
	{
	  appendToMessage (context, "Validation Errors", validationErrors);
	  if (debug)
	    log.debug ("Validation Errors: " + validationErrors.toString ());
	}
	else
	{
	    // TODO: Redirect to an edit page.  Deal with extra fields.
	    newsMgr.updateNews (connection, acl, null, projectID,
				eventDate, headline, body, "1",
				"2000-12-01 01:01:01",
				"2000-12-24 01:01:01", "1");
	    redirectTo("ProjectNews");
	  }
	}
    }
    catch (Exception e)
    {
      log.exception (e);
      String message = "ProjectNewsEdit: " + e.getMessage ();
      if (debug)
	log.debug (message);
      context.put ("message", message);
    }


    if (debug)
      log.debug ("ProjectNewsEdit:  done");

    context.put ("missingFields", missingFields);
    context.put ("validationErrors", validationErrors);
    context.put ("projectName", projectName);

    return templateName;
  }

}				/* end class ProjectNewsEdit */
@


1.1
log
@Initial revision
@
text
@d82 1
a82 1
    "$Id: ProjectNewsEdit.java.sav,v 1.1 2000/11/08 04:12:04 elicia Exp $";
@


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
@@
