head	1.39;
access;
symbols
	TIGRIS_1_1_0RC2:1.28
	TIGRIS_1_1_0RC1:1.28
	TIGRIS_1_1:1.28.0.4
	TIGRIS_1_0_8:1.28
	TIGRIS_1_0_8RC3:1.28
	TIGRIS_1_0_8RC2:1.28
	TIGRIS_1_0_8RC1:1.28
	TIGRIS_1_0_7:1.28
	TIGRIS_1_0_7RC3:1.28
	TIGRIS_1_0_7RC2:1.28
	TIGRIS_1_0_7RC1:1.28
	TIGRIS_1_0_6:1.28
	TIGRIS_1_0_6RC5:1.28
	TIGRIS_1_0_6RC4:1.28
	TIGRIS_1_0_6RC3:1.28
	TIGRIS_1_0_6RC2:1.28
	TIGRIS_1_0_6RC1:1.28
	TIGRIS_1_0_5:1.28
	TIGRIS_1_0_5RC6:1.28
	TIGRIS_1_0_5RC5:1.28
	TIGRIS_1_0_5RC4:1.28
	TIGRIS_1_0_5RC3:1.28
	TIGRIS_1_0_5RC2:1.28
	TIGRIS_1_0_5RC1:1.28
	TIGRIS_1_0_4:1.28
	TIGRIS_1_0_3:1.28
	TIGRIS_1_0_2:1.28
	TIGRIS_1_0_1:1.28
	TIGRIS_1_0:1.28.0.6
	TIGRIS_1_0_0:1.28
	TIGRIS_1_0_0_RC1:1.28.0.2
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.20
	TIGRIS_0_9_2_3:1.20
	HELM_PEER_PORT_BRANCH:1.1.1.2
	TURBINE_PEER:1.21
	TIGRIS_0_9_2_1:1.21
	TIGRIS_0_9_2:1.20.0.2
	TIGRIS_0_9_0:1.16.0.2
	TIGRIS_0_8_4:1.14.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.39
date	2001.08.11.09.08.07;	author dlr;	state Exp;
branches;
next	1.38;

1.38
date	2001.07.19.19.08.43;	author dlr;	state Exp;
branches;
next	1.37;

1.37
date	2001.07.18.10.05.14;	author dlr;	state Exp;
branches;
next	1.36;

1.36
date	2001.07.17.20.10.49;	author leonardr;	state Exp;
branches;
next	1.35;

1.35
date	2001.06.02.01.17.00;	author elicia;	state Exp;
branches;
next	1.34;

1.34
date	2001.05.25.19.50.26;	author dlr;	state Exp;
branches;
next	1.33;

1.33
date	2001.05.23.01.50.15;	author dlr;	state Exp;
branches;
next	1.32;

1.32
date	2001.05.23.01.22.12;	author ms;	state Exp;
branches;
next	1.31;

1.31
date	2001.05.23.00.47.31;	author ms;	state Exp;
branches;
next	1.30;

1.30
date	2001.05.23.00.43.49;	author ms;	state Exp;
branches;
next	1.29;

1.29
date	2001.05.22.19.16.02;	author ms;	state Exp;
branches;
next	1.28;

1.28
date	2001.03.14.00.54.42;	author elicia;	state Exp;
branches;
next	1.27;

1.27
date	2001.03.02.16.47.56;	author leonardr;	state Exp;
branches;
next	1.26;

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

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

1.24
date	2001.02.21.01.08.23;	author dlr;	state Exp;
branches;
next	1.23;

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

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

1.21
date	2001.01.25.02.52.28;	author ms;	state Exp;
branches
	1.21.2.1;
next	1.20;

1.20
date	2001.01.08.23.25.03;	author dlr;	state Exp;
branches
	1.20.2.1;
next	1.19;

1.19
date	2000.12.27.23.33.30;	author brian;	state Exp;
branches;
next	1.18;

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

1.17
date	2000.12.22.21.05.35;	author elicia;	state Exp;
branches;
next	1.16;

1.16
date	2000.12.12.22.25.26;	author elicia;	state Exp;
branches
	1.16.2.1;
next	1.15;

1.15
date	2000.12.07.02.30.36;	author elicia;	state Exp;
branches;
next	1.14;

1.14
date	2000.12.04.03.39.33;	author jrobbins;	state Exp;
branches;
next	1.13;

1.13
date	2000.12.04.02.14.02;	author jrobbins;	state Exp;
branches;
next	1.12;

1.12
date	2000.11.28.21.57.29;	author elicia;	state Exp;
branches;
next	1.11;

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

1.10
date	2000.11.22.21.10.26;	author dlr;	state Exp;
branches;
next	1.9;

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

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

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

1.6
date	2000.11.17.02.50.40;	author elicia;	state Exp;
branches;
next	1.5;

1.5
date	2000.11.16.04.12.54;	author elicia;	state Exp;
branches;
next	1.4;

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

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

1.2
date	2000.11.14.00.53.32;	author elicia;	state Exp;
branches;
next	1.1;

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

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

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

1.16.2.1
date	2000.12.23.00.36.14;	author jrobbins;	state Exp;
branches;
next	;

1.20.2.1
date	2001.03.15.19.30.58;	author susank;	state Exp;
branches;
next	1.20.2.2;

1.20.2.2
date	2001.03.15.19.34.55;	author susank;	state Exp;
branches;
next	;

1.21.2.1
date	2001.01.28.01.02.18;	author dlr;	state dead;
branches;
next	1.21.2.2;

1.21.2.2
date	2001.02.10.00.04.30;	author elicia;	state Exp;
branches;
next	1.21.2.3;

1.21.2.3
date	2001.02.10.01.50.15;	author elicia;	state Exp;
branches;
next	1.21.2.4;

1.21.2.4
date	2001.02.12.23.27.57;	author elicia;	state Exp;
branches;
next	1.21.2.5;

1.21.2.5
date	2001.02.13.22.45.45;	author elicia;	state Exp;
branches;
next	1.21.2.6;

1.21.2.6
date	2001.02.14.23.20.29;	author leonardr;	state Exp;
branches;
next	1.21.2.7;

1.21.2.7
date	2001.02.15.20.50.42;	author leonardr;	state Exp;
branches;
next	1.21.2.8;

1.21.2.8
date	2001.02.16.01.25.14;	author elicia;	state Exp;
branches;
next	1.21.2.9;

1.21.2.9
date	2001.02.17.00.16.15;	author elicia;	state Exp;
branches;
next	1.21.2.10;

1.21.2.10
date	2001.02.17.20.09.56;	author elicia;	state Exp;
branches;
next	1.21.2.11;

1.21.2.11
date	2001.02.20.02.21.13;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.39
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
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.http.HttpSession;

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.security.*;
import org.tigris.helm.om.*;
import org.tigris.helm.tool.TemplateTool;
import org.tigris.helm.tool.ContextAPI;

public class ProjectNewsAdd extends HelmServlet
{
    private static final boolean DEBUG = true;

    private static String ADD_ACTION="Add News Item";
    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";

    protected String processRequest(Context context)
        throws NestableException, RedirectException
    {
        String templateName = super.processRequest(context);
        String action = getAction(context);

        int day, month, year;

        try
        {
            Project currentProject = getCurrentProject(context);
            User loginUser = getLoginUser(context);
            AccessControlList acl = loginUser.getACL();
            Domain currentDomain = getCurrentDomain(context);
          
            // 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));

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

            if (action != null && !action.equals("none"))
            {      
               // Handle date
               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))
               {
                  String redirectURL = null;

                  if (action.equals (ADD_ACTION)) 
                  {
                      // Do add
                      Date publishDate = null;
                      Date removeDate = null;
                      // Set publish date to current date
                      // Set Remove date far future date 3999-01-01
                      Calendar current = Calendar.getInstance();
                      DateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
                      publishDate = current.getTime();
                      removeDate = myFormat.parse("3999-01-01");
 
                      // TODO: Remove hardcoded priority.
                      NewsItem newsItem = NewsItem.add
                          (acl, currentProject, eventDate, headline,
                          body, publishDate, removeDate, 1, imageUrl,
                          articleUrl);

                      redirectURL =
                          currentProject.getProjectPageURL("ProjectNewsList");

                  } else if (action.equals(ADVANCED_ACTION)) {
                      HttpSession session =
                          getSessionManager(context).getSession();
                      session.putValue(HEADLINE, headline); 
                      session.putValue(BODY, body); 
                      session.putValue(IMAGE_URL, imageUrl); 
                      session.putValue(ARTICLE_URL, articleUrl); 
                      session.putValue("eventDate", eventDate); 
                      
                      redirectURL = currentProject.getProjectPageURL
                          ("ProjectNewsAddAdvanced");
                  }
                  redirectToURL(context, redirectURL);
      
               } else {
                   context.put("errors", "yes");
               }
         }
    }
    catch (RedirectException e)
    {
       throw e;
    }
    catch (Exception e)
    {
      Log.error(e);
      throw new NestableException(e);
    }
    
    return templateName;
  }
}
@


