Web Scripts:

- filename convention changed from _ to .

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5793 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2007-05-29 09:32:04 +00:00
parent c3b15747fa
commit 3e0cee8351
50 changed files with 105 additions and 75 deletions

View File

@@ -33,9 +33,8 @@
<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> <tr><td>
<tr><td>Store:<td>${desc.sourceStore}
<tr><td>Location:<td><a href="${url.serviceContext}/description/${desc.id?replace(".", "/")}">${desc.sourceLocation}</a>
<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>
</table> </table>
<br> <br>
</#list> </#list>

View File

@@ -31,8 +31,7 @@ Requirements:
* Transaction: ${desc.requiredTransaction} * Transaction: ${desc.requiredTransaction}
Definition: Definition:
* Store: ${desc.sourceStore}
* Location: ${desc.sourceLocation}
* Id: ${desc.id} * Id: ${desc.id}
* Store: ${desc.storePath}/${desc.descPath}
</#list> </#list>

View File

@@ -106,7 +106,7 @@
<prop key="rss">application/rss+xml</prop> <prop key="rss">application/rss+xml</prop>
<prop key="json">application/json</prop> <prop key="json">application/json</prop>
<prop key="opensearchdescription">application/opensearchdescription+xml</prop> <prop key="opensearchdescription">application/opensearchdescription+xml</prop>
<prop key="wiki">text/plain</prop> <prop key="mediawiki">text/plain</prop>
<prop key="portlet">text/html</prop> <prop key="portlet">text/html</prop>
</props> </props>
</property> </property>
@@ -165,27 +165,27 @@
<!-- --> <!-- -->
<!-- List of available Web APIs --> <!-- List of available Web APIs -->
<bean id="webscript.org.alfresco.index_get" class="org.alfresco.web.scripts.bean.Index" parent="webscript" /> <bean id="webscript.org.alfresco.index.get" class="org.alfresco.web.scripts.bean.Index" parent="webscript" />
<!-- Maintain list of available Web APIs --> <!-- Maintain list of available Web APIs -->
<bean id="webscript.org.alfresco.index_post" class="org.alfresco.web.scripts.bean.IndexUpdate" parent="webscript" /> <bean id="webscript.org.alfresco.index.post" class="org.alfresco.web.scripts.bean.IndexUpdate" parent="webscript" />
<!-- Retrieve Web Script Description Document --> <!-- Retrieve Web Script Description Document -->
<bean id="webscript.org.alfresco.scriptdescription_get" class="org.alfresco.web.scripts.bean.ServiceDescription" parent="webscript" /> <bean id="webscript.org.alfresco.scriptdescription.get" class="org.alfresco.web.scripts.bean.ServiceDescription" parent="webscript" />
<!-- List of registered (OpenSearch) search engines --> <!-- List of registered (OpenSearch) search engines -->
<bean id="webscript.org.alfresco.repository.searchengines_get" class="org.alfresco.web.scripts.bean.SearchEngines" parent="webscript"> <bean id="webscript.org.alfresco.repository.searchengines.get" class="org.alfresco.web.scripts.bean.SearchEngines" parent="webscript">
<property name="configService" ref="webscripts.config" /> <property name="configService" ref="webscripts.config" />
<property name="searchProxy" ref="webscript.org.alfresco.repository.searchproxy_get" /> <property name="searchProxy" ref="webscript.org.alfresco.repository.searchproxy.get" />
</bean> </bean>
<!-- Alfresco Web Client Keyword Search (OpenSearch) --> <!-- Alfresco Web Client Keyword Search (OpenSearch) -->
<bean id="webscript.org.alfresco.repository.keywordsearch_get" class="org.alfresco.web.scripts.bean.KeywordSearch" parent="webscript"> <bean id="webscript.org.alfresco.repository.keywordsearch.get" class="org.alfresco.web.scripts.bean.KeywordSearch" parent="webscript">
<property name="searchService" ref="SearchService" /> <property name="searchService" ref="SearchService" />
</bean> </bean>
<!-- Alfresco (OpenSearch) Proxy --> <!-- Alfresco (OpenSearch) Proxy -->
<bean id="webscript.org.alfresco.repository.searchproxy_get" class="org.alfresco.web.scripts.bean.SearchProxy" parent="webscript"> <bean id="webscript.org.alfresco.repository.searchproxy.get" class="org.alfresco.web.scripts.bean.SearchProxy" parent="webscript">
<property name="configService" ref="webscripts.config" /> <property name="configService" ref="webscripts.config" />
<property name="formatRegistry" ref="webscripts.formatregistry" /> <property name="formatRegistry" ref="webscripts.formatregistry" />
</bean> </bean>

View File

