head	1.29;
access;
symbols
	TIGRIS_1_1_0RC2:1.18
	TIGRIS_1_1_0RC1:1.18
	TIGRIS_1_1:1.18.0.4
	TIGRIS_1_0_8:1.18
	TIGRIS_1_0_8RC3:1.18
	TIGRIS_1_0_8RC2:1.18
	TIGRIS_1_0_8RC1:1.18
	TIGRIS_1_0_7:1.18
	TIGRIS_1_0_7RC3:1.18
	TIGRIS_1_0_7RC2:1.18
	TIGRIS_1_0_7RC1:1.18
	TIGRIS_1_0_6:1.18
	TIGRIS_1_0_6RC5:1.18
	TIGRIS_1_0_6RC4:1.18
	TIGRIS_1_0_6RC3:1.18
	TIGRIS_1_0_6RC2:1.18
	TIGRIS_1_0_6RC1:1.18
	TIGRIS_1_0_5:1.18
	TIGRIS_1_0_5RC6:1.18
	TIGRIS_1_0_5RC5:1.18
	TIGRIS_1_0_5RC4:1.18
	TIGRIS_1_0_5RC3:1.18
	TIGRIS_1_0_5RC2:1.18
	TIGRIS_1_0_5RC1:1.18
	TIGRIS_1_0_4:1.18
	TIGRIS_1_0_3:1.18
	TIGRIS_1_0_2:1.18
	TIGRIS_1_0_1:1.18
	TIGRIS_1_0:1.18.0.6
	TIGRIS_1_0_0:1.18
	TIGRIS_1_0_0_RC1:1.18.0.2
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.12
	TIGRIS_0_9_2_3:1.12
	HELM_PEER_PORT_BRANCH:1.1.1.2
	TURBINE_PEER:1.15
	TIGRIS_0_9_2_1:1.15
	TIGRIS_0_9_2:1.12.0.2
	TIGRIS_0_9_0:1.10.0.2
	TIGRIS_0_8_4:1.7.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.29
date	2001.08.28.17.45.17;	author leonardr;	state Exp;
branches;
next	1.28;

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

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

1.26
date	2001.07.19.19.08.43;	author dlr;	state Exp;
branches;
next	1.25;

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

1.24
date	2001.07.17.20.10.49;	author leonardr;	state Exp;
branches;
next	1.23;

1.23
date	2001.06.02.01.17.00;	author elicia;	state Exp;
branches;
next	1.22;

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

1.21
date	2001.05.23.01.22.12;	author ms;	state Exp;
branches;
next	1.20;

1.20
date	2001.05.23.00.47.31;	author ms;	state Exp;
branches;
next	1.19;

1.19
date	2001.05.23.00.43.49;	author ms;	state Exp;
branches;
next	1.18;

1.18
date	2001.03.07.01.53.25;	author lucas;	state Exp;
branches;
next	1.17;

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

1.16
date	2001.02.06.19.59.57;	author elicia;	state Exp;
branches;
next	1.15;

1.15
date	2001.01.26.05.24.06;	author edk;	state Exp;
branches
	1.15.2.1;
next	1.14;

1.14
date	2001.01.25.02.52.28;	author ms;	state Exp;
branches;
next	1.13;

1.13
date	2001.01.25.01.58.30;	author lucas;	state Exp;
branches;
next	1.12;

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

1.11
date	2000.12.27.23.33.30;	author brian;	state Exp;
branches;
next	1.10;

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

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

1.8
date	2000.12.07.02.30.36;	author elicia;	state Exp;
branches;
next	1.7;

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

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

1.5
date	2000.11.22.23.50.14;	author leonardr;	state Exp;
branches;
next	1.4;

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

1.3
date	2000.11.15.21.12.14;	author elicia;	state Exp;
branches;
next	1.2;

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

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

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

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

1.15.2.1
date	2001.01.28.01.02.18;	author dlr;	state dead;
branches;
next	1.15.2.2;

1.15.2.2
date	2001.02.10.01.50.15;	author elicia;	state Exp;
branches;
next	1.15.2.3;

1.15.2.3
date	2001.02.15.20.50.42;	author leonardr;	state Exp;
branches;
next	1.15.2.4;

1.15.2.4
date	2001.02.16.03.01.34;	author dlr;	state Exp;
branches;
next	1.15.2.5;

1.15.2.5
date	2001.02.17.00.16.39;	author elicia;	state Exp;
branches;
next	;


desc
@@


1.29
log
@More methods migrated to ContextAPI.
@
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.text.*;
import javax.servlet.*;

import org.apache.turbine.util.Log;
import org.apache.commons.util.exception.NestableException;

import org.apache.velocity.context.Context;

import org.tigris.helm.util.URL;
import org.tigris.helm.tool.Emailer;

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

public class ProjectNewsEdit extends HelmServlet
{
    private static final boolean debug = true;

    private static String EDIT_ACTION="Submit Changes";
    private static String ADVANCED_ACTION="Advanced Options";
    private static String HEADLINE="headline";
    private static String BODY="body";
    private static String IMAGE_URL="imageUrl";
    private static String ARTICLE_URL="articleUrl";


