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

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

Introduction

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

Prototype

public static String[] splitLines(String s) 

Source Link

Document

Splits string s around return and newline characters.

Usage

From source file:au.com.permeance.liferay.portal.documentlibrary.servlet.DownloadFolderZipActionsMenuHookListener.java

License:Open Source License

private static String buildCurrentMenuItemsDelimString() {
    String[] curMenuItems = StringUtil
            .splitLines(System.getProperty(HookSysPropsKeys.LIFERAY_DL_FOLDER_ACTIONS_MENU_EXT));
    String curMenuItemsStr = StringUtil.merge(curMenuItems);
    if (LOG.isDebugEnabled()) {
        LOG.debug("curMenuItems: " + curMenuItems);
        List<String> curMenuItemsList = Arrays.asList(curMenuItems);
        LOG.debug("curMenuItemsList: " + curMenuItemsList);
        LOG.debug("curMenuItemsStr: " + curMenuItemsStr);
    }/*from  ww w .  j ava  2s. c o  m*/
    return curMenuItemsStr;
}

From source file:au.com.permeance.liferay.portal.documentlibrary.servlet.FolderActionsMenuHookListener.java

License:Open Source License

public static void startApplication() {

    System.out.println("startApplication");

    String[] newMenuItems = HookPropsValues.DL_FOLDER_ACTIONS_MENU_EXT;
    String newMenuItemsStr = StringUtil.merge(newMenuItems);
    if (LOG.isDebugEnabled()) {
        LOG.debug("newMenuItems: " + newMenuItems);
        LOG.debug("newMenuItemsStr: " + newMenuItemsStr);
    }//from  ww  w.j  av a 2 s  .  co  m

    String[] curMenuItems = StringUtil
            .splitLines(System.getProperty(HookSysPropsKeys.LIFERAY_DL_FOLDER_ACTIONS_MENU_EXT));
    String curMenuItemsStr = StringUtil.merge(curMenuItems);
    if (LOG.isDebugEnabled()) {
        LOG.debug("curMenuItems: " + curMenuItems);
        LOG.debug("curMenuItemsStr: " + curMenuItemsStr);
    }

    String mergedMenuItemsStr = StringUtilHelper.addDelimItems(curMenuItemsStr, newMenuItemsStr,
            StringPool.COMMA);
    LOG.debug("mergedMenuItemsStr: " + mergedMenuItemsStr);

    System.setProperty(HookSysPropsKeys.LIFERAY_DL_FOLDER_ACTIONS_MENU_EXT, mergedMenuItemsStr);
    LOG.info(HookSysPropsKeys.LIFERAY_DL_FOLDER_ACTIONS_MENU_EXT + ": "
            + System.getProperty(HookSysPropsKeys.LIFERAY_DL_FOLDER_ACTIONS_MENU_EXT));
}

From source file:au.com.permeance.liferay.portal.documentlibrary.servlet.FolderActionsMenuHookListener.java

License:Open Source License

public static void stopApplication() {

    System.out.println("stopApplication");

    String[] newMenuItems = HookPropsValues.DL_FOLDER_ACTIONS_MENU_EXT;
    String newMenuItemsStr = StringUtil.merge(newMenuItems);
    if (LOG.isDebugEnabled()) {
        LOG.debug("newMenuItems: " + newMenuItems);
        LOG.debug("newMenuItemsStr: " + newMenuItemsStr);
    }/*from w ww .j av  a 2 s. c o  m*/

    String[] curMenuItems = StringUtil
            .splitLines(System.getProperty(HookSysPropsKeys.LIFERAY_DL_FOLDER_ACTIONS_MENU_EXT));
    String curMenuItemsStr = StringUtil.merge(curMenuItems);
    if (LOG.isDebugEnabled()) {
        LOG.debug("curMenuItems: " + curMenuItems);
        LOG.debug("curMenuItemsStr: " + curMenuItemsStr);
    }

    String mergedMenuItemsStr = StringUtilHelper.removeDelimItems(curMenuItemsStr, newMenuItemsStr,
            StringPool.COMMA);
    LOG.debug("mergedMenuItemsStr: " + mergedMenuItemsStr);

    System.setProperty(HookSysPropsKeys.LIFERAY_DL_FOLDER_ACTIONS_MENU_EXT, mergedMenuItemsStr);
    LOG.info(HookSysPropsKeys.LIFERAY_DL_FOLDER_ACTIONS_MENU_EXT + ": "
            + System.getProperty(HookSysPropsKeys.LIFERAY_DL_FOLDER_ACTIONS_MENU_EXT));
}

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

License:Open Source License

protected String replaceMultiLocaleLayoutFriendlyURLs(String content) {
    if (StringUtil.indexOfAny(content, _MULTI_LOCALE_LAYOUT_VARIABLES) <= -1) {

        return content;
    }//w  w  w. j a v  a  2s.c  o m

    List<String> urls = ListUtil.toList(StringUtil.splitLines(content));

    List<String> outURLs = new ArrayList<>();

    for (String url : urls) {
        outURLs.add(url);

        if (StringUtil.indexOfAny(url, _MULTI_LOCALE_LAYOUT_VARIABLES) > -1) {

            outURLs.add(StringUtil.replace(url, _MULTI_LOCALE_LAYOUT_VARIABLES,
                    _NON_DEFAULT_MULTI_LOCALE_LAYOUT_VARIABLES));
        }
    }

    return StringUtil.merge(outURLs, StringPool.NEW_LINE);
}

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

License:Open Source License

