Example usage for org.jdom2.output Format setTextMode

List of usage examples for org.jdom2.output Format setTextMode

Introduction

In this page you can find the example usage for org.jdom2.output Format setTextMode.

Prototype

public Format setTextMode(Format.TextMode mode) 

Source Link

Document

This sets the text output style.

Usage

From source file:com.medvision360.medrecord.basex.AbstractXmlConverter.java

License:Creative Commons License

protected void outputDocument(Document d, OutputStream os, String encoding) throws IOException {
    Format format = Format.getPrettyFormat();
    format.setTextMode(Format.TextMode.PRESERVE); // this is the default, set just to be very safe
    format.setEncoding(encoding);/*from w w w .j a v a2 s .c om*/
    XMLOutputter output = new XMLOutputter(format);
    output.output(d, os);
}

From source file:com.novell.ldapchai.cr.ChaiResponseSet.java

License:Open Source License

static String rsToChaiXML(final ChaiResponseSet rs) throws ChaiValidationException, ChaiOperationException {
    final Element rootElement = new Element(XML_NODE_ROOT);
    rootElement.setAttribute(XML_ATTRIBUTE_MIN_RANDOM_REQUIRED,
            String.valueOf(rs.getChallengeSet().getMinRandomRequired()));
    rootElement.setAttribute(XML_ATTRIBUTE_LOCALE, rs.getChallengeSet().getLocale().toString());
    rootElement.setAttribute(XML_ATTRIBUTE_VERSION, VALUE_VERSION);
    rootElement.setAttribute(XML_ATTRIBUTE_CHAI_VERSION, ChaiConstant.CHAI_API_VERSION);

    if (rs.caseInsensitive) {
        rootElement.setAttribute(XML_ATTRIBUTE_CASE_INSENSITIVE, "true");
    }//from  w ww . j ava  2 s. c  o  m

    if (rs.csIdentifier != null) {
        rootElement.setAttribute(XML_ATTRIBUTE_CHALLENGE_SET_IDENTIFER, rs.csIdentifier);
    }

    if (rs.timestamp != null) {
        rootElement.setAttribute(XML_ATTRIBUTE_TIMESTAMP, DATE_FORMATTER.format(rs.timestamp));
    }

    if (rs.crMap != null) {
        for (final Challenge loopChallenge : rs.crMap.keySet()) {
            final Answer answer = rs.crMap.get(loopChallenge);
            final Element responseElement = challengeToXml(loopChallenge, answer, XML_NODE_RESPONSE);
            rootElement.addContent(responseElement);
        }
    }

    if (rs.helpdeskCrMap != null) {
        for (final Challenge loopChallenge : rs.helpdeskCrMap.keySet()) {
            final Answer answer = rs.helpdeskCrMap.get(loopChallenge);
            final Element responseElement = challengeToXml(loopChallenge, answer, XML_NODE_HELPDESK_RESPONSE);
            rootElement.addContent(responseElement);
        }
    }

    final Document doc = new Document(rootElement);
    final XMLOutputter outputter = new XMLOutputter();
    final Format format = Format.getRawFormat();
    format.setTextMode(Format.TextMode.PRESERVE);
    format.setLineSeparator("");
    outputter.setFormat(format);
    return outputter.outputString(doc);
}

From source file:com.novell.ldapchai.impl.edir.NmasResponseSet.java

License:Open Source License

static String csToNmasXML(final ChallengeSet cs, final String guidValue) {
    final Element rootElement = new Element(NMAS_XML_ROOTNODE);
    rootElement.setAttribute(NMAS_XML_ATTR_RANDOM_COUNT, String.valueOf(cs.getMinRandomRequired()));
    if (guidValue != null) {
        rootElement.setAttribute("GUID", guidValue);
    } else {/*w  w w  . j a v a  2 s.  co m*/
        rootElement.setAttribute("GUID", "0");
    }

    for (final Challenge challenge : cs.getChallenges()) {
        final Element loopElement = new Element(NMAS_XML_NODE_CHALLENGE);
        if (challenge.getChallengeText() != null) {
            loopElement.setText(challenge.getChallengeText());
        }

        if (challenge.isAdminDefined()) {
            loopElement.setAttribute(NMAS_XML_ATTR_DEFINE, "Admin");
        } else {
            loopElement.setAttribute(NMAS_XML_ATTR_DEFINE, "User");
        }

        if (challenge.isRequired()) {
            loopElement.setAttribute(NMAS_XML_ATTR_TYPE, "Required");
        } else {
            loopElement.setAttribute(NMAS_XML_ATTR_TYPE, "Random");
        }

        loopElement.setAttribute(NMAS_XML_ATTR_MIN_LENGTH, String.valueOf(challenge.getMinLength()));
        loopElement.setAttribute(NMAS_XML_ATTR_MAX_LENGTH, String.valueOf(challenge.getMaxLength()));

        rootElement.addContent(loopElement);
    }

    final XMLOutputter outputter = new XMLOutputter();
    final Format format = Format.getRawFormat();
    format.setTextMode(Format.TextMode.PRESERVE);
    format.setLineSeparator("");
    outputter.setFormat(format);
    return outputter.outputString(rootElement);
}