    /**
     *  Display and process the login screen.
     */
    protected String processRequest(Context context)
        throws NestableException, RedirectException
    {
        String templateName = super.processRequest(context);
        String action = (String) context.get ("action");

        int month, year;

        try
        {
            Project currentProject = getCurrentProject(context);
            User loginUser = getLoginUser(context);
            AccessControlList acl = loginUser.getACL();
            Domain currentDomain = getCurrentDomain(context);
      
            // Get current newsItem to edit
            String newsID = ContextAPI.getParameter(context, "newsID");
            if (newsID == null)
            {  
                redirectToURL(context, "ProjectNewsAdd");
            }
            NewsItem newsItem = (NewsItem)NewsItemPeer.getInstance(newsID);
            context.put("newsItem", newsItem);

            // Put current date into context as a default
            GregorianCalendar today = new GregorianCalendar();
            month = today.get(Calendar.MONTH) +1;
            String currentMonth = Integer.toString(month);
            String currentDay = 
                Integer.toString(today.get(Calendar.DAY_OF_MONTH));

            year = today.get(Calendar.YEAR);
            String currentYear = Integer.toString(year);
            String eventYear;
            if (month == 12)
            {
                context.put("isDecember", "");
                eventYear = ContextAPI.processField(context, "event_year");
            }
            else
            {
                eventYear = currentYear;
            }
            context.put("current_month", currentMonth);
            context.put("current_day", currentDay);
            context.put("current_year", currentYear);
            context.put("next_year", Integer.toString(++year));

            if (action.equals (EDIT_ACTION) || action.equals(ADVANCED_ACTION))
            {
                // Do edit

	        // Get user-entered values
                String headline = ContextAPI.processRequiredField
                    (context, HEADLINE, "Headline");
                String body = ContextAPI.processField(context, BODY);
                String eventMonth = ContextAPI.processField
                    (context, "event_month");
                String eventDay = ContextAPI.processField
                    (context, "event_day");
                String imageUrl = ContextAPI.processField
                    (context, IMAGE_URL);
                String articleUrl = ContextAPI.processField
                    (context, ARTICLE_URL);

                // Handle dates
                Date eventDate = null;

                // Format user-entered event date
                Calendar cal = new GregorianCalendar();
                cal.setLenient(false);
                cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(eventDay));
                cal.set(Calendar.MONTH, Integer.parseInt(eventMonth)-1);
                cal.set(Calendar.YEAR, Integer.parseInt(eventYear));    

                try
                {
                    eventDate = cal.getTime();
                }
                catch (IllegalArgumentException e)
                {
                    ContextAPI.addValidationError
                        (context, "Event date is not valid.");
                }

                if (articleUrl != null && !articleUrl.equals("") 
                    && !URL.hasProtocol(articleUrl))
                {
                    ContextAPI.addValidationError
                        (context, 
                         "Please provide a valid original article URL."); 
                }

                if (ContextAPI.isValidUserInput(context))
                {
                    newsItem.edit(acl, eventDate, headline, body, 
                                  null, null, null, imageUrl, articleUrl);
                    String url = null;
                    if (action.equals(EDIT_ACTION))
                    {
                        url = currentProject.getProjectPageURL("ProjectNewsList");
                    }  
                    else 
                    {
                        StringBuffer urlBuf = new StringBuffer("ProjectNewsEditAdvanced");
                        urlBuf.append("?newsID=").append(newsItem.getID());
                        url = urlBuf.toString();
                    }
                    redirectToURL(context, url);
                } 
                else 
                {
                    context.put("errors", "yes");
                }
            } 
            else 
            { 
                // No action
                // Get current database values
	        String eventDateString = newsItem.getEventDate().toString();
	        String event_month = eventDateString.substring(5,7);
	        String event_day = eventDateString.substring(8,10);
	        String event_year = eventDateString.substring(0,4);
	  
	        // Put current values in context for display
                context.put("newsItem", newsItem);
                context.put("event_month", event_month);
                context.put("event_day", event_day);
                context.put("event_year", event_year);
            }
        }
        catch (RedirectException e)
        {
            throw e;
        }
        catch (Exception e)
        {
            Log.error (e);
            String message = "ProjectNewsAdd: " + e.getMessage ();
            if (debug) Log.info (message);
            context.put ("message", message);
        }
    
        if (debug) Log.debug ("ProjectNewsAdd:  done");
    
        return templateName;

    }
      
}				/* end class ProjectNews */
@


1.28
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
text
@d97 1
a97 1
            String newsID = getParameter(context, "newsID");
@


1.27
log
@Removed Joist references.
@
text
@d55 1
a55 1
import org.apache.turbine.util.TurbineException;
d82 1
a82 1
        throws TurbineException, RedirectException
@


1.26
log
@Updated to use Helm URL class (just ported from Joist).
@
text
@d60 1
a60 1
import org.joist.mail.Emailer;
@


1.25
log
@Ported Joist Redirect*Exception to Helm.
@
text
@d59 1
a59 1
import org.joist.util.URL;
@


1.24
log
@Ported servlets to new error-handling mechanism.
@
text
@a50 1
import java.util.Date;
a51 1
import java.sql.*;
a55 1
import org.apache.turbine.util.TurbineException;
a58 1
import org.joist.security.*;
d68 1
a68 3
    public static final String versionID =
        "$Id: ProjectNewsEdit.java,v 1.23 2001/06/02 01:17:00 elicia Exp $";
    private static boolean debug = true;
@


1.23
log
@added imageURL and original article URL fields
@
text
@d68 2
a69 1
import org.tigris.helm.om.*;
d72 10
a81 10
  public static final String versionID =
    "$Id: ProjectNewsEdit.java,v 1.22 2001/05/23 01:50:15 dlr Exp $";
  private static boolean debug = true;

  private static String EDIT_ACTION="Submit Changes";
  private static String ADVANCED_ACTION="Advanced Options";
  private static String HEADLINE="headline";
  private static String BODY="body";
  private static String IMAGE_URL="imageUrl";
  private static String ARTICLE_URL="articleUrl";
d87 5
a91 31
  protected String processRequest(Context ctx)
    throws TurbineException, RedirectException
  {
     if (debug)
       Log.debug ("ProjectNewsAdd: started!");

     String templateName = super.processRequest(ctx);
     String action = (String) ctx.get ("action");

     if (debug)
        Log.debug ("ProjectNewsAdd: action=" + action);

     ArrayList missingFields = new ArrayList ();
     ArrayList validationErrors = new ArrayList ();
     int month, year;

     try
     {
        Project currentProject = getCurrentProject(ctx);
        User loginUser = getLoginUser(ctx);
        AccessControlList acl = loginUser.getACL();
        Domain currentDomain = getCurrentDomain(ctx);
      
        // Get current newsItem to edit
        String newsID = getParameter(ctx, "newsID");
        if (newsID == null)
        {  
            redirectToURL(ctx, "ProjectNewsAdd");
        }
        NewsItem newsItem = (NewsItem)NewsItemPeer.getInstance(newsID);
        ctx.put("newsItem", newsItem);
d93 1
a93 23
        // Put current date into ctx as a default
        GregorianCalendar today = new GregorianCalendar();
        month = today.get(Calendar.MONTH) +1;
        String currentMonth = Integer.toString(month);
        String currentDay = 
		    Integer.toString(today.get(Calendar.DAY_OF_MONTH));

        year = today.get(Calendar.YEAR);
        String currentYear = Integer.toString(year);
        String eventYear;
        if (month == 12)
        {
            ctx.put("isDecember", "");
            eventYear = processField(ctx, "event_year");
        }
        else
        {
            eventYear = currentYear;
        }
        ctx.put("current_month", currentMonth);
        ctx.put("current_day", currentDay);
        ctx.put("current_year", currentYear);
        ctx.put("next_year", Integer.toString(++year));
d95 1
a95 1
        if (action.equals (EDIT_ACTION) || action.equals(ADVANCED_ACTION))
d97 41
a137 1
            // Do edit
d140 66
a205 56
            String headline = processField(ctx, HEADLINE, "Headline", 
                                           missingFields);
            String body = processField(ctx, BODY);
            String eventMonth = processField(ctx, "event_month");
            String eventDay = processField(ctx, "event_day");
            String imageUrl = processField(ctx, IMAGE_URL);
            String articleUrl = processField(ctx, ARTICLE_URL);

           // Handle dates
           Date eventDate = null;

           // Format user-entered event date
           Calendar cal = new GregorianCalendar();
           cal.setLenient(false);
           cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(eventDay));
           cal.set(Calendar.MONTH, Integer.parseInt(eventMonth)-1);
           cal.set(Calendar.YEAR, Integer.parseInt(eventYear));    

           try
           {
               eventDate = cal.getTime();
           }
           catch (IllegalArgumentException e)
           {
	           validationErrors.add("Event date is not valid.");
           }

           if (articleUrl != null && !articleUrl.equals("") 
               && !URL.hasProtocol(articleUrl))
           {
              validationErrors.add("Please provide a valid original article URL."); 
           }

           if (isValidUserInput(missingFields, validationErrors))
           {
	          newsItem.edit(acl, eventDate, headline, body, 
                            null, null, null, imageUrl, articleUrl);
              String url = null;
              if (action.equals(EDIT_ACTION))
              {
                  url = currentProject.getProjectPageURL("ProjectNewsList");
              }  else {
                  StringBuffer urlBuf = new StringBuffer("ProjectNewsEditAdvanced");
                  urlBuf.append("?newsID=").append(newsItem.getID());
                  url = urlBuf.toString();
              }
              redirectToURL(ctx, url);
           } else {
              reportInvalidUserInput(ctx, missingFields, 
                                     validationErrors);
	          ctx.put("errors", "yes");
           }
        } else {
 
            // No action
            // Get current database values
d211 17
a227 5
	        // Put current values in ctx for display
            ctx.put("newsItem", newsItem);
            ctx.put("event_month", event_month);
            ctx.put("event_day", event_day);
            ctx.put("event_year", event_year);
a228 12
    }
    catch (RedirectException e)
    {
       throw e;
    }
    catch (Exception e)
    {
      Log.error (e);
      String message = "ProjectNewsAdd: " + e.getMessage ();
      if (debug) Log.info (message);
      ctx.put ("message", message);
    }
