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

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

Introduction

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

Prototype

String LESS_THAN

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

Click Source Link

Usage

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

License:Open Source License

protected void readParameterNamesAndTypes() {
    _parameterNames = new ArrayList<String>();
    _parameterTypes = new ArrayList<String>();

    if (!isConstructor() && !isMethod()) {
        return;/*from   w  ww.  java  2 s.com*/
    }

    Matcher matcher = _parameterTypesPattern.matcher(_content);

    if (!matcher.find()) {
        return;
    }

    String parameters = matcher.group(3);

    if (Validator.isNull(parameters)) {
        return;
    }

    parameters = StringUtil.replace(parameters, new String[] { StringPool.TAB, StringPool.NEW_LINE },
            new String[] { StringPool.BLANK, StringPool.SPACE });

    for (int x = 0;;) {
        parameters = StringUtil.trim(parameters);

        if (parameters.startsWith("final ")) {
            parameters = parameters.substring(6);
        }

        x = parameters.indexOf(StringPool.SPACE, x + 1);

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

        String parameterType = parameters.substring(0, x);

        int greaterThanCount = StringUtil.count(parameterType, StringPool.GREATER_THAN);
        int lessThanCount = StringUtil.count(parameterType, StringPool.LESS_THAN);

        if (greaterThanCount != lessThanCount) {
            continue;
        }

        _parameterTypes.add(parameterType);

        int y = parameters.indexOf(StringPool.COMMA, x);

        if (y == -1) {
            _parameterNames.add(parameters.substring(x + 1));

            return;
        }

        _parameterNames.add(parameters.substring(x + 1, y));

        parameters = parameters.substring(y + 1);

        x = 0;
    }
}

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

License:Open Source License

