1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.webdav.methods;
24  
25  import com.liferay.portal.kernel.util.GetterUtil;
26  import com.liferay.portal.kernel.util.InstancePool;
27  import com.liferay.portal.util.PropsUtil;
28  import com.liferay.portal.webdav.WebDAVException;
29  
30  import java.util.HashMap;
31  import java.util.Map;
32  
33  import javax.servlet.http.HttpServletRequest;
34  
35  /**
36   * <a href="MethodFactory.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   */
40  public class MethodFactory {
41  
42      public static Method create(HttpServletRequest request)
43          throws WebDAVException {
44  
45          return _instance._create(request);
46      }
47  
48      private MethodFactory() {
49          _methods = new HashMap<String, Object>();
50  
51          _methods.put("COPY", InstancePool.get(_COPY_METHOD_IMPL));
52          _methods.put("DELETE", InstancePool.get(_DELETE_METHOD_IMPL));
53          _methods.put("GET", InstancePool.get(_GET_METHOD_IMPL));
54          _methods.put("HEAD", InstancePool.get(_HEAD_METHOD_IMPL));
55          _methods.put("LOCK", InstancePool.get(_LOCK_METHOD_IMPL));
56          _methods.put("MKCOL", InstancePool.get(_MKCOL_METHOD_IMPL));
57          _methods.put("MOVE", InstancePool.get(_MOVE_METHOD_IMPL));
58          _methods.put("OPTIONS", InstancePool.get(_OPTIONS_METHOD_IMPL));
59          _methods.put("PROPFIND", InstancePool.get(_PROPFIND_METHOD_IMPL));
60          _methods.put("PROPPATCH", InstancePool.get(_PROPPATCH_METHOD_IMPL));
61          _methods.put("PUT", InstancePool.get(_PUT_METHOD_IMPL));
62          _methods.put("UNLOCK", InstancePool.get(_UNLOCK_METHOD_IMPL));
63      }
64  
65      private Method _create(HttpServletRequest request) throws WebDAVException {
66          String method = request.getMethod();
67  
68          Method methodImpl = (Method)_methods.get(method.toUpperCase());
69  
70          if (methodImpl == null) {
71              throw new WebDAVException(
72                  "Method " + method + " is not implemented");
73          }
74  
75          return methodImpl;
76      }
77  
78      private static final String _COPY_METHOD_IMPL = GetterUtil.getString(
79          PropsUtil.get(MethodFactory.class.getName() + ".COPY"),
80          CopyMethodImpl.class.getName());
81  
82      private static final String _DELETE_METHOD_IMPL = GetterUtil.getString(
83          PropsUtil.get(MethodFactory.class.getName() + ".DELETE"),
84          DeleteMethodImpl.class.getName());
85  
86      private static final String _GET_METHOD_IMPL = GetterUtil.getString(
87          PropsUtil.get(MethodFactory.class.getName() + ".GET"),
88          GetMethodImpl.class.getName());
89  
90      private static final String _HEAD_METHOD_IMPL = GetterUtil.getString(
91          PropsUtil.get(MethodFactory.class.getName() + ".HEAD"),
92          HeadMethodImpl.class.getName());
93  
94      private static final String _LOCK_METHOD_IMPL = GetterUtil.getString(
95          PropsUtil.get(MethodFactory.class.getName() + ".LOCK"),
96          LockMethodImpl.class.getName());
97  
98      private static final String _MKCOL_METHOD_IMPL = GetterUtil.getString(
99          PropsUtil.get(MethodFactory.class.getName() + ".MKCOL"),
100         MkcolMethodImpl.class.getName());
101 
102     private static final String _MOVE_METHOD_IMPL = GetterUtil.getString(
103         PropsUtil.get(MethodFactory.class.getName() + ".MOVE"),
104         MoveMethodImpl.class.getName());
105 
106     private static final String _OPTIONS_METHOD_IMPL = GetterUtil.getString(
107         PropsUtil.get(MethodFactory.class.getName() + ".OPTIONS"),
108         OptionsMethodImpl.class.getName());
109 
110     private static final String _PROPFIND_METHOD_IMPL = GetterUtil.getString(
111         PropsUtil.get(MethodFactory.class.getName() + ".PROPFIND"),
112         PropfindMethodImpl.class.getName());
113 
114     private static final String _PROPPATCH_METHOD_IMPL = GetterUtil.getString(
115         PropsUtil.get(MethodFactory.class.getName() + ".PROPPATCH"),
116         ProppatchMethodImpl.class.getName());
117 
118     private static final String _PUT_METHOD_IMPL = GetterUtil.getString(
119         PropsUtil.get(MethodFactory.class.getName() + ".PUT"),
120         PutMethodImpl.class.getName());
121 
122     private static final String _UNLOCK_METHOD_IMPL = GetterUtil.getString(
123         PropsUtil.get(MethodFactory.class.getName() + ".UNLOCK"),
124         UnlockMethodImpl.class.getName());
125 
126     private static MethodFactory _instance = new MethodFactory();
127 
128     private Map<String, Object> _methods;
129 
130 }