001    /**
002     * Copyright (c) 2000-present 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.facebook;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.facebook.FacebookConnect;
020    import com.liferay.portal.kernel.json.JSONObject;
021    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
022    import com.liferay.registry.Registry;
023    import com.liferay.registry.RegistryUtil;
024    import com.liferay.registry.ServiceTracker;
025    
026    import javax.portlet.PortletRequest;
027    
028    /**
029     * @author Wilson Man
030     * @author Brian Wing Shun Chan
031     * @author Mika Koivisto
032     */
033    @ProviderType
034    public class FacebookConnectUtil {
035    
036            public static String getAccessToken(
037                    long companyId, String redirect, String code) {
038    
039                    return getFacebookConnect().getAccessToken(companyId, redirect, code);
040            }
041    
042            public static String getAccessTokenURL(long companyId) {
043                    return getFacebookConnect().getAccessTokenURL(companyId);
044            }
045    
046            public static String getAppId(long companyId) {
047                    return getFacebookConnect().getAppId(companyId);
048            }
049    
050            public static String getAppSecret(long companyId) {
051                    return getFacebookConnect().getAppSecret(companyId);
052            }
053    
054            public static String getAuthURL(long companyId) {
055                    return getFacebookConnect().getAuthURL(companyId);
056            }
057    
058            public static FacebookConnect getFacebookConnect() {
059                    PortalRuntimePermission.checkGetBeanProperty(FacebookConnectUtil.class);
060    
061                    return _instance._serviceTracker.getService();
062            }
063    
064            public static JSONObject getGraphResources(
065                    long companyId, String path, String accessToken, String fields) {
066    
067                    return getFacebookConnect().getGraphResources(
068                            companyId, path, accessToken, fields);
069            }
070    
071            public static String getGraphURL(long companyId) {
072                    return getFacebookConnect().getGraphURL(companyId);
073            }
074    
075            public static String getProfileImageURL(PortletRequest portletRequest) {
076                    return getFacebookConnect().getProfileImageURL(portletRequest);
077            }
078    
079            public static String getRedirectURL(long companyId) {
080                    return getFacebookConnect().getRedirectURL(companyId);
081            }
082    
083            public static boolean isEnabled(long companyId) {
084                    return getFacebookConnect().isEnabled(companyId);
085            }
086    
087            public static boolean isVerifiedAccountRequired(long companyId) {
088                    return getFacebookConnect().isVerifiedAccountRequired(companyId);
089            }
090    
091            private FacebookConnectUtil() {
092                    Registry registry = RegistryUtil.getRegistry();
093    
094                    _serviceTracker = registry.trackServices(FacebookConnect.class);
095    
096                    _serviceTracker.open();
097            }
098    
099            private static final FacebookConnectUtil _instance =
100                    new FacebookConnectUtil();
101    
102            private final ServiceTracker<FacebookConnect, FacebookConnect>
103                    _serviceTracker;
104    
105    }