d230 1
a230 1
    if (debug) Log.debug ("ProjectNewsAdd:  done");
d232 1
a232 1
    return templateName;
d234 1
a234 1
  }
@


1.22
log
@Ported Helm from WebMacro to Velocity.
@
text
@d1 1
a1 1
/* ================================================================
d63 1
d72 1
a72 1
    "$Id: ProjectNewsEdit.java,v 1.21 2001/05/23 01:22:12 ms Exp $";
d79 2
d149 1
a149 2
            String body = processField(ctx, BODY, "Body", 
                                       missingFields);
d152 2
d174 6
d183 1
a183 1
                            null, null, null);
@


1.21
log
@fixed npe in year
@
text
@d57 2
d60 1
a60 1
import org.webmacro.servlet.*;
d71 1
a71 1
    "$Id: ProjectNewsEdit.java,v 1.20 2001/05/23 00:47:31 ms Exp $";
d83 2
a84 2
  protected String processRequest (Connection conn, WebContext ctx)
    throws HandlerException, RedirectException
d89 1
a89 1
     String templateName = super.processRequest (conn, ctx);
d107 1
a107 1
        String newsID = ctx.getForm("newsID");
@


1.20
log
@keep variables in template standard
@
text
@d69 1
a69 1
    "$Id: ProjectNewsEdit.java,v 1.19 2001/05/23 00:43:49 ms Exp $";
d121 2
d126 5
a131 1
        String currentYear = Integer.toString(year);
a147 1
            String eventYear = processField(ctx, "event_year");
@


1.19
log
@only let next year be specified in december of previous year
@
text
@d69 1
a69 1
    "$Id: ProjectNewsEdit.java,v 1.18 2001/03/07 01:53:25 lucas Exp $";
d129 1
a129 1
        ctx.put("nextYear", Integer.toString(++year));
@


1.18
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@d69 1
a69 1
    "$Id: ProjectNewsEdit.java,v 1.17 2001/02/21 01:08:23 dlr Exp $";
d95 1
d115 2
a116 2
        String currentMonth = 
		    Integer.toString(today.get(Calendar.MONTH) +1);
d119 7
a125 2
        String currentYear = 
		    Integer.toString(today.get(Calendar.YEAR));
d129 1
a129 1

@


1.17
log
@This is the highest revision from the HELM_PEER_PORT_BRANCH.  The previous import caused too many conflicts to resolve manually
@
text
@d65 1
a65 3
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;

d69 1
a69 1
    "$Id: ProjectNewsEdit.java,v 1.15.2.5 2001/02/17 00:16:39 elicia Exp $";
@


1.16
log
@broke into two steps: regular edit, and advanced options
@
text
@d56 2
a57 1
import org.webmacro.util.*;
d64 3
a66 1
import org.tigris.helm.domain.*;
d68 1
a68 1
public class ProjectNewsEdit extends org.tigris.helm.security.HelmServlet
d71 1
a71 2
    "$Id: ProjectNewsAdd.java,v 1.22 2001/02/02 01:10:22 elicia Exp $";
  private static Log log = new Log ("ProjectNews", "Tigris StartPage");
d87 1
a87 1
       log.debug ("ProjectNewsAdd: started!");
d93 1
a93 1
        log.debug ("ProjectNewsAdd: action=" + action);
d101 2
a102 1
        AccessControlList acl = getACL(ctx, conn);
d111 1
a111 1
        NewsItem newsItem = new NewsItem(conn, dMgr, newsID);
a125 15
        if (action.equals("none"))
        {
            // Get current database values
	        String eventDateString = newsItem.getEventDate();
	        String event_month = eventDateString.substring(0,2);
	        String event_day = eventDateString.substring(3,5);
	        String event_year = eventDateString.substring(6,10);
	  
	        // Put current values in ctx for display
            ctx.put("newsItem", newsItem);
            ctx.put("event_month", event_month);
            ctx.put("event_day", event_day);
            ctx.put("event_year", event_year);
        }

d166 1
a166 1
                  url = currentProject.getProjectPageURL("ProjectNews");
d178 15
a192 1
        } 
d200 1
a200 1
      log.exception (e);
d202 1
a202 1
      if (debug) log.info (message);
d206 1
a206 1
    if (debug) log.debug ("ProjectNewsAdd:  done");
@


1.15
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
@d50 1
a50 1
import java.util.ArrayList;
a52 2
import java.util.Calendar;
import java.util.GregorianCalendar;
a55 2
import com.workingdogs.village.*;

d59 1
a59 2
import org.joist.security.RedirectException;
import org.joist.util.TagValidator;
d62 1
a62 2
import org.tigris.helm.security.HelmServlet;
import org.tigris.helm.database.ProjectNewsManager;
a63 3
import org.tigris.helm.tool.DateValidator;
import org.tigris.helm.security.AccessControlList;

d67 11
a77 7
    public static final String versionID =
        "$Id: ProjectNewsEdit.java,v 1.14 2001/01/25 02:52:28 ms Exp $";
    private static Log log = new Log ("ProjectNewsEdit", "Tigris StartPage");
    private static boolean debug = true;
    
    private static String SUBMIT_CHANGES_ACTION="Submit Changes";
    
d81 1
a81 2
  protected String
    processRequest (Connection conn, WebContext context)
d84 2
a85 5
    if (debug)
      log.info ("ProjectNewsEdit: started!");

    String templateName = super.processRequest (conn, context);
    String action = (String)context.get("action");
d87 2
a88 2
    if (debug)
        log.info ("ProjectNewsEdit: action=" + action);
d90 2
d93 37
a129 45
    // 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);
    }

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

    try
    {
      String loginUserID = getLoginUser(context).getID();
      Project currentProject = getCurrentProject(context);
      Domain currentDomain = getCurrentDomain(context);
      AccessControlList acl = getACL(context, conn, loginUserID);

      //If there is no newsID, redirect to ProjectNewsAdd
      String newsID = context.getForm ("newsID");
      if (!haveValue(newsID))
      {
          StringBuffer url = new StringBuffer("ProjectNewsAdd");
          url.append("?projectID=").append(currentProject.getID());
          redirectToURL(context, url.toString());
      }

      NewsItem newsItem = new NewsItem(conn, dMgr, newsID);

      if (action.equals("none"))
      {
          // Get current database values
	      String eventDateString = newsItem.getEventDate();
	      String publishOnString = newsItem.getPublishOn();
	      String removeOnString = newsItem.getRemoveOn();
	      String event_month = eventDateString.substring(0,2);
	      String event_day = eventDateString.substring(3,5);
	      String event_year = eventDateString.substring(6,10);
	      String publish_month = publishOnString.substring(0,2);
	      String publish_day = publishOnString.substring(3,5);
	      String publish_year = publishOnString.substring(6,10);
	      String remove_month = removeOnString.substring(0,2);
	      String remove_day = removeOnString.substring(3,5);
	      String remove_year = removeOnString.substring(6,10);
d131 46
a176 88
	      // Put current values in context for display
          context.put("newsItem", newsItem);
          context.put("event_month", event_month);
          context.put("event_day", event_day);
          context.put("event_year", event_year);
          context.put("publish_month", publish_month);
          context.put("publish_day", publish_day);
          context.put("publish_year", publish_year);
          context.put("remove_month", remove_month);
          context.put("remove_day", remove_day);
          context.put("remove_year", remove_year);

	      // If publish date has already passed, 
	      // Default to publish = "immediately"
	      if (newsItem.getPublishOnAsDate().compareTo(new Date()) <= 0)
	          context.put("publish", "immediately");
	      else
	          context.put("publish", "date");
	      
	      // If remove date is the far future date,
	      // Default to remove = "never"
	      if (remove_year.equals("3999"))
          {
	          context.put("remove", "never");
          }
	      else
          {
	          context.put("remove", "date");
          }
      }

      if (action.equals(SUBMIT_CHANGES_ACTION))
      {
          // Do update
	      // Get user-entered values
	      String event_month = context.getForm ("event_month");
	      String event_day = context.getForm ("event_day");
          String event_year = context.getForm ("event_year");
	      String publish_month = context.getForm ("publish_month");
	      String publish_day = context.getForm ("publish_day");
	      String publish_year = context.getForm ("publish_year");
	      String remove_month = context.getForm ("remove_month");
	      String remove_day = context.getForm ("remove_day");
	      String remove_year = context.getForm ("remove_year");
	      String headline = context.getForm ("headline");
	      String body = context.getForm ("body");
	      String publish = context.getForm ("publish");
	      String remove = context.getForm ("remove");
          Calendar cal = new GregorianCalendar();
          cal.setLenient(false);
          Calendar current = Calendar.getInstance();


          // Set date defaults
          // Event date and publish date default to current date
          // Remove date defaults to far future date 3999-01-01
	      Date eventDate = cal.getTime();
          Date publishOn = cal.getTime();
 	      DateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
	      Date removeOn = myFormat.parse("3999-01-01");
          
          // Format event date
          cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(event_day));
          cal.set(Calendar.MONTH, Integer.parseInt(event_month)-1);
          cal.set(Calendar.YEAR, Integer.parseInt(event_year));    
          try
          {
              eventDate = cal.getTime();
          }
          catch (IllegalArgumentException e)
          {
	          validationErrors.add("Event date is not valid.");
          }

          // Format publish date
	      // If user selected "immediately", set to today's date
          publishOn = current.getTime(); 

	      if (!publish.equals("immediately"))
	      {
              cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(publish_day));
              cal.set(Calendar.MONTH, Integer.parseInt(publish_month)-1);
              cal.set(Calendar.YEAR, Integer.parseInt(publish_year));    
              try
              {
                  publishOn = cal.getTime();
              }
              catch (IllegalArgumentException e)
d178 5
a182 1
	              validationErrors.add("Publish date is not valid.");
d184 7
a190 86
	      } 
	
	      // Format remove date
	      if (!remove.equals("never"))
	      {
              cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(remove_day));
              cal.set(Calendar.MONTH, Integer.parseInt(remove_month)-1);
              cal.set(Calendar.YEAR, Integer.parseInt(remove_year));    
              try
              {
                  removeOn = cal.getTime();
              }
              catch (IllegalArgumentException e)
              {
	              validationErrors.add("Remove date is not valid.");
              }
	      } 

          // Check for errors
	      if (!validate(context,headline, body, eventDate, publishOn, removeOn, validationErrors, missingFields))
	      {
             context.put("headline", headline);
             context.put("body", body);
	         context.put("event_month", event_month);
	         context.put("event_day", event_day);
	         context.put("event_year", event_year);
	         context.put("publish_month", publish_month);
	         context.put("publish_day", publish_day);
	         context.put("publish_year", publish_year);
	         context.put("remove_month", remove_month);
	         context.put("remove_day", remove_day);
	         context.put("remove_year", remove_year);
	         context.put("publish", publish);
	         context.put("remove", remove);
	         context.put("errors", "yes");
	         context.put("newsItem", newsItem);
          }
	      else
          {
	         // If no errors, do update
             // TODO: Remove hardcoded priority.
	         newsItem.edit(acl, newsID, eventDate, headline, body, 
	                       publishOn, removeOn, "1");

             // If user wants to send alert the announce list of change, 
             // Send email
            String sendEmail = context.getForm("send_email");
            if (sendEmail != null && sendEmail.equals("on"))
            {
	            Emailer email = new Emailer();
	            StringBuffer messageBuf = new StringBuffer();
	            String subject = "New news item added on your project";
	            messageBuf.append("A news item has been edited for project ");
	            messageBuf.append(currentProject.getName()).append(".\n");
	            messageBuf.append(headline).append("\n");
	            messageBuf.append(body);
                String rcpt = "announce@@" + currentProject.getName() + 
                               "." + currentDomain.getName();
	            email.sendEmail(rcpt, subject, messageBuf.toString());
            }

	        // Redirect to Project News page
	        StringBuffer url = new StringBuffer("ProjectNews");
            url.append("?projectID=").append(currentProject.getID());
            redirectToURL(context, url.toString());
	     }
      }


      // Put current date into context as a default
      // removeDate default is current date plus one month
      GregorianCalendar today = new GregorianCalendar();
      context.put("current_month", 
	      Integer.toString(today.get(Calendar.MONTH) +1));
      context.put("current_day", 
	      Integer.toString(today.get(Calendar.DAY_OF_MONTH)));
      context.put("current_year", 
	      Integer.toString(today.get(Calendar.YEAR)));
      today.add(Calendar.MONTH, 1);
      context.put("default_remove_month", 
          Integer.toString(today.get(Calendar.MONTH) +1));
      context.put("default_remove_day", 
	      Integer.toString(today.get(Calendar.DAY_OF_MONTH)));
      context.put("default_remove_year", 
	      Integer.toString(today.get(Calendar.YEAR)));

d194 1
a194 1
      throw e;
d199 1
a199 1
      String message = "ProjectNewsEdit: " + e.getMessage ();
d201 1
a201 1
      context.put ("message", message);
d203 3
a205 1

d209 2
a210 60

  /* Check for missing and invalid fields
  *
  */
    private boolean validate(WebContext context, String headline, 
                             String body, Date eventDate, 
			     Date publishOn, Date removeOn,
			     ArrayList validationErrors, 
			     ArrayList missingFields)
    {
        boolean validate = false;

        // Check for missing fields
	if (headline == null || headline.equals (""))
	    missingFields.add ("headline");

	if (body == null || body.equals (""))
	    missingFields.add ("body");

        // Check for invalid html tags in fields
	if (!TagValidator.validate(headline))
	{
	  validationErrors.add("Headline field contains invalid html tags.");
	}
	if (!TagValidator.validate(body))
	{
	  validationErrors.add("Body field contains invalid html tags.");
	}
	
	// Check for field values that don't make sense
	else if (removeOn.compareTo(publishOn) <= 0)
	{
	  validationErrors.add("The remove date should be at least one day after the publish date.");
	}
	else if (removeOn.compareTo(new Date()) <= 0) 
	{
	  validationErrors.add("The remove date should be later than the current date.");
	}


        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);
	}
	else
	{
	   validate = true;
	}

        context.put ("missingFields", missingFields);
        context.put ("validationErrors", validationErrors);
	return validate;
    }
}				/* end class ProjectNewsEdit */
@


