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:org.mskcc.pathdb.action.web_api.NeighborhoodMapRetriever.java

/**
 * Writes html code that constructs frameset for map/legend.
 *
 * @param response HttpServletResponse/*w  w w  .j av  a  2s  .  co m*/
 * @throws IOException
 */
private void writeFramesetToResponse(HttpServletResponse response) throws IOException {

    log.info("NeighborhoodMapRetriever.writeFramesetToResponse");

    // set content type
    response.setContentType("text/html");
    CONTENT_TYPE_SET = true;
    ServletOutputStream stream = response.getOutputStream();

    // write out html to define frameset
    stream.println("<html>");
    stream.println("<head>");
    stream.println("<title>Neighborhood Map</title>");
    stream.println("</head>");
    stream.println("<frameset cols=\"60%,40%\">");
    stream.println("<frame src=\"webservice.do?" + ProtocolRequest.ARG_VERSION + "="
            + ProtocolConstantsVersion3.VERSION_3 + "&" + ProtocolRequest.ARG_COMMAND + "="
            + ProtocolConstantsVersion2.COMMAND_GET_NEIGHBORS + "&" + ProtocolRequest.ARG_QUERY + "="
            + Long.toString(PHYSICAL_ENTITY_RECORD_ID) + "&" + ProtocolRequest.ARG_DATA_SOURCE + "="
            + PROTOCOL_REQUEST.getDataSource() + "&" + ProtocolRequest.ARG_OUTPUT + "="
            + ProtocolConstantsVersion2.FORMAT_IMAGE_MAP + "\">");
    stream.println("<frame src=\"sif_legend.do\">");
    stream.println("</frameset>");
    stream.println("</html>");

    // outta here
    stream.flush();
    stream.close();
}

From source file:org.inbio.ait.web.ajax.controller.SpeciesController.java

/**
 * Return the XML with the results//from w  w w .  j ava 2 s .  c  om
 * @param request
 * @param response
 * @param species
 * @param matchesByPolygon
 * @return
 * @throws java.lang.Exception
 */
private ModelAndView writeReponse(HttpServletRequest request, HttpServletResponse response,
        List<String> species, List<Node> matchesByPolygon) throws Exception {

    response.setCharacterEncoding("ISO-8859-1");
    response.setContentType("text/xml");
    ServletOutputStream out = response.getOutputStream();
    StringBuilder result = new StringBuilder();

    if (matchesByPolygon == null) { //If there is not geographical criteria
        result.append("<?xml version='1.0' encoding='ISO-8859-1'?><response><speciesList>");
        for (String s : species) {
            result.append("<species>" + s + "</species>");
        }
        result.append("</speciesList><polygons></polygons></response>");
        out.println(result.toString());
    } else { //If there is gegraphical criteria
        result.append("<?xml version='1.0' encoding='ISO-8859-1'?><response>");
        result.append("<speciesList></speciesList>");
        result.append("<polygons>");
        for (Node node : matchesByPolygon) {

            result.append("<polygon>");
            result.append("<abs>" + node.getValue1() + "</abs>");
            result.append("<per>" + node.getValue2() + "</per>");
            for (String sp : node.getValue3()) {
                result.append("<sp>" + sp + "</sp>");
            }
            result.append("</polygon>");
        }
        result.append("</polygons></response>");
        out.println(result.toString());
    }

    out.flush();
    out.close();

    return null;
}

From source file:biz.netcentric.cq.tools.actool.dumpservice.impl.DumpserviceImpl.java

