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

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

Introduction

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

Prototype

String SLASH

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

Click Source Link

Usage

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

License:Open Source License

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

    if (!portalSource || !fileName.endsWith("PortletDataHandler.java")) {
        return;/*from www.  j av a 2 s. co  m*/
    }

    int pos = content.indexOf("setDeletionSystemEventStagedModelTypes");

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

    String deletionSystemEventStagedModelTypes = content.substring(pos, content.indexOf(");", pos));

    Matcher matcher = _stagedModelTypesPattern.matcher(deletionSystemEventStagedModelTypes);

    while (matcher.find()) {
        String stagedModelTypeClassName = matcher.group(1);

        pos = stagedModelTypeClassName.indexOf(".class");

        if (pos == -1) {
            pos = stagedModelTypeClassName.indexOf("Constants");
        }

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

        String className = stagedModelTypeClassName.substring(0, pos);

        Pattern packageNamePattern = Pattern
                .compile("import (com\\.liferay\\.[a-zA-Z\\.]*)\\.model\\." + className + ";");

        Matcher packageNameMatcher = packageNamePattern.matcher(content);

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

        StringBundler sb = new StringBundler(6);

        sb.append(BASEDIR);
        sb.append(fileName.substring(0, fileName.indexOf("/src/") + 5));
        sb.append(StringUtil.replace(packageNameMatcher.group(1), StringPool.PERIOD, StringPool.SLASH));
        sb.append("/service/impl/");
        sb.append(className);
        sb.append("LocalServiceImpl.java");

        String localServiceImplFileName = sb.toString();

        String localServiceImplContent = fileUtil.read(localServiceImplFileName);

        if (localServiceImplContent == null) {
            System.out.println("Unable to read " + localServiceImplFileName);

            return;
        }

        if (!localServiceImplContent.contains("@SystemEvent")) {
            processErrorMessage(fileName, "Missing deletion system event: " + localServiceImplFileName);
        }
    }
}

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

License:Open Source License