1.15.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d77 1
a77 1
        "$Id: ProjectNewsEdit.java,v 1.15 2001/01/26 05:24:06 edk Exp $";
@


1.15.2.2
log
@ported to turbine
@
text
@d50 1
a50 1
import java.util.*;
d53 2
d58 1
a58 1
import org.apache.turbine.util.Log;
d60 1
d63 2
a64 1
import org.joist.security.*;
d67 6
a72 3
import org.tigris.helm.security.*;
import org.tigris.helm.om.*;
import org.tigris.helm.om.peer.*;
d76 7
a82 10
  public static final String versionID =
    "$Id: ProjectNewsEdit.java,v 1.16 2001/02/06 19:59:57 elicia Exp $";
  private static boolean debug = true;

  private static String EDIT_ACTION="Submit Changes";
  private static String ADVANCED_ACTION="Advanced Options";
  private static String HEADLINE="headline";
  private static String BODY="body";


d84 1
a84 1
     *  Display and process the Login screen.
d86 2
a87 1
  protected String processRequest (Connection conn, WebContext ctx)
d90 5
a94 2
     if (debug)
       Log.debug ("ProjectNewsAdd: started!");
d96 2
a97 2
     String templateName = super.processRequest (conn, ctx);
     String action = (String) ctx.get ("action");
