Methods Summary |
---|
private boolean | checkForMatchingQuotes(java.lang.String str)This method will check for matching quotes. If quotes do not match then
return false else return true.
//get index of the first quote in the string
int beginQuote = getStringDelimiterIndex(str, QUOTE_STRING, 0);
while (beginQuote != -1)
{
int endQuote = getStringDelimiterIndex(str, QUOTE_STRING, beginQuote+1);
if (endQuote == -1) return false;
beginQuote = getStringDelimiterIndex(str, QUOTE_STRING, endQuote+1);
}
return true;
|
public int | countTokens()returns the number of tokens in the string.
return size;
|
private java.lang.String | getLocalizedString(java.lang.String key)returns the localized string from the properties file as defined in the
CommandProperties element of CLIDescriptor.xml file
Calls the LocalStringsManagerFactory.getCommandLocalStringsManager()
method, returns "Key not found" if it cannot find the key
LocalStringsManager lsm = null;
try
{
lsm = LocalStringsManagerFactory.getCommandLocalStringsManager();
}
catch (CommandValidationException cve)
{
return LocalStringsManager.DEFAULT_STRING_VALUE;
}
return lsm.getString(key);
|
private int | getStringDelimiterIndex(java.lang.String strToken, java.lang.String delimiter, int fromIndex)This method returns the index of the delimiter. It will factor out the
escape and quote characters.
if (fromIndex > strToken.length()-1) return -1;
//get index of the delimiter
final int hasDelimiter = strToken.indexOf(delimiter, fromIndex);
//get index of the first quote in the string token
final int quoteBeginIndex = strToken.indexOf(QUOTE_STRING, fromIndex);
// ex: set server.ias1.jdbcurl="jdbc://oracle"
// if there's is a quote and a delimiter, then find the end quote
if ((quoteBeginIndex != -1) && (hasDelimiter != -1) &&
(quoteBeginIndex < hasDelimiter))
{
//get index of the end quote in the string token
final int quoteEndIndex = strToken.indexOf(QUOTE_STRING, quoteBeginIndex+1);
if (quoteEndIndex == -1)
throw new CommandException(getLocalizedString("UnclosedString"));
if (quoteEndIndex != (strToken.length()-1))
{
return getStringDelimiterIndex(strToken, delimiter, quoteEndIndex + 1);
}
else
{
return -1;
}
}
if ((hasDelimiter > 0) && (strToken.charAt(hasDelimiter-1) == ESCAPE_CHAR))
{
return getStringDelimiterIndex(strToken, delimiter, hasDelimiter+1);
}
else
{
return hasDelimiter;
}
|
public boolean | hasMoreTokens()returns true is there are more token in the list
return tokenIterator.hasNext();
|
public static void | main(java.lang.String[] args)
try {
final CLITokenizer ct = new CLITokenizer(args[0], ":");
while (ct.hasMoreTokens()) {
final String nameAndvalue = ct.nextToken();
final CLITokenizer ct2 = new CLITokenizer(nameAndvalue, "=");
System.out.println("+++++ ct2 tokens = " + ct2.countTokens() + " +++++");
if (ct2.countTokens() == 1)
{
System.out.println(ct2.nextTokenWithoutEscapeAndQuoteChars());
}
else if (ct2.countTokens() == 2)
{
System.out.println(ct2.nextTokenWithoutEscapeAndQuoteChars() + " " +
ct2.nextTokenWithoutEscapeAndQuoteChars());
}
System.out.println("+++++ " + nameAndvalue + " +++++");
}
System.out.println("***** the end *****");
}
catch (Exception e) {
e.printStackTrace();
}
|
public java.lang.String | nextToken()returns the next token string
return (String)tokenIterator.next();
|
public java.lang.String | nextTokenWithoutEscapeAndQuoteChars()returns the token string without the escape characters
final String strWOEscape = removeEscapeChars((String)tokenIterator.next());
final String strWOQuotes = removeQuoteChars(strWOEscape);
return removeEscapeCharsFromQuotes(strWOQuotes);
|
private java.util.ListIterator | populateList(java.lang.String strToken, java.lang.String delimiter)this methos calls the getStringDelimiterIndex to determine the index
of the delimiter and use that to populate the tokenIterator.
java.util.List tokenList = new java.util.Vector();
int endIndex = getStringDelimiterIndex(strToken, delimiter, 0);
if (endIndex == -1) tokenList.add(strToken);
else
{
int beginIndex = 0;
while (endIndex > -1)
{
//do not want to add to the list if the string is empty
if (beginIndex != endIndex)
tokenList.add(strToken.substring(beginIndex, endIndex));
beginIndex = endIndex + 1;
endIndex = getStringDelimiterIndex(strToken, delimiter, beginIndex);
}
//do not want to add to the list if the begindIndex is the last index
if (beginIndex != strToken.length())
tokenList.add(strToken.substring(beginIndex));
}
size = tokenList.size();
try {
return tokenList.listIterator();
}
catch (java.lang.IndexOutOfBoundsException ioe) {
throw new CommandException(ioe);
}
|
private java.lang.String | removeEscapeChars(java.lang.String strValue)Removes the escape characters from the property value
int prefixIndex = 0;
java.lang.StringBuffer strbuff = new java.lang.StringBuffer();
while (prefixIndex < strValue.length())
{
int delimeterIndex = getStringDelimiterIndex(strValue,
String.valueOf(ESCAPE_CHAR), prefixIndex);
if (delimeterIndex == -1)
{
strbuff.append(strValue.substring(prefixIndex));
break;
}
//if a quote is follow by an esacpe then keep the escape character
if (delimeterIndex+1 < strValue.length() &&
String.valueOf(strValue.charAt(delimeterIndex+1)).equals(QUOTE_STRING))
strbuff.append(strValue.substring(prefixIndex, delimeterIndex+1));
else
strbuff.append(strValue.substring(prefixIndex, delimeterIndex));
prefixIndex = delimeterIndex+1;
}
return strbuff.toString();
|
private java.lang.String | removeEscapeCharsFromQuotes(java.lang.String strValue)Removes escape characters that precedes quotes
int prefixIndex = 0;
java.lang.StringBuffer strbuff = new java.lang.StringBuffer();
while (prefixIndex < strValue.length())
{
int delimeterIndex = strValue.indexOf(String.valueOf(ESCAPE_CHAR), prefixIndex);
if (delimeterIndex == -1)
{
strbuff.append(strValue.substring(prefixIndex));
break;
}
//if a quote is follow by an esacpe then remove the escape character
if (String.valueOf(strValue.charAt(delimeterIndex+1)).equals(QUOTE_STRING))
strbuff.append(strValue.substring(prefixIndex, delimeterIndex));
else
strbuff.append(strValue.substring(prefixIndex, delimeterIndex+1));
prefixIndex = delimeterIndex+1;
}
return strbuff.toString();
|
private java.lang.String | removeQuoteChars(java.lang.String strValue)Removes the quote characters from the property value
int prefixIndex = 0;
java.lang.StringBuffer strbuff = new java.lang.StringBuffer();
while (prefixIndex < strValue.length())
{
int delimeterIndex = getStringDelimiterIndex(strValue,
QUOTE_STRING, prefixIndex);
if (delimeterIndex == -1)
{
strbuff.append(strValue.substring(prefixIndex));
break;
}
strbuff.append(strValue.substring(prefixIndex, delimeterIndex));
prefixIndex = delimeterIndex+1;
}
return strbuff.toString();
|