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(_CHECKOUT_METHOD_IMPL);
044
045 _methods.put(method.getMethodName(), method);
046
047 method = (Method)InstancePool.get(_CREATE_URL_DIRECTORIES_METHOD_IMPL);
048
049 _methods.put(method.getMethodName(), method);
050
051 method = (Method)InstancePool.get(_GET_DOCS_META_INFO_METHOD_IMPL);
052
053 _methods.put(method.getMethodName(), method);
054
055 method = (Method)InstancePool.get(_GET_DOCUMENT_METHOD_IMPL);
056
057 _methods.put(method.getMethodName(), method);
058
059 method = (Method)InstancePool.get(_LIST_DOCUMENTS_METHOD_IMPL);
060
061 _methods.put(method.getMethodName(), method);
062
063 method = (Method)InstancePool.get(_MOVE_DOCUMENT_METHOD_IMPL);
064
065 _methods.put(method.getMethodName(), method);
066
067 method = (Method)InstancePool.get(_OPEN_SERVICE_METHOD_IMPL);
068
069 _methods.put(method.getMethodName(), method);
070
071 method = (Method)InstancePool.get(_PUT_DOCUMENT_METHOD_IMPL);
072
073 _methods.put(method.getMethodName(), method);
074
075 method = (Method)InstancePool.get(_REMOVE_DOCUMENTS_METHOD_IMPL);
076
077 _methods.put(method.getMethodName(), method);
078
079 method = (Method)InstancePool.get(_SERVER_VERSION_METHOD_IMPL);
080
081 _methods.put(method.getMethodName(), method);
082
083 method = (Method)InstancePool.get(_UNCHECKOUT_DOCUMENT_METHOD_IMPL);
084
085 _methods.put(method.getMethodName(), method);
086
087 method = (Method)InstancePool.get(_URL_TO_WEB_URL_METHOD_IMPL);
088
089 _methods.put(method.getMethodName(), method);
090 }
091
092 private Method _create(SharepointRequest sharepointRequest)
093 throws SharepointException {
094
095 String method = sharepointRequest.getParameterValue("method");
096
097 method = method.split(StringPool.COLON)[0];
098
099 if (_log.isDebugEnabled()) {
100 _log.debug("Get method " + method);
101 }
102
103 Method methodImpl = (Method)_methods.get(method);
104
105 if (methodImpl == null) {
106 throw new SharepointException(
107 "Method " + method + " is not implemented");
108 }
109 else {
110 if (_log.isDebugEnabled()) {
111 _log.debug(
112 "Method " + method + " is mapped to " +
113 methodImpl.getClass().getName());
114 }
115 }
116
117 return methodImpl;
118 }
119
120 private static final String _CHECKOUT_METHOD_IMPL = GetterUtil.getString(
121 PropsUtil.get(MethodFactory.class.getName() + ".CHECKOUT"),
122 CheckoutMethodImpl.class.getName());
123
124 private static final String _CREATE_URL_DIRECTORIES_METHOD_IMPL =
125 GetterUtil.getString(
126 PropsUtil.get(
127 MethodFactory.class.getName() + ".CREATE_URL_DIRECTORIES"),
128 CreateURLDirectoriesMethodImpl.class.getName());
129
130 private static final String _GET_DOCS_META_INFO_METHOD_IMPL =
131 GetterUtil.getString(
132 PropsUtil.get(
133 MethodFactory.class.getName() + ".GET_DOCS_META_INFO"),
134 GetDocsMetaInfoMethodImpl.class.getName());
135
136 private static final String _GET_DOCUMENT_METHOD_IMPL =
137 GetterUtil.getString(
138 PropsUtil.get(MethodFactory.class.getName() + ".GET_DOCUMENT"),
139 GetDocumentMethodImpl.class.getName());
140
141 private static final String _LIST_DOCUMENTS_METHOD_IMPL =
142 GetterUtil.getString(
143 PropsUtil.get(MethodFactory.class.getName() + ".LIST_DOCUMENTS"),
144 ListDocumentsMethodImpl.class.getName());
145
146 private static final String _MOVE_DOCUMENT_METHOD_IMPL =
147 GetterUtil.getString(
148 PropsUtil.get(MethodFactory.class.getName() + ".MOVE_DOCUMENT"),
149 MoveDocumentMethodImpl.class.getName());
150
151 private static final String _OPEN_SERVICE_METHOD_IMPL =
152 GetterUtil.getString(
153 PropsUtil.get(MethodFactory.class.getName() + ".OPEN_SERVICE"),
154 OpenServiceMethodImpl.class.getName());
155
156 private static final String _PUT_DOCUMENT_METHOD_IMPL =
157 GetterUtil.getString(
158 PropsUtil.get(MethodFactory.class.getName() + ".PUT_DOCUMENT"),
159 PutDocumentMethodImpl.class.getName());
160
161 private static final String _REMOVE_DOCUMENTS_METHOD_IMPL =
162 GetterUtil.getString(
163 PropsUtil.get(MethodFactory.class.getName() + ".REMOVE_DOCUMENTS"),
164 RemoveDocumentsMethodImpl.class.getName());
165
166 private static final String _SERVER_VERSION_METHOD_IMPL =
167 GetterUtil.getString(
168 PropsUtil.get(MethodFactory.class.getName() + ".SERVER_VERSION"),
169 ServerVersionMethodImpl.class.getName());
170
171 private static final String _UNCHECKOUT_DOCUMENT_METHOD_IMPL =
172 GetterUtil.getString(
173 PropsUtil.get(
174 MethodFactory.class.getName() + ".UNCHECKOUT_DOCUMENT"),
175 UncheckoutDocumentMethodImpl.class.getName());
176
177 private static final String _URL_TO_WEB_URL_METHOD_IMPL =
178 GetterUtil.getString(
179 PropsUtil.get(MethodFactory.class.getName() + ".URL_TO_WEB_URL"),
180 UrlToWebUrlMethodImpl.class.getName());
181
182 private static Log _log = LogFactoryUtil.getLog(MethodFactory.class);
183
184 private static MethodFactory _instance = new MethodFactory();
185
186 private Map<String, Object> _methods;
187
188 }