1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.sharepoint.methods;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.util.GetterUtil;
20  import com.liferay.portal.kernel.util.InstancePool;
21  import com.liferay.portal.kernel.util.StringPool;
22  import com.liferay.portal.sharepoint.SharepointException;
23  import com.liferay.portal.sharepoint.SharepointRequest;
24  import com.liferay.portal.util.PropsUtil;
25  
26  import java.util.HashMap;
27  import java.util.Map;
28  
29  /**
30   * <a href="MethodFactory.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Bruno Farache
33   */
34  public class MethodFactory {
35  
36      public static Method create(SharepointRequest sharepointRequest)
37          throws SharepointException {
38  
39          return _instance._create(sharepointRequest);
40      }
41  
42      private MethodFactory() {
43          _methods = new HashMap<String, Object>();
44  
45          Method method = (Method)InstancePool.get(
46              _CREATE_URL_DIRECTORIES_METHOD_IMPL);
47  
48          _methods.put(method.getMethodName(), method);
49  
50          method = (Method)InstancePool.get(_GET_DOCS_META_INFO_METHOD_IMPL);
51  
52          _methods.put(method.getMethodName(), method);
53  
54          method = (Method)InstancePool.get(_GET_DOCUMENT_METHOD_IMPL);
55  
56          _methods.put(method.getMethodName(), method);
57  
58          method = (Method)InstancePool.get(_LIST_DOCUMENTS_METHOD_IMPL);
59  
60          _methods.put(method.getMethodName(), method);
61  
62          method = (Method)InstancePool.get(_MOVE_DOCUMENT_METHOD_IMPL);
63  
64          _methods.put(method.getMethodName(), method);
65  
66          method = (Method)InstancePool.get(_OPEN_SERVICE_METHOD_IMPL);
67  
68          _methods.put(method.getMethodName(), method);
69  
70          method = (Method)InstancePool.get(_PUT_DOCUMENT_METHOD_IMPL);
71  
72          _methods.put(method.getMethodName(), method);
73  
74          method = (Method)InstancePool.get(_REMOVE_DOCUMENTS_METHOD_IMPL);
75  
76          _methods.put(method.getMethodName(), method);
77  
78          method = (Method)InstancePool.get(_SERVER_VERSION_METHOD_IMPL);
79  
80          _methods.put(method.getMethodName(), method);
81  
82          method = (Method)InstancePool.get(_UNCHECKOUT_DOCUMENT_METHOD_IMPL);
83  
84          _methods.put(method.getMethodName(), method);
85  
86          method = (Method)InstancePool.get(_URL_TO_WEB_URL_METHOD_IMPL);
87  
88          _methods.put(method.getMethodName(), method);
89      }
90  
91      private Method _create(SharepointRequest sharepointRequest)
92          throws SharepointException {
93  
94          String method = sharepointRequest.getParameterValue("method");
95  
96          method = method.split(StringPool.COLON)[0];
97  
98          if (_log.isDebugEnabled()) {
99              _log.debug("Get method " + method);
100         }
101 
102         Method methodImpl = (Method)_methods.get(method);
103 
104         if (methodImpl == null) {
105             throw new SharepointException(
106                 "Method " + method + " is not implemented");
107         }
108         else {
109             if (_log.isDebugEnabled()) {
110                 _log.debug(
111                     "Method " + method + " is mapped to " +
112                         methodImpl.getClass().getName());
113             }
114         }
115 
116         return methodImpl;
117     }
118 
119     private static final String _CREATE_URL_DIRECTORIES_METHOD_IMPL =
120         GetterUtil.getString(
121             PropsUtil.get(
122                 MethodFactory.class.getName() + ".CREATE_URL_DIRECTORIES"),
123             CreateURLDirectoriesMethodImpl.class.getName());
124 
125     private static final String _GET_DOCS_META_INFO_METHOD_IMPL =
126         GetterUtil.getString(
127             PropsUtil.get(
128                 MethodFactory.class.getName() + ".GET_DOCS_META_INFO"),
129             GetDocsMetaInfoMethodImpl.class.getName());
130 
131     private static final String _GET_DOCUMENT_METHOD_IMPL =
132         GetterUtil.getString(
133             PropsUtil.get(MethodFactory.class.getName() + ".GET_DOCUMENT"),
134             GetDocumentMethodImpl.class.getName());
135 
136     private static final String _LIST_DOCUMENTS_METHOD_IMPL =
137         GetterUtil.getString(
138             PropsUtil.get(MethodFactory.class.getName() + ".LIST_DOCUMENTS"),
139             ListDocumentsMethodImpl.class.getName());
140 
141     private static final String _MOVE_DOCUMENT_METHOD_IMPL =
142         GetterUtil.getString(
143             PropsUtil.get(MethodFactory.class.getName() + ".MOVE_DOCUMENT"),
144             MoveDocumentMethodImpl.class.getName());
145 
146     private static final String _OPEN_SERVICE_METHOD_IMPL =
147         GetterUtil.getString(
148             PropsUtil.get(MethodFactory.class.getName() + ".OPEN_SERVICE"),
149             OpenServiceMethodImpl.class.getName());
150 
151     private static final String _PUT_DOCUMENT_METHOD_IMPL =
152         GetterUtil.getString(
153             PropsUtil.get(MethodFactory.class.getName() + ".PUT_DOCUMENT"),
154             PutDocumentMethodImpl.class.getName());
155 
156     private static final String _REMOVE_DOCUMENTS_METHOD_IMPL =
157         GetterUtil.getString(
158             PropsUtil.get(MethodFactory.class.getName() + ".REMOVE_DOCUMENTS"),
159             RemoveDocumentsMethodImpl.class.getName());
160 
161     private static final String _SERVER_VERSION_METHOD_IMPL =
162         GetterUtil.getString(
163             PropsUtil.get(MethodFactory.class.getName() + ".SERVER_VERSION"),
164             ServerVersionMethodImpl.class.getName());
165 
166     private static final String _UNCHECKOUT_DOCUMENT_METHOD_IMPL =
167         GetterUtil.getString(
168             PropsUtil.get(
169                 MethodFactory.class.getName() + ".UNCHECKOUT_DOCUMENT"),
170             UncheckoutDocumentMethodImpl.class.getName());
171 
172     private static final String _URL_TO_WEB_URL_METHOD_IMPL =
173         GetterUtil.getString(
174             PropsUtil.get(MethodFactory.class.getName() + ".URL_TO_WEB_URL"),
175             UrlToWebUrlMethodImpl.class.getName());
176 
177     private static Log _log = LogFactoryUtil.getLog(MethodFactory.class);
178 
179     private static MethodFactory _instance = new MethodFactory();
180 
181     private Map<String, Object> _methods;
182 
183 }