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


001:        /**
002:         * $Id: ClasspathGenUtil.java,v 1.7 2007/01/26 03:48:34 portalbld Exp $
003:         * Copyright 2004 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.fabric.util;
014:
015:        import java.io.File;
016:        import java.io.FileReader;
017:        import java.io.BufferedReader;
018:        import java.io.InputStream;
019:        import java.io.InputStreamReader;
020:        import java.io.IOException;
021:        import java.io.FileNotFoundException;
022:        import java.util.Properties;
023:        import java.util.logging.Level;
024:        import java.util.logging.Logger;
025:
026:        import com.sun.portal.util.ResourceLoader;
027:        import com.sun.portal.log.common.PortalLogger;
028:        import com.sun.portal.util.Platform;
029:
030:        public class ClasspathGenUtil {
031:
032:            private static final String fs = Platform.fs;
033:            private static final String SEPARATOR = "/";
034:            private static Logger logger = PortalLogger
035:                    .getLogger(ClasspathGenUtil.class);
036:
037:            public static String getClasspath(String inputfile,
038:                    boolean bReplaceTokens) {
039:
040:                BufferedReader reader = null;
041:                StringBuffer cpStrBuf = new StringBuffer();
042:
043:                try {
044:
045:                    // Get the resource loader
046:                    ResourceLoader rcl = ResourceLoader.getInstance();
047:                    // Get a property object for the PSConfig.properties file
048:                    Properties psConfig = rcl
049:                            .getProperties("PSConfig.properties");
050:
051:                    // Create a reader for the input classpath file
052:                    InputStream ins = rcl.getResourceAsStream(inputfile);
053:                    InputStreamReader insr = new InputStreamReader(ins);
054:                    reader = new BufferedReader(insr);
055:
056:                    String line = null;
057:                    while ((line = reader.readLine()) != null) {
058:
059:                        // Trim the string for removing spaces
060:                        line.trim();
061:                        // If line is empty or is a comment skip processing it
062:                        if (line.length() < 1 || line.startsWith("#")) {
063:                            continue;
064:                        }
065:
066:                        if (bReplaceTokens) {
067:                            line = processClasspathEntry(line, psConfig);
068:                        }
069:
070:                        // Add this modified entry to the classpath stringbuffer
071:                        cpStrBuf.append(line);
072:                        cpStrBuf.append(Platform.pathSep);
073:                    }
074:                } catch (FileNotFoundException fex) {
075:                    logger.log(Level.SEVERE, "PSFB_CSPFU0048", fex);
076:                } catch (IOException ioex) {
077:                    logger.log(Level.SEVERE, "PSFB_CSPFU0048", ioex);
078:                } finally {
079:                    if (reader != null) {
080:                        try {
081:                            reader.close();
082:                        } catch (IOException ioe) {
083:                            logger.log(Level.SEVERE, "PSFB_CSPFU0048", ioe);
084:                        }
085:                    }
086:                }
087:
088:                return cpStrBuf.toString();
089:            }
090:
091:            /**
092:             * Every element  represents a classpath entry.
093:             * A valid classpath entry  can be of three types:
094:             * 1. The element might be a full path on the filesystem. Just add it
095:             *    to the classpath
096:             * 2. The element might contain a tag + directory. In this case the tag
097:             *    needs to be replaced with its value in the PSConfig.properties
098:             *    then add the tagswapped string to classpath
099:             * 3. The element might be a tag that needs to be replaced. In this
100:             *    case replace the tag and add to classpath
101:             *
102:             * @param entry -  classpath entry
103:             * @param psConfig - PSConfig.properties
104:             * @return
105:             */
106:
107:            private static String processClasspathEntry(String entry,
108:                    Properties psConfig) {
109:
110:                String tag = "";
111:                String value = "";
112:
113:                // Get the index of the separator
114:                int index = entry.indexOf(SEPARATOR);
115:                // If the line contains a separator this might be of type
116:                // 1 OR 2. Else it might be of type 3
117:                if (index > 0) {
118:                    // Get the string upto the first occurence of "/"
119:                    tag = entry.substring(0, index);
120:                } else {
121:                    // The complete line might be a tag
122:                    // If its is a valid tag then it must be swapped
123:                    tag = entry;
124:                }
125:
126:                // Try to fetch the value of this tag from PSConfig
127:                // If there is no value for this string in PSConfig
128:                // Then the string is not a tag
129:                value = psConfig.getProperty(tag);
130:
131:                // If the value does not exist in PSConfig,assume that its
132:                // not a tag and just add it as is to the classpath
133:                if (value != null && value.length() > 1) {
134:                    entry = entry.replaceFirst(tag, value);
135:                }
136:                // Replace all "/" to the platform specific file separator
137:                entry = entry.replaceAll(SEPARATOR, fs);
138:                return entry;
139:            }
140:
141:            /**
142:             * Replace all tags from PSConfig.properties found in the input taggedClasspath
143:             * @param taggedClasspath - may contain tags. path elements seperated by ':'
144:             * @return
145:             */
146:            public static String tagSwapClasspath(String taggedClasspath) {
147:
148:                StringBuffer cpStrBuf = new StringBuffer();
149:
150:                try {
151:
152:                    // Get the resource loader
153:                    ResourceLoader rcl = ResourceLoader.getInstance();
154:                    // Get a property object for the PSConfig.properties file
155:                    Properties psConfig = rcl
156:                            .getProperties("PSConfig.properties");
157:
158:                    String[] cpElement = taggedClasspath.split(":");
159:                    for (int idx = 0; idx < cpElement.length; idx++) {
160:                        String entry = cpElement[idx];
161:                        // Trim the string for removing spaces
162:                        entry.trim();
163:                        // If line not empty
164:                        if (entry.length() > 0) {
165:                            entry = processClasspathEntry(entry, psConfig);
166:
167:                            // Add this modified entry to the classpath stringbuffer
168:                            cpStrBuf.append(entry);
169:                            cpStrBuf.append(Platform.pathSep);
170:                        }
171:                    }
172:                } catch (FileNotFoundException fex) {
173:                    logger.log(Level.SEVERE, "PSFB_CSPFU0049", fex);
174:                } catch (IOException ioex) {
175:                    logger.log(Level.SEVERE, "PSFB_CSPFU0049", ioex);
176:                }
177:
178:                return cpStrBuf.toString();
179:            }
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.