Example usage for com.liferay.portal.kernel.util StringPool FOUR_SPACES

List of usage examples for com.liferay.portal.kernel.util StringPool FOUR_SPACES

Introduction

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

Prototype

String FOUR_SPACES

To view the source code for com.liferay.portal.kernel.util StringPool FOUR_SPACES.

Click Source Link

Usage

From source file:com.liferay.message.boards.parser.bbcode.internal.HtmlBBCodeTranslatorImpl.java

License:Open Source License

protected void handleCode(StringBundler sb, List<BBCodeItem> bbCodeItems, IntegerWrapper marker) {

    sb.append("<div class=\"lfr-code\">");
    sb.append("<table>");
    sb.append("<tbody>");

    String code = extractData(bbCodeItems, marker, "code", BBCodeParser.TYPE_DATA, true);

    code = HtmlUtil.escape(code);/* w  ww  .j  a  v a2  s. c  o  m*/
    code = StringUtil.replace(code, CharPool.TAB, StringPool.FOUR_SPACES);

    String[] lines = code.split("\r?\n");

    for (int i = 0; i < lines.length; i++) {
        sb.append("<tr>");
        sb.append("<td class=\"line-numbers\" data-line-number=\"");

        String index = String.valueOf(i + 1);

        sb.append(index);
        sb.append("\"></td>");
        sb.append("<td class=\"lines\">");

        String line = lines[i];

        line = StringUtil.replace(line, StringPool.THREE_SPACES, "&nbsp; &nbsp;");
        line = StringUtil.replace(line, StringPool.DOUBLE_SPACE, "&nbsp; ");

        if (Validator.isNull(line)) {
            line = "<br />";
        }

        sb.append("<div class=\"line\">");
        sb.append(line);
        sb.append("</div>");
        sb.append("</td>");
        sb.append("</tr>");
    }

    sb.append("</tbody>");
    sb.append("</table>");
    sb.append("</div>");
}

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

License:Open Source License

protected String trimLine(String line, boolean allowLeadingSpaces) {
    if (line.trim().length() == 0) {
        return StringPool.BLANK;
    }/*from   w w  w  . ja v a  2  s.  c  om*/

    line = StringUtil.trimTrailing(line);

    if (allowLeadingSpaces || !line.startsWith(StringPool.SPACE) || line.startsWith(" *")) {

        return line;
    }

    if (!line.startsWith(StringPool.FOUR_SPACES)) {
        while (line.startsWith(StringPool.SPACE)) {
            line = StringUtil.replaceFirst(line, StringPool.SPACE, StringPool.BLANK);
        }
    } else {
        int pos = 0;

        String temp = line;

        while (temp.startsWith(StringPool.FOUR_SPACES)) {
            line = StringUtil.replaceFirst(line, StringPool.FOUR_SPACES, StringPool.TAB);

            pos++;

            temp = line.substring(pos);
        }
    }

    return line;
}

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

License:Open Source License

