Class GroovyScript2RestLoader
java.lang.Object
org.exoplatform.services.jcr.ext.script.groovy.GroovyScript2RestLoader
- All Implemented Interfaces:
org.picocontainer.Startable
GroovyScript2RestLoader allows to save a Groovy script in JCR.
- Version:
- $Id: GroovyScript2RestLoader.java 34445 2009-07-24 07:51:18Z dkatayev $
- Author:
- Andrey Parfonov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classstatic classScript list, used for pass script list as JSON.static classScript meta-data, used for pass script meta-data as JSON. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List<GroovyScriptAddRepoPlugin>protected org.exoplatform.container.configuration.ConfigurationManagerSeeConfigurationManager.protected org.exoplatform.services.rest.ext.groovy.GroovyJaxrsPublisherprotected org.exoplatform.container.xml.InitParamsSeeInitParams.protected List<GroovyScript2RestLoaderPlugin>protected RegistryServiceSeeRegistryService.protected org.exoplatform.services.jcr.RepositoryServiceSeeRepositoryService.protected SessionProviderService -
Constructor Summary
ConstructorsConstructorDescriptionGroovyScript2RestLoader(org.exoplatform.services.rest.impl.ResourceBinder binder, org.exoplatform.services.script.groovy.GroovyScriptInstantiator groovyScriptInstantiator, org.exoplatform.services.jcr.RepositoryService repositoryService, SessionProviderService sessionProviderService, org.exoplatform.container.configuration.ConfigurationManager configurationManager, RegistryService registryService, Handler jcrUrlHandler, org.exoplatform.container.xml.InitParams params) GroovyScript2RestLoader(org.exoplatform.services.rest.impl.ResourceBinder binder, org.exoplatform.services.script.groovy.GroovyScriptInstantiator groovyScriptInstantiator, org.exoplatform.services.jcr.RepositoryService repositoryService, SessionProviderService sessionProviderService, org.exoplatform.container.configuration.ConfigurationManager configurationManager, RegistryService registryService, org.exoplatform.services.rest.ext.groovy.GroovyJaxrsPublisher groovyPublisher, Handler jcrUrlHandler, org.exoplatform.container.xml.InitParams params) GroovyScript2RestLoader(org.exoplatform.services.rest.impl.ResourceBinder binder, org.exoplatform.services.script.groovy.GroovyScriptInstantiator groovyScriptInstantiator, org.exoplatform.services.jcr.RepositoryService repositoryService, SessionProviderService sessionProviderService, org.exoplatform.container.configuration.ConfigurationManager configurationManager, Handler jcrUrlHandler, org.exoplatform.container.xml.InitParams params) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPlugin(org.exoplatform.container.component.ComponentPlugin cp) javax.ws.rs.core.ResponseaddScript(InputStream stream, javax.ws.rs.core.UriInfo uriInfo, String repository, String workspace, String path) This method is useful for clients that can send script in request body without form-data.javax.ws.rs.core.ResponseaddScript(Iterator<org.apache.commons.fileupload.FileItem> items, javax.ws.rs.core.UriInfo uriInfo, String repository, String workspace, String path) This method is useful for clients that send scripts as file in 'multipart/*' request body.protected voidAdd scripts that specified in configuration.javax.ws.rs.core.ResponseChange exo:autoload property.protected javax.jcr.NodecreateScript(javax.jcr.Node parent, String name, boolean autoload, InputStream stream) Create JCR node.javax.ws.rs.core.ResponsedeleteScript(String repository, String workspace, String path) Remove node that contains groovy script.protected StringgetAttributeSmart(Element element, String attr) Get attribute value.protected static StringExtract node's name from full node path.Get node type for store scripts, may throwIllegalStateExceptionifnodeTypenot initialized yet.protected static StringExtract path to node's parent from full path.javax.ws.rs.core.ResponseGet source code of groovy script.javax.ws.rs.core.ResponsegetScriptMetadata(String repository, String workspace, String path) Get groovy script's meta-information.javax.ws.rs.core.ResponseReturns the list of all groovy-scripts found in workspace.javax.ws.rs.core.Responseload(String repository, String workspace, String path, boolean state, List<String> sources, List<String> files, javax.ws.rs.core.MultivaluedMap<String, String> properties) Deploy groovy script as REST service.javax.ws.rs.core.Responseload(String repository, String workspace, String path, boolean state, javax.ws.rs.core.MultivaluedMap<String, String> properties, org.exoplatform.services.rest.ext.groovy.SourceFolder[] src, org.exoplatform.services.rest.ext.groovy.SourceFile[] files) Deploy groovy script as REST service.protected voidRead parameters from file.protected voidreadParamsFromRegistryService(SessionProvider sessionProvider) Read parameters from RegistryService.protected voidsetAttributeSmart(Element element, String attr, String value) Set attribute value.voidstart()voidstop()javax.ws.rs.core.ResponseupdateScript(InputStream stream, javax.ws.rs.core.UriInfo uriInfo, String repository, String workspace, String path) This method is useful for clients that can send script in request body without form-data.javax.ws.rs.core.ResponseupdateScript(Iterator<org.apache.commons.fileupload.FileItem> items, javax.ws.rs.core.UriInfo uriInfo, String repository, String workspace, String path) This method is useful for clients that send scripts as file in 'multipart/*' request body.javax.ws.rs.core.ResponsevalidateScript(String name, InputStream script, List<String> sources, List<String> files) Check is specified sourcescriptcontains valid Groovy source code.voidvalidateScript(String name, InputStream script, org.exoplatform.services.rest.ext.groovy.SourceFolder[] src, org.exoplatform.services.rest.ext.groovy.SourceFile[] files) Check is specified sourcescriptcontains valid Groovy source code.protected voidwriteParamsToRegistryService(SessionProvider sessionProvider) Write parameters to RegistryService.
-
Field Details
-
groovyPublisher
protected org.exoplatform.services.rest.ext.groovy.GroovyJaxrsPublisher groovyPublisher -
initParams
protected org.exoplatform.container.xml.InitParams initParamsSeeInitParams. -
repositoryService
protected org.exoplatform.services.jcr.RepositoryService repositoryServiceSeeRepositoryService. -
configurationManager
protected org.exoplatform.container.configuration.ConfigurationManager configurationManagerSeeConfigurationManager. -
registryService
SeeRegistryService. -
sessionProviderService
-
loadPlugins
-
addRepoPlugins
-
-
Constructor Details
-
GroovyScript2RestLoader
public GroovyScript2RestLoader(org.exoplatform.services.rest.impl.ResourceBinder binder, org.exoplatform.services.script.groovy.GroovyScriptInstantiator groovyScriptInstantiator, org.exoplatform.services.jcr.RepositoryService repositoryService, SessionProviderService sessionProviderService, org.exoplatform.container.configuration.ConfigurationManager configurationManager, Handler jcrUrlHandler, org.exoplatform.container.xml.InitParams params) - Parameters:
binder- binder for RESTful servicesgroovyScriptInstantiator- instantiate groovy scriptsrepositoryService- SeeRepositoryServicesessionProviderService- SeeSessionProviderServiceconfigurationManager- for solve resource loading issue in common wayparams- initialized parameters
-
GroovyScript2RestLoader
public GroovyScript2RestLoader(org.exoplatform.services.rest.impl.ResourceBinder binder, org.exoplatform.services.script.groovy.GroovyScriptInstantiator groovyScriptInstantiator, org.exoplatform.services.jcr.RepositoryService repositoryService, SessionProviderService sessionProviderService, org.exoplatform.container.configuration.ConfigurationManager configurationManager, RegistryService registryService, Handler jcrUrlHandler, org.exoplatform.container.xml.InitParams params) - Parameters:
binder- binder for RESTful servicesgroovyScriptInstantiator- instantiates Groovy scriptsrepositoryService- SeeRepositoryServicesessionProviderService- SeeSessionProviderServiceconfigurationManager- for solve resource loading issue in common wayregistryService- SeeRegistryServiceparams- initialized parameters
-
GroovyScript2RestLoader
public GroovyScript2RestLoader(org.exoplatform.services.rest.impl.ResourceBinder binder, org.exoplatform.services.script.groovy.GroovyScriptInstantiator groovyScriptInstantiator, org.exoplatform.services.jcr.RepositoryService repositoryService, SessionProviderService sessionProviderService, org.exoplatform.container.configuration.ConfigurationManager configurationManager, RegistryService registryService, org.exoplatform.services.rest.ext.groovy.GroovyJaxrsPublisher groovyPublisher, Handler jcrUrlHandler, org.exoplatform.container.xml.InitParams params)
-
-
Method Details
-
getNodeType
Get node type for store scripts, may throwIllegalStateExceptionifnodeTypenot initialized yet.- Returns:
- return node type
-
start
public void start()- Specified by:
startin interfaceorg.picocontainer.Startable- See Also:
-
Startable.start()
-
stop
public void stop()- Specified by:
stopin interfaceorg.picocontainer.Startable- See Also:
-
Startable.stop()
-
addPlugin
public void addPlugin(org.exoplatform.container.component.ComponentPlugin cp) -
addScripts
protected void addScripts()Add scripts that specified in configuration. -
createScript
protected javax.jcr.Node createScript(javax.jcr.Node parent, String name, boolean autoload, InputStream stream) throws Exception Create JCR node.- Parameters:
parent- parent nodename- name of node to be createdstream- data stream for property jcr:data- Returns:
- newly created node
- Throws:
Exception- if any errors occurs
-
readParamsFromRegistryService
protected void readParamsFromRegistryService(SessionProvider sessionProvider) throws javax.jcr.PathNotFoundException, javax.jcr.RepositoryException Read parameters from RegistryService.- Parameters:
sessionProvider- the SessionProvider- Throws:
javax.jcr.RepositoryExceptionjavax.jcr.PathNotFoundException
-
writeParamsToRegistryService
protected void writeParamsToRegistryService(SessionProvider sessionProvider) throws IOException, SAXException, ParserConfigurationException, javax.jcr.RepositoryException Write parameters to RegistryService.- Parameters:
sessionProvider- the SessionProvider- Throws:
ParserConfigurationExceptionSAXExceptionIOExceptionjavax.jcr.RepositoryException
-
getAttributeSmart
Get attribute value.- Parameters:
element- The element to get attribute valueattr- The attribute name- Returns:
- Value of attribute if present and null in other case
-
setAttributeSmart
Set attribute value. If value is null the attribute will be removed.- Parameters:
element- The element to set attribute valueattr- The attribute namevalue- The value of attribute
-
readParamsFromFile
protected void readParamsFromFile()Read parameters from file. -
addScript
public javax.ws.rs.core.Response addScript(InputStream stream, @Context javax.ws.rs.core.UriInfo uriInfo, String repository, String workspace, String path) This method is useful for clients that can send script in request body without form-data. At required to set specific Content-type header 'script/groovy'.- Parameters:
stream- the stream that contains groovy source codeuriInfo- see javax.ws.rs.core.UriInforepository- repository nameworkspace- workspace namepath- path to resource to be created- Returns:
- Response with status 'created'
- eXo level API
- Provisional
- eXo anchor for generated doc on REST API
- {code} "stream" : the input stream that contains groovy source code {code}
-
addScript
public javax.ws.rs.core.Response addScript(Iterator<org.apache.commons.fileupload.FileItem> items, @Context javax.ws.rs.core.UriInfo uriInfo, String repository, String workspace, String path) This method is useful for clients that send scripts as file in 'multipart/*' request body. NOTE even we use iterator item should be only one, rule one address - one script. This method is created just for comfort loading script from HTML form. NOT use this script for uploading few files in body of 'multipart/form-data' or other type of multipart.- Parameters:
items- iterator org.apache.commons.fileupload.FileItemuriInfo- javax.ws.rs.core.UriInforepository- repository nameworkspace- workspace namepath- path to resource to be created- Returns:
- Response with status 'created'
- eXo level API
- Provisional
- eXo anchor for generated doc on REST API
- {code} "items" : the sending data with HTML form ('multipart/form-data') {code}
-
validateScript
public javax.ws.rs.core.Response validateScript(String name, InputStream script, List<String> sources, List<String> files) Check is specified sourcescriptcontains valid Groovy source code.- Parameters:
name- script name. This name will be used by GroovyClassLoader to identify script, e.g. specified name will be used in error message in compilation of Groovy fails. If this parameter isnullthen GroovyClassLoader will use automatically generated namescript- Groovy source streamsources- locations (string representation of URL) of source folders that should be add in class path when compile Groovy script. NOTE : To be able load Groovy source files from specified folders the following rules must be observed: - Groovy source files must be located in folder with respect to package structure - Name of Groovy source files must be the same as name of class located in file - Groovy source file must have extension '.groovy' Example: If source stream that we want validate contains the following code: package c.b.a import a.b.c.A class B extends A { // Do something. } Assume we store dependencies in JCR then URL of folder with Groovy sources may be like this:jcr://repository/workspace#/groovy-library. Then absolute path to JCR node that contains Groovy source must be as following:/groovy-library/a/b/c/A.groovyfiles- locations (string representation of URL) of source files that should be add in class path when compile Groovy script. Each location must point directly to file that contains Groovy source. Source file can have any name and extension- Returns:
- Response with corresponded status. 200 if source code is valid
- eXo level API
- Provisional
- eXo anchor for generated doc on REST API
- {code } "script" : the Groovy source stream. {code}
-
validateScript
public void validateScript(String name, InputStream script, org.exoplatform.services.rest.ext.groovy.SourceFolder[] src, org.exoplatform.services.rest.ext.groovy.SourceFile[] files) throws org.exoplatform.services.rest.ext.groovy.MalformedScriptException Check is specified sourcescriptcontains valid Groovy source code.- Parameters:
name- script name. This name will be used by GroovyClassLoader to identify script, e.g. specified name will be used in error message in compilation of Groovy fails. If this parameter isnullthen GroovyClassLoader will use automatically generated namescript- Groovy source streamsrc- set of folders that contains Groovy source files that should be add in class-path when validatescript, seeClassPathEntry.getPath(). NOTE To be able load Groovy source files from specified folders the following rules must be observed:- Groovy source files must be located in folder with respect to package structure
- Name of Groovy source files must be the same as name of class located in file
- Groovy source file must have extension '.groovy'
files- set of groovy source files that should be add in class-path when validatescript. Each item must point directly to file that contains Groovy source, seeClassPathEntry.getPath(). Source file can have any name and extension- Throws:
org.exoplatform.services.rest.ext.groovy.MalformedScriptException- ifscriptcontains not valid source code- eXo level API
- Provisional
-
updateScript
public javax.ws.rs.core.Response updateScript(InputStream stream, @Context javax.ws.rs.core.UriInfo uriInfo, String repository, String workspace, String path) This method is useful for clients that can send script in request body without form-data. At required to set specific Content-type header 'script/groovy'.- Parameters:
stream- the stream that contains groovy source codeuriInfo- see javax.ws.rs.core.UriInforepository- repository nameworkspace- workspace namepath- path to resource to be created- Returns:
- Response with status 'created'
- eXo level API
- Provisional
- eXo anchor for generated doc on REST API
- {code } "stream" : the input stream that contains groovy source code. {code}
-
updateScript
public javax.ws.rs.core.Response updateScript(Iterator<org.apache.commons.fileupload.FileItem> items, @Context javax.ws.rs.core.UriInfo uriInfo, String repository, String workspace, String path) This method is useful for clients that send scripts as file in 'multipart/*' request body. NOTE even we use iterator item should be only one, rule one address - one script. This method is created just for comfort loading script from HTML form. NOT use this script for uploading few files in body of 'multipart/form-data' or other type of multipart.- Parameters:
items- iterator org.apache.commons.fileupload.FileItemuriInfo- see javax.ws.rs.core.UriInforepository- repository nameworkspace- workspace namepath- path to resource to be created- Returns:
- Response with status 'created'
- eXo level API
- Provisional
- eXo anchor for generated doc on REST API
- {code} "items" : the sending data with HTML form ('multipart/form-data') {code}
-
load
@RolesAllowed("administrators") public javax.ws.rs.core.Response load(String repository, String workspace, String path, boolean state, List<String> sources, List<String> files, javax.ws.rs.core.MultivaluedMap<String, String> properties) Deploy groovy script as REST service. If this property set to 'true' then script will be deployed as REST service if 'false' the script will be undeployed. NOTE is script already deployed and state is true script will be re-deployed.- Parameters:
repository- repository nameworkspace- workspace namepath- the path to JCR node that contains groovy script to be deployedstate-trueif resource should be loaded andfalseotherwise. If this attribute is not present in HTTP request then it will be considered astruesources- locations (string representation of URL) of source folders that should be add in class path when compile Groovy script. NOTE: To be able load Groovy source files from specified folders the following rules must be observed: - Groovy source files must be located in folder with respect to package structure - Name of Groovy source files must be the same as name of class located in file - Groovy source file must have extension '.groovy' Example: If source stream that we want validate contains the following code: package c.b.a import a.b.c.A class B extends A { // Do something. } Assume we store dependencies in JCR then URL of folder with Groovy sources may be like this:jcr://repository/workspace#/groovy-library. Then absolute path to JCR node that contains Groovy source must be as following:/groovy-library/a/b/c/A.groovyfiles- locations (string representation of URL) of source files that should be add in class path when compile Groovy script. Each location must point directly to file that contains Groovy source. Source file can have any name and extensionproperties- optional properties to be applied to loaded resource. Ignored ifstateparameter is false- eXo level API
- Provisional
-
load
public javax.ws.rs.core.Response load(String repository, String workspace, String path, boolean state, javax.ws.rs.core.MultivaluedMap<String, String> properties, org.exoplatform.services.rest.ext.groovy.SourceFolder[] src, org.exoplatform.services.rest.ext.groovy.SourceFile[] files) Deploy groovy script as REST service. If this property set to 'true' then script will be deployed as REST service if 'false' the script will be undeployed. NOTE is script already deployed andstateistruescript will be re-deployed.- Parameters:
repository- repository nameworkspace- workspace namepath- the path to JCR node that contains groovy script to be deployedstate-trueif resource should be loaded andfalseotherwise. If this attribute is not present in HTTP request then it will be considered astrueproperties- optional properties to be applied to loaded resource. Ignored ifstateparameter is falsesrc- set of folders that contains Groovy source files that should be add in class-path when compile file located atpath. NOTE To be able load Groovy source files from specified folders the following rules must be observed:- Groovy source files must be located in folder with respect to package structure
- Name of Groovy source files must be the same as name of class located in file
- Groovy source file must have extension '.groovy'
files- set of groovy source files that should be add in class-path when compile file located atpath. Each item must point directly to file that contains Groovy source, seeClassPathEntry.getPath(). Source file can have any name and extension- eXo level API
- Provisional
-
deleteScript
Remove node that contains groovy script.- Parameters:
repository- repository nameworkspace- workspace namepath- JCR path to node that contains script- eXo level API
- Provisional
-
autoload
public javax.ws.rs.core.Response autoload(String repository, String workspace, String path, boolean state) Change exo:autoload property. If this property is 'true' script will be deployed automatically when JCR repository startup and automatically re-deployed when script source code changed.- Parameters:
repository- repository nameworkspace- workspace namepath- JCR path to node that contains scriptstate- value for property exo:autoload, if it is not specified then 'true' will be used as default. Example: .../scripts/groovy/test1.groovy/load is the same to .../scripts/groovy/test1.groovy/load?state=true- eXo level API
- Provisional
-
getScript
Get source code of groovy script.- Parameters:
repository- repository nameworkspace- workspace namepath- JCR path to node that contains script- Returns:
- groovy script as stream
- eXo level API
- Provisional
- eXo response for generated doc on REST API
- {code} "scriptsource" : the source code of groovy script. {code}
-
getScriptMetadata
public javax.ws.rs.core.Response getScriptMetadata(String repository, String workspace, String path) Get groovy script's meta-information.- Parameters:
repository- repository nameworkspace- workspace namepath- JCR path to node that contains script- Returns:
- groovy script's meta-information
- eXo level API
- Provisional
- eXo response for generated doc on REST API
- {code:json} "scriptList" : the groovy script's meta-information {code}
-
list
Returns the list of all groovy-scripts found in workspace.- Parameters:
repository- repository nameworkspace- workspace namename- additional search parameter. If not empty method returns the list of script names matching wildcard else returns all the scripts found in workspace.- Returns:
- list of groovy services
- eXo level API
- Provisional
- eXo response for generated doc on REST API
- {code:json} "scriptList" : the list of all groovy scripts found in workspace. {code}
-
getPath
Extract path to node's parent from full path.- Parameters:
fullPath- full path to node- Returns:
- node's parent path
-
getName
Extract node's name from full node path.- Parameters:
fullPath- full path to node- Returns:
- node's name
-