1 package org
.argeo
.server
.jackrabbit
.webdav
;
3 import java
.util
.Enumeration
;
4 import java
.util
.Properties
;
6 import javax
.jcr
.Repository
;
7 import javax
.servlet
.ServletConfig
;
8 import javax
.servlet
.ServletContext
;
9 import javax
.servlet
.http
.HttpServlet
;
10 import javax
.servlet
.http
.HttpServletRequest
;
12 import org
.apache
.commons
.logging
.Log
;
13 import org
.apache
.commons
.logging
.LogFactory
;
14 import org
.apache
.jackrabbit
.webdav
.jcr
.JCRWebdavServerServlet
;
15 import org
.argeo
.jcr
.RepositoryRegister
;
16 import org
.springframework
.beans
.BeansException
;
17 import org
.springframework
.context
.ApplicationContext
;
18 import org
.springframework
.context
.ApplicationContextAware
;
19 import org
.springframework
.context
.ConfigurableApplicationContext
;
20 import org
.springframework
.web
.context
.ServletContextAware
;
21 import org
.springframework
.web
.servlet
.HandlerExecutionChain
;
22 import org
.springframework
.web
.servlet
.HandlerMapping
;
23 import org
.springframework
.web
.servlet
.mvc
.ServletWrappingController
;
25 public class MultipleRepositoryHandlerMapping
implements HandlerMapping
,
26 ApplicationContextAware
, ServletContextAware
{
27 private final static Log log
= LogFactory
28 .getLog(MultipleRepositoryHandlerMapping
.class);
30 private ConfigurableApplicationContext applicationContext
;
31 private ServletContext servletContext
;
33 private RepositoryRegister repositoryRegister
;
35 public HandlerExecutionChain
getHandler(HttpServletRequest request
)
38 log
.debug("getContextPath=" + request
.getContextPath());
39 log
.debug("getServletPath=" + request
.getServletPath());
40 log
.debug("getPathInfo=" + request
.getPathInfo());
42 String repositoryName
= "repo";
43 String pathPrefix
= "/remoting/repo";
44 String beanName
= "remoting_" + repositoryName
;
46 if (!applicationContext
.containsBean(beanName
)) {
47 Repository repository
= repositoryRegister
.getRepositories().get(
49 JcrRemotingServlet jcrRemotingServlet
= new JcrRemotingServlet(
51 Properties initParameters
= new Properties();
52 initParameters
.setProperty(
53 JCRWebdavServerServlet
.INIT_PARAM_RESOURCE_PATH_PREFIX
,
55 jcrRemotingServlet
.init(new DelegatingServletConfig(beanName
,
57 applicationContext
.getBeanFactory().registerSingleton(beanName
,
60 HttpServlet remotingServlet
= (HttpServlet
) applicationContext
62 return new HandlerExecutionChain(remotingServlet
);
65 public void setApplicationContext(ApplicationContext applicationContext
)
66 throws BeansException
{
67 this.applicationContext
= (ConfigurableApplicationContext
) applicationContext
;
70 public void setServletContext(ServletContext servletContext
) {
71 this.servletContext
= servletContext
;
74 public void setRepositoryRegister(RepositoryRegister repositoryRegister
) {
75 this.repositoryRegister
= repositoryRegister
;
78 private class DelegatingServletConfig
implements ServletConfig
{
80 private Properties initParameters
;
82 public DelegatingServletConfig(String name
, Properties initParameters
) {
85 this.initParameters
= initParameters
;
88 public String
getServletName() {
92 public ServletContext
getServletContext() {
93 return servletContext
;
96 public String
getInitParameter(String paramName
) {
97 return initParameters
.getProperty(paramName
);
100 public Enumeration
getInitParameterNames() {
101 return initParameters
.keys();