a98 2
     if (debug)
        Log.debug ("ProjectNewsAdd: action=" + action);
d100 45
a144 38
     ArrayList missingFields = new ArrayList ();
     ArrayList validationErrors = new ArrayList ();

     try
     {
        Project currentProject = getCurrentProject(ctx);
        User loginUser = getLoginUser(ctx);
        AccessControlList acl = loginUser.getACL();
        Domain currentDomain = getCurrentDomain(ctx);
      
        // Get current newsItem to edit
        String newsID = ctx.getForm("newsID");
        if (newsID == null)
        {  
            redirectToURL(ctx, "ProjectNewsAdd");
        }
        NewsItem newsItem = (NewsItem)NewsItemPeer.getInstance(newsID);
        ctx.put("newsItem", newsItem);

        // Put current date into ctx as a default
        GregorianCalendar today = new GregorianCalendar();
        String currentMonth = 
		    Integer.toString(today.get(Calendar.MONTH) +1);
        String currentDay = 
		    Integer.toString(today.get(Calendar.DAY_OF_MONTH));
        String currentYear = 
		    Integer.toString(today.get(Calendar.YEAR));
        ctx.put("current_month", currentMonth);
        ctx.put("current_day", currentDay);
        ctx.put("current_year", currentYear);

        if (action.equals("none"))
        {
            // Get current database values
	        String eventDateString = newsItem.getEventDate().toString();
	        String event_month = eventDateString.substring(0,2);
	        String event_day = eventDateString.substring(3,5);
	        String event_year = eventDateString.substring(6,10);
d146 88
a233 46
	        // Put current values in ctx for display
            ctx.put("newsItem", newsItem);
            ctx.put("event_month", event_month);
            ctx.put("event_day", event_day);
            ctx.put("event_year", event_year);
        }


        if (action.equals (EDIT_ACTION) || action.equals(ADVANCED_ACTION))
        {
            // Do edit

	        // Get user-entered values
            String headline = processField(ctx, HEADLINE, "Headline", 
                                           missingFields);
            String body = processField(ctx, BODY, "Body", 
                                       missingFields);
            String eventMonth = processField(ctx, "event_month");
            String eventDay = processField(ctx, "event_day");
            String eventYear = processField(ctx, "event_year");

           // Handle dates
           Date eventDate = null;

           // Format user-entered event date
           Calendar cal = new GregorianCalendar();
           cal.setLenient(false);
           cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(eventDay));
           cal.set(Calendar.MONTH, Integer.parseInt(eventMonth)-1);
           cal.set(Calendar.YEAR, Integer.parseInt(eventYear));    

           try
           {
               eventDate = cal.getTime();
           }
           catch (IllegalArgumentException e)
           {
	           validationErrors.add("Event date is not valid.");
           }

           if (isValidUserInput(missingFields, validationErrors))
           {
	          newsItem.edit(acl, eventDate, headline, body, 
                            null, null, null);
              String url = null;
              if (action.equals(EDIT_ACTION))
d235 1
a235 5
                  url = currentProject.getProjectPageURL("ProjectNews");
              }  else {
                  StringBuffer urlBuf = new StringBuffer("ProjectNewsEditAdvanced");
                  urlBuf.append("?newsID=").append(newsItem.getID());
                  url = urlBuf.toString();
d237 86
a322 7
              redirectToURL(ctx, url);
           } else {
              reportInvalidUserInput(ctx, missingFields, 
                                     validationErrors);
	          ctx.put("errors", "yes");
           }
        } 
d326 1
a326 1
       throw e;
d330 4
a333 4
      Log.error (e);
      String message = "ProjectNewsAdd: " + e.getMessage ();
      if (debug) Log.info (message);
      ctx.put ("message", message);
d335 1
a335 3
    
    if (debug) Log.debug ("ProjectNewsAdd:  done");
    
d339 60
a398 2
      
}				/* end class ProjectNews */
@


1.15.2.3
log
@Normalized copyright dates.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d70 1
a70 1
    "$Id: ProjectNewsEdit.java,v 1.15.2.2 2001/02/10 01:50:15 elicia Exp $";
@


1.15.2.4
log
@Added new imports necessitated by Torque.
@
text
@a65 1
import org.tigris.helm.om.base.*;
d70 1
a70 1
    "$Id: ProjectNewsEdit.java,v 1.15.2.3 2001/02/15 20:50:42 leonardr Exp $";
@


1.15.2.5
log
@split into ProjectNewsEdit and ProjectNewsEditAdvanced
@
text
@d2 1
a2 1
 * Copyright (c) 2000 CollabNet.  All rights reserved.
d68 1
a68 1
public class ProjectNewsEdit extends HelmServlet
d71 1
a71 1
    "$Id: ProjectNewsEdit.java,v 1.15.2.4 2001/02/16 03:01:34 dlr Exp $";
