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