Example usage for javax.servlet ServletOutputStream println

List of usage examples for javax.servlet ServletOutputStream println

Introduction

In this page you can find the example usage for javax.servlet ServletOutputStream println.

Prototype


public void println(double d) throws IOException 

Source Link

Document

Writes a double value to the client, followed by a carriage return-line feed (CRLF).

Usage

From source file:pivotal.au.se.gemfirexdweb.controller.CreateIndexController.java

@RequestMapping(value = "/createindex", method = RequestMethod.POST)
public String createIndexAction(@ModelAttribute("indexAttribute") NewIndex indexAttribute, Model model,
        HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {/* w  w  w  .  j  a va  2  s  .c  o m*/
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to action an event for create index");

    String tabName = indexAttribute.getTableName();
    String schema = indexAttribute.getSchemaName();
    String unique = indexAttribute.getUnique();
    String idxName = indexAttribute.getIndexName();
    String submit = request.getParameter("pSubmit");

    String[] selectedColumns = request.getParameterValues("selected_column[]");
    String[] indexOrder = request.getParameterValues("idxOrder[]");
    String[] position = request.getParameterValues("position[]");

    logger.debug("selectedColumns = " + Arrays.toString(selectedColumns));
    logger.debug("indexOrder = " + Arrays.toString(indexOrder));
    logger.debug("position = " + Arrays.toString(position));

    IndexDAO indexDAO = GemFireXDWebDAOFactory.getIndexDAO();

    List<IndexColumn> columns = indexDAO.retrieveIndexColumns(schema, tabName,
            (String) session.getAttribute("user_key"));

    StringBuffer createIndex = new StringBuffer();

    if (unique.equalsIgnoreCase("Y")) {
        createIndex.append("create unique index " + idxName + " on " + schema + "." + tabName + " ");
    } else {
        createIndex.append("create index " + idxName + " on " + schema + "." + tabName + " ");
    }

    createIndex.append("(");

    if (selectedColumns != null) {
        int i = 0;
        Map<String, IndexDefinition> cols = new HashMap<String, IndexDefinition>();

        for (String column : selectedColumns) {
            String columnName = column.substring(0, column.indexOf("_"));
            String index = column.substring(column.indexOf("_") + 1);
            String pos = position[Integer.parseInt(index) - 1];
            if (pos.trim().length() == 0) {
                pos = "" + i;
            }

            logger.debug("Column = " + columnName + ", indexOrder = " + indexOrder[Integer.parseInt(index) - 1]
                    + ", position = " + pos);

            IndexDefinition idxDef = new IndexDefinition(columnName, indexOrder[Integer.parseInt(index) - 1]);

            cols.put("" + pos, idxDef);
            i++;
        }

        // sort map and create index now
        SortedSet<String> keys = new TreeSet<String>(cols.keySet());
        int length = keys.size();
        i = 0;
        for (String key : keys) {
            IndexDefinition idxDefTemp = cols.get(key);
            if (i == (length - 1)) {
                createIndex.append(idxDefTemp.getColumnName() + " " + idxDefTemp.getOrderType() + ")");
            } else {
                createIndex.append(idxDefTemp.getColumnName() + " " + idxDefTemp.getOrderType() + ", ");
            }

            i++;

        }
    }

    if (!checkIfParameterEmpty(request, "caseSensitive")) {
        createIndex.append(" " + request.getParameter("caseSensitive") + "\n");
    }

    if (submit.equalsIgnoreCase("create")) {
        Result result = new Result();

        logger.debug("Creating index as -> " + createIndex.toString());

        result = GemFireXDWebDAOUtil.runCommand(createIndex.toString(),
                (String) session.getAttribute("user_key"));

        model.addAttribute("result", result);
        model.addAttribute("tabName", tabName);
        model.addAttribute("tableSchemaName", schema);
        model.addAttribute("columns", columns);
        model.addAttribute("schema", schema);

        session.removeAttribute("numColumns");
    } else if (submit.equalsIgnoreCase("Show SQL")) {
        logger.debug("Index SQL as follows as -> " + createIndex.toString());
        model.addAttribute("sql", createIndex.toString());
        model.addAttribute("tabName", tabName);
        model.addAttribute("tableSchemaName", schema);
        model.addAttribute("columns", columns);
        model.addAttribute("schema", schema);
    } else if (submit.equalsIgnoreCase("Save to File")) {
        response.setContentType(SAVE_CONTENT_TYPE);
        response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, idxName));

        ServletOutputStream out = response.getOutputStream();
        out.println(createIndex.toString());
        out.close();
        return null;
    }
    // This will resolve to /WEB-INF/jsp/create-index.jsp
    return "create-index";
}

