Package com.adobe.aemds.guide.utils
Class XMLUtils
- java.lang.Object
-
- com.adobe.aemds.guide.utils.XMLUtils
-
public class XMLUtils extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_NS_PATTERN_PREFIX
static java.lang.String
IMPLICIT_AF_NS_PATTERN_PREFIX
static java.lang.String
xmlSkeleton
-
Constructor Summary
Constructors Constructor Description XMLUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addChildNodesOfParentUnderRoot(org.w3c.dom.Node parent, org.w3c.dom.Node root)
Utility to add child nodes of parent directly under root node.static java.lang.String
addReCaptchaDataInXML(java.lang.String formData, java.lang.String updatePath, java.lang.String score)
static java.lang.String
addSubmissionInfoMetaData(java.lang.String data, java.lang.String formContainerPath, java.lang.String submissionTime)
Adds the meta data to the submission info tag.static org.w3c.dom.Node
addToDocument(org.w3c.dom.Document dataDoc, javax.xml.xpath.XPath xPath, org.w3c.dom.Node currentNode, java.lang.String path, java.lang.Object value)
static org.w3c.dom.Node
addToDocument(org.w3c.dom.Document dataDoc, javax.xml.xpath.XPath xPath, org.w3c.dom.Node currentNode, java.lang.String path, java.lang.Object value, org.w3c.dom.Node refNode)
This API adds a node in the document before the refNodestatic void
appendNodeListToNode(org.w3c.dom.Node rootNode, org.w3c.dom.NodeList nodeList)
This API adds a nodelist to the root node.static boolean
checkIfStringHasIndexOperator(java.lang.String bindRef)
static void
convertRTEValXfaCmplntHTML(org.w3c.dom.Node node)
Returns the html compliant dor xml.static void
copyChildren(org.w3c.dom.Node source, org.w3c.dom.Node target)
static void
createAttachmentTag(org.w3c.dom.Document document, org.w3c.dom.Node fileComponentNode, JSONObject jsonObject)
Create XML tag for File attachment componentstatic org.w3c.dom.Node
createNode(org.w3c.dom.Document dataDoc, javax.xml.xpath.XPath xPath, org.w3c.dom.Node node, java.lang.String path)
static org.w3c.dom.Node
createNode(org.w3c.dom.Document dataDoc, javax.xml.xpath.XPath xPath, org.w3c.dom.Node node, java.lang.String path, org.w3c.dom.Node refNode)
static void
disableExternalEntities(javax.xml.parsers.DocumentBuilderFactory factory)
static java.lang.String
docToStr(org.w3c.dom.Document doc)
Deprecated.static java.lang.Object
evaluateXPath(java.lang.String xPathQuery, org.w3c.dom.Node contextNode, javax.xml.namespace.QName type)
static org.w3c.dom.Document
exportDocumentFromDataRef(java.lang.String dataRef, javax.xml.parsers.DocumentBuilder builder, FormDataXMLProviderRegistry formDataXMLProviderRegistry, ResourceResolverHelper resourceResolverHelper)
Deprecated.static java.util.List<java.lang.String>
extractAttachmentNames(org.w3c.dom.Document doc)
static java.lang.String
extractXsdRootElement(JSONObject guideJson)
static java.util.Map<java.lang.String,java.lang.String>
getBoundDataMapWithBindRefKeys(org.w3c.dom.Document document)
Returns Map of all bindRefs to their values only for Bounded Fieldsstatic org.w3c.dom.Element
getBoundDataXmlElement(org.w3c.dom.Document doc)
Returns the bound part(portion bound to schema XSD/XFA) of data XML as element objectstatic java.lang.String
getBoundDataXmlPart(org.w3c.dom.Document doc)
Returns the bound part(portion bound to schema XSD/XFA) of data XMLstatic java.lang.String
getChildBoundRootXpath(java.lang.String fsRoot, java.lang.String bindRefPrefix, java.lang.String childRoot)
static org.w3c.dom.Node
getChildNodeByName(org.w3c.dom.Node node, java.lang.String childName)
Utility API to get a child node by namestatic org.w3c.dom.Document
getChildXmlDoc(org.w3c.dom.Element fsUnBoundDataRoot, org.w3c.dom.Element fsBoundDataRoot, java.lang.String childBoundRootXpath, boolean keepBoundPart)
static java.util.Map<java.lang.String,java.lang.String>
getDataMap(org.w3c.dom.Document document)
Returns Map of all the fields and their valuesstatic java.io.InputStream
getDataRefInputStream(java.lang.String dataRef, FormDataXMLProviderRegistry formDataXMLProviderRegistry, ResourceResolverHelper resourceResolverHelper)
Deprecated.static java.lang.String
getDorDataXmlPart(org.w3c.dom.Document dorDoc, org.w3c.dom.Document doc, java.lang.String excludeFromDorIfHidden, boolean bSetXfaNameSpace, JSONObject guideJson)
Returns the DOR part of data XML Dor Part is: a) ExcludeFromDorIfHidden Tag b) Unbound part of guide data c) bound part of guide data d) afSubmissionInfo of guide datastatic org.w3c.dom.Document
getEmptySubmitDoc()
static JSONObject
getMapOfUnboundData(org.w3c.dom.Document doc)
Returns JSON representation of unbound part of Data XMLstatic java.util.List<org.w3c.dom.Node>
getNamedChildNodes(org.w3c.dom.Node parent, java.lang.String childNode)
Returns list of child and attribute nodes which have passed namestatic org.w3c.dom.NodeList
getNodeListFromXmlString(java.lang.String xmlStr)
This API converts xmlstring to node.static java.lang.String
getPrefillXmlWithoutBoundPart(org.w3c.dom.Document doc)
static java.lang.String
getRelativeXpath(java.lang.String bindRef, java.lang.String root)
static org.w3c.dom.Element
getSignersDataXmlElement(org.w3c.dom.Document doc)
Returns the signers part of data XML as element objectstatic java.util.Map<java.lang.String,java.lang.Object>
getSignersMapForFormSourceFromDataXML(java.lang.String data)
static org.w3c.dom.Element
getSubmissionInfoDataXmlElement(org.w3c.dom.Document doc, java.lang.String submitInfoPart)
Returns the Submission info part of data XML as element object The returned element must be cloned to do further modificationstatic java.lang.String
getSubmissionInfoDataXmlPart(org.w3c.dom.Document doc, java.lang.String submitInfoPart)
Returns the submission info part of data XMLstatic org.w3c.dom.Element
getUnboundDataXmlElement(org.w3c.dom.Document doc)
Returns the unbound part of data XML as element objectstatic java.lang.String
getUnboundDataXmlPart(org.w3c.dom.Document doc)
Returns the unbound part of data XMLstatic java.lang.String
getXMLFromDom(org.w3c.dom.Document doc, java.lang.String tagName)
Returns the XML String of the Node whose tag name is provided from a Document objectstatic java.lang.String
getXMLfromXsdDom(org.w3c.dom.Element doc)
static java.lang.String
getXMLfromXsdDom(org.w3c.dom.Element doc, java.lang.Boolean omitXmlDeclaration)
static java.lang.String
getXSDRootBindRef(JSONObject jsonObject, java.lang.String xsdRoot)
Returns the normalized bindref for XSD binded field.static boolean
isValidXsdRoot(java.lang.String root)
static boolean
isWrappedXml(org.w3c.dom.Document doc)
static boolean
isWrappedXmlStr(java.lang.String docStr)
static boolean
isXsd(JSONObject obj)
static java.lang.String
nodeToStr(org.w3c.dom.Node node, java.lang.Boolean omitXmlDeclaration)
convert node object to string.static void
removeFromDocument(javax.xml.xpath.XPath xPath, org.w3c.dom.Node currentNode, java.lang.String path)
static java.lang.String
replaceAFNSWithDefaultNS(java.lang.String xmlString)
Added with CQ-4304064, Replaces the implcit prefix 'defaultAFNS' to empty prefix for default namespaces.static java.lang.String
replaceDefaultNSWithAFNS(java.lang.String xmlString)
Added with CQ-4304064, Replaces the empty prefix of default namespace with an implcit prefix 'defaultAFNS'.static void
setXfaNameSpace(org.w3c.dom.Element data)
Set XFA namespace to the element object passedstatic void
setXmlSchemaInstanceNamespace(org.w3c.dom.Element data)
Set XML Schema Instance namespace to the element object passedstatic org.w3c.dom.Document
strToDoc(java.lang.String xmlStr)
static java.lang.String
syncExcludeFromDorData(java.lang.String dataXML, java.lang.String ServerSideExcludeFromDorData)
Aligns the excludeFromDor Data present in the data.xml with the one computed in server-side-validation (source of truth)
-
-
-
Field Detail
-
DEFAULT_NS_PATTERN_PREFIX
public static final java.lang.String DEFAULT_NS_PATTERN_PREFIX
- See Also:
- Constant Field Values
-
IMPLICIT_AF_NS_PATTERN_PREFIX
public static final java.lang.String IMPLICIT_AF_NS_PATTERN_PREFIX
- See Also:
- Constant Field Values
-
xmlSkeleton
public static final java.lang.String xmlSkeleton
- See Also:
- Constant Field Values
-
-
Method Detail
-
checkIfStringHasIndexOperator
public static boolean checkIfStringHasIndexOperator(java.lang.String bindRef)
-
extractXsdRootElement
public static java.lang.String extractXsdRootElement(JSONObject guideJson)
-
getXSDRootBindRef
public static java.lang.String getXSDRootBindRef(JSONObject jsonObject, java.lang.String xsdRoot) throws JSONException
Returns the normalized bindref for XSD binded field. It would return the bindRef relative to root node of data document. For example if bindRef is /a/b/c/d then it would return b/c/d as /a would always bind to document root.- Parameters:
jsonObject
-- Throws:
JSONException
-
getRelativeXpath
public static java.lang.String getRelativeXpath(java.lang.String bindRef, java.lang.String root)
-
getXMLfromXsdDom
public static java.lang.String getXMLfromXsdDom(org.w3c.dom.Element doc)
- Parameters:
doc
-
-
getXMLfromXsdDom
public static java.lang.String getXMLfromXsdDom(org.w3c.dom.Element doc, java.lang.Boolean omitXmlDeclaration)
- Parameters:
doc
-omitXmlDeclaration
-
-
addChildNodesOfParentUnderRoot
public static void addChildNodesOfParentUnderRoot(org.w3c.dom.Node parent, org.w3c.dom.Node root)
Utility to add child nodes of parent directly under root node. Parent and root nodes belong to different documents.- Parameters:
parent
- node whose child nodes are to added under root noderoot
- node under which child nodes have to be directly inserted
-
getDorDataXmlPart
public static java.lang.String getDorDataXmlPart(org.w3c.dom.Document dorDoc, org.w3c.dom.Document doc, java.lang.String excludeFromDorIfHidden, boolean bSetXfaNameSpace, JSONObject guideJson)
Returns the DOR part of data XML Dor Part is: a) ExcludeFromDorIfHidden Tag b) Unbound part of guide data c) bound part of guide data d) afSubmissionInfo of guide data- Parameters:
dorDoc
- document representing dordoc
- document representing the data xmlexcludeFromDorIfHidden
-bSetXfaNameSpace
- this is true if xdpRef is not presentguideJson
-- Returns:
- string representing the data xml
- See Also:
Document
-
convertRTEValXfaCmplntHTML
public static void convertRTEValXfaCmplntHTML(org.w3c.dom.Node node)
Returns the html compliant dor xml.- Parameters:
node
- Node node representing the dor xml.- See Also:
Node
-
getSubmissionInfoDataXmlElement
public static org.w3c.dom.Element getSubmissionInfoDataXmlElement(org.w3c.dom.Document doc, java.lang.String submitInfoPart)
Returns the Submission info part of data XML as element object The returned element must be cloned to do further modification- Parameters:
doc
- document representing the data xmlsubmitInfoPart
- child tag of submission info if any, null would return the submission info tag of data xml- Returns:
- string representing the submission info element object
- See Also:
Document
-
getSignersMapForFormSourceFromDataXML
public static java.util.Map<java.lang.String,java.lang.Object> getSignersMapForFormSourceFromDataXML(java.lang.String data)
-
addSubmissionInfoMetaData
public static java.lang.String addSubmissionInfoMetaData(java.lang.String data, java.lang.String formContainerPath, java.lang.String submissionTime)
Adds the meta data to the submission info tag. In case of prefill xml, the tag can already be there in the XML. So, the node for meta data is either updated with the new value if it is already there or is created when its not there.- Parameters:
data
- xml jcr Data
-
getSubmissionInfoDataXmlPart
public static java.lang.String getSubmissionInfoDataXmlPart(org.w3c.dom.Document doc, java.lang.String submitInfoPart)
Returns the submission info part of data XML- Parameters:
doc
- document representing the data xmlsubmitInfoPart
- child tag of submission info if any, null would return the submission info tag of data xml- Returns:
- string representing the submission info of data xml
- See Also:
Document
-
setXfaNameSpace
public static void setXfaNameSpace(org.w3c.dom.Element data)
Set XFA namespace to the element object passed- Parameters:
data
- element object
-
setXmlSchemaInstanceNamespace
public static void setXmlSchemaInstanceNamespace(org.w3c.dom.Element data)
Set XML Schema Instance namespace to the element object passed- Parameters:
data
- element object
-
getBoundDataXmlPart
public static java.lang.String getBoundDataXmlPart(org.w3c.dom.Document doc)
Returns the bound part(portion bound to schema XSD/XFA) of data XML- Parameters:
doc
- document representing the data xml- Returns:
- string representing the bound portion of data xml
- See Also:
Document
-
getBoundDataXmlElement
public static org.w3c.dom.Element getBoundDataXmlElement(org.w3c.dom.Document doc)
Returns the bound part(portion bound to schema XSD/XFA) of data XML as element object- Parameters:
doc
- document representing the data xml- Returns:
- Element object representing the bound portion of data xml
- See Also:
Document
-
getUnboundDataXmlPart
public static java.lang.String getUnboundDataXmlPart(org.w3c.dom.Document doc)
Returns the unbound part of data XML- Parameters:
doc
- document representing the data xml- Returns:
- string representing the unbound portion of data xml
- See Also:
Document
-
getUnboundDataXmlElement
public static org.w3c.dom.Element getUnboundDataXmlElement(org.w3c.dom.Document doc)
Returns the unbound part of data XML as element object- Parameters:
doc
- document representing the data xml- Returns:
- Element object representing the unbound portion of data xml
- See Also:
Document
-
getSignersDataXmlElement
public static org.w3c.dom.Element getSignersDataXmlElement(org.w3c.dom.Document doc)
Returns the signers part of data XML as element object- Parameters:
doc
- document representing the data xml- Returns:
- Element object representing the signers portion of data xml
- See Also:
Document
-
getChildNodeByName
public static org.w3c.dom.Node getChildNodeByName(org.w3c.dom.Node node, java.lang.String childName)
Utility API to get a child node by name- Parameters:
node
- node under which the given childName is to be foundchildName
- name of the child to be found- Returns:
- node representing the given child
-
getDataMap
public static java.util.Map<java.lang.String,java.lang.String> getDataMap(org.w3c.dom.Document document) throws JSONException
Returns Map of all the fields and their values- Parameters:
document
- representing the data xml- Returns:
- Map of all the fields and their values
- Throws:
JSONException
-
getBoundDataMapWithBindRefKeys
public static java.util.Map<java.lang.String,java.lang.String> getBoundDataMapWithBindRefKeys(org.w3c.dom.Document document)
Returns Map of all bindRefs to their values only for Bounded Fields- Parameters:
document
- representing the data xml- Returns:
- Map of all the fields and their values
-
getMapOfUnboundData
public static JSONObject getMapOfUnboundData(org.w3c.dom.Document doc)
Returns JSON representation of unbound part of Data XML- Parameters:
doc
- document representing the data xml- Returns:
- jsonobject of unbound part of data xml
- See Also:
Document
-
getPrefillXmlWithoutBoundPart
public static java.lang.String getPrefillXmlWithoutBoundPart(org.w3c.dom.Document doc)
-
getXMLFromDom
public static java.lang.String getXMLFromDom(org.w3c.dom.Document doc, java.lang.String tagName)
Returns the XML String of the Node whose tag name is provided from a Document object- Parameters:
doc
- Document Object where to search for the tag NametagName
- tag name of the XML Element whose String representation has to be returned
-
getDataRefInputStream
@Deprecated public static java.io.InputStream getDataRefInputStream(java.lang.String dataRef, FormDataXMLProviderRegistry formDataXMLProviderRegistry, ResourceResolverHelper resourceResolverHelper)
Deprecated.Get the Input Stream of the URI provided in dataRef.- Parameters:
dataRef
-formDataXMLProviderRegistry
-resourceResolverHelper
-- Throws:
java.lang.Exception
-
exportDocumentFromDataRef
@Deprecated public static org.w3c.dom.Document exportDocumentFromDataRef(java.lang.String dataRef, javax.xml.parsers.DocumentBuilder builder, FormDataXMLProviderRegistry formDataXMLProviderRegistry, ResourceResolverHelper resourceResolverHelper) throws java.lang.Exception
Deprecated.- Parameters:
dataRef
- , document builder and reference to the servicebuilder
-formDataXMLProviderRegistry
-resourceResolverHelper
-- Returns:
- document obtained from the service
- Throws:
java.lang.Exception
-
createNode
public static org.w3c.dom.Node createNode(org.w3c.dom.Document dataDoc, javax.xml.xpath.XPath xPath, org.w3c.dom.Node node, java.lang.String path) throws javax.xml.xpath.XPathExpressionException
- Parameters:
dataDoc
-xPath
-node
-path
-- Throws:
javax.xml.xpath.XPathExpressionException
-
createNode
public static org.w3c.dom.Node createNode(org.w3c.dom.Document dataDoc, javax.xml.xpath.XPath xPath, org.w3c.dom.Node node, java.lang.String path, org.w3c.dom.Node refNode) throws javax.xml.xpath.XPathExpressionException
- Parameters:
dataDoc
-xPath
-node
-path
-refNode
-- Throws:
javax.xml.xpath.XPathExpressionException
-
removeFromDocument
public static void removeFromDocument(javax.xml.xpath.XPath xPath, org.w3c.dom.Node currentNode, java.lang.String path)
- Parameters:
xPath
-currentNode
-path
-
-
createAttachmentTag
public static void createAttachmentTag(org.w3c.dom.Document document, org.w3c.dom.Node fileComponentNode, JSONObject jsonObject)
Create XML tag for File attachment component- Parameters:
document
-fileComponentNode
-jsonObject
-
-
addToDocument
public static org.w3c.dom.Node addToDocument(org.w3c.dom.Document dataDoc, javax.xml.xpath.XPath xPath, org.w3c.dom.Node currentNode, java.lang.String path, java.lang.Object value)
- Parameters:
dataDoc
-xPath
-currentNode
-path
-value
-- Returns:
- Node created at the specified path
-
addToDocument
public static org.w3c.dom.Node addToDocument(org.w3c.dom.Document dataDoc, javax.xml.xpath.XPath xPath, org.w3c.dom.Node currentNode, java.lang.String path, java.lang.Object value, org.w3c.dom.Node refNode)
This API adds a node in the document before the refNode- Parameters:
dataDoc
-xPath
-currentNode
-path
-value
-refNode
- reference node with respect to which the new node is to be inserted- Returns:
- Node created at the specified path
-
isXsd
public static boolean isXsd(JSONObject obj)
-
isWrappedXml
public static boolean isWrappedXml(org.w3c.dom.Document doc)
-
isWrappedXmlStr
public static boolean isWrappedXmlStr(java.lang.String docStr)
-
isValidXsdRoot
public static boolean isValidXsdRoot(java.lang.String root)
-
getEmptySubmitDoc
public static org.w3c.dom.Document getEmptySubmitDoc()
-
getChildBoundRootXpath
public static java.lang.String getChildBoundRootXpath(java.lang.String fsRoot, java.lang.String bindRefPrefix, java.lang.String childRoot)
-
getNamedChildNodes
public static java.util.List<org.w3c.dom.Node> getNamedChildNodes(org.w3c.dom.Node parent, java.lang.String childNode)
Returns list of child and attribute nodes which have passed name- Parameters:
parent
- node whose children and attributes are searchedchildNode
- name of child to be returned- Returns:
- list of child nodes having childNode as name
-
evaluateXPath
public static java.lang.Object evaluateXPath(java.lang.String xPathQuery, org.w3c.dom.Node contextNode, javax.xml.namespace.QName type)
-
copyChildren
public static void copyChildren(org.w3c.dom.Node source, org.w3c.dom.Node target)
-
getChildXmlDoc
public static org.w3c.dom.Document getChildXmlDoc(org.w3c.dom.Element fsUnBoundDataRoot, org.w3c.dom.Element fsBoundDataRoot, java.lang.String childBoundRootXpath, boolean keepBoundPart)
-
nodeToStr
public static java.lang.String nodeToStr(org.w3c.dom.Node node, java.lang.Boolean omitXmlDeclaration)
convert node object to string.- Parameters:
node
- Node to be converted to string.omitXmlDeclaration
- Boolean to check if xml declaration tag should be there in converted string or not.- Throws:
java.lang.Exception
-
docToStr
@Deprecated public static java.lang.String docToStr(org.w3c.dom.Document doc)
Deprecated.convert document object to string. This api is deprecated and new api to be used isnodeToStr
- Parameters:
doc
- Document to be converted to string.- Throws:
java.lang.Exception
-
getNodeListFromXmlString
public static org.w3c.dom.NodeList getNodeListFromXmlString(java.lang.String xmlStr)
This API converts xmlstring to node.- Parameters:
xmlStr
- String xml String which needs to be converted to nodeList.- Returns:
- NodeList NodeList created converting xml string.
-
appendNodeListToNode
public static void appendNodeListToNode(org.w3c.dom.Node rootNode, org.w3c.dom.NodeList nodeList)
This API adds a nodelist to the root node.- Parameters:
rootNode
- Node root node to which the nodelist needs to be appended.nodeList
- NodeList created converting xml string.
-
strToDoc
public static org.w3c.dom.Document strToDoc(java.lang.String xmlStr)
-
extractAttachmentNames
public static java.util.List<java.lang.String> extractAttachmentNames(org.w3c.dom.Document doc)
-
disableExternalEntities
public static void disableExternalEntities(javax.xml.parsers.DocumentBuilderFactory factory)
-
replaceDefaultNSWithAFNS
public static java.lang.String replaceDefaultNSWithAFNS(java.lang.String xmlString)
Added with CQ-4304064, Replaces the empty prefix of default namespace with an implcit prefix 'defaultAFNS'.- Parameters:
xmlString
- given input xml which might contain default namespace (namespace with empty prefix).- Returns:
- updated xml after above mentioned replacement.
-
replaceAFNSWithDefaultNS
public static java.lang.String replaceAFNSWithDefaultNS(java.lang.String xmlString)
Added with CQ-4304064, Replaces the implcit prefix 'defaultAFNS' to empty prefix for default namespaces.- Parameters:
xmlString
- given input xml which might contain implcit prefix 'defaultAFNS'- Returns:
- updated xml after above mentioned replacement.
-
syncExcludeFromDorData
public static java.lang.String syncExcludeFromDorData(java.lang.String dataXML, java.lang.String ServerSideExcludeFromDorData)
Aligns the excludeFromDor Data present in the data.xml with the one computed in server-side-validation (source of truth)- Parameters:
dataXML
- string representing data xmlServerSideExcludeFromDorData
- string computed as part of server side validation- Returns:
- updated data xml string.
-
addReCaptchaDataInXML
public static java.lang.String addReCaptchaDataInXML(java.lang.String formData, java.lang.String updatePath, java.lang.String score)
-
-