Example usage for com.liferay.portal.kernel.util StringUtil contains

List of usage examples for com.liferay.portal.kernel.util StringUtil contains

Introduction

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

Prototype

public static boolean contains(String s, String text) 

Source Link

Document

Returns true if the string contains the text as one or more consecutive comma delimited list entries.

Usage

From source file:com.beorn.onlinepayment.rule.parameter.ParameterListContainsCondition.java

License:Open Source License

public boolean isSatisfiedBy(ParametersConditionSubject subject) {
    String parameter = subject.getParameter(_key);
    return parameter != null && StringUtil.contains(parameter, _value);
}

From source file:com.liferay.adaptive.media.blogs.editor.configuration.internal.stat1c.StaticAdaptiveMediaBlogsEditorConfigContributor.java

License:Open Source License

@Override
public void populateConfigJSONObject(JSONObject jsonObject, Map<String, Object> inputEditorTaglibAttributes,
        ThemeDisplay themeDisplay, RequestBackedPortletURLFactory requestBackedPortletURLFactory) {

    String extraPlugins = jsonObject.getString("extraPlugins");

    if (StringUtil.contains(extraPlugins, "adaptivemedia")) {
        return;//  w  w  w .ja  v a  2  s  .  co  m
    }

    String itemSelectorURL = jsonObject.getString("filebrowserImageBrowseLinkUrl");

    if (Validator.isNull(itemSelectorURL)) {
        return;
    }

    List<ItemSelectorCriterion> itemSelectorCriteria = _itemSelector.getItemSelectorCriteria(itemSelectorURL);

    boolean adaptiveMediaImageURLItemSelectorReturnTypeAdded = false;

    for (ItemSelectorCriterion itemSelectorCriterion : itemSelectorCriteria) {

        if (itemSelectorCriterion instanceof BlogsItemSelectorCriterion
                || itemSelectorCriterion instanceof FileItemSelectorCriterion
                || itemSelectorCriterion instanceof ImageItemSelectorCriterion
                || itemSelectorCriterion instanceof UploadItemSelectorCriterion) {

            addAdaptiveMediaImageURLItemSelectorReturnType(itemSelectorCriterion);

            adaptiveMediaImageURLItemSelectorReturnTypeAdded = true;
        }
    }

    if (!adaptiveMediaImageURLItemSelectorReturnTypeAdded) {
        return;
    }

    if (Validator.isNotNull(extraPlugins)) {
        extraPlugins = extraPlugins + ",adaptivemedia";
    } else {
        extraPlugins = "adaptivemedia";
    }

    jsonObject.put("extraPlugins", extraPlugins);

    String itemSelectedEventName = _itemSelector.getItemSelectedEventName(itemSelectorURL);

    PortletURL itemSelectorPortletURL = _itemSelector.getItemSelectorURL(requestBackedPortletURLFactory,
            itemSelectedEventName,
            itemSelectorCriteria.toArray(new ItemSelectorCriterion[itemSelectorCriteria.size()]));

    jsonObject.put("filebrowserImageBrowseLinkUrl", itemSelectorPortletURL.toString());
    jsonObject.put("filebrowserImageBrowseUrl", itemSelectorPortletURL.toString());

    _allowTagRule(jsonObject, _PICTURE_TAG_RULE);
    _allowTagRule(jsonObject, _IMG_TAG_RULE);
}

From source file:com.liferay.journal.util.impl.JournalUtil.java

License:Open Source License

