KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > velocity > demo > action > PostReplyCommand


1 package org.apache.velocity.demo.action;
2
3 /*
4  * Copyright 1999,2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 // Java
20
import java.util.*;
21
22 // Servlet
23
import javax.servlet.http.HttpServlet JavaDoc;
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27 // Velocity
28
import org.apache.velocity.context.Context;
29
30 // Demo
31
import org.apache.velocity.demo.om.*;
32
33 /**
34  * Adds a reply to the forum
35  *
36  * @author <a HREF="mailto:daveb@miceda-data.com">Dave Bryson</a>
37  * @version $Revision: 1.2.14.1 $
38  * $Id: PostReplyCommand.java,v 1.2.14.1 2004/03/04 00:18:29 geirm Exp $
39  */

40 public class PostReplyCommand extends Command
41 {
42     public PostReplyCommand( HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp )
43     {
44         super( req, resp );
45     }
46     
47     /**
48      * Collects the parameters from the Form.
49      * Adds the Reply to the parent message then refreshes
50      * the View
51      */

52     public String JavaDoc exec( Context ctx )
53     {
54         String JavaDoc name = request.getParameter("name");
55         String JavaDoc subject = request.getParameter("subject");
56         String JavaDoc email = request.getParameter("email");
57         String JavaDoc content = request.getParameter("content");
58         String JavaDoc parent = request.getParameter("id");
59         
60         // Create the reply
61
Message message = new Message();
62         message.setName( name );
63         message.setSubject( subject );
64         message.setEmail( email );
65         message.setContents( content );
66         
67         //Post the reply
68
ForumDatabase.postReply( message, parent );
69         
70         // Now get the message and show the added replies
71
Message m = ForumDatabase.getMessage( parent );
72         ctx.put("message", m );
73         ctx.put("id", parent);
74
75         // Put Replies in the context
76
if ( m.numberOfReplies() > 0 )
77         {
78             ctx.put("hasReplies", Boolean.TRUE);
79             ctx.put("replies", m.getReplies());
80         }
81         else
82         {
83             ctx.put("hasReplies", Boolean.FALSE);
84         }
85         return ViewCommand.VIEW;
86     }
87 }
88
89
90
91
92
Popular Tags