KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > forum > actions > area > Search


1 /* Copyright 2000-2005 Anders Hovmöller
2  *
3  * The person or persons who have associated their work with
4  * this document (the "Dedicator") hereby dedicate the entire
5  * copyright in the work of authorship identified below (the
6  * "Work") to the public domain.
7  *
8  * Dedicator makes this dedication for the benefit of the
9  * public at large and to the detriment of Dedicator's heirs
10  * and successors. Dedicator intends this dedication to be an
11  * overt act of relinquishment in perpetuity of all present
12  * and future rights under copyright law, whether vested or
13  * contingent, in the Work. Dedicator understands that such
14  * relinquishment of all rights includes the relinquishment of
15  * all rights to enforce (by lawsuit or otherwise) those
16  * copyrights in the Work.
17  *
18  * Dedicator recognizes that, once placed in the public
19  * domain, the Work may be freely reproduced, distributed,
20  * transmitted, used, modified, built upon, or otherwise
21  * exploited by anyone for any purpose, commercial or non-
22  * commercial, and in any way, including by methods that have
23  * not yet been invented or conceived.
24  */

25
26 package net.killingar.forum.actions.area;
27
28 import net.killingar.forum.internal.Area;
29 import net.killingar.forum.internal.IDItemImpl;
30 import net.killingar.forum.internal.Message;
31 import net.killingar.forum.internal.managers.AreaManager;
32
33 import java.util.ArrayList JavaDoc;
34 import java.util.List JavaDoc;
35
36 public class Search extends ActionAreaSupport
37 {
38     AreaManager areamgr;
39     List JavaDoc messages;
40     long areaID = -1;
41     Area area;
42     boolean subject = true;
43     boolean body = true;
44     String JavaDoc search;
45
46     public Area getArea() { return area; }
47     public boolean getBody() { return body; }
48     public List JavaDoc getMessages() { return messages; }
49     public String JavaDoc getSearch() { return search; }
50     public boolean getSubject() { return subject; }
51
52     public void setAreaID(String JavaDoc s) { areaID = Long.parseLong(s); }
53     public void setBody(boolean flag) { body = flag; }
54     public void setSearch(String JavaDoc s) { search = s; }
55     public void setSubject(boolean flag) { subject = flag; }
56
57     protected String JavaDoc doExecute()
58     {
59         try
60         {
61             if (search == null)
62                 return "input";
63             Message msgs[] = areamgr.search(search, ((IDItemImpl)(area)).ID, subject, body);
64             messages = new ArrayList JavaDoc(msgs.length);
65             for (int i = 0; i < msgs.length; i++)
66                 messages.add(new MessageData(manager, msgs[i], false, false));
67
68             return SUCCESS;
69         }
70         catch (Exception JavaDoc exception)
71         {
72             addErrorMessage("displaying search area page failed, exception thrown (" + exception.toString() + ")");
73             exception.printStackTrace();
74             return ERROR;
75         }
76     }
77
78     protected void doValidation()
79     {
80         if (areaID == -1)
81             addErrorMessage("no area specified");
82
83         try
84         {
85             areamgr = (AreaManager)manager.getManager(AreaManager.class.getName());
86             area = areamgr.getArea(areaID);
87         }
88         catch (Exception JavaDoc exception)
89         {
90             addErrorMessage("error getting area manager or area (" + exception.getMessage() + ")");
91             exception.printStackTrace();
92         }
93         if (area == null)
94             addErrorMessage("invalid area ID specified");
95     }
96 }
97
Popular Tags