Example usage for java.io PrintWriter print

List of usage examples for java.io PrintWriter print

Introduction

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

Prototype

public void print(Object obj) 

Source Link

Document

Prints an object.

Usage

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java

protected static void leerConvocatoria(HttpServletRequest request, HttpServletResponse response)
        throws IOException {

    ConvocatoriaEntity e = CtrlUsuario.leerConvocatoria(request.getParameter("1")); // id de la convocatoria

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (e.getNombre().isEmpty()) {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", "La convocatoria ya no existe");
        out.print(obj);
    } else {//w  ww . j a  v a 2s.co m
        JSONObject obj = new JSONObject();
        obj.put("id", e.getIdConvocatoria());
        obj.put("nombre", e.getNombre());
        obj.put("descripcion", e.getDescripcion());
        obj.put("cupos", e.getCupos());
        obj.put("fechaFin", "" + e.getFechaFinRegistro());
        out.print(obj);
    }
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java

protected static void eliminarUsuario(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList r = CtrlAdmin.eliminarUsuario(Integer.parseInt(request.getParameter("1"))); // id_usuario

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        if (r.get(1) == "usuario") {
            obj.put("isError", true);
            obj.put("errorDescrip", "El usuario no existe");

        } else {//w w w  . j a v  a2s .  c  om
            Util.errordeRespuesta(r, out);
        }
        out.print(obj);
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else
        Util.errordeRespuesta(r, out);
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java

protected static void leerTaller(HttpServletRequest request, HttpServletResponse response) throws IOException {

    TallerEntity e = CtrlUsuario.leerTaller(request.getParameter("1")); // id de la taller

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (e.getNombre().isEmpty()) {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", "El taller ya no esta disponible");
        out.print(obj);
    } else {/*ww  w . ja  v a2s. co m*/
        JSONObject obj = new JSONObject();
        obj.put("id", e.getIdTaller());
        obj.put("nombre", e.getNombre());
        obj.put("descripcion", e.getDescripcion());
        obj.put("cupos", e.getCupos());
        obj.put("costo", e.getCosto());
        obj.put("fechaFin", "" + e.getFechaFinRegistro());
        obj.put("fechaInicio", "" + e.getFechaInicio());

        out.print(obj);
    }
}

From source file:com.zimbra.common.util.TemplateCompiler.java

private static void convertLines(PrintWriter out, String pkg, String lines, Map<String, String> attrs,
        boolean authoritative) {
    out.print("AjxTemplate.register(\"");
    out.print(pkg);/*from  w w w.j av  a  2s.c o  m*/
    out.println("\", ");
    out.println("function(name, params, data, buffer) {");
    out.println("\tvar _hasBuffer = Boolean(buffer);");
    out.println("\tdata = (typeof data == \"string\" ? { id: data } : data) || {};");
    out.println("\tbuffer = buffer || [];");
    out.println("\tvar _i = buffer.length;");
    out.println();

    Matcher matcher = RE_REPLACE.matcher(lines);
    if (matcher.find()) {
        int offset = 0;
        do {
            int index = matcher.start();
            if (offset < index) {
                printStringLines(out, lines.substring(offset, index));
            }
            String param = matcher.group(1);
            String inline = matcher.group(2);
            if (param != null) {
                printDataLine(out, param);
            } else if (inline != null) {
                printBufferLine(out, inline);
            } else {
                printLine(out, "\t", matcher.group(3).replaceAll("\n", "\n\t"), "\n");
            }
            offset = matcher.end();
        } while (matcher.find());
        if (offset < lines.length()) {
            printStringLines(out, lines.substring(offset));
        }
    } else {
        printStringLines(out, lines);
    }
    out.println();

    out.println("\treturn _hasBuffer ? buffer.length : buffer.join(\"\");");
    out.println("},");
    if (attrs != null && attrs.size() > 0) {
        out.println("{");
        Iterator<String> iter = attrs.keySet().iterator();
        while (iter.hasNext()) {
            String aname = iter.next();
            String avalue = attrs.get(aname);
            out.print("\t\"");
            printEscaped(out, aname);
            out.print("\": \"");
            printEscaped(out, avalue);
            out.print("\"");
            if (iter.hasNext()) {
                out.print(",");
            }
            out.println();
        }
        out.print("}");
    } else {
        out.print("null");
    }
    out.print(", ");
    out.print(authoritative);
    out.println(");");
}

From source file:org.esgf.legacydatacart.WgetGeneratorController.java

private static void writeBash(String wgetText, String filename, HttpServletResponse response) {
    try {//from w  w  w.  j a  v a2 s  . co  m
        //attach the sh file extension to the response
        response.setContentType("text/x-sh");
        response.addHeader("Content-Disposition", "attachment; filename=" + filename);
        response.setContentLength((int) wgetText.length());

        PrintWriter out = response.getWriter();
        out.print(wgetText);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.infinities.keystone4j.utils.Cms.java

public static byte[] DERtoPEM(byte[] bytes, String headfoot) {
    ByteArrayOutputStream pemStream = new ByteArrayOutputStream();
    PrintWriter writer = new PrintWriter(pemStream);

    byte[] stringBytes = BaseEncoding.base64().encode(bytes).getBytes();

    String encoded = new String(stringBytes);

    if (headfoot != null) {
        writer.print("-----BEGIN " + headfoot + "-----\n");
    }/*ww  w.j a v a  2s .c o  m*/

    // write 64 chars per line till done
    int i = 0;
    while ((i + 1) * 64 < encoded.length()) {
        writer.print(encoded.substring(i * 64, (i + 1) * 64));
        writer.print("\n");
        i++;
    }
    if (encoded.length() % 64 != 0) {
        writer.print(encoded.substring(i * 64)); // write remainder
        writer.print("\n");
    }
    if (headfoot != null) {
        writer.print("-----END " + headfoot + "-----\n");
    }
    writer.flush();
    return pemStream.toByteArray();
}

From source file:org.fcrepo.test.api.TestHTTPStatusCodes.java

private static void writeStringToFile(String string, File file) throws Exception {
    FileOutputStream out = new FileOutputStream(file);
    PrintWriter writer = new PrintWriter(new OutputStreamWriter(out));
    try {//from   w  w  w.j av a 2s  .c  om
        writer.print(string);
    } finally {
        writer.close();
    }
}

From source file:eu.annocultor.tools.GeneratorOfXmlSchemaForConvertersDoclet.java

public static boolean start(RootDoc root) {
    Logger log = Logger.getLogger("DocletGenerator");

    if (destination == null) {
        try {//  w w  w . j  av  a2  s . c  o m
            // loaded from RuleListenersFragment
            ruleListenerDef = IOUtils.toString(GeneratorOfXmlSchemaForConvertersDoclet.class
                    .getResourceAsStream("/RuleListenersFragment.xsd"), "UTF-8");

            String fn = System.getenv("annocultor.xconverter.destination.file.name");
            fn = (fn == null) ? "./../../../src/site/resources/schema/XConverterInclude.xsd" : fn;

            destination = new File(fn);
            if (destination.exists()) {
                destination.delete();
            }

            // initial copy of the template and include
            FileOutputStream os;
            os = new FileOutputStream(new File(destination.getParentFile(), "XConverter.xsd"));
            IOUtils.copy(new AutoCloseInputStream(GeneratorOfXmlSchemaForConvertersDoclet.class
                    .getResourceAsStream("/XConverterTemplate.xsd")), os);
            os.close();
            os = new FileOutputStream(destination);
            IOUtils.copy(new AutoCloseInputStream(GeneratorOfXmlSchemaForConvertersDoclet.class
                    .getResourceAsStream("/XConverterInclude.xsd")), os);
            os.close();
        } catch (Exception e) {
            try {
                throw new RuntimeException("On destination " + destination.getCanonicalPath(), e);
            } catch (IOException e1) {
                // too bad
                throw new RuntimeException(e1);
            }
        }
    }

    try {
        String s = Utils.loadFileToString(destination.getCanonicalPath(), "\n");
        int breakPoint = s.indexOf(XSD_TEXT_TO_REPLACED_WITH_GENERATED_XML_SIGNATURES);
        if (breakPoint < 0) {
            throw new Exception(
                    "Signature not found in XSD: " + XSD_TEXT_TO_REPLACED_WITH_GENERATED_XML_SIGNATURES);
        }
        String preambula = s.substring(0, breakPoint);
        String appendix = s.substring(breakPoint);

        destination.delete();

        PrintWriter schemaWriter = new PrintWriter(destination);
        schemaWriter.print(preambula);

        ClassDoc[] classes = root.classes();
        for (int i = 0; i < classes.length; ++i) {
            ClassDoc cd = classes[i];
            PrintWriter documentationWriter = null;
            if (getSuperClasses(cd).contains(Rule.class.getName())) {
                for (ConstructorDoc constructorDoc : cd.constructors()) {
                    if (constructorDoc.isPublic()) {
                        if (isMeantForXMLAccess(constructorDoc)) {
                            // dump APT doc
                            if (documentationWriter == null) {
                                // Create APT file and write the rule description
                                File file = new File("./../../../src/site/xdoc/rules." + cd.name() + ".xml");
                                documentationWriter = new PrintWriter(file);
                                log.info("Generating doc for rule " + file.getCanonicalPath());
                                printRuleDocStart(cd, documentationWriter);
                            }

                            // create XSD 

                            // check for the init() method
                            boolean initFound = false;
                            for (MethodDoc methodDoc : cd.methods()) {
                                if ("init".equals(methodDoc.name())) {
                                    if (methodDoc.parameters().length == 0) {
                                        initFound = true;
                                        break;
                                    }
                                }
                            }
                            if (!initFound) {
                                //                           throw new Exception("Method init() is required. Please make sure NOW that it is called in constructor " + cd.name());
                            }

                            printConstructorSchema(constructorDoc, schemaWriter);

                            if (documentationWriter != null) {
                                printConstructorDoc(constructorDoc, documentationWriter);
                            }
                        }
                    }
                }
            }

            if (documentationWriter != null) {
                printRuleDocEnd(documentationWriter);
            }
        }

        schemaWriter.print(appendix);
        schemaWriter.close();
        log.info("Saved to " + destination.getCanonicalPath());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return true;
}

From source file:com.zimbra.common.util.TemplateCompiler.java

private static void printEscaped(PrintWriter out, String s) {
    int length = s.length();
    for (int i = 0; i < length; i++) {
        char c = s.charAt(i);
        if (c == '"') {
            out.print('\\');
        } else if (c == '\n') {
            out.print("\\n");
            continue;
        } else if (c == '\r') {
            out.print("\\r");
            continue;
        } else if (c == '\t') {
            out.print("\\t");
            continue;
        } else if (c == '\\') {
            out.print("\\\\");
            continue;
        }//from w  w w .  jav  a  2  s.  co  m
        out.print(c);
    }
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void iniciarWSC(HttpServletRequest request, HttpServletResponse response) throws IOException {
    ArrayList<UsuarioEntity> usuarios = CtrlAdmin.iniciarWSC(Integer.parseInt(request.getParameter("1")), //id evento
            Integer.parseInt(request.getParameter("2")), //tamao tabla
            Integer.parseInt(request.getParameter("3"))//pagina
    ); // parameter 1: documentoDocente param2: idTaller

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();

    JSONArray list1 = new JSONArray();
    for (UsuarioEntity usuario : usuarios) {
        JSONObject obj = new JSONObject();
        obj.put("id", usuario.getIdUsuario());
        obj.put("titulo", usuario.getNombres() + " " + usuario.getApellidos());
        list1.add(obj);/*from   w ww  .j  ava2s.  c  om*/
    }
    out.print(list1);
}