From source file:org.openlaszlo.servlets.HistoryServlet.java

private void doSaveMessage(HttpServletRequest req, HttpServletResponse res, Document doc) {
    mLogger.debug("doSaveMessage()");
    if (mHistory.size() == mHistoryLength) {
        mHistory.remove(0);/*from  w  w w . ja v  a  2  s  .co m*/
    }
    String message = doc.getRootElement().getChild("root").getText();
    mHistory.add(message);

    ServletOutputStream out = null;
    try {
        out = res.getOutputStream();
        out.println("<status message=\"message saved\" />");
        out.flush();
    } catch (IOException e) {
        mLogger.info("IOException: " + e.getMessage());
    } finally {
        close(out);
    }
}

From source file:pivotal.au.se.gemfirexdweb.controller.CreateProcedureController.java

@RequestMapping(value = "/createprocedure", method = RequestMethod.POST)
public String createProcedureAction(@ModelAttribute("procedureAttribute") NewProcedure procedureAttribute,
        Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session)
        throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {//from w w  w  .j  av a 2 s  .c  o  m
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to action an event for create Procedure");

    String schema = procedureAttribute.getSchemaName().trim();

    if (schema.length() == 0) {
        schema = (String) session.getAttribute("schema");
    }

    logger.debug("New Procedure schema name = " + schema);
    logger.debug("New Procedure name = " + procedureAttribute.getProcedureName());

    // perform some action here with what we have
    String submit = request.getParameter("pSubmit");

    if (submit != null) {
        if (submit.equalsIgnoreCase("Parameter(s)")) {
            int cols = Integer.parseInt(request.getParameter("numParams"));
            int numParams = Integer.parseInt((String) session.getAttribute("numParams"));

            numParams = numParams + cols;

            session.setAttribute("numParams", "" + numParams);
            model.addAttribute("numParams", numParams);
        } else {
            // build create HDFS Store SQL
            StringBuffer createProcedure = new StringBuffer();

            createProcedure
                    .append("CREATE PROCEDURE " + schema + "." + procedureAttribute.getProcedureName() + " \n");

            String[] parameterTypes = request.getParameterValues("parameter_type[]");
            String[] parameterNames = request.getParameterValues("parameter_name[]");
            String[] dataTypes = request.getParameterValues("data_type[]");
            String[] columnPrecision = request.getParameterValues("column_precision[]");

            logger.debug("parameterTypes = " + Arrays.toString(parameterTypes));
            logger.debug("parameterNames = " + Arrays.toString(parameterNames));
            logger.debug("dataTypes = " + Arrays.toString(dataTypes));
            logger.debug("columnPrecision = " + Arrays.toString(columnPrecision));

            int i = 0;

            int size = 0;

            if (parameterNames != null) {
                size = parameterNames.length;

                for (String parameterName : parameterNames) {
                    if (i == 0) {
                        createProcedure.append("(");
                    }

                    createProcedure.append(parameterTypes[i] + " " + parameterName + " " + dataTypes[i]);
                    if (columnPrecision[i].length() != 0) {
                        createProcedure.append("(" + columnPrecision[i] + ")");
                    }

                    i++;
                    if (i < size) {
                        createProcedure.append(", \n");
                    }
                }

                if (i >= 1) {
                    createProcedure.append(") \n");
                }
            }

            if (!checkIfParameterEmpty(request, "language")) {
                createProcedure.append("LANGUAGE " + procedureAttribute.getLanguage() + " \n");
            }

            if (!checkIfParameterEmpty(request, "parameterStyle")) {
                createProcedure.append("PARAMETER STYLE " + procedureAttribute.getParameterStyle() + " \n");
            }

            if (!checkIfParameterEmpty(request, "sqlAccess")) {
                createProcedure.append(procedureAttribute.getSqlAccess() + " \n");
            }

            if (!checkIfParameterEmpty(request, "dynamicResultsets")) {
                createProcedure
                        .append("DYNAMIC RESULT SETS " + procedureAttribute.getDynamicResultsets() + " \n");
            }

            createProcedure.append("EXTERNAL NAME '" + procedureAttribute.getExternalName() + "'\n");

            if (submit.equalsIgnoreCase("create")) {
                Result result = new Result();

                logger.debug("Creating Procedure as -> " + createProcedure.toString());

                result = GemFireXDWebDAOUtil.runCommand(createProcedure.toString(),
                        (String) session.getAttribute("user_key"));

                model.addAttribute("result", result);

            } else if (submit.equalsIgnoreCase("Show SQL")) {
                logger.debug("Create Procedure SQL as follows as -> " + createProcedure.toString());
                model.addAttribute("sql", createProcedure.toString());
            } else if (submit.equalsIgnoreCase("Save to File")) {
                response.setContentType(SAVE_CONTENT_TYPE);
                response.setHeader("Content-Disposition", "attachment; filename="
                        + String.format(FILENAME, procedureAttribute.getProcedureName()));

                ServletOutputStream out = response.getOutputStream();
                out.println(createProcedure.toString());
                out.close();
                return null;
            }
        }

    }

    // This will resolve to /WEB-INF/jsp/create-procedure.jsp
    return "create-procedure";
}

