001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.webdav.methods;
022:
023: import com.liferay.portal.kernel.util.GetterUtil;
024: import com.liferay.portal.kernel.util.InstancePool;
025: import com.liferay.portal.util.PropsUtil;
026: import com.liferay.portal.webdav.WebDAVException;
027: import com.liferay.util.CollectionFactory;
028:
029: import java.util.Map;
030:
031: import javax.servlet.http.HttpServletRequest;
032:
033: import org.apache.commons.logging.Log;
034: import org.apache.commons.logging.LogFactory;
035:
036: /**
037: * <a href="MethodFactory.java.html"><b><i>View Source</i></b></a>
038: *
039: * @author Brian Wing Shun Chan
040: *
041: */
042: public class MethodFactory {
043:
044: public static Method create(HttpServletRequest req)
045: throws WebDAVException {
046:
047: return _instance._create(req);
048: }
049:
050: private MethodFactory() {
051: _methods = CollectionFactory.getHashMap();
052:
053: if (_log.isDebugEnabled()) {
054: _log.debug("Delete method implementation "
055: + _DELETE_METHOD_IMPL);
056: }
057:
058: _methods.put("COPY", InstancePool.get(_COPY_METHOD_IMPL));
059: _methods.put("DELETE", InstancePool.get(_DELETE_METHOD_IMPL));
060: _methods.put("GET", InstancePool.get(_GET_METHOD_IMPL));
061: _methods.put("HEAD", InstancePool.get(_HEAD_METHOD_IMPL));
062: _methods.put("MKCOL", InstancePool.get(_MKCOL_METHOD_IMPL));
063: _methods.put("MOVE", InstancePool.get(_MOVE_METHOD_IMPL));
064: _methods.put("OPTIONS", InstancePool.get(_OPTIONS_METHOD_IMPL));
065: _methods.put("PROPFIND", InstancePool
066: .get(_PROPFIND_METHOD_IMPL));
067: _methods.put("PROPPATCH", InstancePool
068: .get(_PROPPATCH_METHOD_IMPL));
069: _methods.put("PUT", InstancePool.get(_PUT_METHOD_IMPL));
070: }
071:
072: private Method _create(HttpServletRequest req)
073: throws WebDAVException {
074: String method = req.getMethod();
075:
076: if (_log.isDebugEnabled()) {
077: _log.debug("Get method " + method);
078: }
079:
080: Method methodImpl = (Method) _methods.get(method.toUpperCase());
081:
082: if (methodImpl == null) {
083: throw new WebDAVException("Method " + method
084: + " is not implemented");
085: } else {
086: if (_log.isDebugEnabled()) {
087: _log.debug("Method " + method + " is mapped to "
088: + methodImpl.getClass().getName());
089: }
090: }
091:
092: return methodImpl;
093: }
094:
095: private static final String _COPY_METHOD_IMPL = GetterUtil
096: .getString(PropsUtil.get(MethodFactory.class.getName()
097: + ".COPY"), CopyMethodImpl.class.getName());
098:
099: private static final String _DELETE_METHOD_IMPL = GetterUtil
100: .getString(PropsUtil.get(MethodFactory.class.getName()
101: + ".DELETE"), DeleteMethodImpl.class.getName());
102:
103: private static final String _GET_METHOD_IMPL = GetterUtil
104: .getString(PropsUtil.get(MethodFactory.class.getName()
105: + ".GET"), GetMethodImpl.class.getName());
106:
107: private static final String _HEAD_METHOD_IMPL = GetterUtil
108: .getString(PropsUtil.get(MethodFactory.class.getName()
109: + ".HEAD"), HeadMethodImpl.class.getName());
110:
111: private static final String _MKCOL_METHOD_IMPL = GetterUtil
112: .getString(PropsUtil.get(MethodFactory.class.getName()
113: + ".MKCOL"), MkcolMethodImpl.class.getName());
114:
115: private static final String _MOVE_METHOD_IMPL = GetterUtil
116: .getString(PropsUtil.get(MethodFactory.class.getName()
117: + ".MOVE"), MoveMethodImpl.class.getName());
118:
119: private static final String _OPTIONS_METHOD_IMPL = GetterUtil
120: .getString(PropsUtil.get(MethodFactory.class.getName()
121: + ".OPTIONS"), OptionsMethodImpl.class.getName());
122:
123: private static final String _PROPFIND_METHOD_IMPL = GetterUtil
124: .getString(PropsUtil.get(MethodFactory.class.getName()
125: + ".PROPFIND"), PropfindMethodImpl.class.getName());
126:
127: private static final String _PROPPATCH_METHOD_IMPL = GetterUtil
128: .getString(PropsUtil.get(MethodFactory.class.getName()
129: + ".PROPPATCH"), ProppatchMethodImpl.class
130: .getName());
131:
132: private static final String _PUT_METHOD_IMPL = GetterUtil
133: .getString(PropsUtil.get(MethodFactory.class.getName()
134: + ".PUT"), PutMethodImpl.class.getName());
135:
136: private static Log _log = LogFactory.getLog(MethodFactory.class);
137:
138: private static MethodFactory _instance = new MethodFactory();
139:
140: private Map _methods;
141:
142: }
|