@Override
protected String doFormat(File file, String fileName, String absolutePath, String content) throws Exception {

    if (isGenerated(content)) {
        return content;
    }/* ww  w .  j  a  va  2s .c  o m*/

    String className = file.getName();

    int pos = className.lastIndexOf(StringPool.PERIOD);

    className = className.substring(0, pos);

    String packagePath = fileName;

    int packagePathX = packagePath.indexOf("/src/");

    if (packagePathX == -1) {
        packagePathX = packagePath.indexOf("/integration/") + 8;
    }

    int packagePathY = packagePath.lastIndexOf(StringPool.SLASH);

    if ((packagePathX + 5) >= packagePathY) {
        packagePath = StringPool.BLANK;
    } else {
        packagePath = packagePath.substring(packagePathX + 5, packagePathY);
    }

    packagePath = StringUtil.replace(packagePath, StringPool.SLASH, StringPool.PERIOD);

    if (packagePath.endsWith(".model")) {
        if (content.contains("extends " + className + "Model")) {
            return content;
        }
    }

    String newContent = content;

    if (newContent.contains("$\n */")) {
        processErrorMessage(fileName, "*: " + fileName);

        newContent = StringUtil.replace(newContent, "$\n */", "$\n *\n */");
    }

    newContent = fixCopyright(newContent, absolutePath, fileName);

    if (newContent.contains(className + ".java.html")) {
        processErrorMessage(fileName, "Java2HTML: " + fileName);
    }

    if (newContent.contains(" * @author Raymond Aug") && !newContent.contains(" * @author Raymond Aug\u00e9")) {

        newContent = newContent.replaceFirst("Raymond Aug.++", "Raymond Aug\u00e9");

        processErrorMessage(fileName, "UTF-8: " + fileName);
    }

    newContent = fixDataAccessConnection(className, newContent);
    newContent = fixSessionKey(fileName, newContent, sessionKeyPattern);

    newContent = StringUtil.replace(newContent,
            new String[] { "com.liferay.portal.PortalException", "com.liferay.portal.SystemException",
                    "com.liferay.util.LocalizationUtil" },
            new String[] { "com.liferay.portal.kernel.exception.PortalException",
                    "com.liferay.portal.kernel.exception.SystemException",
                    "com.liferay.portal.kernel.util.LocalizationUtil" });

    newContent = StringUtil.replace(newContent, " final static ", " static final ");

    newContent = fixCompatClassImports(absolutePath, newContent);

    newContent = stripJavaImports(newContent, packagePath, className);

    newContent = StringUtil.replace(newContent,
            new String[] { ";\n/**", "\t/*\n\t *", "catch(", "else{", "if(", "for(", "while(", "List <", "){\n",
                    "]{\n", ";;\n" },
            new String[] { ";\n\n/**", "\t/**\n\t *", "catch (", "else {", "if (", "for (", "while (", "List<",
                    ") {\n", "] {\n", ";\n" });

    while (true) {
        Matcher matcher = _incorrectLineBreakPattern.matcher(newContent);

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

        newContent = StringUtil.replaceFirst(newContent, StringPool.NEW_LINE, StringPool.BLANK,
                matcher.start());
    }

    newContent = sortAnnotations(newContent, StringPool.BLANK);

    Matcher matcher = _logPattern.matcher(newContent);

    if (matcher.find()) {
        String logClassName = matcher.group(1);

        if (!logClassName.equals(className)) {
            newContent = StringUtil.replaceLast(newContent, logClassName + ".class)", className + ".class)");
        }
    }

    if (!isExcluded(_staticLogVariableExclusions, absolutePath)) {
        newContent = StringUtil.replace(newContent, "private Log _log", "private static final Log _log");
    }

    if (newContent.contains("*/\npackage ")) {
        processErrorMessage(fileName, "package: " + fileName);
    }

    if (!newContent.endsWith("\n\n}") && !newContent.endsWith("{\n}")) {
        processErrorMessage(fileName, "}: " + fileName);
    }

    if (portalSource && !_allowUseServiceUtilInServiceImpl && !className.equals("BaseServiceImpl")
            && className.endsWith("ServiceImpl") && newContent.contains("ServiceUtil.")) {

        processErrorMessage(fileName, "ServiceUtil: " + fileName);
    }

    // LPS-34911

    if (portalSource && !isExcluded(_upgradeServiceUtilExclusions, absolutePath)
            && fileName.contains("/portal/upgrade/") && !fileName.contains("/test/")
            && newContent.contains("ServiceUtil.")) {

        processErrorMessage(fileName, "ServiceUtil: " + fileName);
    }

    if (!isRunsOutsidePortal(absolutePath) && !isExcluded(_proxyExclusions, absolutePath)
            && newContent.contains("import java.lang.reflect.Proxy;")) {

        processErrorMessage(fileName, "Proxy: " + fileName);
    }

    if (newContent.contains("import edu.emory.mathcs.backport.java")) {
        processErrorMessage(fileName, "edu.emory.mathcs.backport.java: " + fileName);
    }

    if (newContent.contains("import jodd.util.StringPool")) {
        processErrorMessage(fileName, "jodd.util.StringPool: " + fileName);
    }

    // LPS-45027

    if (newContent.contains("com.liferay.portal.kernel.util.UnmodifiableList")) {

        processErrorMessage(fileName, "Use java.util.Collections.unmodifiableList instead of "
                + "com.liferay.portal.kernel.util.UnmodifiableList: " + fileName);
    }

    // LPS-28266

    for (int pos1 = -1;;) {
        pos1 = newContent.indexOf(StringPool.TAB + "try {", pos1 + 1);

        if (pos1 == -1) {
            break;
        }

        int pos2 = newContent.indexOf(StringPool.TAB + "try {", pos1 + 1);
        int pos3 = newContent.indexOf("\"select count(", pos1);

        if ((pos2 != -1) && (pos3 != -1) && (pos2 < pos3)) {
            continue;
        }

        int pos4 = newContent.indexOf("rs.getLong(1)", pos1);
        int pos5 = newContent.indexOf(StringPool.TAB + "finally {", pos1);

        if ((pos3 == -1) || (pos4 == -1) || (pos5 == -1)) {
            break;
        }

        if ((pos3 < pos4) && (pos4 < pos5)) {
            processErrorMessage(fileName, "Use getInt(1) for count: " + fileName);
        }
    }

    // LPS-33070

    matcher = _processCallablePattern.matcher(content);

    if (matcher.find() && !content.contains("private static final long serialVersionUID")) {

        processErrorMessage(fileName, "Assign ProcessCallable implementation a serialVersionUID: " + fileName);
    }

    checkLanguageKeys(fileName, newContent, languageKeyPattern);

    newContent = StringUtil.replace(newContent, StringPool.TAB + "for (;;) {",
            StringPool.TAB + "while (true) {");

    // LPS-36174

    if (_checkUnprocessedExceptions && !fileName.contains("/test/")) {
        checkUnprocessedExceptions(newContent, file, packagePath, fileName);
    }

    // LPS-39508

    if (!isExcluded(_secureRandomExclusions, absolutePath) && !isRunsOutsidePortal(absolutePath)
            && content.contains("java.security.SecureRandom")
            && !content.contains("javax.crypto.KeyGenerator")) {

        processErrorMessage(fileName, "Use SecureRandomUtil or com.liferay.portal.kernel.security."
                + "SecureRandom instead of java.security.SecureRandom: " + fileName);
    }

    // LPS-41315

    checkLogLevel(newContent, fileName, "debug");
    checkLogLevel(newContent, fileName, "info");
    checkLogLevel(newContent, fileName, "trace");
    checkLogLevel(newContent, fileName, "warn");

    // LPS-46632

    checkSystemEventAnnotations(newContent, fileName);

    // LPS-41205

    if (fileName.contains("/upgrade/") && newContent.contains("LocaleUtil.getDefault()")) {

        processErrorMessage(fileName, "Use UpgradeProcessUtil.getDefaultLanguageId(companyId) "
                + "instead of LocaleUtil.getDefault(): " + fileName);
    }

    // LPS-46017

    newContent = StringUtil.replace(newContent, " static interface ", " interface ");

    // LPS-47055

    newContent = fixSystemExceptions(newContent);

    // LPS-47648

    if (portalSource && fileName.contains("/test/integration/")) {
        newContent = StringUtil.replace(newContent, "FinderCacheUtil.clearCache();", StringPool.BLANK);
    }

    // LPS-47682

    newContent = fixIncorrectParameterTypeForLanguageUtil(newContent, false, fileName);

    if (portalSource && fileName.contains("/portal-service/")
            && content.contains("import javax.servlet.jsp.")) {

        processErrorMessage(fileName, "Never import javax.servlet.jsp.* from portal-service " + fileName);
    }

    // LPS-48153

    //newContent = applyDiamondOperator(newContent);

    // LPS-49552

    checkFinderCacheInterfaceMethod(fileName, newContent);

    newContent = fixIncorrectEmptyLineBeforeCloseCurlyBrace(newContent, fileName);

    pos = newContent.indexOf("\npublic ");

    if (pos != -1) {
        String javaClassContent = newContent.substring(pos + 1);

        String beforeJavaClass = newContent.substring(0, pos + 1);

        int javaClassLineCount = StringUtil.count(beforeJavaClass, "\n") + 1;

        newContent = formatJavaTerms(className, fileName, absolutePath, newContent, javaClassContent,
                javaClassLineCount, _checkJavaFieldTypesExclusions, _javaTermAccessLevelModifierExclusions,
                _javaTermSortExclusions, _testAnnotationsExclusions);
    }

    newContent = formatJava(fileName, absolutePath, newContent);

    return StringUtil.replace(newContent, "\n\n\n", "\n\n");
}

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

