Source Code Cross Referenced for Options.java in  » Database-Client » JSqlTool » org » jsqltool » utils » 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 » Database Client » JSqlTool » org.jsqltool.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.jsqltool.utils;
002:
003:        import java.util.*;
004:        import javax.crypto.*;
005:        import java.security.*;
006:        import javax.crypto.*;
007:        import javax.crypto.spec.*;
008:        import java.security.*;
009:        import javax.swing.JOptionPane;
010:
011:        /**
012:         * <p>Title: JSqlTool Project</p>
013:         * <p>Description: This is a singleton class used to store application properties.
014:         * </p>
015:         * <p>Copyright: Copyright (C) 2006 Mauro Carniel</p>
016:         *
017:         * <p> This file is part of JSqlTool project.
018:         * This library is free software; you can redistribute it and/or
019:         * modify it under the terms of the (LGPL) Lesser General Public
020:         * License as published by the Free Software Foundation;
021:         *
022:         *                GNU LESSER GENERAL PUBLIC LICENSE
023:         *                 Version 2.1, February 1999
024:         *
025:         * This library is distributed in the hope that it will be useful,
026:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
027:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
028:         * Library General Public License for more details.
029:         *
030:         * You should have received a copy of the GNU Library General Public
031:         * License along with this library; if not, write to the Free
032:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
033:         *
034:         *       The author may be contacted at:
035:         *           maurocarniel@tin.it</p>
036:         *
037:         * @author Mauro Carniel
038:         * @version 1.0
039:         */
040:        public class Options {
041:
042:            /** unique instance of the class */
043:            private static Options opt = null;
044:
045:            /** date format */
046:            private String dateFormat;
047:
048:            /** Oracle PLAN table, used to execute query explain */
049:            private String oracleExplainPlanTable;
050:
051:            /** flag used to allow record updating when no pk is defined */
052:            private boolean updateWhenNoPK;
053:
054:            /** language id to be used inside the application */
055:            private String language = null;
056:
057:            /** contains internationalizaton settings */
058:            private ResourceBundle resourceBundle = null;
059:
060:            /** cipher object for password-based encryption */
061:            private Cipher encCipher = null;
062:
063:            /** cipher object for password-based decryption */
064:            private Cipher decCipher = null;
065:
066:            /** PBE parameter set */
067:            private PBEParameterSpec pbeParamSpec = null;
068:
069:            /** SecretKey object */
070:            private SecretKey pbeKey = null;
071:
072:            private Options() {
073:                try {
074:                    // Salt
075:                    byte[] salt = { (byte) 0xc7, (byte) 0x73, (byte) 0x21,
076:                            (byte) 0x8c, (byte) 0x7e, (byte) 0xc8, (byte) 0xee,
077:                            (byte) 0x99 };
078:
079:                    // Iteration count
080:                    int count = 20;
081:
082:                    // Create PBE parameter set
083:                    pbeParamSpec = new PBEParameterSpec(salt, count);
084:
085:                    // Prompt user for encryption password.
086:                    // Collect user password as char array (using the
087:                    // "readPasswd" method from above), and convert
088:                    // it into a SecretKey object, using a PBE key
089:                    // factory.
090:                    PBEKeySpec pbeKeySpec = new PBEKeySpec(new char[] { '2',
091:                            '1', '1', '7', '4' });
092:                    SecretKeyFactory keyFac = SecretKeyFactory
093:                            .getInstance("PBEWithMD5AndDES");
094:                    pbeKey = keyFac.generateSecret(pbeKeySpec);
095:
096:                    // get cipher object for password-based encryption
097:                    encCipher = Cipher.getInstance("PBEWithMD5AndDES");
098:
099:                    // get cipher object for password-based decryption
100:                    decCipher = Cipher.getInstance("PBEWithMD5AndDES");
101:
102:                } catch (Throwable ex) {
103:                    ex.printStackTrace();
104:                }
105:            }
106:
107:            /**
108:             * @return unique instance of the class
109:             */
110:            public static Options getInstance() {
111:                if (java.beans.Beans.isDesignTime())
112:                    return new Options();
113:                if (opt == null)
114:                    opt = new Options();
115:                return opt;
116:            }
117:
118:            /**
119:             * @return date format
120:             */
121:            public String getDateFormat() {
122:                return dateFormat;
123:            }
124:
125:            /**
126:             * @return Oracle PLAN table, used to execute query explain
127:             */
128:            public final String getOracleExplainPlanTable() {
129:                return oracleExplainPlanTable;
130:            }
131:
132:            /**
133:             * @return allow record updating when no pk is defined
134:             */
135:            public final boolean isUpdateWhenNoPK() {
136:                return updateWhenNoPK;
137:            }
138:
139:            /**
140:             * Allow record updating when no pk is defined
141:             * @param updateWhenNoPK allow record updating when no pk is defined
142:             */
143:            public final void setUpdateWhenNoPK(boolean updateWhenNoPK) {
144:                this .updateWhenNoPK = updateWhenNoPK;
145:            }
146:
147:            /**
148:             * Set Oracle PLAN table, used to execute query explain.
149:             * @param oracleExplainPlanTable Oracle PLAN table, used to execute query explain
150:             */
151:            public final void setOracleExplainPlanTable(
152:                    String oracleExplainPlanTable) {
153:                this .oracleExplainPlanTable = oracleExplainPlanTable;
154:            }
155:
156:            /**
157:             * Set date format.
158:             * @param dateFormat date format
159:             */
160:            public final void setDateFormat(String dateFormat) {
161:                this .dateFormat = dateFormat;
162:            }
163:
164:            /**
165:             * @return language id to be used inside the application
166:             */
167:            public final String getLanguage() {
168:                return language;
169:            }
170:
171:            /**
172:             * Set language id to be used inside the application.
173:             * @param language language id to be used inside the application
174:             */
175:            public final void setLanguage(String language) {
176:                this .language = language;
177:                resourceBundle = ResourceBundle.getBundle(
178:                        "org.jsqltool.utils.Dictionary", new Locale(language));
179:            }
180:
181:            /**
182:             * @param key key to translate
183:             * @return key translation
184:             */
185:            public final String getResource(String key) {
186:                if (java.beans.Beans.isDesignTime())
187:                    return key;
188:                String value = null;
189:                try {
190:                    value = resourceBundle.getString(key);
191:                } catch (Exception ex) {
192:                    return key;
193:                }
194:                return value == null ? key : value;
195:            }
196:
197:            /**
198:             * Encrypt text.
199:             * @param text text to encrypt
200:             * @return encrypted text
201:             */
202:            public final String encode(String text)
203:                    throws IllegalBlockSizeException, BadPaddingException,
204:                    InvalidKeyException, InvalidAlgorithmParameterException {
205:                // initialize cipher for encryption, without supplying
206:                // any parameters. Here, "myKey" is assumed to refer
207:                // to an already-generated key.
208:                encCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
209:                byte[] cipherText = encCipher.doFinal(text.getBytes());
210:                return new String(cipherText);
211:            }
212:
213:            /**
214:             * Decrypt text.
215:             * @param text text to decrypt
216:             * @return decrypted text
217:             */
218:            public final String decode(String text)
219:                    throws IllegalBlockSizeException, BadPaddingException,
220:                    InvalidKeyException, InvalidAlgorithmParameterException {
221:                // initialize cipher for decryption, without supplying
222:                // any parameters. Here, "myKey" is assumed to refer
223:                // to an already-generated key.
224:                decCipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);
225:                byte[] cipherText = decCipher.doFinal(text.getBytes());
226:                return new String(cipherText);
227:
228:            }
229:
230:            /**
231:             * Encrypt text.
232:             * @param text text to encrypt
233:             * @return encrypted text
234:             */
235:            public final byte[] encodeToBytes(String text)
236:                    throws IllegalBlockSizeException, BadPaddingException,
237:                    InvalidKeyException, InvalidAlgorithmParameterException {
238:                encCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
239:                byte[] cipherText = encCipher.doFinal(text.getBytes());
240:                return cipherText;
241:            }
242:
243:            /**
244:             * Decrypt text.
245:             * @param text text to decrypt
246:             * @return decrypted text
247:             */
248:            public final String decodeFromBytes(byte[] text)
249:                    throws IllegalBlockSizeException, BadPaddingException,
250:                    InvalidKeyException, InvalidAlgorithmParameterException {
251:                // initialize cipher for decryption, without supplying
252:                // any parameters. Here, "myKey" is assumed to refer
253:                // to an already-generated key.
254:                decCipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);
255:                byte[] cipherText = decCipher.doFinal(text);
256:                return new String(cipherText);
257:            }
258:
259:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.