Example usage for com.liferay.portal.kernel.util PrefsPropsUtil getPreferences

List of usage examples for com.liferay.portal.kernel.util PrefsPropsUtil getPreferences

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util PrefsPropsUtil getPreferences.

Prototype

public static PortletPreferences getPreferences(long companyId) 

Source Link

Usage

From source file:com.liferay.map.google.maps.internal.display.context.GoogleMapsDisplayContext.java

License:Open Source License

public String getCompanyGoogleMapsAPIKey() {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    PortletPreferences companyPortletPreferences = PrefsPropsUtil.getPreferences(themeDisplay.getCompanyId());

    return companyPortletPreferences.getValue("googleMapsAPIKey", null);
}

From source file:com.liferay.map.util.MapProviderHelper.java

License:Open Source License

public String getMapProviderKey(long companyId) {
    PortletPreferences companyPortletPreferences = PrefsPropsUtil.getPreferences(companyId);

    return companyPortletPreferences.getValue(MapProviderWebKeys.MAP_PROVIDER_KEY, null);
}

From source file:com.liferay.sync.admin.portlet.AdminPortlet.java

License:Open Source License

protected void updatePreferences(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences(CompanyThreadLocal.getCompanyId());

    int maxConnections = ParamUtil.getInteger(actionRequest, "maxConnections");

    portletPreferences.setValue(PortletPropsKeys.SYNC_CLIENT_MAX_CONNECTIONS, String.valueOf(maxConnections));

    int pollInterval = ParamUtil.getInteger(actionRequest, "pollInterval");

    portletPreferences.setValue(PortletPropsKeys.SYNC_CLIENT_POLL_INTERVAL, String.valueOf(pollInterval));

    boolean enabled = ParamUtil.getBoolean(actionRequest, "enabled");

    portletPreferences.setValue(PortletPropsKeys.SYNC_SERVICES_ENABLED, String.valueOf(enabled));

    portletPreferences.store();//from   w w  w  .j ava  2s.  c om
}

From source file:com.liferay.sync.service.impl.SyncDLObjectServiceImpl.java

License:Open Source License

@Override
public PortletPreferences getPortletPreferences() throws PortalException {
    User user = getUser();/*  w  ww. java2 s  . c o  m*/

    PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences(user.getCompanyId());

    Properties properties = PortletProps.getProperties();

    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        String key = String.valueOf(entry.getKey());
        String value = String.valueOf(entry.getValue());

        if (portletPreferences.getValue(key, null) != null) {
            continue;
        }

        try {
            portletPreferences.setValue(key, value);
        } catch (Exception e) {
            _log.error(e, e);
        }
    }

    return portletPreferences;
}

From source file:com.liferay.sync.service.impl.SyncPreferencesLocalServiceImpl.java

License:Open Source License

@Override
public PortletPreferences getPortletPreferences(long companyId) throws PortalException {

    PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences(companyId);

    Properties properties = PortletProps.getProperties();

    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        String key = String.valueOf(entry.getKey());
        String value = String.valueOf(entry.getValue());

        if (portletPreferences.getValue(key, null) != null) {
            continue;
        }//from w  w w . j  a  v  a  2 s . c o m

        try {
            portletPreferences.setValue(key, value);
        } catch (Exception e) {
            _log.error(e, e);
        }
    }

    return portletPreferences;
}

From source file:com.liferay.sync.web.internal.portlet.SyncAdminPortlet.java

License:Open Source License

