org.tinyjee.maven.dim.utils
Class PositioningJsonDocumentBuilder
java.lang.Object
org.tinyjee.maven.dim.utils.AbstractPositioningDocumentBuilder
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:
- JSON-Objects translate to XML elements with child nodes. The root element is named "json".
- JSON-Fields translate to XML elements with text content or child nodes if the value is an JSON-Object.
- JSON-Arrays translate to multiple siblings of XML elements that are assembled as if they were a JSON-Field.
- The resulting XML is composed of element and text nodes. Attributes are not created.
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
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ROOT_ELEMENT_TAG_NAME
public static final String ROOT_ELEMENT_TAG_NAME
- See Also:
- Constant Field Values
PositioningJsonDocumentBuilder
public PositioningJsonDocumentBuilder()
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