1
22
23 package com.liferay.portal.sharepoint.methods;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.portal.kernel.util.GetterUtil;
28 import com.liferay.portal.kernel.util.InstancePool;
29 import com.liferay.portal.kernel.util.StringPool;
30 import com.liferay.portal.sharepoint.SharepointException;
31 import com.liferay.portal.sharepoint.SharepointRequest;
32 import com.liferay.portal.util.PropsUtil;
33
34 import java.util.HashMap;
35 import java.util.Map;
36
37
43 public class MethodFactory {
44
45 public static Method create(SharepointRequest sharepointRequest)
46 throws SharepointException {
47
48 return _instance._create(sharepointRequest);
49 }
50
51 private MethodFactory() {
52 _methods = new HashMap<String, Object>();
53
54 Method method = (Method)InstancePool.get(
55 _CREATE_URL_DIRECTORIES_METHOD_IMPL);
56
57 _methods.put(method.getMethodName(), method);
58
59 method = (Method)InstancePool.get(_GET_DOCS_META_INFO_METHOD_IMPL);
60
61 _methods.put(method.getMethodName(), method);
62
63 method = (Method)InstancePool.get(_GET_DOCUMENT_METHOD_IMPL);
64
65 _methods.put(method.getMethodName(), method);
66
67 method = (Method)InstancePool.get(_LIST_DOCUMENTS_METHOD_IMPL);
68
69 _methods.put(method.getMethodName(), method);
70
71 method = (Method)InstancePool.get(_MOVE_DOCUMENT_METHOD_IMPL);
72
73 _methods.put(method.getMethodName(), method);
74
75 method = (Method)InstancePool.get(_OPEN_SERVICE_METHOD_IMPL);
76
77 _methods.put(method.getMethodName(), method);
78
79 method = (Method)InstancePool.get(_PUT_DOCUMENT_METHOD_IMPL);
80
81 _methods.put(method.getMethodName(), method);
82
83 method = (Method)InstancePool.get(_REMOVE_DOCUMENTS_METHOD_IMPL);
84
85 _methods.put(method.getMethodName(), method);
86
87 method = (Method)InstancePool.get(_SERVER_VERSION_METHOD_IMPL);
88
89 _methods.put(method.getMethodName(), method);
90
91 method = (Method)InstancePool.get(_UNCHECKOUT_DOCUMENT_METHOD_IMPL);
92
93 _methods.put(method.getMethodName(), method);
94
95 method = (Method)InstancePool.get(_URL_TO_WEB_URL_METHOD_IMPL);
96
97 _methods.put(method.getMethodName(), method);
98 }
99
100 private Method _create(SharepointRequest sharepointRequest)
101 throws SharepointException {
102
103 String method = sharepointRequest.getParameterValue("method");
104
105 method = method.split(StringPool.COLON)[0];
106
107 if (_log.isDebugEnabled()) {
108 _log.debug("Get method " + method);
109 }
110
111 Method methodImpl = (Method)_methods.get(method);
112
113 if (methodImpl == null) {
114 throw new SharepointException(
115 "Method " + method + " is not implemented");
116 }
117 else {
118 if (_log.isDebugEnabled()) {
119 _log.debug(
120 "Method " + method + " is mapped to " +
121 methodImpl.getClass().getName());
122 }
123 }
124
125 return methodImpl;
126 }
127
128 private static final String _CREATE_URL_DIRECTORIES_METHOD_IMPL =
129 GetterUtil.getString(
130 PropsUtil.get(
131 MethodFactory.class.getName() + ".CREATE_URL_DIRECTORIES"),
132 CreateURLDirectoriesMethodImpl.class.getName());
133
134 private static final String _GET_DOCS_META_INFO_METHOD_IMPL =
135 GetterUtil.getString(
136 PropsUtil.get(
137 MethodFactory.class.getName() + ".GET_DOCS_META_INFO"),
138 GetDocsMetaInfoMethodImpl.class.getName());
139
140 private static final String _GET_DOCUMENT_METHOD_IMPL =
141 GetterUtil.getString(
142 PropsUtil.get(MethodFactory.class.getName() + ".GET_DOCUMENT"),
143 GetDocumentMethodImpl.class.getName());
144
145 private static final String _LIST_DOCUMENTS_METHOD_IMPL =
146 GetterUtil.getString(
147 PropsUtil.get(MethodFactory.class.getName() + ".LIST_DOCUMENTS"),
148 ListDocumentsMethodImpl.class.getName());
149
150 private static final String _MOVE_DOCUMENT_METHOD_IMPL =
151 GetterUtil.getString(
152 PropsUtil.get(MethodFactory.class.getName() + ".MOVE_DOCUMENT"),
153 MoveDocumentMethodImpl.class.getName());
154
155 private static final String _OPEN_SERVICE_METHOD_IMPL =
156 GetterUtil.getString(
157 PropsUtil.get(MethodFactory.class.getName() + ".OPEN_SERVICE"),
158 OpenServiceMethodImpl.class.getName());
159
160 private static final String _PUT_DOCUMENT_METHOD_IMPL =
161 GetterUtil.getString(
162 PropsUtil.get(MethodFactory.class.getName() + ".PUT_DOCUMENT"),
163 PutDocumentMethodImpl.class.getName());
164
165 private static final String _REMOVE_DOCUMENTS_METHOD_IMPL =
166 GetterUtil.getString(
167 PropsUtil.get(MethodFactory.class.getName() + ".REMOVE_DOCUMENTS"),
168 RemoveDocumentsMethodImpl.class.getName());
169
170 private static final String _SERVER_VERSION_METHOD_IMPL =
171 GetterUtil.getString(
172 PropsUtil.get(MethodFactory.class.getName() + ".SERVER_VERSION"),
173 ServerVersionMethodImpl.class.getName());
174
175 private static final String _UNCHECKOUT_DOCUMENT_METHOD_IMPL =
176 GetterUtil.getString(
177 PropsUtil.get(
178 MethodFactory.class.getName() + ".UNCHECKOUT_DOCUMENT"),
179 UncheckoutDocumentMethodImpl.class.getName());
180
181 private static final String _URL_TO_WEB_URL_METHOD_IMPL =
182 GetterUtil.getString(
183 PropsUtil.get(MethodFactory.class.getName() + ".URL_TO_WEB_URL"),
184 UrlToWebUrlMethodImpl.class.getName());
185
186 private static Log _log = LogFactoryUtil.getLog(MethodFactory.class);
187
188 private static MethodFactory _instance = new MethodFactory();
189
190 private Map<String, Object> _methods;
191
192 }