License:Open Source License

protected String getCombinedLinesContent(String content, String fileName, String absolutePath, String line,
        String trimmedLine, int lineLength, int lineCount, String previousLine, int lineTabCount,
        int previousLineTabCount) {

    if (Validator.isNull(line) || Validator.isNull(previousLine)
            || isExcluded(_fitOnSingleLineExclusions, absolutePath, lineCount)) {

        return null;
    }//  w w w  . ja  v  a 2s  . c o m

    String trimmedPreviousLine = StringUtil.trimLeading(previousLine);

    if (line.contains("// ") || line.contains("*/") || line.contains("*/") || previousLine.contains("// ")
            || previousLine.contains("*/") || previousLine.contains("*/")) {

        return null;
    }

    int tabDiff = lineTabCount - previousLineTabCount;

    if (previousLine.endsWith(" extends")) {
        return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                previousLine, "extends", tabDiff, false, false, false);
    }

    if (previousLine.endsWith(" implements")) {
        return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                previousLine, "implements ", tabDiff, false, false, false);
    }

    if (trimmedLine.startsWith("+ ") || trimmedLine.startsWith("- ") || trimmedLine.startsWith("|| ")
            || trimmedLine.startsWith("&& ")) {

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

        String linePart = trimmedLine.substring(0, pos);

        return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                previousLine, linePart, tabDiff, true, true, false);
    }

    int previousLineLength = getLineLength(previousLine);

    if ((trimmedLine.length() + previousLineLength) < _MAX_LINE_LENGTH) {
        if (trimmedPreviousLine.startsWith("for ") && previousLine.endsWith(StringPool.COLON)
                && line.endsWith(StringPool.OPEN_CURLY_BRACE)) {

            return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                    previousLine, null, tabDiff, false, true, false);
        }

        if (line.endsWith(StringPool.SEMICOLON) && !previousLine.endsWith(StringPool.COLON)
                && !previousLine.endsWith(StringPool.OPEN_BRACKET)
                && !previousLine.endsWith(StringPool.OPEN_CURLY_BRACE)
                && !previousLine.endsWith(StringPool.OPEN_PARENTHESIS)
                && !previousLine.endsWith(StringPool.PERIOD) && (lineTabCount == (previousLineTabCount + 1))) {

            return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                    previousLine, null, tabDiff, false, true, false);
        }

        if ((trimmedPreviousLine.startsWith("if ") || trimmedPreviousLine.startsWith("else "))
                && (previousLine.endsWith("||") || previousLine.endsWith("&&"))
                && line.endsWith(StringPool.OPEN_CURLY_BRACE)) {

            return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                    previousLine, null, tabDiff, false, true, false);
        }

        if ((trimmedLine.startsWith("extends ") || trimmedLine.startsWith("implements ")
                || trimmedLine.startsWith("throws"))
                && (line.endsWith(StringPool.OPEN_CURLY_BRACE) || line.endsWith(StringPool.SEMICOLON))
                && (lineTabCount == (previousLineTabCount + 1))) {

            return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                    previousLine, null, tabDiff, false, true, false);
        }

        if (previousLine.endsWith(StringPool.EQUAL) && line.endsWith(StringPool.OPEN_PARENTHESIS)) {

            String nextLine = getNextLine(content, lineCount);

            if (nextLine.endsWith(StringPool.SEMICOLON)) {
                return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                        previousLine, null, tabDiff, false, true, true);
            }
        }
    }

    if (((trimmedLine.length() + previousLineLength) <= _MAX_LINE_LENGTH)
            && (previousLine.endsWith(StringPool.OPEN_BRACKET)
                    || previousLine.endsWith(StringPool.OPEN_PARENTHESIS)
                    || previousLine.endsWith(StringPool.PERIOD))
            && line.endsWith(StringPool.SEMICOLON)) {

        return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                previousLine, null, tabDiff, false, false, false);
    }

    if (previousLine.endsWith(StringPool.EQUAL) && line.endsWith(StringPool.SEMICOLON)) {

        String tempLine = trimmedLine;

        for (int pos = 0;;) {
            pos = tempLine.indexOf(StringPool.DASH);

            if (pos == -1) {
                pos = tempLine.indexOf(StringPool.PLUS);
            }

            if (pos == -1) {
                pos = tempLine.indexOf(StringPool.SLASH);
            }

            if (pos == -1) {
                pos = tempLine.indexOf(StringPool.STAR);
            }

            if (pos == -1) {
                pos = tempLine.indexOf("||");
            }

            if (pos == -1) {
                pos = tempLine.indexOf("&&");
            }

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

            String linePart = tempLine.substring(0, pos);

            int openParenthesisCount = StringUtil.count(linePart, StringPool.OPEN_PARENTHESIS);
            int closeParenthesisCount = StringUtil.count(linePart, StringPool.CLOSE_PARENTHESIS);

            if (openParenthesisCount == closeParenthesisCount) {
                return null;
            }

            tempLine = tempLine.substring(0, pos) + tempLine.substring(pos + 1);
        }

        int x = trimmedLine.indexOf(StringPool.OPEN_PARENTHESIS);

        if (x == 0) {
            x = trimmedLine.indexOf(StringPool.OPEN_PARENTHESIS, 1);
        }

        if (x != -1) {
            int y = trimmedLine.indexOf(StringPool.CLOSE_PARENTHESIS, x);
            int z = trimmedLine.indexOf(StringPool.QUOTE);

            if (((x + 1) != y) && ((z == -1) || (z > x))) {
                char previousChar = trimmedLine.charAt(x - 1);

                if ((previousChar != CharPool.CLOSE_PARENTHESIS) && (previousChar != CharPool.OPEN_PARENTHESIS)
                        && (previousChar != CharPool.SPACE)
                        && (previousLineLength + 1 + x) < _MAX_LINE_LENGTH) {

                    String linePart = trimmedLine.substring(0, x + 1);

                    if (linePart.startsWith(StringPool.OPEN_PARENTHESIS)
                            && !linePart.contains(StringPool.CLOSE_PARENTHESIS)) {

                        return null;
                    }

                    return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                            previousLine, linePart, tabDiff, true, true, false);
                }
            }
        }
    }

    if (previousLine.endsWith(StringPool.COMMA) && (previousLineTabCount == lineTabCount)
            && !previousLine.contains(StringPool.CLOSE_CURLY_BRACE)
            && (line.endsWith(") {") || !line.endsWith(StringPool.OPEN_CURLY_BRACE))) {

        int x = trimmedLine.indexOf(StringPool.COMMA);

        if (x != -1) {
            while ((previousLineLength + 1 + x) < _MAX_LINE_LENGTH) {
                String linePart = trimmedLine.substring(0, x + 1);

                if (isValidJavaParameter(linePart)) {
                    if (trimmedLine.equals(linePart)) {
                        return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength,
                                lineCount, previousLine, null, tabDiff, false, true, false);
                    } else {
                        return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength,
                                lineCount, previousLine, linePart + StringPool.SPACE, tabDiff, true, true,
                                false);
                    }
                }

                String partAfterComma = trimmedLine.substring(x + 1);

                int pos = partAfterComma.indexOf(StringPool.COMMA);

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

                x = x + pos + 1;
            }
        } else if (!line.endsWith(StringPool.OPEN_PARENTHESIS) && !line.endsWith(StringPool.PLUS)
                && !line.endsWith(StringPool.PERIOD)
                && (!trimmedLine.startsWith("new ") || !line.endsWith(StringPool.OPEN_CURLY_BRACE))
                && ((trimmedLine.length() + previousLineLength) < _MAX_LINE_LENGTH)) {

            return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                    previousLine, null, tabDiff, false, true, false);
        }
    }

    if (!previousLine.endsWith(StringPool.OPEN_PARENTHESIS)) {
        return null;
    }

    if (StringUtil.count(previousLine, StringPool.OPEN_PARENTHESIS) > 1) {
        int pos = trimmedPreviousLine.lastIndexOf(StringPool.OPEN_PARENTHESIS,
                trimmedPreviousLine.length() - 2);

        if ((pos > 0) && Character.isLetterOrDigit(trimmedPreviousLine.charAt(pos - 1))) {

            String filePart = trimmedPreviousLine.substring(pos + 1);

            if (!filePart.contains(StringPool.CLOSE_PARENTHESIS) && !filePart.contains(StringPool.QUOTE)) {

                return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                        previousLine, filePart, tabDiff, false, false, false);
            }
        }
    }

    if ((trimmedLine.length() + previousLineLength) > _MAX_LINE_LENGTH) {
        return null;
    }

    if (line.endsWith(StringPool.COMMA)) {
        String strippedQuotesLine = stripQuotes(trimmedLine, CharPool.QUOTE);

        int openParenthesisCount = StringUtil.count(strippedQuotesLine, StringPool.OPEN_PARENTHESIS);
        int closeParenthesisCount = StringUtil.count(strippedQuotesLine, StringPool.CLOSE_PARENTHESIS);

        if (closeParenthesisCount > openParenthesisCount) {
            return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                    previousLine, null, tabDiff, false, false, false);
        }
    }

    if (((line.endsWith(StringPool.OPEN_CURLY_BRACE) && !trimmedLine.startsWith("new "))
            || line.endsWith(StringPool.CLOSE_PARENTHESIS))
            && (trimmedPreviousLine.startsWith("else ") || trimmedPreviousLine.startsWith("if ")
                    || trimmedPreviousLine.startsWith("private ")
                    || trimmedPreviousLine.startsWith("protected ")
                    || trimmedPreviousLine.startsWith("public "))) {

        return getCombinedLinesContent(content, fileName, line, trimmedLine, lineLength, lineCount,
                previousLine, null, tabDiff, false, false, false);
    }

    return null;
}

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