From source file:pivotal.au.se.gemfirexdweb.controller.CreateFunctionController.java

@RequestMapping(value = "/createfunction", method = RequestMethod.POST)
public String createFunctionAction(@ModelAttribute("functionAttribute") NewFunction functionAttribute,
        Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session)
        throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {//from   w ww.  j ava  2s  . co  m
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to action an event for create Procedure");

    String schema = functionAttribute.getSchemaName().trim();

    if (schema.length() == 0) {
        schema = (String) session.getAttribute("schema");
    }

    logger.debug("New Function schema name = " + schema);
    logger.debug("New Function name = " + functionAttribute.getFunctionName());

    // perform some action here with what we have
    String submit = request.getParameter("pSubmit");

    if (submit != null) {
        if (submit.equalsIgnoreCase("Parameter(s)")) {
            int cols = Integer.parseInt(request.getParameter("numParams"));
            int numParams = Integer.parseInt((String) session.getAttribute("numParams"));

            numParams = numParams + cols;

            session.setAttribute("numParams", "" + numParams);
            model.addAttribute("numParams", numParams);
        } else {
            // build create HDFS Store SQL
            StringBuffer createFunction = new StringBuffer();

            createFunction
                    .append("CREATE FUNCTION " + schema + "." + functionAttribute.getFunctionName() + " \n");

            String[] parameterTypes = request.getParameterValues("parameter_type[]");
            String[] parameterNames = request.getParameterValues("parameter_name[]");
            String[] dataTypes = request.getParameterValues("data_type[]");
            String[] columnPrecision = request.getParameterValues("column_precision[]");

            logger.debug("parameterTypes = " + Arrays.toString(parameterTypes));
            logger.debug("parameterNames = " + Arrays.toString(parameterNames));
            logger.debug("dataTypes = " + Arrays.toString(dataTypes));
            logger.debug("columnPrecision = " + Arrays.toString(columnPrecision));

            int i = 0;
            int size = 0;

            if (parameterNames != null) {
                size = parameterNames.length;

                for (String parameterName : parameterNames) {
                    if (i == 0) {
                        createFunction.append("(");
                    }

                    createFunction.append(parameterName + " " + dataTypes[i]);
                    if (columnPrecision[i].length() != 0) {
                        createFunction.append("(" + columnPrecision[i] + ")");
                    }

                    i++;
                    if (i < size) {
                        createFunction.append(", \n");
                    }
                }

                if (i >= 1) {
                    createFunction.append(") \n");
                }
            }

            createFunction.append("RETURNS " + functionAttribute.getReturnType());
            if (functionAttribute.getReturnPrecision().trim().length() != 0) {
                createFunction.append("(" + functionAttribute.getReturnPrecision() + ") \n");
            } else {
                createFunction.append(" \n");
            }

            if (!checkIfParameterEmpty(request, "language")) {
                createFunction.append("LANGUAGE " + functionAttribute.getLanguage() + " \n");
            }

            createFunction.append("EXTERNAL NAME '" + functionAttribute.getExternalName() + "' \n");

            if (!checkIfParameterEmpty(request, "parameterStyle")) {
                createFunction.append("PARAMETER STYLE " + functionAttribute.getParameterStyle() + " \n");
            }

            if (!checkIfParameterEmpty(request, "sqlAccess")) {
                createFunction.append(functionAttribute.getSqlAccess() + " \n");
            }

            if (!checkIfParameterEmpty(request, "ifNull")) {
                createFunction.append(functionAttribute.getIfNull() + " \n");
            }

            if (submit.equalsIgnoreCase("create")) {
                Result result = new Result();

                logger.debug("Creating Function as -> " + createFunction.toString());

                result = GemFireXDWebDAOUtil.runCommand(createFunction.toString(),
                        (String) session.getAttribute("user_key"));

                model.addAttribute("result", result);
                model.addAttribute("returnType", functionAttribute.getReturnType());
            } else if (submit.equalsIgnoreCase("Show SQL")) {
                logger.debug("Create Function SQL as follows as -> " + createFunction.toString());
                model.addAttribute("sql", createFunction.toString());
                model.addAttribute("returnType", functionAttribute.getReturnType());
            } else if (submit.equalsIgnoreCase("Save to File")) {
                response.setContentType(SAVE_CONTENT_TYPE);
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + String.format(FILENAME, functionAttribute.getFunctionName()));

                ServletOutputStream out = response.getOutputStream();
                out.println(createFunction.toString());
                out.close();
                return null;
            }
        }

    }

    // This will resolve to /WEB-INF/jsp/create-function.jsp
    return "create-function";
}

