Top Description Fields Constructors Methods
org.codehaus.jettison.util

public Class StringIndenter

extends Object
Class Inheritance

indent json, assumes the input is not yet indented.  here is an example:
{
"FastResponseJs":{
  "ajaxElements":{
    "AjaxMapEntry":[
      {
        "theKey":{
          "@class":"string",
          "$":"ajax1a"
        },
        "theValue":{
          "@class":"AjaxEvent",
          "ajaxSendFormNames":{
            "string":"ajax1"
          },
          "ajaxEventType":"NORMAL",
          "eventName":"onblur",
          "ajaxId":"PRLZY5QZ",
          "screenElementId":"ajax1a",
          "asynchronous":true,
          "disableValidation":true
        }

      },
      {
        "theKey":{
       ...


  Usage: String formatted = new StringIndenter(jsonString).result();

Field Summary

Modifier and TypeField and Description
private int
currentNumberOfIndents

current number of indents (times to is the indent

private int
endTagIndex

current end tag

private String
json

chars to process

private StringBuilder
result

result

private int
startTagIndex

current start tag

Constructor Summary

AccessConstructor and Description
public
StringIndenter(String
is the json to format indenter
theJson
)

Method Summary

Modifier and TypeMethod and Description
private int

Returns:

the next start tag
findEndTagIndex
()

after the last start tag, find the next end start tag

private static int

Returns:

the start tag index of -1 if not found another
findNextEndTagIndex
(String json, int
is the char after the start of tag
startFrom
)

find the end tag from json and a start from index

private static int

Returns:

the start tag index of -1 if not found another
findNextStartTagIndex
(String json, int startFrom)

find the start tag from json and a start from index either look for a quote, {, [ or scalar.

private int

Returns:

the next start tag
findStartTagIndex
()

after the last end tag, find the next start tag

private void
indent()

indent the string

private static boolean

Returns:

if it is an instant indent
instantIndent
(String json, int index)

see if instant indent

private static boolean

Returns:

if it is an instant indent
instantNewline
(String json, int index)

see if instant indent

private static boolean

Returns:

if it is an instant unindent
instantUnindent
(String json, int index)

see if instant unindent

private static boolean

Returns:

if it is an instant indent
instantUnindentTwoChars
(String json, int index)

see if instant indent

private void
newlineIndent()

put a newline and indent

private boolean

Returns:

true if on new line
onNewline
()

see if current pos is on newline

private void
printNewlineIndent(int start, int end)

put a newline and indent

private static String

Returns:

the string
repeat
(String theString, int times)

repeat a string a certain number of times.

public String

Returns:

the result
result
()

get the result

private void
unindent()

unindent a previous indent if it is there

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentNumberOfIndentsback to summary
private int currentNumberOfIndents

current number of indents (times to is the indent

endTagIndexback to summary
private int endTagIndex

current end tag

jsonback to summary
private String json

chars to process

resultback to summary
private StringBuilder result

result

startTagIndexback to summary
private int startTagIndex

current start tag

Constructor Detail

StringIndenterback to summary
public StringIndenter(String theJson)
Parameters
theJson:String

is the json to format indenter

Method Detail

findEndTagIndexback to summary
private int findEndTagIndex()

after the last start tag, find the next end start tag

Returns:int

the next start tag

findNextEndTagIndexback to summary
private static int findNextEndTagIndex(String json, int startFrom)

find the end tag from json and a start from index

Parameters
startFrom:int

is the char after the start of tag

Returns:int

the start tag index of -1 if not found another

findNextStartTagIndexback to summary
private static int findNextStartTagIndex(String json, int startFrom)

find the start tag from json and a start from index either look for a quote, {, [ or scalar. generally not whitespace

Returns:int

the start tag index of -1 if not found another

findStartTagIndexback to summary
private int findStartTagIndex()

after the last end tag, find the next start tag

Returns:int

the next start tag

indentback to summary
private void indent()

indent the string

instantIndentback to summary
private static boolean instantIndent(String json, int index)

see if instant indent

Returns:boolean

if it is an instant indent

instantNewlineback to summary
private static boolean instantNewline(String json, int index)

see if instant indent

Returns:boolean

if it is an instant indent

instantUnindentback to summary
private static boolean instantUnindent(String json, int index)

see if instant unindent

Returns:boolean

if it is an instant unindent

instantUnindentTwoCharsback to summary
private static boolean instantUnindentTwoChars(String json, int index)

see if instant indent

Returns:boolean

if it is an instant indent

newlineIndentback to summary
private void newlineIndent()

put a newline and indent

onNewlineback to summary
private boolean onNewline()

see if current pos is on newline

Returns:boolean

true if on new line

printNewlineIndentback to summary
private void printNewlineIndent(int start, int end)

put a newline and indent

repeatback to summary
private static String repeat(String theString, int times)

repeat a string a certain number of times.

Returns:String

the string

resultback to summary
public String result()

get the result

Returns:String

the result

unindentback to summary
private void unindent()

unindent a previous indent if it is there