Example usage for org.jdom2.output XMLOutputter XMLOutputter

List of usage examples for org.jdom2.output XMLOutputter XMLOutputter

Introduction

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

Prototype

public XMLOutputter(XMLOutputProcessor processor) 

Source Link

Document

This will create an XMLOutputter with the specified XMLOutputProcessor.

Usage

From source file:com.sun.syndication.io.WireFeedOutput.java

License:Open Source License

/**
 * Writes to an Writer the XML representation for the given WireFeed.
 * <p>/*from   w w  w .  java2s .c  om*/
 * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
 * of the developer to ensure the Writer instance is using the same charset encoding.
 * <p>
 * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
 * <p>
 * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
 *        the type given to the FeedOuptut constructor.
 * @param writer Writer to write the XML representation for the given WireFeed.
 * @param prettyPrint pretty-print XML (true) oder collapsed
 * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
 * @throws IOException thrown if there was some problem writing to the Writer.
 * @throws FeedException thrown if the XML representation for the feed could not be created.
 *
 */
public void output(WireFeed feed, Writer writer, boolean prettyPrint)
        throws IllegalArgumentException, IOException, FeedException {
    Document doc = outputJDom(feed);
    String encoding = feed.getEncoding();
    Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat();
    if (encoding != null) {
        format.setEncoding(encoding);
    }
    XMLOutputter outputter = new XMLOutputter(format);
    outputter.output(doc, writer);
}

From source file:com.thoughtworks.go.util.XmlUtils.java

License:Apache License

private static XMLOutputter xmlOutputer() {
    Format format = Format.getPrettyFormat().setEncoding("utf-8").setLineSeparator("\n");
    return new XMLOutputter(format);
}

From source file:com.xebialabs.overcast.support.libvirt.JDomUtil.java

License:Apache License

public static String documentToString(Document xml, Format format) throws IOException {
    StringWriter vsw = new StringWriter();
    XMLOutputter xout = new XMLOutputter(format);
    xout.output(xml, vsw);//from  w ww  . j  av a  2s .  c  o m
    return vsw.toString();
}

From source file:com.xebialabs.overcast.support.libvirt.JDomUtil.java

License:Apache License

public static String elementToString(Element element, Format format) throws IOException {
    StringWriter vsw = new StringWriter();
    XMLOutputter xout = new XMLOutputter(format);
    xout.output(element, vsw);//from w w w.  j av a 2 s . c  o m
    return vsw.toString();
}

From source file:Contabilidad.CodeBase64.java

