001package org.apache.commons.ssl.org.bouncycastle.asn1.x509; 002 003/** 004 * class for breaking up an X500 Name into it's component tokens, ala 005 * java.util.StringTokenizer. We need this class as some of the 006 * lightweight Java environment don't support classes like 007 * StringTokenizer. 008 * @deprecated use X500NameTokenizer 009 */ 010public class X509NameTokenizer 011{ 012 private String value; 013 private int index; 014 private char separator; 015 private StringBuffer buf = new StringBuffer(); 016 017 public X509NameTokenizer( 018 String oid) 019 { 020 this(oid, ','); 021 } 022 023 public X509NameTokenizer( 024 String oid, 025 char separator) 026 { 027 this.value = oid; 028 this.index = -1; 029 this.separator = separator; 030 } 031 032 public boolean hasMoreTokens() 033 { 034 return (index != value.length()); 035 } 036 037 public String nextToken() 038 { 039 if (index == value.length()) 040 { 041 return null; 042 } 043 044 int end = index + 1; 045 boolean quoted = false; 046 boolean escaped = false; 047 048 buf.setLength(0); 049 050 while (end != value.length()) 051 { 052 char c = value.charAt(end); 053 054 if (c == '"') 055 { 056 if (!escaped) 057 { 058 quoted = !quoted; 059 } 060 buf.append(c); 061 escaped = false; 062 } 063 else 064 { 065 if (escaped || quoted) 066 { 067 buf.append(c); 068 escaped = false; 069 } 070 else if (c == '\\') 071 { 072 buf.append(c); 073 escaped = true; 074 } 075 else if (c == separator) 076 { 077 break; 078 } 079 else 080 { 081 buf.append(c); 082 } 083 } 084 end++; 085 } 086 087 index = end; 088 089 return buf.toString(); 090 } 091}