1.38
log
@Updated to use Helm URL class (just ported from Joist).
@
text
@d55 1
a55 1
import org.apache.turbine.util.TurbineException;
d78 1
a78 1
        throws TurbineException, RedirectException
d206 1
a206 1
      throw new TurbineException(e);
@


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


1.36
log
@Ported servlets to new error-handling mechanism.
@
text
@a50 1
import java.util.Date;
d52 1
a52 3
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
a55 1
import org.apache.turbine.services.velocity.TurbineVelocity;
a58 1
import org.joist.security.*;
d68 1
a68 1
    private static boolean DEBUG = true;
@


1.35
log
@added imageURL and original article URL fields
@
text
@d69 1
d82 1
a82 1
    protected String processRequest(Context ctx)
d85 2
a86 2
        String templateName = super.processRequest(ctx);
        String action = getAction(ctx);
a87 2
        List missingFields = new ArrayList ();
        List validationErrors = new ArrayList ();
d92 2
a93 2
            Project currentProject = getCurrentProject(ctx);
            User loginUser = getLoginUser(ctx);
d95 1
a95 1
            Domain currentDomain = getCurrentDomain(ctx);
d97 1
a97 1
            // Put current date into ctx as a default
d109 2
a110 2
                ctx.put("isDecember", "");
                eventYear = processField(ctx, "event_year");
d116 4
a119 4
            ctx.put("current_month", currentMonth);
            ctx.put("current_day", currentDay);
            ctx.put("current_year", currentYear);
            ctx.put("next_year", Integer.toString(++year));
d122 8
a129 7
            String headline = processField(ctx, HEADLINE, "Headline", 
                                           missingFields);
            String body = processField(ctx, BODY);
            String imageUrl = processField(ctx, IMAGE_URL);
            String articleUrl = processField(ctx, ARTICLE_URL);
            String eventMonth = processField(ctx, "event_month");
            String eventDay = processField(ctx, "event_day");
d148 2
a149 1
                   validationErrors.add("Event date is not valid.");
d155 3
a157 1
                  validationErrors.add("Please provide a valid original article URL."); 
d160 1
a160 1
               if (isValidUserInput(missingFields, validationErrors))
d187 1
a187 1
                          getSessionManager(ctx).getSession();
d197 1
a197 1
                  redirectToURL(ctx, redirectURL);
d200 1
a200 3
                   reportInvalidUserInput(ctx, missingFields, 
                                          validationErrors);
	               ctx.put("errors", "yes");
@


1.34
log
@Removed duplicate imports and broke long lines.
@
text
@d64 1
d78 2
d125 3
a127 2
            String body = processField(ctx, BODY, "Body", 
                                           missingFields);
d151 6
d176 2
a177 1
                          body, publishDate, removeDate, 1);
d187 2
@


1.33
log
@Ported Helm from WebMacro to Velocity.
@
text
@a58 1
import org.apache.turbine.util.TurbineException;
d60 1
a60 1
import org.apache.velocity.context.Context;
a63 1
import org.joist.mail.Emailer;
d168 2
a169 1
                      redirectURL = currentProject.getProjectPageURL("ProjectNewsList");
d172 2
a173 1
                      HttpSession session = getSessionManager(ctx).getSession();
d178 2
a179 1
                      redirectURL = currentProject.getProjectPageURL("ProjectNewsAddAdvanced");
a200 1

d202 1
a202 2
      
} /* end class ProjectNews */
@


1.32
log
@fixed npe in year
@
text
@d58 5
a62 3
import org.apache.turbine.services.webmacro.TurbineWebMacro;
import org.webmacro.servlet.*;
import org.webmacro.servlet.WebContext;
d80 2
a81 2
    protected String processRequest (Connection conn, WebContext ctx)
        throws HandlerException, RedirectException
d83 1
a83 1
        String templateName = super.processRequest (conn, ctx);
d196 1
a196 1
      throw new HandlerException(e.getMessage());
@


1.31
log
@keep variables in template standard
@
text
@a98 4
            if (month == 12)
            {
                ctx.put("isDecember", "");
            }
d104 10
a125 1
            String eventYear = processField(ctx, "event_year");
@


1.30
log
@only let next year be specified in december of previous year
@
text
@d111 1
a111 1
            ctx.put("nextYear", Integer.toString(++year));
@


1.29
log
@only let year be selected in december
@
text
@d86 1
d97 1
a97 1
            int month = today.get(Calendar.MONTH) + 1;
a98 1
            // only let year be specfied in december.
d106 2
a107 2
            String currentYear = 
                Integer.toString(today.get(Calendar.YEAR));
d111 1
@


1.28
log
@changed so that news item is added after the advanced options step as per issue 3029
@
text
@d96 8
a103 2
            String currentMonth = 
                Integer.toString(today.get(Calendar.MONTH) +1);
@


1.27
log
@Code cleanup and conversion to template-based email.
@
text
@a76 2
    private static final String NEW_NEWS_ITEM_TEMPLATE=
        TemplateTool.getPathToMessageTemplate("NewNewsItem.wm");
d78 1
a78 1
    protected String processRequest (Connection conn, WebContext context)
d81 2
a82 2
        String templateName = super.processRequest (conn, context);
        String action = getAction(context);
d89 2
a90 2
            Project currentProject = getCurrentProject(context);
            User loginUser = getLoginUser(context);
d92 1
a92 1
            Domain currentDomain = getCurrentDomain(context);
d94 1
a94 1
            // Put current date into context as a default
d102 3
a104 3
            context.put("current_month", currentMonth);
            context.put("current_day", currentDay);
            context.put("current_year", currentYear);
d107 1
a107 1
            String headline = processField(context, HEADLINE, "Headline", 
d109 1
a109 1
            String body = processField(context, BODY, "Body", 
d111 7
a117 9
            String eventMonth = processField(context, "event_month");
            String eventDay = processField(context, "event_day");
            String eventYear = processField(context, "event_year");

            if (action.equals (ADD_ACTION) || action.equals(ADVANCED_ACTION))
            {
               // Do add

               // Handle dates
a118 2
               Date publishDate = null;
               Date removeDate = null;
a134 8
               // Set publish date to current date
               // Set Remove date far future date 3999-01-01
               Calendar current = Calendar.getInstance();
               DateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
               publishDate = current.getTime();
               removeDate = myFormat.parse("3999-01-01");
               
               // Check for errors
d137 3
a139 22
                  // TODO: Remove hardcoded priority.
                  NewsItem newsItem = NewsItem.add
                      (acl, currentProject, eventDate, headline,
                       body, publishDate, removeDate, 1);

                  // Send email to alert project owner of new news item.
                  // TODO: send out emails on publish date
                  Emailer email = new Emailer();
                  StringBuffer messageBuf = new StringBuffer();
                  String subject = newsItem.getProject().getName() + " news: " + newsItem.getHeadline();
                  WebContext ctx = TurbineWebMacro.getContext();
                  ctx.put("newsItem", newsItem);
                  String msgBody = TurbineWebMacro
                      .handleRequest(ctx, NEW_NEWS_ITEM_TEMPLATE);
                  Log.debug("Sending message: " + subject + "/" + msgBody);
                  String rcpt = "announce@@" + currentProject.getName() 
                      + "." + currentDomain.getName();
                  email.sendEmail(rcpt, subject, msgBody);

                  // Do redirect
                  String url = null;
                  if (action.equals(ADD_ACTION))
d141 33
a173 14
                      url = currentProject.getProjectPageURL("ProjectNewsList");
                  }  else {
                      StringBuffer urlBuf = new StringBuffer("ProjectNewsAddAdvanced");
                  urlBuf.append("?newsID=").append(newsItem.getID());
                  url = urlBuf.toString();
              }
              redirectToURL(context, url);
                  
           } else {
              reportInvalidUserInput(context, missingFields, 
                                     validationErrors);
	          context.put("errors", "yes");
           }
        } 
@


1.26
log
@Removed reference to TemplateInterpolator.
@
text
@d58 1
d67 1
d71 1
a71 1
    private static boolean debug = true;
d77 2
a78 1
    private static String NEW_NEWS_ITEM_TEMPLATE="NewNewsItem.wm";
d80 1
a80 1
    protected String processRequest (Connection conn, WebContext ctx)
d83 2
a84 2
        if (debug)
            Log.debug ("ProjectNewsAdd: started!");
d86 2
a87 8
        String templateName = super.processRequest (conn, ctx);
        String action = (String) ctx.get ("action");

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

        ArrayList missingFields = new ArrayList ();
        ArrayList validationErrors = new ArrayList ();