From source file:org.openlaszlo.servlets.HistoryServlet.java

private void doHelp(HttpServletRequest req, HttpServletResponse res, String xxx) {
    ServletOutputStream out = null;
    try {//from   w  w  w  .  j a  v a2s. co  m
        out = res.getOutputStream();

        out.println("<!-- " + xxx + " -->");

        out.println("<help>");
        out.println("You must pass in an xml query parameter (?xml=...).  ");
        out.println("The following are valid xml values.");

        out.println("<xml description=\"Save message.\" >");
        out.println("<resultset>");
        out.println("<root dset=\"message\"><from name=\"aName\" />messageText</root>");
        out.println("</resultset>");
        out.println("</xml>");

        out.println("<xml description=\"Get message history.\" >");
        out.println("<resultset>");
        out.println("<root><history/></root>");
        out.println("</resultset>");
        out.println("</xml>");

        out.println("<xml description=\"LPS push of client disconnect.\" >");
        out.println("<resultset>");
        out.println("<root dset=\"__LPSUSERDISCONNECT\">username</root>");
        out.println("</resultset>");
        out.println("</xml>");

        out.println("</help>");
        out.flush();
    } catch (IOException e) {
        mLogger.info("IOException: " + e.getMessage());
    } finally {
        close(out);
    }
}

From source file:pivotal.au.se.gemfirexdweb.controller.GatewayReceiverController.java