protected void doUpdatePreferences(ActionRequest actionRequest, ActionResponse actionResponse)
        throws Exception {

    PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences(CompanyThreadLocal.getCompanyId());

    boolean allowUserPersonalSites = ParamUtil.getBoolean(actionRequest, "allowUserPersonalSites");

    portletPreferences.setValue(SyncServiceConfigurationKeys.SYNC_ALLOW_USER_PERSONAL_SITES,
            String.valueOf(allowUserPersonalSites));

    boolean enabled = ParamUtil.getBoolean(actionRequest, "enabled");

    portletPreferences.setValue(SyncServiceConfigurationKeys.SYNC_SERVICES_ENABLED, String.valueOf(enabled));

    boolean forceSecurityMode = ParamUtil.getBoolean(actionRequest, "forceSecurityMode");

    portletPreferences.setValue(SyncServiceConfigurationKeys.SYNC_CLIENT_FORCE_SECURITY_MODE,
            String.valueOf(forceSecurityMode));

    boolean lanEnabled = ParamUtil.getBoolean(actionRequest, "lanEnabled");

    if (lanEnabled) {
        _syncUtil.enableLanSync(CompanyThreadLocal.getCompanyId());
    }// w  w w. j av  a2  s  .  c o  m

    portletPreferences.setValue(SyncServiceConfigurationKeys.SYNC_LAN_ENABLED, String.valueOf(lanEnabled));

    int maxConnections = ParamUtil.getInteger(actionRequest, "maxConnections");

    portletPreferences.setValue(SyncServiceConfigurationKeys.SYNC_CLIENT_MAX_CONNECTIONS,
            String.valueOf(maxConnections));

    int maxDownloadRate = ParamUtil.getInteger(actionRequest, "maxDownloadRate");

    portletPreferences.setValue(SyncServiceConfigurationKeys.SYNC_CLIENT_MAX_DOWNLOAD_RATE,
            String.valueOf(maxDownloadRate));

    int maxUploadRate = ParamUtil.getInteger(actionRequest, "maxUploadRate");

    portletPreferences.setValue(SyncServiceConfigurationKeys.SYNC_CLIENT_MAX_UPLOAD_RATE,
            String.valueOf(maxUploadRate));

    boolean oAuthEnabled = ParamUtil.getBoolean(actionRequest, "oAuthEnabled");

    portletPreferences.setValue(SyncConstants.SYNC_OAUTH_ENABLED, String.valueOf(oAuthEnabled));

    int pollInterval = ParamUtil.getInteger(actionRequest, "pollInterval");

    portletPreferences.setValue(SyncServiceConfigurationKeys.SYNC_CLIENT_POLL_INTERVAL,
            String.valueOf(pollInterval));

    portletPreferences.setValue(SyncConstants.SYNC_CONTEXT_MODIFIED_TIME,
            String.valueOf(System.currentTimeMillis()));

    portletPreferences.store();

    if (oAuthEnabled) {
        if (!_syncOAuthHelperUtil.isDeployed()) {
            SessionErrors.add(actionRequest, OAuthPortletUndeployedException.class);

            return;
        }

        ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

        _syncOAuthHelperUtil.enableOAuth(CompanyThreadLocal.getCompanyId(), serviceContext);
    }
}

From source file:fi.javaguru.akismet.mb.portlet.AkismetPortlet.java

License:Open Source License

public void updateConfiguration(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {

    long companyId = PortalUtil.getCompanyId(actionRequest);
    String apiKey = ParamUtil.getString(actionRequest, "akismet.api.key");
    boolean enabled = ParamUtil.getBoolean(actionRequest, "akismet.enabled");

    try {//from   w w w .java  2 s  . c  o  m
        if (Validator.isNotNull(apiKey)) {
            Akismet akismet = new Akismet(apiKey, PortalUtil.getPortalURL(actionRequest));

            if (!akismet.verifyKey()) {
                throw new AkismetException("Unable to verify api key");
            }
        } else if (enabled) {
            throw new AkismetException("Unable to verify api key");
        }

        PortletPreferences preferences = PrefsPropsUtil.getPreferences(companyId);

        preferences.setValue("akismet.api.key", apiKey);
        preferences.setValue("akismet.enabled", String.valueOf(enabled));

        preferences.store();
    } catch (AkismetException ae) {
        SessionErrors.add(actionRequest, AkismetException.class);
    } catch (SystemException se) {
        SessionErrors.add(actionRequest, se.getClass());
    }
}