License:Open Source License

protected void addJSPReferenceFileNames(String fileName) {
    for (Map.Entry<String, String> entry : _jspContents.entrySet()) {
        String referenceFileName = entry.getKey();

        if (_includeFileNames.contains(referenceFileName)) {
            continue;
        }//from   ww w . ja va 2  s.com

        String sharedPath = fileName.substring(0, StringUtil.startsWithWeight(referenceFileName, fileName));

        if (Validator.isNull(sharedPath) || !sharedPath.contains(StringPool.SLASH)) {

            continue;
        }

        if (!sharedPath.endsWith(StringPool.SLASH)) {
            sharedPath = sharedPath.substring(0, sharedPath.lastIndexOf(CharPool.SLASH) + 1);
        }

        String content = null;

        for (int x = -1;;) {
            x = sharedPath.indexOf(CharPool.SLASH, x + 1);

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

            if (content == null) {
                content = entry.getValue();
            }

            if (content.contains("<%@ include file=\"" + fileName.substring(x))) {

                _includeFileNames.add(referenceFileName);

                break;
            }
        }
    }
}

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

License:Open Source License

protected String buildFullPathIncludeFileName(String fileName, String includeFileName) {

    String topLevelDirName = null;

    int x = includeFileName.indexOf(CharPool.SLASH, 1);

    if (x != -1) {
        topLevelDirName = includeFileName.substring(1, x);
    }//from  w ww .  jav  a2s .  com

    String path = fileName;

    while (true) {
        int y = path.lastIndexOf(CharPool.SLASH);

        if (y == -1) {
            return StringPool.BLANK;
        }

        if (Validator.isNull(topLevelDirName) || path.equals(topLevelDirName)
                || path.endsWith(StringPool.SLASH + topLevelDirName)) {

            String fullPathIncludeFileName = path.substring(0, y) + includeFileName;

            if (_jspContents.containsKey(fullPathIncludeFileName)
                    && !fullPathIncludeFileName.equals(fileName)) {

                return fullPathIncludeFileName;
            }
        }

        path = path.substring(0, y);
    }
}

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

