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

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

Introduction

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

Prototype

String SEMICOLON

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

Click Source Link

Usage

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

License:Open Source License

protected String getCombinedLinesContent(String content, String fileName, String line, String trimmedLine,
        int lineLength, int lineCount, String previousLine, String linePart, int tabDiff,
        boolean addToPreviousLine, boolean extraSpace, boolean removeTabOnNextLine) {

    if (linePart == null) {
        String combinedLine = previousLine;

        if (extraSpace) {
            combinedLine += StringPool.SPACE;
        }/*from   w w  w  .j  av  a2 s.co  m*/

        combinedLine += trimmedLine;

        String nextLine = getNextLine(content, lineCount);

        if (nextLine == null) {
            return null;
        }

        if (removeTabOnNextLine) {
            return StringUtil.replace(content, "\n" + previousLine + "\n" + line + "\n" + nextLine + "\n",
                    "\n" + combinedLine + "\n" + nextLine.substring(1) + "\n");
        }

        if (line.endsWith(StringPool.OPEN_CURLY_BRACE) && (tabDiff != 0) && !previousLine.contains(" class ")
                && Validator.isNull(nextLine)) {

            return StringUtil.replace(content, "\n" + previousLine + "\n" + line + "\n", "\n" + combinedLine);
        }

        return StringUtil.replace(content, "\n" + previousLine + "\n" + line + "\n",
                "\n" + combinedLine + "\n");
    }

    String firstLine = previousLine;
    String secondLine = line;

    if (addToPreviousLine) {
        if (extraSpace) {
            firstLine += StringPool.SPACE;
        }

        firstLine += linePart;

        secondLine = StringUtil.replaceFirst(line, linePart, StringPool.BLANK);
    } else {
        if (((linePart.length() + lineLength) <= _MAX_LINE_LENGTH)
                && (line.endsWith(StringPool.OPEN_CURLY_BRACE) || line.endsWith(StringPool.SEMICOLON))) {

            firstLine = StringUtil.replaceLast(firstLine, StringUtil.trim(linePart), StringPool.BLANK);

            secondLine = StringUtil.replaceLast(line, StringPool.TAB, StringPool.TAB + linePart);
        } else {
            processErrorMessage(fileName, "line break: " + fileName + " " + lineCount);

            return null;
        }
    }

    firstLine = StringUtil.trimTrailing(firstLine);

    return StringUtil.replace(content, "\n" + previousLine + "\n" + line + "\n",
            "\n" + firstLine + "\n" + secondLine + "\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;
    }/*from   w  ww  . j a va2 s .  co 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.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;/*www .ja  v a2  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 String sortExceptions(String line) {
    if (!line.endsWith(StringPool.OPEN_CURLY_BRACE) && !line.endsWith(StringPool.SEMICOLON)) {

        return line;
    }//w w w. ja va2  s . c om

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

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

    String previousException = StringPool.BLANK;

    String[] exceptions = StringUtil.split(line.substring(x), CharPool.SPACE);

    for (int i = 1; i < exceptions.length; i++) {
        String exception = exceptions[i];

        if (exception.equals(StringPool.OPEN_CURLY_BRACE)) {
            break;
        }

        if (exception.endsWith(StringPool.COMMA) || exception.endsWith(StringPool.SEMICOLON)) {

            exception = exception.substring(0, exception.length() - 1);
        }

        if (Validator.isNotNull(previousException) && (previousException.compareToIgnoreCase(exception) > 0)) {

            line = StringUtil.replace(line, previousException + ", " + exception,
                    exception + ", " + previousException);

            return sortExceptions(line);
        }

        previousException = exception;
    }

    return line;
}

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

License:Open Source License

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

    String newContent = trimContent(content, false);

    newContent = StringUtil.replace(newContent,
            new String[] { "else{", "for(", "function (", "if(", "while(", "){\n", "= new Array();",
                    "= new Object();" },
            new String[] { "else {", "for (", "function(", "if (", "while (", ") {\n", "= [];", "= {};" });

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

        if (!matcher.find()) {
            break;
        }/*from   ww w.j  a  v  a  2 s.  c om*/

        String match = matcher.group();

        int pos = match.indexOf("var ");

        StringBundler sb = new StringBundler(4);

        sb.append(match.substring(0, match.length() - 2));
        sb.append(StringPool.SEMICOLON);
        sb.append("\n");
        sb.append(match.substring(0, pos + 4));

        newContent = StringUtil.replace(newContent, match, sb.toString());
    }

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

    checkLanguageKeys(fileName, newContent, languageKeyPattern);

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

    return newContent;
}

From source file:com.liferay.westminstercatechism.util.WCUtil.java

License:Open Source License

