Package net.sf.saxon.ma.json
Class JsonHandler
- java.lang.Object
-
- net.sf.saxon.ma.json.JsonHandler
-
- Direct Known Subclasses:
JsonHandlerMap
,JsonHandlerXML
public class JsonHandler extends java.lang.Object
Default handler class for accepting the result from parsing JSON strings
-
-
Field Summary
Fields Modifier and Type Field Description protected IntPredicateProxy
charChecker
boolean
escape
-
Constructor Summary
Constructors Constructor Description JsonHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
endArray()
Close the current arrayvoid
endMap()
Close the current object/mapXPathContext
getContext()
Sequence
getResult()
protected void
handleInvalidCharacters(java.lang.StringBuilder buffer)
Deal with invalid characters in the JSON stringprotected void
markAsEscaped(java.lang.String escaped, boolean isKey)
java.lang.String
reEscape(java.lang.String val)
Optionally apply escaping or unescaping to a value.void
setContext(XPathContext context)
void
setFallbackFunction(java.util.Map<java.lang.String,Sequence> options, XPathContext context)
boolean
setKey(java.lang.String unEscaped, java.lang.String reEscaped)
Set the key to be written for the next entry in an object/mapvoid
startArray()
Open a new arrayvoid
startMap()
Start a new object/mapvoid
writeBoolean(boolean value)
Write a boolean valuevoid
writeNull()
Write a null valuevoid
writeNumeric(java.lang.String asString, AtomicValue parsedValue)
Write a numeric valuevoid
writeString(java.lang.String val)
Write a string value
-
-
-
Field Detail
-
escape
public boolean escape
-
charChecker
protected IntPredicateProxy charChecker
-
-
Method Detail
-
setContext
public void setContext(XPathContext context)
-
getContext
public XPathContext getContext()
-
getResult
public Sequence getResult() throws XPathException
- Throws:
XPathException
-
setKey
public boolean setKey(java.lang.String unEscaped, java.lang.String reEscaped)
Set the key to be written for the next entry in an object/map- Parameters:
unEscaped
- the key for the entry (null implies no key) in unescaped form (backslashes, if present, do not signal an escape sequence)reEscaped
- the key for the entry (null implies no key) in reescaped form. In this form special characters are represented as backslash-escaped sequences if the escape option is yes; if escape=no, the reEscaped form is the same as the unEscaped form.- Returns:
- true if the key is already present in the map, false if it is not
-
startArray
public void startArray() throws XPathException
Open a new array- Throws:
XPathException
- if any error occurs
-
endArray
public void endArray() throws XPathException
Close the current array- Throws:
XPathException
- if any error occurs
-
startMap
public void startMap() throws XPathException
Start a new object/map- Throws:
XPathException
- if any error occurs
-
endMap
public void endMap() throws XPathException
Close the current object/map- Throws:
XPathException
- if any error occurs
-
writeNumeric
public void writeNumeric(java.lang.String asString, AtomicValue parsedValue) throws XPathException
Write a numeric value- Parameters:
asString
- the raw string representation of the valueparsedValue
- the parsed representation of the value, typically an xs:double, but under user control- Throws:
XPathException
- if any error occurs
-
writeString
public void writeString(java.lang.String val) throws XPathException
Write a string value- Parameters:
val
- The string to be written (which may or may not contain JSON escape sequences, according to the options that were set)- Throws:
XPathException
- if any error occurs
-
reEscape
public java.lang.String reEscape(java.lang.String val) throws XPathException
Optionally apply escaping or unescaping to a value.- Parameters:
val
- the string to be escaped or unEscaped. This is supplied as a String rather than a UnicodeString because there are special rules for handling unpaired surrogates, which cannot be represented in a UnicodeString- Returns:
- the escaped or unescaped string
- Throws:
XPathException
- if there are invalid characters or escape sequences
-
writeBoolean
public void writeBoolean(boolean value) throws XPathException
Write a boolean value- Parameters:
value
- the boolean value to be written- Throws:
XPathException
- if any error occurs
-
writeNull
public void writeNull() throws XPathException
Write a null value- Throws:
XPathException
- if any error occurs
-
handleInvalidCharacters
protected void handleInvalidCharacters(java.lang.StringBuilder buffer) throws XPathException
Deal with invalid characters in the JSON string- Parameters:
buffer
- the JSON string- Throws:
XPathException
- if any error occurs
-
markAsEscaped
protected void markAsEscaped(java.lang.String escaped, boolean isKey) throws XPathException
- Throws:
XPathException
-
setFallbackFunction
public void setFallbackFunction(java.util.Map<java.lang.String,Sequence> options, XPathContext context) throws XPathException
- Throws:
XPathException
-
-