001: /*
002: * Lucane - a collaborative platform
003: * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019: package org.lucane.applications.jmailadmin;
020:
021: import java.util.ArrayList;
022:
023: import org.lucane.applications.jmailadmin.gui.MainFrame;
024: import org.lucane.client.*;
025: import org.lucane.client.widgets.DialogBox;
026: import org.lucane.common.ConnectInfo;
027: import org.lucane.common.net.ObjectConnection;
028:
029: public class JMailAdminPlugin extends StandalonePlugin {
030: private ConnectInfo service;
031:
032: public JMailAdminPlugin() {
033: }
034:
035: public Plugin newInstance(ConnectInfo[] friends) {
036: return new JMailAdminPlugin();
037: }
038:
039: public void start() {
040: this .service = Communicator.getInstance().getConnectInfo(
041: "org.lucane.applications.jmailadmin");
042: MainFrame mf = new MainFrame(this );
043: mf.setExitPluginOnClose(true);
044: mf.show();
045: }
046:
047: public boolean storeAccount(Account a) {
048: boolean result = true;
049:
050: JMailAdminAction jma = new JMailAdminAction(
051: JMailAdminAction.STORE_ACCOUNT, a);
052: ObjectConnection oc = Communicator.getInstance().sendMessageTo(
053: service, service.getName(), jma);
054:
055: try {
056: if (oc.readString().startsWith("OK"))
057: DialogBox.info(tr("msg.accountStored"));
058: else {
059: DialogBox.error(tr("err.storeAccount"));
060: result = false;
061: }
062: } catch (Exception e) {
063: result = false;
064: DialogBox.error(tr("err.storeAccount"));
065: e.printStackTrace();
066: }
067: oc.close();
068:
069: return result;
070: }
071:
072: public Account getAccount(String user) {
073: Account a = null;
074: JMailAdminAction jma = new JMailAdminAction(
075: JMailAdminAction.GET_ACCOUNT, user);
076: ObjectConnection oc = Communicator.getInstance().sendMessageTo(
077: service, service.getName(), jma);
078:
079: try {
080: if (oc.readString().startsWith("OK"))
081: a = (Account) oc.read();
082: } catch (Exception e) {
083: //probably no account yet
084: a = new Account(user);
085: }
086:
087: oc.close();
088: return a;
089: }
090:
091: public ArrayList getUsers() {
092: ArrayList users = null;
093: JMailAdminAction jma = new JMailAdminAction(
094: JMailAdminAction.GET_USERS);
095: ObjectConnection oc = Communicator.getInstance().sendMessageTo(
096: service, service.getName(), jma);
097:
098: try {
099: if (oc.readString().startsWith("OK"))
100: users = (ArrayList) oc.read();
101: } catch (Exception e) {
102: DialogBox.error(tr("err.unableToGetUserList"));
103: }
104:
105: oc.close();
106: return users;
107: }
108: }
|