Source Code Cross Referenced for JSCFController.java in  » Mail-Clients » columba-1.4 » org » columba » mail » pgp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Mail Clients » columba 1.4 » org.columba.mail.pgp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // The contents of this file are subject to the Mozilla Public License Version
002:        // 1.1
003:        //(the "License"); you may not use this file except in compliance with the
004:        //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005:        //
006:        //Software distributed under the License is distributed on an "AS IS" basis,
007:        //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008:        //for the specific language governing rights and
009:        //limitations under the License.
010:        //
011:        //The Original Code is "The Columba Project"
012:        //
013:        //The Initial Developers of the Original Code are Frederik Dietz and Timo
014:        // Stich.
015:        //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016:        //
017:        //All Rights Reserved.
018:        package org.columba.mail.pgp;
019:
020:        import java.util.Hashtable;
021:        import java.util.Map;
022:        import java.util.Properties;
023:        import java.util.logging.Logger;
024:
025:        import org.columba.api.plugin.IExtension;
026:        import org.columba.api.plugin.IExtensionHandler;
027:        import org.columba.api.plugin.PluginHandlerNotFoundException;
028:        import org.columba.core.gui.externaltools.ExternalToolsManager;
029:        import org.columba.core.logging.Logging;
030:        import org.columba.core.plugin.PluginManager;
031:        import org.columba.mail.config.MailConfig;
032:        import org.columba.mail.config.SecurityItem;
033:        import org.waffel.jscf.JSCFConnection;
034:        import org.waffel.jscf.JSCFDriverManager;
035:        import org.waffel.jscf.JSCFException;
036:        import org.waffel.jscf.gpg.GPGDriver;
037:
038:        /**
039:         * The <code>JSCFController</code> controls JSCFDrivers and Connections. It
040:         * chaches for each account the connection to JSCFDrivers. The
041:         * <code>JSCFController</code> uses the "singleton pattern", which mean, that
042:         * you should access it, using the <code>getInstcane</code> method.
043:         * 
044:         * @author waffel
045:         */
046:        public class JSCFController {
047:
048:            /** JDK 1.4+ logging framework logger, used for logging. */
049:            private static final Logger LOG = Logger
050:                    .getLogger("org.columba.mail.pgp");
051:
052:            private static JSCFController myInstance = null;
053:
054:            private static Map connectionMap;
055:
056:            /**
057:             * Gives a instance of the <code>JSCFController</code> back. If no
058:             * instance was created before, a new instance will be created.
059:             * 
060:             * @return A Instance of <code>JSCFController</code>
061:             */
062:            public static JSCFController getInstance() {
063:                if (myInstance == null) {
064:                    myInstance = new JSCFController();
065:                    registerDrivers();
066:                    connectionMap = new Hashtable();
067:                }
068:
069:                return myInstance;
070:            }
071:
072:            private static void registerDrivers() {
073:                try {
074:                    // at the moment we are only supporting gpg. So let us code hard
075:                    // here the gpg driver
076:                    JSCFDriverManager.registerJSCFDriver(new GPGDriver());
077:                } catch (JSCFException e) {
078:
079:                    e.printStackTrace();
080:                }
081:            }
082:
083:            /**
084:             * Creates a new Connection to the gpg driver, if the connection for the
085:             * given <code>userID</code> are not exists. Properties for the connection
086:             * are created by using the SecurityItem from the <code>AccountItem</code>.
087:             * Properties like PATH and the GPG USERID are stored for the connection, if
088:             * the connection are not exists.
089:             * 
090:             * @param userID
091:             *            UserID from which the connection should give back
092:             * @return a alrady etablished connection for this user or a newly created
093:             *         connection for this userID, if no connection exists for the
094:             *         userID
095:             * @throws JSCFException
096:             *             If there are several Driver problems
097:             */
098:            public JSCFConnection getConnection(String userID)
099:                    throws JSCFException {
100:                SecurityItem pgpItem = MailConfig.getInstance()
101:                        .getAccountList().getDefaultAccount().getPGPItem();
102:                JSCFConnection con = (JSCFConnection) connectionMap.get(userID);
103:
104:                if (con == null) {
105:                    LOG.fine("no connection for userID (" + userID
106:                            + ") found. Creating a new Connection.");
107:                    // let us hard coding the gpg for each connection. Later we should
108:                    // support also other variants (like smime)
109:                    con = JSCFDriverManager.getConnection("jscf:gpg:");
110:
111:                    // getting the path to gpg
112:
113:                    IExtensionHandler handler = null;
114:                    String path = null;
115:                    try {
116:                        LOG.fine("try to get the handler");
117:                        handler = PluginManager.getInstance()
118:                                .getExtensionHandler(
119:                                        "org.columba.core.externaltools");
120:                        LOG.fine("recived Handler ... getting path from it");
121:                        path = ExternalToolsManager.getInstance()
122:                                .getLocationOfExternalTool("gpg").getPath();
123:                        LOG.fine("setting path: " + path);
124:                    } catch (PluginHandlerNotFoundException e) {
125:                        LOG.fine("PluginHandler not found" + e);
126:                        if (Logging.DEBUG) {
127:                            e.printStackTrace();
128:                        }
129:                    }
130:
131:                    /*
132:                     * if (path == null) { throw new ProgramNotFoundException("invalid
133:                     * path"); }
134:                     */
135:                    Properties props = con.getProperties();
136:                    if (path == null) {
137:                        throw new ProgramNotFoundException("invalid path");
138:                    }
139:                    props.put("PATH", path);
140:                    if (handler != null) {
141:                        IExtension extension = handler.getExtension("gpg");
142:
143:                        LOG.fine("gpg userId: "
144:                                + extension.getMetadata().getId());
145:                    }
146:                    LOG.info("gpg path: " + props.get("PATH"));
147:                    props.put("USERID", pgpItem.get("id"));
148:                    LOG.info("current gpg userID: " + props.get("USERID"));
149:                    con.setProperties(props);
150:                    connectionMap.put(userID, con);
151:                }
152:
153:                return con;
154:            }
155:
156:            /**
157:             * Creates a new JSCFConnection for the current used Account. The current
158:             * used Account is determind from the AccountItem. This method calls only
159:             * {@link #getConnection(String)}with the <code>id</code> from the
160:             * SecurityItem.
161:             * 
162:             * @return a alrady etablished connection for the current account or a newly
163:             *         created connection for the current account, if no connection
164:             *         exists for the current account
165:             * @throws JSCFException
166:             *             If there are several Driver problems
167:             */
168:            public JSCFConnection getConnection() throws JSCFException {
169:                SecurityItem pgpItem = MailConfig.getInstance()
170:                        .getAccountList().getDefaultAccount().getPGPItem();
171:
172:                return getConnection(pgpItem.get("id"));
173:            }
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.