com.plumtree.portalpages.rest.utils
Class JSONParser

java.lang.Object
  extended by com.plumtree.portalpages.rest.utils.JSONParser
All Implemented Interfaces:
IJSONParser

public class JSONParser
extends java.lang.Object
implements IJSONParser

This JSON parser handles simple objects only. It is very limited, and does not handle arrays, or non-string object types. It also only handles escaped quotes and slashes, and only allows double quotes around values, not single quotes.


Field Summary
protected static char CLOSE_CURLY_BRACKET
           
protected static char COMMA
           
protected static char ESCAPE
           
protected  java.lang.String m_strObjectName
           
protected  XPHashtable m_xpMembers
           
protected static char OPEN_CURLY_BRACKET
           
protected static char QUOTE
           
protected static char SEMI_COLON
           
 
Method Summary
 java.lang.String GetEscapedTokenAndEndQuote(XPStringTokenizer _tokenizer)
          This gets an escaped quoted sequence, starting immediately after the opening quote.
static IJSONParser GetInstance()
           
 java.lang.String GetMember(java.lang.String _strName)
           
 java.lang.String GetObjectName()
           
 java.lang.String GetToken(XPStringTokenizer _tokenizer)
           
 boolean IsWhiteSpace(java.lang.String _strToken)
          Checks if a token is a single piece of whitespace.
 void ParseJSONObject(java.lang.String _strJSON)
          Parses the supplied JSON object.
 void SkipToken(XPStringTokenizer _tokenizer, char _token)
          Skip the next token if it matches the expected token.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPEN_CURLY_BRACKET

protected static final char OPEN_CURLY_BRACKET
See Also:
Constant Field Values

CLOSE_CURLY_BRACKET

protected static final char CLOSE_CURLY_BRACKET
See Also:
Constant Field Values

QUOTE

protected static final char QUOTE
See Also:
Constant Field Values

SEMI_COLON

protected static final char SEMI_COLON
See Also:
Constant Field Values

COMMA

protected static final char COMMA
See Also:
Constant Field Values

ESCAPE

protected static final char ESCAPE
See Also:
Constant Field Values

m_strObjectName

protected java.lang.String m_strObjectName

m_xpMembers

protected XPHashtable m_xpMembers
Method Detail

GetInstance

public static IJSONParser GetInstance()
Returns:
an instance of a IJSONParser.

ParseJSONObject

public void ParseJSONObject(java.lang.String _strJSON)
Description copied from interface: IJSONParser
Parses the supplied JSON object.

Specified by:
ParseJSONObject in interface IJSONParser
Parameters:
_strJSON - the JSON string to be parsed.

GetToken

public java.lang.String GetToken(XPStringTokenizer _tokenizer)
Parameters:
_tokenizer - the JSON tokenizer
Returns:
the next token without whitespace.

SkipToken

public void SkipToken(XPStringTokenizer _tokenizer,
                      char _token)
Skip the next token if it matches the expected token.

Parameters:
_tokenizer - the JSON tokenizer
_token - the expected token
Throws:
XPFormatException - if the next token doesn't match the expected token.

IsWhiteSpace

public boolean IsWhiteSpace(java.lang.String _strToken)
Checks if a token is a single piece of whitespace.

Parameters:
_strToken -
Returns:
boolean true means that the token is whitespace.

GetEscapedTokenAndEndQuote

public java.lang.String GetEscapedTokenAndEndQuote(XPStringTokenizer _tokenizer)
This gets an escaped quoted sequence, starting immediately after the opening quote. It reads the end quote, but does not return it.

Parameters:
_tokenizer -
Returns:
the escaped string token. The closing quote has been read.
Throws:
XPFormatException

GetObjectName

public java.lang.String GetObjectName()
Specified by:
GetObjectName in interface IJSONParser
Returns:
the top-level JSON object name.

GetMember

public java.lang.String GetMember(java.lang.String _strName)
Specified by:
GetMember in interface IJSONParser
Parameters:
_strName - The key for the JSON member to be returned.
Returns:
the requested JSON member value.



Copyright © 2002,2003,2004,2005 Plumtree Software, Inc., All Rights Reserved.