Source Code Cross Referenced for Config.java in  » Mail-Clients » columba-1.4 » org » columba » chat » config » 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.chat.config 
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.chat.config;
019:
020:        import java.io.BufferedInputStream;
021:        import java.io.File;
022:        import java.io.FileInputStream;
023:        import java.io.FileNotFoundException;
024:        import java.io.FileOutputStream;
025:        import java.io.IOException;
026:        import java.io.InputStream;
027:        import java.io.OutputStream;
028:        import java.util.Properties;
029:
030:        import org.columba.chat.config.api.IAccount;
031:        import org.columba.chat.config.api.IConfig;
032:        import org.columba.core.config.DefaultConfigDirectory;
033:        import org.columba.core.io.DiskIO;
034:        import org.columba.core.shutdown.ShutdownManager;
035:
036:        /**
037:         * Configuration handling. Currently, using a Properties object to serialize an
038:         * {@link Account}. Default port for the jabber protocol is 5222.
039:         *
040:         * @author fdietz
041:         */
042:        public class Config implements  IConfig {
043:
044:            private File file;
045:
046:            private File chatDirectory;
047:
048:            private IAccount account;
049:
050:            private Properties properties;
051:
052:            /**
053:             *
054:             */
055:            public Config() {
056:
057:                // get Columba's top-level configuration directory
058:                File parentFile = DefaultConfigDirectory.getDefaultPath();
059:                ;
060:
061:                // create top-level configuration directory
062:                chatDirectory = new File(parentFile, "chat");
063:                DiskIO.ensureDirectory(chatDirectory);
064:
065:                file = new File(chatDirectory, "config.ini");
066:
067:                if (file.exists())
068:                    load();
069:                else
070:                    account = new Account();
071:
072:                // persist changes on exit
073:                ShutdownManager.getInstance().register(new Runnable() {
074:
075:                    public void run() {
076:                        try {
077:                            save();
078:                        } catch (Exception e) {
079:                            e.printStackTrace();
080:                        }
081:                    }
082:                });
083:            }
084:
085:            /**
086:             * @return Returns the account.
087:             */
088:            public IAccount getAccount() {
089:                return account;
090:            }
091:
092:            /**
093:             * @param account
094:             *            The account to set.
095:             */
096:            public void setAccount(Account account) {
097:                this .account = account;
098:            }
099:
100:            /**
101:             * Load configuration from disk. Automatically called on application
102:             * startup.
103:             */
104:            private void load() {
105:                // use key/value properties file
106:                properties = new Properties();
107:
108:                // load configuraation
109:                try {
110:                    // open stream to file
111:                    InputStream is = new BufferedInputStream(
112:                            new FileInputStream(file));
113:                    // load properties from stream
114:                    properties.load(is);
115:                    // close stream
116:                    is.close();
117:                } catch (FileNotFoundException e) {
118:
119:                    e.printStackTrace();
120:                } catch (IOException e) {
121:
122:                    e.printStackTrace();
123:                }
124:
125:                // create account object
126:                account = new Account(properties.getProperty("id"));
127:
128:                if (properties.getProperty("host") != null)
129:                    account.setHost(properties.getProperty("host"));
130:                else
131:                    account.setHost("jabber.org");
132:
133:                if (properties.getProperty("password") != null)
134:                    account.setPassword(properties.getProperty("password")
135:                            .toCharArray());
136:
137:                if (properties.getProperty("resource") != null)
138:                    account.setResource(properties.getProperty("resource"));
139:                else
140:                    account.setResource("Altura");
141:
142:                if (properties.getProperty("enable_ssl") != null)
143:                    account.setEnableSSL(new Boolean(properties
144:                            .getProperty("enable_ssl")).booleanValue());
145:                else
146:                    account.setEnableSSL(true);
147:
148:                if (properties.getProperty("port") != null)
149:                    account.setPort(new Integer(properties.getProperty("port"))
150:                            .intValue());
151:                else
152:                    account.setPort(5222);
153:
154:            }
155:
156:            /**
157:             * Save configuration to file. Automatically called by using the system
158:             * shutdown hook.
159:             *
160:             */
161:            private void save() {
162:                if (properties == null)
163:                    properties = new Properties();
164:
165:                // store account data in properties
166:                put("host", account.getHost());
167:                put("id", account.getId());
168:                if (account.getPassword() != null)
169:                    put("password", new String(account.getPassword()));
170:                put("resource", account.getResource());
171:                put("enable_ssl", new Boolean(account.isEnableSSL()).toString());
172:                put("port", new Integer(account.getPort()).toString());
173:
174:                try {
175:                    // create stream to file
176:                    OutputStream os = new FileOutputStream(file);
177:                    // save properties to file
178:                    properties.store(os, "account");
179:                    // close stream
180:                    os.close();
181:                } catch (IOException e1) {
182:
183:                    e1.printStackTrace();
184:                }
185:            }
186:
187:            private void put(String key, Object value) {
188:                if (value != null)
189:                    properties.put(key, value);
190:            }
191:
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.