protected String formatJSP(String fileName, String absolutePath, String content) throws IOException {

    StringBundler sb = new StringBundler();

    String currentAttributeAndValue = null;
    String previousAttribute = null;
    String previousAttributeAndValue = null;

    String currentException = null;
    String previousException = null;

    boolean hasUnsortedExceptions = false;

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

        _checkedForIncludesFileNames = new HashSet<String>();
        _includeFileNames = new HashSet<String>();

        int lineCount = 0;

        String line = null;//  w  w w.  j av a2  s.  co m

        String previousLine = StringPool.BLANK;

        boolean readAttributes = false;

        boolean javaSource = false;

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

            if (portalSource && hasUnusedTaglib(fileName, line)) {
                continue;
            }

            if (!fileName.contains("jsonw") || !fileName.endsWith("action.jsp")) {

                line = trimLine(line, false);
            }

            if (line.contains("<aui:button ") && line.contains("type=\"button\"")) {

                processErrorMessage(fileName, "aui:button " + fileName + " " + lineCount);
            }

            if (line.contains("debugger.")) {
                processErrorMessage(fileName, "debugger " + fileName + " " + lineCount);
            }

            String trimmedLine = StringUtil.trimLeading(line);
            String trimmedPreviousLine = StringUtil.trimLeading(previousLine);

            checkStringBundler(trimmedLine, fileName, lineCount);

            checkEmptyCollection(trimmedLine, fileName, lineCount);

            if (trimmedLine.equals("<%") || trimmedLine.equals("<%!")) {
                javaSource = true;
            } else if (trimmedLine.equals("%>")) {
                javaSource = false;
            }

            if (javaSource || trimmedLine.contains("<%= ")) {
                checkInefficientStringMethods(line, fileName, absolutePath, lineCount);
            }

            if (javaSource && portalSource && !isExcluded(_unusedVariablesExclusions, absolutePath, lineCount)
                    && !_jspContents.isEmpty() && hasUnusedVariable(fileName, trimmedLine)) {

                continue;
            }

            // LPS-47179

            if (line.contains(".sendRedirect(") && !fileName.endsWith("_jsp.jsp")) {

                processErrorMessage(fileName, "Do not use sendRedirect in jsp: " + fileName + " " + lineCount);
            }

            if (!trimmedLine.equals("%>") && line.contains("%>") && !line.contains("--%>")
                    && !line.contains(" %>")) {

                line = StringUtil.replace(line, "%>", " %>");
            }

            if (line.contains("<%=") && !line.contains("<%= ")) {
                line = StringUtil.replace(line, "<%=", "<%= ");
            }

            if (trimmedPreviousLine.equals("%>") && Validator.isNotNull(line) && !trimmedLine.equals("-->")) {

                sb.append("\n");
            } else if (Validator.isNotNull(previousLine) && !trimmedPreviousLine.equals("<!--")
                    && trimmedLine.equals("<%")) {

                sb.append("\n");
            } else if (trimmedPreviousLine.equals("<%") && Validator.isNull(line)) {

                continue;
            } else if (trimmedPreviousLine.equals("<%") && trimmedLine.startsWith("//")) {

                sb.append("\n");
            } else if (Validator.isNull(previousLine) && trimmedLine.equals("%>") && (sb.index() > 2)) {

                String lineBeforePreviousLine = sb.stringAt(sb.index() - 3);

                if (!lineBeforePreviousLine.startsWith("//")) {
                    sb.setIndex(sb.index() - 1);
                }
            }

            if ((trimmedLine.startsWith("if (") || trimmedLine.startsWith("else if (")
                    || trimmedLine.startsWith("while (")) && trimmedLine.endsWith(") {")) {

                checkIfClauseParentheses(trimmedLine, fileName, lineCount);
            }

            if (readAttributes) {
                if (!trimmedLine.startsWith(StringPool.FORWARD_SLASH)
                        && !trimmedLine.startsWith(StringPool.GREATER_THAN)) {

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

                    if (pos != -1) {
                        String attribute = trimmedLine.substring(0, pos);

                        if (!trimmedLine.endsWith(StringPool.APOSTROPHE)
                                && !trimmedLine.endsWith(StringPool.GREATER_THAN)
                                && !trimmedLine.endsWith(StringPool.QUOTE)) {

                            processErrorMessage(fileName, "attribute: " + fileName + " " + lineCount);

                            readAttributes = false;
                        } else if (trimmedLine.endsWith(StringPool.APOSTROPHE)
                                && !trimmedLine.contains(StringPool.QUOTE)) {

                            line = StringUtil.replace(line, StringPool.APOSTROPHE, StringPool.QUOTE);

                            readAttributes = false;
                        } else if (Validator.isNotNull(previousAttribute)) {
                            if (!isAttributName(attribute) && !attribute.startsWith(StringPool.LESS_THAN)) {

                                processErrorMessage(fileName, "attribute: " + fileName + " " + lineCount);

                                readAttributes = false;
                            } else if (Validator.isNull(previousAttributeAndValue)
                                    && (previousAttribute.compareTo(attribute) > 0)) {

                                previousAttributeAndValue = previousLine;
                                currentAttributeAndValue = line;
                            }
                        }

                        if (!readAttributes) {
                            previousAttribute = null;
                            previousAttributeAndValue = null;
                        } else {
                            previousAttribute = attribute;
                        }
                    }
                } else {
                    previousAttribute = null;

                    readAttributes = false;
                }
            }

            if (!hasUnsortedExceptions) {
                int x = line.indexOf("<liferay-ui:error exception=\"<%=");

                if (x != -1) {
                    int y = line.indexOf(".class %>", x);

                    if (y != -1) {
                        currentException = line.substring(x, y);

                        if (Validator.isNotNull(previousException)
                                && (previousException.compareTo(currentException) > 0)) {

                            currentException = line;
                            previousException = previousLine;

                            hasUnsortedExceptions = true;
                        }
                    }
                }

                if (!hasUnsortedExceptions) {
                    previousException = currentException;
                    currentException = null;
                }
            }

            if (trimmedLine.startsWith(StringPool.LESS_THAN) && !trimmedLine.startsWith("<%")
                    && !trimmedLine.startsWith("<!")) {

                if (!trimmedLine.contains(StringPool.GREATER_THAN) && !trimmedLine.contains(StringPool.SPACE)) {

                    readAttributes = true;
                } else {
                    line = sortAttributes(fileName, line, lineCount, true);
                }
            }

            if (!trimmedLine.contains(StringPool.DOUBLE_SLASH) && !trimmedLine.startsWith(StringPool.STAR)) {

                while (trimmedLine.contains(StringPool.TAB)) {
                    line = StringUtil.replaceLast(line, StringPool.TAB, StringPool.SPACE);

                    trimmedLine = StringUtil.replaceLast(trimmedLine, StringPool.TAB, StringPool.SPACE);
                }

                while (trimmedLine.contains(StringPool.DOUBLE_SPACE)
                        && !trimmedLine.contains(StringPool.QUOTE + StringPool.DOUBLE_SPACE)
                        && !fileName.endsWith(".vm")) {

                    line = StringUtil.replaceLast(line, StringPool.DOUBLE_SPACE, StringPool.SPACE);

                    trimmedLine = StringUtil.replaceLast(trimmedLine, StringPool.DOUBLE_SPACE,
                            StringPool.SPACE);
                }
            }

            if (!fileName.endsWith("/touch.jsp")) {
                int x = line.indexOf("<%@ include file");

                if (x != -1) {
                    x = line.indexOf(StringPool.QUOTE, x);

                    int y = line.indexOf(StringPool.QUOTE, x + 1);

                    if (y != -1) {
                        String includeFileName = line.substring(x + 1, y);

                        Matcher matcher = _jspIncludeFilePattern.matcher(includeFileName);

                        if (!matcher.find()) {
                            processErrorMessage(fileName, "include: " + fileName + " " + lineCount);
                        }
                    }
                }
            }

            line = replacePrimitiveWrapperInstantiation(fileName, line, lineCount);

            previousLine = line;

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

    content = sb.toString();

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

    content = formatTaglibQuotes(fileName, content, StringPool.QUOTE);
    content = formatTaglibQuotes(fileName, content, StringPool.APOSTROPHE);

    if (Validator.isNotNull(previousAttributeAndValue)) {
        content = StringUtil.replaceFirst(content, previousAttributeAndValue + "\n" + currentAttributeAndValue,
                currentAttributeAndValue + "\n" + previousAttributeAndValue);
    }

    if (hasUnsortedExceptions) {
        if ((StringUtil.count(content, currentException) > 1)
                || (StringUtil.count(content, previousException) > 1)) {

            processErrorMessage(fileName, "unsorted exceptions: " + fileName);
        } else {
            content = StringUtil.replaceFirst(content, previousException, currentException);

            content = StringUtil.replaceLast(content, currentException, previousException);
        }
    }

    return content;
}

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

