Example usage for com.liferay.portal.kernel.util GetterUtil getInteger

List of usage examples for com.liferay.portal.kernel.util GetterUtil getInteger

Introduction

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

Prototype

public static int getInteger(String value) 

Source Link

Document

Returns the String value as an integer.

Usage

From source file:br.com.thiagomoreira.liferay.plugins.MarkdownDisplayPortlet.java

License:Apache License

@Override
public void render(RenderRequest request, RenderResponse response) throws PortletException, IOException {

    PortletPreferences preferences = request.getPreferences();
    String markdownURL = preferences.getValue("markdownURL", null);
    int timeToLive = 60 * GetterUtil.getInteger(preferences.getValue("timeToLive", "1"));
    boolean autolinks = GetterUtil.getBoolean(preferences.getValue("autolinks", "false"));
    boolean fencedBlockCodes = GetterUtil.getBoolean(preferences.getValue("fencedBlockCodes", "false"));
    boolean tables = GetterUtil.getBoolean(preferences.getValue("tables", "false"));

    if (Validator.isNotNull(markdownURL)) {
        PortalCache<Serializable, Object> portalCache = SingleVMPoolUtil
                .getCache(MarkdownDisplayPortlet.class.getName());

        String content = (String) portalCache.get(markdownURL);

        if (content == null) {
            int options = Extensions.NONE;
            if (autolinks) {
                options = options | Extensions.AUTOLINKS;
            }//from   ww  w  .  jav  a 2 s .c  o m
            if (fencedBlockCodes) {
                options = options | Extensions.FENCED_CODE_BLOCKS;
            }
            if (tables) {
                options = options | Extensions.TABLES;
            }

            PegDownProcessor processor = new PegDownProcessor(options);

            String markdownSource = HttpUtil.URLtoString(markdownURL);
            content = processor.markdownToHtml(markdownSource);

            portalCache.put(markdownURL, content, timeToLive);
        }

        request.setAttribute("content", content);
    } else {
        request.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, Boolean.TRUE);
    }

    super.render(request, response);
}

From source file:br.com.thiagomoreira.liferay.plugins.portalpropertiesprettier.PortalPropertiesPrettierPortlet.java

License:Apache License

protected void incrementCounter(PortletRequest request) throws IOException, PortletException {
    PortletPreferences preferences = request.getPreferences();

    int count = GetterUtil.getInteger(preferences.getValue("counter", "0"));

    count++;//ww w . j ava  2 s  . c o m

    preferences.setValue("counter", String.valueOf(count));
    preferences.store();
}

From source file:br.com.thiagomoreira.liferay.plugins.portalpropertiesprettier.PortalPropertiesPrettierPortletTest.java

License:Apache License

@Test
public void testIncrementCounter() throws Exception {
    int counter = 10;
    PortletPreferences preferences = new MockPortletPreferences();

    preferences.setValue("counter", String.valueOf(counter));

    MockPortletRequest request = new MockPortletRequest();

    request.setPreferences(preferences);

    PortalPropertiesPrettierPortlet portlet = new PortalPropertiesPrettierPortlet();

    portlet.incrementCounter(request);//from  w w w . j a  va 2s  . c  om

    String actual = preferences.getValue("counter", "0");

    Assert.assertEquals(counter + 1, GetterUtil.getInteger(actual));
}

From source file:ca.efendi.datafeeds.web.internal.portlet.DatafeedsPortlet.java

License:Apache License

protected int getStatus(final RenderRequest renderRequest) throws Exception {
    final ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    if (!themeDisplay.isSignedIn()) {
        return WorkflowConstants.STATUS_APPROVED;
    }//w ww . j av a 2  s.co  m
    final String value = renderRequest.getParameter("status");
    final int status = GetterUtil.getInteger(value);
    if ((value != null) && (status == WorkflowConstants.STATUS_APPROVED)) {
        return WorkflowConstants.STATUS_APPROVED;
    }
    final long resourcePrimKey = ParamUtil.getLong(renderRequest, "resourcePrimKey");
    if (resourcePrimKey == 0) {
        return WorkflowConstants.STATUS_APPROVED;
    }
    //final PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
    /**
     * if (KBArticlePermission.contains( permissionChecker, resourcePrimKey,
     * ActionKeys.UPDATE)) {
     *
     * return ParamUtil.getInteger( renderRequest, "status",
     * WorkflowConstants.STATUS_ANY); }
     */
    return WorkflowConstants.STATUS_APPROVED;
}

From source file:com.cd.learning.hook.MBUtil.java

