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

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

Introduction

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

Prototype

public static boolean getBoolean(String name, boolean defaultValue) 

Source Link

Usage

From source file:com.custom.portal.security.ldap.CustomDefaultLDAPToPortalConverter.java

License:Open Source License

@Override
public CustomLDAPUser importLDAPUser(long companyId, Attributes attributes, Properties userMappings,
        Properties userExpandoMappings, Properties contactMappings, Properties contactExpandoMappings,
        String password) throws Exception {

    boolean autoScreenName = PrefsPropsUtil.getBoolean(companyId,
            PropsKeys.USERS_SCREEN_NAME_ALWAYS_AUTOGENERATE);

    String screenName = LDAPUtil.getAttributeString(attributes, userMappings, UserConverterKeys.SCREEN_NAME)
            .toLowerCase();/*from   ww  w.j  ava2  s. co m*/
    String emailAddress = LDAPUtil.getAttributeString(attributes, userMappings,
            UserConverterKeys.EMAIL_ADDRESS);

    if (_log.isDebugEnabled()) {
        _log.debug("Screen name " + screenName + " and email address " + emailAddress);
    }

    String firstName = LDAPUtil.getAttributeString(attributes, userMappings, UserConverterKeys.FIRST_NAME);
    String middleName = LDAPUtil.getAttributeString(attributes, userMappings, UserConverterKeys.MIDDLE_NAME);
    String lastName = LDAPUtil.getAttributeString(attributes, userMappings, UserConverterKeys.LAST_NAME);

    if (Validator.isNull(firstName) || Validator.isNull(lastName)) {
        String fullName = LDAPUtil.getAttributeString(attributes, userMappings, UserConverterKeys.FULL_NAME);

        FullNameGenerator fullNameGenerator = FullNameGeneratorFactory.getInstance();

        String[] names = fullNameGenerator.splitFullName(fullName);

        firstName = names[0];
        middleName = names[1];
        lastName = names[2];
    }

    if (!autoScreenName && Validator.isNull(screenName)) {
        throw new UserScreenNameException("Screen name cannot be null for "
                + ContactConstants.getFullName(firstName, middleName, lastName));
    }

    if (Validator.isNull(emailAddress)
            && PrefsPropsUtil.getBoolean(companyId, PropsKeys.USERS_EMAIL_ADDRESS_REQUIRED)) {

        throw new UserEmailAddressException("Email address cannot be null for "
                + ContactConstants.getFullName(firstName, middleName, lastName));
    }

    CustomLDAPUser ldapUser = new CustomLDAPUser();

    ldapUser.setAutoPassword(password.equals(StringPool.BLANK));
    ldapUser.setAutoScreenName(autoScreenName);

    Contact contact = ContactUtil.create(0);

    int prefixId = getListTypeId(attributes, contactMappings, ContactConverterKeys.PREFIX,
            ListTypeConstants.CONTACT_PREFIX);

    contact.setPrefixId(prefixId);

    int suffixId = getListTypeId(attributes, contactMappings, ContactConverterKeys.SUFFIX,
            ListTypeConstants.CONTACT_SUFFIX);

    contact.setSuffixId(suffixId);

    String gender = LDAPUtil.getAttributeString(attributes, contactMappings, ContactConverterKeys.GENDER);

    gender = StringUtil.toLowerCase(gender);

    if (GetterUtil.getBoolean(gender) || gender.equals("female")) {
        contact.setMale(false);
    } else {
        contact.setMale(true);
    }

    try {
        Date birthday = DateUtil.parseDate(
                LDAPUtil.getAttributeString(attributes, contactMappings, ContactConverterKeys.BIRTHDAY),
                LocaleUtil.getDefault());

        contact.setBirthday(birthday);
    } catch (ParseException pe) {
        Calendar birthdayCalendar = CalendarFactoryUtil.getCalendar(1970, Calendar.JANUARY, 1);

        contact.setBirthday(birthdayCalendar.getTime());
    }

    contact.setSmsSn(LDAPUtil.getAttributeString(attributes, contactMappings, ContactConverterKeys.SMS_SN));
    contact.setAimSn(LDAPUtil.getAttributeString(attributes, contactMappings, ContactConverterKeys.AIM_SN));
    contact.setFacebookSn(
            LDAPUtil.getAttributeString(attributes, contactMappings, ContactConverterKeys.FACEBOOK_SN));
    contact.setIcqSn(LDAPUtil.getAttributeString(attributes, contactMappings, ContactConverterKeys.ICQ_SN));
    contact.setJabberSn(
            LDAPUtil.getAttributeString(attributes, contactMappings, ContactConverterKeys.JABBER_SN));
    contact.setMsnSn(LDAPUtil.getAttributeString(attributes, contactMappings, ContactConverterKeys.MSN_SN));
    contact.setMySpaceSn(
            LDAPUtil.getAttributeString(attributes, contactMappings, ContactConverterKeys.MYSPACE_SN));
    contact.setSkypeSn(LDAPUtil.getAttributeString(attributes, contactMappings, ContactConverterKeys.SKYPE_SN));
    contact.setTwitterSn(
            LDAPUtil.getAttributeString(attributes, contactMappings, ContactConverterKeys.TWITTER_SN));
    contact.setYmSn(LDAPUtil.getAttributeString(attributes, contactMappings, ContactConverterKeys.YM_SN));
    contact.setJobTitle(
            LDAPUtil.getAttributeString(attributes, contactMappings, ContactConverterKeys.JOB_TITLE));

    ldapUser.setContact(contact);

    Map<String, String[]> contactExpandoAttributes = getExpandoAttributes(attributes, contactExpandoMappings);

    ldapUser.setContactExpandoAttributes(contactExpandoAttributes);

    Phone phone = PhoneUtil.create(0);

    phone.setNumber(
            (LDAPUtil.getAttributeString(attributes, contactMappings, CustomContactConverterKeys.PHONE)));

    ldapUser.setPhone(phone);

    Address address = AddressUtil.create(0);

    address.setCity(
            (LDAPUtil.getAttributeString(attributes, contactMappings, CustomContactConverterKeys.CITY)));
    address.setZip((LDAPUtil.getAttributeString(attributes, contactMappings, CustomContactConverterKeys.ZIP)));
    address.setStreet1(
            (LDAPUtil.getAttributeString(attributes, contactMappings, CustomContactConverterKeys.STREET)));

    ldapUser.setAddress(address);

    ldapUser.setCreatorUserId(0);
    ldapUser.setGroupIds(null);
    ldapUser.setOrganizationIds(null);
    ldapUser.setPasswordReset(false);

    Object portrait = LDAPUtil.getAttributeObject(attributes,
            userMappings.getProperty(UserConverterKeys.PORTRAIT));

    if (portrait != null) {
        byte[] portraitBytes = (byte[]) portrait;

        if (portraitBytes.length > 0) {
            ldapUser.setPortraitBytes((byte[]) portrait);
        }

        ldapUser.setUpdatePortrait(true);
    }

    ldapUser.setRoleIds(null);
    ldapUser.setSendEmail(false);

    ServiceContext serviceContext = new ServiceContext();

    String uuid = LDAPUtil.getAttributeString(attributes, userMappings, UserConverterKeys.UUID);

    serviceContext.setUuid(uuid);

    ldapUser.setServiceContext(serviceContext);

    ldapUser.setUpdatePassword(!password.equals(StringPool.BLANK));

    User user = UserUtil.create(0);

    user.setCompanyId(companyId);
    user.setEmailAddress(emailAddress);
    user.setFirstName(firstName);

    String jobTitle = LDAPUtil.getAttributeString(attributes, userMappings, UserConverterKeys.JOB_TITLE);

    user.setJobTitle(jobTitle);

    Locale locale = LocaleUtil.getDefault();

    user.setLanguageId(locale.toString());

    user.setLastName(lastName);
    user.setMiddleName(middleName);
    user.setOpenId(StringPool.BLANK);
    user.setPasswordUnencrypted(password);
    user.setScreenName(screenName);

    String status = LDAPUtil.getAttributeString(attributes, userMappings, UserConverterKeys.STATUS);

    if (Validator.isNotNull(status)) {
        user.setStatus(GetterUtil.getInteger(status));
    }

    ldapUser.setUser(user);

    Map<String, String[]> userExpandoAttributes = getExpandoAttributes(attributes, userExpandoMappings);

    ldapUser.setUserExpandoAttributes(userExpandoAttributes);

    ldapUser.setUserGroupIds(null);
    ldapUser.setUserGroupRoles(null);

    return ldapUser;
}

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;/*  ww  w  . j a  va 2 s.c o  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.documentlibrary.util.AudioProcessorImpl.java

License:Open Source License

public boolean isSupported(String mimeType) {
    if (Validator.isNull(mimeType)) {
        return false;
    }/*  ww  w  . j  a  v a2s . c o m*/

    try {
        if (PrefsPropsUtil.getBoolean(PropsKeys.XUGGLER_ENABLED, PropsValues.XUGGLER_ENABLED)) {

            return _audioMimeTypes.contains(mimeType);
        }
    } catch (Exception e) {
    }

    return false;
}