protected String checkIfClauseTabsAndSpaces(String ifClause) throws IOException {

    if (ifClause.contains("!(") || ifClause.contains(StringPool.TAB + "//")) {

        return ifClause;
    }//from  ww  w . ja v  a  2s  .  c  om

    UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(new UnsyncStringReader(ifClause));

    String line = null;

    String previousLine = null;
    int previousLineLeadingWhiteSpace = 0;

    int lastCriteriumLineLeadingWhiteSpace = 0;

    int closeParenthesesCount = 0;
    int openParenthesesCount = 0;

    while ((line = unsyncBufferedReader.readLine()) != null) {
        String originalLine = line;

        line = StringUtil.replace(line, StringPool.TAB, StringPool.FOUR_SPACES);

        int leadingWhiteSpace = line.length() - StringUtil.trimLeading(line).length();

        if (Validator.isNull(previousLine)) {
            lastCriteriumLineLeadingWhiteSpace = line.indexOf(StringPool.OPEN_PARENTHESIS);
        } else if (previousLine.endsWith("|") || previousLine.endsWith("&") || previousLine.endsWith("^")) {

            int expectedLeadingWhiteSpace = lastCriteriumLineLeadingWhiteSpace + openParenthesesCount
                    - closeParenthesesCount;

            if (leadingWhiteSpace != expectedLeadingWhiteSpace) {
                return fixIfClause(ifClause, originalLine, leadingWhiteSpace - expectedLeadingWhiteSpace);
            }

            lastCriteriumLineLeadingWhiteSpace = leadingWhiteSpace;

            closeParenthesesCount = 0;
            openParenthesesCount = 0;
        } else {
            int expectedLeadingWhiteSpace = 0;

            if (previousLine.contains(StringPool.TAB + "if (")) {
                expectedLeadingWhiteSpace = previousLineLeadingWhiteSpace + 8;
            } else if (previousLine.contains(StringPool.TAB + "else if (")
                    || previousLine.contains(StringPool.TAB + "while (")) {

                expectedLeadingWhiteSpace = previousLineLeadingWhiteSpace + 12;
            }

            if ((expectedLeadingWhiteSpace != 0) && (leadingWhiteSpace != expectedLeadingWhiteSpace)) {

                return fixIfClause(ifClause, originalLine, leadingWhiteSpace - expectedLeadingWhiteSpace);
            }
        }

        if (line.endsWith(") {")) {
            return ifClause;
        }

        line = stripQuotes(line, CharPool.QUOTE);
        line = stripQuotes(line, CharPool.APOSTROPHE);

        closeParenthesesCount += StringUtil.count(line, StringPool.CLOSE_PARENTHESIS);
        openParenthesesCount += StringUtil.count(line, StringPool.OPEN_PARENTHESIS);

        previousLine = originalLine;
        previousLineLeadingWhiteSpace = leadingWhiteSpace;
    }

    return ifClause;
}

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

License:Open Source License

protected String fixIfClause(String ifClause, String line, int delta) {
    String newLine = line;//from  w  w  w  .  j a v a2s.c om

    String whiteSpace = StringPool.BLANK;
    int whiteSpaceLength = Math.abs(delta);

    while (whiteSpaceLength > 0) {
        if (whiteSpaceLength >= 4) {
            whiteSpace += StringPool.TAB;

            whiteSpaceLength -= 4;
        } else {
            whiteSpace += StringPool.SPACE;

            whiteSpaceLength -= 1;
        }
    }

    if (delta > 0) {
        if (!line.contains(StringPool.TAB + whiteSpace)) {
            newLine = StringUtil.replaceLast(newLine, StringPool.TAB, StringPool.FOUR_SPACES);
        }

        newLine = StringUtil.replaceLast(newLine, StringPool.TAB + whiteSpace, StringPool.TAB);
    } else {
        newLine = StringUtil.replaceLast(newLine, StringPool.TAB, StringPool.TAB + whiteSpace);
    }

    newLine = StringUtil.replaceLast(newLine, StringPool.FOUR_SPACES, StringPool.TAB);

    return StringUtil.replace(ifClause, line, newLine);
}

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

License:Open Source License

protected String formatPortalPortalProperties() throws Exception {
    if (!portalSource) {
        return ContentUtil.get("portal.properties");
    }/*from   w ww. j  a  v  a2 s. c o m*/

    String fileName = "portal-impl/src/portal.properties";

    File file = getFile(fileName, 4);

    String content = fileUtil.read(file);

    StringBundler sb = new StringBundler();

    try (UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(
            new UnsyncStringReader(content))) {

        String line = null;

        while ((line = unsyncBufferedReader.readLine()) != null) {
            line = trimLine(line, true);

            if (line.startsWith(StringPool.TAB)) {
                line = line.replaceFirst(StringPool.TAB, StringPool.FOUR_SPACES);
            }

            sb.append(line);
            sb.append("\n");
        }
    }

    String newContent = sb.toString();

    if (newContent.endsWith("\n")) {
        newContent = newContent.substring(0, newContent.length() - 1);
    }

    processFormattedFile(file, fileName, content, newContent);

    return newContent;
}

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

License:Open Source License