d91 2
a92 2
            Project currentProject = getCurrentProject(ctx);
            User loginUser = getLoginUser(ctx);
d94 1
a94 2
            Domain currentDomain = getCurrentDomain(ctx);
            HttpSession session = ctx.getSession();
d96 1
a96 1
            // Put current date into ctx as a default
d104 3
a106 3
            ctx.put("current_month", currentMonth);
            ctx.put("current_day", currentDay);
            ctx.put("current_year", currentYear);
d109 1
a109 1
            String headline = processField(ctx, HEADLINE, "Headline", 
d111 1
a111 1
            String body = processField(ctx, BODY, "Body", 
d113 3
a115 3
            String eventMonth = processField(ctx, "event_month");
            String eventDay = processField(ctx, "event_day");
            String eventYear = processField(ctx, "event_year");
d160 9
a168 7
                  String subject = "New news item added on your project";
                  messageBuf.append("A new news item has been entered 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());
d180 1
a180 1
              redirectToURL(ctx, url);
d183 1
a183 1
              reportInvalidUserInput(ctx, missingFields, 
d185 1
a185 1
	          ctx.put("errors", "yes");
d195 2
a196 4
      Log.error (e);
      String message = "ProjectNewsAdd: " + e.getMessage ();
      if (debug) Log.debug (message);
      ctx.put ("message", message);
a198 2
    if (debug) Log.debug ("ProjectNewsAdd:  done");
    
d203 1
a203 1
}				/* end class ProjectNews */
@


1.25
log
@Now using TurbineWebMacroService instead of TemplateInterpolator.
@
text
@a65 1
import org.tigris.helm.tool.TemplateInterpolator;
@


1.24
log
@This is the highest revision from the HELM_PEER_PORT_BRANCH.  The previous import caused too many conflicts to resolve manually
@
text
@d59 1
a59 1
import org.webmacro.engine.BuildContext;
@


1.23
log
@broke into two steps: add and advanced options
@
text
@d57 1
a57 1
import org.webmacro.util.*;
d59 1
d65 2
a66 1
import org.tigris.helm.domain.*;
d68 1
a68 1
public class ProjectNewsAdd extends org.tigris.helm.security.HelmServlet
d70 1
a70 56
  public static final String versionID =
    "$Id: ProjectNewsAdd.java,v 1.22 2001/02/02 01:10:22 elicia Exp $";
  private static Log log = new Log ("ProjectNews", "Tigris StartPage");
  private static boolean debug = true;

  private static String ADD_ACTION="Add News Item";
  private static String ADVANCED_ACTION="Advanced Options";
  private static String HEADLINE="headline";
  private static String BODY="body";


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

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

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

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

     try
     {
        Project currentProject = getCurrentProject(ctx);
        AccessControlList acl = getACL(ctx, conn);
        Domain currentDomain = getCurrentDomain(ctx);
        HttpSession session = ctx.getSession();
      
        // Put current date into context 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);

	    // 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");
d72 17
a88 3
        if (action.equals (ADD_ACTION) || action.equals(ADVANCED_ACTION))
        {
           // Do add
d90 2
a91 19
           // Handle dates
           Date eventDate = null;
           Date publishDate = null;
           Date removeDate = 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.");
           }
d93 87
a179 33
           // Set publish date to current date
           // Set Remove date far future date 3999-01-01
           Calendar current = Calendar.getInstance();
 	       DateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
           publishDate = current.getTime();
	       removeDate = myFormat.parse("3999-01-01");
           
	       // Check for errors
           if (isValidUserInput(missingFields, validationErrors))
	       {
	          // TODO: Remove hardcoded priority.
	          NewsItem newsItem = currentProject.addNewsItem 
                                  (acl, eventDate, headline, body, 
                                   publishDate, removeDate, "1");
		      // Send email to alert project owner of new news item.
              // TODO: send out emails on publish date
		      Emailer email = new Emailer();
		      StringBuffer messageBuf = new StringBuffer();
		      String subject = "New news item added on your project";
		      messageBuf.append("A new news item has been entered 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());

              // Do redirect
              String url = null;
              if (action.equals(ADD_ACTION))
              {
                  url = currentProject.getProjectPageURL("ProjectNews");
              }  else {
                  StringBuffer urlBuf = new StringBuffer("ProjectNewsAddAdvanced");
d198 1
a198 1
      log.exception (e);
d200 1
a200 1
      if (debug) log.info (message);
d204 1
a204 1
    if (debug) log.debug ("ProjectNewsAdd:  done");
@


1.22
log
@now the user who proposed the news item can edit and delete it
@
text
@d50 1
a50 1
import java.util.ArrayList;
a51 2
import java.util.Calendar;
import java.util.GregorianCalendar;
d55 1
d60 1
a60 3
import com.workingdogs.village.*;

import org.joist.util.*;
a61 6
import org.joist.security.*;

import org.tigris.helm.security.HelmServlet;
import org.tigris.helm.security.AccessControlList;
import org.tigris.helm.tool.DateValidator;
import org.tigris.helm.domain.Domain;
d63 2
d69 1
a69 1
    "$Id: ProjectNewsAdd.java,v 1.21 2001/01/25 02:52:28 ms Exp $";
d73 4
a76 1
  private static String SUBMIT_CHANGES_ACTION="Add News Item";
d82 1
a82 1
  protected String processRequest (Connection connection, WebContext ctx)
d85 2
a86 2
    if (debug)
      log.debug ("ProjectNewsAdd: started!");
d88 2
a89 2
    String templateName = super.processRequest (connection, ctx);
    String action = (String) ctx.get ("action");
d91 1
a91 1
    if (debug)
d94 2
a95 8
    // 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) ctx.get ("Error");
    if (errorMessage != null)
    {
       action = "none";
       appendToMessage (ctx, errorMessage);
    }
d97 27
a123 2
    ArrayList missingFields = new ArrayList ();
    ArrayList validationErrors = new ArrayList ();
d125 3
a127 7
    try
    {
      String loginUserID = getLoginUser(ctx).getID();
      Project currentProject = getCurrentProject(ctx);
      Domain currentDomain = getCurrentDomain(ctx);
      AccessControlList acl = getACL(ctx, connection, loginUserID);
      
d129 49
a177 57
      if (action.equals (SUBMIT_CHANGES_ACTION))
      {
          // Do add
	      // Get user-entered values
          String headline = ctx.getForm("headline");
          String body = ctx.getForm("body");
          String publish = ctx.getForm("publish");
          String remove = ctx.getForm("remove");
	      String event_month = ctx.getForm ("event_month");
	      String event_day = ctx.getForm ("event_day");
	      String event_year = ctx.getForm ("event_year");
	      String publish_month = ctx.getForm ("publish_month");
	      String publish_day = ctx.getForm ("publish_day");
	      String publish_year = ctx.getForm ("publish_year");
	      String remove_month = ctx.getForm ("remove_month");
	      String remove_day = ctx.getForm ("remove_day");
	      String remove_year = ctx.getForm ("remove_year");
          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();
          Date removeOn = cal.getTime();
 	      DateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
	      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)
d179 5
a183 1
		          validationErrors.add("Publish date is not valid.");
d185 5
a189 34
	      } 
	  
	      // 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(ctx,headline, body, eventDate, publishOn, removeOn, validationErrors, missingFields))
	      {
              ctx.put("headline", headline);
              ctx.put("body", body);
	          ctx.put("event_month", event_month);
	          ctx.put("event_day", event_day);
	          ctx.put("event_year", event_year);
	          ctx.put("publish_month", publish_month);
	          ctx.put("publish_day", publish_day);
	          ctx.put("publish_year", publish_year);
	          ctx.put("remove_month", remove_month);
	          ctx.put("remove_day", remove_day);
	          ctx.put("remove_year", remove_year);
	          ctx.put("publish", publish);
	          ctx.put("remove", remove);
d191 2
a192 46
          }
    	  else 
	      {
             // If no errors, do update
	         // TODO: Remove hardcoded priority.
	         String confirmationMessage = currentProject.addNewsItem 
                  (acl, eventDate, headline, body, 
                   publishOn, removeOn, "1");

	         if (publish.equals("immediately"))
	         {
		        // Send email to alert project owner of new news item.
		        Emailer email = new Emailer();
		        StringBuffer messageBuf = new StringBuffer();
		        String subject = "New news item added on your project";
		        messageBuf.append("A new news item has been entered 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());
             }
	      
             //appendToMessage(ctx, confirmationMessage);
             redirectToURL(ctx, "ProjectNews");
	      }   
      }
            
      
      // Put current date into ctx as a default
      // removeDate default is current date plus one month
      GregorianCalendar today = new GregorianCalendar();
      ctx.put("current_month", 
		  Integer.toString(today.get(Calendar.MONTH) +1));
      ctx.put("current_day", 
		  Integer.toString(today.get(Calendar.DAY_OF_MONTH)));
      ctx.put("current_year", 
		  Integer.toString(today.get(Calendar.YEAR)));
      today.add(Calendar.MONTH, 1);
      ctx.put("default_remove_month", 
		  Integer.toString(today.get(Calendar.MONTH) +1));
      ctx.put("default_remove_day", 
		  Integer.toString(today.get(Calendar.DAY_OF_MONTH)));
      ctx.put("default_remove_year", 
		  Integer.toString(today.get(Calendar.YEAR)));

a211 61

  /* Check for missing and invalid fields
  *
  */
    private boolean validate(WebContext ctx, 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))
	    {
	        ctx.put("headline", TagValidator.escapeHTML(headline));
	        validationErrors.add("Headline has invalid HTML or Javascript");
	    }
	    if (!TagValidator.validate(body))
	    {
	        ctx.put("body", TagValidator.escapeHTML(body));
	        validationErrors.add("Body has invalid HTML or Javascript");
	    }
		
	    // 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 (ctx, "Missing Fields", missingFields);
	   }
	   if (!validationErrors.isEmpty ())
	   {
	       appendToMessage (ctx, "Validation Errors", validationErrors);
	   }
	   else
	   {
	       validate = true;
	   }

       ctx.put ("missingFields", missingFields);
       ctx.put ("validationErrors", validationErrors);
	
       return validate;
    }
@


1.21
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
@d76 1
a76 1
    "$Id: ProjectNewsAdd.java,v 1.20 2001/01/08 23:25:03 dlr Exp $";
d86 1
a86 2
  protected String
    processRequest (Connection connection, WebContext context)
d92 2
a93 2
    String templateName = super.processRequest (connection, context);
    String action = (String) context.get ("action");
d100 1
a100 1
    String errorMessage = (String) context.get ("Error");
d104 1
a104 1
       appendToMessage (context, errorMessage);
d112 4
a115 4
      String loginUserID = getLoginUser(context).getID();
      Project currentProject = getCurrentProject(context);
      Domain currentDomain = getCurrentDomain(context);
      AccessControlList acl = getACL(context, connection, loginUserID);
d122 13
a134 13
          String headline = context.getForm("headline");
          String body = context.getForm("body");
          String publish = context.getForm("publish");
          String remove = context.getForm("remove");
	      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");
d165 2
a166 2
	  if (!publish.equals("immediately"))
	  {
d171 1
a171 1
	      {
d176 1
a176 1
		  validationErrors.add("Publish date is not valid.");
d178 1
a178 1
	  } 
d180 3
a182 3
	  // Format remove date
	  if (!remove.equals("never"))
	  {
d192 1
a192 1
		  validationErrors.add("Remove date is not valid.");
d194 19
a212 18
	  } 
	  // 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");
d214 1
a214 9
	  else 
	  {
              // If no errors, do update
	      // TODO: Remove hardcoded priority.
	      String confirmationMessage = currentProject.addNewsItem (acl,
								       eventDate, headline, body, 
								       publishOn, removeOn, "1");

	      if (publish.equals("immediately"))
d216 19
a234 11
		  // Send email to alert project owner of new news item.
		  Emailer email = new Emailer();
		  StringBuffer messageBuf = new StringBuffer();
		  String subject = "New news item added on your project";
		  messageBuf.append("A new news item has been entered 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());
              }
d236 3
a238 2
              appendToMessage(context, confirmationMessage);
	  }
d242 1
a242 1
      // Put current date into context as a default
d245 1
a245 1
      context.put("current_month", 
d247 1
a247 1
      context.put("current_day", 
d249 1
a249 1
      context.put("current_year", 
d252 1
a252 1
      context.put("default_remove_month", 
d254 1
a254 1
      context.put("default_remove_day", 
d256 1
a256 1
      context.put("default_remove_year", 
d269 1
a269 1
      context.put ("message", message);
d282 1
a282 1
    private boolean validate(WebContext context, String headline, 
d284 3
a286 3
			     Date publishOn, Date removeOn,
			     ArrayList validationErrors, 
			     ArrayList missingFields)
d291 1
a291 1
	if (headline == null || headline.equals (""))
d294 4
a297 2
	if (body == null || body.equals (""))
	    missingFields.add ("body");
d299 11
a309 11
	// Check for invalid html tags in fields
	if (!TagValidator.validate(headline))
	{
	    context.put("headline", TagValidator.escapeHTML(headline));
	    validationErrors.add("Headline has invalid HTML or Javascript");
	}
	if (!TagValidator.validate(body))
	{
	    context.put("body", TagValidator.escapeHTML(body));
	    validationErrors.add("Body has invalid HTML or Javascript");
	}
d311 22
a332 22
	// 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 (!validationErrors.isEmpty ())
	{
	    appendToMessage (context, "Validation Errors", validationErrors);
	}
	else
	{
	    validate = true;
	}
d334 2
a335 2
        context.put ("missingFields", missingFields);
        context.put ("validationErrors", validationErrors);
d337 1
a337 1
        return validate;
@


1.21.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d76 1
a76 1
    "$Id: ProjectNewsAdd.java,v 1.21 2001/01/25 02:52:28 ms Exp $";
@


1.21.2.2
log
@ported to turbine
@
text
@d50 1
a50 1
import java.util.*;
d52 2
a56 1
import javax.servlet.http.*;
d58 2
a59 2
import org.apache.turbine.util.Log;
//import org.webmacro.servlet.*;
d61 3
a63 1
//import org.joist.security.*;
d65 6
a71 2
import org.tigris.helm.security.*;
import org.tigris.helm.om.*;
d73 1
a73 1
public class ProjectNewsAdd extends HelmServlet
d76 2
a77 1
    "$Id: ProjectNewsAdd.java,v 1.23 2001/02/06 19:59:24 elicia Exp $";
d80 1
a80 4
  private static String ADD_ACTION="Add News Item";
  private static String ADVANCED_ACTION="Advanced Options";
  private static String HEADLINE="headline";
  private static String BODY="body";
d86 2
a87 1
  protected String processRequest (Connection conn, WebContext ctx)
d90 5
a94 2
     if (debug)
       Log.debug ("ProjectNewsAdd: started!");
d96 11
a106 2
     String templateName = super.processRequest (conn, ctx);
     String action = (String) ctx.get ("action");
d108 2
a109 2
     if (debug)
        Log.debug ("ProjectNewsAdd: action=" + action);
d111 6
a116 10
     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);
        HttpSession session = ctx.getSession();
d118 74
a191 74
        // Put current date into context 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);

	    // 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");

        if (action.equals (ADD_ACTION) || action.equals(ADVANCED_ACTION))
        {
           // Do add

           // Handle dates
           Date eventDate = null;
           Date publishDate = null;
           Date removeDate = 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.");
           }

           // Set publish date to current date
           // Set Remove date far future date 3999-01-01
           Calendar current = Calendar.getInstance();
 	       DateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
           publishDate = current.getTime();
	       removeDate = myFormat.parse("3999-01-01");
           
	       // Check for errors
           if (isValidUserInput(missingFields, validationErrors))
	       {
	          // TODO: Remove hardcoded priority.
	          NewsItem newsItem = NewsItem.add(currentProject, acl,
                                               eventDate, headline, body,
                                               publishDate, removeDate, "1");
		      // Send email to alert project owner of new news item.
              // TODO: send out emails on publish date
		      Emailer email = new Emailer();
		      StringBuffer messageBuf = new StringBuffer();
		      String subject = "New news item added on your project";
		      messageBuf.append("A new news item has been entered 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());

              // Do redirect
              String url = null;
              if (action.equals(ADD_ACTION))
d193 1
a193 5
                  url = currentProject.getProjectPageURL("ProjectNewsList");
              }  else {
                  StringBuffer urlBuf = new StringBuffer("ProjectNewsAddAdvanced");
                  urlBuf.append("?newsID=").append(newsItem.getID());
                  url = urlBuf.toString();
d195 63
a257 8
              redirectToURL(ctx, url);
                  
           } else {
              reportInvalidUserInput(ctx, missingFields, 
                                     validationErrors);
	          ctx.put("errors", "yes");
           }
        } 
d265 1
a265 1
      Log.error (e);
d267 2
a268 2
      if (debug) Log.debug (message);
      ctx.put ("message", message);
d271 1
a271 1
    if (debug) Log.debug ("ProjectNewsAdd:  done");
d277 59
@


1.21.2.3
log
@ported to turbine
@
text
@d58 1
a58 1
import org.webmacro.servlet.*;
d60 1
a60 1
import org.joist.security.*;
d69 1
a69 1
    "$Id: ProjectNewsAdd.java,v 1.21.2.2 2001/02/10 00:04:30 elicia Exp $";
@


1.21.2.4
log
@changed priority field to int
@
text
@d69 1
a69 1
    "$Id: ProjectNewsAdd.java,v 1.21.2.3 2001/02/10 01:50:15 elicia Exp $";
d162 1
a162 1
                                               publishDate, removeDate, 1);
@


1.21.2.5
log
@no longer passing project to add method in om
@
text
@d69 1
a69 1
    "$Id: ProjectNewsAdd.java,v 1.21.2.4 2001/02/12 23:27:57 elicia Exp $";
d160 2
a161 1
	          NewsItem newsItem = NewsItem.add(acl, eventDate, headline, body,
@


1.21.2.6
log
@Big wide-ranging patch being committed all at once due to network downness. Features of this patch include: lots of added and updated JavaDoc, conversion of emails to use TemplateInterpolator and HelmEmailer, rearrangement of methods, changing code that gets mappings and loops over them to code that just gets the appropriate objects from the peer using AddJoin.
@
text
@d2 1
a2 1
 * Copyright (c) 2001 CollabNet.  All rights reserved.
d17 1
a17 1
 * software developed by CollabNet (http://www.collab.net/)."
d27 1
a27 1
 * permission of CollabNet.
d32 1
a32 1
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
a58 1
import org.webmacro.engine.BuildContext;
a64 1
import org.tigris.helm.tool.TemplateInterpolator;
d68 9
a76 9
    public static final String versionID =
        "$Id: ProjectNewsAdd.java,v 1.21.2.5 2001/02/13 22:45:45 elicia Exp $";
    private static boolean debug = true;

    private static String ADD_ACTION="Add News Item";
    private static String ADVANCED_ACTION="Advanced Options";
    private static String HEADLINE="headline";
    private static String BODY="body";
    private static String NEW_NEWS_ITEM_TEMPLATE="NewNewsItem.wm";
d81 34
a114 5
    protected String processRequest (Connection conn, WebContext context)
        throws HandlerException, RedirectException
    {
        if (debug)
            Log.debug ("ProjectNewsAdd: started!");
d116 8
a123 8
        String templateName = super.processRequest (conn, context);
        String action = (String) context.get ("action");

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

        ArrayList missingFields = new ArrayList ();
        ArrayList validationErrors = new ArrayList ();
d125 1
a125 1
        try
d127 1
a127 17
            Project currentProject = getCurrentProject(context);
            User loginUser = getLoginUser(context);
            AccessControlList acl = loginUser.getACL();
            Domain currentDomain = getCurrentDomain(context);
            HttpSession session = context.getSession();
      
            // Put current date into context 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));
            context.put("current_month", currentMonth);
            context.put("current_day", currentDay);
            context.put("current_year", currentYear);
d129 26
a154 39
	    // Get user-entered values
            String headline = processField(context, HEADLINE, "Headline", 
                                           missingFields);
            String body = processField(context, BODY, "Body", 
                                       missingFields);
            String eventMonth = processField(context, "event_month");
            String eventDay = processField(context, "event_day");
            String eventYear = processField(context, "event_year");

            if (action.equals (ADD_ACTION) || action.equals(ADVANCED_ACTION))
            {
                // Do add

                // Handle dates
                Date eventDate = null;
                Date publishDate = null;
                Date removeDate = 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.");
                }

                // Set publish date to current date
                // Set Remove date far future date 3999-01-01
                Calendar current = Calendar.getInstance();
                DateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
                publishDate = current.getTime();
                removeDate = myFormat.parse("3999-01-01");
d156 29
a184 36
                // Check for errors
                if (isValidUserInput(missingFields, validationErrors))
                {
                    // TODO: Remove hardcoded priority.
                    NewsItem newsItem = NewsItem.add
                        (acl, eventDate, headline, body,
                         publishDate, removeDate, 1);

                    // Send email to alert project owner of new news item.
                    // TODO: send out emails on publish date
                    // TODO: Move into NewsItem.add() in the meantime?
                    Emailer email = new Emailer();
                    String subject = "New news item added to project " 
                        + currentProject.getName();

                    BuildContext ctx = TemplateInterpolator.createContext();
                    ctx.put("project", currentProject);
                    ctx.put("newsItem", newsItem);
                    String messageBody = TemplateInterpolator.interpolate
                        (NEW_NEWS_ITEM_TEMPLATE, ctx, getClass());
               
                    String rcpt = "announce@@" + currentProject.getName() 
                        + "." + currentDomain.getName();
                    email.sendEmail(rcpt, subject, messageBody);

                    // Do redirect
                    String url = null;
                    if (action.equals(ADD_ACTION))
                    {
                        url = currentProject.getProjectPageURL("ProjectNewsList");
                    }  else {
                        StringBuffer urlBuf = new StringBuffer("ProjectNewsAddAdvanced");
                        urlBuf.append("?newsID=").append(newsItem.getID());
                        url = urlBuf.toString();
                    }
                    redirectToURL(context, url);
d186 18
a203 18
                } else {
                    reportInvalidUserInput(context, missingFields, 
                                           validationErrors);
                    context.put("errors", "yes");
                }
            } 
        }
        catch (RedirectException e)
        {
            throw e;
        }
        catch (Exception e)
        {
            Log.error (e);
            String message = "ProjectNewsAdd: " + e.getMessage ();
            if (debug) Log.debug (message);
            context.put ("message", message);
        }
d205 1
a205 1
        if (debug) Log.debug ("ProjectNewsAdd:  done");
d207 1
a207 1
        return templateName;
d209 1
a209 1
    }
d211 1
a211 1
}/* end class ProjectNews */
@


1.21.2.7
log
@Normalized copyright dates.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d71 1
a71 1
        "$Id: ProjectNewsAdd.java,v 1.21.2.6 2001/02/14 23:20:29 leonardr Exp $";
@


1.21.2.8
log
@passing in project to the add method
@
text
@d71 1
a71 1
        "$Id: ProjectNewsAdd.java,v 1.21.2.7 2001/02/15 20:50:42 leonardr Exp $";
d163 2
a164 2
                        (acl, currentProject, eventDate, headline,
                         body, publishDate, removeDate, 1);
@


1.21.2.9
log
@cleanup
@
text
@d2 1
a2 1
 * Copyright (c) 2000 CollabNet.  All rights reserved.
d17 1
a17 1
 * software developed by Collab.Net (http://www.Collab.Net/)."
d27 1
a27 1
 * permission of Collab.Net.
d32 1
a32 1
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d71 1
a71 1
        "$Id: ProjectNewsAdd.java,v 1.21.2.8 2001/02/16 01:25:14 elicia Exp $";
d80 4
a83 1
    protected String processRequest (Connection conn, WebContext ctx)
d89 2
a90 2
        String templateName = super.processRequest (conn, ctx);
        String action = (String) ctx.get ("action");
d100 2
a101 2
            Project currentProject = getCurrentProject(ctx);
            User loginUser = getLoginUser(ctx);
d103 4
a106 4
            Domain currentDomain = getCurrentDomain(ctx);
            HttpSession session = ctx.getSession();
          
            // Put current date into ctx as a default
d114 3
a116 3
            ctx.put("current_month", currentMonth);
            ctx.put("current_day", currentDay);
            ctx.put("current_year", currentYear);
d118 2
a119 4
            // Get user-entered values
            String headline = processField(ctx, HEADLINE, "Headline", 
                                           missingFields);
            String body = processField(ctx, BODY, "Body", 
d121 5
a125 3
            String eventMonth = processField(ctx, "event_month");
            String eventDay = processField(ctx, "event_day");
            String eventYear = processField(ctx, "event_year");
d129 1
a129 1
               // Do add
d131 47
a177 26
               // Handle dates
               Date eventDate = null;
               Date publishDate = null;
               Date removeDate = 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.");
               }

               // Set publish date to current date
               // Set Remove date far future date 3999-01-01
               Calendar current = Calendar.getInstance();
               DateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
               publishDate = current.getTime();
               removeDate = myFormat.parse("3999-01-01");
d179 15
a193 31
               // Check for errors
               if (isValidUserInput(missingFields, validationErrors))
               {
                  // TODO: Remove hardcoded priority.
                  NewsItem newsItem = NewsItem.add
                      (acl, currentProject, eventDate, headline,
                       body, publishDate, removeDate, 1);

                  // Send email to alert project owner of new news item.
                  // TODO: send out emails on publish date
                  Emailer email = new Emailer();
                  StringBuffer messageBuf = new StringBuffer();
                  String subject = "New news item added on your project";
                  messageBuf.append("A new news item has been entered 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());

                  // Do redirect
                  String url = null;
                  if (action.equals(ADD_ACTION))
                  {
                      url = currentProject.getProjectPageURL("ProjectNews");
                  }  else {
                      StringBuffer urlBuf = new StringBuffer("ProjectNewsAddAdvanced");
                  urlBuf.append("?newsID=").append(newsItem.getID());
                  url = urlBuf.toString();
              }
              redirectToURL(ctx, url);
d195 18
a212 18
           } else {
              reportInvalidUserInput(ctx, missingFields, 
                                     validationErrors);
	          ctx.put("errors", "yes");
           }
        } 
    }
    catch (RedirectException e)
    {
       throw e;
    }
    catch (Exception e)
    {
      Log.error (e);
      String message = "ProjectNewsAdd: " + e.getMessage ();
      if (debug) Log.debug (message);
      ctx.put ("message", message);
    }
d214 1
a214 1
    if (debug) Log.debug ("ProjectNewsAdd:  done");
d216 1
a216 1
    return templateName;
d218 1
a218 1
  }
d220 1
a220 1
}				/* end class ProjectNews */
@


1.21.2.10
log
@changed name of list servlet to redirect to
@
text
@d71 1
a71 1
        "$Id: ProjectNewsAdd.java,v 1.21.2.9 2001/02/17 00:16:15 elicia Exp $";
d179 1
a179 1
                      url = currentProject.getProjectPageURL("ProjectNewsList");
@


1.21.2.11
log
@Removed useless versionID string.
@
text
@d70 2
@


1.20
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
@d76 1
a76 1
    "$Id: ProjectNewsAdd.java,v 1.19 2000/12/27 23:33:30 brian Exp $";
d166 2
a167 2
	      if (!publish.equals("immediately"))
	      {
d172 1
a172 1
              {
d177 1
a177 1
	              validationErrors.add("Publish date is not valid.");
d179 5
a183 5
	      } 
	
	      // Format remove date
	      if (!remove.equals("never"))
	      {
d193 1
a193 1
	              validationErrors.add("Remove date is not valid.");
d195 4
a198 5
	      } 

          // Check for errors
	      if (!validate(context,headline, body, eventDate, publishOn, removeOn, validationErrors, missingFields))
	      {
d201 12
a212 12
	          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");
d214 9
a222 1
	      else 
d224 10
a233 18
              // If no errors, do update
	          // TODO: Remove hardcoded priority.
	          String confirmationMessage = currentProject.addNewsItem (acl,
                                               eventDate, headline, body, 
	       	  		                           publishOn, removeOn, "1");

	          if (publish.equals("immediately"))
	          {
	             // Send email to alert project owner of new news item.
	             Emailer email = new Emailer();
	             StringBuffer messageBuf = new StringBuffer();
	             String subject = "New news item added on your project";
	             messageBuf.append("A new news item has been entered 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());
d235 1
a235 1

d237 2
a238 2
           }
        }
d240 17
a256 17

        // 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)));
d283 3
a285 3
			                 Date publishOn, Date removeOn,
			                 ArrayList validationErrors, 
			                 ArrayList missingFields)
d290 5
a294 16
	    if (headline == null || headline.equals (""))
	        missingFields.add ("headline");

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

        // Check for invalid html tags in fields
        TagValidator tag = new TagValidator();
	    if (!tag.validate(headline, new StringBuffer()))
	    {
	       validationErrors.add("Headline field contains invalid html tags.");
	    }
	    else if (!tag.validate(body, new StringBuffer()))
	    {
	       validationErrors.add("Body field contains invalid html tags.");
	    }
d296 21
a316 10
	    // 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.");
	    }

d319 11
a329 11
	    {
	       appendToMessage (context, "Missing Fields", missingFields);
	    }
	    else if (!validationErrors.isEmpty ())
	    {
	       appendToMessage (context, "Validation Errors", validationErrors);
	    }
	    else
	    {
	       validate = true;
	    }
@


1.20.2.1
log
@missing ) for context put current_month
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d76 1
a76 1
    "$Id: ProjectNewsAdd.java,v 1.20 2001/01/08 23:25:03 dlr Exp $";
d246 1
a246 1
	        Integer.toString(today.get(Calendar.MONTH) +1)));
@


1.20.2.2
log
@removed that ), I was wrong
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d76 1
a76 1
    "$Id: ProjectNewsAdd.java,v 1.20.2.1 2001/03/15 19:30:58 susank Exp $";
d246 1
a246 1
	        Integer.toString(today.get(Calendar.MONTH) +1));
@


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

Genericize.
@
text
@d76 1
a76 1
    "$Id: ProjectNewsAdd.java,v 1.18 2000/12/27 01:35:47 elicia Exp $";
d113 1
a113 1
      String loginUserID = getLoginUser(context).getUserID();
@


1.18
log
@printing a different confirmation message for adding a news item, depending on if user has permissions to approve item
@
text
@d76 1
a76 1
    "$Id: ProjectNewsAdd.java,v 1.17 2000/12/22 21:05:35 elicia Exp $";
d228 1
a228 1
	             String subject = "New news item added on your SourceCast project";
@


1.17
log
@now displaying confirmation message when user posts news item
@
text
@d76 1
a76 1
    "$Id: ProjectNewsAdd.java,v 1.16 2000/12/12 22:25:26 elicia Exp $";
d219 3
a221 2
	          currentProject.addNewsItem (acl, eventDate, headline, body, 
	       	  		          publishOn, removeOn, "1");
d237 1
a237 5
	          // Redirect to Project News page
	          StringBuffer url = new StringBuffer("ProjectNews");
              url.append("?projectID=").append(currentProject.getID());
              appendToMessage(context, "Thank you for adding your news item. When the administrator approves it, it will appear in the list of news items for this project."); 
              //redirectToURL(context, url.toString());
@


1.16
log
@using Calendar instead of Date to process dates.
@
text
@d76 1
a76 1
    "$Id: ProjectNewsAdd.java,v 1.15 2000/12/07 02:30:36 elicia Exp $";
d239 2
a240 1
              redirectToURL(context, url.toString());
@


1.16.2.1
log
@moved in cahnges to ProjectNews from HEAD
@
text
@d76 1
a76 1
    "$Id: ProjectNewsAdd.java,v 1.17 2000/12/22 21:05:35 elicia Exp $";
d239 1
a239 2
              appendToMessage(context, "Thank you for adding your news item. When the administrator approves it, it will appear in the list of news items for this project."); 
              //redirectToURL(context, url.toString());
@


1.15
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
@d53 1
d76 1
a76 1
    "$Id: ProjectNewsAdd.java,v 1.14 2000/12/04 03:39:33 jrobbins Exp $";
d119 61
a179 45
        if (action.equals (SUBMIT_CHANGES_ACTION))
        {
           // Do add
	   // Get user-entered values
           DateValidator validDate = new DateValidator();
 	   DateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
	   StringBuffer dateBuf = new StringBuffer();
	   Date eventDate, publishOn, removeOn;
           String headline = context.getForm("headline");
           String body = context.getForm("body");
           String publish = context.getForm("publish");
           String remove = context.getForm("remove");
	   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");

           // 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());
	   }
d181 19
a199 17
	   // 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 removal date.");
	      removeOn = myFormat.parse(dateBuf.toString());
	   }

           // Check for errors
	   if (!validate(context,headline, body, eventDate, publishOn, removeOn, validationErrors, missingFields))
	   {
d202 12
a213 12
	      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");
d215 2
a216 2
	  else 
	  {
d218 14
a231 14
	      // TODO: Remove hardcoded priority.
	      currentProject.addNewsItem (acl, eventDate, headline, body, 
	       			          publishOn, removeOn, "1");

	      if (publish.equals("immediately"))
	      {
	         // Send email to alert project owner of new news item.
	         Emailer email = new Emailer();
	         StringBuffer messageBuf = new StringBuffer();
	         String subject = "New news item added on your SourceCast project";
	         messageBuf.append("A new news item has been entered for project ");
	         messageBuf.append(currentProject.getName()).append(".\n");
	         messageBuf.append(headline).append("\n");
	         messageBuf.append(body);
d233 1
a233 1
	         email.sendEmail(rcpt, subject, messageBuf.toString());
d236 2
a237 2
	      // Redirect to Project News page
	      StringBuffer url = new StringBuffer("ProjectNews");
d240 3
a242 2
           } 
        }    
d245 2
a246 2
        // removedate default is current date plus one month
        Calendar current = Calendar.getInstance();
d248 1
a248 1
	    Integer.toString(current.get(Calendar.MONTH) +1));
