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>Transaction:<td>${desc.requiredTransaction}
<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>Description:<td><a href="${url.serviceContext}/description/${desc.id}">${desc.storePath}/${desc.descPath}</a>
</table>
<br>
</#list>

View File

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

View File

@@ -106,7 +106,7 @@
<prop key="rss">application/rss+xml</prop>
<prop key="json">application/json</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>
</props>
</property>
@@ -165,27 +165,27 @@
<!-- -->
<!-- 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 -->
<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 -->
<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 -->
<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="searchProxy" ref="webscript.org.alfresco.repository.searchproxy_get" />
<property name="searchProxy" ref="webscript.org.alfresco.repository.searchproxy.get" />
</bean>
<!-- 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" />
</bean>
<!-- 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="formatRegistry" ref="webscripts.formatregistry" />
</bean>

View File

@@ -96,7 +96,7 @@ public class ClassPathStore implements WebScriptStore, InitializingBean
{
int filePathLength = fileDir.getAbsolutePath().length() +1;
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)
{
if (resource instanceof FileSystemResource)

View File

@@ -53,7 +53,7 @@ public class DeclarativeWebScript extends AbstractWebScript
// Logger
private static final Log logger = LogFactory.getLog(DeclarativeWebScript.class);
private String baseTemplatePath;
private String basePath;
private ScriptLocation executeScript;
@@ -64,10 +64,10 @@ public class DeclarativeWebScript extends AbstractWebScript
public void init(WebScriptRegistry apiRegistry)
{
super.init(apiRegistry);
baseTemplatePath = getDescription().getId().replace('.', '/');
basePath = getDescription().getId();
// Test for "execute" script
String scriptPath = baseTemplatePath + ".js";
String scriptPath = basePath + ".js";
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)
{
format = (format == null) ? "" : format;
String templatePath = baseTemplatePath + "_" + format + ".ftl";
String templatePath = basePath + "." + format + ".ftl";
if (logger.isDebugEnabled())
logger.debug("Rendering template '" + templatePath + "'");

View File

@@ -222,8 +222,8 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
{
WebScript existingService = webscriptsById.get(id);
WebScriptDescription existingDesc = existingService.getDescription();
String msg = "Web Script description document " + serviceDesc.getSourceStore() + "/" + serviceDesc.getSourceLocation();
msg += " overridden by " + existingDesc.getSourceStore() + "/" + existingDesc.getSourceLocation();
String msg = "Web Script description document " + serviceDesc.getStorePath() + "/" + serviceDesc.getDescPath();
msg += " overridden by " + existingDesc.getStorePath() + "/" + existingDesc.getDescPath();
logger.debug(msg);
}
continue;
@@ -231,13 +231,14 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
// construct service implementation
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);
serviceImpl.setDescription(serviceDesc);
serviceImpl.init(this);
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
webscriptsById.put(id, serviceImpl);
@@ -263,7 +264,7 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
WebScript existingService = webscriptsByURL.get(uriIdx);
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);
}
}
@@ -303,16 +304,19 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
throw new WebScriptException("Expected <webscript> root element - found <" + rootElement.getName() + ">");
}
// retrieve id
String id = serviceDescPath.substring(0, serviceDescPath.lastIndexOf("_desc.xml")).replace('/', '.');
// retrieve script path
String scriptPath = serviceDescPath.substring(0, serviceDescPath.lastIndexOf('/'));
// retrieve script id
String id = serviceDescPath.substring(0, serviceDescPath.lastIndexOf(".desc.xml"));
// retrieve http method
int methodIdx = id.lastIndexOf('_');
int methodIdx = id.lastIndexOf('.');
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
Element shortNameElement = rootElement.element("shortname");
@@ -400,8 +404,9 @@ public class DeclarativeWebScriptRegistry extends AbstractLifecycleBean
// construct service description
WebScriptDescriptionImpl serviceDesc = new WebScriptDescriptionImpl();
serviceDesc.setSourceStore(store);
serviceDesc.setSourceLocation(serviceDescPath);
serviceDesc.setStore(store);
serviceDesc.setScriptPath(scriptPath);
serviceDesc.setDescPath(serviceDescPath);
serviceDesc.setId(id);
serviceDesc.setShortName(shortName);
serviceDesc.setDescription(description);

View File

@@ -268,15 +268,18 @@ public class RepoStore implements WebScriptStore, ApplicationContextAware, Appli
int baseDirLength = baseDir.length() +1;
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);
List<NodeRef> nodes = resultSet.getNodeRefs();
for (NodeRef nodeRef : nodes)
{
String nodeDir = getPath(nodeRef);
if (nodeDir.endsWith(".desc.xml"))
{
String documentPath = nodeDir.substring(baseDirLength);
documentPaths.add(documentPath);
}
}
return documentPaths.toArray(new String[documentPaths.size()]);
}

View File

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

View File

@@ -57,26 +57,33 @@ public interface WebScriptDescription
/**
* 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()
throws IOException;
public String getStorePath();
/**
* 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)
*/
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

View File

@@ -37,8 +37,9 @@ import java.util.Map;
*/
public class WebScriptDescriptionImpl implements WebScriptDescription
{
private WebScriptStore sourceStore;
private String sourceLocation;
private WebScriptStore store;
private String scriptPath;
private String descPath;
private String id;
private String shortName;
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)
* @see org.alfresco.web.scripts.WebScriptDescription#getSourceDocument()
* @see org.alfresco.web.scripts.WebScriptDescription#getStorePath()
*/
public InputStream getSourceDocument()
throws IOException
public String getStorePath()
{
return this.sourceStore.getDescriptionDocument(sourceLocation);
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptDescription#getSourceStore()
*/
public String getSourceStore()
{
return this.sourceStore.getBasePath();
return store.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)
* @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
{
// extract web script id
String extensionPath = req.getExtensionPath();
if (extensionPath == null || extensionPath.length() == 0)
String scriptId = req.getExtensionPath();
if (scriptId == null || scriptId.length() == 0)
{
throw new WebScriptException("Web Script Id not provided");
}
String scriptId = extensionPath.replace("/", ".");
// locate web script
WebScript script = getWebScriptRegistry().getWebScript(scriptId);
@@ -67,7 +66,7 @@ public class ServiceDescription extends AbstractWebScript
InputStream serviceDescIS = null;
try
{
serviceDescIS = desc.getSourceDocument();
serviceDescIS = desc.getDescDocument();
OutputStream out = res.getOutputStream();
res.setContentType(MimetypeMap.MIMETYPE_XML + ";charset=UTF-8");
byte[] buffer = new byte[2048];

View File

@@ -268,7 +268,7 @@ public class UIOpenSearch extends SelfRenderingComponent
ConfigService cfgSvc = (ConfigService)FacesContextUtils.
getRequiredWebApplicationContext(context).getBean("webscripts.config");
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)
{
// get the OpenSearch configuration