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:
David Caruana
2007-06-06 11:57:42 +00:00
parent c89bce7bda
commit 3d86571cda
9 changed files with 127 additions and 62 deletions

View File

@@ -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)

View File

@@ -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()
*/

View File

@@ -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 + ")");
}
}

View File

@@ -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;
}
/**

View File

@@ -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
*

View File

@@ -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;
}