List of usage examples for com.liferay.portal.kernel.util StringPool GREATER_THAN
String GREATER_THAN
To view the source code for com.liferay.portal.kernel.util StringPool GREATER_THAN.
Click Source Link
From source file:com.liferay.tools.sourceformatter.JavaSourceProcessor.java
License:Open Source License
protected String getTruncateLongLinesContent(String content, String line, String trimmedLine, int lineCount) { String indent = StringPool.BLANK; for (int i = 0; i < getLeadingTabCount(line); i++) { indent += StringPool.TAB;/*ww w . java 2 s . c o m*/ } if (line.endsWith(StringPool.OPEN_PARENTHESIS) || line.endsWith(StringPool.SEMICOLON)) { int x = line.indexOf(" = "); if (x != -1) { String firstLine = line.substring(0, x + 2); if (firstLine.contains(StringPool.QUOTE)) { return null; } String secondLine = indent + StringPool.TAB + line.substring(x + 3); if (line.endsWith(StringPool.SEMICOLON)) { return StringUtil.replace(content, "\n" + line + "\n", "\n" + firstLine + "\n" + secondLine + "\n"); } else if (Validator.isNotNull(getNextLine(content, lineCount))) { return StringUtil.replace(content, "\n" + line + "\n", "\n" + firstLine + "\n" + secondLine + "\n" + StringPool.TAB); } } } if (line.endsWith(StringPool.CLOSE_PARENTHESIS) || line.endsWith(StringPool.COMMA) || line.endsWith(StringPool.OPEN_CURLY_BRACE) || line.endsWith(StringPool.SEMICOLON)) { int x = 0; while (true) { x = line.indexOf(", ", x + 1); if (x == -1) { break; } if (isValidJavaParameter(line.substring(0, x))) { String firstLine = line.substring(0, x + 1); String secondLine = indent + line.substring(x + 2); return StringUtil.replace(content, "\n" + line + "\n", "\n" + firstLine + "\n" + secondLine + "\n"); } } } if ((line.endsWith(StringPool.OPEN_CURLY_BRACE) || line.endsWith(StringPool.SEMICOLON)) && (trimmedLine.startsWith("private ") || trimmedLine.startsWith("protected ") || trimmedLine.startsWith("public "))) { String firstLine = null; int x = 0; while (true) { int y = line.indexOf(" extends ", x); if (y != -1) { firstLine = line.substring(0, y); if (StringUtil.count(firstLine, StringPool.GREATER_THAN) != StringUtil.count(firstLine, StringPool.LESS_THAN)) { x = y + 1; continue; } } else { y = line.indexOf(" implements "); if (y == -1) { y = line.indexOf(" throws "); } if (y == -1) { break; } firstLine = line.substring(0, y); } String secondLine = indent + StringPool.TAB + line.substring(y + 1); return StringUtil.replace(content, "\n" + line + "\n", "\n" + firstLine + "\n" + secondLine + "\n"); } } if ((line.endsWith(StringPool.CLOSE_PARENTHESIS) || line.endsWith(StringPool.OPEN_CURLY_BRACE)) && (trimmedLine.startsWith("private ") || trimmedLine.startsWith("protected ") || trimmedLine.startsWith("public "))) { int x = line.indexOf(StringPool.OPEN_PARENTHESIS); if ((x != -1) && (line.charAt(x + 1) != CharPool.CLOSE_PARENTHESIS)) { String secondLineIndent = indent + StringPool.TAB; if (line.endsWith(StringPool.CLOSE_PARENTHESIS)) { secondLineIndent += StringPool.TAB; } String firstLine = line.substring(0, x + 1); String secondLine = secondLineIndent + line.substring(x + 1); return StringUtil.replace(content, "\n" + line + "\n", "\n" + firstLine + "\n" + secondLine + "\n"); } } if (line.endsWith(StringPool.SEMICOLON)) { int x = line.indexOf(StringPool.OPEN_PARENTHESIS); if (x != -1) { char c = line.charAt(x - 1); if ((c != CharPool.SPACE) && (c != CharPool.TAB) && (line.charAt(x + 1) != CharPool.CLOSE_PARENTHESIS)) { String firstLine = line.substring(0, x + 1); if (firstLine.contains(StringPool.QUOTE)) { return null; } String secondLine = indent + StringPool.TAB + line.substring(x + 1); return StringUtil.replace(content, "\n" + line + "\n", "\n" + firstLine + "\n" + secondLine + "\n"); } } } if (line.contains(StringPool.TAB + "for (") && line.endsWith(" {")) { int x = line.indexOf(" : "); if (x != -1) { String firstLine = line.substring(0, x + 2); String secondLine = indent + StringPool.TAB + StringPool.TAB + line.substring(x + 3); return StringUtil.replace(content, "\n" + line + "\n", "\n" + firstLine + "\n" + secondLine + "\n" + "\n"); } } return null; }
From source file:com.liferay.tools.sourceformatter.JavaSourceProcessor.java
License:Open Source License
protected boolean isValidJavaParameter(String javaParameter) { if (javaParameter.contains(" implements ") || javaParameter.contains(" throws ")) { return false; }/*from w ww . j a v a 2 s .c o m*/ int quoteCount = StringUtil.count(javaParameter, StringPool.QUOTE); if ((quoteCount % 2) == 1) { return false; } javaParameter = stripQuotes(javaParameter, CharPool.QUOTE); int openParenthesisCount = StringUtil.count(javaParameter, StringPool.OPEN_PARENTHESIS); int closeParenthesisCount = StringUtil.count(javaParameter, StringPool.CLOSE_PARENTHESIS); int lessThanCount = StringUtil.count(javaParameter, StringPool.LESS_THAN); int greaterThanCount = StringUtil.count(javaParameter, StringPool.GREATER_THAN); int openCurlyBraceCount = StringUtil.count(javaParameter, StringPool.OPEN_CURLY_BRACE); int closeCurlyBraceCount = StringUtil.count(javaParameter, StringPool.CLOSE_CURLY_BRACE); if ((openParenthesisCount == closeParenthesisCount) && (lessThanCount == greaterThanCount) && (openCurlyBraceCount == closeCurlyBraceCount)) { return true; } return false; }
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;/*w w w . j a v a2 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;//from w w w. j a v a 2s . com 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.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 www. j a va2s .c o 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.bridges.common.ScriptPostProcess.java
License:Open Source License
public void postProcessPage(PortletURL actionURL, String actionParameterName) { processPage("<a", StringPool.GREATER_THAN, "href=", actionURL, actionParameterName); processPage("<A", StringPool.GREATER_THAN, "HREF=", actionURL, actionParameterName); processPage("<area", StringPool.GREATER_THAN, "href=", actionURL, actionParameterName); processPage("<AREA", StringPool.GREATER_THAN, "HREF=", actionURL, actionParameterName); processPage("<FORM", StringPool.GREATER_THAN, "ACTION=", actionURL, actionParameterName); processPage("<form", StringPool.GREATER_THAN, "action=", actionURL, actionParameterName); }
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 ww w. j a v a 2 s .co 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;/* w ww .j ava 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 ava 2 s . c o 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 w w . j a v a2 s .c om 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; }