Class XmlServiceSupport
- All Implemented Interfaces:
net.solarnetwork.service.Identifiable
- Since:
- 2.0
- Version:
- 1.0
- Author:
- matt
-
Field Summary
FieldsFields inherited from class net.solarnetwork.node.service.support.HttpClientSupport
ACCEPT_JSON, ACCEPT_TEXT, DEFAULT_CONNECTION_TIMEOUT, HTTP_METHOD_GET, HTTP_METHOD_POST, logFields inherited from interface net.solarnetwork.service.Identifiable
GROUP_UID_PROPERTY, UID_PROPERTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidextractBeanDataFromXml(Object obj, Node xml, Map<String, XPathExpression> xpathMap) Populate JavaBean properties via XPath extraction.extractTrackingId(InputSource xml, XPathExpression xp, String xpath) Extract a tracking ID from an XML string.Get the DOM 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.net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin>Get theEventAdminservice.Get a SAX InputSource from a URLConnection's InputStream.Get the configured namespace context.getSimpleDocument(Object o, String elementName) Turn an object into a simple XML Document.getSimpleSource(Object o, String elementName) Turn an object into a simple XML Document.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 the XSLT factory to use.getXmlAsString(Source source, boolean indent) Turn an XML Source into a String.getXPathExpressionMap(Map<String, String> xpathMap) Compile XPathExpression mappings from String XPath expressions.Get the XPath factory.voidinit()Initialize this class after properties are set.final voidpostEvent(org.osgi.service.event.Event event) Post anEvent.voidregisterCustomEditors(org.springframework.beans.BeanWrapper bean) Extending classes can override this method to register custom bean editors.voidsetDocBuilderFactory(DocumentBuilderFactory docBuilderFactory) Set a JAXPDocumentBuilderFactoryto use.voidsetEventAdmin(net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> eventAdmin) Set anEventAdminservice to use.voidsetNsContext(NamespaceContext nsContext) Set an optionalNamespaceContextto use for proper XML namespace handling in some contexts, such as XPath.voidsetTransformerFactory(TransformerFactory transformerFactory) Set a JAXPTransformerFactoryfor handling XSLT transformations with.voidsetXpathFactory(XPathFactory xpathFactory) Set a JAXPXPathFactoryfor handling XPath operations with.webFormGet(org.springframework.beans.BeanWrapper bean, String url, Map<String, ?> attributes) Send a bean as a web form GET and return an XML InputSource from the response content.voidwebFormGetForBean(org.springframework.beans.BeanWrapper bean, Object obj, String url, Map<String, ?> attributes, Map<String, XPathExpression> xpathMap) Send a bean as a web GET and parse the XML response as bean properties.webFormPost(org.springframework.beans.BeanWrapper bean, String url, Map<String, ?> attributes) Send a bean as a web form POST and return an XML InputSource from the response content.voidwebFormPostForBean(org.springframework.beans.BeanWrapper bean, Object obj, String url, Map<String, ?> attributes, Map<String, XPathExpression> xpathMap) Send a bean as a web form POST and parse the XML response as bean properties.webFormPostForTrackingId(org.springframework.beans.BeanWrapper bean, String url, XPathExpression trackingIdXPath, String xpath, Map<String, ?> attributes) Send a bean as a web form POST and parse the XML response for a bean.Methods inherited from class net.solarnetwork.node.service.support.HttpClientSupport
appendXWWWFormURLEncodedValue, getConnectionTimeout, getIdentityService, getInputStreamFromURLConnection, getSslService, getUnicodeReaderFromURLConnection, getURLConnection, getURLConnection, getURLConnection, postXWWWFormURLEncodedData, postXWWWFormURLEncodedDataForString, setConnectionTimeout, setIdentityService, setSslService, setupTokenAuthorization, xWWWFormURLEncodedMethods inherited from class net.solarnetwork.node.service.support.BaseIdentifiable
baseIdentifiableSettings, baseIdentifiableSettings, getExpressionServices, getPlaceholderService, populateExpressionDatumProperties, resolvePlaceholders, resolvePlaceholders, setExpressionServices, setPlaceholderServiceMethods inherited from class net.solarnetwork.service.support.BasicIdentifiable
basicIdentifiableMetadataSettings, basicIdentifiableSettings, basicIdentifiableSettings, basicIdentifiableSettings, doubleMetadataValue, getDisplayName, getGroupUid, getGroupUID, getMessageSource, getMetadata, getMetadataCount, getUid, getUID, integerMetadataValue, metadataValue, numberMetadataValue, saveMetadataValue, saveMetadataValue, setDisplayName, setGroupUid, setGroupUID, setMessageSource, setMetadata, setMetadataCount, setUid, setUID, smartMetadataValueMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.solarnetwork.service.Identifiable
getDisplayName, getGroupUid, getUid
-
Field Details
-
ATTR_NODE_ID
Special attribute key for a node ID value.- See Also:
-
-
Constructor Details
-
XmlServiceSupport
public XmlServiceSupport()
-
-
Method Details
-
init
public void init()Initialize this class after properties are set. -
getXPathExpressionMap
Compile XPathExpression mappings from String XPath expressions.- Parameters:
xpathMap- the XPath string expressions- Returns:
- the XPathExperssion mapping
-
getTemplates
Get an XSLT Templates object from an XSLT Resource.- Parameters:
resource- the XSLT Resource to load- Returns:
- the compiled Templates
-
getSimpleSource
Turn an object into a simple XML Document.The returned XML will be a single element with all JavaBean properties turned into attributed. For example:
<powerDatum id="123" pvVolts="123.123" ... />
- Parameters:
o- the object to turn into XMLelementName- the name of the XML element- Returns:
- the element, as XSLT Source
- See Also:
-
getSimpleDocument
Turn an object into a simple XML Document.The returned XML will be a single element with all JavaBean properties turned into attributes. For example:
<powerDatum id="123" pvVolts="123.123" ... />
- Parameters:
o- the object to turn into XMLelementName- the name of the XML element- Returns:
- the element, as an XML DOM Document
-
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 XML 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 XML 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
Populate JavaBean properties via XPath extraction.This method will call
registerCustomEditors(BeanWrapper)so custom editors can be registered if desired.- Parameters:
obj- the object to set properties on, or a BeanWrapperxml- the XMLxpathMap- the mapping of JavaBean property names to XPaths
-
registerCustomEditors
public void registerCustomEditors(org.springframework.beans.BeanWrapper bean) Extending classes can override this method to register custom bean editors.This method does nothing itself, and is designed to have custom implementation in extending classes.
- Parameters:
bean- the bean in question
-
getInputSourceFromURLConnection
Get a SAX InputSource from a URLConnection's InputStream.This method handles
gzipanddeflatedecoding automatically, if thecontentTypeis reported as such.- Parameters:
conn- the URLConnection- Returns:
- the InputSource
- Throws:
IOException- if any IO error occurs
-
webFormPost
public InputSource webFormPost(org.springframework.beans.BeanWrapper bean, String url, Map<String, ?> attributes) Send a bean as a web form POST and return an XML InputSource from the response content.- Parameters:
bean- the beanurl- the URL to POST toattributes- extra POST attributes and bean override values- Returns:
- an InputSource to the response content XML
-
webFormGet
public InputSource webFormGet(org.springframework.beans.BeanWrapper bean, String url, Map<String, ?> attributes) Send a bean as a web form GET and return an XML InputSource from the response content.- Parameters:
bean- the bean to extract GET parameters from, or null for no parametersurl- the URL to GET toattributes- extra GET attributes and bean override values- Returns:
- an InputSource to the response content XML
-
webFormPostForBean
public void webFormPostForBean(org.springframework.beans.BeanWrapper bean, Object obj, String url, Map<String, ?> attributes, Map<String, XPathExpression> xpathMap) Send a bean as a web form POST and parse the XML response as bean properties.- Parameters:
bean- the bean to POSTobj- the result bean to populate from the HTTP response XMLurl- the URL to POST toattributes- extra POST attributes and bean override valuesxpathMap- the mapping of JavaBean property names to XPaths
-
webFormGetForBean
public void webFormGetForBean(org.springframework.beans.BeanWrapper bean, Object obj, String url, Map<String, ?> attributes, Map<String, XPathExpression> xpathMap) Send a bean as a web GET and parse the XML response as bean properties.This method calls
webFormGet(BeanWrapper, String, Map)followed byextractBeanDataFromXml(Object, Node, Map).- Parameters:
bean- the bean whose properties to send as GET parameters, or null for no parametersobj- the result bean to populate from the HTTP response XMLurl- the URL to GETattributes- extra GET attributes and bean override valuesxpathMap- the mapping of JavaBean property names to XPaths- See Also:
-
extractTrackingId
Extract a tracking ID from an XML string.- Parameters:
xml- the XML to extract fromxp- the XPath to use that returns a numberxpath- the XPath as a string (for debugging)- Returns:
- the tracking ID, or null if not found
-
webFormPostForTrackingId
public Long webFormPostForTrackingId(org.springframework.beans.BeanWrapper bean, String url, XPathExpression trackingIdXPath, String xpath, Map<String, ?> attributes) Send a bean as a web form POST and parse the XML response for a bean.- Parameters:
bean- the beanurl- the URL to POST totrackingIdXPath- the XPath for extracting the tracking IDxpath- the trackingIdXPath as a String (for debugging)attributes- extra POST attributes and bean override values- Returns:
- the extracted tracking ID, or null if none found
-
postEvent
public final void postEvent(org.osgi.service.event.Event event) Post anEvent.This method only works if a
EventAdminhas been configured viasetEventAdmin(OptionalService). Otherwise the event is silently ignored.- Parameters:
event- the event to post- Since:
- 1.5
-
getNsContext
Get the configured namespace context.- Returns:
- the context
-
setNsContext
Set an optionalNamespaceContextto use for proper XML namespace handling in some contexts, such as XPath.- Parameters:
nsContext- the context to use
-
getDocBuilderFactory
Get the DOM factory.If an explicit one has not been configured via
setDocBuilderFactory(DocumentBuilderFactory)then a default one will be instantiated and cached when this method is called.- Returns:
- the DOM factory
-
setDocBuilderFactory
Set a JAXPDocumentBuilderFactoryto use.- Parameters:
docBuilderFactory- the DOM factory to use
-
getXpathFactory
Get the XPath factory.If not explicit factory has been configured via
setXpathFactory(XPathFactory)then a default one will be instantiated and cached when this method is called.- Returns:
- the factory
-
setXpathFactory
Set a JAXPXPathFactoryfor handling XPath operations with.- Parameters:
xpathFactory- the factory to use
-
getTransformerFactory
Get the XSLT factory to use.If an expliciy one has not been configured via
setTransformerFactory(TransformerFactory)then a default one will be created and cached when this method is called.- Returns:
- the XSLT factory
-
setTransformerFactory
Set a JAXPTransformerFactoryfor handling XSLT transformations with.- Parameters:
transformerFactory- the factory
-
getEventAdmin
public net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> getEventAdmin()Get theEventAdminservice.- Returns:
- the EventAdmin service
-
setEventAdmin
public void setEventAdmin(net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> eventAdmin) Set anEventAdminservice to use.- Parameters:
eventAdmin- the EventAdmin to use
-