Package org.frankframework.align
Class Json2Xml
java.lang.Object
org.xml.sax.helpers.XMLFilterImpl
org.frankframework.align.XmlAligner
org.frankframework.align.Json2Xml
- All Implemented Interfaces:
ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
,XMLFilter
,XMLReader
XML Schema guided JSON to XML converter;
- Author:
- Gerrit van Brakel
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
Fields inherited from class org.frankframework.align.XmlAligner
FEATURE_NAMESPACE_PREFIXES, FEATURE_NAMESPACES, log, validatorHandler, XML_SCHEMA_INSTANCE_NAMESPACE, XML_SCHEMA_NIL_ATTRIBUTE
-
Constructor Summary
ConstructorDescriptionJson2Xml
(ValidatorHandler validatorHandler, List<org.apache.xerces.xs.XSModel> schemaInformation, boolean insertElementContainerElements, String rootElement, boolean strictSyntax) -
Method Summary
Modifier and TypeMethodDescriptionasSource
(jakarta.json.JsonValue container) Obtain the XmlAligner as aSource
that can be used as input of aTransformer
.static Json2Xml
create
(URL schemaURL, boolean compactJsonArrays, String rootElement, boolean strictSyntax, boolean deepSearch, String targetNamespace, Map<String, Object> overrideValues) Helper method for testsprotected jakarta.json.JsonValue
filterNodeChildren
(jakarta.json.JsonValue node, Set<String> allowedNames) Create a copy of the JSON node that contains only keys from the allowedNames set in the top level.getAllNodeChildNames
(jakarta.json.JsonValue node) getAttributes
(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, jakarta.json.JsonValue node) List<org.apache.xerces.xs.XSParticle>
getBestChildElementPath
(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, jakarta.json.JsonValue node, boolean silent) boolean
getBestMatchingElementPath
(org.apache.xerces.xs.XSElementDeclaration baseElementDeclaration, jakarta.json.JsonValue baseNode, org.apache.xerces.xs.XSParticle particle, List<org.apache.xerces.xs.XSParticle> path, List<String> failureReasons) final Iterable<jakarta.json.JsonValue>
getChildrenByName
(jakarta.json.JsonValue node, org.apache.xerces.xs.XSElementDeclaration childElementDeclaration) getNamespacePrefix
(String uri) Iterable<jakarta.json.JsonValue>
getNodeChildrenByName
(jakarta.json.JsonValue node, org.apache.xerces.xs.XSElementDeclaration childElementDeclaration) getNodeText
(jakarta.json.JsonValue node) protected String
getOverride
(jakarta.json.JsonValue node) protected jakarta.json.JsonValue
getSubstitutedChild
(String childName) final String
getText
(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, jakarta.json.JsonValue node) getUnprocessedChildElementNames
(jakarta.json.JsonValue node, Set<String> processedChildren) protected void
handleComplexTypedElement
(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, jakarta.json.JsonValue node) void
handleElement
(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, jakarta.json.JsonValue node) void
handleElementContents
(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, jakarta.json.JsonValue node) void
handleError
(String msg) void
void
handleRootNode
(jakarta.json.JsonValue container, String name, String nodeNamespace) Pushes node through validator.protected void
handleSimpleTypedElement
(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, jakarta.json.JsonValue node) boolean
boolean
protected boolean
isEmptyNode
(jakarta.json.JsonValue node) boolean
boolean
isNil
(jakarta.json.JsonValue node) boolean
void
parse
(InputSource input) Start the parse, obtain the container to parse from the InputSource when set byasSource(JsonValue)
.protected void
processChildElement
(jakarta.json.JsonValue node, String parentName, org.apache.xerces.xs.XSElementDeclaration childElementDeclaration, boolean mandatory, Set<String> processedChildren) protected void
sendString
(String string) void
setDeepSearch
(boolean deepSearch) void
setFailOnWildcards
(boolean failOnWildcards) void
setOverrideValues
(Map<String, Object> overrideValues) void
setReadAttributes
(boolean readAttributes) void
setRootElement
(String rootElement) void
setSubstitutionProvider
(SubstitutionProvider<?> substitutions) void
setTargetNamespace
(String targetNamespace) void
startParse
(jakarta.json.JsonValue node) static String
translate
(jakarta.json.JsonStructure jsonStructure, URL schemaURL, boolean compactJsonArrays, String rootElement, String targetNamespace) Helper method for teststranslate
(jakarta.json.JsonValue data) void
translate
(jakarta.json.JsonValue data, ContentHandler handler) Methods inherited from class org.frankframework.align.XmlAligner
collectChildElements, endElement, findElementDeclarationForName, findElementDeclarationsForName, findMultipleOccurringChildElements, getAttributeUses, getAttributeUses, getContext, getDocumentLocator, getElementType, getMultipleOccurringChildElements, getSchemaInformation, getSchemaInformation, getTypeDefinition, getTypeDefinition, getValidatorHandler, handleRecoverableError, isIgnoreUndeclaredElements, isMultipleOccurringChildElement, isMultipleOccurringChildInParentElement, isNil, isParentOfSingleMultipleOccurringChildElement, isPresentInSet, isTypeContainsWildcard, newLine, setDocumentLocator, setFeature, setIgnoreUndeclaredElements, setPsviProvider, setSchemaInformation, startDocument, startElement, typeContainsWildcard
Methods inherited from class org.xml.sax.helpers.XMLFilterImpl
characters, endDocument, endPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, ignorableWhitespace, notationDecl, parse, processingInstruction, resolveEntity, setContentHandler, setDTDHandler, setEntityResolver, setErrorHandler, setParent, setProperty, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
Field Details
-
MSG_FULL_INPUT_IN_STRICT_COMPACTING_MODE
- See Also:
-
MSG_EXPECTED_SINGLE_ELEMENT
- See Also:
-
XSI_PREFIX_MAPPING
- See Also:
-
MSG_EXPECTED_ELEMENT
- See Also:
-
MSG_CANNOT_NOT_FIND_ELEMENT_DECLARATION
- See Also:
-
-
Constructor Details
-
Json2Xml
public Json2Xml(ValidatorHandler validatorHandler, List<org.apache.xerces.xs.XSModel> schemaInformation, boolean insertElementContainerElements, String rootElement, boolean strictSyntax)
-
-
Method Details
-
startParse
- Throws:
SAXException
-
handleElementContents
public void handleElementContents(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, jakarta.json.JsonValue node) throws SAXException - Throws:
SAXException
-
getNodeText
-
isNil
public boolean isNil(jakarta.json.JsonValue node) -
getAttributes
public Map<String,String> getAttributes(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, jakarta.json.JsonValue node) throws SAXException - Throws:
SAXException
-
hasChild
- Throws:
SAXException
-
getAllNodeChildNames
- Throws:
SAXException
-
getNodeChildrenByName
public Iterable<jakarta.json.JsonValue> getNodeChildrenByName(jakarta.json.JsonValue node, org.apache.xerces.xs.XSElementDeclaration childElementDeclaration) throws SAXException - Throws:
SAXException
-
getSubstitutedChild
-
getOverride
-
processChildElement
protected void processChildElement(jakarta.json.JsonValue node, String parentName, org.apache.xerces.xs.XSElementDeclaration childElementDeclaration, boolean mandatory, Set<String> processedChildren) throws SAXException - Throws:
SAXException
-
isEmptyNode
protected boolean isEmptyNode(jakarta.json.JsonValue node) -
filterNodeChildren
protected jakarta.json.JsonValue filterNodeChildren(jakarta.json.JsonValue node, Set<String> allowedNames) Create a copy of the JSON node that contains only keys from the allowedNames set in the top level.- Parameters:
node
- Node to copyallowedNames
- Names of child-nodes to keep in the copy- Returns:
- Copy of the JSON node.
-
translate
public static String translate(jakarta.json.JsonStructure jsonStructure, URL schemaURL, boolean compactJsonArrays, String rootElement, String targetNamespace) throws SAXException Helper method for tests- Throws:
SAXException
-
create
public static Json2Xml create(URL schemaURL, boolean compactJsonArrays, String rootElement, boolean strictSyntax, boolean deepSearch, String targetNamespace, Map<String, Object> overrideValues) throws SAXExceptionHelper method for tests- Throws:
SAXException
-
getChildrenByName
public final Iterable<jakarta.json.JsonValue> getChildrenByName(jakarta.json.JsonValue node, org.apache.xerces.xs.XSElementDeclaration childElementDeclaration) throws SAXException - Throws:
SAXException
-
getText
public final String getText(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, jakarta.json.JsonValue node) -
getUnprocessedChildElementNames
protected Set<String> getUnprocessedChildElementNames(jakarta.json.JsonValue node, Set<String> processedChildren) throws SAXException - Throws:
SAXException
-
setSubstitutionProvider
-
setOverrideValues
-
asSource
Obtain the XmlAligner as aSource
that can be used as input of aTransformer
. -
parse
Start the parse, obtain the container to parse from the InputSource when set byasSource(JsonValue)
. Normally, the parse is started via {#startParse(C container)}, but this implementation allowsasSource(JsonValue)
to function.- Specified by:
parse
in interfaceXMLReader
- Overrides:
parse
in classXMLFilterImpl
- Throws:
SAXException
IOException
-
handleRootNode
public void handleRootNode(jakarta.json.JsonValue container, String name, String nodeNamespace) throws SAXException Pushes node through validator. Must push all nodes through validatorhandler, recursively, respecting the alignment request. Must set current=node before calling validatorHandler.startElement(), in order to get the right argument for the onStartElement / performAlignment callbacks.- Throws:
SAXException
-
handleElement
public void handleElement(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, jakarta.json.JsonValue node) throws SAXException - Throws:
SAXException
-
handleComplexTypedElement
protected void handleComplexTypedElement(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, jakarta.json.JsonValue node) throws SAXException - Throws:
SAXException
-
handleSimpleTypedElement
protected void handleSimpleTypedElement(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, jakarta.json.JsonValue node) throws SAXException - Throws:
SAXException
-
getBestChildElementPath
@Nonnull public List<org.apache.xerces.xs.XSParticle> getBestChildElementPath(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, jakarta.json.JsonValue node, boolean silent) throws SAXException - Throws:
SAXException
-
getBestMatchingElementPath
public boolean getBestMatchingElementPath(org.apache.xerces.xs.XSElementDeclaration baseElementDeclaration, jakarta.json.JsonValue baseNode, org.apache.xerces.xs.XSParticle particle, List<org.apache.xerces.xs.XSParticle> path, List<String> failureReasons) throws SAXException - Parameters:
baseElementDeclaration
- XSD Type Declaration of the base elementbaseNode
- Node from which to search for pathparticle
- XSD Particle for which to search for pathfailureReasons
- returns the reasons why no match was foundpath
- in this list the longest list of child elements, that matches the available, is maintained. Null if no matching.- Returns:
- true when a matching path is found. if false, failureReasons will contain reasons why.
- Throws:
SAXException
- If there was any exception
-
sendString
- Throws:
SAXException
-
handleError
- Throws:
SAXException
-
handleError
- Throws:
SAXException
-
getQName
- Throws:
SAXException
-
getNamespacePrefix
- Throws:
SAXException
-
translate
- Throws:
SAXException
-
translate
- Throws:
SAXException
-
isReadAttributes
public boolean isReadAttributes() -
setReadAttributes
public void setReadAttributes(boolean readAttributes) -
getRootElement
-
setRootElement
-
getTargetNamespace
-
setTargetNamespace
-
isDeepSearch
public boolean isDeepSearch() -
setDeepSearch
public void setDeepSearch(boolean deepSearch) -
isFailOnWildcards
public boolean isFailOnWildcards() -
setFailOnWildcards
public void setFailOnWildcards(boolean failOnWildcards)
-