Class XmlSupport
The configurable properties of this class are:
- docBuilderFactory
- A JAXP
DocumentBuilderFactoryto use. If not configured, theDocumentBuilderFactory.newInstance()method will be used to create a default one. - transformerFactory
- A JAXP
TransformerFactoryfor handling XSLT transformations with. If not configured, theTransformerFactory.newInstance()method will be used to create a default one. - xpathFactory
- A JAXP
XPathFactoryfor handling XPath operations with. If not configured theXPathFactory.newInstance()method will be used to create a default one. - nsContext
- An optional
NamespaceContextto use for proper XML namespace handling in some contexts, such as XPath.
- Version:
- 1.2
- Author:
- matt
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidextractBeanDataFromXml(org.springframework.beans.PropertyAccessor bean, Node xml, Map<String, XPathExpression> xpathMap) Populate JavaBean properties via XPath extraction.extractStringFromXml(Node xml, XPathExpression xpath) Extract a String value via an XPath expression.Get a document builder factory.getDocument(org.springframework.beans.BeanWrapper bean, String elementName) Turn an object into a simple XML Document, supporting custom property editors.getElement(org.springframework.beans.BeanWrapper bean, String elementName, Document dom) Turn an object into a simple XML Element, supporting custom property editors.getElement(org.springframework.beans.BeanWrapper bean, Document dom) Turn an object into a simple XML Element, supporting custom property editors.Get the namespace context.Turn an object into a simple XML Document, supporting custom property editors.Turn a Document into a Source.getTemplates(org.springframework.core.io.Resource resource) Get an XSLT Templates object from an XSLT Resource.Get a transformer factory.getXmlAsString(Source source, boolean indent) Turn an XML Source into a String.getXPathExpression(String xpath) Compile a single XPathExpression from a String XPath expression.getXPathExpressionMap(Map<String, String> xpathMap) Compile XPathExpression mappings from String XPath expressions.Get an XPath factory.voidsetDocBuilderFactory(DocumentBuilderFactory docBuilderFactory) Set the document builder factor.voidsetNsContext(NamespaceContext nsContext) Set the namespace context.voidsetTransformerFactory(TransformerFactory transformerFactory) Set the transformer factory.voidsetXpathFactory(XPathFactory xpathFactory) Set the XPath factory.
-
Field Details
-
log
protected final org.slf4j.Logger logA class-level logger.
-
-
Constructor Details
-
XmlSupport
public XmlSupport()
-
-
Method Details
-
getXPathExpressionMap
Compile XPathExpression mappings from String XPath expressions.- Parameters:
xpathMap- the XPath string expressions- Returns:
- the XPathExperssion mapping
-
getXPathExpression
Compile a single XPathExpression from a String XPath expression. ThegetNsContext()will be configured on the resulting XPathExpression, if available.- Parameters:
xpath- the XPath to compile- Returns:
- the compiled XPath
- Throws:
XPathExpressionException- if the XPath cannot be compiled
-
getTemplates
Get an XSLT Templates object from an XSLT Resource.- Parameters:
resource- the XSLT Resource to load- Returns:
- the compiled Templates
-
getDocument
Turn an object into a simple XML Document, supporting custom property editors.The returned XML will be a document with a single element with all JavaBean properties turned into attributes. For example:
<powerDatum id="123" pvVolts="123.123" ... />
PropertyEditorinstances can be registered with the suppliedBeanWrapperfor custom handling of properties, e.g. dates.- Parameters:
bean- the object to turn into XMLelementName- the name of the XML element- Returns:
- the element, as an XML DOM Document
-
getElement
Turn an object into a simple XML Element, supporting custom property editors.The returned XML will be a single element with all JavaBean properties turned into attributes and the element named after the bean object's class name. For example:
<PowerDatum id="123" pvVolts="123.123" ... />
PropertyEditorinstances can be registered with the suppliedBeanWrapperfor custom handling of properties, e.g. dates.- Parameters:
bean- the object to turn into XMLdom- the document- Returns:
- the element, as an XML DOM Document
-
getElement
public Element getElement(org.springframework.beans.BeanWrapper bean, String elementName, Document dom) Turn an object into a simple XML Element, supporting custom property editors.The returned XML will be a single element with all JavaBean properties turned into attributes. For example:
<powerDatum id="123" pvVolts="123.123" ... />
PropertyEditorinstances can be registered with the suppliedBeanWrapperfor custom handling of properties, e.g. dates.- Parameters:
bean- the object to turn into XMLelementName- the name of the XML elementdom- the document- Returns:
- the element, as an XML DOM Element
-
getSource
Turn an object into a simple XML Document, supporting custom property editors.The returned XML will be a single element with all JavaBean properties turned into attributed. For example:
<powerDatum id="123" pvVolts="123.123" ... />
- Parameters:
bean- the object to turn into XMLelementName- the name of the XML element- Returns:
- the element, as XSLT Source
- See Also:
-
getSource
Turn a Document into a Source.This method will log the XML document at the FINEST level.
- Parameters:
dom- the Document to turn into XSLT source- Returns:
- the document, as XSLT Source
-
getXmlAsString
Turn an XML Source into a String.- Parameters:
source- the XML Sourceindent- if true then indent the result- Returns:
- the XML, as a String
-
extractBeanDataFromXml
public void extractBeanDataFromXml(org.springframework.beans.PropertyAccessor bean, Node xml, Map<String, XPathExpression> xpathMap) Populate JavaBean properties via XPath extraction.- Parameters:
bean- the object to set properties onxml- the XMLxpathMap- the mapping of JavaBean property names to XPaths
-
extractStringFromXml
Extract a String value via an XPath expression.- Parameters:
xml- the XMLxpath- the XPath expression- Returns:
- the String
-
getNsContext
Get the namespace context.- Returns:
- the context
-
setNsContext
Set the namespace context.- Parameters:
nsContext- the context to set
-
getDocBuilderFactory
Get a document builder factory.- Returns:
- the factory
-
setDocBuilderFactory
Set the document builder factor.- Parameters:
docBuilderFactory- the factory to set
-
getXpathFactory
Get an XPath factory.- Returns:
- the factory
-
setXpathFactory
Set the XPath factory.- Parameters:
xpathFactory- the factory to set
-
getTransformerFactory
Get a transformer factory.- Returns:
- the factory
-
setTransformerFactory
Set the transformer factory.- Parameters:
transformerFactory- the factory to set
-