d250 1
a250 1
	    Integer.toString(current.get(Calendar.DAY_OF_MONTH)));
d252 2
a253 1
	    Integer.toString(current.get(Calendar.YEAR)));
d255 5
a259 1
	    Integer.toString(current.get(Calendar.MONTH) +2));
d286 3
a288 3
			     Date publishOn, Date removeOn,
			     ArrayList validationErrors, 
			     ArrayList missingFields)
d293 2
a294 2
	if (headline == null || headline.equals (""))
	    missingFields.add ("headline");
d296 2
a297 2
	if (body == null || body.equals (""))
	    missingFields.add ("body");
d301 8
a308 8
	if (!tag.validate(headline, new StringBuffer()))
	{
	  validationErrors.add("Headline field contains invalid html tags.");
	}
	else if (!tag.validate(body, new StringBuffer()))
	{
	  validationErrors.add("Body field contains invalid html tags.");
	}
d310 9
a318 9
	// 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.");
	}
d322 11
a332 13
	{
	  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;
	}
d336 2
a337 1
	return validate;
@


1.14
log
@put in missing "." in address
@
text
@d75 1
a75 1
    "$Id: ProjectNewsAdd.java,v 1.13 2000/12/04 02:14:02 jrobbins Exp $";
d203 13
a215 10
	      // Send email to alert project owner of new news item.
	      Emailer email = new Emailer();
	      StringBuffer messageBuf = new StringBuffer();
	      String subject = "New news item added on your SourceCast project";
	      messageBuf.append("A new news item has been entered 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());
@


1.13
log
@made news posting actually send to announce mailing list
@
text
@d75 1
a75 1
    "$Id: ProjectNewsAdd.java,v 1.12 2000/11/28 21:57:29 elicia Exp $";
d211 1
a211 1
              String rcpt = "announce@@" + currentProject.getName() + currentDomain.getName();
@


1.12
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
@d69 1
d75 1
a75 1
    "$Id: ProjectNewsAdd.java,v 1.11 2000/11/23 04:07:59 elicia Exp $";
d114 1
d211 2
a212 2
	      email.sendEmail("announce@@projectname.domain", 
	                      subject, messageBuf.toString());
@


1.11
log
@added radio buttons to default to "never" for a date to remove news items, and "immeidately" for a date to publish news items

cleanup.
@
text
@a61 2
import org.joist.*;
import org.joist.database.*;
a62 1
import org.joist.session.*;
a66 1
import org.tigris.helm.database.ProjectNewsManager;
d68 1
d74 1
a74 1
    "$Id: ProjectNewsAdd.java,v 1.10 2000/11/22 21:10:26 dlr Exp $";
d78 3
d89 1
a89 1
      log.debug ("ProjectNews: started!");
a93 4
    ProjectNewsManager newsMgr = (ProjectNewsManager)
      getDataManager (context).getManager
      ("org.tigris.helm.database.ProjectNewsManager");

d95 1
a95 1
        log.debug ("ProjectNews: action=" + action);
d106 2
d115 46
a160 38
      if (action.equals ("Add News Item"))
      {
	java.text.DateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
	StringBuffer dateBuf = new StringBuffer();
	Date publishOn;
	Date removeOn;
        String month;
	String day;
	String year;
        String headline = context.getForm("headline");
        String body = context.getForm("body");
        String publish = context.getForm("publish");
        String remove = context.getForm("remove");

        // Format event date
	month = context.getForm ("event_month");
	day = context.getForm ("event_day");
	year = context.getForm ("event_year");
	dateBuf.append(year).append("-");
	dateBuf.append(month).append("-").append(day);
	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 {
	  month = context.getForm ("publish_month");
	  day = context.getForm ("publish_day");
	  year = context.getForm ("publish_year");
	  dateBuf = new StringBuffer();
	  dateBuf.append(year).append("-");
	  dateBuf.append(month).append("-").append(day);
	  publishOn = myFormat.parse(dateBuf.toString());
	}
d162 68
a229 45
	// 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 {
	  month = context.getForm ("remove_month");
	  day = context.getForm ("remove_day");
	  year = context.getForm ("remove_year");
	  dateBuf = new StringBuffer();
	  dateBuf.append(year).append("-");
	  dateBuf.append(month).append("-").append(day);
	  removeOn = myFormat.parse(dateBuf.toString());
	}

        // If no errors, do update
	if (!validate(context,headline, body, 
	              eventDate, publishOn, removeOn))
	{
            context.put("headline", headline);
            context.put("body", body);
        }
	else 
	{
	    currentProject.addNewsItem (acl, eventDate, headline, body, 
				        publishOn, removeOn, "1");
	    StringBuffer url = new StringBuffer("ProjectNews");
            url.append("?projectID=").append(currentProject.getID());
	    Emailer email = new Emailer();
	    StringBuffer messageBuf = new StringBuffer();
	    String subject = "New news item added on your SourceCast project";
	    messageBuf.append("A new news item has been entered for project ");
	    messageBuf.append(currentProject.getName()).append(".\n");
	    messageBuf.append(headline).append("\n");
	    messageBuf.append(body);
	    email.sendEmail("announce@@projectname.domain", subject, messageBuf.toString());
            redirectToURL(context, url.toString());
        } 
     }    

    // Put current date into context as a default
    Calendar current = Calendar.getInstance();
    context.put("currentMonth", Integer.toString(current.get(Calendar.MONTH) +1));
    context.put("currentDay", Integer.toString(current.get(Calendar.DAY_OF_MONTH)));
    context.put("currentYear", Integer.toString(current.get(Calendar.YEAR)));
