01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.crypto.asn1.x509;
17:
18: /**
19: * class for breaking up an X500 Name into it's component tokens, ala
20: * java.util.StringTokenizer. We need this class as some of the
21: * lightweight Java environment don't support classes like
22: * StringTokenizer.
23: */
24: public class X509NameTokenizer {
25: private String value;
26: private int index;
27: private char seperator;
28: private StringBuffer buf = new StringBuffer();
29:
30: public X509NameTokenizer(String oid) {
31: this (oid, ',');
32: }
33:
34: public X509NameTokenizer(String oid, char seperator) {
35: this .value = oid;
36: this .index = -1;
37: this .seperator = seperator;
38: }
39:
40: public boolean hasMoreTokens() {
41: return (index != value.length());
42: }
43:
44: public String nextToken() {
45: if (index == value.length()) {
46: return null;
47: }
48:
49: int end = index + 1;
50: boolean quoted = false;
51: boolean escaped = false;
52:
53: buf.setLength(0);
54:
55: while (end != value.length()) {
56: char c = value.charAt(end);
57:
58: if (c == '"') {
59: if (!escaped) {
60: quoted = !quoted;
61: } else {
62: buf.append(c);
63: }
64: escaped = false;
65: } else {
66: if (escaped || quoted) {
67: buf.append(c);
68: escaped = false;
69: } else if (c == '\\') {
70: escaped = true;
71: } else if (c == seperator) {
72: break;
73: } else {
74: buf.append(c);
75: }
76: }
77: end++;
78: }
79:
80: index = end;
81: return buf.toString().trim();
82: }
83: }
|