@@ -96,7 +96,7 @@ public class ClassPathStore implements WebScriptStore, InitializingBean
{ {
int filePathLength = fileDir.getAbsolutePath().length() +1; int filePathLength = fileDir.getAbsolutePath().length() +1;
List<String> documentPaths = new ArrayList<String>(); List<String> documentPaths = new ArrayList<String>();
Resource[] resources = resolver.getResources("classpath*:" + classPath + "/**/*_desc.xml"); Resource[] resources = resolver.getResources("classpath*:" + classPath + "/**/*.desc.xml");
for (Resource resource : resources) for (Resource resource : resources)
{ {
if (resource instanceof FileSystemResource) if (resource instanceof FileSystemResource)

View File

@@ -53,7 +53,7 @@ public class DeclarativeWebScript extends AbstractWebScript
// Logger // Logger
private static final Log logger = LogFactory.getLog(DeclarativeWebScript.class); private static final Log logger = LogFactory.getLog(DeclarativeWebScript.class);
private String baseTemplatePath; private String basePath;
private ScriptLocation executeScript; private ScriptLocation executeScript;
@@ -64,10 +64,10 @@ public class DeclarativeWebScript extends AbstractWebScript
public void init(WebScriptRegistry apiRegistry) public void init(WebScriptRegistry apiRegistry)
{ {
super.init(apiRegistry); super.init(apiRegistry);
baseTemplatePath = getDescription().getId().replace('.', '/'); basePath = getDescription().getId();
// Test for "execute" script // Test for "execute" script
String scriptPath = baseTemplatePath + ".js"; String scriptPath = basePath + ".js";
executeScript = getWebScriptRegistry().getScriptProcessor().findScript(scriptPath); executeScript = getWebScriptRegistry().getScriptProcessor().findScript(scriptPath);
} }
@@ -210,7 +210,7 @@ public class DeclarativeWebScript extends AbstractWebScript
final protected void renderFormatTemplate(String format, Map<String, Object> model, Writer writer) final protected void renderFormatTemplate(String format, Map<String, Object> model, Writer writer)
{ {
format = (format == null) ? "" : format; format = (format == null) ? "" : format;
String templatePath = baseTemplatePath + "_" + format + ".ftl"; String templatePath = basePath + "." + format + ".ftl";
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("Rendering template '" + templatePath + "'"); logger.debug("Rendering template '" + templatePath + "'");

View File

@@ -222,8 +222,8 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
{ {
WebScript existingService = webscriptsById.get(id); WebScript existingService = webscriptsById.get(id);
WebScriptDescription existingDesc = existingService.getDescription(); WebScriptDescription existingDesc = existingService.getDescription();
String msg = "Web Script description document " + serviceDesc.getSourceStore() + "/" + serviceDesc.getSourceLocation(); String msg = "Web Script description document " + serviceDesc.getStorePath() + "/" + serviceDesc.getDescPath();
msg += " overridden by " + existingDesc.getSourceStore() + "/" + existingDesc.getSourceLocation(); msg += " overridden by " + existingDesc.getStorePath() + "/" + existingDesc.getDescPath();
logger.debug(msg); logger.debug(msg);
} }
continue; continue;
@@ -231,13 +231,14 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
// construct service implementation // construct service implementation
ApplicationContext applicationContext = getApplicationContext(); ApplicationContext applicationContext = getApplicationContext();
String serviceImplName = (applicationContext.containsBean("webscript." + id)) ? "webscript." + id : defaultWebScript; String beanName = "webscript." + id.replace('/', '.');
String serviceImplName = (applicationContext.containsBean(beanName)) ? beanName : defaultWebScript;
AbstractWebScript serviceImpl = (AbstractWebScript)applicationContext.getBean(serviceImplName); AbstractWebScript serviceImpl = (AbstractWebScript)applicationContext.getBean(serviceImplName);
serviceImpl.setDescription(serviceDesc); serviceImpl.setDescription(serviceDesc);
serviceImpl.init(this); serviceImpl.init(this);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("Found Web Script " + serviceDescPath + " (id: " + id + ", impl: " + serviceImplName + ", auth: " + serviceDesc.getRequiredAuthentication() + ", trx: " + serviceDesc.getRequiredTransaction() + ")"); logger.debug("Found Web Script " + id + " (desc: " + serviceDescPath + ", impl: " + serviceImplName + ", auth: " + serviceDesc.getRequiredAuthentication() + ", trx: " + serviceDesc.getRequiredTransaction() + ")");
// register service and its urls // register service and its urls
webscriptsById.put(id, serviceImpl); webscriptsById.put(id, serviceImpl);
@@ -263,7 +264,7 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
WebScript existingService = webscriptsByURL.get(uriIdx); WebScript existingService = webscriptsByURL.get(uriIdx);
if (!existingService.getDescription().getId().equals(serviceDesc.getId())) if (!existingService.getDescription().getId().equals(serviceDesc.getId()))
{ {
String msg = "Web Script document " + serviceDesc.getSourceLocation() + " is attempting to define the url '" + uriIdx + "' already defined by " + existingService.getDescription().getSourceLocation(); String msg = "Web Script document " + serviceDesc.getDescPath() + " is attempting to define the url '" + uriIdx + "' already defined by " + existingService.getDescription().getDescPath();
throw new WebScriptException(msg); throw new WebScriptException(msg);
} }
} }
@@ -303,16 +304,19 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
throw new WebScriptException("Expected <webscript> root element - found <" + rootElement.getName() + ">"); throw new WebScriptException("Expected <webscript> root element - found <" + rootElement.getName() + ">");
} }
// retrieve id // retrieve script path
String id = serviceDescPath.substring(0, serviceDescPath.lastIndexOf("_desc.xml")).replace('/', '.'); String scriptPath = serviceDescPath.substring(0, serviceDescPath.lastIndexOf('/'));
// retrieve script id
String id = serviceDescPath.substring(0, serviceDescPath.lastIndexOf(".desc.xml"));
// retrieve http method // retrieve http method
int methodIdx = id.lastIndexOf('_'); int methodIdx = id.lastIndexOf('.');
if (methodIdx == id.length() - 1) if (methodIdx == id.length() - 1)
{ {
throw new WebScriptException("Unable to establish HTTP Method from web script description: naming convention must be <name>_<method>_desc.xml"); throw new WebScriptException("Unable to establish HTTP Method from web script description: naming convention must be <name>.<method>.desc.xml");
} }
String method = id.substring(id.lastIndexOf('_') + 1).toUpperCase(); String method = id.substring(id.lastIndexOf('.') + 1).toUpperCase();
// retrieve short name // retrieve short name
Element shortNameElement = rootElement.element("shortname"); Element shortNameElement = rootElement.element("shortname");
@@ -400,8 +404,9 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
// construct service description // construct service description
WebScriptDescriptionImpl serviceDesc = new WebScriptDescriptionImpl(); WebScriptDescriptionImpl serviceDesc = new WebScriptDescriptionImpl();
serviceDesc.setSourceStore(store); serviceDesc.setStore(store);
serviceDesc.setSourceLocation(serviceDescPath); serviceDesc.setScriptPath(scriptPath);
serviceDesc.setDescPath(serviceDescPath);
serviceDesc.setId(id); serviceDesc.setId(id);
serviceDesc.setShortName(shortName); serviceDesc.setShortName(shortName);
serviceDesc.setDescription(description); serviceDesc.setDescription(description);

View File

@@ -268,14 +268,17 @@ public class RepoStore implements WebScriptStore, ApplicationContextAware, Appli
int baseDirLength = baseDir.length() +1; int baseDirLength = baseDir.length() +1;
List<String> documentPaths = new ArrayList<String>(); List<String> documentPaths = new ArrayList<String>();
String query = "PATH:\"" + repoPath + "//*\" AND @cm\\:name:\"*_desc.xml\""; String query = "PATH:\"" + repoPath + "//*\" AND @cm\\:name:\"*desc.xml\"";
ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query); ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query);
List<NodeRef> nodes = resultSet.getNodeRefs(); List<NodeRef> nodes = resultSet.getNodeRefs();
for (NodeRef nodeRef : nodes) for (NodeRef nodeRef : nodes)
{ {
String nodeDir = getPath(nodeRef); String nodeDir = getPath(nodeRef);
String documentPath = nodeDir.substring(baseDirLength); if (nodeDir.endsWith(".desc.xml"))
documentPaths.add(documentPath); {
String documentPath = nodeDir.substring(baseDirLength);
documentPaths.add(documentPath);
}
} }
return documentPaths.toArray(new String[documentPaths.size()]); return documentPaths.toArray(new String[documentPaths.size()]);

