Source Code Cross Referenced for EnvironmentReader.java in  » Database-ORM » MMBase » org » mmbase » util » externalprocess » 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 » MMBase » org.mmbase.util.externalprocess 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:        This software is OSI Certified Open Source Software.
004:        OSI Certified is a certification mark of the Open Source Initiative.
005:
006:        The license (Mozilla version 1.0) can be read at the MMBase site.
007:        See http://www.MMBase.org/license
008:
009:         */
010:        package org.mmbase.util.externalprocess;
011:
012:        import java.io.ByteArrayOutputStream;
013:        import java.io.IOException;
014:        import java.util.Properties;
015:        import java.util.StringTokenizer;
016:        import java.util.Vector;
017:
018:        /** Reader for importing the OS Environment properties into java.
019:         * java.lang.System.getProperties() has only some environment info
020:         *
021:         * @todo more OS support
022:         *
023:         * @author Nico Klasens (Finalist IT Group)
024:         * @version $Id: EnvironmentReader.java,v 1.6 2007/03/02 21:05:15 nklasens Exp $
025:         * @since MMBase-1.6
026:         */
027:        public class EnvironmentReader {
028:            private static Properties envVars = null;
029:            private static Vector<String> rawVars = null;
030:
031:            /**
032:             * Get value of environment properties
033:             * @return Properties environment
034:             */
035:            public static Properties getEnvVars() {
036:
037:                if (null != envVars)
038:                    return envVars;
039:
040:                envVars = new Properties();
041:                rawVars = new Vector<String>(32);
042:                String lineSeparator = System.getProperty("line.separator");
043:
044:                String command = getEnvCommand();
045:
046:                CommandLauncher launcher = new CommandLauncher(
047:                        "EnvironmentReader");
048:                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
049:                try {
050:                    launcher.execute(command);
051:                    launcher.waitAndRead(outputStream, null);
052:
053:                    String envStr = outputStream.toString();
054:                    StringTokenizer strTokens = new StringTokenizer(envStr,
055:                            lineSeparator);
056:
057:                    String line;
058:                    while (strTokens.hasMoreTokens()) {
059:                        line = strTokens.nextToken();
060:
061:                        rawVars.add(line);
062:                        int idx = line.indexOf('=');
063:                        if (idx != -1) {
064:                            String key = line.substring(0, idx);
065:                            String value = line.substring(idx + 1);
066:                            envVars.setProperty(key, value);
067:                        } else {
068:                            envVars.setProperty(line, "");
069:                        }
070:                    }
071:                } catch (ProcessException e) {
072:                } finally {
073:                    try {
074:                        if (outputStream != null) {
075:                            outputStream.close();
076:                        }
077:                    } catch (IOException e) {
078:                        //ignore
079:                    }
080:                }
081:                rawVars.trimToSize();
082:                return envVars;
083:            }
084:
085:            /**
086:             * Command string to get OS Environment properties
087:             * @return String
088:             */
089:            public static String getEnvCommand() {
090:                String OS = System.getProperty("os.name").toLowerCase();
091:                if (OS.indexOf("windows 9") > -1) {
092:                    return "command.com /c set";
093:                } else {
094:                    if ((OS.indexOf("nt") > -1)
095:                            || (OS.indexOf("windows 2000") > -1)
096:                            || (OS.indexOf("windows xp") > -1)) {
097:                        return "cmd.exe /c set";
098:                    } else {
099:                        throw new UnsupportedOperationException(
100:                                "OS not supported yet");
101:                    }
102:                }
103:            }
104:
105:            /**
106:             * Get value of environment property
107:             * @param key property name
108:             * @return String value of environment property
109:             */
110:            public static String getEnvVar(String key) {
111:                Properties p = getEnvVars();
112:                return p.getProperty(key);
113:            }
114:
115:            /**
116:             * getRawEnvVars returns an array of lines read from the shell.
117:             * @return String[] lines of the shell
118:             */
119:            public static String[] getRawEnvVars() {
120:                getEnvVars();
121:                return rawVars.toArray(new String[0]);
122:            }
123:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.