Merge Web Scripts from BRANCHES/DEV/DAVE

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5355 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2007-03-08 14:51:33 +00:00
parent bea1a12b32
commit 4b30804f20
24 changed files with 882 additions and 123 deletions

View File

@@ -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<String, Object> executeImpl(APIRequest req, APIResponse res)
{
List<String> tasks = new ArrayList<String>();
// 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<String, Object> model = new HashMap<String, Object>(7, 1.0f);
model.put("tasks", tasks);
model.put("services", getAPIRegistry().getServices());
return model;
}
}

View File

@@ -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();
}

View File

@@ -87,4 +87,9 @@ public interface APIRegistry
* @return script processor
*/
public APIScriptProcessor getScriptProcessor();
/**
* Resets the API Registry
*/
public void reset();
}

View File

@@ -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?
*

View File

@@ -107,5 +107,13 @@ public class APIScriptProcessor
{
return scriptService.executeScript(location, model);
}
/**
* Reset script cache
*/
public void resetCache()
{
// NOOP
}
}

View File

@@ -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
*/

View File

@@ -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());

View File

@@ -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);

View File

@@ -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

View File

@@ -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<Object>()
{
public Object doWork() throws Exception
{
return TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork<Object>()
{
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<NodeRef> 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<String[]>()
{
public String[] doWork() throws Exception
{
return TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork<String[]>()
{
public String[] doWork() throws Exception
{
int baseDirLength = baseDir.length() +1;
List<String> documentPaths = new ArrayList<String>();
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);
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<InputStream>()
{
public InputStream doWork() throws Exception
{
return TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork<InputStream>()
{
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<Object>()
{
public Object doWork() throws Exception
{
return TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork<Object>()
{
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<Long>()
{
public Long doWork() throws Exception
{
return TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork<Long>()
{
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<Reader>()
{
public Reader doWork() throws Exception
{
return TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork<Reader>()
{
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<ScriptLocation>()
{
public ScriptLocation doWork() throws Exception
{
return TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork<ScriptLocation>()
{
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<InputStream>()
{
public InputStream doWork() throws Exception
{
return TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork<InputStream>()
{
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;
}
}
}

View File

@@ -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;
}

View File

@@ -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
*