License:Open Source License

protected boolean hasUnusedTaglib(String fileName, String line) {
    if (!line.startsWith("<%@ taglib uri=")) {
        return false;
    }//from www . jav  a 2 s  . c o  m

    int x = line.indexOf(" prefix=");

    if (x == -1) {
        return false;
    }

    x = line.indexOf(StringPool.QUOTE, x);

    int y = line.indexOf(StringPool.QUOTE, x + 1);

    if ((x == -1) || (y == -1)) {
        return false;
    }

    String taglibPrefix = line.substring(x + 1, y);

    String regex = StringPool.LESS_THAN + taglibPrefix + StringPool.COLON;

    return hasUnusedJSPTerm(fileName, regex, "taglib");
}

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

License:Open Source License

protected String fixPoshiXMLNumberOfTabs(String content) {
    Matcher matcher = _poshiTabsPattern.matcher(content);

    int tabCount = 0;

    boolean ignoredCdataBlock = false;
    boolean ignoredCommentBlock = false;

    while (matcher.find()) {
        String statement = matcher.group();

        Matcher quoteWithSlashMatcher = _poshiQuoteWithSlashPattern.matcher(statement);

        String fixedQuoteStatement = statement;

        if (quoteWithSlashMatcher.find()) {
            fixedQuoteStatement = StringUtil.replace(statement, quoteWithSlashMatcher.group(), "\"\"");
        }//from  ww  w  .j  a  va2s.  com

        Matcher closingTagMatcher = _poshiClosingTagPattern.matcher(fixedQuoteStatement);
        Matcher openingTagMatcher = _poshiOpeningTagPattern.matcher(fixedQuoteStatement);
        Matcher wholeTagMatcher = _poshiWholeTagPattern.matcher(fixedQuoteStatement);

        if (closingTagMatcher.find() && !openingTagMatcher.find() && !wholeTagMatcher.find()
                && !statement.contains("<!--") && !statement.contains("-->") && !statement.contains("<![CDATA[")
                && !statement.contains("]]>")) {

            tabCount--;
        }

        if (statement.contains("]]>")) {
            ignoredCdataBlock = false;
        } else if (statement.contains("<![CDATA[")) {
            ignoredCdataBlock = true;
        }

        if (statement.contains("-->")) {
            ignoredCommentBlock = false;
        } else if (statement.contains("<!--")) {
            ignoredCommentBlock = true;
        }

        if (!ignoredCommentBlock && !ignoredCdataBlock) {
            StringBundler sb = new StringBundler(tabCount + 1);

            for (int i = 0; i < tabCount; i++) {
                sb.append(StringPool.TAB);
            }

            sb.append(StringPool.LESS_THAN);

            String replacement = sb.toString();

            if (!replacement.equals(matcher.group(1))) {
                String newStatement = StringUtil.replace(statement, matcher.group(1), replacement);

                return StringUtil.replaceFirst(content, statement, newStatement, matcher.start());
            }
        }

        if (openingTagMatcher.find() && !closingTagMatcher.find() && !wholeTagMatcher.find()
                && !statement.contains("<!--") && !statement.contains("-->") && !statement.contains("<![CDATA[")
                && !statement.contains("]]>")) {

            tabCount++;
        }
    }

    return content;
}

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

