Source Code Cross Referenced for BrowserControl.java in  » Database-ORM » XORM » org » xorm » tools » 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 ORM » XORM » org.xorm.tools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.xorm.tools;
002:
003:        import java.io.IOException;
004:
005:        /**
006:         * Taken from http://www.javaworld.com/javaworld/javatips/jw-javatip66.html
007:         * @author Steven Spencer
008:         *
009:         * A simple, static class to display a URL in the system browser.
010:         *
011:         * Under Unix, the system browser is hard-coded to be 'netscape'.
012:         * Netscape must be in your PATH for this to work.  This has been
013:         * tested with the following platforms: AIX, HP-UX and Solaris.
014:         *
015:         * Under Windows, this will bring up the default browser under windows,
016:         * usually either Netscape or Microsoft IE.  The default browser is
017:         * determined by the OS.  This has been tested under Windows 95/98/NT.
018:         *
019:         * Examples:
020:         * * BrowserControl.displayURL("http://www.javaworld.com")
021:         *
022:         * BrowserControl.displayURL("file://c:\\docs\\index.html")
023:         *
024:         * BrowserContorl.displayURL("file:///user/joe/index.html");
025:         * 
026:         * Note - you must include the url type -- either "http://" or
027:         * "file://".
028:         */
029:        public class BrowserControl {
030:            /**
031:             * Display a file in the system browser.  If you want to display a
032:             * file, you must include the absolute path name.
033:             *
034:             * @param url the file's url (the url must start with either "http://"
035:             or
036:             * "file://").
037:             */
038:            public static void displayURL(String url) {
039:                boolean windows = isWindowsPlatform();
040:                String cmd = null;
041:                try {
042:                    if (windows) {
043:                        // cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
044:                        cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
045:                        Process p = Runtime.getRuntime().exec(cmd);
046:                    } else {
047:                        // Under Unix, Netscape has to be running for the "-remote"
048:                        // command to work.  So, we try sending the command and
049:                        // check for an exit value.  If the exit command is 0,
050:                        // it worked, otherwise we need to start the browser.
051:                        // cmd = 'netscape -remote openURL(http://www.javaworld.com)'
052:                        cmd = UNIX_PATH + " " + UNIX_FLAG + "(" + url + ")";
053:                        Process p = Runtime.getRuntime().exec(cmd);
054:                        try {
055:                            // wait for exit code -- if it's 0, command worked,
056:                            // otherwise we need to start the browser up.
057:                            int exitCode = p.waitFor();
058:                            if (exitCode != 0) {
059:                                // Command failed, start up the browser
060:                                // cmd = 'netscape http://www.javaworld.com'
061:                                cmd = UNIX_PATH + " " + url;
062:                                p = Runtime.getRuntime().exec(cmd);
063:                            }
064:                        } catch (InterruptedException x) {
065:                            System.err
066:                                    .println("Error bringing up browser, cmd='"
067:                                            + cmd + "'");
068:                            System.err.println("Caught: " + x);
069:                        }
070:                    }
071:                } catch (IOException x) {
072:                    // couldn't exec browser
073:                    System.err.println("Could not invoke browser, command="
074:                            + cmd);
075:                    System.err.println("Caught: " + x);
076:                }
077:            }
078:
079:            /**
080:             * Try to determine whether this application is running under Windows
081:             * or some other platform by examing the "os.name" property.
082:             *
083:             * @return true if this application is running under a Windows OS
084:             */
085:            public static boolean isWindowsPlatform() {
086:                String os = System.getProperty("os.name");
087:                if (os != null && os.startsWith(WIN_ID))
088:                    return true;
089:                else
090:                    return false;
091:            }
092:
093:            // Used to identify the windows platform.
094:            private static final String WIN_ID = "Windows";
095:            // The default system browser under windows.
096:            //private static final String WIN_PATH = "rundll32";
097:            private static final String WIN_PATH = "cmd /c start";
098:            // The flag to display a url.
099:            //private static final String WIN_FLAG = "url.dll,FileProtocolHandler";
100:            private static final String WIN_FLAG = "";
101:
102:            // The default browser under unix.
103:            private static final String UNIX_PATH = "netscape";
104:            // The flag to display a url.
105:            private static final String UNIX_FLAG = "-remote openURL";
106:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.