public static String prepareLocalizedContentForImport(String content, Locale defaultImportLocale)
        throws LocaleException {

    try {/*ww w  . ja va 2 s. com*/
        Document oldDocument = SAXReaderUtil.read(content);

        Document newDocument = SAXReaderUtil.read(content);

        Element newRootElement = newDocument.getRootElement();

        Attribute availableLocalesAttribute = newRootElement.attribute("available-locales");

        if (availableLocalesAttribute == null) {
            newRootElement = newRootElement.addAttribute("available-locales", StringPool.BLANK);

            availableLocalesAttribute = newRootElement.attribute("available-locales");
        }

        String defaultImportLanguageId = LocaleUtil.toLanguageId(defaultImportLocale);

        if (!StringUtil.contains(availableLocalesAttribute.getValue(), defaultImportLanguageId)) {

            if (Validator.isNull(availableLocalesAttribute.getValue())) {
                availableLocalesAttribute.setValue(defaultImportLanguageId);
            } else {
                availableLocalesAttribute.setValue(
                        availableLocalesAttribute.getValue() + StringPool.COMMA + defaultImportLanguageId);
            }

            _mergeArticleContentUpdate(oldDocument, newRootElement,
                    LocaleUtil.toLanguageId(defaultImportLocale));

            content = XMLUtil.formatXML(newDocument);
        }

        Attribute defaultLocaleAttribute = newRootElement.attribute("default-locale");

        if (defaultLocaleAttribute == null) {
            newRootElement = newRootElement.addAttribute("default-locale", StringPool.BLANK);

            defaultLocaleAttribute = newRootElement.attribute("default-locale");
        }

        Locale defaultContentLocale = LocaleUtil.fromLanguageId(defaultLocaleAttribute.getValue());

        if (!LocaleUtil.equals(defaultContentLocale, defaultImportLocale)) {
            defaultLocaleAttribute.setValue(defaultImportLanguageId);

            content = XMLUtil.formatXML(newDocument);
        }
    } catch (Exception e) {
        throw new LocaleException(LocaleException.TYPE_CONTENT,
                "The locale " + defaultImportLocale + " is not available");
    }

    return content;
}

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

License:Open Source License

public Message updateFlag(long messageId, int flag, boolean value) throws PortalException {

    String flagString = String.valueOf(flag);

    Message message = messagePersistence.findByPrimaryKey(messageId);

    String flags = message.getFlags();

    if (value && !StringUtil.contains(flags, flagString)) {
        message.setFlags(StringUtil.add(flags, flagString));
    } else if (!value && StringUtil.contains(flags, flagString)) {
        message.setFlags(StringUtil.remove(flags, flagString));
    }/* w w w .ja v  a 2s. com*/

    return messagePersistence.update(message);
}

From source file:com.liferay.mobile.device.rules.rule.group.action.BaseRedirectActionHandler.java

License:Open Source License

@Override
public void applyAction(MDRAction mdrAction, HttpServletRequest request, HttpServletResponse response)
        throws PortalException {

    String url = getURL(mdrAction, request, response);

    if (Validator.isNull(url)) {
        if (_log.isInfoEnabled()) {
            _log.info("URL is null");
        }//from w w w .  j  a v a2  s  . c  o  m

        return;
    }

    String requestURL = String.valueOf(request.getRequestURL());

    if (StringUtil.contains(requestURL, url)) {
        if (_log.isInfoEnabled()) {
            _log.info("Skipping redirect. Current URL contains redirect URL.");
        }

        return;
    }

    try {
        response.sendRedirect(url);
    } catch (IOException ioe) {
        throw new PortalException("Unable to redirect to " + url, ioe);
    }
}

From source file:com.liferay.opensocial.model.impl.GadgetConstants.java

License:Open Source License

public static boolean isAdhocGadget(String gadgetKey) {
    return StringUtil.contains(gadgetKey, ADHOC_PREFIX);
}

From source file:com.liferay.opensocial.model.impl.GadgetConstants.java

License:Open Source License

public static boolean isPublishedGadget(String gadgetKey) {
    return StringUtil.contains(gadgetKey, PUBLISHED_PREFIX);
}

From source file:com.liferay.so.hook.upgrade.v3_0_0.UpgradeLayout.java

License:Open Source License

