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

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

Introduction

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

Prototype

String APOSTROPHE

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

Click Source Link

Usage

From source file:com.liferay.taglib.aui.ScriptTag.java

License:Open Source License

protected void processEndTag(ScriptData scriptData) throws Exception {
    JspWriter jspWriter = pageContext.getOut();

    jspWriter.write("<script type=\"text/javascript\">\n// <![CDATA[\n");

    StringBundler rawSB = scriptData.getRawSB();

    rawSB.writeTo(jspWriter);//ww  w .ja v  a2  s.co  m

    StringBundler callbackSB = scriptData.getCallbackSB();

    if (callbackSB.index() > 0) {
        String loadMethod = "use";

        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

        if (BrowserSnifferUtil.isIe(request) && (BrowserSnifferUtil.getMajorVersion(request) < 8)) {

            loadMethod = "ready";
        }

        jspWriter.write("AUI().");
        jspWriter.write(loadMethod);
        jspWriter.write("(");

        Set<String> useSet = scriptData.getUseSet();

        for (String use : useSet) {
            jspWriter.write(StringPool.APOSTROPHE);
            jspWriter.write(use);
            jspWriter.write(StringPool.APOSTROPHE);
            jspWriter.write(StringPool.COMMA_AND_SPACE);
        }

        jspWriter.write("function(A) {");

        callbackSB.writeTo(jspWriter);

        jspWriter.write("});");
    }

    jspWriter.write("\n// ]]>\n</script>");
}

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

License:Open Source License

protected String fixSessionKey(String fileName, String content, Pattern pattern) {

    Matcher matcher = pattern.matcher(content);

    if (!matcher.find()) {
        return content;
    }/*from   w  ww.j  av a 2s.co  m*/

    String newContent = content;

    do {
        String match = matcher.group();

        String s = null;

        if (pattern.equals(sessionKeyPattern)) {
            s = StringPool.COMMA;
        } else if (pattern.equals(taglibSessionKeyPattern)) {
            s = "key=";
        }

        int x = match.indexOf(s);

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

        x = x + s.length();

        String substring = match.substring(x).trim();

        String quote = StringPool.BLANK;

        if (substring.startsWith(StringPool.APOSTROPHE)) {
            quote = StringPool.APOSTROPHE;
        } else if (substring.startsWith(StringPool.QUOTE)) {
            quote = StringPool.QUOTE;
        } else {
            continue;
        }

        int y = match.indexOf(quote, x);
        int z = match.indexOf(quote, y + 1);

        if ((y == -1) || (z == -1)) {
            continue;
        }

        String prefix = match.substring(0, y + 1);
        String suffix = match.substring(z);
        String oldKey = match.substring(y + 1, z);

        boolean alphaNumericKey = true;

        for (char c : oldKey.toCharArray()) {
            if (!Validator.isChar(c) && !Validator.isDigit(c) && (c != CharPool.DASH)
                    && (c != CharPool.UNDERLINE)) {

                alphaNumericKey = false;
            }
        }

        if (!alphaNumericKey) {
            continue;
        }

        String newKey = TextFormatter.format(oldKey, TextFormatter.O);

        newKey = TextFormatter.format(newKey, TextFormatter.M);

        if (newKey.equals(oldKey)) {
            continue;
        }

        String oldSub = prefix.concat(oldKey).concat(suffix);
        String newSub = prefix.concat(newKey).concat(suffix);

        newContent = StringUtil.replaceFirst(newContent, oldSub, newSub);
    } while (matcher.find());

    return newContent;
}

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

License:Open Source License