d238 4
a241 4
       log.exception(e);
       String msg = "Could not send invitation: " + e.getMessage();
       appendToMessage(context, msg);
       throw new HandlerException(msg);
d244 1
a244 1
    if (debug) log.debug ("ProjectNews:  done");
d249 1
d256 3
a258 1
			     Date publishOn, Date removeOn)
a261 3
        ArrayList missingFields = new ArrayList ();
        ArrayList validationErrors = new ArrayList ();

a273 2
	  if (debug)
	    log.info ("Validation Errors: invalid html tag in headline" );
d278 10
a287 2
	  if (debug)
	    log.info ("Validation Errors: invalid html tag in body" );
a299 10
	  if (debug)
	    log.debug ("Validation Errors: " + validationErrors.toString ());
	}
	
	// Check for field values that don't make sense
	else if (removeOn.compareTo(publishOn) <= 0)
	{
	  appendToMessage (context, "The remove date should be at least one day after the publish date.");
	  if (debug)
	    log.info ("Validation Errors: invalid remove or publish date.");
a300 7
	else if (removeOn.compareTo(new Date()) <= 0) 
	{
	  appendToMessage (context, "The remove date should be later than the current date.");
	  if (debug)
	    log.info ("Validation Errors: invalid remove or publish date.");
	}

@


1.10
log
@Corrected instruction.
@
text
@d77 1
a77 1
    "$Id: ProjectNewsAdd.java,v 1.9 2000/11/22 20:10:57 elicia Exp $";
a109 2
    ArrayList missingFields = new ArrayList ();
    ArrayList validationErrors = new ArrayList ();
d121 2
d126 4
d135 2
a136 1
	dateBuf.append(year).append("-").append(month).append("-").append(day);
d139 17
a155 8
	// Format publish date
	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 publishDate = myFormat.parse(dateBuf.toString());

d157 2
a158 45
	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 removeDate = myFormat.parse(dateBuf.toString());

	String headline = context.getForm ("headline");
	String body = context.getForm ("body");

        context.put("headline", headline);
        context.put("body", body);

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

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

        TagValidator tag = new TagValidator();


	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 if (!tag.validate(headline, new StringBuffer()))
	{
	  appendToMessage (context, "Headline field contains invalid html tags.");
	  if (debug)
	    log.info ("Validation Errors: invalid html tag in headline" );
	}
	else if (!tag.validate(body, new StringBuffer()))
d160 18
a177 17
	  appendToMessage (context, "Body field contains invalid html tags.");
	  if (debug)
	    log.info ("Validation Errors: invalid html tag in body" );
	}
	else if (removeDate.compareTo(publishDate) <= 0)
	{
	  appendToMessage (context, "The remove date must be at least one day after the publish date.");
	  if (debug)
	    log.info ("Validation Errors: invalid remove or publish date.");
	}
	else if ((removeDate.compareTo(new Date()) <= 0) || ((publishDate.compareTo(new Date()) > 0)))
	{
	  appendToMessage (context, "The publish and remove dates must be later than the current date.");
	  if (debug)
	    log.info ("Validation Errors: invalid remove or publish date.");
	}

