Example usage for java.io PrintWriter append

List of usage examples for java.io PrintWriter append

Introduction

In this page you can find the example usage for java.io PrintWriter append.

Prototype

public PrintWriter append(char c) 

Source Link

Document

Appends the specified character to this writer.

Usage

From source file:org.sakaiproject.nakamura.templates.servlet.FulfillTemplateServlet.java

@Override
@SuppressWarnings("unchecked")
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {

    try {//from  w  w  w  . ja v  a2s.co m
        // get text of the template
        Resource requestResource = request.getResource();
        Node templateNode = requestResource.adaptTo(Node.class);
        String templateText = "";
        if (templateNode != null && templateNode.hasProperty("sakai:template")) {
            templateText = templateNode.getProperty("sakai:template").getString();
        } else {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST,
                    "Requested path does not contain a Sakai template");
            return;
        }
        Collection<String> missingTerms = templateService.missingTerms(request.getRequestParameterMap(),
                templateText);
        if (!missingTerms.isEmpty()) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST,
                    "Your request is missing parameters for the template: "
                            + StringUtils.join(missingTerms, ", "));
        }

        if (templateNode.hasProperty("sakai:content-type")) {
            response.setContentType(templateNode.getProperty("sakai:content-type").getString());
        }

        PrintWriter writer = response.getWriter();
        writer.append(templateService.evaluateTemplate(request.getParameterMap(), templateText));
        writer.flush();

    } catch (RepositoryException e) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getLocalizedMessage());
    }

}

From source file:org.emergent.plumber.InfoServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String msg = "";
    try {/*from  w w  w .j a  v  a  2 s  .com*/
        msg = getMsg(req);
    } catch (SQLException e) {
        log(e.getMessage(), e);
    }

    if (msg != null) {
        resp.setContentType("application/json");
        PrintWriter writer = resp.getWriter();
        log("infocolresp: " + msg);
        writer.append(msg);
    } else {
        resp.sendError(404);
    }
}

From source file:org.kalypso.model.hydrology.internal.preprocessing.writer.BodentypWriter.java

@Override
protected void writeContent(final PrintWriter buffer) {
    buffer.append("/Bodentypen:\n/\n/Typ       Tiefe[dm]\n"); //$NON-NLS-1$

    final Parameter parameter = (Parameter) m_parameterWorkspace.getRootFeature();

    // write normal soil types
    doWrite(parameter.getSoiltypes(), buffer);

    // write DRWBM soil types
    doWriteDRWBM(parameter.getDRWBMSoiltypes(), buffer);
}

From source file:com.silverpeas.form.MyFieldDisplayer.java

@Override
public void displayScripts(PrintWriter out, FieldTemplate template, PagesContext PagesContext)
        throws IOException {
    out.append(toScript(template));
}

From source file:org.smartfrog.services.www.bulkio.server.AbstractBulkioServlet.java

protected void returnPlainText(HttpServletResponse response, String message) throws IOException {
    response.setContentType(HttpHeaders.TEXT_PLAIN);
    PrintWriter writer = response.getWriter();
    try {//from w w  w . j  av a 2s . c o  m
        writer.append(message);
    } finally {
        closeQuietly(writer);
    }
}

From source file:org.eurekastreams.server.service.servlets.GetThemeCssServlet.java

/**
 * Pump out an HTTP error./*ww  w.  ja  v  a2  s.com*/
 * 
 * @param statusCode
 *            the status code.
 * @param response
 *            the response.
 */
private void httpError(final int statusCode, final HttpServletResponse response) {
    try {
        response.setStatus(statusCode);
        response.setContentType("text/html");
        PrintWriter writer = response.getWriter();
        writer.append("<html><body><h1>Error Code: " + statusCode + "</h1><body></html>");
        writer.flush();
    } catch (IOException e) {
        log.error(e);
    }
}

From source file:de.perdian.apps.dashboard.mvc.portal.PortalView.java

@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");

    PrintWriter printWriter = response.getWriter();
    printWriter.append("<!DOCTYPE html>\n");
    printWriter.append("<html>\n");
    printWriter.append("<head>\n");
    this.appendDashboardHead(model, request, response);
    printWriter.append("</head>\n");
    printWriter.append("<body>\n");
    this.appendDashboardBody(model, request, response);
    printWriter.append("</body>\n");
    printWriter.append("</html>\n");

}

From source file:Controllers.ProfileController.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//  w ww .ja v  a2 s  . c  om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, SQLException, ClassNotFoundException {
    if ("GET_PROFILE".equals(request.getParameter("TASK"))) {
        //Returns a user as a JSON string from a user ID
        String userID = request.getParameter("user_id");
        User user = new User();
        user.setFacebookID(userID);
        user = user.getUser();

        //GET RIDES TAKEN AND GIVEN HERE
        //user.updateGivenAndTaken();

        JSONObject jsonUser = user.toJSON();
        response.setContentType("application/json");
        PrintWriter out = response.getWriter();
        out.append(jsonUser.toString()); //Might be toString instead
        out.flush();
    } else if ("UPDATE_CAR".equals(request.getParameter("TASK"))) {
        //Returns a user as a JSON string from a user ID
        String userID = request.getParameter("user_id");
        User user = new User();
        user.setFacebookID(userID);
        user = user.getUser();

        String newBrand = request.getParameter("car_brand");
        String newModel = request.getParameter("car_model");
        String newColour = request.getParameter("car_colour");
        String newLicence = request.getParameter("licence_plate");

        user.setCarBrand(newBrand);
        user.setCarModel(newModel);
        user.setCarColour(newColour);
        user.setLicencePlate(newLicence);
        user.updateDB();

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.append("Profile Updated"); //Might be toString instead
        out.flush();
    }
}

From source file:demo.project.ExportTable.java

/**
 * @param w/*from  w w  w  .  j  a va 2 s .co m*/
 * @param ranker
 */
private void dumpHeader(PrintWriter w, ColumnRanker ranker) {
    w.append("Item");
    RowSortedTable<Integer, Integer, String> headers = TreeBasedTable.create();
    int r = 0;
    int c = 0;
    for (Iterator<ARankColumnModel> it = table.getColumnsOf(ranker); it.hasNext();) {
        ARankColumnModel col = it.next();
        headers.put(r, c++, col.getLabel());
        if (col instanceof ACompositeRankColumnModel)
            c = addAll(headers, r, c, (ACompositeRankColumnModel) col);
    }
    for (int row : headers.rowKeySet()) {
        for (int j = 0; j < c; ++j) {
            String l = headers.get(row, j);
            w.append('\t');
            if (l != null)
                w.append(l);
        }
        w.println();
    }
}

From source file:org.eclipse.virgo.management.console.UploadServlet.java

private void doDeployment(List<File> uploadedFiles, HttpServletResponse response)
        throws MalformedObjectNameException, NullPointerException, IOException {
    ObjectName objectName = new ObjectName(DEPLOYER_MBEAN_NAME);
    PrintWriter writer = response.getWriter();
    writer.append("<ol id=\"uploadResults\">");
    for (File file : uploadedFiles) {
        URI uri = file.toURI();// ww w . jav a 2s  .c o m
        try {
            Object invoke = this.mBeanServer.invoke(objectName, "deploy", new Object[] { uri.toString() },
                    new String[] { String.class.getName() });
            writer.append("<li>" + file.getName() + " deployed as " + getDeploymentIdentity(invoke) + "</li>");
        } catch (Exception e) {
            writer.append("<li>" + file.getName() + " failed to deploy '" + e.getMessage() + "'</li>");
        }
        writer.append("<li />");
    }
    writer.append("</ol>");
    writer.close();
}