protected void formatPortalProperties(String fileName, String content) throws Exception {

    UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(new UnsyncStringReader(content));

    int lineCount = 0;

    String line = null;//w  w  w  .j av a  2 s. c om

    int previousPos = -1;

    while ((line = unsyncBufferedReader.readLine()) != null) {
        lineCount++;

        int pos = line.indexOf(StringPool.EQUAL);

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

        String property = line.substring(0, pos + 1);

        property = property.trim();

        pos = _portalPortalPropertiesContent.indexOf(StringPool.FOUR_SPACES + property);

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

        if (pos < previousPos) {
            processErrorMessage(fileName, "sort " + fileName + " " + lineCount);
        }

        previousPos = pos;
    }
}

From source file:it.smc.calendar.sync.caldav.CalDAVMethodFactory.java

License:Open Source License

public Method create(HttpServletRequest request) throws WebDAVException {
    String method = request.getMethod();

    if (_log.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();

        sb.append("Serving CalDAV request: ");
        sb.append(PortalUtil.getCurrentCompleteURL(request));
        sb.append(StringPool.RETURN_NEW_LINE);
        sb.append(method);/*from   w w  w  .j  ava  2s  . co m*/
        sb.append(StringPool.RETURN_NEW_LINE);
        sb.append("User: ");
        sb.append(PrincipalThreadLocal.getUserId());

        Enumeration<String> headerNames = request.getHeaderNames();

        String headerName;

        while (headerNames.hasMoreElements()) {
            headerName = headerNames.nextElement();
            sb.append(headerName);
            sb.append(StringPool.COLON);
            sb.append(StringPool.SPACE);
            sb.append(request.getHeader(headerName));
            sb.append(StringPool.RETURN_NEW_LINE);
        }

        _log.debug(sb.toString());
    }

    Method methodImpl = (Method) _methods.get(StringUtil.toUpperCase(method));

    if (methodImpl == null) {
        throw new WebDAVException("Method " + method + " is not implemented");
    }

    try {
        String content = new String(FileUtil.getBytes(request.getInputStream()));

        if (Validator.isNotNull(content)) {
            CalDAVRequestThreadLocal.setRequestContent(content);

            if (_log.isDebugEnabled()) {
                String formattedContent = content;

                if (CalDAVUtil.isRequestContentXML(request)) {
                    Document document = CalDAVRequestThreadLocal.getRequestDocument();
                    formattedContent = document.formattedString(StringPool.FOUR_SPACES);
                }

                _log.debug("Request content: \n" + formattedContent);
            }
        }
    } catch (Exception e) {
        _log.error(e, e);
    }

    return methodImpl;
}

From source file:it.smc.calendar.sync.caldav.methods.BasePropMethodImpl.java

License:Open Source License

protected int writeResponseXML(WebDAVRequest webDAVRequest, Set<QName> props) throws Exception {

    WebDAVStorage storage = webDAVRequest.getWebDAVStorage();

    long depth = WebDAVUtil.getDepth(webDAVRequest.getHttpServletRequest());

    Document document = SAXReaderUtil.createDocument();

    Element multistatusElement = SAXReaderUtil.createElement(CalDAVProps.createQName("multistatus"));

    document.setRootElement(multistatusElement);

    Resource resource = storage.getResource(webDAVRequest);

    if (resource != null) {
        addResponse(storage, webDAVRequest, resource, props, multistatusElement, depth);

        String xml = document.formattedString(StringPool.FOUR_SPACES);

        if (_log.isDebugEnabled()) {
            _log.debug("Response XML\n" + xml);
        }/*from  w  w  w.  j  a  v  a  2 s .  c o  m*/

        // Set the status prior to writing the XML

        int status = WebDAVUtil.SC_MULTI_STATUS;

        HttpServletResponse response = webDAVRequest.getHttpServletResponse();

        response.setContentType(ContentTypes.TEXT_XML_UTF8);
        response.setStatus(status);

        try {
            ServletResponseUtil.write(response, xml);

            response.flushBuffer();
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e);
            }
        }

        return status;
    } else {
        if (_log.isDebugEnabled()) {
            _log.debug("No resource found for " + storage.getRootPath() + webDAVRequest.getPath());
        }

        return HttpServletResponse.SC_NOT_FOUND;
    }
}