From source file:XMLWriter.WriteCodesXML.java

License:Open Source License

public static void writeCode(Code code, String xmlSource) {
    try {/*w  ww .j  ava2  s  .  co m*/
        Document doc = builder.build(xmlSource);
        Element rootNode = doc.getRootElement();
        Element codigo = new Element("codigo", ns);
        codigo.setAttribute("id", code.getID());

        for (Element e : rootNode.getChildren("codigo", ns))
            if (e.getAttributeValue("id").equals(code.getID())) {
                rootNode.removeContent(e);
                break;
            }

        Element idProf = new Element("idProfesor", ns);
        idProf.setText(code.getIDProfesor());
        Element nombre = new Element("nombre", ns);
        nombre.setText(code.getNombre());
        Element lenguaje = new Element("lenguaje", ns);
        lenguaje.setText(code.getLenguaje());
        Element resaltar = new Element("resaltar", ns);
        resaltar.setText(code.getResaltar());
        List<Element> lineas = new ArrayList<Element>();
        for (String l : code.getLineas()) {
            Element linea = new Element("linea", ns);
            linea.setText(l);
            lineas.add(linea);
        }
        List<Element> comentarios = new ArrayList<Element>();
        if (code.getIDComentarios().size() > 0) {
            for (String c : code.getIDComentarios()) {
                Element comentario = new Element("idComentario", ns);
                comentario.setText(c);
                comentarios.add(comentario);
            }
        }

        codigo.addContent(idProf);
        codigo.addContent(nombre);
        codigo.addContent(lenguaje);
        codigo.addContent(resaltar);
        codigo.addContent(lineas);
        if (comentarios.size() > 0)
            codigo.addContent(comentarios);

        rootNode.addContent(codigo);

        Format form = Format.getPrettyFormat().clone();
        form.setTextMode(Format.TextMode.TRIM_FULL_WHITE);
        XMLOutputter xmlOut = new XMLOutputter(form);
        FileOutputStream file = new FileOutputStream(xmlSource);
        xmlOut.output(doc, file);
        file.close();
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }
}

From source file:XMLWriter.WriteCodesXML.java

License:Open Source License

public static boolean deleteCode(Code code, String xmlSource) {
    try {/*  w w  w .  j a  va  2  s.  c  om*/
        Document doc = builder.build(xmlSource);
        Element rootNode = doc.getRootElement();
        boolean find = false;

        for (Element e : rootNode.getChildren("codigo", ns))
            if (e.getAttributeValue("id").equals(code.getID())) {
                find = rootNode.removeContent(e);
                break;
            }
        if (!find)
            return false;

        Format form = Format.getPrettyFormat().clone();
        form.setTextMode(Format.TextMode.TRIM_FULL_WHITE);
        XMLOutputter xmlOut = new XMLOutputter(form);
        FileOutputStream file = new FileOutputStream(xmlSource);
        xmlOut.output(doc, file);
        file.close();
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }
    return true;
}

From source file:XMLWriter.WriteCodesXML.java

License:Open Source License

public static boolean addComment(String idCode, String idComment, String xmlSource) {
    try {//from  ww  w .  j a  v a2 s.c om
        Document doc = builder.build(xmlSource);
        Element rootNode = doc.getRootElement();
        boolean find = false;

        for (Element e : rootNode.getChildren("codigo", ns))
            if (e.getAttributeValue("id").equals(idCode)) {
                find = true;
                Element idComentario = new Element("idComentario", ns);
                idComentario.setText(idComment);
                e.addContent(idComentario);
                break;
            }
        if (!find)
            return false;

        Format form = Format.getPrettyFormat().clone();
        form.setTextMode(Format.TextMode.TRIM_FULL_WHITE);
        XMLOutputter xmlOut = new XMLOutputter(form);
        FileOutputStream file = new FileOutputStream(xmlSource);
        xmlOut.output(doc, file);
        file.close();
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }
    return true;
}

