1 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 ; 29 import java.util.Date ; 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 e) { 53 e.printStackTrace(); 54 } 55 56 ui.getMainWindow().show(); 57 } 58 59 public long getLastRefreshTime(String forum) 60 { 61 String refreshTime = getLocalConfig().get(forum + "-refresh", "0"); 62 return Long.parseLong(refreshTime); 63 } 64 65 public void updateLastRefreshTime(String forum) 66 { 67 Date now = new Date (); 68 getLocalConfig().set(forum + "-refresh", String.valueOf(now.getTime())); 69 } 70 71 72 public ArrayList getForumList() 73 throws Exception 74 { 75 ForumAction fa = new ForumAction(ForumAction.LIST_FORUMS); 76 ObjectConnection oc = Communicator.getInstance().sendMessageTo( 77 service, service.getName(), fa); 78 79 String ack = oc.readString(); 80 if(ack.equals("OK")) 81 { 82 ArrayList list = (ArrayList )oc.read(); 83 oc.close(); 84 return list; 85 } 86 87 oc.close(); 88 throw new Exception (ack); 89 } 90 91 public ArrayList getMessageList(ForumInfo forum) 92 throws Exception 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 ack = oc.readString(); 100 if(ack.equals("OK")) 101 { 102 ArrayList list = (ArrayList )oc.read(); 103 oc.close(); 104 return list; 105 } 106 107 oc.close(); 108 throw new Exception (ack); 109 } 110 111 public ForumMessage getMessageContent(String forum, ForumMessage message) 112 throws Exception 113 { 114 int id = message.getId(); 115 ForumAction fa = new ForumAction(ForumAction.GET_MESSAGE_CONTENT, forum, new Integer (id)); 116 ObjectConnection oc = Communicator.getInstance().sendMessageTo( 117 service, service.getName(), fa); 118 119 String 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 (ack); 129 } 130 131 public void post(String forum, ForumMessage msg) 132 throws Exception 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 ack = oc.readString(); 139 oc.close(); 140 141 if(!ack.equals("OK")) 142 throw new Exception (ack); 143 } 144 } 145 | Popular Tags |