private WCUtil() {
    Document document = null;/*from w  w w  .  jav  a 2  s.  c o m*/

    try {
        ClassLoader classLoader = getClass().getClassLoader();

        URL url = classLoader
                .getResource("com/liferay/westminstercatechism/dependencies/" + "westminster_catechmism.xml");

        document = SAXReaderUtil.read(url);
    } catch (DocumentException de) {
        _log.error(de, de);
    }

    _shorter = new ArrayList<WCEntry>();

    Element rootElement = document.getRootElement();

    Element shorterElement = rootElement.element("shorter");

    List<Element> entryElements = shorterElement.elements("entry");

    for (Element entryElement : entryElements) {
        List<String[]> proofs = new ArrayList<String[]>();

        Element proofsElement = entryElement.element("proofs");

        List<Element> scripturesElements = proofsElement.elements("scriptures");

        for (Element scripturesElement : scripturesElements) {
            proofs.add(StringUtil.split(scripturesElement.getText(), StringPool.SEMICOLON));
        }

        _shorter.add(new WCEntry(entryElement.elementText("question"), entryElement.elementText("answer"),
                proofs.toArray(new String[0][0])));
    }

    _shorter = Collections.unmodifiableList(_shorter);

    _larger = new ArrayList<WCEntry>();

    Element largerElement = rootElement.element("larger");

    entryElements = largerElement.elements("entry");

    for (Element entry : entryElements) {
        List<String[]> proofs = new ArrayList<String[]>();

        Element proofsElement = entry.element("proofs");

        List<Element> scripturesElements = proofsElement.elements("scriptures");

        for (Element scriptures : scripturesElements) {
            proofs.add(StringUtil.split(scriptures.getText(), StringPool.SEMICOLON));
        }

        _larger.add(new WCEntry(entry.elementText("question"), entry.elementText("answer"),
                proofs.toArray(new String[0][0])));
    }

    _larger = Collections.unmodifiableList(_larger);
}

From source file:com.liferay.wsrp.bind.V2MarkupServiceImpl.java

License:Open Source License

protected void processUploadContexts(UploadContext[] uploadContexts, Http.Options httpOptions) {

    if (uploadContexts == null) {
        return;/*from  w w w  . j  a  v a2  s . co  m*/
    }

    for (UploadContext uploadContext : uploadContexts) {
        NamedString mimeAttribute = uploadContext.getMimeAttributes(0);

        String[] mimeAttributeValues = StringUtil.split(mimeAttribute.getValue(), StringPool.SEMICOLON);

        String name = StringUtil.replace(mimeAttributeValues[1], "name=", StringPool.BLANK);

        name = StringUtil.trim(name);

        String fileName = StringUtil.replace(mimeAttributeValues[2], "filename=", StringPool.BLANK);

        fileName = StringUtil.trim(fileName);

        String contentType = uploadContext.getMimeType();

        String charSet = null;

        if (contentType.contains(StringPool.SEMICOLON)) {
            int pos = contentType.indexOf(StringPool.SEMICOLON);

            charSet = contentType.substring(pos + 1);
            charSet = StringUtil.trim(charSet);

            contentType = contentType.substring(0, pos);
        }

        httpOptions.addFilePart(name, fileName, uploadContext.getUploadData(), contentType, charSet);
    }
}

From source file:it.dontesta.labs.liferay.portal.dao.db.SQLServerDB.java

License:Open Source License

@Override
protected String reword(String data) throws IOException {
    try (UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(new UnsyncStringReader(data))) {

        StringBundler sb = new StringBundler();

        String line = null;//from  w ww  . ja va2  s .  c  o  m

        while ((line = unsyncBufferedReader.readLine()) != null) {
            if (line.startsWith(ALTER_COLUMN_NAME)) {
                String[] template = buildColumnNameTokens(line);

                line = StringUtil.replace(
                        "exec sp_rename '@table@.@old-column@', " + "'@new-column@', 'column';",
                        REWORD_TEMPLATE, template);
            } else if (line.startsWith(ALTER_COLUMN_TYPE)) {
                String[] template = buildColumnTypeTokens(line);

                line = StringUtil.replace("alter table @table@ alter column @old-column@ @type@;",
                        REWORD_TEMPLATE, template);
            } else if (line.startsWith(ALTER_TABLE_NAME)) {
                String[] template = buildTableNameTokens(line);

                line = StringUtil.replace("exec sp_rename '@old-table@', '@new-table@';", RENAME_TABLE_TEMPLATE,
                        template);
            } else if (line.contains(DROP_INDEX)) {
                String[] tokens = StringUtil.split(line, ' ');

                String tableName = tokens[4];

                if (tableName.endsWith(StringPool.SEMICOLON)) {
                    tableName = tableName.substring(0, tableName.length() - 1);
                }

                line = StringUtil.replace("drop index @table@.@index@;", "@table@", tableName);
                line = StringUtil.replace(line, "@index@", tokens[2]);
            }

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

        return sb.toString();
    }
}

From source file:org.oep.cmon.portlet.hosotructiep.HoSoBusinessUtil.java

License:Apache License

/**
 * This is function getDSEmailCanBoDangDuocPhanCongXuLyHoSo
 * Version: 1.0//from   w  ww.  j  a v  a2  s  . c o  m
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param hoSo
 * @return String[]
 */
public static String[] getDSEmailCanBoDangDuocPhanCongXuLyHoSo(HoSoTTHCCong hoSo) {

    String[] out = new String[0];

    if (hoSo != null && hoSo.getTrangThaiHoSo() != Constants.HOSO_TTHC_CONG_TRANG_THAI_HOSO_NEW
            && hoSo.getTrangThaiHoSo() != Constants.HOSO_TTHC_CONG_TRANG_THAI_HOSO_MOI_TIEP_NHAN) {
        try {
            String sql = new StringBuilder("SELECT * FROM bpm_procinst WHERE name='").append(hoSo.getMaSoHoSo())
                    .append("'").toString();
            List<ProcessInstance> list = WebserviceFactory.getUengineService().getFromDBBySelectStatement(sql);
            if (list != null && !list.isEmpty()) {
                String dsEmail = list.get(0).getCurrep();
                out = dsEmail.split(StringPool.SEMICOLON);
            }
        } catch (Exception e) {
            _log.warn("LOI KHI GOI WS UENGINE LAY DANH SACH EMAIL CAN BO DANG DUOC PHAN CONG XU LY: maHoSo@"
                    + hoSo.getMaSoHoSo());
        }
    }

    return out;
}