1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.plugin.webdav

File XWikiDavFilter.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

4
7
3
1
78
39
8
1.14
2.33
3
2.67

Classes

Class Line # Actions
XWikiDavFilter 43 7 0% 8 4
0.7142857371.4%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.plugin.webdav;
21   
22    import java.io.IOException;
23   
24    import javax.servlet.Filter;
25    import javax.servlet.FilterChain;
26    import javax.servlet.FilterConfig;
27    import javax.servlet.ServletException;
28    import javax.servlet.ServletRequest;
29    import javax.servlet.ServletResponse;
30    import javax.servlet.annotation.WebFilter;
31    import javax.servlet.http.HttpServletRequest;
32    import javax.servlet.http.HttpServletResponse;
33   
34    import org.apache.jackrabbit.webdav.DavMethods;
35   
36    /**
37    * The filter used to bypass the DefaultServlet of the servlet container (we steal the webdav requests made to the
38    * application root).
39    *
40    * @version $Id: 34626b3bf192778a53b2a69fd10cf1c1b8a765d0 $
41    */
42    @WebFilter(filterName = "webdavfilter", displayName = "WebDAV Filter", urlPatterns = { "/*" })
 
43    public class XWikiDavFilter implements Filter
44    {
 
45  1 toggle @Override
46    public void init(FilterConfig filterConfig) throws ServletException
47    {
48    // Nothing to be initialized.
49    }
50   
51    /**
52    * {@inheritDoc}
53    * <p>
54    * Here we 'steal' both OPTIONS and PROPFIND request types and direct them to webdav servlet.
55    * </p>
56    */
 
57  93 toggle @Override
58    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
59    throws IOException, ServletException
60    {
61  93 if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
62  93 HttpServletRequest httpRequest = (HttpServletRequest) request;
63  93 int methodCode = DavMethods.getMethodCode(httpRequest.getMethod());
64  93 if (httpRequest.getRequestURI().equals("/xwiki/")
65    && (methodCode == DavMethods.DAV_OPTIONS || methodCode == DavMethods.DAV_PROPFIND)) {
66  0 httpRequest.getRequestDispatcher("webdav").forward(request, response);
67  0 return;
68    }
69    }
70  93 chain.doFilter(request, response);
71    }
72   
 
73  1 toggle @Override
74    public void destroy()
75    {
76    // Nothing to be destroyed.
77    }
78    }