public class JavaScriptLoader extends Object
The resource path can be a filesystem path or classpath. Both are supported and could be mixed.
For details of the source declaration see JavaScript.
JavaScript,
DetectionScript,
JsCallFunction,
JavaScriptSource| Constructor and Description |
|---|
JavaScriptLoader() |
| Modifier and Type | Method and Description |
|---|---|
protected StringBuilder |
fromClasspath(String classpath,
VaniContext vaniContext)
method to read javsScript file specified by path from classpath.
|
protected StringBuilder |
fromFilesystem(String sourcePath,
VaniContext vaniContext)
method to read javsScript file specified by path from file system.
|
protected Set<String> |
getResourcesPathFromClasspath(String classpath,
VaniContext context)
method to get paths of classpath resources.
|
protected List<Path> |
getResourcesPathFromFilesystem(String resourcePath)
method to get paths of resources on filesystem.
|
<T> JavaScriptSource<T> |
load(JavaScript javaScript,
Class<T> jsInterface,
VaniContext vaniContext)
This method is responsible for loading the javascript code from
filesystem or classpath.
|
protected <T> void |
setCallFunction(JavaScriptSource<T> jsSource,
VaniContext vaniContext)
This method will look for method annotated with
JsCallFunction in
the target interface of provided JavaScriptSource. |
protected <T> void |
setDetectedMethod(JavaScriptSource<T> jsSource)
This method will look for method annotated with (
DetectionScript
in taret interface of provided JavaScriptSource. |
void |
setReflectionUtil(VaniReflectionUtil reflectionUtil) |
public <T> JavaScriptSource<T> load(JavaScript javaScript, Class<T> jsInterface, VaniContext vaniContext) throws JavaScriptReadException
javaScript - annotation with source declarationjsInterface - vaniContext - JavaScriptSource object, which contains the
source code, custom call function and detection script. If
resource could not be found, object will have an empty source.JavaScriptReadException - will be thrown if an IOException occurs during reading js
sourceprotected <T> void setDetectedMethod(JavaScriptSource<T> jsSource)
DetectionScript
in taret interface of provided JavaScriptSource. If a method is
found, the javascript code of the annotation will be set to specified
jsSource as detection script.jsSource - protected <T> void setCallFunction(JavaScriptSource<T> jsSource, VaniContext vaniContext)
JsCallFunction in
the target interface of provided JavaScriptSource. If a method is
found, the corresponding source will be loaded and set to the provided
JavaScriptSource as custom javascript call function.
It supports filesystem and classpath declaration.
jsSource - vaniContext - protected StringBuilder fromClasspath(String classpath, VaniContext vaniContext) throws JavaScriptReadException
If you provide resource and path, only matching resources with provided path will be used.
sourcePath - vaniContext - StringBuffer containing only source code of
specified js-script by sourcePath or empty
StringBuilder if file does not existJavaScriptReadException - will be thrown if an IOException occurs during reading js
sourceprotected StringBuilder fromFilesystem(String sourcePath, VaniContext vaniContext) throws JavaScriptReadException
sourcePath - vaniContext - StringBuffer containing only source code of
specified js-script by sourcePath or empty
StringBuilder if file does not existJavaScriptReadException - will be thrown if an error occurs during collecting paths to
specified resources or reading source fileprotected List<Path> getResourcesPathFromFilesystem(String resourcePath) throws Throwable
If you don't provide an path, it will look in current working path for it.
sourceData - Throwable - will be thrown if an error occurs during search for given
resources on filesystemprotected Set<String> getResourcesPathFromClasspath(String classpath, VaniContext context)
If you provide resource and path, only matching resources with provided path will be returned.
classpath - name of resource (also path and regex are supported)context - public void setReflectionUtil(VaniReflectionUtil reflectionUtil)
Copyright © 2016. All rights reserved.