From source file:com.liferay.portlet.documentlibrary.util.AudioProcessorImpl.java

License:Open Source License

private void _generateAudio(FileVersion fileVersion) throws Exception {
    String tempFileId = DLUtil.getTempFileId(fileVersion.getFileEntryId(), fileVersion.getVersion());

    File audioTempFile = _getAudioTempFile(tempFileId, fileVersion.getExtension());
    File previewTempFile = getPreviewTempFile(tempFileId);

    try {//from   w  w  w . j  a v  a2 s .co m
        if (!PrefsPropsUtil.getBoolean(PropsKeys.XUGGLER_ENABLED, PropsValues.XUGGLER_ENABLED)
                || _hasAudio(fileVersion)) {

            return;
        }

        if (_isGeneratePreview(fileVersion)) {
            File file = null;

            if (fileVersion instanceof LiferayFileVersion) {
                try {
                    LiferayFileVersion liferayFileVersion = (LiferayFileVersion) fileVersion;

                    file = liferayFileVersion.getFile(false);
                } catch (UnsupportedOperationException uoe) {
                }
            }

            if (file == null) {
                InputStream inputStream = fileVersion.getContentStream(false);

                FileUtil.write(audioTempFile, inputStream);

                file = audioTempFile;
            }

            try {
                _generateAudioXuggler(fileVersion, file, previewTempFile);
            } catch (Exception e) {
                _log.error(e, e);
            }
        }
    } catch (NoSuchFileEntryException nsfee) {
    } finally {
        _fileVersionIds.remove(fileVersion.getFileVersionId());

        FileUtil.delete(audioTempFile);
        FileUtil.delete(previewTempFile);
    }
}

