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

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

Introduction

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

Prototype

public static boolean startsWith(String s, String start) 

Source Link

Document

Returns true if, ignoring case, the string starts with the specified start string.

Usage

From source file:com.liferay.alloy.util.DefaultValueUtil.java

License:Open Source License

public static String getDefaultValue(String className, String value) {
    String defaultValue = StringPool.BLANK;

    if (className.equals(ArrayList.class.getName()) || className.equals(HashMap.class.getName())
            || className.equals(Object.class.getName()) || className.equals(String.class.getName())) {

        if (!isValidStringValue(value)) {
            return defaultValue;
        }/*w w w. jav  a 2s  .  c om*/

        if (_EMPTY_STRINGS.contains(value)) {
            value = StringPool.BLANK;
        } else if (className.equals(ArrayList.class.getName())
                && !StringUtil.startsWith(value.trim(), StringPool.OPEN_BRACKET)) {

            value = "[]";
        } else if (className.equals(HashMap.class.getName())
                && !StringUtil.startsWith(value.trim(), StringPool.OPEN_CURLY_BRACE)) {

            value = "{}";
        }

        defaultValue = StringUtil.unquote(value);
    } else if (className.equals(boolean.class.getName()) || className.equals(Boolean.class.getName())) {

        defaultValue = String.valueOf(GetterUtil.getBoolean(value));
    } else if (className.equals(int.class.getName()) || className.equals(Integer.class.getName())) {

        if (_INFINITY.contains(value)) {
            value = String.valueOf(Integer.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getInteger(value));
    } else if (className.equals(double.class.getName()) || className.equals(Double.class.getName())) {

        if (_INFINITY.contains(value)) {
            value = String.valueOf(Double.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getDouble(value));
    } else if (className.equals(float.class.getName()) || className.equals(Float.class.getName())) {

        if (_INFINITY.contains(value)) {
            value = String.valueOf(Float.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getFloat(value));
    } else if (className.equals(long.class.getName()) || className.equals(Long.class.getName())) {

        if (_INFINITY.contains(value)) {
            value = String.valueOf(Long.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getLong(value));
    } else if (className.equals(short.class.getName()) || className.equals(Short.class.getName())) {

        if (_INFINITY.contains(value)) {
            value = String.valueOf(Short.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getShort(value));
    } else if (className.equals(Number.class.getName())) {
        if (_INFINITY.contains(value)) {
            value = String.valueOf(Integer.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getNumber(value));
    }

    return defaultValue;
}

From source file:com.liferay.asset.publisher.web.internal.exportimport.portlet.preferences.processor.AssetPublisherExportImportPortletPreferencesProcessor.java

License:Open Source License

protected PortletPreferences updateExportPortletPreferences(PortletDataContext portletDataContext,
        String portletId, PortletPreferences portletPreferences) throws Exception {

    String anyAssetTypeString = portletPreferences.getValue("anyAssetType", null);

    String selectionStyle = portletPreferences.getValue("selectionStyle", null);

    if (Validator.isNotNull(selectionStyle) && selectionStyle.equals("manual")) {

        portletPreferences.reset("anyAssetType");

        anyAssetTypeString = portletPreferences.getValue("anyAssetType", null);
    } else if (Validator.isNotNull(anyAssetTypeString) && anyAssetTypeString.equals("false")) {

        String[] classNameIds = portletPreferences.getValues("classNameIds", StringPool.EMPTY_ARRAY);

        if (classNameIds.length == 1) {
            portletPreferences.setValue("anyAssetType", classNameIds[0]);

            anyAssetTypeString = portletPreferences.getValue("anyAssetType", null);

            portletPreferences.reset("classNameIds");
        }//from  w  w w.j  a va  2s.co  m
    }

    String anyAssetTypeClassName = StringPool.BLANK;

    long anyAssetType = GetterUtil.getLong(anyAssetTypeString);

    if (anyAssetType > 0) {
        anyAssetTypeClassName = portal.getClassName(anyAssetType);
    }

    Portlet portlet = _portletLocalService.getPortletById(portletDataContext.getCompanyId(), portletId);

    Enumeration<String> enu = portletPreferences.getNames();

    while (enu.hasMoreElements()) {
        String name = enu.nextElement();

        String value = GetterUtil.getString(portletPreferences.getValue(name, null));

        if (name.equals("anyAssetType") || name.equals("classNameIds")) {
            if (name.equals("classNameIds") && Validator.isNotNull(anyAssetTypeString)
                    && !anyAssetTypeString.equals("false")) {

                portletPreferences.reset(name);
            } else {
                updateExportClassNameIds(portletPreferences, name);
            }
        } else if (name.equals("anyClassTypeDLFileEntryAssetRendererFactory")
                || (name.equals("classTypeIds") && anyAssetTypeClassName.equals(DLFileEntry.class.getName()))
                || name.equals("classTypeIdsDLFileEntryAssetRendererFactory")) {

            String anyClassTypeDLFileEntryAssetRendererFactory = portletPreferences
                    .getValue("anyClassTypeDLFileEntryAssetRendererFactory", null);

            String[] classTypeIdsDLFileEntryAssetRendererFactory = portletPreferences
                    .getValues("classTypeIdsDLFileEntryAssetRendererFactory", StringPool.EMPTY_ARRAY);

            if (Validator.isNotNull(anyClassTypeDLFileEntryAssetRendererFactory)
                    && anyClassTypeDLFileEntryAssetRendererFactory.equals("false")
                    && (classTypeIdsDLFileEntryAssetRendererFactory.length == 1)) {

                portletPreferences.setValue("anyClassTypeDLFileEntryAssetRendererFactory",
                        classTypeIdsDLFileEntryAssetRendererFactory[0]);

                portletPreferences.reset("classTypeIdsDLFileEntryAssetRendererFactory");

                anyClassTypeDLFileEntryAssetRendererFactory = portletPreferences
                        .getValue("anyClassTypeDLFileEntryAssetRendererFactory", null);
            }

            if (!anyAssetTypeClassName.equals(DLFileEntry.class.getName())
                    || (name.equals("classTypeIdsDLFileEntryAssetRendererFactory")
                            && Validator.isNotNull(anyClassTypeDLFileEntryAssetRendererFactory)
                            && !anyClassTypeDLFileEntryAssetRendererFactory.equals("false"))) {

                portletPreferences.reset(name);
            } else {
                updateExportPortletPreferencesClassPKs(portletDataContext, portlet, portletPreferences, name,
                        DLFileEntryType.class.getName());
            }
        } else if (name.equals("anyClassTypeJournalArticleAssetRendererFactory")
                || (name.equals("classTypeIds") && anyAssetTypeClassName.equals(JournalArticle.class.getName()))
                || name.equals("classTypeIdsJournalArticleAssetRendererFactory")) {

            String anyClassTypeJournalArticleAssetRendererFactory = portletPreferences
                    .getValue("anyClassTypeJournalArticleAssetRendererFactory", null);

            String[] classTypeIdsJournalArticleAssetRendererFactory = portletPreferences
                    .getValues("classTypeIdsJournalArticleAssetRendererFactory", StringPool.EMPTY_ARRAY);

            if (Validator.isNotNull(anyClassTypeJournalArticleAssetRendererFactory)
                    && anyClassTypeJournalArticleAssetRendererFactory.equals("false")
                    && (classTypeIdsJournalArticleAssetRendererFactory.length == 1)) {

                portletPreferences.setValue("anyClassTypeJournalArticleAssetRendererFactory",
                        classTypeIdsJournalArticleAssetRendererFactory[0]);

                portletPreferences.reset("classTypeIdsJournalArticleAssetRendererFactory");

                anyClassTypeJournalArticleAssetRendererFactory = portletPreferences
                        .getValue("anyClassTypeJournalArticleAssetRendererFactory", null);
            }

            if (!anyAssetTypeClassName.equals(JournalArticle.class.getName())
                    || (name.equals("classTypeIdsJournalArticleAssetRendererFactory")
                            && Validator.isNotNull(anyClassTypeJournalArticleAssetRendererFactory)
                            && !anyClassTypeJournalArticleAssetRendererFactory.equals("false"))) {

                portletPreferences.reset(name);
            } else {
                updateExportPortletPreferencesClassPKs(portletDataContext, portlet, portletPreferences, name,
                        DDMStructure.class.getName());
            }
        } else if (name.equals("assetVocabularyId")) {
            long assetVocabularyId = GetterUtil.getLong(value);

            AssetVocabulary assetVocabulary = _assetVocabularyLocalService
                    .fetchAssetVocabulary(assetVocabularyId);

            if (assetVocabulary != null) {
                StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, portletId,
                        assetVocabulary);
            }

            updateExportPortletPreferencesClassPKs(portletDataContext, portlet, portletPreferences, name,
                    AssetVocabulary.class.getName());
        } else if (name.startsWith("orderByColumn")
                && StringUtil.startsWith(value, DDMStructureManager.STRUCTURE_INDEXER_FIELD_PREFIX)) {

            updateExportOrderByColumnClassPKs(portletDataContext, portlet, portletPreferences, name);
        } else if (name.startsWith("queryName") && StringUtil.equalsIgnoreCase(value, "assetCategories")) {

            String index = name.substring(9);

            long assetCategoryId = GetterUtil.getLong(portletPreferences.getValue("queryValues" + index, null));

            AssetCategory assetCategory = _assetCategoryLocalService.fetchAssetCategory(assetCategoryId);

            if (assetCategory != null) {
                StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, portletId,
                        assetCategory);
            }

            updateExportPortletPreferencesClassPKs(portletDataContext, portlet, portletPreferences,
                    "queryValues" + index, AssetCategory.class.getName());
        } else if (name.equals("scopeIds")) {
            updateExportScopeIds(portletDataContext, portletPreferences, name, portletDataContext.getPlid());
        }
    }

    return portletPreferences;
}

From source file:com.liferay.asset.publisher.web.internal.exportimport.portlet.preferences.processor.AssetPublisherExportImportPortletPreferencesProcessor.java

License:Open Source License

protected PortletPreferences updateImportPortletPreferences(PortletDataContext portletDataContext,
        PortletPreferences portletPreferences) throws Exception {

    Company company = _companyLocalService.getCompanyById(portletDataContext.getCompanyId());

    Group companyGroup = company.getGroup();

    String anyAssetTypeClassName = portletPreferences.getValue("anyAssetType", StringPool.BLANK);

    Enumeration<String> enu = portletPreferences.getNames();

    while (enu.hasMoreElements()) {
        String name = enu.nextElement();

        String value = GetterUtil.getString(portletPreferences.getValue(name, null));

        if (name.equals("anyAssetType") || name.equals("classNameIds")) {
            updateImportClassNameIds(portletPreferences, name);
        } else if (name.equals("anyClassTypeDLFileEntryAssetRendererFactory")
                || (name.equals("classTypeIds") && anyAssetTypeClassName.equals(DLFileEntry.class.getName()))
                || name.equals("classTypeIdsDLFileEntryAssetRendererFactory")) {

            updateImportPortletPreferencesClassPKs(portletDataContext, portletPreferences, name,
                    DLFileEntryType.class, companyGroup.getGroupId());
        } else if (name.equals("anyClassTypeJournalArticleAssetRendererFactory")
                || (name.equals("classTypeIds") && anyAssetTypeClassName.equals(JournalArticle.class.getName()))
                || name.equals("classTypeIdsJournalArticleAssetRendererFactory")) {

            updateImportPortletPreferencesClassPKs(portletDataContext, portletPreferences, name,
                    DDMStructure.class, companyGroup.getGroupId());
        } else if (name.equals("assetVocabularyId")) {
            updateImportPortletPreferencesClassPKs(portletDataContext, portletPreferences, name,
                    AssetVocabulary.class, companyGroup.getGroupId());
        } else if (name.startsWith("orderByColumn")
                && StringUtil.startsWith(value, DDMStructureManager.STRUCTURE_INDEXER_FIELD_PREFIX)) {

            updateImportOrderByColumnClassPKs(portletDataContext, portletPreferences, name,
                    companyGroup.getGroupId());
        } else if (name.startsWith("queryName") && StringUtil.equalsIgnoreCase(value, "assetCategories")) {

            String index = name.substring(9);

            updateImportPortletPreferencesClassPKs(portletDataContext, portletPreferences,
                    "queryValues" + index, AssetCategory.class, companyGroup.getGroupId());
        } else if (name.equals("scopeIds")) {
            updateImportScopeIds(portletDataContext, portletPreferences, name, companyGroup.getGroupId(),
                    portletDataContext.getPlid());
        }//from w  w w.  j a  v a2 s. co  m
    }

    restorePortletPreference(portletDataContext, "notifiedAssetEntryIds", portletPreferences);

    return portletPreferences;
}

From source file:com.liferay.dynamic.data.mapping.data.provider.internal.rest.DDMRESTDataProvider.java

License:Open Source License

protected DDMDataProviderResponse doGetData(DDMDataProviderRequest ddmDataProviderRequest) {

    DDMDataProviderContext ddmDataProviderContext = ddmDataProviderRequest.getDDMDataProviderContext();

    DDMRESTDataProviderSettings ddmRESTDataProviderSettings = ddmDataProviderContext
            .getSettingsInstance(DDMRESTDataProviderSettings.class);

    HttpRequest httpRequest = HttpRequest.get(ddmRESTDataProviderSettings.url());

    if (StringUtil.startsWith(ddmRESTDataProviderSettings.url(), Http.HTTPS)) {

        httpRequest.trustAllCerts(true);
    }/*from   ww w .  j a  v  a  2 s. c  o m*/

    if (Validator.isNotNull(ddmRESTDataProviderSettings.username())) {
        httpRequest.basicAuthentication(ddmRESTDataProviderSettings.username(),
                ddmRESTDataProviderSettings.password());
    }

    setRequestParameters(ddmDataProviderRequest, ddmRESTDataProviderSettings, httpRequest);

    String cacheKey = getCacheKey(httpRequest);

    DDMRESTDataProviderResult ddmRESTDataProviderResult = _portalCache.get(cacheKey);

    if ((ddmRESTDataProviderResult != null) && ddmRESTDataProviderSettings.cacheable()) {

        return ddmRESTDataProviderResult.getDDMDataProviderResponse();
    }

    HttpResponse httpResponse = httpRequest.send();

    DocumentContext documentContext = JsonPath.parse(httpResponse.body());

    DDMDataProviderResponse ddmDataProviderResponse = createDDMDataProviderResponse(documentContext,
            ddmDataProviderRequest, ddmRESTDataProviderSettings);

    if (ddmRESTDataProviderSettings.cacheable()) {
        _portalCache.put(cacheKey, new DDMRESTDataProviderResult(ddmDataProviderResponse));
    }

    return ddmDataProviderResponse;
}

From source file:com.liferay.dynamic.data.mapping.data.provider.internal.rest.DDMRESTDataProvider.java

License:Open Source License

protected String normalizePath(String path) {
    if (StringUtil.startsWith(path, StringPool.PERIOD) || StringUtil.startsWith(path, StringPool.DOLLAR)) {

        return path;
    }//from w w w.j  ava 2s . c o m

    return StringPool.PERIOD.concat(path);
}

From source file:com.liferay.dynamic.data.mapping.util.DDMFormFieldFactoryHelper.java

License:Open Source License

protected boolean isLocalizableValue(String value) {
    if (StringUtil.startsWith(value, StringPool.PERCENT)) {
        return true;
    }/*from   w  ww .  ja v  a 2 s  .  c o  m*/

    return false;
}

From source file:com.liferay.iframe.web.internal.portlet.action.IFrameConfigurationAction.java

License:Open Source License

@Override
public void processAction(PortletConfig portletConfig, ActionRequest actionRequest,
        ActionResponse actionResponse) throws Exception {

    String src = getParameter(actionRequest, "src");

    if (!src.startsWith("/") && !StringUtil.startsWith(src, "http://")
            && !StringUtil.startsWith(src, "https://") && !StringUtil.startsWith(src, "mhtml://")) {

        src = HttpUtil.getProtocol(actionRequest) + "://" + src;

        setPreference(actionRequest, "src", src);
    }/*from   www.  ja v a2 s  .c om*/

    String[] htmlAttributes = StringUtil.splitLines(getParameter(actionRequest, "htmlAttributes"));

    for (String htmlAttribute : htmlAttributes) {
        int pos = htmlAttribute.indexOf(CharPool.EQUAL);

        if (pos == -1) {
            continue;
        }

        String key = htmlAttribute.substring(0, pos);
        String value = htmlAttribute.substring(pos + 1);

        setPreference(actionRequest, key, value);
    }

    super.processAction(portletConfig, actionRequest, actionResponse);
}

From source file:com.liferay.knowledgebase.admin.util.AdminUtil.java

License:Open Source License

public static String[] unescapeSections(String sections) {
    String[] sectionsArray = StringUtil.split(sections);

    for (int i = 0; i < sectionsArray.length; i++) {
        String section = sectionsArray[i];

        if (StringUtil.startsWith(section, StringPool.UNDERLINE)
                && StringUtil.endsWith(section, StringPool.UNDERLINE)) {

            sectionsArray[i] = section.substring(1, section.length() - 1);
        }/*from   w ww  . ja v a2  s. co  m*/
    }

    return sectionsArray;
}

From source file:com.liferay.portlet.iframe.action.ConfigurationActionImpl.java

License:Open Source License

@Override
public void processAction(PortletConfig portletConfig, ActionRequest actionRequest,
        ActionResponse actionResponse) throws Exception {

    String src = getParameter(actionRequest, "src");

    if (!src.startsWith("/") && !StringUtil.startsWith(src, "http://")
            && !StringUtil.startsWith(src, "https://") && !StringUtil.startsWith(src, "mhtml://")) {

        src = HttpUtil.getProtocol(actionRequest) + "://" + src;

        setPreference(actionRequest, "src", src);
    }//  w  w w.j av a  2s .c  om

    String[] htmlAttributes = StringUtil.splitLines(getParameter(actionRequest, "htmlAttributes"));

    for (String htmlAttribute : htmlAttributes) {
        int pos = htmlAttribute.indexOf(CharPool.EQUAL);

        if (pos == -1) {
            continue;
        }

        String key = htmlAttribute.substring(0, pos);
        String value = htmlAttribute.substring(pos + 1, htmlAttribute.length());

        setPreference(actionRequest, key, value);
    }

    super.processAction(portletConfig, actionRequest, actionResponse);
}

From source file:com.liferay.portlet.messageboards.pop.MessageListenerImpl.java

License:Open Source License

protected long getParentMessageId(String recipient, Message message) throws Exception {

    if (!StringUtil.startsWith(recipient, MBUtil.MESSAGE_POP_PORTLET_PREFIX)) {

        return MBUtil.getParentMessageId(message);
    }//from  w ww .  j  a  v a 2 s .  c o m

    int pos = recipient.indexOf(CharPool.AT);

    if (pos < 0) {
        return MBUtil.getParentMessageId(message);
    }

    String target = recipient.substring(MBUtil.MESSAGE_POP_PORTLET_PREFIX.length(), pos);

    String[] parts = StringUtil.split(target, CharPool.PERIOD);

    long parentMessageId = 0;

    if (parts.length == 2) {
        parentMessageId = GetterUtil.getLong(parts[1]);
    }

    if (parentMessageId > 0) {
        return parentMessageId;
    }

    return MBUtil.getParentMessageId(message);
}