1
2
3
4
5
6 package org.apache.ws.security.components.crypto;
7
8 /***
9 * class for breaking up an X500 Name into it's component tokens, ala
10 * java.util.StringTokenizer. We need this class as some of the
11 * lightweight Java environment don't support classes like
12 * StringTokenizer.
13 */
14 public class X509NameTokenizer {
15 private String oid;
16 private int index;
17 private StringBuffer buf = new StringBuffer();
18
19 public X509NameTokenizer(String oid) {
20 this.oid = oid;
21 this.index = -1;
22 }
23
24 public boolean hasMoreTokens() {
25 return (index != oid.length());
26 }
27
28 public String nextToken() {
29 if (index == oid.length()) {
30 return null;
31 }
32
33 int end = index + 1;
34 boolean quoted = false;
35 boolean escaped = false;
36
37 buf.setLength(0);
38
39 while (end != oid.length()) {
40 char c = oid.charAt(end);
41
42 if (c == '"') {
43 if (!escaped) {
44 quoted = !quoted;
45 } else {
46 buf.append(c);
47 }
48 escaped = false;
49 } else {
50 if (escaped || quoted) {
51 buf.append(c);
52 escaped = false;
53 } else if (c == '//') {
54 escaped = true;
55 } else if (c == ',') {
56 break;
57 } else {
58 buf.append(c);
59 }
60 }
61 end++;
62 }
63
64 index = end;
65 return buf.toString().trim();
66 }
67 }