Class BaseXsltService
- All Implemented Interfaces:
Comparable<String>,net.solarnetwork.domain.Identity<String>,net.solarnetwork.service.LocalizedServiceInfoProvider,net.solarnetwork.settings.SettingSpecifierProvider,EntityResolver
public abstract class BaseXsltService
extends net.solarnetwork.settings.support.BaseSettingsSpecifierLocalizedServiceInfoProvider<String>
implements EntityResolver
Base service class for XSLT support.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternA regular expression matching an XML DOCTYPE declaration.protected final DocumentBuilderFactoryThe document builder factory.protected final com.fasterxml.jackson.databind.ObjectMapperA JSON mapper.static final StringThe setting key for the XSLT stylesheet.static final StringThe setting key for the XSLT stylesheet cache seconds.protected final SharedValueCache<String, Templates, String> A cache for templates.protected final DurationA templates cache duration.protected final TransformerFactoryThe transformer factory.static final StringThe XSLT input parameter for input JSON.Fields inherited from class net.solarnetwork.service.support.BaseLocalizedServiceInfoProvider
log -
Constructor Summary
ConstructorsConstructorDescriptionBaseXsltService(String serviceId, DocumentBuilderFactory documentBuilderFactory, TransformerFactory transformerFactory, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Duration templatesCacheTtl) Constructor.BaseXsltService(String serviceId, DocumentBuilderFactory documentBuilderFactory, TransformerFactory transformerFactory, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Duration templatesCacheTtl, SharedValueCache<String, Templates, String> templatesCache) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected DocumentBuilderGet a new document builder.protected static StringGet textual input.resolveEntity(String publicId, String systemId) protected TemplatesGet aTemplatesinstance.protected longtemplatesCacheTtlSeconds(net.solarnetwork.service.IdentifiableConfiguration config) Get the templates cache TTL seconds.Methods inherited from class net.solarnetwork.settings.support.BaseSettingsSpecifierLocalizedServiceInfoProvider
getLocalizedServiceInfo, getSettingUid, populateInfoMessages, resolveInfoMessagesMethods inherited from class net.solarnetwork.service.support.BaseLocalizedServiceInfoProvider
getMessageSource, setMessageSourceMethods inherited from class net.solarnetwork.domain.BasicIdentity
clone, compareTo, equals, getId, hashCodeMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.solarnetwork.domain.Identity
hasIdMethods inherited from interface net.solarnetwork.settings.SettingSpecifierProvider
getDisplayName, getMessageSource, getSettingSpecifiers, localizedInfo, templateSettingSpecifiers, unwrap
-
Field Details
-
SETTING_XSLT
The setting key for the XSLT stylesheet.- See Also:
-
SETTING_XSLT_CACHE_DURATION
The setting key for the XSLT stylesheet cache seconds.- See Also:
-
XSLT_PARAM_JSON
The XSLT input parameter for input JSON.- See Also:
-
transformerFactory
The transformer factory. -
documentBuilderFactory
The document builder factory. -
objectMapper
protected final com.fasterxml.jackson.databind.ObjectMapper objectMapperA JSON mapper. -
templatesCacheTtl
A templates cache duration. -
templatesCache
A cache for templates. -
DOCTYPE_PAT
A regular expression matching an XML DOCTYPE declaration.
-
-
Constructor Details
-
BaseXsltService
public BaseXsltService(String serviceId, DocumentBuilderFactory documentBuilderFactory, TransformerFactory transformerFactory, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Duration templatesCacheTtl) Constructor.- Parameters:
serviceId- the service ID to usedocumentBuilderFactory- the XML document builder factorytransformerFactory- the XSLT transformer factory to useobjectMapper- the object mappertemplatesCacheTtl- the TTL for the templates cache, or null or 0 for no caching- Throws:
IllegalArgumentException- if any argument is null
-
-
Method Details
-
resolveEntity
- Specified by:
resolveEntityin interfaceEntityResolver- Throws:
SAXExceptionIOException
-
documentBuilder
Get a new document builder.This instance will be configured as the
EntityResolver.- Returns:
- the new document builder
- Throws:
ParserConfigurationException- if an XML error occurs
-
templates
protected Templates templates(String xslt, net.solarnetwork.service.IdentifiableConfiguration config, Object cacheKey) throws IOException Get aTemplatesinstance.- Parameters:
xslt- the XSLT to parseconfig- optional settings to use, for exampleSETTING_XSLT_CACHE_DURATIONcacheKey- optional cache key to use (will be converted to a string), otherwise generate a key based on the XSLT itself- Returns:
- the templates, never null
- Throws:
IOException- if any error occurs parsing the XSLT
-
templatesCacheTtlSeconds
protected long templatesCacheTtlSeconds(net.solarnetwork.service.IdentifiableConfiguration config) Get the templates cache TTL seconds.- Parameters:
config- the optional settings- Returns:
- the TTL, in seconds
-
inputText
Get textual input.- Parameters:
input- the input, can be anInputStream,Reader, or anything else will haveObject.toString()invoked; UTF-8 will be assumed for streams- Returns:
- the text value, never null
- Throws:
IOException- if any IO error occurs
-