protected String sortAttributes(String fileName, String line, int lineCount, boolean allowApostropheDelimeter) {

    String s = line;//from www  .  j a v  a  2  s .  c  o  m

    int x = s.indexOf(StringPool.SPACE);

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

    s = s.substring(x + 1);

    String previousAttribute = null;
    String previousAttributeAndValue = null;

    boolean wrongOrder = false;

    for (x = 0;;) {
        x = s.indexOf(StringPool.EQUAL);

        if ((x == -1) || (s.length() <= (x + 1))) {
            return line;
        }

        String attribute = s.substring(0, x);

        if (!isAttributName(attribute)) {
            return line;
        }

        if (Validator.isNotNull(previousAttribute) && (previousAttribute.compareTo(attribute) > 0)) {

            wrongOrder = true;
        }

        s = s.substring(x + 1);

        char delimeter = s.charAt(0);

        if ((delimeter != CharPool.APOSTROPHE) && (delimeter != CharPool.QUOTE)) {

            if (delimeter != CharPool.AMPERSAND) {
                processErrorMessage(fileName, "delimeter: " + fileName + " " + lineCount);
            }

            return line;
        }

        s = s.substring(1);

        String value = null;

        int y = -1;

        while (true) {
            y = s.indexOf(delimeter, y + 1);

            if ((y == -1) || (s.length() <= (y + 1))) {
                return line;
            }

            value = s.substring(0, y);

            if (value.startsWith("<%")) {
                int endJavaCodeSignCount = StringUtil.count(value, "%>");
                int startJavaCodeSignCount = StringUtil.count(value, "<%");

                if (endJavaCodeSignCount == startJavaCodeSignCount) {
                    break;
                }
            } else {
                int greaterThanCount = StringUtil.count(value, StringPool.GREATER_THAN);
                int lessThanCount = StringUtil.count(value, StringPool.LESS_THAN);

                if (greaterThanCount == lessThanCount) {
                    break;
                }
            }
        }

        if (delimeter == CharPool.APOSTROPHE) {
            if (!value.contains(StringPool.QUOTE)) {
                line = StringUtil.replace(line, StringPool.APOSTROPHE + value + StringPool.APOSTROPHE,
                        StringPool.QUOTE + value + StringPool.QUOTE);

                return sortAttributes(fileName, line, lineCount, allowApostropheDelimeter);
            } else if (!allowApostropheDelimeter) {
                String newValue = StringUtil.replace(value, StringPool.QUOTE, "&quot;");

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

                return sortAttributes(fileName, line, lineCount, allowApostropheDelimeter);
            }
        }

        StringBundler sb = new StringBundler(5);

        sb.append(attribute);
        sb.append(StringPool.EQUAL);
        sb.append(delimeter);
        sb.append(value);
        sb.append(delimeter);

        String currentAttributeAndValue = sb.toString();

        if (wrongOrder) {
            if ((StringUtil.count(line, currentAttributeAndValue) == 1)
                    && (StringUtil.count(line, previousAttributeAndValue) == 1)) {

                line = StringUtil.replaceFirst(line, previousAttributeAndValue, currentAttributeAndValue);

                line = StringUtil.replaceLast(line, currentAttributeAndValue, previousAttributeAndValue);

                return sortAttributes(fileName, line, lineCount, allowApostropheDelimeter);
            }

            return line;
        }

        s = s.substring(y + 1);

        if (s.startsWith(StringPool.GREATER_THAN)) {
            x = s.indexOf(StringPool.SPACE);

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

            s = s.substring(x + 1);

            previousAttribute = null;
            previousAttributeAndValue = null;
        } else {
            s = StringUtil.trimLeading(s);

            previousAttribute = attribute;
            previousAttributeAndValue = currentAttributeAndValue;
        }
    }
}

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 ww .  ja v a  2  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 String formatTaglibQuotes(String fileName, String content, String quoteType) {

    String quoteFix = StringPool.APOSTROPHE;

    if (quoteFix.equals(quoteType)) {
        quoteFix = StringPool.QUOTE;//from  w w  w. j a v a 2  s .  c  o  m
    }

    Pattern pattern = Pattern.compile(getTaglibRegex(quoteType));

    Matcher matcher = pattern.matcher(content);

    while (matcher.find()) {
        int x = content.indexOf(quoteType + "<%=", matcher.start());
        int y = content.indexOf("%>" + quoteType, x);

        while ((x != -1) && (y != -1)) {
            String beforeResult = content.substring(matcher.start(), x);

            if (beforeResult.contains(" />\"")) {
                break;
            }

            String result = content.substring(x + 1, y + 2);

            if (result.contains(quoteType)) {
                int lineCount = 1;

                char[] contentCharArray = content.toCharArray();

                for (int i = 0; i < x; i++) {
                    if (contentCharArray[i] == CharPool.NEW_LINE) {
                        lineCount++;
                    }
                }

                if (!result.contains(quoteFix)) {
                    StringBundler sb = new StringBundler(5);

                    sb.append(content.substring(0, x));
                    sb.append(quoteFix);
                    sb.append(result);
                    sb.append(quoteFix);
                    sb.append(content.substring(y + 3, content.length()));

                    content = sb.toString();
                } else {
                    processErrorMessage(fileName, "taglib: " + fileName + " " + lineCount);
                }
            }

            x = content.indexOf(quoteType + "<%=", y);

            if (x > matcher.end()) {
                break;
            }

            y = content.indexOf("%>" + quoteType, x);
        }
    }

    return content;
}

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