d81 1
a81 1
     *  Display and process the login screen.
d126 15
d181 1
a181 1
                  url = currentProject.getProjectPageURL("ProjectNewsList");
d193 1
a193 15
        } else {
 
            // No action
            // Get current database values
	        String eventDateString = newsItem.getEventDate().toString();
	        String event_month = eventDateString.substring(5,7);
	        String event_day = eventDateString.substring(8,10);
	        String event_year = eventDateString.substring(0,4);
	  
	        // Put current values in ctx for display
            ctx.put("newsItem", newsItem);
            ctx.put("event_month", event_month);
            ctx.put("event_day", event_day);
            ctx.put("event_year", event_year);
        }
@


1.14
log
@Integrated TagValidator with the form-input in the servlets so that when a
form says "no html here" it actually checks the input for html, and if it allows HTML then checks it for some releative sanity.
These changes require you to update joist also for changes in TagValidator.
@
text
@d77 1
a77 1
        "$Id: ProjectNewsEdit.java,v 1.13 2001/01/25 01:58:30 lucas Exp $";
d128 1
a128 1
      NewsItem newsItem = new NewsItem(dMgr, newsID);
@


1.13
log
@updated to use new NewsItem cxtr
@
text
@d77 1
a77 1
        "$Id: ProjectNewsEdit.java,v 1.12 2001/01/08 23:25:03 dlr Exp $";
d359 1
a359 2
        TagValidator tag = new TagValidator();
	if (!tag.validate(headline, new StringBuffer()))
d363 1
a363 1
	else if (!tag.validate(body, new StringBuffer()))
@


1.12
log
@Corrected a bunch of regressions to previous User instantion method.  Deprecated User's getUserID() method in favor of getID() for better conformance with BusinessObject interface and orthoginality with other business objects.  Added a guest user and interface.  Added some JavaDoc to User.
@
text
@d77 1
a77 1
        "$Id: ProjectNewsEdit.java,v 1.11 2000/12/27 23:33:30 brian Exp $";
d128 1
a128 1
      NewsItem newsItem = new NewsItem(conn, dMgr, newsID);
@


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

Genericize.
@
text
@d77 1
a77 1
        "$Id: ProjectNewsEdit.java,v 1.10 2000/12/15 00:27:29 elicia Exp $";
d114 1
a114 1
      String loginUserID = getLoginUser(context).getUserID();
@


1.10
log
@checking user input box about whether to send an email regarding update
@
text
@d77 1
a77 1
        "$Id: ProjectNewsEdit.java,v 1.9 2000/12/12 23:05:24 elicia Exp $";
d288 1
a288 1
	            String subject = "New news item added on your SourceCast project";
@


1.9
log
@updated to use Calendar instead of Date
@
text
@d77 1
a77 1
        "$Id: ProjectNewsEdit.java,v 1.8 2000/12/07 02:30:36 elicia Exp $";
d284 1
a284 1
            if (sendEmail.equals("on"))
@


1.8
log
@only sending announcement to list for new news item if item is published immediately.

On edit, send edit announcement if user checks checkbox
@
text
@d52 1
a52 1
import java.text.DateFormat;
d54 1
a54 1
import java.text.SimpleDateFormat;
d77 1
a77 1
        "$Id: ProjectNewsEdit.java,v 1.7 2000/11/28 21:57:29 elicia Exp $";
d133 12
a144 12
	  String eventDateString = newsItem.getEventDate();
	  String publishOnString = newsItem.getPublishOn();
	  String removeOnString = newsItem.getRemoveOn();
	  String event_month = eventDateString.substring(0,2);
	  String event_day = eventDateString.substring(3,5);
	  String event_year = eventDateString.substring(6,10);
	  String publish_month = publishOnString.substring(0,2);
	  String publish_day = publishOnString.substring(3,5);
	  String publish_year = publishOnString.substring(6,10);
	  String remove_month = removeOnString.substring(0,2);
	  String remove_day = removeOnString.substring(3,5);
	  String remove_year = removeOnString.substring(6,10);
d146 1
a146 1
	  // Put current values in context for display
d158 6
a163 6
	  // If publish date has already passed, 
	  // Default to publish = "immediately"
	  if (newsItem.getPublishOnAsDate().compareTo(new Date()) <= 0)
	      context.put("publish", "immediately");
	  else
	      context.put("publish", "date");
d165 10
a174 6
	  // If remove date is the far future date,
	  // Default to remove = "never"
	  if (remove_year.equals("3999"))
	      context.put("remove", "never");
	  else
	      context.put("remove", "date");
d179 101
a279 81
        // Do update
	// Get user-entered values
        DateValidator validDate = new DateValidator();
	DateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
	StringBuffer dateBuf = new StringBuffer();
	String event_month = context.getForm ("event_month");
	String event_day = context.getForm ("event_day");
	String event_year = context.getForm ("event_year");
	String publish_month = context.getForm ("publish_month");
	String publish_day = context.getForm ("publish_day");
	String publish_year = context.getForm ("publish_year");
	String remove_month = context.getForm ("remove_month");
	String remove_day = context.getForm ("remove_day");
	String remove_year = context.getForm ("remove_year");
	String headline = context.getForm ("headline");
	String body = context.getForm ("body");
	String publish = context.getForm ("publish");
	String remove = context.getForm ("remove");
	Date eventDate, publishOn, removeOn;

        // Format event date
	dateBuf.append(event_year).append("-");
	dateBuf.append(event_month).append("-").append(event_day);
	if (!validDate.isDateValid(event_month, event_day, event_year))
	    validationErrors.add("Invalid event date.");
        eventDate = myFormat.parse(dateBuf.toString());

	// Format publish date
	// If user selected "immediately", set to today's date
	if (publish.equals("immediately"))
	{
	  DateFormat currentFormat = 
	      new SimpleDateFormat("EEE MMM dd kk:mm:ss z yyyy");
	  publishOn = currentFormat.parse(new Date().toString());
	} else {
	  dateBuf = new StringBuffer();
	  dateBuf.append(publish_year).append("-");
	  dateBuf.append(publish_month).append("-").append(publish_day);
	  if (!validDate.isDateValid(publish_month, publish_day, publish_year))
	      validationErrors.add("Invalid publish date.");
	  publishOn = myFormat.parse(dateBuf.toString());
	}

	// Format remove date
	// If user selected "never", set to far future date(1-1-3999)
	if (remove.equals("never"))
	{
	    removeOn = myFormat.parse("3999-01-01");
	} else {
	    dateBuf = new StringBuffer();
            dateBuf.append(remove_year).append("-");
	    dateBuf.append(remove_month).append("-").append(remove_day);
	    if (!validDate.isDateValid(remove_month, remove_day, remove_year))
	        validationErrors.add("Invalid remove date.");
	    removeOn = myFormat.parse(dateBuf.toString());
	 }

        // Check for errors
	if (!validate(context,headline, body, eventDate, publishOn, removeOn, validationErrors, missingFields))
	{
            context.put("headline", headline);
            context.put("body", body);
	    context.put("event_month", event_month);
	    context.put("event_day", event_day);
	    context.put("event_year", event_year);
	    context.put("publish_month", publish_month);
	    context.put("publish_day", publish_day);
	    context.put("publish_year", publish_year);
	    context.put("remove_month", remove_month);
	    context.put("remove_day", remove_day);
	    context.put("remove_year", remove_year);
	    context.put("publish", publish);
	    context.put("remove", remove);
	    context.put("errors", "yes");
	    context.put("newsItem", newsItem);
        }
	else {
	    // If no errors, do update
            // TODO: Remove hardcoded priority.
	    newsItem.edit(acl, newsID, eventDate, headline, body, 
	                  publishOn, removeOn, "1");
d281 2
a282 1
            // If user wants to send alert the announce list of change, send email
d286 10
a295 9
	         Emailer email = new Emailer();
	         StringBuffer messageBuf = new StringBuffer();
	         String subject = "New news item added on your SourceCast project";
	         messageBuf.append("A news item has been edited for project ");
	         messageBuf.append(currentProject.getName()).append(".\n");
	         messageBuf.append(headline).append("\n");
	         messageBuf.append(body);
                 String rcpt = "announce@@" + currentProject.getName() + "." + currentDomain.getName();
	         email.sendEmail(rcpt, subject, messageBuf.toString());
d298 2
a299 2
	    // Redirect to Project News page
	    StringBuffer url = new StringBuffer("ProjectNews");
d302 1
a302 1
	}