License:Open Source License

protected String sortPoshiAttributes(String fileName, String content) throws Exception {

    StringBundler sb = new StringBundler();

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

        String line = null;//from  w w  w  .  j  a va 2 s .  co m

        int lineCount = 0;

        boolean sortAttributes = true;

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

            String trimmedLine = StringUtil.trimLeading(line);

            if (sortAttributes) {
                if (trimmedLine.startsWith(StringPool.LESS_THAN)
                        && trimmedLine.endsWith(StringPool.GREATER_THAN) && !trimmedLine.startsWith("<%")
                        && !trimmedLine.startsWith("<!")) {

                    line = sortAttributes(fileName, line, lineCount, false);
                } else if (trimmedLine.startsWith("<![CDATA[") && !trimmedLine.endsWith("]]>")) {

                    sortAttributes = false;
                }
            } else if (trimmedLine.endsWith("]]>")) {
                sortAttributes = true;
            }

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

    content = sb.toString();

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

    return content;
}

From source file:com.liferay.util.mail.InternetAddressUtil.java

License:Open Source License

public static String toString(Address address) {
    InternetAddress internetAddress = (InternetAddress) address;

    if (internetAddress != null) {
        StringBundler sb = new StringBundler(5);

        String personal = internetAddress.getPersonal();
        String emailAddress = internetAddress.getAddress();

        if (Validator.isNotNull(personal)) {
            sb.append(personal);//from   w ww .j a v a  2  s . c  o m
            sb.append(StringPool.SPACE);
            sb.append(StringPool.LESS_THAN);
            sb.append(emailAddress);
            sb.append(StringPool.GREATER_THAN);
        } else {
            sb.append(emailAddress);
        }

        return sb.toString();
    }

    return StringPool.BLANK;
}

From source file:com.liferay.wiki.service.persistence.impl.WikiPageFinderImpl.java

License:Open Source License

