edu.isi.pegasus.planner.code.generator.condor

## Class CondorQuoteParser

- java.lang.Object
- - edu.isi.pegasus.planner.code.generator.condor.CondorQuoteParser

    public class CondorQuoteParser
    extends java.lang.Object

A utility class to correctly quote arguments strings before handing over to Condor.

The following Condor Quoting Rules are followed while quoting a String.

     1) \' => ''   e.g \'Test\' is converted to ''Test''
     2) \" => ""   e.g \"Test\" is converted to ""Test""
     3) '  => '    if not enclosed in surrounding double quotes
                   e.g 'Test' is converted to 'Test'
     4) '  => ''   if enclosed in surrounding double quotes
                   e.g "'Test'" is converted to ''Test''
     5) "  => '    if not enclosed in surrounding single quotes
                   e.g Karan "Vahi" is converted to Karan 'Vahi'
     6) "  => ""   if enclosed in surrounding single quotes.
                   e.g 'Karan "Vahi"' is converted to 'Karan ""Vahi""'.
     7) *  =>  *   if enclosed in single or double quotes, the enclosed characters
                   are copied literally including \ (no escaping rules apply)
     8) \\ => \    escaping rules apply if not enclosed in single or double quotes.
                   e.g \\\\ becomes \\, and \\\ throws error.

In order to pass \n etc in the arguments, either quote it or escape it. for e.g in the DAX the following are valid ways to pass Karan\nVahi to the as arguments

       1) "Karan\nVahi"
       2) 'Karan\nVahi'
       3) Karan\\nVahi

In addition while writing out to the SubmitFile the whole argument String should be in enclosing ". for e.g arguments = "Test";

Version:
  $Revision$
Author:
  Karan Vahi, Gaurang Mehta

### Field Summary

Fields
`private static byte[][]` `cAction` There are five identified actions.
`private static byte[][]` `cState` Table to contain the state transition diagram for the parser.

### Constructor Summary

Constructors
Constructor and Description
`CondorQuoteParser()`

### Method Summary

All Methods Static Methods Concrete Methods
`static void` `main(java.lang.String[] args)` A Test program.
`static java.lang.String` `quote(java.lang.String s)` Parses a string and condor quotes it.
`static java.lang.String` `quote(java.lang.String s, boolean enclose)` Parses a string and condor quotes it.
`private static void` `test(java.lang.String s)` Helper test method that tries and catches exception

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### cState

    private static final byte[][] cState

Table to contain the state transition diagram for the parser. The rows are defined as current states 0 through 7. The columns is the current input character. The cell contains first the action to be taken, followed by the new state to transition to:

          | EOS |  \  |  '  |  "  |other|
          |  0  |  1  |  2  |  3  |  4  |
     -----+-----+-----+-----+-----+-----+
       0  | -,F |  -,1| A2,2| A2,3| A1,0|
       1  | -,E1| A1,0| A3,0| A4,0| A1,0|
       2  | -,E2| A1,2| A2,0| A4,2| A1,2|
       3  | -,E3| A1,3| A3,3| A2,0| A1,3|
     -----+-----+-----+-----+-----+-----+
       F  |  4  | final state
       E1 |  5  | error1: unexpected end of input
       E2 |  6  | error2: unmatched single quotes
       E3 |  7  | error3: unmatched double quotes

The state variable collects the new state for a given state (rows) and input character set (column) identifier.

The state diagram for the above table is shown as follows

#### cAction

    private static final byte[][] cAction

There are five identified actions.

      -   | 0 | noop
      A1  | 1 | append input character to result
      A2  | 2 | append '  to result
      A3  | 3 | append '' to result
      A4  | 4 | append "" to result

The action variable collects the action to take for a given state (rows) and input character set (column).

### Constructor Detail

#### CondorQuoteParser

    public CondorQuoteParser()

### Method Detail

#### quote

    public static java.lang.String quote(java.lang.String s)
                                  throws CondorQuoteParserException

Parses a string and condor quotes it. The enclosing quotes are not generated around the String.

Parameters:
  `s` - is the input string to parse and quote.
Returns:
  the quoted String.
Throws:
  `CondorQuoteParserException` - if the input cannot be recognized.

#### quote

    public static java.lang.String quote(java.lang.String s,
                                         boolean enclose)
                                  throws CondorQuoteParserException

Parses a string and condor quotes it. Enclosing quotes are generated around the whole string if boolean enclose parameter is set.

Parameters:
  `s` - is the input string to parse and quote.
  `enclose` - boolean indicating whether to generate enclosing quotes or not.
Returns:
  the quoted String.
Throws:
  `CondorQuoteParserException` - if the input cannot be recognized.

#### main

    public static void main(java.lang.String[] args)

A Test program.

#### test

    private static void test(java.lang.String s)

Helper test method that tries and catches exception

Parameters:
  `s` - the string to be parsed.