Example usage for com.liferay.portal.util PrefsPropsUtil getString

List of usage examples for com.liferay.portal.util PrefsPropsUtil getString

Introduction

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

Prototype

public static String getString(String name, String defaultValue) 

Source Link

Usage

From source file:com.liferay.dynamic.data.lists.form.web.internal.notification.DDLFormEmailNotificationSender.java

License:Open Source License

protected String getEmailFromAddress(DDLRecordSet recordSet) throws PortalException {

    DDLRecordSetSettings recordSettings = recordSet.getSettingsModel();

    String defaultEmailFromAddress = PrefsPropsUtil.getString(recordSet.getCompanyId(),
            PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);

    return GetterUtil.getString(recordSettings.emailFromAddress(), defaultEmailFromAddress);
}

From source file:com.liferay.dynamic.data.lists.form.web.internal.notification.DDLFormEmailNotificationSender.java

License:Open Source License

protected String getEmailFromName(DDLRecordSet recordSet) throws PortalException {

    DDLRecordSetSettings recordSettings = recordSet.getSettingsModel();

    String defaultEmailFromName = PrefsPropsUtil.getString(recordSet.getCompanyId(),
            PropsKeys.ADMIN_EMAIL_FROM_NAME);

    return GetterUtil.getString(recordSettings.emailFromName(), defaultEmailFromName);
}

From source file:com.liferay.dynamic.data.mapping.form.web.internal.notification.DDMFormEmailNotificationSender.java

License:Open Source License

protected String getEmailFromAddress(DDMFormInstance ddmFormInstance) throws PortalException {

    DDMFormInstanceSettings formInstancetings = ddmFormInstance.getSettingsModel();

    String defaultEmailFromAddress = PrefsPropsUtil.getString(ddmFormInstance.getCompanyId(),
            PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);

    return GetterUtil.getString(formInstancetings.emailFromAddress(), defaultEmailFromAddress);
}

From source file:com.liferay.dynamic.data.mapping.form.web.internal.notification.DDMFormEmailNotificationSender.java

License:Open Source License

protected String getEmailFromName(DDMFormInstance ddmFormInstance) throws PortalException {

    DDMFormInstanceSettings formInstancetings = ddmFormInstance.getSettingsModel();

    String defaultEmailFromName = PrefsPropsUtil.getString(ddmFormInstance.getCompanyId(),
            PropsKeys.ADMIN_EMAIL_FROM_NAME);

    return GetterUtil.getString(formInstancetings.emailFromName(), defaultEmailFromName);
}

From source file:com.liferay.mail.service.impl.MailServiceImpl.java

License:Open Source License

public Session getSession() throws SystemException {
    if (_session != null) {
        return _session;
    }/*from  ww w .j  av  a2s . c o  m*/

    Session session = InfrastructureUtil.getMailSession();

    if (!PrefsPropsUtil.getBoolean(PropsKeys.MAIL_SESSION_MAIL)) {
        _session = session;

        return _session;
    }

    String advancedPropertiesString = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_ADVANCED_PROPERTIES,
            PropsValues.MAIL_SESSION_MAIL_ADVANCED_PROPERTIES);
    String pop3Host = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_POP3_HOST,
            PropsValues.MAIL_SESSION_MAIL_POP3_HOST);
    String pop3Password = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_POP3_PASSWORD,
            PropsValues.MAIL_SESSION_MAIL_POP3_PASSWORD);
    int pop3Port = PrefsPropsUtil.getInteger(PropsKeys.MAIL_SESSION_MAIL_POP3_PORT,
            PropsValues.MAIL_SESSION_MAIL_POP3_PORT);
    String pop3User = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_POP3_USER,
            PropsValues.MAIL_SESSION_MAIL_POP3_USER);
    String smtpHost = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST,
            PropsValues.MAIL_SESSION_MAIL_SMTP_HOST);
    String smtpPassword = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_SMTP_PASSWORD,
            PropsValues.MAIL_SESSION_MAIL_SMTP_PASSWORD);
    int smtpPort = PrefsPropsUtil.getInteger(PropsKeys.MAIL_SESSION_MAIL_SMTP_PORT,
            PropsValues.MAIL_SESSION_MAIL_SMTP_PORT);
    String smtpUser = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_SMTP_USER,
            PropsValues.MAIL_SESSION_MAIL_SMTP_USER);
    String storeProtocol = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_STORE_PROTOCOL,
            PropsValues.MAIL_SESSION_MAIL_STORE_PROTOCOL);
    String transportProtocol = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_TRANSPORT_PROTOCOL,
            PropsValues.MAIL_SESSION_MAIL_TRANSPORT_PROTOCOL);

    Properties properties = session.getProperties();

    // Incoming

    if (!storeProtocol.equals(Account.PROTOCOL_POPS)) {
        storeProtocol = Account.PROTOCOL_POP;
    }

    properties.setProperty("mail.store.protocol", storeProtocol);

    String storePrefix = "mail." + storeProtocol + ".";

    properties.setProperty(storePrefix + "host", pop3Host);
    properties.setProperty(storePrefix + "password", pop3Password);
    properties.setProperty(storePrefix + "port", String.valueOf(pop3Port));
    properties.setProperty(storePrefix + "user", pop3User);

    // Outgoing

    if (!transportProtocol.equals(Account.PROTOCOL_SMTPS)) {
        transportProtocol = Account.PROTOCOL_SMTP;
    }

    properties.setProperty("mail.transport.protocol", transportProtocol);

    String transportPrefix = "mail." + transportProtocol + ".";

    boolean smtpAuth = false;

    if (Validator.isNotNull(smtpPassword) || Validator.isNotNull(smtpUser)) {

        smtpAuth = true;
    }

    properties.setProperty(transportPrefix + "auth", String.valueOf(smtpAuth));
    properties.setProperty(transportPrefix + "host", smtpHost);
    properties.setProperty(transportPrefix + "password", smtpPassword);
    properties.setProperty(transportPrefix + "port", String.valueOf(smtpPort));
    properties.setProperty(transportPrefix + "user", smtpUser);

    // Advanced

    try {
        if (Validator.isNotNull(advancedPropertiesString)) {
            Properties advancedProperties = PropertiesUtil.load(advancedPropertiesString);

            Iterator<Map.Entry<Object, Object>> itr = advancedProperties.entrySet().iterator();

            while (itr.hasNext()) {
                Map.Entry<Object, Object> entry = itr.next();

                String key = (String) entry.getKey();
                String value = (String) entry.getValue();

                properties.setProperty(key, value);
            }
        }
    } catch (IOException ioe) {
        if (_log.isWarnEnabled()) {
            _log.warn(ioe, ioe);
        }
    }

    _session = Session.getInstance(properties);

    return _session;
}

