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 void
addChangeListener(ResourceConfigChangeListener listener)
Add the specified change listener to the list of change listeners.void
addParameters(ResourceConfig resourceConfig)
ResourceConfig
copy()
Perform a shallow clone of this configuration.boolean
equals(Object obj)
byte[]
getBytes()
Get the resource as a byte array.String
getExtendedConfigNS()
Deprecated.<T> Parameter<T>
getParameter(String name, Class<T> valueClass)
Get the named ResourceConfigparameter
.int
getParameterCount()
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 ResourceConfigparameter
List.Object
getParameterValue(String name)
<T> T
getParameterValue(String name, Class<T> valueClass)
Get the named ResourceConfig parameter.<T> T
getParameterValue(String name, Class<T> valueClass, T defaultValue)
Get the named ResourceConfig parameter.List<?>
getParameterValues()
Get allparameter
values set on this configuration.ProfileTargetingExpression[]
getProfileTargetingExpressions()
Get the profile targeting expressions for this ResourceConfig.String
getResource()
Get the resource for this ResourceConfig.String
getResourceType()
Get the resource "type" for this resource.SelectorPath
getSelectorPath()
Get the selector steps.String
getTargetProfile()
Get the target profile string as set in the configuration.boolean
isDefaultResource()
Is this resource config a default applied resource.boolean
isInline()
Is this resource defined inline in the configuration, or is it referenced through a URI.boolean
isJavaResource()
Does this resource configuration refer to a Java Class resource.boolean
isXmlDef()
Is this selector defininition an XML based definition.void
removeChangeListener(ResourceConfigChangeListener listener)
Remove the specified change listener from the list of change listeners.void
removeParameter(String name)
Remove the named parameter.void
setDefaultResource(boolean defaultResource)
Set this resource config as a default applied resource.void
setExtendedConfigNS(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> void
setParameter(Parameter<T> parameter)
void
setResource(String resource)
Set the configs "resource".void
setResourceType(String resourceType)
Explicitly set the resource type.void
setSelector(String selector, Properties namespaces)
Set the config selector.void
setSelectorPath(SelectorPath selectorPath)
Set the selector steps.void
setTargetProfile(String targetProfile)
Set the configs "target profile".protected Class<?>
toJavaResource()
Returns the resource as a Java Class instance.Properties
toProperties()
Create aProperties
instance from this suppliedDefaultResourceConfig
String
toString()
String
toXml()
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:
copy
in interfaceResourceConfig
- Returns:
- Configuration clone.
-
getExtendedConfigNS
@Deprecated public String getExtendedConfigNS()
Deprecated.Get the extended config namespace from which this configuration was created.- Specified by:
getExtendedConfigNS
in 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:
setExtendedConfigNS
in interfaceResourceConfig
- Parameters:
extendedConfigNS
- The extended config namespace from which this configuration was created.
-
addParameters
public void addParameters(ResourceConfig resourceConfig)
- Specified by:
addParameters
in interfaceResourceConfig
-
setSelector
public void setSelector(String selector, Properties namespaces)
Set the config selector.- Specified by:
setSelector
in interfaceResourceConfig
- Parameters:
selector
- The selector definition.
-
setResource
public void setResource(String resource)
Set the configs "resource".- Specified by:
setResource
in 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:
isInline
in 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:
getTargetProfile
in interfaceResourceConfig
- Returns:
- The target profile.
-
setTargetProfile
public void setTargetProfile(String targetProfile)
Set the configs "target profile".- Specified by:
setTargetProfile
in 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:
setResourceType
in interfaceResourceConfig
- Parameters:
resourceType
- The resource type.
-
setSelectorPath
public void setSelectorPath(SelectorPath selectorPath)
Set the selector steps.- Specified by:
setSelectorPath
in interfaceResourceConfig
- Parameters:
selectorPath
- The selector steps.
-
getSelectorPath
public SelectorPath getSelectorPath()
Get the selector steps.- Specified by:
getSelectorPath
in interfaceResourceConfig
- Returns:
- The selector steps.
-
getProfileTargetingExpressions
public ProfileTargetingExpression[] getProfileTargetingExpressions()
Get the profile targeting expressions for this ResourceConfig.- Specified by:
getProfileTargetingExpressions
in interfaceResourceConfig
- Returns:
- The profile targeting expressions.
-
getResource
public String getResource()
Get the resource for this ResourceConfig.- Specified by:
getResource
in interfaceResourceConfig
- Returns:
- The cdrar path.
-
isDefaultResource
public boolean isDefaultResource()
Is this resource config a default applied resource. Some resources (e.g.DOMSerializerVisitor
orDefaultSAXElementSerializer
) are applied by default when no other resources are targeted at an element.- Specified by:
isDefaultResource
in 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.DOMSerializerVisitor
orDefaultSAXElementSerializer
) are applied by default when no other resources are targeted at an element.- Specified by:
setDefaultResource
in 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:
getResourceType
in 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:
setParameter
in 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:
setParameter
in 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:
setParameter
in 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:
getParameter
in 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:
getParameters
in interfaceResourceConfig
- Returns:
- The configuration parameters. The Map value is either a
Parameter
or parameter list (List<Parameter
>).
-
getParameterValues
public List<?> getParameterValues()
Get allparameter
values set on this configuration.- Specified by:
getParameterValues
in interfaceResourceConfig
- Returns:
Parameter
valueList
, or null if not set.
-
getParameters
public List<Parameter<?>> getParameters(String name)
Get the named ResourceConfigparameter
List.- Specified by:
getParameters
in interfaceResourceConfig
- Parameters:
name
- Name of parameter to get.- Returns:
Parameter
valueList
, or null if not set.
-
getParameterValue
public Object getParameterValue(String name)
- Specified by:
getParameterValue
in interfaceResourceConfig
-
getParameterValue
public <T> T getParameterValue(String name, Class<T> valueClass)
Get the named ResourceConfig parameter.- Specified by:
getParameterValue
in 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:
getParameterValue
in 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:
getParameterCount
in interfaceResourceConfig
- Returns:
- Number of parameters defined on this ResourceConfig.
-
removeParameter
public void removeParameter(String name)
Remove the named parameter.- Specified by:
removeParameter
in 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:
isXmlDef
in 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 theURIResourceLocator
i.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:
getBytes
in 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:
isJavaResource
in 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:
addChangeListener
in 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:
removeChangeListener
in interfaceResourceConfig
- Parameters:
listener
- The listener instance.
-
toXml
public String toXml()
Generate an XML'ified description of this resource.- Specified by:
toXml
in interfaceResourceConfig
- Returns:
- XML'ified description of the resource.
-
toProperties
public Properties toProperties()
Create aProperties
instance from this suppliedDefaultResourceConfig
- Specified by:
toProperties
in interfaceResourceConfig
- Returns:
- The resource parameters as a
Properties
instance.
-
-