protected void updateSOAnnouncements(final long companyId) throws Exception {

    ActionableDynamicQuery actionableDynamicQuery = new LayoutActionableDynamicQuery() {

        @Override/*from  ww w  .j a va  2  s. c om*/
        protected void performAction(Object object) throws PortalException {
            Layout layout = (Layout) object;

            if (!SocialOfficeServiceUtil.isSocialOfficeGroup(layout.getGroupId())) {

                return;
            }

            Group group = GroupLocalServiceUtil.fetchGroup(layout.getGroupId());

            if (layout.isPublicLayout() && group.isUser()) {
                return;
            }

            LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

            if (layoutTypePortlet.hasPortletId(PortletKeys.SO_ANNOUNCEMENTS)) {

                return;
            }

            UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

            if (layoutTypePortlet.hasPortletId(PortletKeys.ANNOUNCEMENTS)) {
                LayoutTemplate layoutTemplate = layoutTypePortlet.getLayoutTemplate();

                for (String columnName : layoutTemplate.getColumns()) {
                    String columnValue = typeSettingsProperties.getProperty(columnName);

                    columnValue = StringUtil.replace(columnValue, PortletKeys.ANNOUNCEMENTS,
                            PortletKeys.SO_ANNOUNCEMENTS);

                    typeSettingsProperties.setProperty(columnName, columnValue);
                }

                layout.setTypeSettingsProperties(typeSettingsProperties);
            } else {
                if (layout.getPriority() != 0) {
                    return;
                }

                if (layout.getGroupId() == _layoutSetPrototypeGroupId) {
                    return;
                }

                String columnValue = typeSettingsProperties.getProperty("column-1");

                if (Validator.isNull(columnValue)) {
                    return;
                }

                int columnPos = 0;

                if (StringUtil.contains(columnValue, PortletKeys.MICROBLOGS_STATUS_UPDATE)) {

                    columnPos = 1;
                }

                layoutTypePortlet.addPortletId(0, PortletKeys.SO_ANNOUNCEMENTS, "column-1", columnPos, false);

                layout = layoutTypePortlet.getLayout();
            }

            LayoutLocalServiceUtil.updateLayout(layout);

            LayoutUtil.addResources(layout, PortletKeys.SO_ANNOUNCEMENTS);
        }

        protected long getLayoutSetPrototypeGroupId(long companyId, String layoutSetPrototypeKey)
                throws Exception {

            LayoutSetPrototype layoutSetPrototype = LayoutSetPrototypeUtil.fetchLayoutSetPrototype(companyId,
                    layoutSetPrototypeKey);

            if (layoutSetPrototype != null) {
                return layoutSetPrototype.getGroupId();
            }

            return 0;
        }

        private long _layoutSetPrototypeGroupId = getLayoutSetPrototypeGroupId(companyId,
                SocialOfficeConstants.LAYOUT_SET_PROTOTYPE_KEY_USER_PUBLIC);

    };

    actionableDynamicQuery.setCompanyId(companyId);

    actionableDynamicQuery.performActions();
}

From source file:org.opencps.dossiermgt.service.persistence.DossierFinderImpl.java

License:Open Source License

/**
 * @param groupId// ww w  .j  a  v  a  2  s  .  c o  m
 * @param userId
 * @param keywords
 * @param serviceDomainTreeIndex
 * @param dossierStatus
 * @param andOperator
 * @return
 */
