001
014
015 package com.liferay.portal.sharepoint.methods;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.util.GetterUtil;
020 import com.liferay.portal.kernel.util.InstancePool;
021 import com.liferay.portal.kernel.util.StringPool;
022 import com.liferay.portal.sharepoint.SharepointException;
023 import com.liferay.portal.sharepoint.SharepointRequest;
024 import com.liferay.portal.util.PropsUtil;
025
026 import java.util.HashMap;
027 import java.util.Map;
028
029
032 public class MethodFactory {
033
034 public static Method create(SharepointRequest sharepointRequest)
035 throws SharepointException {
036
037 return _instance._create(sharepointRequest);
038 }
039
040 private MethodFactory() {
041 _methods = new HashMap<String, Object>();
042
043 Method method = (Method)InstancePool.get(
044 _CREATE_URL_DIRECTORIES_METHOD_IMPL);
045
046 _methods.put(method.getMethodName(), method);
047
048 method = (Method)InstancePool.get(_GET_DOCS_META_INFO_METHOD_IMPL);
049
050 _methods.put(method.getMethodName(), method);
051
052 method = (Method)InstancePool.get(_GET_DOCUMENT_METHOD_IMPL);
053
054 _methods.put(method.getMethodName(), method);
055
056 method = (Method)InstancePool.get(_LIST_DOCUMENTS_METHOD_IMPL);
057
058 _methods.put(method.getMethodName(), method);
059
060 method = (Method)InstancePool.get(_MOVE_DOCUMENT_METHOD_IMPL);
061
062 _methods.put(method.getMethodName(), method);
063
064 method = (Method)InstancePool.get(_OPEN_SERVICE_METHOD_IMPL);
065
066 _methods.put(method.getMethodName(), method);
067
068 method = (Method)InstancePool.get(_PUT_DOCUMENT_METHOD_IMPL);
069
070 _methods.put(method.getMethodName(), method);
071
072 method = (Method)InstancePool.get(_REMOVE_DOCUMENTS_METHOD_IMPL);
073
074 _methods.put(method.getMethodName(), method);
075
076 method = (Method)InstancePool.get(_SERVER_VERSION_METHOD_IMPL);
077
078 _methods.put(method.getMethodName(), method);
079
080 method = (Method)InstancePool.get(_UNCHECKOUT_DOCUMENT_METHOD_IMPL);
081
082 _methods.put(method.getMethodName(), method);
083
084 method = (Method)InstancePool.get(_URL_TO_WEB_URL_METHOD_IMPL);
085
086 _methods.put(method.getMethodName(), method);
087 }
088
089 private Method _create(SharepointRequest sharepointRequest)
090 throws SharepointException {
091
092 String method = sharepointRequest.getParameterValue("method");
093
094 method = method.split(StringPool.COLON)[0];
095
096 if (_log.isDebugEnabled()) {
097 _log.debug("Get method " + method);
098 }
099
100 Method methodImpl = (Method)_methods.get(method);
101
102 if (methodImpl == null) {
103 throw new SharepointException(
104 "Method " + method + " is not implemented");
105 }
106 else {
107 if (_log.isDebugEnabled()) {
108 _log.debug(
109 "Method " + method + " is mapped to " +
110 methodImpl.getClass().getName());
111 }
112 }
113
114 return methodImpl;
115 }
116
117 private static final String _CREATE_URL_DIRECTORIES_METHOD_IMPL =
118 GetterUtil.getString(
119 PropsUtil.get(
120 MethodFactory.class.getName() + ".CREATE_URL_DIRECTORIES"),
121 CreateURLDirectoriesMethodImpl.class.getName());
122
123 private static final String _GET_DOCS_META_INFO_METHOD_IMPL =
124 GetterUtil.getString(
125 PropsUtil.get(
126 MethodFactory.class.getName() + ".GET_DOCS_META_INFO"),
127 GetDocsMetaInfoMethodImpl.class.getName());
128
129 private static final String _GET_DOCUMENT_METHOD_IMPL =
130 GetterUtil.getString(
131 PropsUtil.get(MethodFactory.class.getName() + ".GET_DOCUMENT"),
132 GetDocumentMethodImpl.class.getName());
133
134 private static final String _LIST_DOCUMENTS_METHOD_IMPL =
135 GetterUtil.getString(
136 PropsUtil.get(MethodFactory.class.getName() + ".LIST_DOCUMENTS"),
137 ListDocumentsMethodImpl.class.getName());
138
139 private static final String _MOVE_DOCUMENT_METHOD_IMPL =
140 GetterUtil.getString(
141 PropsUtil.get(MethodFactory.class.getName() + ".MOVE_DOCUMENT"),
142 MoveDocumentMethodImpl.class.getName());
143
144 private static final String _OPEN_SERVICE_METHOD_IMPL =
145 GetterUtil.getString(
146 PropsUtil.get(MethodFactory.class.getName() + ".OPEN_SERVICE"),
147 OpenServiceMethodImpl.class.getName());
148
149 private static final String _PUT_DOCUMENT_METHOD_IMPL =
150 GetterUtil.getString(
151 PropsUtil.get(MethodFactory.class.getName() + ".PUT_DOCUMENT"),
152 PutDocumentMethodImpl.class.getName());
153
154 private static final String _REMOVE_DOCUMENTS_METHOD_IMPL =
155 GetterUtil.getString(
156 PropsUtil.get(MethodFactory.class.getName() + ".REMOVE_DOCUMENTS"),
157 RemoveDocumentsMethodImpl.class.getName());
158
159 private static final String _SERVER_VERSION_METHOD_IMPL =
160 GetterUtil.getString(
161 PropsUtil.get(MethodFactory.class.getName() + ".SERVER_VERSION"),
162 ServerVersionMethodImpl.class.getName());
163
164 private static final String _UNCHECKOUT_DOCUMENT_METHOD_IMPL =
165 GetterUtil.getString(
166 PropsUtil.get(
167 MethodFactory.class.getName() + ".UNCHECKOUT_DOCUMENT"),
168 UncheckoutDocumentMethodImpl.class.getName());
169
170 private static final String _URL_TO_WEB_URL_METHOD_IMPL =
171 GetterUtil.getString(
172 PropsUtil.get(MethodFactory.class.getName() + ".URL_TO_WEB_URL"),
173 UrlToWebUrlMethodImpl.class.getName());
174
175 private static Log _log = LogFactoryUtil.getLog(MethodFactory.class);
176
177 private static MethodFactory _instance = new MethodFactory();
178
179 private Map<String, Object> _methods;
180
181 }