1 23 24 package org.apache.slide.common; 25 26 import java.util.StringTokenizer ; 27 import java.util.Vector ; 28 import java.util.NoSuchElementException ; 29 30 45 public final class UriTokenizer extends StringTokenizer { 46 47 48 50 51 57 public UriTokenizer(SlideToken slideToken, Namespace namespace, String uri) { 58 super(uri, "/"); 59 60 uris = new Vector (); 62 63 this.slideToken = slideToken; 64 this.namespace = namespace; 65 66 String courScope = new String (); 67 68 uris.addElement("/"); 69 70 while(super.hasMoreTokens()) { 72 courScope = courScope + "/" + super.nextToken(); 73 uris.addElement(courScope); 74 } 75 76 pos = 0; 77 } 78 79 80 86 public UriTokenizer(Namespace namespace, String uri) { 87 this(null, namespace, uri); 88 } 89 90 91 97 public UriTokenizer(Namespace namespace, Scope scope) { 98 this(null, namespace, scope.toString()); 99 } 100 101 102 104 105 108 Vector uris; 109 110 111 114 int pos; 115 116 117 120 Namespace namespace; 121 122 SlideToken slideToken; 123 124 125 127 128 133 public Uri getParentUri() { 134 if (uris.size() < 1) { 135 return null; 136 } else { 137 return namespace.getUri(slideToken, (String ) uris.elementAt(uris.size() - 1)); 138 } 139 } 140 141 142 147 public boolean hasMoreElements() { 148 return uris.size() > pos; 149 } 150 151 152 157 public boolean hasMoreTokens() { 158 return hasMoreElements(); 159 } 160 161 162 168 public Object nextElement() 169 throws NoSuchElementException { 170 Object obj = null; 171 try { 172 if (!hasMoreElements()) { 173 throw new NoSuchElementException (); 174 } 175 obj = uris.elementAt(pos); 176 pos = pos + 1; 177 } catch (ArrayIndexOutOfBoundsException e) { 178 e.printStackTrace(); 180 } 181 return obj; 182 } 183 184 185 191 public String nextToken() 192 throws NoSuchElementException { 193 return (String ) nextElement(); 194 } 195 196 197 203 public Uri nextUri() 204 throws NoSuchElementException { 205 return namespace.getUri(slideToken, nextToken()); 206 } 207 208 209 215 public String nextToken(String delim) 216 throws NoSuchElementException { 217 return nextToken(); 218 } 219 220 } 221 | Popular Tags |