Web Scripts:

- simplify how web scripts urls & formats are described
- fix 'reset' on index page (when accessed via /)
- fix xml status response (rogue html in template)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5897 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2007-06-08 21:39:54 +00:00
parent f95c3de04f
commit bb2536fcf5
36 changed files with 101 additions and 189 deletions

View File

@@ -1,6 +1,6 @@
<webscript> <webscript>
<shortname>Web Scripts Documentation</shortname> <shortname>Web Scripts Documentation</shortname>
<description>Web Scripts Documentation</description> <description>Web Scripts Documentation</description>
<url format="html" template="/" /> <url>/</url>
<url format="html" template="/index" /> <url>/index</url>
</webscript> </webscript>

View File

@@ -1,5 +1,6 @@
<webscript> <webscript>
<shortname>Web Script Maintenance</shortname> <shortname>Web Script Maintenance</shortname>
<description>Maintain index of Web Scripts</description> <description>Maintain index of Web Scripts</description>
<url format="html" template="/index?reset={reset?}" /> <url>/index?reset={reset?}</url>
<url>/?reset={reset?}</url>
</webscript> </webscript>

View File

@@ -1,6 +1,6 @@
<webscript> <webscript>
<shortname>All Web Scripts Index</shortname> <shortname>All Web Scripts Index</shortname>
<description>Retrieve an index of all Web Scripts</description> <description>Retrieve an index of all Web Scripts</description>
<url format="html" template="/index/all" /> <url>/index/all</url>
<url format="mediawiki" template="/index/all.mediawiki" /> <url>/index/all.mediawiki</url>
</webscript> </webscript>

View File

@@ -27,7 +27,7 @@
<span class="mainSubTitle">${desc.shortName}</span> <span class="mainSubTitle">${desc.shortName}</span>
<table> <table>
<#list desc.URIs as uri> <#list desc.URIs as uri>
<tr><td><a href="${url.serviceContext}${uri.URI}">${desc.method} ${url.serviceContext}${uri.URI}</a> => ${uri.format}<#if uri.format = desc.defaultFormat> (default)</#if> <tr><td><a href="${url.serviceContext}${uri}">${desc.method} ${url.serviceContext}${uri}</a>
</#list> </#list>
<tr><td> <tr><td>
</table> </table>
@@ -36,6 +36,7 @@
<tr><td>Authentication:<td>${desc.requiredAuthentication} <tr><td>Authentication:<td>${desc.requiredAuthentication}
<tr><td>Transaction:<td>${desc.requiredTransaction} <tr><td>Transaction:<td>${desc.requiredTransaction}
<tr><td>Format Style:<td>${desc.formatStyle} <tr><td>Format Style:<td>${desc.formatStyle}
<tr><td>Default Format:<td>${desc.defaultFormat!"<i>Determined at run-time</i>"}
<tr><td> <tr><td>
<tr><td>Id:<td>${desc.id} <tr><td>Id:<td>${desc.id}
<tr><td>Description:<td><a href="${url.serviceContext}/description/${desc.id}">${desc.storePath}/${desc.descPath}</a> <tr><td>Description:<td><a href="${url.serviceContext}/description/${desc.id}">${desc.storePath}/${desc.descPath}</a>

View File