@RequestMapping(value = "/gatewayreceivers", method = RequestMethod.POST)
public String performGatewayReceiversAction(Model model, HttpServletResponse response,
        HttpServletRequest request, HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {//from  www.ja  v a  2s .c  o  m
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    int startAtIndex = 0, endAtIndex = 0;
    Result result = new Result();
    List<GatewayReceiver> gatewayreceivers = null;
    String ddlString = null;

    logger.debug("Received request to perform an action on the gateway recievers");

    GatewayReceiverDAO grDAO = GemFireXDWebDAOFactory.getGatewayRecieverDAO();

    if (request.getParameter("search") != null) {
        gatewayreceivers = grDAO.retrieveGatewayReceiverList((String) session.getAttribute("schema"),
                (String) request.getParameter("search"), (String) session.getAttribute("user_key"));

        model.addAttribute("search", (String) request.getParameter("search"));
    } else {
        String[] tableList = request.getParameterValues("selected_gatewayreceivers[]");
        String commandStr = request.getParameter("submit_mult");

        logger.debug("tableList = " + Arrays.toString(tableList));
        logger.debug("command = " + commandStr);

        // start actions now if tableList is not null

        if (tableList != null) {
            List al = new ArrayList<Result>();
            List<String> al2 = new ArrayList<String>();

            for (String id : tableList) {
                if (commandStr.equalsIgnoreCase("DDL") || commandStr.equalsIgnoreCase("DDL_FILE")) {
                    ddlString = grDAO.generateDDL(id, (String) session.getAttribute("user_key"));
                    al2.add(ddlString);
                } else {
                    result = null;
                    result = grDAO.simplegatewayReceiverCommand(id, commandStr,
                            (String) session.getAttribute("user_key"));
                    al.add(result);
                }
            }

            if (commandStr.equalsIgnoreCase("DDL")) {
                request.setAttribute("arrayresultddl", al2);
            } else if (commandStr.equalsIgnoreCase("DDL_FILE")) {
                response.setContentType(SAVE_CONTENT_TYPE);
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + String.format(FILENAME, "GatewayReceiverDDL"));

                ServletOutputStream out = response.getOutputStream();
                for (String ddl : al2) {
                    out.println(ddl);
                }

                out.close();
                return null;
            } else {
                model.addAttribute("arrayresult", al);
            }
        }

        gatewayreceivers = grDAO.retrieveGatewayReceiverList((String) session.getAttribute("schema"), null,
                (String) session.getAttribute("user_key"));
    }

    model.addAttribute("records", gatewayreceivers.size());
    model.addAttribute("estimatedrecords", gatewayreceivers.size());

    UserPref userPref = (UserPref) session.getAttribute("prefs");

    if (gatewayreceivers.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("gatewayreceivers", gatewayreceivers);
    } else {
        if (request.getParameter("startAtIndex") != null) {
            startAtIndex = Integer.parseInt(request.getParameter("startAtIndex"));
        }

        if (request.getParameter("endAtIndex") != null) {
            endAtIndex = Integer.parseInt(request.getParameter("endAtIndex"));
            if (endAtIndex > gatewayreceivers.size()) {
                endAtIndex = gatewayreceivers.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();
        }

        List subList = gatewayreceivers.subList(startAtIndex, endAtIndex);
        model.addAttribute("gatewayreceivers", subList);
    }

    model.addAttribute("startAtIndex", startAtIndex);
    model.addAttribute("endAtIndex", endAtIndex);

    // This will resolve to /WEB-INF/jsp/gatewayreceivers.jsp
    return "gatewayreceivers";

}

From source file:pivotal.au.se.gemfirexdweb.controller.DiskStoreController.java

@RequestMapping(value = "/diskstores", method = RequestMethod.POST)
public String performDiskStoreAction(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {/*ww w. j  a v  a  2  s. com*/
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    int startAtIndex = 0, endAtIndex = 0;
    Result result = new Result();
    List<DiskStore> dsks = null;
    String ddlString = null;

    logger.debug("Received request to perform an action on the disk stores");

    DiskStoreDAO dsDAO = GemFireXDWebDAOFactory.getDiskStoreDAO();

    if (request.getParameter("search") != null) {
        dsks = dsDAO.retrieveDiskStoreList("", (String) request.getParameter("search"),
                (String) session.getAttribute("user_key"));

        model.addAttribute("search", (String) request.getParameter("search"));
    } else {
        String[] tableList = request.getParameterValues("selected_ds[]");
        String commandStr = request.getParameter("submit_mult");

        logger.debug("tableList = " + Arrays.toString(tableList));
        logger.debug("command = " + commandStr);

        // start actions now if tableList is not null

        if (tableList != null) {
            List al = new ArrayList<Result>();
            List<String> al2 = new ArrayList<String>();

            for (String table : tableList) {
                if (commandStr.equalsIgnoreCase("DDL") || commandStr.equalsIgnoreCase("DDL_FILE")) {
                    ddlString = dsDAO.generateDDL(table, (String) session.getAttribute("user_key"));
                    al2.add(ddlString);
                } else {
                    result = null;
                    result = dsDAO.simplediskStoreCommand(table, commandStr,
                            (String) session.getAttribute("user_key"));
                    al.add(result);
                }
            }

            if (commandStr.equalsIgnoreCase("DDL")) {
                request.setAttribute("arrayresultddl", al2);
            } else if (commandStr.equalsIgnoreCase("DDL_FILE")) {
                response.setContentType(SAVE_CONTENT_TYPE);
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + String.format(FILENAME, "DiskStoreDDL"));

                ServletOutputStream out = response.getOutputStream();
                for (String ddl : al2) {
                    out.println(ddl);
                }

                out.close();
                return null;
            } else {
                model.addAttribute("arrayresult", al);
            }
        }

        dsks = dsDAO.retrieveDiskStoreList("", null, (String) session.getAttribute("user_key"));
    }

    model.addAttribute("records", dsks.size());
    model.addAttribute("estimatedrecords", dsks.size());

    UserPref userPref = (UserPref) session.getAttribute("prefs");

    if (dsks.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("diskstores", dsks);
    } else {
        if (request.getParameter("startAtIndex") != null) {
            startAtIndex = Integer.parseInt(request.getParameter("startAtIndex"));
        }

        if (request.getParameter("endAtIndex") != null) {
            endAtIndex = Integer.parseInt(request.getParameter("endAtIndex"));
            if (endAtIndex > dsks.size()) {
                endAtIndex = dsks.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();

        }

        List subList = dsks.subList(startAtIndex, endAtIndex);
        model.addAttribute("diskstores", subList);
    }

    model.addAttribute("startAtIndex", startAtIndex);
    model.addAttribute("endAtIndex", endAtIndex);

    // This will resolve to /WEB-INF/jsp/diskstores.jsp
    return "diskstores";

}

From source file:pivotal.au.se.gemfirexdweb.controller.HdfsStoreController.java

@RequestMapping(value = "/hdfsstores", method = RequestMethod.POST)
public String performHdfsStoreAction(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {/*from  w  w  w.  j  a v a  2s .c  o m*/
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    int startAtIndex = 0, endAtIndex = 0;
    Result result = new Result();
    List<HdfsStore> hdfsStores = null;
    String ddlString = null;

    logger.debug("Received request to perform an action on the hdfs stores");

    HdfsStoreDAO hdfsDAO = GemFireXDWebDAOFactory.getHdfsStoreDAO();

    if (request.getParameter("search") != null) {
        hdfsStores = hdfsDAO.retrieveHdfsStoreList("", (String) request.getParameter("search"),
                (String) session.getAttribute("user_key"));

        model.addAttribute("search", (String) request.getParameter("search"));
    } else {
        String[] tableList = request.getParameterValues("selected_hdfs[]");
        String commandStr = request.getParameter("submit_mult");

        logger.debug("tableList = " + Arrays.toString(tableList));
        logger.debug("command = " + commandStr);

        // start actions now if tableList is not null

        if (tableList != null) {
            List al = new ArrayList<Result>();
            List<String> al2 = new ArrayList<String>();

            for (String table : tableList) {
                if (commandStr.equalsIgnoreCase("DDL") || commandStr.equalsIgnoreCase("DDL_FILE")) {
                    ddlString = hdfsDAO.generateDDL(table, (String) session.getAttribute("user_key"));
                    al2.add(ddlString);
                } else {
                    result = null;
                    result = hdfsDAO.simplehdfsStoreCommand(table, commandStr,
                            (String) session.getAttribute("user_key"));
                    al.add(result);
                }
            }

            if (commandStr.equalsIgnoreCase("DDL")) {
                request.setAttribute("arrayresultddl", al2);
            } else if (commandStr.equalsIgnoreCase("DDL_FILE")) {
                response.setContentType(SAVE_CONTENT_TYPE);
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + String.format(FILENAME, "HDFSStoreDDL"));

                ServletOutputStream out = response.getOutputStream();
                for (String ddl : al2) {
                    out.println(ddl);
                }

                out.close();
                return null;
            } else {
                model.addAttribute("arrayresult", al);
            }
        }

        hdfsStores = hdfsDAO.retrieveHdfsStoreList("", null, (String) session.getAttribute("user_key"));
    }

    model.addAttribute("records", hdfsStores.size());
    model.addAttribute("estimatedrecords", hdfsStores.size());

    UserPref userPref = (UserPref) session.getAttribute("prefs");

    if (hdfsStores.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("hdfsstores", hdfsStores);
    } else {
        if (request.getParameter("startAtIndex") != null) {
            startAtIndex = Integer.parseInt(request.getParameter("startAtIndex"));
        }

        if (request.getParameter("endAtIndex") != null) {
            endAtIndex = Integer.parseInt(request.getParameter("endAtIndex"));
            if (endAtIndex > hdfsStores.size()) {
                endAtIndex = hdfsStores.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();

        }

        List subList = hdfsStores.subList(startAtIndex, endAtIndex);
        model.addAttribute("hdfsstores", subList);
    }

    model.addAttribute("startAtIndex", startAtIndex);
    model.addAttribute("endAtIndex", endAtIndex);

    // This will resolve to /WEB-INF/jsp/hdfsstores.jsp
    return "hdfsstores";

}

From source file:pivotal.au.se.gemfirexdweb.controller.AsyncController.java

@RequestMapping(value = "/asyncevent", method = RequestMethod.POST)
public String performAsyncAction(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {//from  ww w  .  j a va2 s. c  o m
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    int startAtIndex = 0, endAtIndex = 0;
    Result result = new Result();
    List<Asyncevent> asyncevents = null;
    String ddlString = null;

    logger.debug("Received request to perform an action on the async events");

    AsynceventDAO asyncDAO = GemFireXDWebDAOFactory.getAsynceventDAO();

    if (request.getParameter("search") != null) {
        asyncevents = asyncDAO.retrieveAsynceventList((String) session.getAttribute("schema"),
                (String) request.getParameter("search"), (String) session.getAttribute("user_key"));

        model.addAttribute("search", (String) request.getParameter("search"));
    } else {
        String[] tableList = request.getParameterValues("selected_async[]");
        String commandStr = request.getParameter("submit_mult");

        logger.debug("tableList = " + Arrays.toString(tableList));
        logger.debug("command = " + commandStr);

        // start actions now if tableList is not null

        if (tableList != null) {
            List al = new ArrayList<Result>();
            List<String> al2 = new ArrayList<String>();

            for (String asyncName : tableList) {
                if (commandStr.equalsIgnoreCase("DDL") || commandStr.equalsIgnoreCase("DDL_FILE")) {
                    ddlString = asyncDAO.generateDDL(asyncName, (String) session.getAttribute("user_key"));
                    al2.add(ddlString);
                } else {
                    result = null;
                    result = asyncDAO.simpleasynceventCommand(asyncName, commandStr,
                            (String) session.getAttribute("user_key"));
                    al.add(result);
                }
            }

            if (commandStr.equalsIgnoreCase("DDL")) {
                request.setAttribute("arrayresultddl", al2);
            } else if (commandStr.equalsIgnoreCase("DDL_FILE")) {
                response.setContentType(SAVE_CONTENT_TYPE);
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + String.format(FILENAME, "AsyncEventListenerDDL"));

                ServletOutputStream out = response.getOutputStream();
                for (String ddl : al2) {
                    out.println(ddl);
                }

                out.close();
                return null;
            } else {
                model.addAttribute("arrayresult", al);
            }
        }

        asyncevents = asyncDAO.retrieveAsynceventList((String) session.getAttribute("schema"), null,
                (String) session.getAttribute("user_key"));
    }

    model.addAttribute("records", asyncevents.size());
    model.addAttribute("estimatedrecords", asyncevents.size());

    UserPref userPref = (UserPref) session.getAttribute("prefs");

    if (asyncevents.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("asyncevents", asyncevents);
    } else {
        if (request.getParameter("startAtIndex") != null) {
            startAtIndex = Integer.parseInt(request.getParameter("startAtIndex"));
        }

        if (request.getParameter("endAtIndex") != null) {
            endAtIndex = Integer.parseInt(request.getParameter("endAtIndex"));
            if (endAtIndex > asyncevents.size()) {
                endAtIndex = asyncevents.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();
        }

        List subList = asyncevents.subList(startAtIndex, endAtIndex);
        model.addAttribute("asyncevents", subList);
    }

    model.addAttribute("startAtIndex", startAtIndex);
    model.addAttribute("endAtIndex", endAtIndex);

    // This will resolve to /WEB-INF/jsp/async.jsp
    return "async";
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.DashboardPropertyListController.java

private void doHelp(HttpServletResponse res) throws IOException, ServletException {
    ServletOutputStream out = res.getOutputStream();
    res.setContentType("text/html; charset=UTF-8");
    out.println("<html><body><h2>Quick Notes on using EntityMergedPropList:</h2>");
    out.println("<p>request.attributes 'entity' must be set by Entity servlet before calling."
            + " It should already be 'filled out.' </p>");
    out.println("</body></html>");
}