Source Code Cross Referenced for RegReader.java in  » Portal » Open-Portal » com » sun » portal » proxylet » client » common » 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 » Portal » Open Portal » com.sun.portal.proxylet.client.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright Sun Microsystems, Inc. All rights reserved.
003:         * The Registry class provides is used to load the native
004:         * library DLL, as well as a placeholder for the top level
005:         * keys, error codes, and utility methods.
006:         *
007:         * @version 1.0
008:         *
009:         */package com.sun.portal.proxylet.client.common;
010:
011:        import com.sun.portal.proxylet.client.common.ui.ProxyletUI;
012:        import com.sun.portal.proxylet.client.common.browser.BrowserHelper;
013:        import java.io.*;
014:
015:        public class RegReader {
016:            public static final int ERROR_FILE_NOT_FOUND = 2;
017:            private String tempDirectory;
018:            public static boolean dllLoaded = false;
019:            boolean binit = false;
020:            private static final RegReader THEINSTANCE = new RegReader();
021:
022:            public native String getJWSVersion();
023:
024:            public native String getBrowserInstallPath(String browsername,
025:                    String browserversion);
026:
027:            static {
028:                try {
029:                    Log.debugu("trying to load library... ");
030:                    System.loadLibrary("RegReader");
031:                    Log.debugu("loaded library..");
032:                    dllLoaded = true;
033:                } catch (Throwable e) {
034:                    e.printStackTrace();
035:                    dllLoaded = false;
036:                }
037:            }
038:
039:            private RegReader() {
040:            }
041:
042:            public synchronized static RegReader getInstance() {
043:                if (THEINSTANCE.binit == false) {
044:                    try {
045:                        THEINSTANCE.init();
046:                    } catch (Exception e) {
047:                        // Unable to create temp directory
048:                        e.printStackTrace();
049:                        String location = null;
050:                        location = BrowserHelper
051:                                .getNewfileLocation(ProxyletUI.frame);
052:                        THEINSTANCE.setTempDirectory(location);
053:                    }
054:                    THEINSTANCE.binit = true;
055:
056:                }
057:                return THEINSTANCE;
058:            }
059:
060:            void init() throws Exception {
061:                try {
062:                    if (!dllLoaded) {
063:                        Log.debug("Loading library explicitly");
064:                        loadExplicitly();
065:                    }
066:                    if (tempDirectory != null) {
067:                        if (new File(tempDirectory).isDirectory())
068:                            return;
069:                    }
070:                    File f = File.createTempFile("abcdd", ".sunxyz");
071:                    tempDirectory = f.getPath();
072:                    tempDirectory = tempDirectory.substring(0, tempDirectory
073:                            .lastIndexOf("\\") + 1);
074:                    Log.debugu(" tempDirectory = " + tempDirectory);
075:                    f.delete();
076:                } catch (IOException e) {
077:                    System.out.println("Unable to create temp file");
078:                    ProxyletUI.setText(Param.getString("perr.8",
079:                            "ERR: Unable to write to disk"));
080:                    throw e;
081:                }
082:
083:            }
084:
085:            public void loadExplicitly() throws Exception {
086:                System.out.println("In loadExplicityly");
087:                //install  dll
088:                String location = extractResource("RegReader.dll");
089:                Log.debugu("RegReader.dll file location = " + location);
090:                System.out.println("RegReader.dll file location = " + location);
091:                try {
092:                    System.load(location);
093:                    dllLoaded = true;
094:                    Log.debugu("loaded library 'RegReader.dll' explicitly");
095:                    System.out
096:                            .println("loaded library 'RegReader.dll' explicitly");
097:                } catch (Exception e) {
098:                    System.out.println("Exception occured in loadExplicityly");
099:                    dllLoaded = false;
100:                    throw e;
101:                }
102:            }
103:
104:            public String extractResource(String resourceName) throws Exception {
105:                String tempDirectory = getTempDirectory();
106:                File registryReaderDLLFile = new File(tempDirectory
107:                        + resourceName);
108:
109:                ClassLoader c1 = RegReader.class.getClassLoader();
110:                InputStream is = c1.getResourceAsStream(resourceName);
111:                if (is != null) {
112:                    BufferedOutputStream ostream = null;
113:
114:                    //imp: RegReader.dll file is extracted to the same local file by RegReader.java
115:                    //in both proxyletapplet.jar and jnlpclient.jar. Since, jnlpclient.jar executes
116:                    //after the applet, we check if it's possible to extract the resource to the file.
117:                    //if it's not, we assume that the file is already present. We can't just rely on
118:                    // the check for the file being present because the client machine might have
119:                    // some old dll.
120:                    try {
121:                        //generate a temporary name for the resource and write to temp file
122:                        ostream = new BufferedOutputStream(
123:                                new FileOutputStream(registryReaderDLLFile));
124:                    } catch (FileNotFoundException fnfe) {
125:                        //ignore..
126:                    }
127:                    if (ostream != null) {
128:                        BufferedInputStream istream = new BufferedInputStream(
129:                                is);
130:                        if (registryReaderDLLFile.exists()) {
131:                            registryReaderDLLFile.delete();
132:                            registryReaderDLLFile.createNewFile();
133:                        }
134:
135:                        Log.debugu("Extracting resource " + resourceName
136:                                + " to directory " + tempDirectory);
137:
138:                        int bsize = 2048;
139:                        int n = 0;
140:                        byte[] buffer = new byte[bsize];
141:                        while ((n = istream.read(buffer, 0, bsize)) != -1) {
142:                            ostream.write(buffer, 0, n);
143:                        }
144:                        istream.close();
145:                        ostream.close();
146:                    }
147:                }
148:                registryReaderDLLFile.deleteOnExit();
149:                Log.debugu("dllFilePath = "
150:                        + registryReaderDLLFile.getAbsolutePath());
151:                System.out.println("dllFilePath = "
152:                        + registryReaderDLLFile.getAbsolutePath());
153:                return registryReaderDLLFile.getAbsolutePath();
154:            }
155:
156:            public String getTempDirectory() {
157:                if (tempDirectory == null || tempDirectory.trim().length() != 0) {
158:                    try {
159:                        File f = File.createTempFile("abcdd", ".sunxyz");
160:                        tempDirectory = f.getPath();
161:                        tempDirectory = tempDirectory.substring(0,
162:                                tempDirectory.lastIndexOf("\\") + 1);
163:                        f.delete();
164:                    } catch (IOException e) {
165:                        ProxyletUI.setText(Param.getString("perr.2",
166:                                "ERR: installing dll."));
167:                        e.printStackTrace();
168:                    }
169:                }
170:
171:                return tempDirectory;
172:            }
173:
174:            public void setTempDirectory(String tempDir) {
175:                tempDirectory = tempDir;
176:            }
177:
178:            public String getBrowserLaunchCommand(String browserName,
179:                    String browserVersion) {
180:                System.out.println("Inside getBrowserlaunchcommand");
181:                String brName = browserName.trim().toLowerCase();
182:                System.out.println("browser name " + brName);
183:                System.out.println("browser version " + browserVersion);
184:                String command = getBrowserInstallPath(
185:                        getBrowserRegistryKeyName(brName), browserVersion
186:                                .trim());
187:
188:                System.out.println("launch url " + command);
189:
190:                if (brName.indexOf("msie") != -1) {
191:                    command = command + "\\iexplore.exe";
192:
193:                }
194:                return command;
195:            }
196:
197:            private String getBrowserRegistryKeyName(String browserName) {
198:                browserName = browserName.trim().toLowerCase();
199:
200:                if (browserName.equals("mozilla"))
201:                    return "mozilla.org";
202:                if (browserName.indexOf("firefox") != -1)
203:                    return "mozilla";
204:                if (browserName.indexOf("netscape") != -1)
205:                    return "netscape";
206:
207:                return browserName;
208:            }
209:
210:            public boolean detectJWSInstallation() {
211:                String value = getJWSVersion();
212:                System.out.println("detect jws installation " + value);
213:                float jwsVer = 0.0f;
214:                jwsVer = (new Float(value.substring(0, 3))).floatValue();
215:
216:                if ((new Float(jwsVer)).compareTo(new Float(1.4)) >= 0)
217:                    return true;
218:
219:                return false;
220:            }
221:
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.