License:Open Source License

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

    StringBundler sb = new StringBundler();

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

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

        String previousLineSqlCommand = StringPool.BLANK;

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

            if (Validator.isNotNull(line) && !line.startsWith(StringPool.TAB)) {

                String sqlCommand = StringUtil.split(line, CharPool.SPACE)[0];

                if (Validator.isNotNull(previousLineSqlCommand) && !previousLineSqlCommand.equals(sqlCommand)) {

                    sb.append("\n");
                }

                previousLineSqlCommand = sqlCommand;
            } else {
                previousLineSqlCommand = StringPool.BLANK;
            }

            String strippedQuotesLine = stripQuotes(line, CharPool.APOSTROPHE);

            if (strippedQuotesLine.contains(StringPool.QUOTE)) {
                line = StringUtil.replace(line, StringPool.QUOTE, StringPool.APOSTROPHE);
            }

            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

protected void doProcessPage(String startTag, String endTag, String ref, PortletURL actionURL,
        String actionParameterName) {

    StringBundler sb = new StringBundler();

    String content = _sb.toString();

    int startTagPos = content.indexOf(startTag);
    int endTagPos = 0;

    int startRefPos = 0;
    int endRefPos = 0;

    while (startTagPos != -1) {
        sb.append(content.substring(0, startTagPos));

        content = content.substring(startTagPos);

        endTagPos = content.indexOf(endTag);
        startRefPos = content.indexOf(ref);

        if ((startRefPos == -1) || (startRefPos > endTagPos)) {
            sb.append(content.substring(0, endTagPos));

            content = content.substring(endTagPos);
        } else {//from   w ww  . j a  va  2s .  c  om
            startRefPos = startRefPos + ref.length();

            sb.append(content.substring(0, startRefPos));

            content = content.substring(startRefPos);

            String quote = StringPool.BLANK;

            if (content.startsWith(StringPool.APOSTROPHE)) {
                quote = StringPool.APOSTROPHE;
            } else if (content.startsWith(StringPool.QUOTE)) {
                quote = StringPool.QUOTE;
            }

            String url = StringPool.BLANK;

            if (quote.length() > 0) {
                sb.append(quote);

                content = content.substring(1);

                endRefPos = content.indexOf(quote);

                url = content.substring(0, endRefPos);
            } else {
                endTagPos = content.indexOf(endTag);

                endRefPos = 0;

                StringBundler unquotedURL = new StringBundler();

                while (true) {
                    char c = content.charAt(endRefPos);

                    if (!Character.isSpaceChar(c) && (endRefPos < endTagPos)) {

                        endRefPos++;

                        unquotedURL.append(c);
                    } else {
                        endRefPos--;

                        break;
                    }
                }

                url = unquotedURL.toString();
            }

            if ((url.charAt(0) == CharPool.POUND) || url.startsWith("http")) {

                sb.append(url);
                sb.append(quote);
            } else {
                actionURL.setParameter(actionParameterName, url);

                sb.append(actionURL.toString());
                sb.append(quote);
            }

            content = content.substring(endRefPos + 1);
        }

        startTagPos = content.indexOf(startTag);
    }

    sb.append(content);

    _sb = sb;
}

From source file:com.liferay.util.JS.java

License:Open Source License

