org.apache.jackrabbit.mk.json
Class JsopTokenizer

java.lang.Object
  extended by org.apache.jackrabbit.mk.json.JsopTokenizer
All Implemented Interfaces:
JsopReader

public class JsopTokenizer
extends Object
implements JsopReader

A tokenizer for Json and Jsop strings.


Field Summary
static int COMMENT
           
static int END
           
static int ERROR
           
static int FALSE
           
static int IDENTIFIER
           
static int NULL
           
static int NUMBER
           
static int STRING
           
static int TRUE
           
 
Constructor Summary
JsopTokenizer(String json)
           
JsopTokenizer(String json, int pos)
           
 
Method Summary
static String decode(String s)
          Decode a Json string.
static String decodeQuoted(String s)
          Decode a quoted Json string.
 String getEscapedToken()
          Get the last encoded (raw) string, including escape sequences.
 int getLastPos()
           
 int getPos()
           
 String getToken()
          Get the last token value if the the token type was STRING or NUMBER.
 int getTokenType()
          Get the token type of the last token.
 boolean matches(int type)
          Read a token which must match a given token type.
 int read()
          Read a token and return the token type.
 String read(int type)
          Read a token which must match a given token type.
 String readRawValue()
          Read a value and return the raw Json representation.
 String readString()
          Read a string.
 void resetReader()
           
 void setPos(int pos)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

END

public static final int END
See Also:
Constant Field Values

STRING

public static final int STRING
See Also:
Constant Field Values

NUMBER

public static final int NUMBER
See Also:
Constant Field Values

TRUE

public static final int TRUE
See Also:
Constant Field Values

FALSE

public static final int FALSE
See Also:
Constant Field Values

NULL

public static final int NULL
See Also:
Constant Field Values

ERROR

public static final int ERROR
See Also:
Constant Field Values

IDENTIFIER

public static final int IDENTIFIER
See Also:
Constant Field Values

COMMENT

public static final int COMMENT
See Also:
Constant Field Values
Constructor Detail

JsopTokenizer

public JsopTokenizer(String json,
                     int pos)

JsopTokenizer

public JsopTokenizer(String json)
Method Detail

resetReader

public void resetReader()
Specified by:
resetReader in interface JsopReader

toString

public String toString()
Overrides:
toString in class Object

getTokenType

public int getTokenType()
Get the token type of the last token.

Specified by:
getTokenType in interface JsopReader
Returns:
the token type

getToken

public String getToken()
Get the last token value if the the token type was STRING or NUMBER. For STRING, the text is decoded; for NUMBER, it is returned as parsed. In all other cases the result is undefined.

Specified by:
getToken in interface JsopReader
Returns:
the token

getEscapedToken

public String getEscapedToken()
Get the last encoded (raw) string, including escape sequences.

Returns:
the encoded string

read

public String read(int type)
Read a token which must match a given token type.

Specified by:
read in interface JsopReader
Parameters:
type - the token type
Returns:
the token (a null object when reading a null value)
Throws:
IllegalStateException - if the token type doesn't match

readString

public String readString()
Read a string.

Specified by:
readString in interface JsopReader
Returns:
the de-escaped string
Throws:
IllegalStateException - if the token type doesn't match

matches

public boolean matches(int type)
Read a token which must match a given token type.

Specified by:
matches in interface JsopReader
Parameters:
type - the token type
Returns:
true if there was a match

read

public int read()
Read a token and return the token type.

Specified by:
read in interface JsopReader
Returns:
the token type

decodeQuoted

public static String decodeQuoted(String s)
Decode a quoted Json string.

Parameters:
s - the encoded string, with double quotes
Returns:
the string

decode

public static String decode(String s)
Decode a Json string.

Parameters:
s - the encoded string, without double quotes
Returns:
the string

readRawValue

public String readRawValue()
Read a value and return the raw Json representation.

Specified by:
readRawValue in interface JsopReader
Returns:
the Json representation of the value

getPos

public int getPos()

getLastPos

public int getLastPos()

setPos

public void setPos(int pos)


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.