Class DefaultResourceConfig
- java.lang.Object
-
- org.smooks.engine.resource.config.DefaultResourceConfig
-
- All Implemented Interfaces:
ResourceConfig
public class DefaultResourceConfig extends Object implements ResourceConfig
-
-
Field Summary
-
Fields inherited from interface org.smooks.api.resource.config.ResourceConfig
DOCUMENT_FRAGMENT_SELECTOR, SELECTOR_NONE, XML_DEF_PREFIX
-
-
Constructor Summary
Constructors Constructor Description DefaultResourceConfig()Public default constructor.DefaultResourceConfig(String selector, Properties namespaces)Public constructor.DefaultResourceConfig(String selector, Properties namespaces, String resource)Public constructor.DefaultResourceConfig(String selector, Properties namespaces, String targetProfile, String resource)Public constructor.DefaultResourceConfig(String selector, Properties namespaces, String selectorNamespaceURI, String targetProfile, String resource)Public constructor.DefaultResourceConfig(ResourceConfig resourceConfig)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddChangeListener(ResourceConfigChangeListener listener)Add the specified change listener to the list of change listeners.voidaddParameters(ResourceConfig resourceConfig)ResourceConfigcopy()Perform a shallow clone of this configuration.booleanequals(Object obj)byte[]getBytes()Get the resource as a byte array.StringgetExtendedConfigNS()Deprecated.<T> Parameter<T>getParameter(String name, Class<T> valueClass)Get the named ResourceConfigparameter.intgetParameterCount()Get the ResourceConfig parameter count.Map<String,Object>getParameters()Get the param map associated with this configuration.List<Parameter<?>>getParameters(String name)Get the named ResourceConfigparameterList.ObjectgetParameterValue(String name)<T> TgetParameterValue(String name, Class<T> valueClass)Get the named ResourceConfig parameter.<T> TgetParameterValue(String name, Class<T> valueClass, T defaultValue)Get the named ResourceConfig parameter.List<?>getParameterValues()Get allparametervalues set on this configuration.ProfileTargetingExpression[]getProfileTargetingExpressions()Get the profile targeting expressions for this ResourceConfig.StringgetResource()Get the resource for this ResourceConfig.StringgetResourceType()Get the resource "type" for this resource.SelectorPathgetSelectorPath()Get the selector steps.StringgetTargetProfile()Get the target profile string as set in the configuration.booleanisDefaultResource()Is this resource config a default applied resource.booleanisInline()Is this resource defined inline in the configuration, or is it referenced through a URI.booleanisJavaResource()Does this resource configuration refer to a Java Class resource.booleanisXmlDef()Is this selector defininition an XML based definition.voidremoveChangeListener(ResourceConfigChangeListener listener)Remove the specified change listener from the list of change listeners.voidremoveParameter(String name)Remove the named parameter.voidsetDefaultResource(boolean defaultResource)Set this resource config as a default applied resource.voidsetExtendedConfigNS(String extendedConfigNS)Deprecated.<T> Parameter<T>setParameter(String name, String type, T value)Set the named ResourceConfig parameter value (with type).<T> Parameter<T>setParameter(String name, T value)Set the named ResourceConfig parameter value (default type - String).<T> voidsetParameter(Parameter<T> parameter)voidsetResource(String resource)Set the configs "resource".voidsetResourceType(String resourceType)Explicitly set the resource type.voidsetSelector(String selector, Properties namespaces)Set the config selector.voidsetSelectorPath(SelectorPath selectorPath)Set the selector steps.voidsetTargetProfile(String targetProfile)Set the configs "target profile".protected Class<?>toJavaResource()Returns the resource as a Java Class instance.PropertiestoProperties()Create aPropertiesinstance from this suppliedDefaultResourceConfigStringtoString()StringtoXml()Generate an XML'ified description of this resource.
-
-
-
Constructor Detail
-
DefaultResourceConfig
public DefaultResourceConfig()
Public default constructor.- See Also:
#setSelector(String),setTargetProfile(String),setResource(String),setResourceType(String),setParameter(String, Object)
-
DefaultResourceConfig
public DefaultResourceConfig(String selector, Properties namespaces)
Public constructor.- Parameters:
selector- The selector definition.- See Also:
setTargetProfile(String),setResource(String),setResourceType(String),setParameter(String, Object)
-
DefaultResourceConfig
public DefaultResourceConfig(ResourceConfig resourceConfig)
-
DefaultResourceConfig
public DefaultResourceConfig(String selector, Properties namespaces, String resource)
Public constructor.- Parameters:
selector- The selector definition.resource- The resource.- See Also:
setTargetProfile(String),setResourceType(String),setParameter(String, Object)
-
DefaultResourceConfig
public DefaultResourceConfig(String selector, Properties namespaces, String targetProfile, String resource)
Public constructor.- Parameters:
selector- The selector definition.targetProfile- Target Profile(s). Comma separated list ofProfileTargetingExpressions.resource- The resource.- See Also:
setResourceType(String),setParameter(String, Object)
-
DefaultResourceConfig
public DefaultResourceConfig(String selector, Properties namespaces, @Deprecated String selectorNamespaceURI, String targetProfile, String resource)
Public constructor.- Parameters:
selector- The selector definition.selectorNamespaceURI- The selector namespace URI.targetProfile- Target Profile(s). Comma separated list ofProfileTargetingExpressions.resource- The resource.- See Also:
setResourceType(String),setParameter(String, Object)
-
-
Method Detail
-
copy
public ResourceConfig copy()
Perform a shallow clone of this configuration.- Specified by:
copyin interfaceResourceConfig- Returns:
- Configuration clone.
-
getExtendedConfigNS
@Deprecated public String getExtendedConfigNS()
Deprecated.Get the extended config namespace from which this configuration was created.- Specified by:
getExtendedConfigNSin interfaceResourceConfig- Returns:
- The extended config namespace from which this configuration was created.
-
setExtendedConfigNS
@Deprecated public void setExtendedConfigNS(String extendedConfigNS)
Deprecated.Set the extended config namespace from which this configuration was created.- Specified by:
setExtendedConfigNSin interfaceResourceConfig- Parameters:
extendedConfigNS- The extended config namespace from which this configuration was created.
-
addParameters
public void addParameters(ResourceConfig resourceConfig)
- Specified by:
addParametersin interfaceResourceConfig
-
setSelector
public void setSelector(String selector, Properties namespaces)
Set the config selector.- Specified by:
setSelectorin interfaceResourceConfig- Parameters:
selector- The selector definition.
-
setResource
public void setResource(String resource)
Set the configs "resource".- Specified by:
setResourcein interfaceResourceConfig- Parameters:
resource- The resource.
-
isInline
public boolean isInline()
Is this resource defined inline in the configuration, or is it referenced through a URI. Note that this method also returns false if the resource is undefined (null).- Specified by:
isInlinein interfaceResourceConfig- Returns:
- True if the resource is defined inline, otherwise false.
-
getTargetProfile
public String getTargetProfile()
Get the target profile string as set in the configuration.- Specified by:
getTargetProfilein interfaceResourceConfig- Returns:
- The target profile.
-
setTargetProfile
public void setTargetProfile(String targetProfile)
Set the configs "target profile".- Specified by:
setTargetProfilein interfaceResourceConfig- Parameters:
targetProfile- Target Profile(s). Comma separated list ofProfileTargetingExpressions.
-
setResourceType
public void setResourceType(String resourceType)
Explicitly set the resource type. E.g. "class", "xsl", "groovy" etc.- Specified by:
setResourceTypein interfaceResourceConfig- Parameters:
resourceType- The resource type.
-
setSelectorPath
public void setSelectorPath(SelectorPath selectorPath)
Set the selector steps.- Specified by:
setSelectorPathin interfaceResourceConfig- Parameters:
selectorPath- The selector steps.
-
getSelectorPath
public SelectorPath getSelectorPath()
Get the selector steps.- Specified by:
getSelectorPathin interfaceResourceConfig- Returns:
- The selector steps.
-
getProfileTargetingExpressions
public ProfileTargetingExpression[] getProfileTargetingExpressions()
Get the profile targeting expressions for this ResourceConfig.- Specified by:
getProfileTargetingExpressionsin interfaceResourceConfig- Returns:
- The profile targeting expressions.
-
getResource
public String getResource()
Get the resource for this ResourceConfig.- Specified by:
getResourcein interfaceResourceConfig- Returns:
- The cdrar path.
-
isDefaultResource
public boolean isDefaultResource()
Is this resource config a default applied resource. Some resources (e.g.DOMSerializerVisitororDefaultSAXElementSerializer) are applied by default when no other resources are targeted at an element.- Specified by:
isDefaultResourcein interfaceResourceConfig- Returns:
- True if this is a default applied resource, otherwise false.
-
setDefaultResource
public void setDefaultResource(boolean defaultResource)
Set this resource config as a default applied resource. Some resources (e.g.DOMSerializerVisitororDefaultSAXElementSerializer) are applied by default when no other resources are targeted at an element.- Specified by:
setDefaultResourcein interfaceResourceConfig- Parameters:
defaultResource- True if this is a default applied resource, otherwise false.
-
getResourceType
public String getResourceType()
Get the resource "type" for this resource. Determines the type through the following checks (in order):- Is it a Java resource. See
isJavaResource(). If it is, return "class". - Is the "restype" resource paramater specified. If it is, return it's value. Ala DTD v1.0
- Is the resource type explicitly set on this configuration. If it is, return it's value. Ala the "type" attribute on the resource element on DTD v2.0
- Return the resource path file extension e.g. "xsl".
- Specified by:
getResourceTypein interfaceResourceConfig- Returns:
- The resource type.
- Is it a Java resource. See
-
setParameter
public <T> Parameter<T> setParameter(String name, T value)
Set the named ResourceConfig parameter value (default type - String). Overwrites previous value of the same name.- Specified by:
setParameterin interfaceResourceConfig- Parameters:
name- Parameter name.value- Parameter value.- Returns:
- The parameter instance.
-
setParameter
public <T> Parameter<T> setParameter(String name, String type, T value)
Set the named ResourceConfig parameter value (with type). Overwrites previous value of the same name.- Specified by:
setParameterin interfaceResourceConfig- Parameters:
name- Parameter name.type- Parameter type.value- Parameter value.- Returns:
- The parameter instance.
-
setParameter
public <T> void setParameter(Parameter<T> parameter)
- Specified by:
setParameterin interfaceResourceConfig
-
getParameter
public <T> Parameter<T> getParameter(String name, Class<T> valueClass)
Get the named ResourceConfigparameter. If there is more than one of the named parameters defined, the first defined value is returned.- Specified by:
getParameterin interfaceResourceConfig- Parameters:
name- Name of parameter to get.- Returns:
- Parameter value, or null if not set.
-
getParameters
public Map<String,Object> getParameters()
Get the param map associated with this configuration.- Specified by:
getParametersin interfaceResourceConfig- Returns:
- The configuration parameters. The Map value is either a
Parameteror parameter list (List<Parameter>).
-
getParameterValues
public List<?> getParameterValues()
Get allparametervalues set on this configuration.- Specified by:
getParameterValuesin interfaceResourceConfig- Returns:
ParametervalueList, or null if not set.
-
getParameters
public List<Parameter<?>> getParameters(String name)
Get the named ResourceConfigparameterList.- Specified by:
getParametersin interfaceResourceConfig- Parameters:
name- Name of parameter to get.- Returns:
ParametervalueList, or null if not set.
-
getParameterValue
public Object getParameterValue(String name)
- Specified by:
getParameterValuein interfaceResourceConfig
-
getParameterValue
public <T> T getParameterValue(String name, Class<T> valueClass)
Get the named ResourceConfig parameter.- Specified by:
getParameterValuein interfaceResourceConfig- Parameters:
name- Name of parameter to get.- Returns:
- Parameter value, or null if not set.
-
getParameterValue
public <T> T getParameterValue(String name, Class<T> valueClass, T defaultValue)
Get the named ResourceConfig parameter.- Specified by:
getParameterValuein interfaceResourceConfig- Parameters:
name- Name of parameter to get.defaultValue- The default value to be returned if there are no parameters on the this ResourceConfig instance, or the parameter is not defined.- Returns:
- Parameter value, or defaultVal if not defined.
-
getParameterCount
public int getParameterCount()
Get the ResourceConfig parameter count.- Specified by:
getParameterCountin interfaceResourceConfig- Returns:
- Number of parameters defined on this ResourceConfig.
-
removeParameter
public void removeParameter(String name)
Remove the named parameter.- Specified by:
removeParameterin interfaceResourceConfig- Parameters:
name- The name of the parameter to be removed.
-
isXmlDef
public boolean isXmlDef()
Is this selector defininition an XML based definition. I.e. is the selector attribute value prefixed with "xmldef:".- Specified by:
isXmlDefin interfaceResourceConfig- Returns:
- True if this selector defininition is an XML based definition, otherwise false.
-
getBytes
public byte[] getBytes()
Get the resource as a byte array. If the resource data is not inlined in the configuration (in a "resdata" param), it will be resolved using theURIResourceLocatori.e. the path will be enterpretted as aURI. If the resource doesn't resolve to a stream producing URI, the resource string will be converted to bytes and returned.- Specified by:
getBytesin interfaceResourceConfig- Returns:
- The resource as a byte array, or null if resource path is null or the resource doesn't exist.
-
toJavaResource
protected Class<?> toJavaResource()
Returns the resource as a Java Class instance.- Returns:
- The Java Class instance refered to be this resource configuration, or null if the resource doesn't refer to a Java Class.
-
isJavaResource
public boolean isJavaResource()
Does this resource configuration refer to a Java Class resource.- Specified by:
isJavaResourcein interfaceResourceConfig- Returns:
- True if this resource configuration refers to a Java Class resource, otherwise false.
-
addChangeListener
public void addChangeListener(ResourceConfigChangeListener listener)
Add the specified change listener to the list of change listeners.- Specified by:
addChangeListenerin interfaceResourceConfig- Parameters:
listener- The listener instance.
-
removeChangeListener
public void removeChangeListener(ResourceConfigChangeListener listener)
Remove the specified change listener from the list of change listeners.- Specified by:
removeChangeListenerin interfaceResourceConfig- Parameters:
listener- The listener instance.
-
toXml
public String toXml()
Generate an XML'ified description of this resource.- Specified by:
toXmlin interfaceResourceConfig- Returns:
- XML'ified description of the resource.
-
toProperties
public Properties toProperties()
Create aPropertiesinstance from this suppliedDefaultResourceConfig- Specified by:
toPropertiesin interfaceResourceConfig- Returns:
- The resource parameters as a
Propertiesinstance.
-
-