mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Web Scripts:
- support url extension for specifying required response format - update scriptUrl method to handle various forms of specifying format on url - refactor web script request hierarchy; remove copy & paste - add reset web script registry to web script "Test Server" git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5803 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -40,6 +40,7 @@ import javax.servlet.ServletContext;
|
||||
import org.alfresco.service.cmr.repository.FileTypeImageSize;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.util.AbstractLifecycleBean;
|
||||
import org.alfresco.web.scripts.WebScriptDescription.FormatStyle;
|
||||
import org.alfresco.web.scripts.WebScriptDescription.RequiredAuthentication;
|
||||
import org.alfresco.web.scripts.WebScriptDescription.RequiredTransaction;
|
||||
import org.alfresco.web.scripts.WebScriptDescription.URI;
|
||||
@@ -238,7 +239,9 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
|
||||
serviceImpl.init(this);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Found Web Script " + id + " (desc: " + serviceDescPath + ", impl: " + serviceImplName + ", auth: " + serviceDesc.getRequiredAuthentication() + ", trx: " + serviceDesc.getRequiredTransaction() + ")");
|
||||
logger.debug("Found Web Script " + id + " (desc: " + serviceDescPath + ", impl: " + serviceImplName + ", auth: " +
|
||||
serviceDesc.getRequiredAuthentication() + ", trx: " + serviceDesc.getRequiredTransaction() + ", format: " +
|
||||
serviceDesc.getFormatStyle() + ")");
|
||||
|
||||
// register service and its urls
|
||||
webscriptsById.put(id, serviceImpl);
|
||||
@@ -256,6 +259,14 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
|
||||
{
|
||||
uriTemplate = uriTemplate.substring(0, tokenIdx);
|
||||
}
|
||||
if (serviceDesc.getFormatStyle() != WebScriptDescription.FormatStyle.argument)
|
||||
{
|
||||
int extIdx = uriTemplate.lastIndexOf(".");
|
||||
if (extIdx != -1)
|
||||
{
|
||||
uriTemplate = uriTemplate.substring(0, extIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// index service by static part of url (ensuring no other service has already claimed the url)
|
||||
String uriIdx = serviceDesc.getMethod().toString() + ":" + uriTemplate;
|
||||
@@ -338,7 +349,7 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
|
||||
List urlElements = rootElement.elements("url");
|
||||
if (urlElements == null || urlElements.size() == 0)
|
||||
{
|
||||
throw new WebScriptException("Expected at one <url> element");
|
||||
throw new WebScriptException("Expected at least one <url> element");
|
||||
}
|
||||
List<WebScriptDescription.URI> uris = new ArrayList<WebScriptDescription.URI>();
|
||||
Iterator iterElements = urlElements.iterator();
|
||||
@@ -402,6 +413,28 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
|
||||
}
|
||||
}
|
||||
|
||||
// retrieve format
|
||||
String defaultFormat = uris.get(0).getFormat();
|
||||
FormatStyle formatStyle = FormatStyle.any;
|
||||
Element formatElement = rootElement.element("format");
|
||||
if (formatElement != null)
|
||||
{
|
||||
String formatStyleStr = formatElement.getTextTrim();
|
||||
if (formatStyleStr != null && formatStyleStr.length() > 0)
|
||||
{
|
||||
formatStyle = FormatStyle.valueOf(formatStyleStr);
|
||||
if (formatStyle == null)
|
||||
{
|
||||
throw new WebScriptException("Format Style '" + formatStyle + "' is not a valid value");
|
||||
}
|
||||
}
|
||||
String defaultFormatStr = formatElement.attributeValue("default");
|
||||
if (defaultFormatStr != null && defaultFormatStr.length() > 0)
|
||||
{
|
||||
defaultFormat = defaultFormatStr;
|
||||
}
|
||||
}
|
||||
|
||||
// construct service description
|
||||
WebScriptDescriptionImpl serviceDesc = new WebScriptDescriptionImpl();
|
||||
serviceDesc.setStore(store);
|
||||
@@ -414,7 +447,8 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
|
||||
serviceDesc.setRequiredTransaction(reqTrx);
|
||||
serviceDesc.setMethod(method);
|
||||
serviceDesc.setUris(uris.toArray(new WebScriptDescription.URI[uris.size()]));
|
||||
serviceDesc.setDefaultFormat(uris.get(0).getFormat());
|
||||
serviceDesc.setDefaultFormat(defaultFormat);
|
||||
serviceDesc.setFormatStyle(formatStyle);
|
||||
return serviceDesc;
|
||||
}
|
||||
catch(DocumentException e)
|
||||
|
Reference in New Issue
Block a user