01: /*
02: * Created on Jul 9, 2004
03: *
04: * This file is part of Thingamablog. ( http://thingamablog.sf.net )
05: *
06: * Copyright (c) 2004, Bob Tantlinger All Rights Reserved.
07: *
08: * This program is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU General Public License
10: * as published by the Free Software Foundation; either version 2
11: * of the License, or (at your option) any later version.
12: *
13: * This program is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU General Public License for more details.
17: *
18: * You should have received a copy of the GNU General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21: * USA.
22: */
23: package net.sf.thingamablog.transport;
24:
25: import net.sf.thingamablog.blog.Weblog;
26:
27: /**
28: * Factory for logging in to a weblog's transport
29: *
30: * @author Bob Tantlinger
31: *
32: */
33: public class LoginFactory {
34:
35: /**
36: * Logs in to a weblog's transport
37: *
38: * @param w The weblog
39: * @param prompt The prompt
40: * @return true if logged in successfully, false otherwise
41: */
42: public static boolean publishLogin(Weblog w, LoginPrompt prompt) {
43: if (w.getPublishTransport() instanceof LocalTransport)
44: return true; //no login for local transports
45:
46: if (w.getPublishTransport() instanceof RemoteTransport) {
47: RemoteTransport rt = (RemoteTransport) w
48: .getPublishTransport();
49: return doLogin(rt, prompt);
50: }
51:
52: return true;//all other Transport types return successful login
53: }
54:
55: public static boolean emailLogin(Weblog w, LoginPrompt prompt) {
56: return doLogin(w.getMailTransport(), prompt);
57: }
58:
59: private static boolean doLogin(RemoteTransport rt,
60: LoginPrompt prompt) {
61: if (!rt.isSavePassword())//got to get the user's pw
62: {
63: prompt.promptUser(rt.getUserName(), rt.getAddress());
64: rt.setPassword(prompt.getPassword());
65: return !prompt.isLoginCancelled();
66: }
67:
68: return true;
69: }
70: }
|