From source file:com.liferay.portlet.documentlibrary.util.DocumentConversionUtil.java

License:Open Source License

public static boolean isEnabled() {
    try {//from w  ww.ja  v a  2  s .  c o  m
        return PrefsPropsUtil.getBoolean(PropsKeys.OPENOFFICE_SERVER_ENABLED,
                PropsValues.OPENOFFICE_SERVER_ENABLED);
    } catch (Exception e) {
    }

    return false;
}

From source file:com.liferay.portlet.documentlibrary.util.VideoProcessorImpl.java

License:Open Source License

public boolean isSupported(String mimeType) {
    if (Validator.isNull(mimeType)) {
        return false;
    }/*from   w ww.  j av  a 2 s.  com*/

    try {
        if (PrefsPropsUtil.getBoolean(PropsKeys.XUGGLER_ENABLED, PropsValues.XUGGLER_ENABLED)) {

            return _videoMimeTypes.contains(mimeType);
        }
    } catch (Exception e) {
    }

    return false;
}

From source file:com.liferay.portlet.documentlibrary.util.VideoProcessorImpl.java

License:Open Source License

private void _generateVideo(FileVersion fileVersion) throws Exception {
    String tempFileId = DLUtil.getTempFileId(fileVersion.getFileEntryId(), fileVersion.getVersion());

    File videoTempFile = _getVideoTempFile(tempFileId, fileVersion.getExtension());

    File[] previewTempFiles = new File[_PREVIEW_TYPES.length];

    for (int i = 0; i < _PREVIEW_TYPES.length; i++) {
        previewTempFiles[i] = getPreviewTempFile(tempFileId, _PREVIEW_TYPES[i]);
    }//from  ww  w  .  jav  a2 s  .c om

    try {
        if (!PrefsPropsUtil.getBoolean(PropsKeys.XUGGLER_ENABLED, PropsValues.XUGGLER_ENABLED)
                || _hasVideo(fileVersion)) {

            return;
        }

        File file = null;

        if (_isGeneratePreview(fileVersion) || _isGenerateThumbnail(fileVersion)) {

            if (fileVersion instanceof LiferayFileVersion) {
                try {
                    LiferayFileVersion liferayFileVersion = (LiferayFileVersion) fileVersion;

                    file = liferayFileVersion.getFile(false);
                } catch (UnsupportedOperationException uoe) {
                }
            }

            if (file == null) {
                InputStream inputStream = fileVersion.getContentStream(false);

                FileUtil.write(videoTempFile, inputStream);

                file = videoTempFile;
            }
        }

        if (_isGeneratePreview(fileVersion)) {
            try {
                _generateVideoXuggler(fileVersion, file, previewTempFiles,
                        PropsValues.DL_FILE_ENTRY_PREVIEW_VIDEO_HEIGHT,
                        PropsValues.DL_FILE_ENTRY_PREVIEW_VIDEO_WIDTH);
            } catch (Exception e) {
                _log.error(e, e);
            }
        }

        if (_isGenerateThumbnail(fileVersion)) {
            try {
                _generateThumbnailXuggler(fileVersion, file, PropsValues.DL_FILE_ENTRY_PREVIEW_VIDEO_HEIGHT,
                        PropsValues.DL_FILE_ENTRY_PREVIEW_VIDEO_WIDTH);
            } catch (Exception e) {
                _log.error(e, e);
            }
        }
    } catch (NoSuchFileEntryException nsfee) {
    } finally {
        _fileVersionIds.remove(fileVersion.getFileVersionId());

        for (int i = 0; i < previewTempFiles.length; i++) {
            FileUtil.delete(previewTempFiles[i]);
        }

        FileUtil.delete(videoTempFile);
    }
}

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  ava 2 s .com*/
    }

    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();
}