public void writeAuthorizableConfigToStream(Set<AuthorizableConfigBean> authorizableSet,
        ServletOutputStream outStream) throws IOException {

    outStream.println("- " + Constants.GROUP_CONFIGURATION_KEY + ":");
    outStream.println();//from   w w  w  . j a  v a  2 s . c  o m

    for (AuthorizableConfigBean bean : authorizableSet) {
        outStream.println(AcHelper.getBlankString(AcDumpElementYamlVisitor.DUMP_INDENTATION_KEY) + "- "
                + bean.getPrincipalID() + ":");
        outStream.println();
        outStream.println(
                AcHelper.getBlankString(AcDumpElementYamlVisitor.DUMP_INDENTATION_FIRST_PROPERTY) + "- name: ");
        outStream.println(AcHelper.getBlankString(AcDumpElementYamlVisitor.DUMP_INDENTATION_PROPERTY)
                + "memberOf: " + bean.getMemberOfString());
        outStream.println(AcHelper.getBlankString(AcDumpElementYamlVisitor.DUMP_INDENTATION_PROPERTY) + "path: "
                + bean.getPath());
        outStream.println(AcHelper.getBlankString(AcDumpElementYamlVisitor.DUMP_INDENTATION_PROPERTY)
                + "isGroup: " + "'" + bean.isGroup() + "'");
        outStream.println();
    }
}

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

