001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.sharepoint.methods;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.kernel.util.InstancePool;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.sharepoint.SharepointException;
021    import com.liferay.portal.sharepoint.SharepointRequest;
022    import com.liferay.portal.util.PropsUtil;
023    
024    import java.util.HashMap;
025    import java.util.Map;
026    
027    /**
028     * @author Bruno Farache
029     */
030    public class MethodFactory {
031    
032            public static Method create(SharepointRequest sharepointRequest)
033                    throws SharepointException {
034    
035                    return _instance._create(sharepointRequest);
036            }
037    
038            private MethodFactory() {
039                    _methods = new HashMap<String, Object>();
040    
041                    Method method = (Method)InstancePool.get(_CHECKOUT_METHOD_IMPL);
042    
043                    _methods.put(method.getMethodName(), method);
044    
045                    method = (Method)InstancePool.get(_CREATE_URL_DIRECTORIES_METHOD_IMPL);
046    
047                    _methods.put(method.getMethodName(), method);
048    
049                    method = (Method)InstancePool.get(_GET_DOCS_META_INFO_METHOD_IMPL);
050    
051                    _methods.put(method.getMethodName(), method);
052    
053                    method = (Method)InstancePool.get(_GET_DOCUMENT_METHOD_IMPL);
054    
055                    _methods.put(method.getMethodName(), method);
056    
057                    method = (Method)InstancePool.get(_LIST_DOCUMENTS_METHOD_IMPL);
058    
059                    _methods.put(method.getMethodName(), method);
060    
061                    method = (Method)InstancePool.get(_MOVE_DOCUMENT_METHOD_IMPL);
062    
063                    _methods.put(method.getMethodName(), method);
064    
065                    method = (Method)InstancePool.get(_OPEN_SERVICE_METHOD_IMPL);
066    
067                    _methods.put(method.getMethodName(), method);
068    
069                    method = (Method)InstancePool.get(_PUT_DOCUMENT_METHOD_IMPL);
070    
071                    _methods.put(method.getMethodName(), method);
072    
073                    method = (Method)InstancePool.get(_REMOVE_DOCUMENTS_METHOD_IMPL);
074    
075                    _methods.put(method.getMethodName(), method);
076    
077                    method = (Method)InstancePool.get(_SERVER_VERSION_METHOD_IMPL);
078    
079                    _methods.put(method.getMethodName(), method);
080    
081                    method = (Method)InstancePool.get(_UNCHECKOUT_DOCUMENT_METHOD_IMPL);
082    
083                    _methods.put(method.getMethodName(), method);
084    
085                    method = (Method)InstancePool.get(_URL_TO_WEB_URL_METHOD_IMPL);
086    
087                    _methods.put(method.getMethodName(), method);
088            }
089    
090            private Method _create(SharepointRequest sharepointRequest)
091                    throws SharepointException {
092    
093                    String method = sharepointRequest.getParameterValue("method");
094    
095                    method = method.split(StringPool.COLON)[0];
096    
097                    Method methodImpl = (Method)_methods.get(method);
098    
099                    if (methodImpl == null) {
100                            throw new SharepointException(
101                                    "Method " + method + " is not implemented");
102                    }
103    
104                    return methodImpl;
105            }
106    
107            private static final String _CHECKOUT_METHOD_IMPL = GetterUtil.getString(
108                    PropsUtil.get(MethodFactory.class.getName() + ".CHECKOUT"),
109                    CheckoutMethodImpl.class.getName());
110    
111            private static final String _CREATE_URL_DIRECTORIES_METHOD_IMPL =
112                    GetterUtil.getString(
113                            PropsUtil.get(
114                                    MethodFactory.class.getName() + ".CREATE_URL_DIRECTORIES"),
115                            CreateURLDirectoriesMethodImpl.class.getName());
116    
117            private static final String _GET_DOCS_META_INFO_METHOD_IMPL =
118                    GetterUtil.getString(
119                            PropsUtil.get(
120                                    MethodFactory.class.getName() + ".GET_DOCS_META_INFO"),
121                            GetDocsMetaInfoMethodImpl.class.getName());
122    
123            private static final String _GET_DOCUMENT_METHOD_IMPL =
124                    GetterUtil.getString(
125                            PropsUtil.get(MethodFactory.class.getName() + ".GET_DOCUMENT"),
126                            GetDocumentMethodImpl.class.getName());
127    
128            private static final String _LIST_DOCUMENTS_METHOD_IMPL =
129                    GetterUtil.getString(
130                            PropsUtil.get(MethodFactory.class.getName() + ".LIST_DOCUMENTS"),
131                            ListDocumentsMethodImpl.class.getName());
132    
133            private static final String _MOVE_DOCUMENT_METHOD_IMPL =
134                    GetterUtil.getString(
135                            PropsUtil.get(MethodFactory.class.getName() + ".MOVE_DOCUMENT"),
136                            MoveDocumentMethodImpl.class.getName());
137    
138            private static final String _OPEN_SERVICE_METHOD_IMPL =
139                    GetterUtil.getString(
140                            PropsUtil.get(MethodFactory.class.getName() + ".OPEN_SERVICE"),
141                            OpenServiceMethodImpl.class.getName());
142    
143            private static final String _PUT_DOCUMENT_METHOD_IMPL =
144                    GetterUtil.getString(
145                            PropsUtil.get(MethodFactory.class.getName() + ".PUT_DOCUMENT"),
146                            PutDocumentMethodImpl.class.getName());
147    
148            private static final String _REMOVE_DOCUMENTS_METHOD_IMPL =
149                    GetterUtil.getString(
150                            PropsUtil.get(MethodFactory.class.getName() + ".REMOVE_DOCUMENTS"),
151                            RemoveDocumentsMethodImpl.class.getName());
152    
153            private static final String _SERVER_VERSION_METHOD_IMPL =
154                    GetterUtil.getString(
155                            PropsUtil.get(MethodFactory.class.getName() + ".SERVER_VERSION"),
156                            ServerVersionMethodImpl.class.getName());
157    
158            private static final String _UNCHECKOUT_DOCUMENT_METHOD_IMPL =
159                    GetterUtil.getString(
160                            PropsUtil.get(
161                                    MethodFactory.class.getName() + ".UNCHECKOUT_DOCUMENT"),
162                            UncheckoutDocumentMethodImpl.class.getName());
163    
164            private static final String _URL_TO_WEB_URL_METHOD_IMPL =
165                    GetterUtil.getString(
166                            PropsUtil.get(MethodFactory.class.getName() + ".URL_TO_WEB_URL"),
167                            UrlToWebUrlMethodImpl.class.getName());
168    
169            private static MethodFactory _instance = new MethodFactory();
170    
171            private Map<String, Object> _methods;
172    
173    }