d181 1
a181 1
				        publishDate, removeDate, "1");
d196 1
a196 3

    context.put ("missingFields", missingFields);
    context.put ("validationErrors", validationErrors);
d220 72
@


1.9
log
@fixed error checking for publish date
@
text
@d77 1
a77 1
    "$Id: ProjectNewsAdd.java,v 1.8 2000/11/22 03:26:58 elicia Exp $";
d195 1
a195 1
	  appendToMessage (context, "The remove date should be at least one day after the publish date.");
d201 1
a201 1
	  appendToMessage (context, "The publish and remove dates should be later than the current date.");
@


1.8
log
@checking to make sure the removeDate is later than the publishDate, and that both are later than the current date
@
text
@d77 1
a77 1
    "$Id: ProjectNewsAdd.java,v 1.7 2000/11/22 02:18:34 elicia Exp $";
d199 1
a199 1
	else if ((removeDate.compareTo(new Date()) <= 0) || ((publishDate.compareTo(new Date()) <= 0)))
@


1.7
log
@modernized files--using NewsItem business object
@
text
@d77 1
a77 1
    "$Id: ProjectNewsAdd.java,v 1.6 2000/11/17 02:50:40 elicia Exp $";
d192 12
@


1.6
log
@catching exceptions individually to avoid catching RedirectException
@
text
@d77 1
a77 1
    "$Id: ProjectNewsAdd.java,v 1.5 2000/11/16 04:12:54 elicia Exp $";