d305 1
d307 2
a308 2
      // removedate default is current date plus one month
      Calendar current = Calendar.getInstance();
d310 1
a310 1
          Integer.toString(current.get(Calendar.MONTH) +1));
d312 1
a312 1
          Integer.toString(current.get(Calendar.DAY_OF_MONTH)));
d314 2
a315 1
          Integer.toString(current.get(Calendar.YEAR)));
d317 5
a321 1
          Integer.toString(current.get(Calendar.MONTH) +2));
@


1.7
log
@now pre-populating fields with either database values, or user-entered values in the case of an error, or default values in the case of a first-time add
@
text
@d65 1
d69 1
a69 1
import org.tigris.helm.domain.NewsItem;
d77 1
a77 1
        "$Id: ProjectNewsEdit.java,v 1.6 2000/11/23 03:42:11 edk Exp $";
d116 1
d256 15
@


1.6
log
@this wasn't even compiling ... hopefully this change is sufficient
to make it work.
@
text
@a49 1
import java.io.*;
d52 2
d62 3
a64 3
import org.webmacro.engine.*;
import org.webmacro.broker.*;
import org.webmacro.resource.*;
d69 1
a69 1
import org.joist.security.RedirectException;
d76 1
a76 1
        "$Id: ProjectNewsEdit.java,v 1.5 2000/11/22 23:50:14 leonardr Exp $";
a97 1
    String newsID = context.getForm ("newsID");
a98 5

    ProjectNewsManager newsMgr = (ProjectNewsManager)
      getDataManager (context).getManager
      ("org.tigris.helm.database.ProjectNewsManager");
  
d113 12
a124 3
        String loginUserID = getLoginUser(context).getUserID();
        Project currentProject = getCurrentProject(context);
        AccessControlList acl = getACL(context, conn, loginUserID);
d126 1
d130 1
a130 9
          //If there is no newsId, redirect to ProjectNewsAdd
          if (!haveValue(newsID))
          {
	      StringBuffer url = new StringBuffer("ProjectNewsAdd");
              url.append("?projectID=").append(currentProject.getID());
              redirectToURL(context, url.toString());
          }

          NewsItem newsItem = new NewsItem(conn, dMgr, newsID);
d136 1
a136 1
	  String event_year = eventDateString.substring(6,8);
d139 1
a139 1
	  String publish_year = publishOnString.substring(6,8);
d142 3
a144 1
	  String remove_year = removeOnString.substring(6,8);
d155 14
d173 4
a176 1
	java.text.DateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
d178 14
a191 3
        String month;
	String day;
	String year;
d194 5
a198 5
	month = context.getForm ("event_month");
	day = context.getForm ("event_day");
	year = context.getForm ("event_year");
	dateBuf.append(year).append("-").append(month).append("-").append(day);
	Date eventDate = myFormat.parse(dateBuf.toString());
d201 14
a214 6
	month = context.getForm ("publish_month");
	day = context.getForm ("publish_day");
	year = context.getForm ("publish_year");
	dateBuf = new StringBuffer();
	dateBuf.append(year).append("-").append(month).append("-").append(day);
	Date publishOn = myFormat.parse(dateBuf.toString());
d217 12
a228 12
	month = context.getForm ("remove_month");
	day = context.getForm ("remove_day");
	year = context.getForm ("remove_year");
	dateBuf = new StringBuffer();
	dateBuf.append(year).append("-").append(month).append("-").append(day);
	Date removeOn = myFormat.parse(dateBuf.toString());

	String headline = context.getForm ("headline");
	if (headline == null || headline.equals (""))
	    missingFields.add ("headline");
	else
	    context.put ("headline", headline);
d230 2
a231 13
	String body = context.getForm ("body");
	if (body == null || body.equals (""))
	    missingFields.add ("body");
	else
	    context.put ("body", body);

	if (!missingFields.isEmpty ())
	{
	  appendToMessage (context, "Missing Fields", missingFields);
	  if (debug)
	    log.info ("Missing Fields: " + missingFields.toString ());
	}
	else if (!validationErrors.isEmpty ())
d233 19
a251 8
	  appendToMessage (context, "Validation Errors", validationErrors);
	  if (debug)
	    log.info ("Validation Errors: " + validationErrors.toString ());
	}
	else
	{
            // TODO: Remove hardcoded dates.
	    NewsItem newsItem = new NewsItem(conn, dMgr, newsID);
d254 2
d261 17
d283 1
a283 2
      if (debug)
	log.info (message);
d287 21
d309 20
a328 2
    if (debug)
      log.info ("ProjectNewsEdit:  done");
a329 2
    context.put ("missingFields", missingFields);
    context.put ("validationErrors", validationErrors);
d331 14
a344 2
    return templateName;
  }
d346 4
@


1.5
log
@Some preemptive button name changes.
@
text
@d75 1
a75 1
        "$Id: ProjectNewsEdit.java,v 1.4 2000/11/22 02:18:34 elicia Exp $";
d79 1
a79 1
    private static SUBMIT_CHANGES_ACTION="Submit Changes";
@


1.4
log
@modernized files--using NewsItem business object
@
text
@d74 7
a80 5
  public static final String versionID =
    "$Id: ProjectNewsEdit.java,v 1.3 2000/11/15 21:12:14 elicia Exp $";
  private static Log log = new Log ("ProjectNewsEdit", "Tigris StartPage");
  private static boolean debug = true;

d158 1
a158 1
      if (action.equals("Edit News Item"))
@


1.3
log
@using currentProject.getID() instead of getting projectID from the Form.
@
text
@d75 1
a75 1
    "$Id: ProjectNewsEdit.java,v 1.2 2000/11/15 00:04:41 dlr Exp $";
d83 1
a83 1
    processRequest (Connection connection, WebContext context)
d89 1
a89 1
    String templateName = super.processRequest (connection, context);