License:Open Source License

@Override
protected void format() throws Exception {
    _moveFrequentlyUsedImportsToCommonInit = GetterUtil
            .getBoolean(getProperty("move.frequently.used.imports.to.common.init"));
    _unusedVariablesExclusions = getPropertyList("jsp.unused.variables.excludes.files");

    String[] excludes = new String[] { "**\\null.jsp", "**\\tools\\**" };
    String[] includes = new String[] { "**\\*.jsp", "**\\*.jspf", "**\\*.vm" };

    List<String> fileNames = getFileNames(excludes, includes);

    Pattern pattern = Pattern.compile("\\s*@\\s*include\\s*file=['\"](.*)['\"]");

    for (String fileName : fileNames) {
        File file = new File(BASEDIR + fileName);

        fileName = StringUtil.replace(fileName, StringPool.BACK_SLASH, StringPool.SLASH);

        String absolutePath = getAbsolutePath(file);

        String content = fileUtil.read(file);

        Matcher matcher = pattern.matcher(content);

        String newContent = content;

        while (matcher.find()) {
            newContent = StringUtil.replaceFirst(newContent, matcher.group(),
                    "@ include file=\"" + matcher.group(1) + "\"", matcher.start());
        }//from w  ww. j  a  v a2 s  .c o m

        processFormattedFile(file, fileName, content, newContent);

        if (portalSource && _moveFrequentlyUsedImportsToCommonInit && fileName.endsWith("/init.jsp")
                && !absolutePath.contains("/modules/") && !fileName.endsWith("/common/init.jsp")) {

            addImportCounts(content);
        }

        _jspContents.put(fileName, newContent);
    }

    if (portalSource && _moveFrequentlyUsedImportsToCommonInit) {
        moveFrequentlyUsedImportsToCommonInit(4);
    }

    for (String fileName : fileNames) {
        format(fileName);
    }
}

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