@@ -28,13 +28,14 @@ The following reference provides a list of all available Web Scripts organised b
<#if desc.description??><#if desc.description?ends_with(".")>${desc.description}<#else>${desc.description}.</#if><#else></#if> <#if desc.description??><#if desc.description?ends_with(".")>${desc.description}<#else>${desc.description}.</#if><#else></#if>
<#list desc.URIs as uri> <#list desc.URIs as uri>
[http://localhost:8080/${url.serviceContext}${uri.URI} ${desc.method} ${url.serviceContext}${uri.URI}] => ${uri.format}<#if uri.format = desc.defaultFormat> (default)</#if> [http://localhost:8080/${url.serviceContext}${uri} ${desc.method} ${url.serviceContext}${uri}]
</#list> </#list>
Requirements: Requirements:
* Authentication: ${desc.requiredAuthentication} * Authentication: ${desc.requiredAuthentication}
* Transaction: ${desc.requiredTransaction} * Transaction: ${desc.requiredTransaction}
* Format Style: ${desc.formatStyle} * Format Style: ${desc.formatStyle}
* Default Format: ${desc.defaultFormat!"<i>Determined at run-time</i>"}
Definition: Definition:
* Id: ${desc.id} * Id: ${desc.id}

View File

@@ -1,5 +1,5 @@
<webscript> <webscript>
<shortname>Web Script Package Index</shortname> <shortname>Web Script Package Index</shortname>
<description>Provide an index of Web Scripts for the specified Web Script package</description> <description>Provide an index of Web Scripts for the specified Web Script package</description>
<url format="html" template="/index/package/{package}" /> <url>/index/package/{package}</url>
</webscript> </webscript>

View File

@@ -41,7 +41,7 @@
<span class="mainSubTitle">${desc.shortName}</span> <span class="mainSubTitle">${desc.shortName}</span>
<table> <table>
<#list desc.URIs as uri> <#list desc.URIs as uri>
<tr><td><a href="${url.serviceContext}${uri.URI}">${desc.method} ${url.serviceContext}${uri.URI}</a> => ${uri.format}<#if uri.format = desc.defaultFormat> (default)</#if> <tr><td><a href="${url.serviceContext}${uri}">${desc.method} ${url.serviceContext}${uri}</a>
</#list> </#list>
<tr><td> <tr><td>
</table> </table>
@@ -50,6 +50,7 @@
<tr><td>Authentication:<td>${desc.requiredAuthentication} <tr><td>Authentication:<td>${desc.requiredAuthentication}
<tr><td>Transaction:<td>${desc.requiredTransaction} <tr><td>Transaction:<td>${desc.requiredTransaction}
<tr><td>Format Style:<td>${desc.formatStyle} <tr><td>Format Style:<td>${desc.formatStyle}
<tr><td>Default Format:<td>${desc.defaultFormat!"<i>Determined at run-time</i>"}
<tr><td> <tr><td>
<tr><td>Id:<td>${desc.id} <tr><td>Id:<td>${desc.id}
<tr><td>Description:<td><a href="${url.serviceContext}/description/${desc.id}">${desc.storePath}/${desc.descPath}</a> <tr><td>Description:<td><a href="${url.serviceContext}/description/${desc.id}">${desc.storePath}/${desc.descPath}</a>

View File

@@ -1,6 +1,6 @@
<webscript> <webscript>
<shortname>Web Script URI Index</shortname> <shortname>Web Script URI Index</shortname>
<description>Provide an index of Web Scripts for the specified Web Script URI</description> <description>Provide an index of Web Scripts for the specified Web Script URI</description>
<url format="html" template="/index/uri/{uri}" /> <url>/index/uri/{uri}</url>
<format>argument</format> <format>argument</format>
</webscript> </webscript>

View File

@@ -41,7 +41,7 @@
<span class="mainSubTitle">${desc.shortName}</span> <span class="mainSubTitle">${desc.shortName}</span>
<table> <table>
<#list desc.URIs as uri> <#list desc.URIs as uri>
<tr><td><a href="${url.serviceContext}${uri.URI}">${desc.method} ${url.serviceContext}${uri.URI}</a> => ${uri.format}<#if uri.format = desc.defaultFormat> (default)</#if> <tr><td><a href="${url.serviceContext}${uri}">${desc.method} ${url.serviceContext}${uri}</a>
</#list> </#list>
<tr><td> <tr><td>
</table> </table>
@@ -50,6 +50,7 @@
<tr><td>Authentication:<td>${desc.requiredAuthentication} <tr><td>Authentication:<td>${desc.requiredAuthentication}
<tr><td>Transaction:<td>${desc.requiredTransaction} <tr><td>Transaction:<td>${desc.requiredTransaction}
<tr><td>Format Style:<td>${desc.formatStyle} <tr><td>Format Style:<td>${desc.formatStyle}
<tr><td>Default Format:<td>${desc.defaultFormat!"<i>Determined at run-time</i>"}
<tr><td> <tr><td>
<tr><td>Id:<td>${desc.id} <tr><td>Id:<td>${desc.id}
<tr><td>Description:<td><a href="${url.serviceContext}/description/${desc.id}">${desc.storePath}/${desc.descPath}</a> <tr><td>Description:<td><a href="${url.serviceContext}/description/${desc.id}">${desc.storePath}/${desc.descPath}</a>

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>Document Actions (Office Add-In)</shortname> <shortname>Document Actions (Office Add-In)</shortname>
<description>Used by the Office Add-In to perform actions on managed documents</description> <description>Used by the Office Add-In to perform actions on managed documents</description>
<url format="html" template="/office/docActions" /> <url>/office/docActions</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>Document Details (Office Add-In)</shortname> <shortname>Document Details (Office Add-In)</shortname>
<description>Generate the Office Add-In Document Details page</description> <description>Generate the Office Add-In Document Details page</description>
<url format="html" template="/office/documentDetails?p={path?}" /> <url>/office/documentDetails?p={path?}</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>Get Users (Office Add-In)</shortname> <shortname>Get Users (Office Add-In)</shortname>
<description>Used by the Office Add-In to query for users</description> <description>Used by the Office Add-In to query for users</description>
<url format="html" template="/office/getUsers?s={searchTerm}" /> <url>/office/getUsers?s={searchTerm}</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>My Alfresco (Office Add-In)</shortname> <shortname>My Alfresco (Office Add-In)</shortname>
<description>Generate the Office Add-In My Alfresco page</description> <description>Generate the Office Add-In My Alfresco page</description>
<url format="html" template="/office/myAlfresco?p={path?}" /> <url>/office/myAlfresco?p={path?}</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>My Tasks (Office Add-In)</shortname> <shortname>My Tasks (Office Add-In)</shortname>
<description>Generate the Office Add-In My Tasks page</description> <description>Generate the Office Add-In My Tasks page</description>
<url format="html" template="/office/myTasks?p={path}" /> <url>/office/myTasks?p={path}</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>My Tasks Detail (Office Add-In)</shortname> <shortname>My Tasks Detail (Office Add-In)</shortname>
<description>Generate the Office Add-In Task Detail page</description> <description>Generate the Office Add-In Task Detail page</description>
<url format="html" template="/office/myTasksDetail?t={taskId}" /> <url>/office/myTasksDetail?t={taskId}</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>Navigation (Office Add-In)</shortname> <shortname>Navigation (Office Add-In)</shortname>
<description>Generate the Office Add-In Navigation page</description> <description>Generate the Office Add-In Navigation page</description>
<url format="html" template="/office/navigation?p={path?}" /> <url>/office/navigation?p={path?}</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>Search (Office Add-In)</shortname> <shortname>Search (Office Add-In)</shortname>
<description>Generate the Office Add-In Search page</description> <description>Generate the Office Add-In Search page</description>
<url format="html" template="/office/search?p={path?}" /> <url>/office/search?p={path?}</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>Search Results (Office Add-In)</shortname> <shortname>Search Results (Office Add-In)</shortname>
<description>Generate the Office Add-In Search Results page</description> <description>Generate the Office Add-In Search Results page</description>
<url format="html" template="/office/searchResults?search={searchString?}&amp;maxresults={maxresults?}" /> <url>/office/searchResults?search={searchString?}&amp;maxresults={maxresults?}</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>Document List</shortname> <shortname>Document List</shortname>
<description>Generate the Document list portlet page</description> <description>Generate the Document list portlet page</description>
<url format="html" template="/doclist?f={filter?}&amp;p={path?}&amp;q={query?}"/> <url>/doclist?f={filter?}&amp;p={path?}&amp;q={query?}</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>My Spaces</shortname> <shortname>My Spaces</shortname>
<description>Generate the My Spaces portlet page</description> <description>Generate the My Spaces portlet page</description>
<url format="html" template="/myspaces?f={filter?}&amp;p={path?}"/> <url>/myspaces?f={filter?}&amp;p={path?}</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>My Spaces Panel</shortname> <shortname>My Spaces Panel</shortname>
<description>Generate the inner panel for the My Spaces portlet page</description> <description>Generate the inner panel for the My Spaces portlet page</description>
<url format="html" template="/myspacespanel?f={filter}&amp;p={path}&amp;h={home}"/> <url>/myspacespanel?f={filter}&amp;p={path}&amp;h={home}</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>My Tasks</shortname> <shortname>My Tasks</shortname>
<description>Generate the My Tasks portlet page</description> <description>Generate the My Tasks portlet page</description>
<url format="html" template="/mytasks?f={filter?}"/> <url>/mytasks?f={filter?}</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>My Tasks Panel</shortname> <shortname>My Tasks Panel</shortname>
<description>Generate the Generate the inner panel for the My Tasks portlet page</description> <description>Generate the Generate the inner panel for the My Tasks portlet page</description>
<url format="html" template="/mytaskspanel?f={filter?}"/> <url>/mytaskspanel?f={filter?}</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>My Web Forms</shortname> <shortname>My Web Forms</shortname>
<description>Generate the My Web Forms portlet page</description> <description>Generate the My Web Forms portlet page</description>
<url format="html" template="/mywebforms"/> <url>/mywebforms</url>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,12 +1,12 @@
<webscript> <webscript>
<shortname>Alfresco Keyword Search (OpenSearch Enabled)</shortname> <shortname>Alfresco Keyword Search (OpenSearch Enabled)</shortname>
<description>Execute Keyword Search against Alfresco Repository (Company Home and below)</description> <description>Execute Keyword Search against Alfresco Repository (Company Home and below)</description>
<url format="html" template="/api/search/keyword.html?q={searchTerms}&amp;p={startPage?}&amp;c={count?}&amp;l={language?}&amp;guest={alf:guest?}"/> <url>/api/search/keyword.html?q={searchTerms}&amp;p={startPage?}&amp;c={count?}&amp;l={language?}</url>
<url format="html" template="/search/keyword.html?q={searchTerms}&amp;p={startPage?}&amp;c={count?}&amp;l={language?}&amp;guest={alf:guest?}"/> <url>/search/keyword.html?q={searchTerms}&amp;p={startPage?}&amp;c={count?}&amp;l={language?}</url>
<url format="atom" template="/api/search/keyword.atom?q={searchTerms}&amp;p={startPage?}&amp;c={count?}&amp;l={language?}&amp;guest={alf:guest?}"/> <url>/api/search/keyword.atom?q={searchTerms}&amp;p={startPage?}&amp;c={count?}&amp;l={language?}</url>
<url format="atom" template="/search/keyword.atom?q={searchTerms}&amp;p={startPage?}&amp;c={count?}&amp;l={language?}&amp;guest={alf:guest?}"/> <url>/search/keyword.atom?q={searchTerms}&amp;p={startPage?}&amp;c={count?}&amp;l={language?}</url>
<url format="rss" template="/api/search/keyword.rss?q={searchTerms}&amp;p={startPage?}&amp;c={count?}&amp;l={language?}&amp;guest={alf:guest?}"/> <url>/api/search/keyword.rss?q={searchTerms}&amp;p={startPage?}&amp;c={count?}&amp;l={language?}</url>
<url format="rss" template="/search/keyword.rss?q={searchTerms}&amp;p={startPage?}&amp;c={count?}&amp;l={language?}&amp;guest={alf:guest?}"/> <url>/search/keyword.rss?q={searchTerms}&amp;p={startPage?}&amp;c={count?}&amp;l={language?}</url>
<url format="portlet" template="/api/search/keyword.portlet?q={searchTerms}&amp;p={startPage?}&amp;c={count?}&amp;l={language?}&amp;guest={alf:guest?}"/> <url>/api/search/keyword.portlet?q={searchTerms}&amp;p={startPage?}&amp;c={count?}&amp;l={language?}</url>
<authentication>guest</authentication> <authentication>guest</authentication>
</webscript> </webscript>

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>Keyword Search Description</shortname> <shortname>Keyword Search Description</shortname>
<description>OpenSearch description document for Alfresco Repository keyword search</description> <description>OpenSearch description document for Alfresco Repository keyword search</description>
<url format="opensearchdescription" template="/api/search/keyword/description.xml" /> <url>/api/search/keyword/description.xml</url>
<url format="opensearchdescription" template="/search/keyword/description.xml" /> <url>/search/keyword/description.xml</url>
<format>argument</format> <format default="opensearchdescription">argument</format>
</webscript> </webscript>

View File

@@ -1,7 +1,8 @@
<webscript> <webscript>
<shortname>Login</shortname> <shortname>Login</shortname>
<description>Establish a ticket</description> <description>Establish a ticket</description>
<url format="xml" template="/api/login?u={username}&amp;pw={password?}"/> <url>/api/login?u={username}&amp;pw={password?}</url>
<format default="xml"/>
<authentication>none</authentication> <authentication>none</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,7 +1,8 @@
<webscript> <webscript>
<shortname>Delete Login Ticket</shortname> <shortname>Delete Login Ticket</shortname>
<description>Delete Login Ticket</description> <description>Delete Login Ticket</description>
<url format="xml" template="/api/login/ticket/{ticket}"/> <url>/api/login/ticket/{ticket}</url>
<format default="xml"/>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,7 +1,8 @@
<webscript> <webscript>
<shortname>Get Login Ticket</shortname> <shortname>Get Login Ticket</shortname>
<description>Get Login Ticket</description> <description>Get Login Ticket</description>
<url format="xml" template="/api/login/ticket/{ticket}"/> <url>/api/login/ticket/{ticket}</url>
<format default="xml"/>
<authentication>user</authentication> <authentication>user</authentication>
<transaction>required</transaction> <transaction>required</transaction>
</webscript> </webscript>

View File

@@ -1,8 +1,8 @@
<webscript> <webscript>
<shortname>Search Engines</shortname> <shortname>Search Engines</shortname>
<description>Lists "search engines" registered with this Alfresco Repository</description> <description>Lists "search engines" registered with this Alfresco Repository</description>
<url format="html" template="/api/search/engines?type={type?}" /> <url>/api/search/engines?type={type?}</url>
<url format="html" template="/search/engines?type={type?}" /> <url>/search/engines?type={type?}</url>
<url format="atom" template="/api/search/engines.atom?type={type?}" /> <url>/api/search/engines.atom?type={type?}</url>
<url format="atom" template="/search/engines.atom?type={type?}" /> <url>/search/engines.atom?type={type?}</url>
</webscript> </webscript>

View File

@@ -1,6 +1,7 @@
<webscript> <webscript>
<shortname>Proxied (OpenSearch) Search</shortname> <shortname>Proxied (OpenSearch) Search</shortname>
<description>Search engine proxy for issuing a search against a remote search engine</description> <description>Search engine proxy for issuing a search against a remote search engine</description>
<url template="/api/search/engine/{engine}/{format}"/> <url>/api/search/engine/{engine}/{format}</url>
<url template="/search/engine/{engine}/{format}"/> <url>/search/engine/{engine}/{format}</url>
<format default=""/>
</webscript> </webscript>

View File

@@ -1,6 +1,6 @@
<webscript> <webscript>
<shortname>Web Script Description</shortname> <shortname>Web Script Description</shortname>
<description>Retrieve description document for identified Web Script</description> <description>Retrieve description document for identified Web Script</description>
<url format="html" template="/description/{serviceId}" /> <url>/description/{serviceId}</url>
<format>argument</format> <format>argument</format>
</webscript> </webscript>

View File

@@ -27,5 +27,4 @@
${exception} ${exception}
${exception.stackTrace[0]} ${exception.stackTrace[0]}
</#if> </#if>
<tr><td><td>&nbsp;
</#macro> </#macro>

View File

@@ -43,7 +43,6 @@ import org.alfresco.util.AbstractLifecycleBean;
import org.alfresco.web.scripts.WebScriptDescription.FormatStyle; import org.alfresco.web.scripts.WebScriptDescription.FormatStyle;
import org.alfresco.web.scripts.WebScriptDescription.RequiredAuthentication; import org.alfresco.web.scripts.WebScriptDescription.RequiredAuthentication;
import org.alfresco.web.scripts.WebScriptDescription.RequiredTransaction; import org.alfresco.web.scripts.WebScriptDescription.RequiredTransaction;
import org.alfresco.web.scripts.WebScriptDescription.URI;
import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.Utils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@@ -150,11 +149,20 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
* @see org.alfresco.web.scripts.WebScriptRegistry#reset() * @see org.alfresco.web.scripts.WebScriptRegistry#reset()
*/ */
public void reset() public void reset()
{
long startTime = System.currentTimeMillis();
try
{ {
getTemplateProcessor().resetCache(); getTemplateProcessor().resetCache();
getScriptProcessor().resetCache(); getScriptProcessor().resetCache();
initWebScripts(); initWebScripts();
} }
finally
{
if (logger.isInfoEnabled())
logger.info("Registered " + webscriptsById.size() + " Web Scripts " + webscriptsByURL.size() + ", URLs (in " + (System.currentTimeMillis() - startTime) + "ms)");
}
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.util.AbstractLifecycleBean#onBootstrap(org.springframework.context.ApplicationEvent) * @see org.alfresco.util.AbstractLifecycleBean#onBootstrap(org.springframework.context.ApplicationEvent)
@@ -162,7 +170,7 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
@Override @Override
protected void onBootstrap(ApplicationEvent event) protected void onBootstrap(ApplicationEvent event)
{ {
initWebScripts(); reset();
} }
/* (non-Javadoc) /* (non-Javadoc)
@@ -178,7 +186,7 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
* *
* Note: Each invocation of this method resets the list of the services * Note: Each invocation of this method resets the list of the services
*/ */
public void initWebScripts() private void initWebScripts()
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("Initialising Web Scripts"); logger.debug("Initialising Web Scripts");
@@ -250,17 +258,16 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("Found Web Script " + id + " (desc: " + serviceDescPath + ", impl: " + serviceImplName + ", auth: " + logger.debug("Found Web Script " + id + " (desc: " + serviceDescPath + ", impl: " + serviceImplName + ", auth: " +
serviceDesc.getRequiredAuthentication() + ", trx: " + serviceDesc.getRequiredTransaction() + ", format: " + serviceDesc.getRequiredAuthentication() + ", trx: " + serviceDesc.getRequiredTransaction() + ", format style: " +
serviceDesc.getFormatStyle() + ")"); serviceDesc.getFormatStyle() + ", default format: " + serviceDesc.getDefaultFormat() + ")");
// register service and its urls // register service and its urls
webscriptsById.put(id, serviceImpl); webscriptsById.put(id, serviceImpl);
for (URI uri : serviceDesc.getURIs()) for (String uriTemplate : serviceDesc.getURIs())
{ {
// establish static part of url template // establish static part of url template
boolean wildcard = false; boolean wildcard = false;
boolean extension = true; boolean extension = true;
String uriTemplate = uri.getURI();
int queryArgIdx = uriTemplate.indexOf('?'); int queryArgIdx = uriTemplate.indexOf('?');
if (queryArgIdx != -1) if (queryArgIdx != -1)
{ {
@@ -309,9 +316,6 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
registerURIs(serviceImpl); registerURIs(serviceImpl);
} }
} }
if (logger.isDebugEnabled())
logger.debug("Registered " + webscriptsById.size() + " Web Scripts; " + webscriptsByURL.size() + " URLs");
} }
/** /**
@@ -347,10 +351,10 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
private void registerURIs(WebScript script) private void registerURIs(WebScript script)
{ {
WebScriptDescription desc = script.getDescription(); WebScriptDescription desc = script.getDescription();
for (URI uri : desc.getURIs()) for (String uri : desc.getURIs())
{ {
Path path = uriByPath.get("/"); Path path = uriByPath.get("/");
String[] parts = uri.getURI().split("/"); String[] parts = uri.split("/");
for (String part : parts) for (String part : parts)
{ {
if (part.indexOf("?") != -1) if (part.indexOf("?") != -1)
@@ -429,32 +433,25 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
{ {
throw new WebScriptException("Expected at least one <url> element"); throw new WebScriptException("Expected at least one <url> element");
} }
List<WebScriptDescription.URI> uris = new ArrayList<WebScriptDescription.URI>(); List<String> uris = new ArrayList<String>();
Iterator iterElements = urlElements.iterator(); Iterator iterElements = urlElements.iterator();
while(iterElements.hasNext()) while(iterElements.hasNext())
{ {
// retrieve url element // retrieve url element
Element urlElement = (Element)iterElements.next(); Element urlElement = (Element)iterElements.next();
// retrieve url mimetype
String format = urlElement.attributeValue("format");
if (format == null)
{
// default to unspecified format
format = "";
}
// retrieve url template // retrieve url template
String template = urlElement.attributeValue("template"); String template = urlElement.getTextTrim();
if (template == null || template.length() == 0) if (template == null || template.length() == 0)
{ {
throw new WebScriptException("Expected template attribute on <url> element"); // NOTE: for backwards compatibility only
template = urlElement.attributeValue("template");
if (template == null || template.length() == 0)
{
throw new WebScriptException("Expected <url> element value");
} }
}
WebScriptDescriptionImpl.URIImpl uriImpl = new WebScriptDescriptionImpl.URIImpl(); uris.add(template);
uriImpl.setFormat(format);
uriImpl.setUri(template);
uris.add(uriImpl);
} }
// retrieve authentication // retrieve authentication
@@ -492,11 +489,18 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
} }
// retrieve format // retrieve format
String defaultFormat = uris.get(0).getFormat(); String defaultFormat = "html";
FormatStyle formatStyle = FormatStyle.any; FormatStyle formatStyle = FormatStyle.any;
Element formatElement = rootElement.element("format"); Element formatElement = rootElement.element("format");
if (formatElement != null) if (formatElement != null)
{ {
// establish if default is set explicitly
String attrDefaultValue = formatElement.attributeValue("default");
if (attrDefaultValue != null)
{
defaultFormat = (attrDefaultValue.length() == 0) ? null : attrDefaultValue;
}
// establish format declaration style
String formatStyleStr = formatElement.getTextTrim(); String formatStyleStr = formatElement.getTextTrim();
if (formatStyleStr != null && formatStyleStr.length() > 0) if (formatStyleStr != null && formatStyleStr.length() > 0)
{ {
@@ -506,11 +510,6 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
throw new WebScriptException("Format Style '" + formatStyle + "' is not a valid value"); 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 // construct service description
@@ -524,7 +523,7 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
serviceDesc.setRequiredAuthentication(reqAuth); serviceDesc.setRequiredAuthentication(reqAuth);
serviceDesc.setRequiredTransaction(reqTrx); serviceDesc.setRequiredTransaction(reqTrx);
serviceDesc.setMethod(method); serviceDesc.setMethod(method);
serviceDesc.setUris(uris.toArray(new WebScriptDescription.URI[uris.size()])); serviceDesc.setUris(uris.toArray(new String[uris.size()]));
serviceDesc.setDefaultFormat(defaultFormat); serviceDesc.setDefaultFormat(defaultFormat);
serviceDesc.setFormatStyle(formatStyle); serviceDesc.setFormatStyle(formatStyle);
return serviceDesc; return serviceDesc;

View File

@@ -140,7 +140,7 @@ public interface WebScriptDescription
* *
* @return array of URIs in order specified in service description document * @return array of URIs in order specified in service description document
*/ */
public URI[] getURIs(); public String[] getURIs();
/** /**
* Gets the style of Format discriminator supported by this web script * Gets the style of Format discriminator supported by this web script
@@ -149,45 +149,14 @@ public interface WebScriptDescription
*/ */
public FormatStyle getFormatStyle(); public FormatStyle getFormatStyle();
/**
* Gets a URI by format
*
* @param format the format
* @return the URI (or null, if no URI registered for the format)
*/
public URI getURI(String format);
/** /**
* Gets the default response format * Gets the default response format
* *
* Note: the default response format is the first listed in the service * Note: the default response format is the first listed in the service
* description document * description document
* *
* @return default response format * @return default response format (or null, if format not known until run-time)
*/ */
public String getDefaultFormat(); public String getDefaultFormat();
/**
* Web Script URL
*
* @author davidc
*/
public interface URI
{
/**
* Gets the URI response format
*
* @return format
*/
public String getFormat();
/**
* Gets the URI
*
* @return uri
*/
public String getURI();
}
} }

