Source Code Cross Referenced for Launcher.java in  » Testing » abbot-1.0.1 » abbot » util » 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 » Testing » abbot 1.0.1 » abbot.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package abbot.util;
002:
003:        import java.net.URLEncoder;
004:        import java.util.ArrayList;
005:        import java.util.Arrays;
006:        import java.io.IOException;
007:        import abbot.Platform;
008:
009:        /** Mail and browser launcher which augments {@link Runtime Runtime.exec}
010:         * methods.  Provides for built-in email and web browser support.
011:         */
012:        public class Launcher {
013:
014:            // TODO: provide an array of known mailto: handlers
015:            // for now we assume the browsers will make an attempt to handle mailto:
016:            private static final String[] HTTP = { "firefox", "galeon",
017:                    "konqueror", "opera", "mozilla", "netscape", "mosaic", };
018:
019:            /** Perform trickery to get the right contents into the email handler from
020:                a mailto: line.
021:             */
022:            private static String encodeForMail(String base) {
023:                StringBuffer buf = new StringBuffer(base);
024:                // Avoid URLEncoder.encode for spaces; it replaces them with plus
025:                // signs, which remain pluses when decoded.
026:                String SPACE = "--SPACE--";
027:                for (int idx = buf.toString().indexOf(" "); idx != -1; idx = buf
028:                        .toString().indexOf(" ")) {
029:                    buf.replace(idx, idx + 1, SPACE);
030:                }
031:                buf = new StringBuffer(URLEncoder.encode(buf.toString()));
032:                for (int idx = buf.toString().indexOf(SPACE); idx != -1; idx = buf
033:                        .toString().indexOf(SPACE)) {
034:                    if (Platform.isOSX()) {
035:                        // The "open" command parses spaces
036:                        buf.replace(idx, idx + SPACE.length(), "%20");
037:                    } else {
038:                        buf.replace(idx, idx + SPACE.length(), " ");
039:                    }
040:                }
041:                return buf.toString();
042:            }
043:
044:            /** Format a message to the given user with the given subject and message
045:                body. */
046:            public static void mail(String user, String subject, String body)
047:                    throws IOException {
048:                mail(user, subject, body, null);
049:            }
050:
051:            /** Format a message to the given user with the given subject and message
052:                body, including a CC list. */
053:            public static void mail(String user, String subject, String body,
054:                    String cc) throws IOException {
055:                mail(user, subject, body, cc, null);
056:            }
057:
058:            /** Format a message to the given user with the given subject and message
059:                body, including CC and BCC lists. */
060:            public static void mail(String user, String subject, String body,
061:                    String cc, String bcc) throws IOException {
062:                StringBuffer mailto = new StringBuffer("mailto:" + user + "?");
063:                if (cc != null)
064:                    mailto.append("CC=" + cc + "&");
065:                if (bcc != null)
066:                    mailto.append("BCC=" + bcc + "&");
067:
068:                mailto.append("Subject=" + encodeForMail(subject) + "&"
069:                        + "Body=" + encodeForMail(body) + "");
070:                open(mailto.toString());
071:            }
072:
073:            /** Open the given target URL in the platform's browser. */
074:            public static void open(String target) throws IOException {
075:                open(null, target);
076:            }
077:
078:            /** Use the given command/program to open the given target. */
079:            public static void open(String command, String target)
080:                    throws IOException {
081:                boolean tryBrowsers = false;
082:                ArrayList args = new ArrayList();
083:                if (command != null) {
084:                    args.add(command);
085:                } else {
086:                    if (Platform.isOSX()) {
087:                        args.add("open");
088:                    } else if (Platform.isWindows()) {
089:                        if (Platform.isWindows9X()) {
090:                            args.add("command.com");
091:                            args.add("/o");
092:                        } else {
093:                            args.add("cmd.exe");
094:                            args.add("/c");
095:                            args.add("start");
096:                            args.add("\"Title\"");
097:                        }
098:                        // Always quote the argument, just in case
099:                        // See MS docs for cmd.exe; &, |, and () must be escaped with
100:                        // ^ or double-quoted.  semicolon and comma are command
101:                        // argument separators, and probably require quoting as well. 
102:                        target = "\"" + target + "\"";
103:                    } else {
104:                        args.add("placeholder");
105:                        tryBrowsers = true;
106:                    }
107:                }
108:                args.add(target);
109:
110:                String[] cmd = (String[]) args.toArray(new String[args.size()]);
111:                if (!tryBrowsers) {
112:                    ProcessOutputHandler.exec(cmd);
113:                } else {
114:                    // TODO: choose the appropriate application based on the target
115:                    // URL format, instead of relying on browsers to do it.
116:                    for (int i = 0; i < HTTP.length; i++) {
117:                        try {
118:                            cmd[0] = HTTP[i];
119:                            ProcessOutputHandler.exec(cmd);
120:                            return;
121:                        } catch (IOException e) {
122:                            // not found, try another one
123:                        }
124:                    }
125:                    throw new IOException("No target handler found (tried "
126:                            + Arrays.asList(HTTP) + ")");
127:                }
128:            }
129:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.