KickJava   Java API By Example, From Geeks To Geeks.

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


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 // Servlet
20
import javax.servlet.http.HttpServlet JavaDoc;
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.http.HttpServletResponse JavaDoc;
23
24 // Velocity
25
import org.apache.velocity.context.Context;
26
27 // Demo
28
import org.apache.velocity.demo.om.*;
29
30 /**
31  * View a specific message and it's replies
32  *
33  * @author <a HREF="mailto:daveb@miceda-data.com">Dave Bryson</a>
34  * @version $Revision: 1.2.14.1 $
35  * $Id: ViewCommand.java,v 1.2.14.1 2004/03/04 00:18:29 geirm Exp $
36  */

37 public class ViewCommand extends Command
38 {
39     /** The template to call */
40     public static final String JavaDoc VIEW = "view.vm";
41     
42     public ViewCommand( HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp )
43     {
44         super( req, resp );
45     }
46
47     /**
48      * Loads the specific message from the store.
49      */

50     public String JavaDoc exec( Context ctx )
51     {
52         String JavaDoc value = request.getParameter("id");
53         Message m = ForumDatabase.getMessage( value );
54        
55         // Populate the context
56
ctx.put("message", m );
57         ctx.put("id", value);
58         
59         // Put Replies in the context
60
if ( m.numberOfReplies() > 0 )
61         {
62             ctx.put("hasReplies", Boolean.TRUE);
63             ctx.put("replies", m.getReplies());
64         }
65         else
66         {
67             ctx.put("hasReplies", Boolean.FALSE);
68         }
69         
70         return VIEW;
71     }
72 }
73
74
75
Popular Tags