1 18 package org.apache.tools.ant; 19 20 import java.io.File ; 21 import java.util.NoSuchElementException ; 22 import java.util.StringTokenizer ; 23 import org.apache.tools.ant.taskdefs.condition.Os; 24 25 33 public class PathTokenizer { 34 37 private StringTokenizer tokenizer; 38 39 43 private String lookahead = null; 44 45 50 private boolean onNetWare = Os.isFamily("netware"); 51 52 56 private boolean dosStyleFilesystem; 57 58 63 public PathTokenizer(String path) { 64 if (onNetWare) { 65 tokenizer = new StringTokenizer (path, ":;", true); 68 } else { 69 tokenizer = new StringTokenizer (path, ":;", false); 72 } 73 dosStyleFilesystem = File.pathSeparatorChar == ';'; 74 } 75 76 84 public boolean hasMoreTokens() { 85 if (lookahead != null) { 86 return true; 87 } 88 89 return tokenizer.hasMoreTokens(); 90 } 91 92 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 && Character.isLetter(token.charAt(0)) 111 && dosStyleFilesystem 112 && tokenizer.hasMoreTokens()) { 113 String nextToken = tokenizer.nextToken().trim(); 116 if (nextToken.startsWith("\\") || nextToken.startsWith("/")) { 117 token += ":" + nextToken; 121 } else { 122 lookahead = nextToken; 124 } 125 } 126 } else { 127 if (token.equals(File.pathSeparator) || token.equals(":")) { 130 token = tokenizer.nextToken().trim(); 132 } 133 134 if (tokenizer.hasMoreTokens()) { 135 String nextToken = tokenizer.nextToken().trim(); 137 138 if (!nextToken.equals(File.pathSeparator)) { 140 if (nextToken.equals(":")) { 141 if (!token.startsWith("/") && !token.startsWith("\\") 142 && !token.startsWith(".") 143 && !token.startsWith("..")) { 144 String oneMore = tokenizer.nextToken().trim(); 146 if (!oneMore.equals(File.pathSeparator)) { 147 token += ":" + oneMore; 148 } else { 149 token += ":"; 150 lookahead = oneMore; 151 } 152 } 153 } else { 156 lookahead = nextToken; 158 } 159 } 160 } 161 } 162 return token; 163 } 164 } 165 166 | Popular Tags |