private int countDossierByUser(long groupId, long userId, String[] keywords, String serviceDomainTreeIndex,
        String dossierStatus, boolean andOperator) {

    Session session = null;

    try {
        session = openSession();

        String sql = CustomSQLUtil.get(COUNT_DOSSIER_BY_USER);

        if (keywords != null && keywords.length > 0) {
            sql = CustomSQLUtil.replaceKeywords(sql, "lower(opencps_serviceinfo.serviceName)", StringPool.LIKE,
                    true, keywords);

            sql = CustomSQLUtil.replaceKeywords(sql, "lower(opencps_service_config.govAgencyName)",
                    StringPool.LIKE, true, keywords);

            sql = CustomSQLUtil.replaceKeywords(sql, "lower(opencps_dossier.subjectName)", StringPool.LIKE,
                    true, keywords);

            sql = CustomSQLUtil.replaceKeywords(sql, "lower(opencps_dossier.receptionNo)", StringPool.LIKE,
                    true, keywords);
        } else {
            sql = StringUtil.replace(sql,
                    "AND ((lower(opencps_serviceinfo.serviceName) LIKE ? [$AND_OR_NULL_CHECK$]) OR (lower(opencps_service_config.govAgencyName) LIKE ? [$AND_OR_NULL_CHECK$]) OR (lower(opencps_dossier.subjectName) LIKE ? [$AND_OR_NULL_CHECK$]) OR (lower(opencps_dossier.receptionNo) LIKE ? [$AND_OR_NULL_CHECK$]))",
                    StringPool.BLANK);
        }

        if (Validator.isNull(serviceDomainTreeIndex)) {

            sql = StringUtil.replace(sql,
                    "AND (opencps_dossier.serviceDomainIndex LIKE ? OR opencps_dossier.serviceDomainIndex = ?)",
                    StringPool.BLANK);
        } else {
            if (StringUtil.contains(serviceDomainTreeIndex, StringPool.PERIOD)) {
                sql = StringUtil.replace(sql,
                        "AND (opencps_dossier.serviceDomainIndex LIKE ? OR opencps_dossier.serviceDomainIndex = ?)",
                        "AND (opencps_dossier.serviceDomainIndex LIKE ?)");

                serviceDomainTreeIndex = serviceDomainTreeIndex.substring(0,
                        serviceDomainTreeIndex.indexOf(StringPool.PERIOD) + 1);

            }

        }

        if (Validator.isNull(dossierStatus)) {
            sql = StringUtil.replace(sql, "AND (opencps_dossier.dossierStatus = ?)", StringPool.BLANK);
        }

        sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);

        SQLQuery q = session.createSQLQuery(sql);

        q.addScalar(COUNT_COLUMN_NAME, Type.INTEGER);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(userId);

        if (Validator.isNotNull(serviceDomainTreeIndex)
                && StringUtil.contains(serviceDomainTreeIndex, StringPool.PERIOD)) {
            qPos.add(serviceDomainTreeIndex + StringPool.PERCENT);

        } else if (Validator.isNotNull(serviceDomainTreeIndex)
                && !StringUtil.contains(serviceDomainTreeIndex, StringPool.PERIOD)) {
            qPos.add(serviceDomainTreeIndex + StringPool.PERIOD + StringPool.PERCENT);
            qPos.add(serviceDomainTreeIndex);
        }

        if (keywords != null && keywords.length > 0) {
            qPos.add(keywords, 2);
            qPos.add(keywords, 2);
            qPos.add(keywords, 2);
            qPos.add(keywords, 2);
        }

        if (Validator.isNotNull(dossierStatus)) {
            qPos.add(dossierStatus);
        }

        Iterator<Integer> itr = q.iterate();

        if (itr.hasNext()) {
            Integer count = itr.next();

            if (count != null) {
                return count.intValue();
            }
        }

        return 0;

    } catch (Exception e) {
        _log.error(e);
    } finally {
        closeSession(session);
    }

    return 0;
}

From source file:org.opencps.dossiermgt.service.persistence.DossierFinderImpl.java

License:Open Source License

/**
 * @param groupId//from w ww  .j av a  2  s  .  c  o  m
 * @param userId
 * @param keywords
 * @param serviceDomainTreeIndex
 * @param dossierStatus
 * @param andOperator
 * @param start
 * @param end
 * @param obc
 * @return
 */
