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