@RequestMapping(value = "/createtable", method = RequestMethod.POST)
public String createTableAction(@ModelAttribute("tableAttribute") NewTable tableAttribute, 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 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 table");

    String tabName = tableAttribute.getTableName();

    String[] columnNames = request.getParameterValues("column_name[]");
    String[] columnTypes = request.getParameterValues("column_type[]");
    String[] columnPrecision = request.getParameterValues("column_precision[]");
    String[] columnDefaultValues = request.getParameterValues("column_default_value[]");
    String[] columnSelectedNulls = request.getParameterValues("column_selected_null[]");
    String[] columnSelectedPrimaryKeys = request.getParameterValues("column_selected_primary_key[]");
    String[] columnSelectedAutoIncrements = request.getParameterValues("column_selected_auto_increment[]");

    logger.debug("New Table Name = " + tabName);
    logger.debug("columnNames = " + Arrays.toString(columnNames));
    logger.debug("columnTypes = " + Arrays.toString(columnTypes));
    logger.debug("columnPrecision = " + Arrays.toString(columnPrecision));
    logger.debug("columnDefaultValues = " + Arrays.toString(columnDefaultValues));
    logger.debug("columnSelectedNulls = " + Arrays.toString(columnSelectedNulls));
    logger.debug("columnSelectedPrimaryKeys = " + Arrays.toString(columnSelectedPrimaryKeys));
    logger.debug("columnSelectedAutoIncrements = " + Arrays.toString(columnSelectedAutoIncrements));

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

    DiskStoreDAO dsDAO = GemFireXDWebDAOFactory.getDiskStoreDAO();
    HdfsStoreDAO hdfsDAO = GemFireXDWebDAOFactory.getHdfsStoreDAO();

    List<DiskStore> dsks = dsDAO.retrieveDiskStoreForCreateList((String) session.getAttribute("user_key"));

    List<HdfsStore> hdfs = hdfsDAO.retrieveHdfsStoreForCreateList((String) session.getAttribute("user_key"));

    model.addAttribute("diskstores", dsks);
    model.addAttribute("hdfsstores", hdfs);

    if (submit != null) {

        if (submit.equalsIgnoreCase("Column(s)")) {
            TypeDAO typeDAO = GemFireXDWebDAOFactory.getTypeDAO();
            List<Type> types = typeDAO.retrieveTypeList((String) session.getAttribute("schema"), null,
                    (String) session.getAttribute("user_key"));

            model.addAttribute("types", types);

            int cols = Integer.parseInt(request.getParameter("numColumns"));
            int numColumns = Integer.parseInt((String) session.getAttribute("numColumns"));

            numColumns = numColumns + cols;

            session.setAttribute("numColumns", "" + numColumns);
            session.setAttribute("tabName", tableAttribute.getTableName());

            model.addAttribute("numColumns", numColumns);
            model.addAttribute("tabName", tableAttribute.getTableName());
            model.addAttribute("hdfsStore", tableAttribute.getHdfsStore());
            model.addAttribute("diskStore", tableAttribute.getDiskStore());
        } else {
            // build create table SQL 
            StringBuffer createTable = new StringBuffer();
            String schema = tableAttribute.getSchemaName();
            if (schema.length() == 0) {
                schema = (String) session.getAttribute("schema");
            }

            createTable.append("create table " + schema + "." + tabName + " \n");
            createTable.append("(");

            int i = 0;
            String val = null;

            if (columnNames != null) {
                int size = columnNames.length;
                for (String columnName : columnNames) {
                    createTable.append(columnName + " ");
                    createTable.append(columnTypes[i]);

                    // doing precision / size
                    val = checkIfEntryExists(columnPrecision, i);
                    if (val != null) {
                        createTable.append("(" + columnPrecision[i] + ")");
                    }
                    val = null;

                    // doing auto increment check here
                    val = checkIfEntryExists(columnSelectedAutoIncrements, i);
                    if (val != null) {
                        // should check for column type here
                        if (val.equalsIgnoreCase("Y")) {
                            createTable.append(" generated always as identity");
                        }
                    }
                    val = null;

                    // doing default value
                    val = checkIfEntryExists(columnDefaultValues, i);
                    if (val != null) {
                        // should check for column type here
                        createTable.append(" default " + columnDefaultValues[i]);
                    }
                    val = null;

                    // doing not null check here
                    val = checkIfEntryExists(columnSelectedNulls, i);
                    if (val != null) {
                        if (val.equalsIgnoreCase("Y")) {
                            createTable.append(" NOT NULL");
                        }
                    }
                    val = null;

                    // doing primary key check here
                    val = checkIfEntryExists(columnSelectedPrimaryKeys, i);
                    if (val != null) {
                        if (val.equalsIgnoreCase("Y")) {
                            createTable.append(" CONSTRAINT " + tabName + "_PK Primary Key");
                        }
                    }
                    val = null;

                    int j = size - 1;
                    if (i < j) {
                        createTable.append(",\n");
                    }

                    i++;
                }

            }

            createTable.append(")\n");

            if (request.getParameter("dataPolicy").equalsIgnoreCase("REPLICATE")) {
                createTable.append("REPLICATE\n");
            }

            if (!checkIfParameterEmpty(request, "serverGroups")) {
                createTable.append("SERVER GROUPS (" + tableAttribute.getServerGroups() + ")\n");
            }

            if (!checkIfParameterEmpty(request, "persistant")) {
                if (tableAttribute.getPersistant().equalsIgnoreCase("Y")) {
                    createTable.append("PERSISTENT ");
                    if (!checkIfParameterEmpty(request, "diskStore")) {
                        createTable.append("'" + tableAttribute.getDiskStore() + "' ");
                        if (!checkIfParameterEmpty(request, "persistenceType")) {
                            createTable.append(tableAttribute.getPersistenceType() + "\n");
                        } else {
                            createTable.append("\n");
                        }

                    }
                }
            }

            if (request.getParameter("dataPolicy").equalsIgnoreCase("PARTITION")) {
                if (!checkIfParameterEmpty(request, "partitionBy")) {
                    createTable.append("PARTITION BY " + tableAttribute.getPartitionBy() + "\n");
                }

                if (!checkIfParameterEmpty(request, "colocateWith")) {
                    createTable.append("COLOCATE WITH (" + tableAttribute.getColocateWith() + ")\n");
                }

                if (!checkIfParameterEmpty(request, "redundancy")) {
                    createTable.append("REDUNDANCY " + tableAttribute.getRedundancy() + "\n");
                }
            }

            if (!checkIfParameterEmpty(request, "hdfsStore")) {
                createTable.append("HDFSSTORE (" + tableAttribute.getHdfsStore() + ") ");
                if (request.getParameter("writeonly").equalsIgnoreCase("Y")) {
                    createTable.append("WRITEONLY\n");
                } else {
                    // need to ad eviction properties here
                    if (!checkIfParameterEmpty(request, "evictionbycriteria")) {
                        createTable.append(
                                "EVICTION BY CRITERIA (" + tableAttribute.getEvictionbycriteria() + ")\n");
                    }

                    if (!checkIfParameterEmpty(request, "evictionfrequency")) {
                        createTable
                                .append("EVICTION FREQUENCY " + tableAttribute.getEvictionfrequency() + "\n");
                    } else {
                        if (request.getParameter("evictincoming").equalsIgnoreCase("Y")) {
                            createTable.append("EVICT INCOMING\n");
                        }
                    }
                }

            }

            if (!checkIfParameterEmpty(request, "gatewaysender")) {
                createTable.append("GATEWAYSENDER (" + tableAttribute.getGatewaysender() + ")\n");
            }

            if (!checkIfParameterEmpty(request, "asynceventlistener")) {
                createTable.append("ASYNCEVENTLISTENER (" + tableAttribute.getAsynceventlistener() + ")\n");
            }

            if (!checkIfParameterEmpty(request, "offheap")) {
                if (request.getParameter("offheap").equalsIgnoreCase("Y")) {
                    createTable.append("OFFHEAP\n");
                }
            }

            if (!checkIfParameterEmpty(request, "other")) {
                createTable.append(tableAttribute.getOther() + "\n");
            }

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

                logger.debug("Creating table as -> " + createTable.toString());

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

                model.addAttribute("result", result);
                model.addAttribute("hdfsStore", tableAttribute.getHdfsStore());
                model.addAttribute("diskStore", tableAttribute.getDiskStore());

            } else if (submit.equalsIgnoreCase("Show SQL")) {
                logger.debug("Table SQL as follows as -> " + createTable.toString());
                model.addAttribute("sql", createTable.toString());
                model.addAttribute("hdfsStore", tableAttribute.getHdfsStore());
                model.addAttribute("diskStore", tableAttribute.getDiskStore());
            } else if (submit.equalsIgnoreCase("Save to File")) {
                response.setContentType(SAVE_CONTENT_TYPE);
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + String.format(FILENAME, tabName));

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

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

From source file:org.n52.smartsensoreditor.controller.SaveLocalControllerSML.java

/**
 * Hanlde user request/*from w w w. j  a va 2 s.com*/
 *
 * @param request
 * @param pResponse
 * @return
 * @throws Exception
 */
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse pResponse) throws Exception {
    // get document stored in backenservice
    Document lDoc = mBackendService.mergeBackend();
    XPathUtil lUtil = new XPathUtil();
    lUtil.setContext(editorContext);
    String lFileId = lUtil.evaluateAsString("//gmd:fileIdentifier/gco:CharacterString/text()", lDoc);
    if (lFileId.equals("")) {
        lFileId = lUtil.evaluateAsString("/*/gml:identifier/text()", lDoc);
    }
    lFileId = lFileId.trim();
    // set response attributes
    //pResponse.setContentType("application/x-download");
    pResponse.setContentType(getContentType() == null ? "application/x-download" : getContentType());
    // set header
    if (getSetHeader() != null) {
        for (Map.Entry<String, String> entry : getSetHeader().entrySet()) {
            pResponse.setHeader(entry.getKey(), entry.getValue());
        }
    }
    // add header
    if (getAddHeader() != null) {
        for (Map.Entry<String, String> entry : getAddHeader().entrySet()) {
            pResponse.addHeader(entry.getKey(), entry.getValue());
        }
    }
    pResponse.setHeader("Content-disposition", "attachment; filename=" + lFileId + ".xml");
    if (LOG.isDebugEnabled())
        LOG.debug("Preparing download for document with id: " + lFileId);
    ServletOutputStream lOutputStream = pResponse.getOutputStream();
    try {
        // write document to servlet response
        TransformerFactory tf = TransformerFactory.newInstance();
        // identity
        Transformer t = tf.newTransformer();
        t.setOutputProperty(OutputKeys.INDENT, "yes");
        t.transform(new DOMSource(lDoc), new StreamResult(lOutputStream));
    } catch (Exception e) {
        pResponse.setHeader("Content-disposition", "attachment; filename=ExportError.xml");
        lOutputStream.println("<?xml version='1.0' encoding=\"UTF-8\" standalone=\"no\" ?>");
        lOutputStream.println("<ExportExceptionReport version=\"1.1.0\">");
        lOutputStream.println("    Request rejected due to errors.");
        lOutputStream.println("      Reason: " + e.getMessage());
        lOutputStream.println("</ExportExceptionReport>");
        lOutputStream.println();
        LOG.error("Exception while copying from input to output stream: " + e.getMessage());
    } finally {
        lOutputStream.flush();
        lOutputStream.close();
    }
    // forward
    return null;
}

From source file:org.openmrs.module.vcttrac.util.FileExporter.java

/**
 * Auto generated method comment/*from   www.j  a  v a  2 s .  c om*/
 * 
 * @param request
 * @param response
 * @param patientList
 * @param filename
 * @param title
 * @throws Exception
 */
public void exportToCSVFile(HttpServletRequest request, HttpServletResponse response,
        List<VCTClient> clientList, String filename, String title, String searchDescr) throws Exception {
    ServletOutputStream outputStream = null;

    try {
        outputStream = response.getOutputStream();
        //         Person p;

        response.setContentType("text/plain");
        response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
        outputStream.println(VCTTracUtil.getMessage("vcttrac.export.title.bigtitle", null));
        outputStream.println(VCTTracUtil.getMessage("vcttrac.export.report.title", null) + ", " + title);
        outputStream.println(
                VCTTracUtil.getMessage("vcttrac.export.report.description", null) + ", " + searchDescr);
        outputStream.println();
        outputStream.println(VCTTracUtil.getMessage("vcttrac.export.title.generatedby", null) + ", "
                + Context.getAuthenticatedUser().getPersonName());
        outputStream.println(VCTTracUtil.getMessage("vcttrac.export.title.generatedon", null) + ", "
                + (new SimpleDateFormat("dd-MMM-yyyy HH:mm").format(new Date())));
        outputStream.println(VCTTracUtil.getMessage("vcttrac.export.title.numberofclients", null) + ", "
                + clientList.size());
        outputStream.println();
        //         outputStream
        //                 .println("No., Names, Gender, BirthDay, Registration Date, Counseling Done ?, Got Rsultat ?, Result of HIV Test");
        setColumnTitles(outputStream);
        outputStream.println();

        int ids = 0;

        for (VCTClient client : clientList) {
            ids += 1;
            /*p = client.getClient();
            outputStream.println(ids
            + ","
            + p.getPersonName()
            + ","
            + p.getGender()
            + ","
            + df.format(p.getBirthdate())
            + ","
            + df.format(client.getDateOfRegistration())
            + ","
            + ((client.getCounselingObs() != null) ? "Yes" : "No")
            + ","
            + ((client.getResultObs() != null) ? "Yes" : "No")
            + ","
            + VCTModuleTag.convsetObsValueByConcept(client.getResultObs(), VCTTracUtil
                    .getResultOfHivTestConceptId()));*/

            displayRowValues(outputStream, client, ids);
        }

        outputStream.flush();
    } catch (Exception e) {
        log.error(">>VCT>>Export>>in>>CSV>>Format>> " + e.getMessage());
        e.printStackTrace();
    } finally {
        if (null != outputStream)
            outputStream.close();
    }
}

From source file:it.cnr.icar.eric.server.interfaces.rest.QueryManagerURLHandler.java

/** Write the directory listing showing specified objects */
private void writeDirectoryListing(List<?> roList) throws IOException, RegistryException {
    ServletOutputStream sout = null;
    String requestURL = request.getRequestURL().toString() + "?" + request.getQueryString();
    response.setContentType("text/html; charset=UTF-8");
    try {//from   ww  w . j a v a  2 s .  c o m
        sout = response.getOutputStream();

        sout.println("<html>");
        sout.println("<head>");
        sout.println("<title>Index of " + requestURL + "</title>");
        sout.println("</head>");
        sout.println("<body>");
        sout.println("<h1>Index of " + requestURL + "</h1>");
        sout.println("<pre>ObjectType\t\tName\t\tVersion\t\tContent Version\t\tLogical ID");
        sout.println("<hr/>");

        Iterator<?> iter = roList.iterator();
        while (iter.hasNext()) {
            //                RegistryObjectType ro = (RegistryObjectType)iter.next();
            // take ComplexType from Element
            @SuppressWarnings("unchecked")
            RegistryObjectType ebRegistryObjectType = ((JAXBElement<RegistryObjectType>) iter.next())
                    .getValue();
            writeDirectoryListingItem(sout, ebRegistryObjectType);
        }

        sout.println("</pre>");
        sout.println("<hr/>");
        sout.println("<address>freebXML Regisry Server version 3.0</address>");
        sout.println("</body>");
        sout.println("</html>");
    } finally {
        if (sout != null) {
            sout.close();
        }
    }
}

From source file:org.openmrs.module.vcttrac.util.FileExporter.java

/**
 * Auto generated method comment//from w ww.ja v  a 2 s.c  om
 * 
 * @param outputStream
 * @param showNames
 */
private void setColumnTitles(ServletOutputStream outputStream) {
    try {

        boolean hasPrivilegeToViewPatientNames = Context.getAuthenticatedUser()
                .hasPrivilege("View Patient Names");
        boolean hasPrivilegeToViewClientResult = Context.getAuthenticatedUser()
                .hasPrivilege("View VCT Client result");

        outputStream.println(VCTTracUtil.getMessage("vcttrac.export.column.registrationdate", null) + ", "
                + VCTTracUtil.getMessage("vcttrac.export.column.number", null) + ", "
                + VCTTracUtil.getMessage("vcttrac.export.column.clientcode", null) + ", "
                + ((hasPrivilegeToViewPatientNames)
                        ? VCTTracUtil.getMessage("vcttrac.export.column.names", null) + ", "
                        : "")
                + VCTTracUtil.getMessage("vcttrac.export.column.gender", null) + ", "
                + VCTTracUtil.getMessage("vcttrac.export.column.birthday", null) + ", "
                + VCTTracUtil.getMessage("vcttrac.export.column.counselingdone", null) + ", "
                + VCTTracUtil.getMessage("vcttrac.export.column.gotresult", null) + ", "
                + ((hasPrivilegeToViewClientResult)
                        ? VCTTracUtil.getMessage("vcttrac.export.column.resultoftest", null)
                        : ""));

    } catch (Exception e) {
        log.error(">>VCT>>Export>>in>>CSV>>Format>> Fail to set column titles >> " + e.getMessage());
        e.printStackTrace();
    }
}

From source file:org.ralasafe.servlet.AbstractPolicyDesignAction.java

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String oper = req.getParameter("oper");
    if (log.isDebugEnabled()) {
        log.debug("oper=" + oper);
    }//from  w ww .jav a 2 s  .  c  o  m

    AbstractPolicyDesignHandler handler = getPolicyHandler(req);
    req.setAttribute("handler", handler);

    if ("deleteVariable".equals(oper)) {
        int id = WebUtil.getIntParameter(req, "index", 0);
        handler.deleteVariable(id);
    } else if ("addVariable".equals(oper)) {
        DefineVariable var = getDefineVariable(req);

        handler.addVariable(var);
    } else if ("updateVariable".equals(oper)) {
        DefineVariable var = getDefineVariable(req);

        int varIndex = WebUtil.getIntParameter(req, "index", -1);
        handler.updateVariable(varIndex, var);
    } else if ("loadExprTree".equals(oper)) {
        ExprGroup exprGroup = handler.getExprGroup();

        resp.setContentType("application/json;charset=UTF-8");
        ServletOutputStream out = resp.getOutputStream();

        String xml = handler.getExpressionTree(exprGroup);

        if (log.isDebugEnabled()) {
            log.debug("Expression tree json: " + xml);
        }

        out.println(xml);
        out.flush();
    } else if ("addExprChildExprGroup".equals(oper)) {
        String nodeId = req.getParameter("nodeId");
        String type = req.getParameter("type");

        handler.addExprChildExprGroup(nodeId, type);
        return;
    } else if ("editExprGroup".equals(oper)) {
        String nodeId = req.getParameter("nodeId");
        String type = req.getParameter("type");

        handler.editExprGroup(nodeId, type);
        return;
    } else if ("deleteExpr".equals(oper)) {
        String nodeId = req.getParameter("nodeId");

        handler.deleteExpr(nodeId);
        return;
    } else if ("addExprChild".equals(oper)) {
        String pId = req.getParameter("pId");
        String exprType = req.getParameter("exprType");

        if ("binary".equals(exprType)) {
            BinaryExpr expr = getBinaryExpr(req);

            handler.addBinaryExpr(expr, pId);
        } else if ("null".equals(exprType)) {
            Variable var = getVariable(req);
            String operator = req.getParameter("operator");

            handler.addNullExpr(var, operator, pId);
        } else if ("in".equals(exprType)) {
            Variable var1 = getVariable(req, 1);
            Variable var2 = getVariable(req, 2);
            String operator = req.getParameter("operator");

            handler.addInExpr(var1, var2, operator, pId);
        }
        return;
    } else if ("editExpr".equals(oper)) {
        String nodeId = req.getParameter("nodeId");
        String exprType = req.getParameter("exprType");

        if ("binary".equals(exprType)) {
            BinaryExpr expr = getBinaryExpr(req);

            handler.editBinaryExpr(expr, nodeId);
        } else if ("null".equals(exprType)) {
            Variable var = getVariable(req);

            String operator = req.getParameter("operator");
            handler.editNullExpr(var, operator, nodeId);
        } else if ("in".equals(exprType)) {
            Variable var1 = getVariable(req, 1);
            Variable var2 = getVariable(req, 2);
            String operator = req.getParameter("operator");

            handler.editInExpr(var1, var2, operator, nodeId);
        }
        return;
    } else if ("save".equals(oper)) {
        // remove handler from session
        req.getSession().removeAttribute(getPolicyHandlerAttributeKey(req));

        int id = WebUtil.getIntParameter(req, "id", -23);
        try {
            handler.save(id);
        } catch (EntityExistException e) {
            log.error("", e);
            throw new ServletException(e);
        }

        return;
    }
}

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