View File

@@ -26,8 +26,6 @@ package org.alfresco.web.scripts;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
/** /**
@@ -47,9 +45,8 @@ public class WebScriptDescriptionImpl implements WebScriptDescription
private RequiredTransaction requiredTransaction; private RequiredTransaction requiredTransaction;
private FormatStyle formatStyle; private FormatStyle formatStyle;
private String httpMethod; private String httpMethod;
private URI[] uris; private String[] uris;
private String defaultFormat; private String defaultFormat;
private Map<String, URI> uriByFormat;
/** /**
@@ -246,32 +243,19 @@ public class WebScriptDescriptionImpl implements WebScriptDescription
* *
* @param uris * @param uris
*/ */
public void setUris(URI[] uris) public void setUris(String[] uris)
{ {
this.uriByFormat = new HashMap<String, URI>(uris.length);
for (URI uri : uris)
{
this.uriByFormat.put(uri.getFormat(), uri);
}
this.uris = uris; this.uris = uris;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptDescription#getURIs() * @see org.alfresco.web.scripts.WebScriptDescription#getURIs()
*/ */
public URI[] getURIs() public String[] getURIs()
{ {
return this.uris; return this.uris;
} }
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptDescription#getURI(java.lang.String)
*/
public URI getURI(String format)
{
return this.uriByFormat.get(format);
}
/** /**
* Sets the default response format * Sets the default response format
* *
@@ -290,52 +274,4 @@ public class WebScriptDescriptionImpl implements WebScriptDescription
return this.defaultFormat; return this.defaultFormat;
} }
/**
* Web Script URL Implementation
*
* @author davidc
*/
public static class URIImpl implements WebScriptDescription.URI
{
private String format;
private String uri;
/**
* Sets the URI response format
*
* @param format
*/
public void setFormat(String format)
{
this.format = format;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptDescription.URI#getFormat()
*/
public String getFormat()
{
return this.format;
}
/**
* Sets the URI
*
* @param uri
*/
public void setUri(String uri)
{
this.uri = uri;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptDescription.URI#getURI()
*/
public String getURI()
{
return this.uri;
}
}
} }