License:Open Source License

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

    String path = StringPool.BLANK;

    int pos = fileName.lastIndexOf(StringPool.SLASH);

    if (pos != -1) {
        path = fileName.substring(0, pos + 1);
    }/*from   w  w  w  .  j  a v a2s . c  om*/

    Properties properties = new Properties();

    InputStream inputStream = new FileInputStream(fileName);

    properties.load(inputStream);

    Enumeration<String> enu = (Enumeration<String>) properties.propertyNames();

    while (enu.hasMoreElements()) {
        String key = enu.nextElement();

        if (!key.endsWith("excludes.files")) {
            continue;
        }

        String value = properties.getProperty(key);

        if (Validator.isNull(value)) {
            continue;
        }

        List<String> propertyFileNames = ListUtil.fromString(value, StringPool.COMMA);

        for (String propertyFileName : propertyFileNames) {
            pos = propertyFileName.indexOf(StringPool.AT);

            if (pos != -1) {
                propertyFileName = propertyFileName.substring(0, pos);
            }

            if (!fileUtil.exists(path + propertyFileName)) {
                processErrorMessage(fileName, "Incorrect property value: " + propertyFileName + " " + fileName);
            }
        }
    }
}

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

License:Open Source License

public void printError(String fileName, String message) {
    if (_useProperties) {
        String encodedFileName = StringUtil.replace(fileName, StringPool.BACK_SLASH, StringPool.SLASH);

        _properties.remove(encodedFileName);
    }//  w  w w.j a  v a2  s  .  co m

    System.out.println(message);
}

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

