org.alfresco.util.exec
Class ExecParameterTokenizer

java.lang.Object
  extended by org.alfresco.util.exec.ExecParameterTokenizer

public class ExecParameterTokenizer
extends java.lang.Object

This class is used to tokenize strings used as parameters for RuntimeExec objects. Examples of such strings are as follows (ImageMagick-like parameters):

The first is the simple case which would be parsed into Strings as follows: "-font", "Helvetica", "-pointsize", "50"

The second is more complex in that it includes a quoted parameter, which would be parsed as a single String: "-font", "Helvetica", "-pointsize", "50", "circle 100,100 150,150" Note however that the quotation characters will be stripped from the token.

The third shows an example with embedded quotation marks, which would parse to: "-font", "Helvetica", "-pointsize", "50", "gravity south fill black text 0,12 'CopyRight'" In this case, the embedded quotation marks (which must be different from those surrounding the parameter) are preserved in the extracted token.

The class does not understand escaped quotes such as p1 p2 "a b c \"hello\" d" p4

Since:
3.4.2

Nested Class Summary
 class ExecParameterTokenizer.QuotedSubstring
          A substring that is surrounded by (single or double) quotes.
static interface ExecParameterTokenizer.Substring
          Utility interface for a substring in a parameter string.
 class ExecParameterTokenizer.UnquotedSubstring
          A substring that is not surrounded by (single or double) quotes.
 
Constructor Summary
ExecParameterTokenizer(java.lang.String str)
           
 
Method Summary
 java.util.List getAllTokens()
          This method returns the tokens in a parameter string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExecParameterTokenizer

public ExecParameterTokenizer(java.lang.String str)
Method Detail

getAllTokens

public java.util.List getAllTokens()
This method returns the tokens in a parameter string. Any tokens not contained within single or double quotes will be tokenized in the normal way i.e. by using whitespace separators and the standard StringTokenizer algorithm. Any tokens which are contained within single or double quotes will be returned as single String instances and will have their quote marks removed.

See above for examples.

Throws:
java.lang.NullPointerException - if the string to be tokenized was null.


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.