public static String toScript(String[] array) {
    StringBundler sb = new StringBundler(array.length * 4 + 2);

    sb.append(StringPool.OPEN_BRACKET);// ww w  .  ja va  2  s  . c o  m

    for (int i = 0; i < array.length; i++) {
        sb.append(StringPool.APOSTROPHE);
        sb.append(UnicodeFormatter.toString(array[i]));
        sb.append(StringPool.APOSTROPHE);

        if (i + 1 < array.length) {
            sb.append(StringPool.COMMA);
        }
    }

    sb.append(StringPool.CLOSE_BRACKET);

    return sb.toString();
}

From source file:org.apache.jsp.html.taglib.aui.script.page_jsp.java

License:Open Source License

public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;/*from  www  . j a v a 2  s . c  o m*/
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
        response.setContentType("text/html; charset=UTF-8");
        pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true);
        _jspx_page_context = pageContext;
        application = pageContext.getServletContext();
        config = pageContext.getServletConfig();
        session = pageContext.getSession();
        out = pageContext.getOut();
        _jspx_out = out;

        /**
         * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
         *
         * This library is free software; you can redistribute it and/or modify it under
         * the terms of the GNU Lesser General Public License as published by the Free
         * Software Foundation; either version 2.1 of the License, or (at your option)
         * any later version.
         *
         * This library is distributed in the hope that it will be useful, but WITHOUT
         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
         * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
         * details.
         */

        out.write('\n');
        out.write('\n');

        /**
         * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
         *
         * This library is free software; you can redistribute it and/or modify it under
         * the terms of the GNU Lesser General Public License as published by the Free
         * Software Foundation; either version 2.1 of the License, or (at your option)
         * any later version.
         *
         * This library is distributed in the hope that it will be useful, but WITHOUT
         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
         * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
         * details.
         */

        out.write('\n');
        out.write('\n');

        /**
         * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
         *
         * This library is free software; you can redistribute it and/or modify it under
         * the terms of the GNU Lesser General Public License as published by the Free
         * Software Foundation; either version 2.1 of the License, or (at your option)
         * any later version.
         *
         * This library is distributed in the hope that it will be useful, but WITHOUT
         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
         * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
         * details.
         */

        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        //  liferay-theme:defineObjects
        com.liferay.taglib.theme.DefineObjectsTag _jspx_th_liferay_002dtheme_005fdefineObjects_005f0 = (com.liferay.taglib.theme.DefineObjectsTag) _005fjspx_005ftagPool_005fliferay_002dtheme_005fdefineObjects_005fnobody
                .get(com.liferay.taglib.theme.DefineObjectsTag.class);
        _jspx_th_liferay_002dtheme_005fdefineObjects_005f0.setPageContext(_jspx_page_context);
        _jspx_th_liferay_002dtheme_005fdefineObjects_005f0.setParent(null);
        int _jspx_eval_liferay_002dtheme_005fdefineObjects_005f0 = _jspx_th_liferay_002dtheme_005fdefineObjects_005f0
                .doStartTag();
        if (_jspx_th_liferay_002dtheme_005fdefineObjects_005f0
                .doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
            _005fjspx_005ftagPool_005fliferay_002dtheme_005fdefineObjects_005fnobody
                    .reuse(_jspx_th_liferay_002dtheme_005fdefineObjects_005f0);
            return;
        }
        _005fjspx_005ftagPool_005fliferay_002dtheme_005fdefineObjects_005fnobody
                .reuse(_jspx_th_liferay_002dtheme_005fdefineObjects_005f0);
        com.liferay.portal.theme.ThemeDisplay themeDisplay = null;
        com.liferay.portal.model.Company company = null;
        com.liferay.portal.model.Account account = null;
        com.liferay.portal.model.User user = null;
        com.liferay.portal.model.User realUser = null;
        com.liferay.portal.model.Contact contact = null;
        com.liferay.portal.model.Layout layout = null;
        java.util.List layouts = null;
        java.lang.Long plid = null;
        com.liferay.portal.model.LayoutTypePortlet layoutTypePortlet = null;
        java.lang.Long scopeGroupId = null;
        com.liferay.portal.security.permission.PermissionChecker permissionChecker = null;
        java.util.Locale locale = null;
        java.util.TimeZone timeZone = null;
        com.liferay.portal.model.Theme theme = null;
        com.liferay.portal.model.ColorScheme colorScheme = null;
        com.liferay.portal.theme.PortletDisplay portletDisplay = null;
        java.lang.Long portletGroupId = null;
        themeDisplay = (com.liferay.portal.theme.ThemeDisplay) _jspx_page_context.findAttribute("themeDisplay");
        company = (com.liferay.portal.model.Company) _jspx_page_context.findAttribute("company");
        account = (com.liferay.portal.model.Account) _jspx_page_context.findAttribute("account");
        user = (com.liferay.portal.model.User) _jspx_page_context.findAttribute("user");
        realUser = (com.liferay.portal.model.User) _jspx_page_context.findAttribute("realUser");
        contact = (com.liferay.portal.model.Contact) _jspx_page_context.findAttribute("contact");
        layout = (com.liferay.portal.model.Layout) _jspx_page_context.findAttribute("layout");
        layouts = (java.util.List) _jspx_page_context.findAttribute("layouts");
        plid = (java.lang.Long) _jspx_page_context.findAttribute("plid");
        layoutTypePortlet = (com.liferay.portal.model.LayoutTypePortlet) _jspx_page_context
                .findAttribute("layoutTypePortlet");
        scopeGroupId = (java.lang.Long) _jspx_page_context.findAttribute("scopeGroupId");
        permissionChecker = (com.liferay.portal.security.permission.PermissionChecker) _jspx_page_context
                .findAttribute("permissionChecker");
        locale = (java.util.Locale) _jspx_page_context.findAttribute("locale");
        timeZone = (java.util.TimeZone) _jspx_page_context.findAttribute("timeZone");
        theme = (com.liferay.portal.model.Theme) _jspx_page_context.findAttribute("theme");
        colorScheme = (com.liferay.portal.model.ColorScheme) _jspx_page_context.findAttribute("colorScheme");
        portletDisplay = (com.liferay.portal.theme.PortletDisplay) _jspx_page_context
                .findAttribute("portletDisplay");
        portletGroupId = (java.lang.Long) _jspx_page_context.findAttribute("portletGroupId");
        out.write('\n');
        out.write('\n');

        /**
         * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
         *
         * This library is free software; you can redistribute it and/or modify it under
         * the terms of the GNU Lesser General Public License as published by the Free
         * Software Foundation; either version 2.1 of the License, or (at your option)
         * any later version.
         *
         * This library is distributed in the hope that it will be useful, but WITHOUT
         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
         * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
         * details.
         */

        out.write('\n');
        out.write('\n');

        PortletRequest portletRequest = (PortletRequest) request
                .getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);

        PortletResponse portletResponse = (PortletResponse) request
                .getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);

        String namespace = StringPool.BLANK;

        boolean useNamespace = GetterUtil.getBoolean((String) request.getAttribute("aui:form:useNamespace"),
                true);

        if ((portletResponse != null) && useNamespace) {
            namespace = portletResponse.getNamespace();
        }

        String currentURL = PortalUtil.getCurrentURL(request);

        out.write('\n');
        out.write('\n');

        /**
         * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
         *
         * This library is free software; you can redistribute it and/or modify it under
         * the terms of the GNU Lesser General Public License as published by the Free
         * Software Foundation; either version 2.1 of the License, or (at your option)
         * any later version.
         *
         * This library is distributed in the hope that it will be useful, but WITHOUT
         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
         * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
         * details.
         */

        out.write('\n');
        out.write('\n');
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");
        out.write("\n");

        ScriptData scriptData = (ScriptData) request.getAttribute(ScriptTag.class.getName());

        if (scriptData == null) {
            scriptData = (ScriptData) request.getAttribute(WebKeys.AUI_SCRIPT_DATA);

            if (scriptData != null) {
                request.removeAttribute(WebKeys.AUI_SCRIPT_DATA);
            }
        }

        out.write('\n');
        out.write('\n');
        //  c:if
        org.apache.taglibs.standard.tag.rt.core.IfTag _jspx_th_c_005fif_005f0 = (org.apache.taglibs.standard.tag.rt.core.IfTag) _005fjspx_005ftagPool_005fc_005fif_0026_005ftest
                .get(org.apache.taglibs.standard.tag.rt.core.IfTag.class);
        _jspx_th_c_005fif_005f0.setPageContext(_jspx_page_context);
        _jspx_th_c_005fif_005f0.setParent(null);
        // /html/taglib/aui/script/page.jsp(34,0) name = test type = boolean reqTime = true required = true fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
        _jspx_th_c_005fif_005f0.setTest(scriptData != null);
        int _jspx_eval_c_005fif_005f0 = _jspx_th_c_005fif_005f0.doStartTag();
        if (_jspx_eval_c_005fif_005f0 != javax.servlet.jsp.tagext.Tag.SKIP_BODY) {
            do {
                out.write("\n");
                out.write("\t<script type=\"text/javascript\">\n");
                out.write("\t\t// <![CDATA[\n");
                out.write("\n");
                out.write("\t\t\t");

                StringBundler rawSB = scriptData.getRawSB();

                rawSB.writeTo(out);

                StringBundler callbackSB = scriptData.getCallbackSB();

                out.write("\n");
                out.write("\n");
                out.write("\t\t\t");
                //  c:if
                org.apache.taglibs.standard.tag.rt.core.IfTag _jspx_th_c_005fif_005f1 = (org.apache.taglibs.standard.tag.rt.core.IfTag) _005fjspx_005ftagPool_005fc_005fif_0026_005ftest
                        .get(org.apache.taglibs.standard.tag.rt.core.IfTag.class);
                _jspx_th_c_005fif_005f1.setPageContext(_jspx_page_context);
                _jspx_th_c_005fif_005f1.setParent((javax.servlet.jsp.tagext.Tag) _jspx_th_c_005fif_005f0);
                // /html/taglib/aui/script/page.jsp(46,3) name = test type = boolean reqTime = true required = true fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
                _jspx_th_c_005fif_005f1.setTest(callbackSB.index() > 0);
                int _jspx_eval_c_005fif_005f1 = _jspx_th_c_005fif_005f1.doStartTag();
                if (_jspx_eval_c_005fif_005f1 != javax.servlet.jsp.tagext.Tag.SKIP_BODY) {
                    do {
                        out.write("\n");
                        out.write("\n");
                        out.write("\t\t\t\t");

                        Set<String> useSet = scriptData.getUseSet();

                        StringBundler useSB = new StringBundler(useSet.size() * 4);

                        for (String use : useSet) {
                            useSB.append(StringPool.APOSTROPHE);
                            useSB.append(use);
                            useSB.append(StringPool.APOSTROPHE);
                            useSB.append(StringPool.COMMA_AND_SPACE);
                        }

                        out.write("\n");
                        out.write("\n");
                        out.write("\t\t\t\tAUI().use(\n");
                        out.write("\n");
                        out.write("\t\t\t\t\t");

                        useSB.writeTo(out);

                        out.write("\n");
                        out.write("\n");
                        out.write("\t\t\t\t\tfunction(A) {\n");
                        out.write("\n");
                        out.write("\t\t\t\t\t\t");

                        callbackSB.writeTo(out);

                        out.write("\n");
                        out.write("\n");
                        out.write("\t\t\t\t\t}\n");
                        out.write("\t\t\t\t);\n");
                        out.write("\t\t\t");
                        int evalDoAfterBody = _jspx_th_c_005fif_005f1.doAfterBody();
                        if (evalDoAfterBody != javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN)
                            break;
                    } while (true);
                }
                if (_jspx_th_c_005fif_005f1.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
                    _005fjspx_005ftagPool_005fc_005fif_0026_005ftest.reuse(_jspx_th_c_005fif_005f1);
                    return;
                }
                _005fjspx_005ftagPool_005fc_005fif_0026_005ftest.reuse(_jspx_th_c_005fif_005f1);
                out.write("\n");
                out.write("\t\t// ]]>\n");
                out.write("\t</script>\n");
                int evalDoAfterBody = _jspx_th_c_005fif_005f0.doAfterBody();
                if (evalDoAfterBody != javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN)
                    break;
            } while (true);
        }
        if (_jspx_th_c_005fif_005f0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
            _005fjspx_005ftagPool_005fc_005fif_0026_005ftest.reuse(_jspx_th_c_005fif_005f0);
            return;
        }
        _005fjspx_005ftagPool_005fc_005fif_0026_005ftest.reuse(_jspx_th_c_005fif_005f0);
    } catch (Throwable t) {
        if (!(t instanceof SkipPageException)) {
            out = _jspx_out;
            if (out != null && out.getBufferSize() != 0)
                try {
                    out.clearBuffer();
                } catch (java.io.IOException e) {
                }
            if (_jspx_page_context != null)
                _jspx_page_context.handlePageException(t);
        }
    } finally {
        _jspxFactory.releasePageContext(_jspx_page_context);
    }
}