private List<DossierBean> searchDossierByUser(long groupId, long userId, String[] keywords,
        String serviceDomainTreeIndex, String dossierStatus, boolean andOperator, int start, int end,
        OrderByComparator obc) {

    Session session = null;

    try {
        session = openSession();

        String sql = CustomSQLUtil.get(SEARCH_DOSSIER_BY_USER);

        if (keywords != null && keywords.length > 0) {
            sql = CustomSQLUtil.replaceKeywords(sql, "lower(opencps_serviceinfo.serviceName)", StringPool.LIKE,
                    true, keywords);

            sql = CustomSQLUtil.replaceKeywords(sql, "lower(opencps_service_config.govAgencyName)",
                    StringPool.LIKE, true, keywords);

            sql = CustomSQLUtil.replaceKeywords(sql, "lower(opencps_dossier.subjectName)", StringPool.LIKE,
                    true, keywords);

            sql = CustomSQLUtil.replaceKeywords(sql, "lower(opencps_dossier.receptionNo)", StringPool.LIKE,
                    true, keywords);
        } else {
            sql = StringUtil.replace(sql,
                    "AND ((lower(opencps_serviceinfo.serviceName) LIKE ? [$AND_OR_NULL_CHECK$]) OR (lower(opencps_service_config.govAgencyName) LIKE ? [$AND_OR_NULL_CHECK$]) OR (lower(opencps_dossier.subjectName) LIKE ? [$AND_OR_NULL_CHECK$]) OR (lower(opencps_dossier.receptionNo) LIKE ? [$AND_OR_NULL_CHECK$]))",
                    StringPool.BLANK);
        }

        if (Validator.isNull(serviceDomainTreeIndex)) {

            sql = StringUtil.replace(sql,
                    "AND (opencps_dossier.serviceDomainIndex LIKE ? OR opencps_dossier.serviceDomainIndex = ?)",
                    StringPool.BLANK);
        } else {
            if (StringUtil.contains(serviceDomainTreeIndex, StringPool.PERIOD)) {
                sql = StringUtil.replace(sql,
                        "AND (opencps_dossier.serviceDomainIndex LIKE ? OR opencps_dossier.serviceDomainIndex = ?)",
                        "AND (opencps_dossier.serviceDomainIndex LIKE ?)");

                serviceDomainTreeIndex = serviceDomainTreeIndex.substring(0,
                        serviceDomainTreeIndex.indexOf(StringPool.PERIOD) + 1);

            }

        }

        if (Validator.isNull(dossierStatus)) {
            sql = StringUtil.replace(sql, "AND (opencps_dossier.dossierStatus = ?)", StringPool.BLANK);
        }

        sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);

        SQLQuery q = session.createSQLQuery(sql);

        q.addEntity("Dossier", DossierImpl.class);
        q.addScalar("SERVICE_NAME", Type.STRING);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(userId);

        if (Validator.isNotNull(serviceDomainTreeIndex)
                && StringUtil.contains(serviceDomainTreeIndex, StringPool.PERIOD)) {
            qPos.add(serviceDomainTreeIndex + StringPool.PERCENT);

        } else if (Validator.isNotNull(serviceDomainTreeIndex)
                && !StringUtil.contains(serviceDomainTreeIndex, StringPool.PERIOD)) {
            qPos.add(serviceDomainTreeIndex + StringPool.PERIOD + StringPool.PERCENT);
            qPos.add(serviceDomainTreeIndex);
        }

        if (keywords != null && keywords.length > 0) {
            qPos.add(keywords, 2);
            qPos.add(keywords, 2);
            qPos.add(keywords, 2);
            qPos.add(keywords, 2);
        }

        if (Validator.isNotNull(dossierStatus)) {
            qPos.add(dossierStatus);
        }

        Iterator<Object[]> itr = (Iterator<Object[]>) QueryUtil.list(q, getDialect(), start, end).iterator();

        List<DossierBean> dossierBeans = new ArrayList<DossierBean>();

        if (itr.hasNext()) {
            while (itr.hasNext()) {
                DossierBean dossierBean = new DossierBean();

                Object[] objects = itr.next();

                Dossier dossier = (Dossier) objects[0];

                String serviceName = (String) objects[1];

                dossierBean.setDossierId(dossier.getDossierId());
                dossierBean.setDossier(dossier);
                dossierBean.setServiceName(serviceName);

                dossierBeans.add(dossierBean);

            }
        }

        return dossierBeans;

    } catch (Exception e) {
        _log.error(e);
    } finally {
        closeSession(session);
    }

    return null;
}