Source Code Cross Referenced for PathTokenizer.java in  » Build » ANT » org » apache » tools » ant » 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 » Build » ANT » org.apache.tools.ant 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:        package org.apache.tools.ant;
019:
020:        import java.io.File;
021:        import java.util.NoSuchElementException;
022:        import java.util.StringTokenizer;
023:        import org.apache.tools.ant.taskdefs.condition.Os;
024:
025:        /**
026:         * A Path tokenizer takes a path and returns the components that make up
027:         * that path.
028:         *
029:         * The path can use path separators of either ':' or ';' and file separators
030:         * of either '/' or '\'.
031:         *
032:         */
033:        public class PathTokenizer {
034:            /**
035:             * A tokenizer to break the string up based on the ':' or ';' separators.
036:             */
037:            private StringTokenizer tokenizer;
038:
039:            /**
040:             * A String which stores any path components which have been read ahead
041:             * due to DOS filesystem compensation.
042:             */
043:            private String lookahead = null;
044:
045:            /**
046:             * A boolean that determines if we are running on Novell NetWare, which
047:             * exhibits slightly different path name characteristics (multi-character
048:             * volume / drive names)
049:             */
050:            private boolean onNetWare = Os.isFamily("netware");
051:
052:            /**
053:             * Flag to indicate whether or not we are running on a platform with a
054:             * DOS style filesystem
055:             */
056:            private boolean dosStyleFilesystem;
057:
058:            /**
059:             * Constructs a path tokenizer for the specified path.
060:             *
061:             * @param path The path to tokenize. Must not be <code>null</code>.
062:             */
063:            public PathTokenizer(String path) {
064:                if (onNetWare) {
065:                    // For NetWare, use the boolean=true mode, so we can use delimiter
066:                    // information to make a better decision later.
067:                    tokenizer = new StringTokenizer(path, ":;", true);
068:                } else {
069:                    // on Windows and Unix, we can ignore delimiters and still have
070:                    // enough information to tokenize correctly.
071:                    tokenizer = new StringTokenizer(path, ":;", false);
072:                }
073:                dosStyleFilesystem = File.pathSeparatorChar == ';';
074:            }
075:
076:            /**
077:             * Tests if there are more path elements available from this tokenizer's
078:             * path. If this method returns <code>true</code>, then a subsequent call
079:             * to nextToken will successfully return a token.
080:             *
081:             * @return <code>true</code> if and only if there is at least one token
082:             * in the string after the current position; <code>false</code> otherwise.
083:             */
084:            public boolean hasMoreTokens() {
085:                if (lookahead != null) {
086:                    return true;
087:                }
088:
089:                return tokenizer.hasMoreTokens();
090:            }
091:
092:            /**
093:             * Returns the next path element from this tokenizer.
094:             *
095:             * @return the next path element from this tokenizer.
096:             *
097:             * @exception NoSuchElementException if there are no more elements in this
098:             *            tokenizer's path.
099:             */
100:            public String nextToken() throws NoSuchElementException {
101:                String token = null;
102:                if (lookahead != null) {
103:                    token = lookahead;
104:                    lookahead = null;
105:                } else {
106:                    token = tokenizer.nextToken().trim();
107:                }
108:
109:                if (!onNetWare) {
110:                    if (token.length() == 1
111:                            && Character.isLetter(token.charAt(0))
112:                            && dosStyleFilesystem && tokenizer.hasMoreTokens()) {
113:                        // we are on a dos style system so this path could be a drive
114:                        // spec. We look at the next token
115:                        String nextToken = tokenizer.nextToken().trim();
116:                        if (nextToken.startsWith("\\")
117:                                || nextToken.startsWith("/")) {
118:                            // we know we are on a DOS style platform and the next path
119:                            // starts with a slash or backslash, so we know this is a
120:                            // drive spec
121:                            token += ":" + nextToken;
122:                        } else {
123:                            // store the token just read for next time
124:                            lookahead = nextToken;
125:                        }
126:                    }
127:                } else {
128:                    // we are on NetWare, tokenizing is handled a little differently,
129:                    // due to the fact that NetWare has multiple-character volume names.
130:                    if (token.equals(File.pathSeparator) || token.equals(":")) {
131:                        // ignore ";" and get the next token
132:                        token = tokenizer.nextToken().trim();
133:                    }
134:
135:                    if (tokenizer.hasMoreTokens()) {
136:                        // this path could be a drive spec, so look at the next token
137:                        String nextToken = tokenizer.nextToken().trim();
138:
139:                        // make sure we aren't going to get the path separator next
140:                        if (!nextToken.equals(File.pathSeparator)) {
141:                            if (nextToken.equals(":")) {
142:                                if (!token.startsWith("/")
143:                                        && !token.startsWith("\\")
144:                                        && !token.startsWith(".")
145:                                        && !token.startsWith("..")) {
146:                                    // it indeed is a drive spec, get the next bit
147:                                    String oneMore = tokenizer.nextToken()
148:                                            .trim();
149:                                    if (!oneMore.equals(File.pathSeparator)) {
150:                                        token += ":" + oneMore;
151:                                    } else {
152:                                        token += ":";
153:                                        lookahead = oneMore;
154:                                    }
155:                                }
156:                                // implicit else: ignore the ':' since we have either a
157:                                // UNIX or a relative path
158:                            } else {
159:                                // store the token just read for next time
160:                                lookahead = nextToken;
161:                            }
162:                        }
163:                    }
164:                }
165:                return token;
166:            }
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.