a120 3
	String month = context.getForm ("month");
	String day = context.getForm ("day");
	String year = context.getForm ("year");
d123 8
d133 17
d196 2
a197 4
	    newsMgr.updateNews (connection, acl, null, currentProject.getID(),
				                 eventDate, headline, body, 
				                 "1", "2000-12-01 01:01:01",
				                 "2000-12-24 01:01:01", "1");
d220 11
a230 25
    } catch (SQLException e) {
      log.exception(e);
      String message = "" + e.getMessage();
      if(debug) log.info(message);
      appendToMessage(context, message);
    } catch (JoistException e) {
      log.exception(e);
      String message = "" + e.getMessage();
      if(debug) log.info(message);
      appendToMessage(context, message);
    } catch (ParseException e) {
      log.exception(e);
      String message = "" + e.getMessage();
      if(debug) log.info(message);
      appendToMessage(context, message);
    } catch (DataSetException e) {
      log.exception(e);
      String message = "" + e.getMessage();
      if(debug) log.info(message);
      appendToMessage(context, message);
    } catch (JoistDatabaseException e) {
      log.exception(e);
      String message = "" + e.getMessage();
      if(debug) log.info(message);
      appendToMessage(context, message);            
@


1.5
log
@added validation of html tags in fields
@
text
@d53 1
a53 1
import java.text.SimpleDateFormat;
d60 2
d63 1
d66 2
a70 2
import org.joist.security.RedirectException;
import org.joist.mail.Emailer;
d77 1
a77 1
    "$Id: ProjectNewsAdd.java,v 1.4 2000/11/15 21:10:55 elicia Exp $";
d128 5
a133 1
	String headline = context.getForm ("headline");
a138 1
	String body = context.getForm ("body");
d146 1
a189 2
        context.put ("body", body);
        context.put ("headline", headline);
a194 2
    context.put ("projectID", currentProject.getID());
    context.put ("projectName", currentProject.getName());
d200 25
a224 7
    }
    catch (Exception e)
    {
       log.exception (e);
       String message = "ProjectNews: " + e.getMessage ();
       if (debug) log.debug (message);
        context.put ("message", message);
@


1.4
log
@using currentProject.getID() instead of getting projectID from the Form.
@
text
@d74 1
a74 1
    "$Id: ProjectNewsAdd.java,v 1.3 2000/11/15 00:02:12 elicia Exp $";
d138 2
d152 14
a165 1
	else
d183 2
@


1.3
log
@email goes out to announce@@projectname.domain when someone adds a new news item for the project.
@
text
@d74 1
a74 1
    "$Id: ProjectNewsAdd.java,v 1.2 2000/11/14 00:53:32 elicia Exp $";
a90 6
    String projectID = context.getForm ("projectID");
    String projectName = null;

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

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

d98 12
d112 4
a115 13
      // 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);
      }

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

