Example usage for com.liferay.portal.kernel.util TextFormatter M

List of usage examples for com.liferay.portal.kernel.util TextFormatter M

Introduction

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

Prototype

int M

To view the source code for com.liferay.portal.kernel.util TextFormatter M.

Click Source Link

Usage

From source file:com.liferay.frontend.editor.tinymce.web.editor.configuration.TinyMCEEditorConfigContributor.java

License:Open Source License

protected JSONArray getToolbarJSONArray(Map<String, Object> inputEditorTaglibAttributes,
        ThemeDisplay themeDisplay) {/*www. j  a  v a2s . c  om*/

    JSONObject toolbarsJSONObject = getToolbarsJSONObject(inputEditorTaglibAttributes);

    String toolbarSet = (String) inputEditorTaglibAttributes.get("liferay-ui:input-editor:toolbarSet");

    String currentToolbarSet = TextFormatter.format(HtmlUtil.escapeJS(toolbarSet), TextFormatter.M);

    if (BrowserSnifferUtil.isMobile(themeDisplay.getRequest())) {
        currentToolbarSet = "phone";
    }

    JSONArray toolbarJSONArray = toolbarsJSONObject.getJSONArray(currentToolbarSet);

    if (toolbarJSONArray == null) {
        toolbarJSONArray = toolbarsJSONObject.getJSONArray("liferay");
    }

    return toolbarJSONArray;
}

From source file:com.liferay.frontend.editor.tinymce.web.internal.editor.configuration.TinyMCEEditorConfigContributor.java

License:Open Source License

protected JSONArray getToolbarJSONArray(Map<String, Object> inputEditorTaglibAttributes,
        ThemeDisplay themeDisplay) {//from  ww w. jav a2s. co m

    JSONObject toolbarsJSONObject = getToolbarsJSONObject(inputEditorTaglibAttributes);

    String toolbarSet = (String) inputEditorTaglibAttributes.get("liferay-ui:input-editor:toolbarSet");

    String currentToolbarSet = TextFormatter.format(HtmlUtil.escapeJS(toolbarSet), TextFormatter.M);

    if (_browserSniffer.isMobile(themeDisplay.getRequest())) {
        currentToolbarSet = "phone";
    }

    JSONArray toolbarJSONArray = toolbarsJSONObject.getJSONArray(currentToolbarSet);

    if (toolbarJSONArray == null) {
        toolbarJSONArray = toolbarsJSONObject.getJSONArray("liferay");
    }

    return toolbarJSONArray;
}

From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java

License:Open Source License

protected String fixSessionKey(String fileName, String content, Pattern pattern) {

    Matcher matcher = pattern.matcher(content);

    if (!matcher.find()) {
        return content;
    }/*from   w w  w  . j av a2s.c  o m*/

    String newContent = content;

    do {
        String match = matcher.group();

        String s = null;

        if (pattern.equals(sessionKeyPattern)) {
            s = StringPool.COMMA;
        } else if (pattern.equals(taglibSessionKeyPattern)) {
            s = "key=";
        }

        int x = match.indexOf(s);

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

        x = x + s.length();

        String substring = match.substring(x).trim();

        String quote = StringPool.BLANK;

        if (substring.startsWith(StringPool.APOSTROPHE)) {
            quote = StringPool.APOSTROPHE;
        } else if (substring.startsWith(StringPool.QUOTE)) {
            quote = StringPool.QUOTE;
        } else {
            continue;
        }

        int y = match.indexOf(quote, x);
        int z = match.indexOf(quote, y + 1);

        if ((y == -1) || (z == -1)) {
            continue;
        }

        String prefix = match.substring(0, y + 1);
        String suffix = match.substring(z);
        String oldKey = match.substring(y + 1, z);

        boolean alphaNumericKey = true;

        for (char c : oldKey.toCharArray()) {
            if (!Validator.isChar(c) && !Validator.isDigit(c) && (c != CharPool.DASH)
                    && (c != CharPool.UNDERLINE)) {

                alphaNumericKey = false;
            }
        }

        if (!alphaNumericKey) {
            continue;
        }

        String newKey = TextFormatter.format(oldKey, TextFormatter.O);

        newKey = TextFormatter.format(newKey, TextFormatter.M);

        if (newKey.equals(oldKey)) {
            continue;
        }

        String oldSub = prefix.concat(oldKey).concat(suffix);
        String newSub = prefix.concat(newKey).concat(suffix);

        newContent = StringUtil.replaceFirst(newContent, oldSub, newSub);
    } while (matcher.find());

    return newContent;
}