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:Main.java

protected static void writeXMLwalkTree(Node node, int indent, PrintWriter out) {
    if (node == null)
        throw new NullPointerException("Null node passed to writeXMLwalkTree()");
    if (node.hasChildNodes()) {
        if (node instanceof Element) {
            Element elem = (Element) node;
            //elem.normalize();
            out.print("\n");
            for (int j = 0; j < indent; j++) {
                out.print(" ");
            }/*from ww w. j  a  v  a  2  s  . c om*/
            out.print("<" + elem.getTagName());
            NamedNodeMap attrs = elem.getAttributes();
            for (int i = 0; i < attrs.getLength(); i++) {
                Attr a = (Attr) attrs.item(i);
                out.print(" " + a.getName() + "=\"" + a.getValue() + "\"");
            }
            out.print(">");
            NodeList nl = node.getChildNodes();
            for (int i = 0; i < nl.getLength(); i++) {
                writeXMLwalkTree(nl.item(i), indent + 2, out);
            }
            //              for(int j=0;j<indent;j++) {
            //                  out.print(" ");
            //              }
            out.println("</" + elem.getTagName() + ">");
        }
    } else {
        if (node instanceof Element) {
            Element elem = (Element) node;
            out.print("\n");
            for (int j = 0; j < indent; j++) {
                out.print(" ");
            }
            out.print("<" + elem.getTagName());
            NamedNodeMap attrs = elem.getAttributes();
            for (int i = 0; i < attrs.getLength(); i++) {
                Attr a = (Attr) attrs.item(i);
                out.print(" " + a.getName() + "=\"" + a.getValue() + "\"");
            }
            out.println("/>");
        } else if (node instanceof CDATASection) {
            CDATASection cdata = (CDATASection) node;
            //              for(int j=0;j<indent;j++) {
            //                  out.print(" ");
            //              }
            out.print("<![CDATA[" + cdata.getData() + "]]>");
        } else if (node instanceof Text) {
            Text text = (Text) node;
            StringBuilder buf = new StringBuilder(text.getData().length());
            for (int i = 0; i < text.getData().length(); i++) {
                if (text.getData().charAt(i) == '\n' || text.getData().charAt(i) == '\r'
                        || text.getData().charAt(i) == ' ' || text.getData().charAt(i) == '\t') {
                    if (buf.length() > 0 && buf.charAt(buf.length() - 1) != ' ') {
                        buf.append(' ');
                    }
                } else {
                    buf.append(text.getData().charAt(i));
                }
            }
            if (buf.length() > 0 && !buf.toString().equals(" ")) {
                StringBuilder buf2 = new StringBuilder(buf.length() + indent);
                //                  for(int j=0;j<indent;j++) {
                //                      buf2.append(' ');
                //                  }
                buf2.append(buf.toString());
                out.print(buf2);
            }
        }
    }
}

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

protected static void isInscritoTaller(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    boolean b = CtrlUsuario.isInscritoTaller(Integer.parseInt(request.getParameter("1")),
            Integer.parseInt(request.getParameter("2")));
    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    JSONObject obj = new JSONObject();
    obj.put("is", b);
    out.print(obj);
}

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

protected static void isInscritoconvocatoria(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    boolean b = CtrlUsuario.isInscritoconvocatoria(Integer.parseInt(request.getParameter("1")),
            Integer.parseInt(request.getParameter("2")));
    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    JSONObject obj = new JSONObject();
    obj.put("is", b);
    out.print(obj);
}

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

protected static void obtenerTotalConvocatorias(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    int numC = CtrlUsuario.obtenerTotalConvocatorias();
    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    JSONObject obj = new JSONObject();
    obj.put("total", numC);
    out.print(obj);
}

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

protected static void obtenerTotalTalleres(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    int numC = CtrlUsuario.obtenerTotalTalleres();
    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    JSONObject obj = new JSONObject();
    obj.put("total", numC);
    out.print(obj);
}

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

protected static void obtenerInscritosConv(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    int numC = CtrlUsuario.obtenerInscritosConv(Integer.parseInt(request.getParameter("1")));
    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    JSONObject obj = new JSONObject();
    obj.put("inscritos", numC);
    out.print(obj);
}

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

protected static void obtenerInscritosTaller(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    int numC = CtrlUsuario.obtenerInscritosTaller(Integer.parseInt(request.getParameter("1")));
    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    JSONObject obj = new JSONObject();
    obj.put("inscritos", numC);
    out.print(obj);
}

From source file:org.sead.repositories.reference.util.SEADGoogleLogin.java

public static String getAccessToken() {
    try {//from  www.  j  a  v a 2  s.c o  m
        refresh_token = new String(Files.readAllBytes(Paths.get("refresh.txt")));
    } catch (IOException e1) {
    }
    if (refresh_token == null) {

        getAuthCode();

        // Ask user to login via browser
        System.out.println(
                "Did not find stored refresh token. Initiating first-time device authorization request.\n");
        System.out.println("1) Go to : " + verification_url + " in your browser\n");
        System.out.println("2) Type : " + user_code + " in your browser\n");
        System.out.println("3) Hit <Return> to continue.\n");
        try {
            System.in.read();
        } catch (IOException e) {
            log.debug("Error getting user response: " + e.getMessage());
        }

        System.out.println("Proceeding");
        getTokensFromCode();

        if (refresh_token != null) {
            PrintWriter writer = null;
            try {
                writer = new PrintWriter("refresh.txt", "UTF-8");
                writer.print(refresh_token);

            } catch (FileNotFoundException e) {
                log.error("Could not write refresh.txt: " + e.getMessage());
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } finally {
                if (writer != null) {
                    writer.close();
                }
            }

        }
    } else {
        getTokenFromRefreshToken();
    }
    return access_token;

}

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

private static void printStringLine(PrintWriter out, String... ss) {
    out.print("\tbuffer[_i++] = \"");
    for (String s : ss) {
        printEscaped(out, s);/*  www . j  av a 2 s  .co m*/
    }
    out.println("\";");
}

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

private static void printBufferLine(PrintWriter out, String... ss) {
    out.print("\tbuffer[_i++] = ");
    for (String s : ss) {
        out.print(s);//w w  w  .j a  v  a  2 s . c  om
    }
    out.println(";");
}