d152 1
a152 4
	  try
	  {
            AccessControlList acl = getACL(context, connection);
	    newsMgr.updateNews (connection, acl, null, projectID,
d157 1
a157 1
            url.append("?projectID=").append(projectID);
d162 1
a162 1
	    messageBuf.append(projectName).append(".\n");
d167 2
a168 21
	  }
	  catch (Exception e)
	  {
	    log.exception (e);
	    String message = "ProjectNews: " + e.getMessage ();
	    if (debug)
	      log.debug (message);
	    context.put ("message", message);
	  }
	}
      }
    }
    catch (Exception e)
    {
      log.exception (e);
      String message = "ProjectNews: " + e.getMessage ();
      if (debug)
	log.debug (message);
      context.put ("message", message);
    }

a169 2
    if (debug)
      log.debug ("ProjectNews:  done");
d173 2
a174 2
    context.put ("projectID", projectID);
    context.put ("projectName", projectName);
d180 11
d192 1
a193 1

@


1.2
log
@putting current date into the context for template to default to
@
text
@d67 1
d74 1
a74 1
    "$Id: ProjectNewsAdd.java,v 1.1.1.1 2000/11/12 21:16:15 dlr Exp $";
d167 8
@


1.1
log
@Initial revision
@
text
@d52 1
d73 1
a73 1
    "$Id: ProjectNewsAdd.java,v 1.9 2000/11/11 03:33:33 dlr Exp $";
d196 4
@


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 1
a50 1
import java.util.*;
d52 1
a52 1
import java.text.*;
a54 1
import javax.servlet.http.*;
d56 1
a56 1
import org.apache.turbine.util.Log;
a57 1
import org.webmacro.engine.BuildContext;
d59 3
a61 2
import org.joist.security.*;
import org.joist.mail.Emailer;
d63 4
a66 3
import org.tigris.helm.security.*;
import org.tigris.helm.om.*;
import org.tigris.helm.tool.TemplateInterpolator;
d68 2
a69 1
public class ProjectNewsAdd extends HelmServlet
d71 27
a97 13
    private static boolean debug = true;

    private static String ADD_ACTION="Add News Item";
    private static String ADVANCED_ACTION="Advanced Options";
    private static String HEADLINE="headline";
    private static String BODY="body";
    private static String NEW_NEWS_ITEM_TEMPLATE="NewNewsItem.wm";

    protected String processRequest (Connection conn, WebContext ctx)
        throws HandlerException, RedirectException
    {
        if (debug)
            Log.debug ("ProjectNewsAdd: started!");
d99 2
a100 2
        String templateName = super.processRequest (conn, ctx);
        String action = (String) ctx.get ("action");
d102 2
a103 2
        if (debug)
            Log.debug ("ProjectNewsAdd: action=" + action);
d105 1
a105 103
        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);
            HttpSession session = ctx.getSession();
          
            // 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);

            // 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");

            if (action.equals (ADD_ACTION) || action.equals(ADVANCED_ACTION))
            {
               // Do add

               // Handle dates
               Date eventDate = null;
               Date publishDate = null;
               Date removeDate = 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.");
               }

               // Set publish date to current date
               // Set Remove date far future date 3999-01-01
               Calendar current = Calendar.getInstance();
               DateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
               publishDate = current.getTime();
               removeDate = myFormat.parse("3999-01-01");
               
               // Check for errors
               if (isValidUserInput(missingFields, validationErrors))
               {
                  // TODO: Remove hardcoded priority.
                  NewsItem newsItem = NewsItem.add
                      (acl, currentProject, eventDate, headline,
                       body, publishDate, removeDate, 1);

                  // Send email to alert project owner of new news item.
                  // TODO: send out emails on publish date
                  Emailer email = new Emailer();
                  StringBuffer messageBuf = new StringBuffer();
                  String subject = "New news item added on your project";
                  messageBuf.append("A new news item has been entered 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());

                  // Do redirect
                  String url = null;
                  if (action.equals(ADD_ACTION))
                  {
                      url = currentProject.getProjectPageURL("ProjectNewsList");
                  }  else {
                      StringBuffer urlBuf = new StringBuffer("ProjectNewsAddAdvanced");
                  urlBuf.append("?newsID=").append(newsItem.getID());
                  url = urlBuf.toString();
              }
              redirectToURL(ctx, url);
                  
           } else {
              reportInvalidUserInput(ctx, missingFields, 
                                     validationErrors);
	          ctx.put("errors", "yes");
           }
        } 
    }
    catch (RedirectException e)
d107 70
a176 1
       throw e;
d180 5
a184 4
      Log.error (e);
      String message = "ProjectNewsAdd: " + e.getMessage ();
      if (debug) Log.debug (message);
      ctx.put ("message", message);
d186 10
a195 3
    
    if (debug) Log.debug ("ProjectNewsAdd:  done");
    
d197 1
a198 2
  }
      
@

