Class StaticContentByRegexResourceLoader
- java.lang.Object
-
- com.hybris.cockpitng.core.persistence.packaging.impl.StaticContentByRegexResourceLoader
-
- All Implemented Interfaces:
ResourceLoader
public class StaticContentByRegexResourceLoader extends java.lang.Object implements ResourceLoader
Responsible for returning default resource for paths whose match regular expression. This loader stores resource mapping in format: regular expression → default resource path.
-
-
Constructor Summary
Constructors Constructor Description StaticContentByRegexResourceLoader()Constructs a new instance.StaticContentByRegexResourceLoader(java.util.Map<java.lang.String,java.lang.String> mapping)Constructs a new instance and sets resource mapping.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.InputStreamgetResourceAsStream(java.lang.String path)Returns default resource when the path match regular expression.protected java.io.InputStreamgetResourceByPath(java.lang.String path)Returns resource identified by path asInputStreamornullif resource does not exist.booleanhasResource(java.lang.String path)Checks whether this loader can load resource identified by path.protected booleanisResourceExisting(java.lang.String path)Checks whether a resource identified by path exist.voidsetMapping(java.util.Map<java.lang.String,java.lang.String> mapping)Sets mapping used to match resource path to default resource path.
-
-
-
Constructor Detail
-
StaticContentByRegexResourceLoader
public StaticContentByRegexResourceLoader()
Constructs a new instance.
-
StaticContentByRegexResourceLoader
public StaticContentByRegexResourceLoader(java.util.Map<java.lang.String,java.lang.String> mapping)
Constructs a new instance and sets resource mapping.- Parameters:
mapping- the mapping in format: regular expression → default resource path.- Throws:
java.lang.IllegalArgumentException- if the mapping is blank.
-
-
Method Detail
-
setMapping
public void setMapping(java.util.Map<java.lang.String,java.lang.String> mapping)
Sets mapping used to match resource path to default resource path.- Parameters:
mapping- the mapping in format: regular expression → default resource path.- Throws:
java.lang.IllegalArgumentException- if the mapping is blank.
-
hasResource
public boolean hasResource(java.lang.String path)
Description copied from interface:ResourceLoaderChecks whether this loader can load resource identified by path.- Specified by:
hasResourcein interfaceResourceLoader- Parameters:
path- the path identifying resource.- Returns:
truewhether this loader can load resource, otherwisefalse.
-
isResourceExisting
protected boolean isResourceExisting(java.lang.String path)
Checks whether a resource identified by path exist.- Parameters:
path- the path identifying resource.- Returns:
trueif the resource exists, otherwisefalse.
-
getResourceAsStream
public java.io.InputStream getResourceAsStream(java.lang.String path)
Returns default resource when the path match regular expression. It matches path to regular expressions in turn until one match and the default resource exists.- Specified by:
getResourceAsStreamin interfaceResourceLoader- Parameters:
path- the path identifying resource.- Returns:
- Resource as
InputStreamornull. - Throws:
java.lang.IllegalArgumentException- if the path is blank.
-
getResourceByPath
protected java.io.InputStream getResourceByPath(java.lang.String path)
Returns resource identified by path asInputStreamornullif resource does not exist.- Parameters:
path- the path identifying resource.- Returns:
- the input stream or
nullif the resource does not exist.
-
-