From source file:XMLWriter.WriteCommentsXML.java

License:Open Source License

public static boolean addComment(Comment com, String xmlSource) {
    try {//w  w  w.j  a v a 2  s . com
        Document doc = builder.build(xmlSource);
        Element rootNode = doc.getRootElement();
        Element comentario = new Element("comentario", ns);
        comentario.setAttribute("id", com.getID());

        Element idUsuario = new Element("idUsuario", ns);
        idUsuario.setText(com.getIDUsuario());
        Element texto = new Element("texto", ns);
        texto.setText("\n            " + com.getTexto().replace("\n", "\n            ") + "\n        ");
        Element calificacion = new Element("calificacion", ns);
        calificacion.setText(com.getCalificacion().toString());
        Element fechaMod = new Element("fechaMod", ns);
        fechaMod.setText(com.getFechaMod());

        comentario.addContent(idUsuario);
        comentario.addContent(texto);
        comentario.addContent(calificacion);
        comentario.addContent(fechaMod);

        rootNode.addContent(comentario);

        Format form = Format.getPrettyFormat().clone();
        form.setTextMode(Format.TextMode.TRIM_FULL_WHITE);
        XMLOutputter xmlOut = new XMLOutputter(form);
        FileOutputStream file = new FileOutputStream(xmlSource);
        xmlOut.output(doc, file);
        file.close();
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }

    return true;
}

From source file:XMLWriter.WriteCommentsXML.java

License:Open Source License

public static boolean rateComment(String id, Integer calif, String xmlSource) {
    try {/*from   w  w w.ja  va 2  s  .  c om*/
        Document doc = builder.build(xmlSource);
        Element rootNode = doc.getRootElement();
        List<Element> lista = rootNode.getChildren("comentario", ns);
        boolean find = false;

        for (Element e : lista) {
            if (e.getAttributeValue("id").equals(id)) {
                find = true;
                e.getChild("calificacion", ns).setText(calif.toString());
                break;
            }
        }
        if (!find)
            return false;

        Format form = Format.getPrettyFormat().clone();
        form.setTextMode(Format.TextMode.TRIM_FULL_WHITE);
        XMLOutputter xmlOut = new XMLOutputter(form);
        FileOutputStream file = new FileOutputStream(xmlSource);
        xmlOut.output(doc, file);
        file.close();
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }

    return true;
}

From source file:XMLWriter.WriteCommentsXML.java

License:Open Source License

public static boolean removeComments(List<String> idComments, String xmlSource) {
    if (idComments.isEmpty())
        return true;

    try {//from  w  w  w . ja  v a2s  .c  om
        Document doc = builder.build(xmlSource);
        Element rootNode = doc.getRootElement();
        List<Element> lista = rootNode.getChildren("comentario", ns);
        List<Element> rem = new ArrayList<Element>();
        boolean find = false, error = false;

        for (Element e : lista) {
            if (idComments.contains(e.getAttributeValue("id"))) {
                find = true;
                rem.add(e);
            }
        }
        for (Element e : rem) {
            error = (error || !rootNode.removeContent(e));
        }
        if (!find || error)
            return false;

        Format form = Format.getPrettyFormat().clone();
        form.setTextMode(Format.TextMode.TRIM_FULL_WHITE);
        XMLOutputter xmlOut = new XMLOutputter(form);
        FileOutputStream file = new FileOutputStream(xmlSource);
        xmlOut.output(doc, file);
        file.close();
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }

    return true;
}

From source file:XMLWriter.WriteCommentsXML.java

License:Open Source License

public static boolean removeComments(String idUser, List<String> idComments, String xmlSource) {
    try {/*from ww  w . j a v  a 2  s  .  c o m*/
        Document doc = builder.build(xmlSource);
        Element rootNode = doc.getRootElement();
        List<Element> lista = rootNode.getChildren("comentario", ns);
        boolean error = false;

        for (Element e : lista)
            if (e.getChildTextTrim("idUsuario", ns).equals(idUser)
                    && idComments.contains(e.getAttributeValue("id")))
                error = (error || !rootNode.removeContent(e));
        if (error)
            return false;

        Format form = Format.getPrettyFormat().clone();
        form.setTextMode(Format.TextMode.TRIM_FULL_WHITE);
        XMLOutputter xmlOut = new XMLOutputter(form);
        FileOutputStream file = new FileOutputStream(xmlSource);
        xmlOut.output(doc, file);
        file.close();
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }

    return true;
}