From source file:org.opencps.statisticsmgt.service.persistence.DossiersStatisticsFinderImpl.java

License:Open Source License

/**
 * @param groupId/*  w w w.j ava2s  . com*/
 * @param month
 * @param year
 * @param govCode
 * @param domainCode
 * @param level
 * @param notNullGov
 * @param notNullDomain
 * @return
 */
public List<DossiersStatistics> getStatsByGovAndDomain(long groupId, int startMonth, int startYear, int period,
        String govCodes, String domainCodes, int level, int domainDeepLevel) {

    //Get tree dictitem by code
    //List<DictItem> dictItems = new ArrayList<DictItem>();

    Session session = null;

    try {
        session = openSession();

        String sql = CustomSQLUtil.get(SQL_GET_STATS_BY_GOV_DOMAIN);

        // _log.info(sql);

        if (Validator.isNull(govCodes)) {
            sql = StringUtil.replace(sql, "(opencps_dossierstatistics.govAgencyCode = ?)",
                    "(opencps_dossierstatistics.govAgencyCode = '')");
        } else {
            if (govCodes.equalsIgnoreCase("all")) {
                sql = StringUtil.replace(sql, "(opencps_dossierstatistics.govAgencyCode = ?)",
                        "(opencps_dossierstatistics.govAgencyCode != '')");
            } else {
                String[] arrGovCode = StringUtil.split(govCodes);
                List<String> tmp = new ArrayList<String>();

                if (arrGovCode != null && arrGovCode.length > 0) {
                    for (int g = 0; g < arrGovCode.length; g++) {
                        if (Validator.isNotNull(arrGovCode[g])) {
                            tmp.add(StringPool.APOSTROPHE + arrGovCode[g] + StringPool.APOSTROPHE);
                        }
                    }
                }

                sql = StringUtil.replace(sql, "(opencps_dossierstatistics.govAgencyCode = ?)",
                        "(opencps_dossierstatistics.govAgencyCode IN (" + StringUtil.merge(tmp) + "))");
            }
        }

        if (Validator.isNull(domainCodes)) {
            sql = StringUtil.replace(sql, "(opencps_dossierstatistics.domainCode = ?)",
                    "(opencps_dossierstatistics.domainCode = '')");
        } else {
            if (domainCodes.equalsIgnoreCase("all")) {
                sql = StringUtil.replace(sql, "(opencps_dossierstatistics.domainCode = ?)",
                        "(opencps_dossierstatistics.domainCode != '')");
            } else {
                String[] arrDomainCode = StringUtil.split(domainCodes);
                List<String> tmp = new ArrayList<String>();

                if (arrDomainCode != null && arrDomainCode.length > 0) {
                    for (int d = 0; d < arrDomainCode.length; d++) {
                        if (Validator.isNotNull(arrDomainCode[d])) {
                            tmp.add(StringPool.APOSTROPHE + arrDomainCode[d] + StringPool.APOSTROPHE);

                        }
                    }
                }

                sql = StringUtil.replace(sql, "(opencps_dossierstatistics.domainCode = ?)",
                        "(opencps_dossierstatistics.domainCode IN (" + StringUtil.merge(tmp) + "))");
            }
        }

        String conditions = StatisticsUtil.getPeriodConditions(startMonth, startYear, period);

        sql = StringUtil.replace(sql, "$FILTER$", conditions);

        _log.info(sql);

        SQLQuery q = session.createSQLQuery(sql);

        q.addEntity("DossiersStatistics", DossiersStatisticsImpl.class);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(level);

        return (List<DossiersStatistics>) QueryUtil.list(q, getDialect(), QueryUtil.ALL_POS, QueryUtil.ALL_POS);

    } catch (Exception e) {
        _log.error(e);
    } finally {
        closeSession(session);
    }

    return null;
}