From source file:com.liferay.message.boards.internal.service.SubscriptionMBMessageLocalServiceWrapper.java

License:Open Source License

protected void notifyDiscussionSubscribers(long userId, MBMessage message, ServiceContext serviceContext)
        throws PortalException {

    if (!PrefsPropsUtil.getBoolean(message.getCompanyId(), PropsKeys.DISCUSSION_EMAIL_COMMENTS_ADDED_ENABLED)) {

        return;// w  ww.java  2 s. co  m
    }

    MBDiscussion mbDiscussion = _mbDiscussionLocalService.getThreadDiscussion(message.getThreadId());

    String contentURL = (String) serviceContext.getAttribute("contentURL");

    contentURL = _http.addParameter(contentURL, serviceContext.getAttribute("namespace") + "messageId",
            message.getMessageId());

    String userAddress = StringPool.BLANK;
    String userName = (String) serviceContext.getAttribute("pingbackUserName");

    if (Validator.isNull(userName)) {
        userAddress = _portal.getUserEmailAddress(message.getUserId());
        userName = _portal.getUserName(message.getUserId(), StringPool.BLANK);
    }

    String fromName = PrefsPropsUtil.getString(message.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String fromAddress = PrefsPropsUtil.getString(message.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);

    String subject = PrefsPropsUtil.getContent(message.getCompanyId(), PropsKeys.DISCUSSION_EMAIL_SUBJECT);
    String body = PrefsPropsUtil.getContent(message.getCompanyId(), PropsKeys.DISCUSSION_EMAIL_BODY);

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setBody(body);
    subscriptionSender.setCompanyId(message.getCompanyId());
    subscriptionSender.setClassName(MBDiscussion.class.getName());
    subscriptionSender.setClassPK(mbDiscussion.getDiscussionId());
    subscriptionSender.setContextAttribute("[$COMMENTS_BODY$]", message.getBody(message.isFormatBBCode()),
            false);
    subscriptionSender.setContextAttributes("[$COMMENTS_USER_ADDRESS$]", userAddress, "[$COMMENTS_USER_NAME$]",
            userName, "[$CONTENT_URL$]", contentURL);
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(message.getBody());
    subscriptionSender.setEntryURL(contentURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);

    Date modifiedDate = message.getModifiedDate();

    subscriptionSender.setMailId("mb_discussion", message.getCategoryId(), message.getMessageId(),
            modifiedDate.getTime());

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (serviceContext.isCommandUpdate()) {
        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    subscriptionSender.setNotificationType(notificationType);

    String portletId = PortletProviderUtil.getPortletId(Comment.class.getName(), PortletProvider.Action.VIEW);

    subscriptionSender.setPortletId(portletId);

    subscriptionSender.setScopeGroupId(message.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);
    subscriptionSender.setSubject(subject);
    subscriptionSender.setUniqueMailId(false);

    String className = (String) serviceContext.getAttribute("className");
    long classPK = ParamUtil.getLong(serviceContext, "classPK");

    subscriptionSender.addPersistedSubscribers(className, classPK);

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.portlet.messageboards.service.impl.MBMessageLocalServiceImpl.java

License:Open Source License

protected void notifyDiscussionSubscribers(MBMessage message, ServiceContext serviceContext)
        throws SystemException {

    if (!PrefsPropsUtil.getBoolean(message.getCompanyId(), PropsKeys.DISCUSSION_EMAIL_COMMENTS_ADDED_ENABLED)) {

        return;/*from  w w w .j  av a 2 s . co m*/
    }

    String contentURL = (String) serviceContext.getAttribute("contentURL");

    String userAddress = StringPool.BLANK;
    String userName = (String) serviceContext.getAttribute("pingbackUserName");

    if (Validator.isNull(userName)) {
        userAddress = PortalUtil.getUserEmailAddress(message.getUserId());
        userName = PortalUtil.getUserName(message.getUserId(), StringPool.BLANK);
    }

    String fromName = PrefsPropsUtil.getString(message.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String fromAddress = PrefsPropsUtil.getString(message.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);

    String subject = PrefsPropsUtil.getContent(message.getCompanyId(), PropsKeys.DISCUSSION_EMAIL_SUBJECT);
    String body = PrefsPropsUtil.getContent(message.getCompanyId(), PropsKeys.DISCUSSION_EMAIL_BODY);

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setBody(body);
    subscriptionSender.setCompanyId(message.getCompanyId());
    subscriptionSender.setContextAttributes("[$COMMENTS_BODY$]", message.getBody(true),
            "[$COMMENTS_USER_ADDRESS$]", userAddress, "[$COMMENTS_USER_NAME$]", userName, "[$CONTENT_URL$]",
            contentURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setMailId("mb_discussion", message.getCategoryId(), message.getMessageId());
    subscriptionSender.setScopeGroupId(message.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);
    subscriptionSender.setSubject(subject);
    subscriptionSender.setUserId(message.getUserId());

    String className = (String) serviceContext.getAttribute("className");
    long classPK = GetterUtil.getLong((String) serviceContext.getAttribute("classPK"));

    subscriptionSender.addPersistedSubscribers(className, classPK);

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.portlet.plugininstaller.action.InstallPluginAction.java

License:Open Source License

protected void localDeploy(ActionRequest actionRequest) throws Exception {
    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    String fileName = null;//w ww. j a va  2s.co  m

    String deploymentContext = ParamUtil.getString(actionRequest, "deploymentContext");

    if (Validator.isNotNull(deploymentContext)) {
        fileName = BaseDeployer.DEPLOY_TO_PREFIX + deploymentContext + ".war";
    } else {
        fileName = GetterUtil.getString(uploadPortletRequest.getFileName("file"));

        int pos = fileName.lastIndexOf(CharPool.PERIOD);

        if (pos != -1) {
            deploymentContext = fileName.substring(0, pos);
        }
    }

    File file = uploadPortletRequest.getFile("file");

    byte[] bytes = FileUtil.getBytes(file);

    if ((bytes == null) || (bytes.length == 0)) {
        SessionErrors.add(actionRequest, UploadException.class.getName());

        return;
    }

    try {
        PluginPackageUtil.registerPluginPackageInstallation(deploymentContext);

        String source = file.toString();

        String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR,
                PropsValues.AUTO_DEPLOY_DEPLOY_DIR);

        String destination = deployDir + StringPool.SLASH + fileName;

        FileUtil.copyFile(source, destination);

        SessionMessages.add(actionRequest, "pluginUploaded");
    } finally {
        PluginPackageUtil.endPluginPackageInstallation(deploymentContext);
    }
}

From source file:com.liferay.portlet.plugininstaller.action.InstallPluginAction.java

License:Open Source License

protected int remoteDeploy(String url, URL urlObj, ActionRequest actionRequest, boolean failOnError)
        throws Exception {

    int responseCode = HttpServletResponse.SC_OK;

    GetMethod getMethod = null;/*from ww  w  .j a  v a 2 s  .co m*/

    String deploymentContext = ParamUtil.getString(actionRequest, "deploymentContext");

    try {
        HttpImpl httpImpl = (HttpImpl) HttpUtil.getHttp();

        HostConfiguration hostConfiguration = httpImpl.getHostConfiguration(url);

        HttpClient httpClient = httpImpl.getClient(hostConfiguration);

        getMethod = new GetMethod(url);

        String fileName = null;

        if (Validator.isNotNull(deploymentContext)) {
            fileName = BaseDeployer.DEPLOY_TO_PREFIX + deploymentContext + ".war";
        } else {
            fileName = url.substring(url.lastIndexOf(CharPool.SLASH) + 1);

            int pos = fileName.lastIndexOf(CharPool.PERIOD);

            if (pos != -1) {
                deploymentContext = fileName.substring(0, pos);
            }
        }

        PluginPackageUtil.registerPluginPackageInstallation(deploymentContext);

        responseCode = httpClient.executeMethod(hostConfiguration, getMethod);

        if (responseCode != HttpServletResponse.SC_OK) {
            if (failOnError) {
                SessionErrors.add(actionRequest, "errorConnectingToUrl",
                        new Object[] { String.valueOf(responseCode) });
            }

            return responseCode;
        }

        long contentLength = getMethod.getResponseContentLength();

        String progressId = ParamUtil.getString(actionRequest, Constants.PROGRESS_ID);

        ProgressInputStream pis = new ProgressInputStream(actionRequest, getMethod.getResponseBodyAsStream(),
                contentLength, progressId);

        String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR,
                PropsValues.AUTO_DEPLOY_DEPLOY_DIR);

        String tmpFilePath = deployDir + StringPool.SLASH + _DOWNLOAD_DIR + StringPool.SLASH + fileName;

        File tmpFile = new File(tmpFilePath);

        if (!tmpFile.getParentFile().exists()) {
            tmpFile.getParentFile().mkdirs();
        }

        FileOutputStream fos = new FileOutputStream(tmpFile);

        try {
            pis.readAll(fos);

            if (_log.isInfoEnabled()) {
                _log.info("Downloaded plugin from " + urlObj + " has " + pis.getTotalRead() + " bytes");
            }
        } finally {
            pis.clearProgress();
        }

        getMethod.releaseConnection();

        if (pis.getTotalRead() > 0) {
            String destination = deployDir + StringPool.SLASH + fileName;

            File destinationFile = new File(destination);

            boolean moved = FileUtil.move(tmpFile, destinationFile);

            if (!moved) {
                FileUtil.copyFile(tmpFile, destinationFile);
                FileUtil.delete(tmpFile);
            }

            SessionMessages.add(actionRequest, "pluginDownloaded");
        } else {
            if (failOnError) {
                SessionErrors.add(actionRequest, UploadException.class.getName());
            }

            responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
        }
    } catch (MalformedURLException murle) {
        SessionErrors.add(actionRequest, "invalidUrl", murle);
    } catch (IOException ioe) {
        SessionErrors.add(actionRequest, "errorConnectingToUrl", ioe);
    } finally {
        if (getMethod != null) {
            getMethod.releaseConnection();
        }

        PluginPackageUtil.endPluginPackageInstallation(deploymentContext);
    }

    return responseCode;
}

From source file:org.intalio.tempo.web.CASFilter510.java

License:Open Source License

protected Filter getCASFilter(long companyId) throws Exception {
    edu.yale.its.tp.cas.client.filter.CASFilter casFilter = _casFilters.get(companyId);

    if (casFilter == null) {
        casFilter = new edu.yale.its.tp.cas.client.filter.CASFilter();

        DynamicFilterConfig config = new DynamicFilterConfig(_filterName, _servletContext);

        String serverName = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_SERVER_NAME);
        String serviceUrl = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_SERVICE_URL);

        config.addInitParameter(edu.yale.its.tp.cas.client.filter.CASFilter.LOGIN_INIT_PARAM,
                PrefsPropsUtil.getString(companyId, PropsKeys.CAS_LOGIN_URL));

        if (Validator.isNotNull(serviceUrl)) {
            config.addInitParameter(edu.yale.its.tp.cas.client.filter.CASFilter.SERVICE_INIT_PARAM, serviceUrl);
        } else {/*from   ww  w . ja  v  a  2  s  . c om*/
            config.addInitParameter(edu.yale.its.tp.cas.client.filter.CASFilter.SERVERNAME_INIT_PARAM,
                    serverName);
        }

        config.addInitParameter(edu.yale.its.tp.cas.client.filter.CASFilter.VALIDATE_INIT_PARAM,
                PrefsPropsUtil.getString(companyId, PropsKeys.CAS_VALIDATE_URL));

        //Add proxy call back url
        config.addInitParameter(edu.yale.its.tp.cas.client.filter.CASFilter.PROXY_CALLBACK_INIT_PARAM,
                PrefsPropsUtil.getString(companyId, "cas.proxycallback.url"));

        casFilter.init(config);

        _casFilters.put(companyId, casFilter);
    }

    return casFilter;
}