License:Open Source License

public List<String> scanForFiles(DirectoryScanner directoryScanner) {
    directoryScanner.scan();//from  w w  w.j a v  a 2s  .co m

    String[] fileNamesArray = directoryScanner.getIncludedFiles();

    if (!_useProperties) {
        return ListUtil.toList(fileNamesArray);
    }

    List<String> fileNames = new ArrayList<String>(fileNamesArray.length);

    for (String fileName : fileNamesArray) {
        File file = new File(fileName);

        String encodedFileName = StringUtil.replace(fileName, StringPool.BACK_SLASH, StringPool.SLASH);

        long timestamp = GetterUtil.getLong(_properties.getProperty(encodedFileName));

        if (timestamp < file.lastModified()) {
            fileNames.add(fileName);

            _properties.setProperty(encodedFileName, String.valueOf(file.lastModified()));
        }
    }

    return fileNames;
}

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

License:Open Source License

protected String getTablesContent(String fileName) throws Exception {
    if (portalSource) {
        if (_tablesContent == null) {
            _tablesContent = getContent("sql/portal-tables.sql", 4);
        }/*from   w w w  . j a  va2  s .co  m*/

        return _tablesContent;
    }

    int pos = fileName.lastIndexOf(StringPool.SLASH);

    return getContent(fileName.substring(0, pos) + "/sql/tables.sql", 1);
}