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.kernel.repository.cmis;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.repository.RepositoryException;
020    import com.liferay.portal.kernel.util.ClassResolverUtil;
021    import com.liferay.portal.kernel.util.MethodKey;
022    import com.liferay.portal.kernel.util.PortalClassInvoker;
023    import com.liferay.portal.kernel.util.UnicodeProperties;
024    
025    import java.util.Map;
026    
027    /**
028     * @author Alexander Chow
029     */
030    public class CMISRepositoryUtil {
031    
032            public static void checkRepository(
033                    long repositoryId, Map<String, String> parameters,
034                    UnicodeProperties typeSettingsProperties, String typeSettingsKey) {
035    
036                    try {
037                            PortalClassInvoker.invoke(
038                                    false, _checkRepositoryMethodKey, repositoryId, parameters,
039                                    typeSettingsProperties, typeSettingsKey);
040                    }
041                    catch (Exception e) {
042                            _log.error(e, e);
043                    }
044            }
045    
046            public static Session createSession(Map<String, String> parameters)
047                    throws RepositoryException {
048    
049                    Session session = null;
050    
051                    try {
052                            Object returnObj = PortalClassInvoker.invoke(
053                                    false, _createSessionMethodKey, parameters);
054    
055                            if (returnObj != null) {
056                                    session = (Session)returnObj;
057                            }
058                    }
059                    catch (RepositoryException re) {
060                            throw re;
061                    }
062                    catch (Exception e) {
063                            _log.error(e, e);
064                    }
065    
066                    return session;
067            }
068    
069            public static String getTypeSettingsValue(
070                    UnicodeProperties typeSettingsProperties, String typeSettingsKey) {
071    
072                    String value = null;
073    
074                    try {
075                            Object returnObj = PortalClassInvoker.invoke(
076                                    false, _getTypeSettingsValueMethodKey, typeSettingsProperties,
077                                    typeSettingsKey);
078    
079                            if (returnObj != null) {
080                                    value = (String)returnObj;
081                            }
082                    }
083                    catch (Exception e) {
084                            _log.error(e, e);
085                    }
086    
087                    return value;
088            }
089    
090            private static final String _CLASS_NAME =
091                    "com.liferay.portal.repository.cmis.CMISRepositoryUtil";
092    
093            private static Log _log = LogFactoryUtil.getLog(CMISRepositoryUtil.class);
094    
095            private static MethodKey _checkRepositoryMethodKey = new MethodKey(
096                    ClassResolverUtil.resolveByPortalClassLoader(_CLASS_NAME),
097                    "checkRepository", long.class, Map.class, UnicodeProperties.class,
098                    String.class);
099            private static MethodKey _createSessionMethodKey = new MethodKey(
100                    ClassResolverUtil.resolveByPortalClassLoader(_CLASS_NAME),
101                    "createSession", Map.class);
102            private static MethodKey _getTypeSettingsValueMethodKey = new MethodKey(
103                    ClassResolverUtil.resolveByPortalClassLoader(_CLASS_NAME),
104                    "getTypeSettingsValue", UnicodeProperties.class, String.class);
105    
106    }