mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Web Scripts:
- addition of extension paths for web script customisations - updated "delete ticket" web script to return appropriate response on success git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5867 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ticket>${ticket}</ticket>
|
@@ -1,6 +1,6 @@
|
||||
<webscript>
|
||||
<shortname>Login Ticket</shortname>
|
||||
<description>Login Ticket</description>
|
||||
<shortname>Get Login Ticket</shortname>
|
||||
<description>Get Login Ticket</description>
|
||||
<url format="xml" template="/login/ticket/{ticket}"/>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
|
@@ -2,9 +2,49 @@
|
||||
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
|
||||
|
||||
<beans>
|
||||
|
||||
<!-- -->
|
||||
<!-- Web Script Storage -->
|
||||
<!-- -->
|
||||
|
||||
<bean id="webscripts.repostore" class="org.alfresco.web.scripts.RepoStore" abstract="true">
|
||||
<property name="transactionHelper" ref="retryingTransactionHelper" />
|
||||
<property name="nodeService" ref="nodeService" />
|
||||
<property name="namespaceService" ref="namespaceService" />
|
||||
<property name="contentService" ref="contentService" />
|
||||
<property name="searchService" ref="SearchService" />
|
||||
</bean>
|
||||
|
||||
<bean id="webscripts.classpathstore" class="org.alfresco.web.scripts.ClassPathStore" abstract="true" />
|
||||
|
||||
<bean parent="webscripts.repostore">
|
||||
<property name="store"><value>workspace://SpacesStore</value></property>
|
||||
<property name="path"><value>/${spaces.company_home.childname}/${spaces.dictionary.childname}/cm:extensionwebscripts</value></property>
|
||||
</bean>
|
||||
|
||||
<bean parent="webscripts.repostore">
|
||||
<property name="mustExist"><value>true</value></property>
|
||||
<property name="store"><value>workspace://SpacesStore</value></property>
|
||||
<property name="path"><value>/${spaces.company_home.childname}/${spaces.dictionary.childname}/cm:webscripts</value></property>
|
||||
</bean>
|
||||
|
||||
<bean parent="webscripts.classpathstore">
|
||||
<property name="classPath"><value>alfresco/extension/templates/webscripts</value></property>
|
||||
</bean>
|
||||
|
||||
<bean parent="webscripts.classpathstore">
|
||||
<property name="mustExist"><value>true</value></property>
|
||||
<property name="classPath"><value>alfresco/templates/webscripts</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="webscripts.storage" class="org.alfresco.web.scripts.WebScriptStorage">
|
||||
<property name="templateProcessor" ref="webscripts.templateprocessor" />
|
||||
<property name="scriptProcessor" ref="webscripts.scriptprocessor" />
|
||||
</bean>
|
||||
|
||||
|
||||
<!-- -->
|
||||
<!-- Web Script Resource Bundles -->
|
||||
<!-- Web Script Context -->
|
||||
<!-- -->
|
||||
|
||||
<bean id="webscripts.resources" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
|
||||
@@ -15,11 +55,6 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<!-- -->
|
||||
<!-- API Definition & Implementation Storage -->
|
||||
<!-- -->
|
||||
|
||||
<bean id="webscripts.context" class="org.alfresco.web.scripts.WebScriptContext">
|
||||
<property name="transactionService" ref="transactionComponent" />
|
||||
<property name="namespaceService" ref="namespaceService" />
|
||||
@@ -30,14 +65,9 @@
|
||||
<property name="companyHomePath"><value>/${spaces.company_home.childname}</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="webscripts.storage" class="org.alfresco.web.scripts.WebScriptStorage">
|
||||
<property name="templateProcessor" ref="webscripts.templateprocessor" />
|
||||
<property name="scriptProcessor" ref="webscripts.scriptprocessor" />
|
||||
</bean>
|
||||
|
||||
<bean id="webscripts.templateprocessor" class="org.alfresco.web.scripts.TemplateProcessor">
|
||||
<property name="freeMarkerProcessor" ref="freeMarkerProcessor" />
|
||||
<property name="serviceRegistry" ref="ServiceRegistry" />
|
||||
<property name="freeMarkerProcessor" ref="freeMarkerProcessor" />
|
||||
<property name="serviceRegistry" ref="ServiceRegistry" />
|
||||
<!-- <property name="defaultEncoding"><value>UTF-8</value></property> -->
|
||||
</bean>
|
||||
|
||||
@@ -45,33 +75,9 @@
|
||||
<property name="scriptService" ref="ScriptService" />
|
||||
</bean>
|
||||
|
||||
<bean id="webscripts.repostore" class="org.alfresco.web.scripts.RepoStore" abstract="true">
|
||||
<property name="transactionHelper" ref="retryingTransactionHelper" />
|
||||
<property name="nodeService" ref="nodeService" />
|
||||
<property name="namespaceService" ref="namespaceService" />
|
||||
<property name="contentService" ref="contentService" />
|
||||
<property name="searchService" ref="SearchService" />
|
||||
</bean>
|
||||
|
||||
<bean id="webscripts.classpathstore" class="org.alfresco.web.scripts.ClassPathStore" abstract="true" />
|
||||
|
||||
|
||||
<!-- -->
|
||||
<!-- Web Script Search Paths -->
|
||||
<!-- -->
|
||||
|
||||
<bean parent="webscripts.repostore">
|
||||
<property name="store"><value>workspace://SpacesStore</value></property>
|
||||
<property name="path"><value>/${spaces.company_home.childname}/${spaces.dictionary.childname}/cm:webscripts</value></property>
|
||||
</bean>
|
||||
|
||||
<bean parent="webscripts.classpathstore">
|
||||
<property name="classPath"><value>alfresco/templates/webscripts</value></property>
|
||||
</bean>
|
||||
|
||||
|
||||
<!-- -->
|
||||
<!-- API Service Registry -->
|
||||
<!-- Web Script Registry -->
|
||||
<!-- -->
|
||||
|
||||
<bean id="webscripts.registry" class="org.alfresco.web.scripts.DeclarativeWebScriptRegistry">
|
||||
@@ -93,11 +99,10 @@
|
||||
<property name="scriptContext" ref="webscripts.context" />
|
||||
<property name="authenticationService" ref="AuthenticationService" />
|
||||
</bean>
|
||||
|
||||
|
||||
|
||||
<!-- -->
|
||||
<!-- API Response Formats -->
|
||||
<!-- Response Formats -->
|
||||
<!-- -->
|
||||
|
||||
<!-- Format Registry -->
|
||||
@@ -138,7 +143,7 @@
|
||||
|
||||
|
||||
<!-- -->
|
||||
<!-- API Configuration -->
|
||||
<!-- Web Script Configuration -->
|
||||
<!-- -->
|
||||
|
||||
<bean id="webscripts.configsource" class="org.alfresco.config.source.UrlConfigSource">
|
||||
@@ -159,7 +164,7 @@
|
||||
|
||||
|
||||
<!-- -->
|
||||
<!-- Base implementations of a Web API Backing Bean -->
|
||||
<!-- Base implementations of a Web Script Backing Bean -->
|
||||
<!-- -->
|
||||
|
||||
<!-- Abstract API Service -->
|
||||
@@ -174,7 +179,7 @@
|
||||
|
||||
|
||||
<!-- -->
|
||||
<!-- Custom Java Web API Backing Beans -->
|
||||
<!-- Custom Java Web Script Backing Beans -->
|
||||
<!-- -->
|
||||
|
||||
<!-- List of available Web APIs -->
|
||||
|
@@ -53,10 +53,24 @@ import freemarker.cache.TemplateLoader;
|
||||
public class ClassPathStore implements WebScriptStore, InitializingBean
|
||||
{
|
||||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||
protected boolean mustExist = false;
|
||||
protected String classPath;
|
||||
protected File fileDir;
|
||||
|
||||
|
||||
/**
|
||||
* Sets whether the class path must exist
|
||||
*
|
||||
* If it must exist, but it doesn't exist, an exception is thrown
|
||||
* on initialisation of the store
|
||||
*
|
||||
* @param mustExist
|
||||
*/
|
||||
public void setMustExist(boolean mustExist)
|
||||
{
|
||||
this.mustExist = mustExist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the class path
|
||||
*
|
||||
@@ -74,7 +88,22 @@ public class ClassPathStore implements WebScriptStore, InitializingBean
|
||||
throws Exception
|
||||
{
|
||||
ClassPathResource resource = new ClassPathResource(classPath);
|
||||
fileDir = resource.getFile();
|
||||
if (resource.exists())
|
||||
{
|
||||
fileDir = resource.getFile();
|
||||
}
|
||||
else if (mustExist)
|
||||
{
|
||||
throw new WebScriptException("Web Script Store classpath:" + classPath + " must exist; it was not found");
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptStore#exists()
|
||||
*/
|
||||
public boolean exists()
|
||||
{
|
||||
return (fileDir != null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@@ -63,6 +63,7 @@ import freemarker.cache.TemplateLoader;
|
||||
public class RepoStore implements WebScriptStore, ApplicationContextAware, ApplicationListener
|
||||
{
|
||||
private ProcessorLifecycle lifecycle = new ProcessorLifecycle();
|
||||
protected boolean mustExist = false;
|
||||
protected StoreRef repoStore;
|
||||
protected String repoPath;
|
||||
protected NodeRef baseNodeRef;
|
||||
@@ -116,6 +117,16 @@ public class RepoStore implements WebScriptStore, ApplicationContextAware, Appli
|
||||
this.namespaceService = namespaceService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the repo store must exist
|
||||
*
|
||||
* @param mustExist
|
||||
*/
|
||||
public void setMustExist(boolean mustExist)
|
||||
{
|
||||
this.mustExist = mustExist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the repo store
|
||||
*/
|
||||
@@ -182,23 +193,30 @@ public class RepoStore implements WebScriptStore, ApplicationContextAware, Appli
|
||||
{
|
||||
String query = "PATH:\"" + repoPath + "\"";
|
||||
ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query);
|
||||
if (resultSet.length() == 0)
|
||||
if (resultSet.length() == 1)
|
||||
{
|
||||
throw new WebScriptException("Unable to locate repository path " + repoStore.toString() + repoPath);
|
||||
baseNodeRef = resultSet.getNodeRef(0);
|
||||
baseDir = getPath(baseNodeRef);
|
||||
}
|
||||
if (resultSet.length() > 1)
|
||||
else if (mustExist)
|
||||
{
|
||||
throw new WebScriptException("Multiple repository paths found for " + repoStore.toString() + repoPath);
|
||||
throw new WebScriptException("Web Script Store " + repoStore.toString() + repoPath + " must exist; it was not found");
|
||||
}
|
||||
baseNodeRef = resultSet.getNodeRef(0);
|
||||
baseDir = getPath(baseNodeRef);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptStore#exists()
|
||||
*/
|
||||
public boolean exists()
|
||||
{
|
||||
return (baseNodeRef != null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptStore#getBasePath()
|
||||
*/
|
||||
|
@@ -217,7 +217,7 @@ public abstract class WebScriptRuntime
|
||||
templatePath = "/status.ftl";
|
||||
if (!registry.getTemplateProcessor().hasTemplate(templatePath))
|
||||
{
|
||||
throw new WebScriptException("Failed to find status template " + status + " (format: " + WebScriptResponse.HTML_FORMAT + ")");
|
||||
throw new WebScriptException("Failed to find status template " + templatePath + " (format: " + WebScriptResponse.HTML_FORMAT + ")");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -97,7 +97,16 @@ public class WebScriptStorage implements ApplicationContextAware, ApplicationLis
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<WebScriptStore> getStores()
|
||||
{
|
||||
return applicationContext.getBeansOfType(WebScriptStore.class, false, false).values();
|
||||
Collection<WebScriptStore> allstores = applicationContext.getBeansOfType(WebScriptStore.class, false, false).values();
|
||||
Collection<WebScriptStore> stores = new ArrayList<WebScriptStore>();
|
||||
for (WebScriptStore store : allstores)
|
||||
{
|
||||
if (store.exists())
|
||||
{
|
||||
stores.add(store);
|
||||
}
|
||||
}
|
||||
return stores;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -37,7 +37,13 @@ import freemarker.cache.TemplateLoader;
|
||||
*/
|
||||
public interface WebScriptStore
|
||||
{
|
||||
|
||||
/**
|
||||
* Determines whether the store actually exists
|
||||
*
|
||||
* @return true => it does exist
|
||||
*/
|
||||
public boolean exists();
|
||||
|
||||
/**
|
||||
* Gets the base path of the store
|
||||
*
|
||||
|
@@ -83,7 +83,7 @@ public class LoginTicketDelete extends DeclarativeWebScript
|
||||
// construct model for ticket
|
||||
Map<String, Object> model = new HashMap<String, Object>(7, 1.0f);
|
||||
model.put("ticket", ticket);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
String ticketUser = ticketComponent.validateTicket(ticket);
|
||||
@@ -91,7 +91,6 @@ public class LoginTicketDelete extends DeclarativeWebScript
|
||||
// do not go any further if tickets are different
|
||||
if (!AuthenticationUtil.getCurrentUserName().equals(ticketUser))
|
||||
{
|
||||
status.setRedirect(true);
|
||||
status.setCode(HttpServletResponse.SC_NOT_FOUND);
|
||||
status.setMessage("Ticket not found");
|
||||
}
|
||||
@@ -99,15 +98,16 @@ public class LoginTicketDelete extends DeclarativeWebScript
|
||||
{
|
||||
// delete the ticket
|
||||
authenticationService.invalidateTicket(ticket);
|
||||
status.setMessage("Deleted Ticket " + ticket);
|
||||
}
|
||||
}
|
||||
catch(AuthenticationException e)
|
||||
{
|
||||
status.setRedirect(true);
|
||||
status.setCode(HttpServletResponse.SC_NOT_FOUND);
|
||||
status.setMessage("Ticket not found");
|
||||
}
|
||||
|
||||
|
||||
status.setRedirect(true);
|
||||
return model;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user