KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.*;
20
21 import javax.servlet.http.HttpServlet JavaDoc;
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24
25 import org.apache.velocity.context.Context;
26 import org.apache.velocity.app.tools.*;
27
28 import org.apache.velocity.demo.om.*;
29
30 /**
31  * Handles listing messages
32  *
33  * @author <a HREF="mailto:daveb@miceda-data.com">Dave Bryson</a>
34  * @version $Revision: 1.3.14.1 $
35  * $Id: ListCommand.java,v 1.3.14.1 2004/03/04 00:18:29 geirm Exp $
36  */

37 public class ListCommand extends Command
38 {
39     /** Name of the Template */
40     public static final String JavaDoc LIST = "list.vm";
41     
42     public ListCommand( HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp )
43     {
44         super( req, resp );
45     }
46     
47     /**
48      * Get a Vector of Messages and put them into the
49      * context for the template
50      */

51     public String JavaDoc exec( Context ctx )
52     {
53         Object JavaDoc[] list = ForumDatabase.listAll();
54         
55         if ( list == null || list.length == 0 )
56         {
57             ctx.put("hasMessages", Boolean.FALSE );
58         }
59         else
60         {
61             ctx.put("hasMessages", Boolean.TRUE );
62             ctx.put("listall", list );
63         }
64         
65         return LIST;
66     }
67 }
68
69
Popular Tags