View File

@@ -126,7 +126,6 @@ public class TestWebScriptServer
*/ */
public void init() public void init()
{ {
registry.initWebScripts();
Config config = configService.getConfig("Server"); Config config = configService.getConfig("Server");
serverConfig = (ServerConfigElement)config.getConfigElement(ServerConfigElement.CONFIG_ELEMENT_ID); serverConfig = (ServerConfigElement)config.getConfigElement(ServerConfigElement.CONFIG_ELEMENT_ID);
} }

View File

@@ -54,29 +54,36 @@ public interface WebScriptDescription
required, required,
requiresnew requiresnew
} }
/** /**
* Gets the source document of this web script * Gets the root path of the store of this web script
* *
* @return source document * @return root path of store
*/ */
public InputStream getSourceDocument() public String getStorePath();
throws IOException;
/** /**
* Gets the store this web script is located in * Gets the path within the store of this web script
* *
* @return path to store * @return path within store
*/ */
public String getSourceStore(); public String getScriptPath();
/** /**
* Gets the source document location of this service description * Gets the path of the description xml document for this web script
* *
* @return document location (path) * @return document location (path)
*/ */
public String getSourceLocation(); public String getDescPath();
/**
* Gets the description xml document for this web script
*
* @return source document
*/
public InputStream getDescDocument()
throws IOException;
/** /**
* Gets the id of this service * Gets the id of this service

View File

@@ -37,8 +37,9 @@ import java.util.Map;
*/ */
public class WebScriptDescriptionImpl implements WebScriptDescription public class WebScriptDescriptionImpl implements WebScriptDescription
{ {
private WebScriptStore sourceStore; private WebScriptStore store;
private String sourceLocation; private String scriptPath;
private String descPath;
private String id; private String id;
private String shortName; private String shortName;
private String description; private String description;
@@ -51,48 +52,66 @@ public class WebScriptDescriptionImpl implements WebScriptDescription
/** /**
* Sets the source store * Sets the web description store
* *
* @param store source store * @param store store
*/ */
public void setSourceStore(WebScriptStore store) public void setStore(WebScriptStore store)
{ {
this.sourceStore = store; this.store = store;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptDescription#getSourceDocument() * @see org.alfresco.web.scripts.WebScriptDescription#getStorePath()
*/ */
public InputStream getSourceDocument() public String getStorePath()
throws IOException
{ {
return this.sourceStore.getDescriptionDocument(sourceLocation); return store.getBasePath();
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptDescription#getSourceStore()
*/
public String getSourceStore()
{
return this.sourceStore.getBasePath();
} }
/** /**
* Sets the source location * Sets the script path
* *
* @param sourceLocation * @param scriptPath
*/ */
public void setSourceLocation(String sourceLocation) public void setScriptPath(String scriptPath)
{ {
this.sourceLocation = sourceLocation; this.scriptPath = scriptPath;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptDescription#getSourceLocation() * @see org.alfresco.web.scripts.WebScriptDescription#getScriptPath()
*/ */
public String getSourceLocation() public String getScriptPath()
{ {
return this.sourceLocation; return scriptPath;
}
/**
* Sets the desc path
*
* @param descPath
*/
public void setDescPath(String descPath)
{
this.descPath = descPath;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptDescription#getDescPath()
*/
public String getDescPath()
{
return descPath;
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptDescription#getDescDocument()
*/
public InputStream getDescDocument()
throws IOException
{
return store.getDescriptionDocument(descPath);
} }
/** /**

View File

@@ -48,12 +48,11 @@ public class ServiceDescription extends AbstractWebScript
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
{ {
// extract web script id // extract web script id
String extensionPath = req.getExtensionPath(); String scriptId = req.getExtensionPath();
if (extensionPath == null || extensionPath.length() == 0) if (scriptId == null || scriptId.length() == 0)
{ {
throw new WebScriptException("Web Script Id not provided"); throw new WebScriptException("Web Script Id not provided");
} }
String scriptId = extensionPath.replace("/", ".");
// locate web script // locate web script
WebScript script = getWebScriptRegistry().getWebScript(scriptId); WebScript script = getWebScriptRegistry().getWebScript(scriptId);
@@ -67,7 +66,7 @@ public class ServiceDescription extends AbstractWebScript
InputStream serviceDescIS = null; InputStream serviceDescIS = null;
try try
{ {
serviceDescIS = desc.getSourceDocument(); serviceDescIS = desc.getDescDocument();
OutputStream out = res.getOutputStream(); OutputStream out = res.getOutputStream();
res.setContentType(MimetypeMap.MIMETYPE_XML + ";charset=UTF-8"); res.setContentType(MimetypeMap.MIMETYPE_XML + ";charset=UTF-8");
byte[] buffer = new byte[2048]; byte[] buffer = new byte[2048];

View File

@@ -268,7 +268,7 @@ public class UIOpenSearch extends SelfRenderingComponent
ConfigService cfgSvc = (ConfigService)FacesContextUtils. ConfigService cfgSvc = (ConfigService)FacesContextUtils.
getRequiredWebApplicationContext(context).getBean("webscripts.config"); getRequiredWebApplicationContext(context).getBean("webscripts.config");
SearchProxy searchProxy = (SearchProxy)FacesContextUtils. SearchProxy searchProxy = (SearchProxy)FacesContextUtils.
getRequiredWebApplicationContext(context).getBean("webscript.org.alfresco.repository.searchproxy_get"); getRequiredWebApplicationContext(context).getBean("webscript.org.alfresco.repository.searchproxy.get");
if (cfgSvc != null) if (cfgSvc != null)
{ {
// get the OpenSearch configuration // get the OpenSearch configuration