@RequestMapping(value = "/query", method = RequestMethod.GET)
public String worksheet(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 2 s  . 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 show query worksheet");
    UserPref userPrefs = (UserPref) session.getAttribute("prefs");

    String action = request.getParameter("action");
    if (action != null) {

        CommandResult result = new CommandResult();
        ConnectionManager cm = ConnectionManager.getInstance();
        Connection conn = cm.getConnection(session.getId());

        if (action.trim().equals("commit")) {
            logger.debug("commit action requested");
            result = QueryUtil.runCommitOrRollback(conn, true, "N");
            addCommandToHistory(session, userPrefs, "commit");

            model.addAttribute("result", result);
        } else if (action.trim().equals("rollback")) {
            logger.debug("rollback action requested");
            result = QueryUtil.runCommitOrRollback(conn, false, "N");
            addCommandToHistory(session, userPrefs, "rollback");

            model.addAttribute("result", result);
        } else if (action.trim().equals("export")) {
            logger.debug("export data to CSV action requested");
            String query = request.getParameter("query");
            String exportDataCSV = QueryUtil.runQueryForCSV(conn, query);

            response.setContentType(SAVE_CONTENT_TYPE);
            response.setHeader("Content-Disposition", "attachment; filename=" + FILENAME_EXPORT);

            ServletOutputStream out = response.getOutputStream();
            out.println(exportDataCSV);
            out.close();
            return null;
        } else if (action.trim().equals("export_json")) {
            logger.debug("export data to JSON action requested");
            String query = request.getParameter("query");
            String exportDataJSON = QueryUtil.runQueryForJSON(conn, query);

            response.setContentType(SAVE_CONTENT_TYPE);
            response.setHeader("Content-Disposition", "attachment; filename=" + FILENAME_EXPORT_JSON);

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

    }

    // Create new QueryWindow and add to model
    // This is the formBackingObject
    model.addAttribute("queryAttribute", new QueryWindow());

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