public void limpia(String ruta) {
    try {//  w w  w .j  a v  a2 s. c om
        org.jdom2.Document doc = new SAXBuilder().build(ruta);
        Element rootNode = doc.getRootElement();
        List list = rootNode.getContent();
        for (int i = 0; i < list.size(); i++) {
            Content elementos = (Content) list.get(i);
            if (elementos.getCType() == Content.CType.Element) {
                Element aux = (Element) elementos;
                if (aux.getName().compareToIgnoreCase("Addenda") == 0) {
                    List list2 = aux.getContent();
                    for (int j = 0; j < list2.size(); j++) {
                        Content elementos2 = (Content) list2.get(j);
                        if (elementos2.getCType() == Content.CType.Element) {
                            Element aux2 = (Element) elementos2;
                            if (aux2.getName().compareToIgnoreCase("FactDocMX") == 0) {
                                list2.remove(aux2);
                            }
                            if (aux2.getName().compareToIgnoreCase("ECFD") == 0) {
                                Namespace NP = Namespace.getNamespace("", "");
                                aux2.setNamespace(NP);
                                List list3 = aux2.getContent();
                                for (int k = 0; k < list3.size(); k++) {
                                    Content elementos3 = (Content) list3.get(k);
                                    if (elementos3.getCType() == Content.CType.Element) {
                                        Element aux3 = (Element) elementos3;
                                        aux3.setNamespace(NP);
                                        List list4 = aux3.getContent();
                                        for (int l = 0; l < list4.size(); l++) {
                                            Content elementos4 = (Content) list4.get(l);
                                            if (elementos4.getCType() == Content.CType.Element) {
                                                Element aux4 = (Element) elementos4;
                                                aux4.setNamespace(NP);
                                                List list5 = aux4.getContent();
                                                for (int m = 0; m < list5.size(); m++) {
                                                    Content elementos5 = (Content) list5.get(m);
                                                    if (elementos5.getCType() == Content.CType.Element) {
                                                        Element aux5 = (Element) elementos5;
                                                        aux5.setNamespace(NP);
                                                        List list6 = aux5.getContent();
                                                        for (int n = 0; n < list6.size(); n++) {
                                                            Content elementos6 = (Content) list6.get(n);
                                                            if (elementos6
                                                                    .getCType() == Content.CType.Element) {
                                                                Element aux6 = (Element) elementos6;
                                                                aux6.setNamespace(NP);
                                                                List list7 = aux6.getContent();
                                                                for (int p = 0; p < list7.size(); p++) {
                                                                    Content elementos7 = (Content) list7.get(p);
                                                                    if (elementos7
                                                                            .getCType() == Content.CType.Element) {
                                                                        Element aux7 = (Element) elementos7;
                                                                        aux7.setNamespace(NP);
                                                                        List list8 = aux7.getContent();
                                                                        for (int q = 0; q < list8.size(); q++) {
                                                                            Content elementos8 = (Content) list8
                                                                                    .get(q);
                                                                            if (elementos8
                                                                                    .getCType() == Content.CType.Element) {
                                                                                Element aux8 = (Element) elementos8;
                                                                                aux8.setNamespace(NP);
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                List atributos = aux2.getAttributes();
                                for (int a = 0; a < atributos.size(); a++) {
                                    Attribute at = (Attribute) atributos.get(a);
                                    if (at.getName().compareToIgnoreCase("schemaLocation") == 0)
                                        aux2.removeAttribute(at);
                                }
                            }
                        }
                    }
                }
            }
        }
        XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
        try {
            outputter.output(doc, new FileOutputStream(ruta));
        } catch (IOException e) {
            System.out.println(e);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:cz.cesnet.shongo.connector.device.AdobeConnectConnector.java

@Override
public String exportRoomSettings(String roomId) throws CommandException {
    Element scoInfo = getScoInfo(roomId);
    Document document = scoInfo.getDocument();
    XMLOutputter xmlOutput = new XMLOutputter(Format.getPrettyFormat());
    return xmlOutput.outputString(document);
}

From source file:cz.cesnet.shongo.connector.device.AdobeConnectConnector.java

@Override
public void importRoomSettings(String roomId, String settings) throws CommandException {
    SAXBuilder saxBuilder = new SAXBuilder();
    Document document;//from   w  ww  . ja v a  2  s . c o m
    try {
        document = saxBuilder.build(new StringReader(settings));
    } catch (Exception exception) {
        throw new CommandException(exception.getMessage(), exception);
    }

    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
    String xmlString = outputter.outputString(document);

    RequestAttributeList attributes = new RequestAttributeList();

    attributes.add("sco-id", roomId);
    //        attributes.add("date-begin", document.getRootElement().getChild("sco").getChild("date-begin").getText());
    //        attributes.add("date-end", document.getRootElement().getChild("sco").getChild("date-end").getText());
    if (document.getRootElement().getChild("sco").getChild("description") != null) {
        attributes.add("description",
                document.getRootElement().getChild("sco").getChild("description").getText());
    }
    attributes.add("url-path", document.getRootElement().getChild("sco").getChild("url-path").getText());
    attributes.add("name", document.getRootElement().getChild("sco").getChild("name").getText());

    execApi("sco-update", attributes);
}

From source file:cz.pecina.retro.memory.Snapshot.java

License:Open Source License

/**
 * Writes a hardware shapshot to a file.
 *
 * @param file output file//w ww. j  ava  2s . co  m
 */
public void write(final File file) {
    log.fine("Writing snapshot to a file, file: " + file.getName());
    final Element snapshot = new Element("snapshot");
    final Namespace namespace = Namespace.getNamespace("xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
    snapshot.addNamespaceDeclaration(namespace);
    snapshot.setAttribute("noNamespaceSchemaLocation",
            Application.XSD_PREFIX + "snapshot-" + SNAPSHOT_XML_FILE_VERSION + ".xsd", namespace);
    snapshot.setAttribute("version", SNAPSHOT_XML_FILE_VERSION);
    hardware.marshal(snapshot);
    final Document doc = new Document(snapshot);
    try (final PrintWriter writer = new PrintWriter(file)) {
        new XMLOutputter(Format.getPrettyFormat()).output(doc, writer);
    } catch (final Exception exception) {
        log.fine("Error, writing failed, exception: " + exception.getMessage());
        throw Application.createError(this, "XMLWrite");
    }
    log.fine("Writing completed");
}

From source file:cz.pecina.retro.memory.XML.java

License:Open Source License

/**
 * Writes a memory range to a file, with wrap-around.
 *
 * @param file               output file
 * @param startAddress       starting address
 * @param number             number of bytes
 * @param destinationAddress destination address
 */// www.  ja  v a2 s  .  co  m
public void write(final File file, final int startAddress, final int number, final int destinationAddress) {
    log.fine(
            String.format("Writing XML data to a file, file: %s, start address: %04x," + " number of bytes: %d",
                    file.getName(), startAddress, number));
    final Element tag = new Element("memory");
    Snapshot.buildBlockElement(sourceMemory, tag, startAddress, number);
    final Namespace namespace = Namespace.getNamespace("xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
    tag.addNamespaceDeclaration(namespace);
    tag.setAttribute("noNamespaceSchemaLocation",
            Application.XSD_PREFIX + "memory-" + MEMORY_XML_FILE_VERSION + ".xsd", namespace);
    tag.setAttribute("version", MEMORY_XML_FILE_VERSION);
    tag.setAttribute("start", String.format("%04X", destinationAddress));
    final Document doc = new Document(tag);
    try (final PrintWriter writer = new PrintWriter(file)) {
        new XMLOutputter(Format.getPrettyFormat()).output(doc, writer);
    } catch (final Exception exception) {
        log.fine("Error, writing failed, exception: " + exception.getMessage());
        throw Application.createError(this, "XMLWrite");
    }
    log.fine("Writing completed");
}

From source file:cz.pecina.retro.trec.XML.java

License:Open Source License

/**
 * Writes the tape to an XML file.//w w w. j a  v  a2s .  com
 *
 * @param file output file
 */
public void write(final File file) {
    log.fine("Writing tape data to an XML file, file: " + file);
    final Element tag = new Element("tape");
    final Namespace namespace = Namespace.getNamespace("xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
    tag.addNamespaceDeclaration(namespace);
    tag.setAttribute("noNamespaceSchemaLocation",
            Application.XSD_PREFIX + "tape-" + TAPE_XML_FILE_VERSION + ".xsd", namespace);
    tag.setAttribute("version", TAPE_XML_FILE_VERSION);
    tag.setAttribute("rate", String.valueOf(tapeRecorderInterface.tapeSampleRate));
    tag.setAttribute("unit", "per sec");
    try {
        long currPos = -1;
        for (long start : tape.navigableKeySet()) {
            final long duration = tape.get(start);
            log.finest(String.format("Fetched: (%d, %d)", start, duration));
            if ((start > currPos) && (duration > 0)) {
                final Element pulse = new Element("pulse");
                pulse.setAttribute("start", String.valueOf(start));
                pulse.setAttribute("duration", String.valueOf(duration));
                tag.addContent(pulse);
                log.finest(String.format("Write: (%d, %d)", start, duration));
                currPos = start + duration;
            }
        }
    } catch (final Exception exception) {
        log.fine("Error, writing failed, exception: " + exception.getMessage());
        throw Application.createError(this, "XMLWrite");
    }
    final Document doc = new Document(tag);
    try (final PrintWriter writer = new PrintWriter(file)) {
        new XMLOutputter(Format.getPrettyFormat()).output(doc, writer);
    } catch (final Exception exception) {
        log.fine("Error, writing failed, exception: " + exception.getMessage());
        throw Application.createError(this, "XMLWrite");
    }
    log.fine("Writing completed");
}