org.tinyjee.maven.dim.utils
Class PositioningJsonDocumentBuilder

java.lang.Object
  extended by org.tinyjee.maven.dim.utils.AbstractPositioningDocumentBuilder
      extended by org.tinyjee.maven.dim.utils.PositioningJsonDocumentBuilder

public class PositioningJsonDocumentBuilder
extends AbstractPositioningDocumentBuilder

Creates a Document builder that parses JSON instead of XML and adds user-data into the parsed DOM nodes that covers line number and column information. The purpose of this implementation is to apply XPath queries on JSON to drive snippet selection.

Translations Rules:

Example - Input:

 {
     "name" : {
         "first" : "Joe",
         "last" : "Sixpack"
     },
     "gender" : "MALE",
     "verified" : false,
     "flags" : ["123", 123, "xyz", {
         "composite": 987,
         "inner flags": [1,{
             "innermost":"abc",
             "innermost-object" : {
                 "x":1
             }
         },3]
     }],
     "userImage" : "Rm9vYmFyIQ=="
 }
 
Example - Result:

 <json>
    <name>
        <first>Joe</first>
        <last>Sixpack</last>
    </name>
    <gender>MALE</gender>
    <verified>false</verified>
    <flags>123</flags><flags>123</flags><flags>xyz</flags><flags>
        <composite>987</composite>
        <inner_flags>1</inner_flags><inner_flags>
            <innermost>abc</innermost>
            <innermost-object>
                <x>1</x>
            </innermost-object>
        </inner_flags><inner_flags>3</inner_flags>
    </flags>
    <userImage>Rm9vYmFyIQ==</userImage>
 </json>
 

Author:
Juergen_Kellerer, 2011-10-12
See Also:
PositioningDocumentBuilder

Field Summary
static String ROOT_ELEMENT_TAG_NAME
           
 
Fields inherited from class org.tinyjee.maven.dim.utils.AbstractPositioningDocumentBuilder
KEY_COLUMN_NUMBER, KEY_LINE_NUMBER
 
Constructor Summary
PositioningJsonDocumentBuilder()
           
 
Method Summary
 JsonFactory getJsonFactory()
           
 Document parse(URL systemId)
          Parses the given URL to a Document.
 Document parse(URL systemId, Reader reader)
          Parses the given URL to a Document.
 
Methods inherited from class org.tinyjee.maven.dim.utils.AbstractPositioningDocumentBuilder
getColumnNumber, getLineNumber
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROOT_ELEMENT_TAG_NAME

public static final String ROOT_ELEMENT_TAG_NAME
See Also:
Constant Field Values
Constructor Detail

PositioningJsonDocumentBuilder

public PositioningJsonDocumentBuilder()
Method Detail

getJsonFactory

public JsonFactory getJsonFactory()

parse

public Document parse(URL systemId)
               throws IOException,
                      ParserConfigurationException
Description copied from class: AbstractPositioningDocumentBuilder
Parses the given URL to a Document.

Specified by:
parse in class AbstractPositioningDocumentBuilder
Parameters:
systemId - the URL of the document to parse.
Returns:
the parsed document.
Throws:
IOException
ParserConfigurationException

parse

public Document parse(URL systemId,
                      Reader reader)
               throws IOException,
                      ParserConfigurationException
Description copied from class: AbstractPositioningDocumentBuilder
Parses the given URL to a Document.

Specified by:
parse in class AbstractPositioningDocumentBuilder
Parameters:
systemId - the URL of the document to parse.
reader - a reader containing the content to parse.
Returns:
the parsed document.
Throws:
IOException
ParserConfigurationException