protected String replaceTimestampParameters(String content) {
    List<String> urls = ListUtil.toList(StringUtil.splitLines(content));

    String timestampParameter = "t=123456789";

    String parameters1 = timestampParameter + "&width=100&height=100";
    String parameters2 = "width=100&" + timestampParameter + "&height=100";
    String parameters3 = "width=100&height=100&" + timestampParameter;
    String parameters4 = timestampParameter + "?" + timestampParameter + "&width=100&height=100";

    List<String> outURLs = new ArrayList<>();

    for (String url : urls) {
        if (!url.contains("[$TIMESTAMP")) {
            continue;
        }/* w w w  .  jav a  2  s . c  om*/

        outURLs.add(StringUtil.replace(url, new String[] { "[$TIMESTAMP$]", "[$TIMESTAMP_ONLY$]" },
                new String[] { "&" + parameters1, "?" + parameters1 }));
        outURLs.add(StringUtil.replace(url, new String[] { "[$TIMESTAMP$]", "[$TIMESTAMP_ONLY$]" },
                new String[] { "&" + parameters2, "?" + parameters2 }));
        outURLs.add(StringUtil.replace(url, new String[] { "[$TIMESTAMP$]", "[$TIMESTAMP_ONLY$]" },
                new String[] { "&" + parameters3, "?" + parameters3 }));
        outURLs.add(StringUtil.replace(url, new String[] { "[$TIMESTAMP$]", "[$TIMESTAMP_ONLY$]" },
                new String[] { StringPool.BLANK, "?" + parameters4 }));
    }

    return StringUtil.merge(outURLs, StringPool.NEW_LINE);
}

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 w  ww.  j a v  a  2s .co m

    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.message.boards.web.internal.portlet.action.MBAdminConfigurationAction.java

License:Open Source License

protected void updateUserRanks(ActionRequest actionRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    for (Locale locale : LanguageUtil.getAvailableLocales(themeDisplay.getSiteGroupId())) {

        String languageId = LocaleUtil.toLanguageId(locale);

        String[] ranks = StringUtil.splitLines(ParamUtil.getString(actionRequest, "ranks_" + languageId));

        Map<String, String> map = new TreeMap<>(new NaturalOrderStringComparator());

        for (String rank : ranks) {
            if (!isValidUserRank(rank)) {
                SessionErrors.add(actionRequest, "userRank");

                return;
            }/*  w ww .j  ava  2s .c  om*/

            String[] kvp = StringUtil.split(rank, CharPool.EQUAL);

            String kvpName = kvp[0];
            String kvpValue = kvp[1];

            map.put(kvpValue, kvpName);
        }

        ranks = new String[map.size()];

        int count = 0;

        for (Map.Entry<String, String> entry : map.entrySet()) {
            String kvpValue = entry.getKey();
            String kvpName = entry.getValue();

            ranks[count++] = kvpName + StringPool.EQUAL + kvpValue;
        }

        String preferenceName = LocalizationUtil.getLocalizedName("ranks", languageId);

        setPreference(actionRequest, preferenceName, ranks);
    }
}

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  a  v  a 2 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, htmlAttribute.length());

        setPreference(actionRequest, key, value);
    }

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

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

License:Open Source License

protected void updateUserRanks(ActionRequest actionRequest) throws Exception {

    Locale[] locales = LanguageUtil.getAvailableLocales();

    for (int i = 0; i < locales.length; i++) {
        String languageId = LocaleUtil.toLanguageId(locales[i]);

        String[] ranks = StringUtil.splitLines(ParamUtil.getString(actionRequest, "ranks_" + languageId));

        Map<String, String> map = new TreeMap<String, String>();

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

            String kvpName = kvp[0];
            String kvpValue = kvp[1];

            map.put(kvpValue, kvpName);/*from  w  ww.ja  v  a  2  s.c o m*/
        }

        ranks = new String[map.size()];

        int count = 0;

        Iterator<Map.Entry<String, String>> itr = map.entrySet().iterator();

        while (itr.hasNext()) {
            Map.Entry<String, String> entry = itr.next();

            String kvpValue = entry.getKey();
            String kvpName = entry.getValue();

            ranks[count++] = kvpName + StringPool.EQUAL + kvpValue;
        }

        String preferenceName = LocalizationUtil.getPreferencesKey("ranks", languageId);

        setPreference(actionRequest, preferenceName, ranks);
    }
}

From source file:com.liferay.portlet.plugininstaller.action.InstallPluginAction.java

License:Open Source License

protected void unignorePackages(ActionRequest actionRequest) throws Exception {

    String[] pluginPackagesUnignored = StringUtil
            .splitLines(ParamUtil.getString(actionRequest, "pluginPackagesUnignored"));

    String[] pluginPackagesIgnored = PrefsPropsUtil.getStringArray(
            PropsKeys.PLUGIN_NOTIFICATIONS_PACKAGES_IGNORED, StringPool.NEW_LINE,
            PropsValues.PLUGIN_NOTIFICATIONS_PACKAGES_IGNORED);

    StringBundler sb = new StringBundler();

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

        if (!ArrayUtil.contains(pluginPackagesUnignored, packageId)) {
            sb.append(packageId);//w  w w  . j  ava2 s  .  c o m
            sb.append(StringPool.NEW_LINE);
        }
    }

    PortletPreferences preferences = PrefsPropsUtil.getPreferences();

    preferences.setValue(PropsKeys.PLUGIN_NOTIFICATIONS_PACKAGES_IGNORED, sb.toString());

    preferences.store();

    PluginPackageUtil.refreshUpdatesAvailableCache();
}