diff --git a/config/alfresco/templates/web/api/org/alfresco/repository/keywordsearch_get_atom.ftl b/config/alfresco/templates/web/api/org/alfresco/repository/keywordsearch_get_atom.ftl
index 41dd75c3db..81c4bf313a 100644
--- a/config/alfresco/templates/web/api/org/alfresco/repository/keywordsearch_get_atom.ftl
+++ b/config/alfresco/templates/web/api/org/alfresco/repository/keywordsearch_get_atom.ftl
@@ -3,7 +3,7 @@
Alfresco (${server.edition})
Alfresco Keyword Search: ${search.searchTerms}
${xmldate(date)}
- ${absurl("/images/logo/AlfrescoLogo16.ico")}
+ ${absurl(url.context)}/images/logo/AlfrescoLogo16.ico
<#if person??>${person.properties.userName}<#else>unknown#if>
@@ -12,22 +12,22 @@
${search.startIndex}
${search.itemsPerPage}
-
-
+
+
<#if search.startPage > 1>
-
-
+
+
#if>
<#if search.startPage < search.totalPages>
-
-
+
+
#if>
-
+
<#list search.results as row>
${row.name}
-
- ${absurl(row.icon16)} <#comment>TODO: What's the standard for entry icons?#comment>
+
+ ${absurl(url.context)}${row.icon16} <#comment>TODO: What's the standard for entry icons?#comment>
urn:uuid:${row.id}
${xmldate(row.properties.modified)}
${row.properties.description!""}
diff --git a/config/alfresco/templates/web/api/org/alfresco/repository/keywordsearch_get_html.ftl b/config/alfresco/templates/web/api/org/alfresco/repository/keywordsearch_get_html.ftl
index baa135d8c7..7cda0032cc 100644
--- a/config/alfresco/templates/web/api/org/alfresco/repository/keywordsearch_get_html.ftl
+++ b/config/alfresco/templates/web/api/org/alfresco/repository/keywordsearch_get_html.ftl
@@ -4,7 +4,7 @@
Alfresco Keyword Search: ${search.searchTerms}
-
+
@@ -12,7 +12,7 @@
-
+
Alfresco Keyword Search
@@ -26,7 +26,7 @@
<#list search.results as row>
- ${row.name}
+ ${row.name}
<#if row.properties.description?? == true>
@@ -39,15 +39,15 @@
diff --git a/config/alfresco/templates/web/api/org/alfresco/repository/keywordsearch_get_rss.ftl b/config/alfresco/templates/web/api/org/alfresco/repository/keywordsearch_get_rss.ftl
index 8eb0591bce..80e84069eb 100644
--- a/config/alfresco/templates/web/api/org/alfresco/repository/keywordsearch_get_rss.ftl
+++ b/config/alfresco/templates/web/api/org/alfresco/repository/keywordsearch_get_rss.ftl
@@ -2,7 +2,7 @@
Alfresco Keyword Search: ${search.searchTerms}
- ${path.serviceContext}/search/keyword?q=${search.searchTerms?url}&p=${search.startPage}&c=${search.itemsPerPage}&l=${search.localeId}&guest=${guest?string("true","")}&format=rss
+ ${absurl(url.service)}?q=${search.searchTerms?url}&p=${search.startPage}&c=${search.itemsPerPage}&l=${search.localeId}&guest=${guest?string("true","")}&format=rss
Alfresco Keyword Search: ${search.searchTerms}
${search.localeId}
${xmldate(date)}
@@ -12,26 +12,26 @@
Alfresco Search: ${search.searchTerms}
16
16
- ${absurl("/images/logo/AlfrescoLogo16.ico")}
+ ${absurl(url.context)}/images/logo/AlfrescoLogo16.ico)}
${search.totalResults}
${search.startIndex}
${search.itemsPerPage}
-
+
<#if search.startPage > 1>
-
-
+
+
#if>
<#if search.startPage < search.totalPages>
-
-
+
+
#if>
-
+
<#list search.results as row>
-
${row.name}
- ${absurl(row.url)}
+ ${absurl(url.context)}${row.url}
${row.properties.description!""}
${xmldate(row.properties.modified)}
${row.id}
diff --git a/config/alfresco/templates/web/api/org/alfresco/repository/keywordsearchdescription_get_opensearchdescription.ftl b/config/alfresco/templates/web/api/org/alfresco/repository/keywordsearchdescription_get_opensearchdescription.ftl
index 3cf1492078..9dd8c10f8d 100644
--- a/config/alfresco/templates/web/api/org/alfresco/repository/keywordsearchdescription_get_opensearchdescription.ftl
+++ b/config/alfresco/templates/web/api/org/alfresco/repository/keywordsearchdescription_get_opensearchdescription.ftl
@@ -4,8 +4,8 @@
Alfresco ${server.edition} Keyword Search ${server.version}
Search Alfresco "company home" using keywords
<#comment>IE takes first template from list, thus html response is listed first#comment>
-
-
-
- ${path.context}/images/logo/AlfrescoLogo16.ico
+
+
+
+ ${absurl(url.context)}/images/logo/AlfrescoLogo16.ico
\ No newline at end of file
diff --git a/config/alfresco/templates/web/api/org/alfresco/repository/searchengines_get_atom.ftl b/config/alfresco/templates/web/api/org/alfresco/repository/searchengines_get_atom.ftl
index 9f0489785e..bae870b070 100644
--- a/config/alfresco/templates/web/api/org/alfresco/repository/searchengines_get_atom.ftl
+++ b/config/alfresco/templates/web/api/org/alfresco/repository/searchengines_get_atom.ftl
@@ -3,17 +3,17 @@
Alfresco (${server.edition})
Registered Search Engines
${xmldate(date)}
- ${path.context}/images/logo/AlfrescoLogo16.ico
+ ${absurl(url.context)}/images/logo/AlfrescoLogo16.ico
<#if person??>${person.properties.userName}<#else>unknown#if>
- ${path.service?xml}
+ ${absurl(url.full)?xml}
<#list engines as engine>
${engine.label}
-
+
<#if engine.urlType == "description">OpenSearch Description<#else>Template URL#if> - ${engine.type}
- ${absurl(engine.url)?xml}
+ ${absurl(url.context)}${engine.url)?xml}
${xmldate(date)}
#list>
diff --git a/config/alfresco/templates/web/api/org/alfresco/repository/searchengines_get_html.ftl b/config/alfresco/templates/web/api/org/alfresco/repository/searchengines_get_html.ftl
index a1999105e3..c356b0514b 100644
--- a/config/alfresco/templates/web/api/org/alfresco/repository/searchengines_get_html.ftl
+++ b/config/alfresco/templates/web/api/org/alfresco/repository/searchengines_get_html.ftl
@@ -2,18 +2,18 @@
-
+
Alfresco Registered Search Engines
<#list engines as engine>
<#if engine.urlType == "description">
-
+
#if>
#list>
-
+
Alfresco Registered Search Engines
@@ -22,7 +22,7 @@
Engine URL Type Response Format
<#list engines as engine>
- ${engine.label}
+ ${engine.label}
<#if engine.urlType == "description">OpenSearch Description<#else>Template URL#if>
${engine.type}
diff --git a/config/alfresco/templates/web/api/org/alfresco/sample/samplesearch_get_atom.ftl b/config/alfresco/templates/web/api/org/alfresco/sample/samplesearch_get_atom.ftl
index f33b79d1fd..fbc53d65e1 100644
--- a/config/alfresco/templates/web/api/org/alfresco/sample/samplesearch_get_atom.ftl
+++ b/config/alfresco/templates/web/api/org/alfresco/sample/samplesearch_get_atom.ftl
@@ -3,15 +3,15 @@
Alfresco (${server.edition})
Alfresco Keyword Search: ${args.q}
${xmldate(date)}
- ${absurl("/images/logo/AlfrescoLogo16.ico")}
+ ${absurl(url.context)}/images/logo/AlfrescoLogo16.ico
<#if person??>${person.properties.userName}<#else>unknown#if>
<#list resultset as node>
${node.name}
-
- ${node.icon16}
+
+ ${absurl(url.context)}${node.icon16}
urn:uuid:${node.id}
${xmldate(node.properties.modified)}
${node.properties.description!""}
diff --git a/config/alfresco/templates/web/api/org/alfresco/sample/samplesearch_get_html.ftl b/config/alfresco/templates/web/api/org/alfresco/sample/samplesearch_get_html.ftl
index 984b6b87c8..be0968aedf 100644
--- a/config/alfresco/templates/web/api/org/alfresco/sample/samplesearch_get_html.ftl
+++ b/config/alfresco/templates/web/api/org/alfresco/sample/samplesearch_get_html.ftl
@@ -3,12 +3,12 @@
Alfresco Keyword Search: ${args.q}
-
+
-
+
Alfresco Keyword Search: ${args.q}
@@ -16,7 +16,7 @@
<#list resultset as node>
- ${node.name}
+ ${node.name}
<#if node.properties.description?? == true>
diff --git a/config/alfresco/templates/web/api/org/alfresco/service/index_get_html.ftl b/config/alfresco/templates/web/api/org/alfresco/service/index_get_html.ftl
index 7e75c7039a..fc7d01dbee 100644
--- a/config/alfresco/templates/web/api/org/alfresco/service/index_get_html.ftl
+++ b/config/alfresco/templates/web/api/org/alfresco/service/index_get_html.ftl
@@ -3,27 +3,31 @@
Alfresco Web APIs
-
+
-
-
-
- Alfresco Web APIs
-
- Alfresco ${server.edition} v${server.version}
- ${services?size} services - Online documentation .
-
+
+
Id Method Authentication
<#list services as service>
<#assign desc = service.description>
${desc.id} ${desc.method} ${desc.requiredAuthentication}
- [${desc.description}]
-
+ [${desc.description}]
+
<#list desc.URIs as uri>
- ${uri.format}<#if uri.format = desc.defaultFormat> (default)#if> ${path.serviceContext}${uri.URI}
+ ${uri.format}<#if uri.format = desc.defaultFormat> (default)#if> ${url.serviceContext}${uri.URI}
#list>
#list>
diff --git a/config/alfresco/templates/web/api/org/alfresco/service/index_post_desc.xml b/config/alfresco/templates/web/api/org/alfresco/service/index_post_desc.xml
new file mode 100644
index 0000000000..0040c3a34f
--- /dev/null
+++ b/config/alfresco/templates/web/api/org/alfresco/service/index_post_desc.xml
@@ -0,0 +1,5 @@
+
+ Service Index Maintenance
+ Maintain index of Web API Services
+
+
\ No newline at end of file
diff --git a/config/alfresco/templates/web/api/org/alfresco/service/index_post_html.ftl b/config/alfresco/templates/web/api/org/alfresco/service/index_post_html.ftl
new file mode 100644
index 0000000000..ad9b1b3055
--- /dev/null
+++ b/config/alfresco/templates/web/api/org/alfresco/service/index_post_html.ftl
@@ -0,0 +1,24 @@
+
+
+
+
+ Alfresco Web APIs Maintenance
+
+
+
+
+
+
+ Alfresco Web APIs Maintenance
+
+ Alfresco ${server.edition} v${server.version}
+ ${services?size} apis .
+
+
+
+ Completed Task
+<#list tasks as task>
+ ${task}
+#list>
+
+
\ No newline at end of file
diff --git a/config/alfresco/web-api-application-context.xml b/config/alfresco/web-api-application-context.xml
index 244c353fe9..3fab5264e4 100644
--- a/config/alfresco/web-api-application-context.xml
+++ b/config/alfresco/web-api-application-context.xml
@@ -30,13 +30,25 @@
+
+
+
+
+
alfresco/templates/web/api
-
-
-
@@ -156,6 +168,9 @@
+
+
+
diff --git a/source/java/org/alfresco/web/api/IndexUpdate.java b/source/java/org/alfresco/web/api/IndexUpdate.java
new file mode 100644
index 0000000000..d0baaa82fa
--- /dev/null
+++ b/source/java/org/alfresco/web/api/IndexUpdate.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2005-2007 Alfresco Software Limited.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+package org.alfresco.web.api;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.alfresco.web.api.framework.APIRequest;
+import org.alfresco.web.api.framework.APIResponse;
+import org.alfresco.web.api.framework.ScriptedAPIService;
+
+
+/**
+ * Retrieves the list of available Web APIs
+ *
+ * @author davidc
+ */
+public class IndexUpdate extends ScriptedAPIService
+{
+
+ /* (non-Javadoc)
+ * @see org.alfresco.web.api.services.APIServiceTemplateImpl#createModel(org.alfresco.web.api.APIRequest, org.alfresco.web.api.APIResponse, java.util.Map)
+ */
+ @Override
+ protected Map executeImpl(APIRequest req, APIResponse res)
+ {
+ List tasks = new ArrayList();
+
+ // reset index
+ String reset = req.getParameter("reset");
+ if (reset != null && reset.equals("on"))
+ {
+ int previousCount = getAPIRegistry().getServices().size();
+ getAPIRegistry().reset();
+ tasks.add("Reset Web API Registry; found " + getAPIRegistry().getServices().size() + " APIs. Previously, there were " + previousCount + ".");
+ }
+
+ // create model for rendering
+ Map model = new HashMap(7, 1.0f);
+ model.put("tasks", tasks);
+ model.put("services", getAPIRegistry().getServices());
+ return model;
+ }
+
+}
diff --git a/source/java/org/alfresco/web/api/SearchProxy.java b/source/java/org/alfresco/web/api/SearchProxy.java
index 40f0c74f22..a6e19348b5 100644
--- a/source/java/org/alfresco/web/api/SearchProxy.java
+++ b/source/java/org/alfresco/web/api/SearchProxy.java
@@ -164,7 +164,7 @@ public class SearchProxy extends AbstractAPIService implements InitializingBean
logger.debug("Mapping engine '" + engine + "' (mimetype '" + mimetype + "') to url '" + engineUrl + "'");
// issue request against search engine
- SearchEngineHttpProxy proxy = new SearchEngineHttpProxy(req.getPath(), engine, engineUrl, res);
+ SearchEngineHttpProxy proxy = new SearchEngineHttpProxy(req.getServicePath() + "/" + req.getContextPath(), engine, engineUrl, res);
proxy.service();
}
diff --git a/source/java/org/alfresco/web/api/framework/APIRegistry.java b/source/java/org/alfresco/web/api/framework/APIRegistry.java
index dc3ca88467..e55ea15d45 100644
--- a/source/java/org/alfresco/web/api/framework/APIRegistry.java
+++ b/source/java/org/alfresco/web/api/framework/APIRegistry.java
@@ -87,4 +87,9 @@ public interface APIRegistry
* @return script processor
*/
public APIScriptProcessor getScriptProcessor();
+
+ /**
+ * Resets the API Registry
+ */
+ public void reset();
}
diff --git a/source/java/org/alfresco/web/api/framework/APIRequest.java b/source/java/org/alfresco/web/api/framework/APIRequest.java
index ff3a5974ca..ffa4111757 100644
--- a/source/java/org/alfresco/web/api/framework/APIRequest.java
+++ b/source/java/org/alfresco/web/api/framework/APIRequest.java
@@ -27,8 +27,6 @@ package org.alfresco.web.api.framework;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
-import org.alfresco.repo.security.authentication.AuthenticationUtil;
-
/**
* API Service Request
@@ -64,25 +62,47 @@ public class APIRequest extends HttpServletRequestWrapper
}
/**
- * Gets the Alfresco Context URL
+ * Get server portion of the request
+ *
+ * e.g. scheme://host:port
*
- * @return context url e.g. http://localhost:port/alfresco
+ * @return server path
*/
- public String getPath()
+ public String getServerPath()
{
- return getScheme() + "://" + getServerName() + ":" + getServerPort() + getContextPath();
+ return getScheme() + "://" + getServerName() + ":" + getServerPort();
+ }
+
+ /**
+ * Gets the Alfresco Service Context Path
+ *
+ * @return service url e.g. /alfresco/service
+ */
+ public String getServiceContextPath()
+ {
+ return getContextPath() + getServletPath();
}
/**
- * Gets the Alfresco Service URL
+ * Gets the Alfresco Service Path
*
- * @return service url e.g. http://localhost:port/alfresco/service
+ * @return service url e.g. /alfresco/service/search/keyword
*/
public String getServicePath()
{
- return getPath() + getServletPath();
+ return getServiceContextPath() + getPathInfo();
}
+ /**
+ * Gets the full request URL
+ *
+ * @return request url e.g. /alfresco/service/search/keyword?q=term
+ */
+ public String getURL()
+ {
+ return getServicePath() + (getQueryString() != null ? "?" + getQueryString() : "");
+ }
+
/**
* Gets the path extension beyond the path registered for this service
*
@@ -107,26 +127,6 @@ public class APIRequest extends HttpServletRequestWrapper
return extensionPath;
}
- /**
- * Gets the full request URL
- *
- * @return request url e.g. http://localhost:port/alfresco/service/keyword?q=term
- */
- public String getUrl()
- {
- return getScheme() + "://" + getServerName() + ":" + getServerPort() + getPathInfo() + (getQueryString() != null ? "?" + getQueryString() : "");
- }
-
- /**
- * Gets the currently authenticated username
- *
- * @return username
- */
- public String getAuthenticatedUsername()
- {
- return AuthenticationUtil.getCurrentUserName();
- }
-
/**
* Determine if Guest User?
*
diff --git a/source/java/org/alfresco/web/api/framework/APIScriptProcessor.java b/source/java/org/alfresco/web/api/framework/APIScriptProcessor.java
index 634de132d0..044d5d7ff2 100644
--- a/source/java/org/alfresco/web/api/framework/APIScriptProcessor.java
+++ b/source/java/org/alfresco/web/api/framework/APIScriptProcessor.java
@@ -107,5 +107,13 @@ public class APIScriptProcessor
{
return scriptService.executeScript(location, model);
}
+
+ /**
+ * Reset script cache
+ */
+ public void resetCache()
+ {
+ // NOOP
+ }
}
diff --git a/source/java/org/alfresco/web/api/framework/APITemplateProcessor.java b/source/java/org/alfresco/web/api/framework/APITemplateProcessor.java
index 368bdd1173..a1a2fb7c44 100644
--- a/source/java/org/alfresco/web/api/framework/APITemplateProcessor.java
+++ b/source/java/org/alfresco/web/api/framework/APITemplateProcessor.java
@@ -83,6 +83,17 @@ public class APITemplateProcessor extends FreeMarkerProcessor implements Applica
this.templateLoader = templateLoader;
}
+ /**
+ * Reset template cache
+ */
+ public void resetCache()
+ {
+ if (templateConfig != null)
+ {
+ templateConfig.clearTemplateCache();
+ }
+ }
+
/**
* Initialise FreeMarker Configuration
*/
diff --git a/source/java/org/alfresco/web/api/framework/AbstractAPIService.java b/source/java/org/alfresco/web/api/framework/AbstractAPIService.java
index c0bd144a9c..6108594a6e 100644
--- a/source/java/org/alfresco/web/api/framework/AbstractAPIService.java
+++ b/source/java/org/alfresco/web/api/framework/AbstractAPIService.java
@@ -218,7 +218,7 @@ public abstract class AbstractAPIService implements APIService
// add api context
model.put("args", createArgModel(req));
model.put("guest", req.isGuest());
- model.put("path", new PathModel(req));
+ model.put("url", new URLModel(req));
model.put("server", new ServerModel(descriptorService.getServerDescriptor()));
// add custom model
@@ -265,12 +265,12 @@ public abstract class AbstractAPIService implements APIService
// add api context
model.put("args", createArgModel(req));
model.put("guest", req.isGuest());
- model.put("path", new PathModel(req));
+ model.put("url", new URLModel(req));
model.put("server", new ServerModel(descriptorService.getServerDescriptor()));
// add template support
model.put("xmldate", new ISO8601DateFormatMethod());
- model.put("absurl", new AbsoluteUrlMethod(req.getPath()));
+ model.put("absurl", new AbsoluteUrlMethod(req.getServerPath()));
model.put("urlencode", new UrlEncodeMethod());
model.put("date", new Date());
diff --git a/source/java/org/alfresco/web/api/framework/ClassPathAPIStore.java b/source/java/org/alfresco/web/api/framework/ClassPathAPIStore.java
index 15dbd9187a..403b0885e5 100644
--- a/source/java/org/alfresco/web/api/framework/ClassPathAPIStore.java
+++ b/source/java/org/alfresco/web/api/framework/ClassPathAPIStore.java
@@ -53,8 +53,8 @@ import freemarker.cache.TemplateLoader;
public class ClassPathAPIStore implements APIStore, InitializingBean
{
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
- private String classPath;
- private File fileDir;
+ protected String classPath;
+ protected File fileDir;
/**
@@ -124,6 +124,10 @@ public class ClassPathAPIStore implements APIStore, InitializingBean
throws IOException
{
File document = new File(fileDir, documentPath);
+ if (!document.exists())
+ {
+ throw new IOException("Description document " + documentPath + " does not exist.");
+ }
return new FileInputStream(document);
}
@@ -149,7 +153,7 @@ public class ClassPathAPIStore implements APIStore, InitializingBean
*/
public ScriptLoader getScriptLoader()
{
- return new ClassPathScriptLoader(fileDir);
+ return new ClassPathScriptLoader();
}
/**
@@ -159,17 +163,6 @@ public class ClassPathAPIStore implements APIStore, InitializingBean
*/
private class ClassPathScriptLoader implements ScriptLoader
{
- private File classPath;
-
- /**
- * Construct
- *
- * @param classPath
- */
- public ClassPathScriptLoader(File classPath)
- {
- this.classPath = classPath;
- }
/* (non-Javadoc)
* @see org.alfresco.web.api.ScriptLoader#getScriptLocation(java.lang.String)
@@ -177,7 +170,7 @@ public class ClassPathAPIStore implements APIStore, InitializingBean
public ScriptLocation getScriptLocation(String path)
{
ScriptLocation location = null;
- File scriptPath = new File(classPath, path);
+ File scriptPath = new File(fileDir, path);
if (scriptPath.exists())
{
location = new ClassPathScriptLocation(scriptPath);
diff --git a/source/java/org/alfresco/web/api/framework/DeclarativeAPIRegistry.java b/source/java/org/alfresco/web/api/framework/DeclarativeAPIRegistry.java
index 54e43b8b46..cbefb2f3fd 100644
--- a/source/java/org/alfresco/web/api/framework/DeclarativeAPIRegistry.java
+++ b/source/java/org/alfresco/web/api/framework/DeclarativeAPIRegistry.java
@@ -218,7 +218,7 @@ public class DeclarativeAPIRegistry implements APIRegistry, ApplicationContextAw
if (logger.isDebugEnabled())
{
APIService existingService = servicesById.get(id);
- logger.debug("Service description document " + existingService.getDescription().getSourceLocation() + " overridden by " + serviceDesc.getSourceLocation());
+ logger.debug("Service description document " + serviceDesc.getSourceLocation() + " overridden by " + existingService.getDescription().getSourceLocation());
}
continue;
}
@@ -519,6 +519,16 @@ public class DeclarativeAPIRegistry implements APIRegistry, ApplicationContextAw
return this.stores.getScriptProcessor();
}
+ /* (non-Javadoc)
+ * @see org.alfresco.web.api.framework.APIRegistry#reset()
+ */
+ public void reset()
+ {
+ getTemplateProcessor().resetCache();
+ getScriptProcessor().resetCache();
+ initServices();
+ }
+
/**
* API Service Match
diff --git a/source/java/org/alfresco/web/api/framework/RepoPathAPIStore.java b/source/java/org/alfresco/web/api/framework/RepoPathAPIStore.java
new file mode 100644
index 0000000000..f5571b6f60
--- /dev/null
+++ b/source/java/org/alfresco/web/api/framework/RepoPathAPIStore.java
@@ -0,0 +1,578 @@
+/*
+ * Copyright (C) 2005-2007 Alfresco Software Limited.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+package org.alfresco.web.api.framework;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.alfresco.model.ContentModel;
+import org.alfresco.repo.security.authentication.AuthenticationUtil;
+import org.alfresco.repo.transaction.TransactionUtil;
+import org.alfresco.service.cmr.repository.ContentReader;
+import org.alfresco.service.cmr.repository.ContentService;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.service.cmr.repository.NodeService;
+import org.alfresco.service.cmr.repository.ScriptLocation;
+import org.alfresco.service.cmr.repository.StoreRef;
+import org.alfresco.service.cmr.search.ResultSet;
+import org.alfresco.service.cmr.search.SearchService;
+import org.alfresco.service.namespace.NamespaceService;
+import org.alfresco.service.transaction.TransactionService;
+import org.alfresco.util.AbstractLifecycleBean;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ApplicationListener;
+
+import freemarker.cache.TemplateLoader;
+
+
+/**
+ * Repository based API Store
+ *
+ * @author davidc
+ */
+public class RepoPathAPIStore implements APIStore, ApplicationContextAware, ApplicationListener
+{
+ private ProcessorLifecycle lifecycle = new ProcessorLifecycle();
+ protected StoreRef repoStore;
+ protected String repoPath;
+ protected NodeRef baseNodeRef;
+ protected String baseDir;
+
+ // dependencies
+ protected TransactionService transactionService;
+ protected SearchService searchService;
+ protected NodeService nodeService;
+ protected ContentService contentService;
+ protected NamespaceService namespaceService;
+
+
+ /**
+ * Sets transaction service
+ *
+ * @param transactionService
+ */
+ public void setTransactionService(TransactionService transactionService)
+ {
+ this.transactionService = transactionService;
+ }
+
+ /**
+ * Sets the search service
+ *
+ * @param searchService
+ */
+ public void setSearchService(SearchService searchService)
+ {
+ this.searchService = searchService;
+ }
+
+ /**
+ * Sets the node service
+ *
+ * @param nodeService
+ */
+ public void setNodeService(NodeService nodeService)
+ {
+ this.nodeService = nodeService;
+ }
+
+ /**
+ * Sets the content service
+ *
+ * @param contentService
+ */
+ public void setContentService(ContentService contentService)
+ {
+ this.contentService = contentService;
+ }
+
+ /**
+ * Sets the namespace service
+ *
+ * @param namespaceService
+ */
+ public void setNamespaceService(NamespaceService namespaceService)
+ {
+ this.namespaceService = namespaceService;
+ }
+
+ /**
+ * Sets the repo store
+ *
+ * @param repoStore
+ */
+ public void setStore(String repoStore)
+ {
+ this.repoStore = new StoreRef(repoStore);
+ }
+
+ /**
+ * Sets the repo path
+ *
+ * @param repoPath repoPath
+ */
+ public void setPath(String repoPath)
+ {
+ this.repoPath = repoPath;
+ }
+
+ /* (non-Javadoc)
+ * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
+ */
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
+ {
+ lifecycle.setApplicationContext(applicationContext);
+ }
+
+ /* (non-Javadoc)
+ * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
+ */
+ public void onApplicationEvent(ApplicationEvent event)
+ {
+ lifecycle.onApplicationEvent(event);
+ }
+
+ /**
+ * Hooks into Spring Application Lifecycle
+ */
+ private class ProcessorLifecycle extends AbstractLifecycleBean
+ {
+ @Override
+ protected void onBootstrap(ApplicationEvent event)
+ {
+ init();
+ }
+
+ @Override
+ protected void onShutdown(ApplicationEvent event)
+ {
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
+ */
+ protected void init()
+ {
+ AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork()
+ {
+ public Object doWork() throws Exception
+ {
+ return TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork()
+ {
+ public Object doWork() throws Exception
+ {
+ String query = "PATH:\"" + repoPath + "\"";
+ ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query);
+ if (resultSet.length() == 0)
+ {
+ throw new APIException("Unable to locate repository path " + repoStore.toString() + repoPath);
+ }
+ if (resultSet.length() > 1)
+ {
+ throw new APIException("Multiple repository paths found for " + repoStore.toString() + repoPath);
+ }
+ baseNodeRef = resultSet.getNodeRef(0);
+ baseDir = getPath(baseNodeRef);
+ return null;
+ }
+ });
+ }
+ }, AuthenticationUtil.getSystemUserName());
+ }
+
+ /* (non-Javadoc)
+ * @see org.alfresco.web.api.APIStore#getBasePath()
+ */
+ public String getBasePath()
+ {
+ return repoStore.toString() + repoPath;
+ }
+
+ /**
+ * Gets the display path for the specified node
+ *
+ * @param nodeRef
+ * @return display path
+ */
+ protected String getPath(NodeRef nodeRef)
+ {
+ return nodeService.getPath(nodeRef).toDisplayPath(nodeService) + "/" + nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
+ }
+
+ /**
+ * Gets the node ref for the specified path within this repo store
+ *
+ * @param documentPath
+ * @return node ref
+ */
+ protected NodeRef findNodeRef(String documentPath)
+ {
+ StringBuilder xpath = new StringBuilder(documentPath.length() << 1);
+ for (StringTokenizer t = new StringTokenizer(documentPath, "/"); t.hasMoreTokens(); /**/)
+ {
+ if (xpath.length() != 0)
+ {
+ xpath.append('/');
+ }
+ xpath.append("*[@cm:name='").append(t.nextToken()).append("']");
+ }
+
+ List nodes = searchService.selectNodes(baseNodeRef, xpath.toString(), null, namespaceService, false);
+ return (nodes.size() == 1) ? nodes.get(0) : null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.alfresco.web.api.APIStore#getDescriptionDocumentPaths()
+ */
+ public String[] getDescriptionDocumentPaths()
+ {
+ return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork()
+ {
+ public String[] doWork() throws Exception
+ {
+ return TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork()
+ {
+ public String[] doWork() throws Exception
+ {
+ int baseDirLength = baseDir.length() +1;
+ List documentPaths = new ArrayList();
+
+ String query = "PATH:\"" + repoPath + "//*\" AND @cm\\:name:\"*_desc.xml\"";
+ ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query);
+ List nodes = resultSet.getNodeRefs();
+ for (NodeRef nodeRef : nodes)
+ {
+ String nodeDir = getPath(nodeRef);
+ String documentPath = nodeDir.substring(baseDirLength);
+ documentPaths.add(documentPath);
+ }
+
+ return documentPaths.toArray(new String[documentPaths.size()]);
+ }
+ });
+ }
+ }, AuthenticationUtil.getSystemUserName());
+ }
+
+ /* (non-Javadoc)
+ * @see org.alfresco.web.api.APIStore#getDescriptionDocument(java.lang.String)
+ */
+ public InputStream getDescriptionDocument(final String documentPath)
+ throws IOException
+ {
+ return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork()
+ {
+ public InputStream doWork() throws Exception
+ {
+ return TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork()
+ {
+ public InputStream doWork() throws Exception
+ {
+ NodeRef nodeRef = findNodeRef(documentPath);
+ if (nodeRef == null)
+ {
+ throw new IOException("Description document " + documentPath + " does not exist.");
+ }
+ ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
+ return reader.getContentInputStream();
+ }
+ });
+ }
+ }, AuthenticationUtil.getSystemUserName());
+ }
+
+ /* (non-Javadoc)
+ * @see org.alfresco.web.api.APIStore#getTemplateLoader()
+ */
+ public TemplateLoader getTemplateLoader()
+ {
+ return new RepoTemplateLoader();
+ }
+
+ /* (non-Javadoc)
+ * @see org.alfresco.web.api.APIStore#getScriptLoader()
+ */
+ public ScriptLoader getScriptLoader()
+ {
+ return new RepoScriptLoader();
+ }
+
+ /**
+ * Repository path based template loader
+ *
+ * @author davidc
+ */
+ private class RepoTemplateLoader implements TemplateLoader
+ {
+ /* (non-Javadoc)
+ * @see freemarker.cache.TemplateLoader#findTemplateSource(java.lang.String)
+ */
+ public Object findTemplateSource(final String name)
+ throws IOException
+ {
+ return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork()
+ {
+ public Object doWork() throws Exception
+ {
+ return TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork()
+ {
+ public Object doWork() throws Exception
+ {
+ RepoTemplateSource source = null;
+ NodeRef nodeRef = findNodeRef(name);
+ if (nodeRef != null)
+ {
+ source = new RepoTemplateSource(nodeRef);
+ }
+ return source;
+ }
+ });
+ }
+ }, AuthenticationUtil.getSystemUserName());
+ }
+
+ /* (non-Javadoc)
+ * @see freemarker.cache.TemplateLoader#getLastModified(java.lang.Object)
+ */
+ public long getLastModified(Object templateSource)
+ {
+ return ((RepoTemplateSource)templateSource).lastModified();
+ }
+
+ /* (non-Javadoc)
+ * @see freemarker.cache.TemplateLoader#getReader(java.lang.Object, java.lang.String)
+ */
+ public Reader getReader(Object templateSource, String encoding) throws IOException
+ {
+ return ((RepoTemplateSource)templateSource).getReader();
+ }
+
+ /* (non-Javadoc)
+ * @see freemarker.cache.TemplateLoader#closeTemplateSource(java.lang.Object)
+ */
+ public void closeTemplateSource(Object arg0) throws IOException
+ {
+ }
+ }
+
+ /**
+ * Repository (content) node template source
+ *
+ * @author davidc
+ */
+ private class RepoTemplateSource
+ {
+ protected final NodeRef nodeRef;
+
+ /**
+ * Construct
+ *
+ * @param ref
+ */
+ private RepoTemplateSource(NodeRef ref)
+ {
+ this.nodeRef = ref;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object o)
+ {
+ if (o instanceof RepoTemplateSource)
+ {
+ return nodeRef.equals(((RepoTemplateSource)o).nodeRef);
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode()
+ {
+ return nodeRef.hashCode();
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ return nodeRef.toString();
+ }
+
+ /**
+ * Gets the last modified time of the content
+ *
+ * @return last modified time
+ */
+ public long lastModified()
+ {
+ return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork()
+ {
+ public Long doWork() throws Exception
+ {
+ return TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork()
+ {
+ public Long doWork() throws Exception
+ {
+ ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
+ return reader.getLastModified();
+ }
+ });
+ }
+ }, AuthenticationUtil.getSystemUserName());
+ }
+
+ /**
+ * Gets the content reader
+ *
+ * @return content reader
+ * @throws IOException
+ */
+ public Reader getReader() throws IOException
+ {
+ return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork()
+ {
+ public Reader doWork() throws Exception
+ {
+ return TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork()
+ {
+ public Reader doWork() throws Exception
+ {
+ ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
+ return new InputStreamReader(reader.getContentInputStream());
+ }
+ });
+ }
+ }, AuthenticationUtil.getSystemUserName());
+ }
+ }
+
+ /**
+ * Repository path based script loader
+ *
+ * @author davidc
+ */
+ private class RepoScriptLoader implements ScriptLoader
+ {
+ /* (non-Javadoc)
+ * @see org.alfresco.web.api.ScriptLoader#getScriptLocation(java.lang.String)
+ */
+ public ScriptLocation getScriptLocation(final String path)
+ {
+ return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork()
+ {
+ public ScriptLocation doWork() throws Exception
+ {
+ return TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork()
+ {
+ public ScriptLocation doWork() throws Exception
+ {
+ ScriptLocation location = null;
+ NodeRef nodeRef = findNodeRef(path);
+ if (nodeRef != null)
+ {
+ location = new RepoScriptLocation(path, nodeRef);
+ }
+ return location;
+ }
+ });
+ }
+ }, AuthenticationUtil.getSystemUserName());
+ }
+ }
+
+ /**
+ * Repo path script location
+ *
+ * @author davidc
+ */
+ private class RepoScriptLocation implements ScriptLocation
+ {
+ protected String path;
+ protected NodeRef nodeRef;
+
+ /**
+ * Construct
+ *
+ * @param location
+ */
+ public RepoScriptLocation(String path, NodeRef nodeRef)
+ {
+ this.path = path;
+ this.nodeRef = nodeRef;
+ }
+
+ /* (non-Javadoc)
+ * @see org.alfresco.service.cmr.repository.ScriptLocation#getInputStream()
+ */
+ public InputStream getInputStream()
+ {
+ return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork()
+ {
+ public InputStream doWork() throws Exception
+ {
+ return TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork()
+ {
+ public InputStream doWork() throws Exception
+ {
+ ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
+ return reader.getContentInputStream();
+ }
+ });
+ }
+ }, AuthenticationUtil.getSystemUserName());
+ }
+
+ /* (non-Javadoc)
+ * @see org.alfresco.service.cmr.repository.ScriptLocation#getReader()
+ */
+ public Reader getReader()
+ {
+ return new InputStreamReader(getInputStream());
+ }
+
+ @Override
+ public String toString()
+ {
+ return repoStore + "/" + baseDir + "/" + path;
+ }
+ }
+
+}
diff --git a/source/java/org/alfresco/web/api/framework/TestAPIServer.java b/source/java/org/alfresco/web/api/framework/TestAPIServer.java
index 8efb51e2e4..b41fbf0dfd 100644
--- a/source/java/org/alfresco/web/api/framework/TestAPIServer.java
+++ b/source/java/org/alfresco/web/api/framework/TestAPIServer.java
@@ -299,11 +299,10 @@ public class TestAPIServer
}
}
- // set path info
+ // set paths
+ req.setContextPath("/alfresco");
+ req.setServletPath("/service");
req.setPathInfo(iArgIndex == -1 ? uri : uri.substring(0, iArgIndex));
-
- // set servlet path
- req.setServletPath("/alfresco/service");
return req;
}
diff --git a/source/java/org/alfresco/web/api/framework/PathModel.java b/source/java/org/alfresco/web/api/framework/URLModel.java
similarity index 71%
rename from source/java/org/alfresco/web/api/framework/PathModel.java
rename to source/java/org/alfresco/web/api/framework/URLModel.java
index 9f9a8aab36..55a30dc3e1 100644
--- a/source/java/org/alfresco/web/api/framework/PathModel.java
+++ b/source/java/org/alfresco/web/api/framework/URLModel.java
@@ -26,11 +26,11 @@ package org.alfresco.web.api.framework;
/**
- * Script / Template Model representing API paths
+ * Script / Template Model representing API Service URLs
*
* @author davidc
*/
-public class PathModel
+public class URLModel
{
private APIRequest req;
@@ -39,7 +39,7 @@ public class PathModel
*
* @param req
*/
- /*package*/ PathModel(APIRequest req)
+ URLModel(APIRequest req)
{
this.req = req;
}
@@ -47,13 +47,13 @@ public class PathModel
/**
* Gets the Context Path
*
- * e.g. http://localhost:port/alfresco
+ * e.g. /alfresco
*
* @return context path
*/
public String getContext()
{
- return req.getPath();
+ return req.getContextPath();
}
public String jsGet_context()
@@ -64,13 +64,13 @@ public class PathModel
/**
* Gets the Service Context Path
*
- * e.g. http://localhost:port/alfresco/service
+ * e.g. /alfresco/service
*
* @return service context path
*/
public String getServiceContext()
{
- return req.getServicePath();
+ return req.getServiceContextPath();
}
public String jsGet_serviceContext()
@@ -81,20 +81,58 @@ public class PathModel
/**
* Gets the Service Path
*
- * e.g. http://localhost:port/alfresco/service/keyword?q=term
+ * e.g. /alfresco/service/search/keyword
*
* @return service path
*/
public String getService()
{
- return req.getUrl();
+ return req.getServicePath();
}
-
+
public String jsGet_service()
{
return getService();
}
+ /**
+ * Gets the full path
+ *
+ * e.g. /alfresco/service/search/keyword?q=term
+ *
+ * @return service path
+ */
+ public String getFull()
+ {
+ return req.getURL();
+ }
+
+ public String jsGet_full()
+ {
+ return getFull();
+ }
+
+ /**
+ * Gets the matching service path
+ *
+ * e.g.
+ * a) service registered path = /search/engine
+ * b) request path = /search/engine/external
+ *
+ * => /search/engine
+ *
+ * @return matching path
+ */
+ public String getMatch()
+ {
+ return getServiceContext() + req.getServiceMatch().getPath();
+ }
+
+ public String jsGet_match()
+ {
+ return getMatch();
+ }
+
/**
* Gets the Service Extension Path
*