d118 1
a118 1
        AccessControlList acl = getACL(context, connection, loginUserID);
d131 23
a153 17
          DataSet newsItemSet = newsMgr.getNewsItem(connection, newsID);
          if (!newsItemSet.containsRecord(0))
          {
              appendToMessage(context, "News item does not exist.");
          } else 
          {
              Record r = newsItemSet.getRecord(0);
              NewsItem newsItem = new NewsItem(connection, dMgr, r);
	      String eventDateString = newsItem.getEventDate();
	      String month = eventDateString.substring(0,2);
	      String day = eventDateString.substring(3,5);
	      String year = eventDateString.substring(6,8);
              context.put("newsItem", newsItem);
              context.put("month", month);
              context.put("day", day);
              context.put("year", year);
          }
a157 3
	String month = context.getForm ("month");
	String day = context.getForm ("day");
	String year = context.getForm ("year");
d160 8
d171 16
d214 3
a216 4
	    newsMgr.updateNews (connection, acl, newsID, currentProject.getID(),
				eventDate, headline, body, "1",
				"2000-12-01 01:01:01",
				"2000-12-24 01:01:01", "1");
@


1.2
log
@Added TODO item for later.
@
text
@d75 1
a75 1
    "$Id: ProjectNewsEdit.java,v 1.1.1.1 2000/11/12 21:16:16 dlr Exp $";
a94 4
    // Get the userID of the person who logged in.
    String loginUserID = (String) context.get ("loginUserID");

    String projectID = context.getForm ("projectID");
a96 9
    //If there is no newsId, redirect to ProjectNewsAdd
    if (!haveValue(newsID))
    {
	StringBuffer url = new StringBuffer("ProjectNewsAdd");
        url.append("?projectID=").append(projectID);
        redirectToURL(context, url.toString());
    }

    Project project = getCurrentProject(context);
d116 4
d123 8
a185 1
            AccessControlList acl = getACL(context, connection);
d187 1
a187 1
	    newsMgr.updateNews (connection, acl, newsID, projectID,
d192 1
a192 1
            url.append("?projectID=").append(projectID);
@


1.1
log
@Initial revision
@
text
@d75 1
a75 1
    "$Id: ProjectNewsEdit.java,v 1.2 2000/11/11 03:33:33 dlr Exp $";
d188 1
@


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 2
a51 1
import java.util.*;
d53 1
a53 1
import java.text.*;
d57 1
a57 1
import org.apache.turbine.util.Log;
d59 1
d61 9
a70 2
import org.joist.security.*;
import org.joist.mail.Emailer;
d72 1
a72 6
import org.tigris.helm.security.*;
import org.tigris.helm.om.*;
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;

public class ProjectNewsEdit extends HelmServlet
d75 2
a76 1
    "$Id: ProjectNewsEdit.java,v 1.15.2.5 2001/02/17 00:16:39 elicia Exp $";
a78 6
  private static String EDIT_ACTION="Submit Changes";
  private static String ADVANCED_ACTION="Advanced Options";
  private static String HEADLINE="headline";
  private static String BODY="body";


d82 2
a83 1
  protected String processRequest (Connection conn, WebContext ctx)
d86 8
a93 2
     if (debug)
       Log.debug ("ProjectNewsAdd: started!");
d95 2
a96 2
     String templateName = super.processRequest (conn, ctx);
     String action = (String) ctx.get ("action");
d98 2
a99 2
     if (debug)
        Log.debug ("ProjectNewsAdd: action=" + action);
d101 6
a106 98
     ArrayList missingFields = new ArrayList ();
     ArrayList validationErrors = new ArrayList ();

     try
     {
        Project currentProject = getCurrentProject(ctx);
        User loginUser = getLoginUser(ctx);
        AccessControlList acl = loginUser.getACL();
        Domain currentDomain = getCurrentDomain(ctx);
      
        // Get current newsItem to edit
        String newsID = ctx.getForm("newsID");
        if (newsID == null)
        {  
            redirectToURL(ctx, "ProjectNewsAdd");
        }
        NewsItem newsItem = (NewsItem)NewsItemPeer.getInstance(newsID);
        ctx.put("newsItem", newsItem);

        // Put current date into ctx as a default
        GregorianCalendar today = new GregorianCalendar();
        String currentMonth = 
		    Integer.toString(today.get(Calendar.MONTH) +1);
        String currentDay = 
		    Integer.toString(today.get(Calendar.DAY_OF_MONTH));
        String currentYear = 
		    Integer.toString(today.get(Calendar.YEAR));
        ctx.put("current_month", currentMonth);
        ctx.put("current_day", currentDay);
        ctx.put("current_year", currentYear);


        if (action.equals (EDIT_ACTION) || action.equals(ADVANCED_ACTION))
        {
            // Do edit

	        // Get user-entered values
            String headline = processField(ctx, HEADLINE, "Headline", 
                                           missingFields);
            String body = processField(ctx, BODY, "Body", 
                                       missingFields);
            String eventMonth = processField(ctx, "event_month");
            String eventDay = processField(ctx, "event_day");
            String eventYear = processField(ctx, "event_year");

           // Handle dates
           Date eventDate = null;

           // Format user-entered event date
           Calendar cal = new GregorianCalendar();
           cal.setLenient(false);
           cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(eventDay));
           cal.set(Calendar.MONTH, Integer.parseInt(eventMonth)-1);
           cal.set(Calendar.YEAR, Integer.parseInt(eventYear));    

           try
           {
               eventDate = cal.getTime();
           }
           catch (IllegalArgumentException e)
           {
	           validationErrors.add("Event date is not valid.");
           }

           if (isValidUserInput(missingFields, validationErrors))
           {
	          newsItem.edit(acl, eventDate, headline, body, 
                            null, null, null);
              String url = null;
              if (action.equals(EDIT_ACTION))
              {
                  url = currentProject.getProjectPageURL("ProjectNewsList");
              }  else {
                  StringBuffer urlBuf = new StringBuffer("ProjectNewsEditAdvanced");
                  urlBuf.append("?newsID=").append(newsItem.getID());
                  url = urlBuf.toString();
              }
              redirectToURL(ctx, url);
           } else {
              reportInvalidUserInput(ctx, missingFields, 
                                     validationErrors);
	          ctx.put("errors", "yes");
           }
        } else {
 
            // No action
            // Get current database values
	        String eventDateString = newsItem.getEventDate().toString();
	        String event_month = eventDateString.substring(5,7);
	        String event_day = eventDateString.substring(8,10);
	        String event_year = eventDateString.substring(0,4);
	  
	        // Put current values in ctx for display
            ctx.put("newsItem", newsItem);
            ctx.put("event_month", event_month);
            ctx.put("event_day", event_day);
            ctx.put("event_year", event_year);
        }
d108 11
a118 1
    catch (RedirectException e)
d120 77
a196 1
       throw e;
d200 5
a204 4
      Log.error (e);
      String message = "ProjectNewsAdd: " + e.getMessage ();
      if (debug) Log.info (message);
      ctx.put ("message", message);
d206 8
a213 3
    
    if (debug) Log.debug ("ProjectNewsAdd:  done");
    
d215 1
d217 1
a217 3
  }
      
}				/* end class ProjectNews */
@

