001
014
015 package com.liferay.portal.webdav.methods;
016
017 import com.liferay.portal.kernel.util.GetterUtil;
018 import com.liferay.portal.kernel.util.InstanceFactory;
019 import com.liferay.portal.kernel.webdav.WebDAVException;
020 import com.liferay.portal.kernel.webdav.methods.Method;
021 import com.liferay.portal.kernel.webdav.methods.MethodFactory;
022 import com.liferay.portal.util.PropsUtil;
023
024 import java.util.HashMap;
025 import java.util.Map;
026
027 import javax.servlet.http.HttpServletRequest;
028
029
032 public class MethodFactoryImpl implements MethodFactory {
033
034 public MethodFactoryImpl() throws Exception {
035 for (String methodName : Method.SUPPORTED_METHOD_NAMES) {
036 addMethod(methodName);
037 }
038 }
039
040 @Override
041 public Method create(HttpServletRequest request) throws WebDAVException {
042 String method = request.getMethod();
043
044 Method methodImpl = (Method)_methods.get(method.toUpperCase());
045
046 if (methodImpl == null) {
047 throw new WebDAVException(
048 "Method " + method + " is not implemented");
049 }
050
051 return methodImpl;
052 }
053
054 protected void addMethod(String methodName) throws Exception {
055 String defaultClassName = methodName.substring(1);
056
057 defaultClassName = defaultClassName.toLowerCase();
058 defaultClassName = methodName.substring(0, 1) + defaultClassName;
059 defaultClassName =
060 "com.liferay.portal.webdav.methods." + defaultClassName +
061 "MethodImpl";
062
063 String className = GetterUtil.getString(
064 PropsUtil.get(MethodFactoryImpl.class.getName() + "." + methodName),
065 defaultClassName);
066
067 _methods.put(methodName, InstanceFactory.newInstance(className));
068 }
069
070 private Map<String, Object> _methods = new HashMap<String, Object>();
071
072 }