License:Open Source License

public static String getUserRank(PortletPreferences preferences, String languageId, int posts)
        throws Exception {

    String rank = StringPool.BLANK;

    String[] ranks = LocalizationUtil.getPreferencesValues(preferences, "ranks", languageId);

    for (int i = 0; i < ranks.length; i++) {
        String[] kvp = StringUtil.split(ranks[i], CharPool.EQUAL);

        String kvpName = kvp[0];/*from w w  w. j  a v a2 s .  c o  m*/
        int kvpPosts = GetterUtil.getInteger(kvp[1]);

        if (posts >= kvpPosts) {
            rank = kvpName;
        } else {
            break;
        }
    }

    return rank;
}

From source file:com.cd.learning.hook.MBUtil.java

License:Open Source License

public static String[] getUserRank(PortletPreferences preferences, String languageId, MBStatsUser statsUser)
        throws Exception {

    String[] rank = { StringPool.BLANK, StringPool.BLANK };

    int maxPosts = 0;

    Group group = GroupLocalServiceUtil.getGroup(statsUser.getGroupId());

    long companyId = group.getCompanyId();

    String[] ranks = LocalizationUtil.getPreferencesValues(preferences, "ranks", languageId);

    for (int i = 0; i < ranks.length; i++) {
        String[] kvp = StringUtil.split(ranks[i], CharPool.EQUAL);

        String curRank = kvp[0];//from   ww  w .j  av a 2s. co m
        String curRankValue = kvp[1];

        String[] curRankValueKvp = StringUtil.split(curRankValue, CharPool.COLON);

        if (curRankValueKvp.length <= 1) {
            int posts = GetterUtil.getInteger(curRankValue);

            if ((posts <= statsUser.getMessageCount()) && (posts >= maxPosts)) {

                rank[0] = curRank;
                maxPosts = posts;
            }
        } else {
            String entityType = curRankValueKvp[0];
            String entityValue = curRankValueKvp[1];

            try {
                if (_isEntityRank(companyId, statsUser, entityType, entityValue)) {

                    rank[1] = curRank;

                    break;
                }
            } catch (Exception e) {
                if (_log.isWarnEnabled()) {
                    _log.warn(e);
                }
            }
        }
    }

    return rank;
}

From source file:com.cmcti.cmts.domain.service.impl.MerchantScopeLocalServiceImpl.java

License:Open Source License

private List<MerchantScope> getMerchants(Iterator<Row> rowIterator, int startRowIdx,
        ServiceContext serviceContext) throws PortalException, SystemException {

    List<MerchantScope> merchants = new ArrayList<MerchantScope>();

    if (startRowIdx > 0) {
        for (int i = 0; i < startRowIdx; i++) {
            if (rowIterator.hasNext())
                rowIterator.next();/*from  ww  w  .j  a  va 2  s . c  o  m*/
        }
    }

    while (rowIterator.hasNext()) {
        Row row = rowIterator.next();

        long merchantScopeId = counterLocalService.increment(MerchantScope.class.getName());
        MerchantScope merchantScope = merchantScopePersistence.create(merchantScopeId);

        // Meta data
        merchantScope.setUserId(serviceContext.getUserId());
        merchantScope.setGroupId(serviceContext.getScopeGroupId());
        merchantScope.setCompanyId(serviceContext.getCompanyId());
        merchantScope.setCreateDate(serviceContext.getCreateDate());
        merchantScope.setModifiedDate(serviceContext.getModifiedDate());

        // CMTSID
        Cell cmtsIdCell = row.getCell(0);
        merchantScope.setCmtsId(GetterUtil.getLong(cmtsIdCell.getStringCellValue()));

        // IfIndex
        Cell ifIndexCell = row.getCell(1);
        merchantScope.setIfIndex(GetterUtil.getInteger(ifIndexCell.getStringCellValue()));

        // Merchat Code
        Cell merchantCodeCell = row.getCell(2);
        merchantScope.setMerchantCode(merchantCodeCell.getStringCellValue());

        merchants.add(merchantScope);
    }

    return merchants;
}

From source file:com.crm.report.util.ReportPreferences.java

License:Open Source License

public static int getRefreshTime(PortletPreferences preferences) {
    return GetterUtil.getInteger(preferences.getValue("refresh-time", "0"));
}

From source file:com.crm.report.util.ReportPreferences.java

License:Open Source License

public static int getHeight(PortletPreferences preferences) {
    return GetterUtil.getInteger(preferences.getValue("height", "300"));
}

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 w w w  .j a  v  a2s .  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;
}