Example usage for com.liferay.portal.kernel.util ArrayUtil filter

List of usage examples for com.liferay.portal.kernel.util ArrayUtil filter

Introduction

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

Prototype

@SuppressWarnings("unchecked")
    public static <T> T[] filter(T[] array, Predicate<T> filterPredicate) 

Source Link

Usage

From source file:com.liferay.asset.publisher.web.display.context.AssetPublisherDisplayContext.java

License:Open Source License

public String[] getExtensions(AssetRenderer<?> assetRenderer) {
    final String[] supportedConversions = assetRenderer.getSupportedConversions();

    if (supportedConversions == null) {
        return getExtensions();
    }//from www.  j av a 2 s  .c  o  m

    return ArrayUtil.filter(getExtensions(), new PredicateFilter<String>() {

        @Override
        public boolean filter(String extension) {
            return ArrayUtil.contains(supportedConversions, extension);
        }

    });
}

From source file:com.liferay.content.targeting.portlet.UserSegmentContentListPortlet.java

License:Open Source License

protected long[] getAvailableClassNameIds(long companyId) {
    long[] availableClassNameIds = AssetRendererFactoryRegistryUtil.getClassNameIds(companyId);

    availableClassNameIds = ArrayUtil.filter(availableClassNameIds, new PredicateFilter<Long>() {

        public boolean filter(Long classNameId) {
            AssetRendererFactory assetRendererFactory = AssetRendererFactoryRegistryUtil
                    .getAssetRendererFactoryByClassName(PortalUtil.getClassName(classNameId));

            return assetRendererFactory.isSelectable();
        }/*from  w ww  .  j av a2  s. co m*/

    });

    return availableClassNameIds;
}

From source file:com.liferay.exportimport.content.processor.base.BaseTextExportImportContentProcessor.java

License:Open Source License

protected Map<String, String[]> getDLReferenceParameters(long groupId, String content, int beginPos,
        int endPos) {

    boolean legacyURL = true;
    char[] stopChars = DL_REFERENCE_LEGACY_STOP_CHARS;

    if (content.startsWith("/documents/", beginPos)) {
        legacyURL = false;//from ww  w. jav a  2s.c om
        stopChars = DL_REFERENCE_STOP_CHARS;
    }

    endPos = StringUtil.indexOfAny(content, stopChars, beginPos, endPos);

    if (endPos == -1) {
        return null;
    }

    Map<String, String[]> map = new HashMap<>();

    String dlReference = content.substring(beginPos, endPos);

    while (dlReference.contains(StringPool.AMPERSAND_ENCODED)) {
        dlReference = dlReference.replace(StringPool.AMPERSAND_ENCODED, StringPool.AMPERSAND);
    }

    if (!legacyURL) {
        String[] pathArray = dlReference.split(StringPool.SLASH);

        if (pathArray.length < 3) {
            return map;
        }

        map.put("groupId", new String[] { pathArray[2] });

        if (pathArray.length == 4) {
            map.put("uuid", new String[] { pathArray[3] });
        } else if (pathArray.length == 5) {
            map.put("folderId", new String[] { pathArray[3] });
            map.put("title", new String[] { HttpUtil.decodeURL(pathArray[4]) });
        } else if (pathArray.length > 5) {
            map.put("uuid", new String[] { pathArray[5] });
        }
    } else {
        dlReference = dlReference.substring(dlReference.indexOf(CharPool.QUESTION) + 1);

        map = HttpUtil.parameterMapFromString(dlReference);

        String[] imageIds = null;

        if (map.containsKey("img_id")) {
            imageIds = map.get("img_id");
        } else if (map.containsKey("i_id")) {
            imageIds = map.get("i_id");
        }

        imageIds = ArrayUtil.filter(imageIds, new PredicateFilter<String>() {

            @Override
            public boolean filter(String imageId) {
                if (Validator.isNotNull(imageId)) {
                    return true;
                }

                return false;
            }

        });

        if (ArrayUtil.isNotEmpty(imageIds)) {
            map.put("image_id", imageIds);
        }
    }

    map.put("endPos", new String[] { String.valueOf(endPos) });

    String groupIdString = MapUtil.getString(map, "groupId");

    if (groupIdString.equals("@group_id@")) {
        groupIdString = String.valueOf(groupId);

        map.put("groupId", new String[] { groupIdString });
    }

    return map;
}

From source file:com.liferay.exportimport.internal.content.processor.DLReferencesExportImportContentProcessor.java

License:Open Source License

protected Map<String, String[]> getDLReferenceParameters(long groupId, String content, int beginPos,
        int endPos) {

    boolean legacyURL = true;
    char[] stopChars = _DL_REFERENCE_LEGACY_STOP_CHARS;

    if (content.startsWith("/documents/", beginPos)) {
        legacyURL = false;/*  www .  j  av a  2  s  . co  m*/
        stopChars = _DL_REFERENCE_STOP_CHARS;
    }

    endPos = StringUtil.indexOfAny(content, stopChars, beginPos, endPos);

    if (endPos == -1) {
        return null;
    }

    Map<String, String[]> map = new HashMap<>();

    String dlReference = content.substring(beginPos, endPos);

    while (dlReference.contains(StringPool.AMPERSAND_ENCODED)) {
        dlReference = dlReference.replace(StringPool.AMPERSAND_ENCODED, StringPool.AMPERSAND);
    }

    if (!legacyURL) {
        String[] pathArray = dlReference.split(StringPool.SLASH);

        if (pathArray.length < 3) {
            return map;
        }

        if ("portlet_file_entry".equals(pathArray[2])) {
            map.put("groupId", new String[] { pathArray[3] });
            map.put("title", new String[] { _http.decodeURL(pathArray[4]) });
            map.put("uuid", new String[] { pathArray[5] });
        } else {
            map.put("groupId", new String[] { pathArray[2] });

            if (pathArray.length == 4) {
                map.put("uuid", new String[] { pathArray[3] });
            } else if (pathArray.length == 5) {
                map.put("folderId", new String[] { pathArray[3] });
                map.put("title", new String[] { _http.decodeURL(pathArray[4]) });
            } else if (pathArray.length > 5) {
                map.put("uuid", new String[] { pathArray[5] });
            }
        }
    } else {
        dlReference = dlReference.substring(dlReference.indexOf(CharPool.QUESTION) + 1);

        map = _http.parameterMapFromString(dlReference);

        String[] imageIds = null;

        if (map.containsKey("img_id")) {
            imageIds = map.get("img_id");
        } else if (map.containsKey("i_id")) {
            imageIds = map.get("i_id");
        }

        imageIds = ArrayUtil.filter(imageIds, Validator::isNotNull);

        if (ArrayUtil.isNotEmpty(imageIds)) {
            map.put("image_id", imageIds);
        }
    }

    map.put("endPos", new String[] { String.valueOf(endPos) });

    String groupIdString = MapUtil.getString(map, "groupId");

    if (groupIdString.equals("@group_id@")) {
        groupIdString = String.valueOf(groupId);

        map.put("groupId", new String[] { groupIdString });
    }

    return map;
}