protected int doCountByCreateDate(long groupId, long nodeId, Timestamp createDate, boolean before,
        boolean inlineSQLHelper) {

    Session session = null;/*  ww  w.  j a  v  a  2  s  .  c  o  m*/

    try {
        session = openSession();

        String sql = CustomSQLUtil.get(getClass(), COUNT_BY_CREATE_DATE);

        String createDateComparator = StringPool.GREATER_THAN;

        if (before) {
            createDateComparator = StringPool.LESS_THAN;
        }

        sql = StringUtil.replace(sql, "[$CREATE_DATE_COMPARATOR$]", createDateComparator);

        if (inlineSQLHelper) {
            sql = InlineSQLHelperUtil.replacePermissionCheck(sql, WikiPage.class.getName(),
                    "WikiPage.resourcePrimKey", groupId);
        }

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

        q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);
        qPos.add(nodeId);
        qPos.add(createDate);
        qPos.add(true);
        qPos.add(WorkflowConstants.STATUS_APPROVED);

        Iterator<Long> itr = q.iterate();

        if (itr.hasNext()) {
            Long count = itr.next();

            if (count != null) {
                return count.intValue();
            }
        }

        return 0;
    } catch (Exception e) {
        throw new SystemException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.liferay.wiki.service.persistence.impl.WikiPageFinderImpl.java

License:Open Source License

protected List<WikiPage> doFindByCreateDate(long groupId, long nodeId, Timestamp createDate, boolean before,
        int start, int end, boolean inlineSQLHelper) {

    Session session = null;//from  www.  j a va  2  s.co  m

    try {
        session = openSession();

        String sql = CustomSQLUtil.get(getClass(), FIND_BY_CREATE_DATE);

        String createDateComparator = StringPool.GREATER_THAN;

        if (before) {
            createDateComparator = StringPool.LESS_THAN;
        }

        sql = StringUtil.replace(sql, "[$CREATE_DATE_COMPARATOR$]", createDateComparator);

        if (inlineSQLHelper) {
            sql = InlineSQLHelperUtil.replacePermissionCheck(sql, WikiPage.class.getName(),
                    "WikiPage.resourcePrimKey", groupId);
        }

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

        q.addEntity("WikiPage", WikiPageImpl.class);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);
        qPos.add(nodeId);
        qPos.add(createDate);
        qPos.add(true);
        qPos.add(WorkflowConstants.STATUS_APPROVED);

        return (List<WikiPage>) QueryUtil.list(q, getDialect(), start, end);
    } catch (Exception e) {
        throw new SystemException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.rivetlogic.quickquestions.action.util.MBUtil.java

License:Open Source License

public static String getParentMessageIdString(Message message) throws Exception {

    // If the previous block failed, try to get the parent message ID from
    // the "References" header as explained in
    // http://cr.yp.to/immhf/thread.html. Some mail clients such as Yahoo!
    // Mail use the "In-Reply-To" header, so we check that as well.

    String parentHeader = null;//from   w ww  . j  a va 2 s .  co  m

    String[] references = message.getHeader("References");

    if (ArrayUtil.isNotEmpty(references)) {
        String reference = references[0];

        int x = reference.lastIndexOf(StringPool.LESS_THAN + MESSAGE_POP_PORTLET_PREFIX);

        if (x > -1) {
            int y = reference.indexOf(StringPool.GREATER_THAN, x);

            parentHeader = reference.substring(x, y + 1);
        }
    }

    if (parentHeader == null) {
        String[] inReplyToHeaders = message.getHeader("In-Reply-To");

        if (ArrayUtil.isNotEmpty(inReplyToHeaders)) {
            parentHeader = inReplyToHeaders[0];
        }
    }

    if (Validator.isNull(parentHeader) || !parentHeader.startsWith(MESSAGE_POP_PORTLET_PREFIX, 1)) {

        parentHeader = _getParentMessageIdFromSubject(message);
    }

    return parentHeader;
}

From source file:org.vaadin.tori.service.LiferayToriMailService.java

License:Apache License

private static String getMailId(final long companyId, final long categoryId, final long messageId)
        throws PortalException, SystemException {

    Company company = CompanyLocalServiceUtil.getCompany(companyId);
    String mx = company.getMx();//  w  ww  . ja  va  2  s  .  com
    StringBundler sb = new StringBundler(10);

    sb.append(StringPool.LESS_THAN);
    sb.append(POP_PORTLET_PREFIX);
    sb.append(categoryId);
    sb.append(StringPool.PERIOD);
    sb.append(messageId);
    sb.append(StringPool.AT);

    String sd = PropsUtil.get(PropsKeys.POP_SERVER_SUBDOMAIN);
    if (sd != null && !"null".equals(sd.toLowerCase())) {
        sb.append(sd);
        sb.append(StringPool.PERIOD);
    }

    sb.append(mx);
    sb.append(StringPool.GREATER_THAN);

    return sb.toString();
}