KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > forum > ForumPlugin


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.forum;
20
21 import org.lucane.applications.forum.gui.MainWindow;
22 import org.lucane.applications.forum.model.ForumInfo;
23 import org.lucane.applications.forum.model.ForumMessage;
24 import org.lucane.client.*;
25 import org.lucane.common.*;
26 import org.lucane.common.net.ObjectConnection;
27
28 import java.util.ArrayList JavaDoc;
29 import java.util.Date JavaDoc;
30
31
32 public class ForumPlugin extends StandalonePlugin
33 {
34     private ConnectInfo service;
35     
36     public ForumPlugin()
37     {
38     }
39     
40     public Plugin newInstance(ConnectInfo[] friends)
41     {
42         return new ForumPlugin();
43     }
44     
45     public void start()
46     {
47         this.service = Communicator.getInstance().getConnectInfo(getName());
48         MainWindow ui = new MainWindow(this);
49         
50         try {
51             ui.getForumList().setForums(getForumList());
52         } catch(Exception JavaDoc e) {
53             e.printStackTrace();
54         }
55         
56         ui.getMainWindow().show();
57     }
58     
59     public long getLastRefreshTime(String JavaDoc forum)
60     {
61         String JavaDoc refreshTime = getLocalConfig().get(forum + "-refresh", "0");
62         return Long.parseLong(refreshTime);
63     }
64
65     public void updateLastRefreshTime(String JavaDoc forum)
66     {
67         Date JavaDoc now = new Date JavaDoc();
68         getLocalConfig().set(forum + "-refresh", String.valueOf(now.getTime()));
69     }
70
71     
72     public ArrayList JavaDoc getForumList()
73     throws Exception JavaDoc
74     {
75         ForumAction fa = new ForumAction(ForumAction.LIST_FORUMS);
76         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
77                 service, service.getName(), fa);
78         
79         String JavaDoc ack = oc.readString();
80         if(ack.equals("OK"))
81         {
82             ArrayList JavaDoc list = (ArrayList JavaDoc)oc.read();
83             oc.close();
84             return list;
85         }
86         
87         oc.close();
88         throw new Exception JavaDoc(ack);
89     }
90     
91     public ArrayList JavaDoc getMessageList(ForumInfo forum)
92     throws Exception JavaDoc
93     {
94         
95         ForumAction fa = new ForumAction(ForumAction.LIST_MESSAGES, forum.getName());
96         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
97                 service, service.getName(), fa);
98         
99         String JavaDoc ack = oc.readString();
100         if(ack.equals("OK"))
101         {
102             ArrayList JavaDoc list = (ArrayList JavaDoc)oc.read();
103             oc.close();
104             return list;
105         }
106         
107         oc.close();
108         throw new Exception JavaDoc(ack);
109     }
110     
111     public ForumMessage getMessageContent(String JavaDoc forum, ForumMessage message)
112     throws Exception JavaDoc
113     {
114         int id = message.getId();
115         ForumAction fa = new ForumAction(ForumAction.GET_MESSAGE_CONTENT, forum, new Integer JavaDoc(id));
116         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
117                 service, service.getName(), fa);
118         
119         String JavaDoc ack = oc.readString();
120         if(ack.equals("OK"))
121         {
122             ForumMessage msg = (ForumMessage)oc.read();
123             oc.close();
124             return msg;
125         }
126         
127         oc.close();
128         throw new Exception JavaDoc(ack);
129     }
130     
131     public void post(String JavaDoc forum, ForumMessage msg)
132     throws Exception JavaDoc
133     {
134         ForumAction fa = new ForumAction(ForumAction.POST_MESSAGE, forum, msg);
135         ObjectConnection oc = Communicator.getInstance().sendMessageTo(
136                 service, service.getName(), fa);
137         
138         String JavaDoc ack = oc.readString();
139         oc.close();
140         
141         if(!ack.equals("OK"))
142             throw new Exception JavaDoc(ack);
143     }
144 }
145
Popular Tags