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() 

Source Link

Document

This will create an XMLOutputter with a default Format and XMLOutputProcessor .

Usage

From source file:information.Information.java

License:Open Source License

public static void generarXML() {
    Document documento;/* www . j a va2 s  .  c om*/
    Element raiz = new Element("Salones");
    documento = new Document(raiz);
    for (Salon salon : salons) {
        Element salone = new Element("Salon");
        salone.setAttribute("Nombre", salon.getName());
        for (Room sala : salon.getRooms()) {
            Element salae = new Element("Sala");
            salae.setAttribute("Nombre", sala.getName());
            salae.setAttribute("Horizontal", Boolean.toString(sala.isHorizontal()));
            salae.addContent(new Element("SufijoIP").setText(Integer.toString(sala.getRoomIPSufix())));
            for (Row fila : sala.getRows()) {
                Element filae = new Element("Fila");
                for (ServerComputer equipo : fila.getComputers()) {
                    Element equipoe = new Element("Equipo");
                    equipoe.setAttribute("Numero", Integer.toString(equipo.getComputerNumber()));
                    equipoe.addContent(new Element("IP").setText(equipo.getIP()));
                    equipoe.addContent(new Element("Mac").setText(equipo.getMac()));
                    equipoe.addContent(new Element("Hostname").setText(equipo.getHostname()));
                    for (String[] resultados : equipo.getResults()) {
                        String orden = resultados[0];
                        String resultado = resultados[1];
                        Element resultadoe = new Element("Ejecucion");
                        resultadoe.addContent(new Element("Orden").setText(orden));
                        resultadoe.addContent(new Element("Resultado").setText(resultado));
                        equipoe.addContent(resultadoe);
                    }
                    filae.addContent(equipoe);
                }
                salae.addContent(filae);
            }
            salone.addContent(salae);
        }
        raiz.addContent(salone);
    }

    XMLOutputter xmlOutput = new XMLOutputter();
    try {
        xmlOutput.output(documento, System.out);
        xmlOutput.setFormat(Format.getPrettyFormat());
        xmlOutput.output(documento, new FileWriter(informationPath));
    } catch (IOException ex) {
        Logger.getLogger(Information.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:interfacermi.Traza.java

public void insertarTraza(String hora, String actor, String accion) {

    Document document = null;//from w  ww .  j a v a  2  s .co m
    Element root = null;
    File xmlFile = new File("Traza.xml");
    //Se comprueba si el archivo XML ya existe o no.
    if (xmlFile.exists()) {
        FileInputStream fis;
        try {
            fis = new FileInputStream(xmlFile);
            SAXBuilder sb = new SAXBuilder();
            document = sb.build(fis);
            //Si existe se obtiene su nodo raiz.
            root = document.getRootElement();
            fis.close();
        } catch (JDOMException | IOException e) {
            e.printStackTrace();
        }
    } else {
        //Si no existe se crea su nodo raz.
        document = new Document();
        root = new Element("Traza");
    }

    //Se crea un nodo Hecho para insertar la informacin.
    Element nodohecho = new Element("Hecho");
    //Se crea un nodo hora para insertar la informacin correspondiente a la hora.
    Element nodohora = new Element("Hora");
    //Se crea un nodo actor para insertar la informacin correspondiente al actor.
    Element nodoactor = new Element("Actor");
    //Se crea un nodo accion para insertar la informacin correspondiente a la accin.
    Element nodoaccion = new Element("Accion");

    //Se asignan los valores enviados para cada nodo.
    nodohora.setText(hora);
    nodoactor.setText(actor);
    nodoaccion.setText(accion);
    //Se aade el contenido al nodo Hecho.  
    nodohecho.addContent(nodohora);
    nodohecho.addContent(nodoactor);
    nodohecho.addContent(nodoaccion);
    //Se aade el nodo Hecho al nodo raz.
    root.addContent(nodohecho);
    document.setContent(root);

    //Se procede a exportar el nuevo o actualizado archivo de traza XML   
    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());

    try {
        xmlOutput.output(document, new FileWriter("Traza.xml"));
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:io.wcm.handler.commons.dom.AbstractElement.java

License:Apache License

@Override
public String toString() {
    return new XMLOutputter().outputString(this);
}

From source file:io.wcm.handler.commons.dom.AbstractElement.java

License:Apache License

/**
 * @return Content of element serialized as string
 *//*  w ww.  j a v  a  2s .c  o m*/
public String toStringContentOnly() {
    return new XMLOutputter().outputElementContentString(this);
}

From source file:it.intecs.pisa.openCatalogue.solr.ingester.BaseIngester.java

private FileFilesystem storeMetadata(org.jdom2.Document metadata, boolean isValid) throws IOException {
    if (metadataRepository != null) {
        XPathExpression<Element> xpath = XPathFactory.instance().compile(idXPath, Filters.element());

        String key = xpath.evaluateFirst(metadata.getRootElement()).getTextTrim().replace(":", "_").replace(".",
                "_");
        FileFilesystem fs = null;//from   ww w  .  j  a  v a2s  .c  o  m
        if (isValid) {
            fs = new FileFilesystem(metadataRepository.getAbsolutePath() + "/" + key + ".xml");
        } else {
            fs = new FileFilesystem(metadataRepository.getAbsolutePath() + "/" + key + ".notValid.xml");
        }
        XMLOutputter outputter = new XMLOutputter();
        String metadataString = outputter.outputString(metadata);
        byte[] b = metadataString.getBytes();
        fs.getOutputStream().write(b);
        return fs;
    } else {
        return null;
    }
}

From source file:it.intecs.pisa.openCatalogue.solr.ingester.BaseIngester.java

private boolean validateMetadata(Document metadata) {
    if (schemaRoot != null && schemaFile != null) {
        try {/* w  w w  . j a  v a 2 s  .co  m*/
            XMLOutputter outputter = new XMLOutputter();
            String metadataString = outputter.outputString(metadata);
            byte[] b = metadataString.getBytes();
            return SchemasUtil.SAXvalidate(new ByteArrayInputStream(b), schemaFile, schemaRoot, schemaCache);
        } catch (Exception e) {
            return false;
        }
    } else {
        return true;
    }
}

From source file:it.isislab.floasys.core.security.users.UserAccountXMLParser.java

License:Open Source License

/**
 * Write another account to the XML file.
 * @param is/*  w  w w . ja v a  2s  .  c  o  m*/
 * @param os
 * @param account
 * @throws CannotParseException
 */
public void write(InputStream is, OutputStream os, UserAccount account) throws CannotParseException {
    try {
        //Read the existing file.
        Document doc = new SAXBuilder().build(is);
        Element rootNode = doc.getRootElement();

        //Create a new user element.
        Element elAccount = new Element(EL_USERACCOUNT);
        Element elUsername = new Element(EL_USERNAME);
        Element elPassword = new Element(EL_PASSWORD);
        Element elActivationCode = new Element(EL_ACTIVATIONCODE);
        Element elActivated = new Element(EL_ACTIVATED);

        elAccount.addContent(elUsername);
        elAccount.addContent(elPassword);
        elAccount.addContent(elActivationCode);
        elAccount.addContent(elActivated);

        //Add the account to the root element.
        rootNode.addContent(elAccount);

        //Set the root for document.
        doc.setContent(rootNode);

        //Write the file content.
        XMLOutputter outputter = new XMLOutputter();
        outputter.setFormat(Format.getPrettyFormat());
        outputter.output(doc, os);
    } catch (Exception ex) {
        throw new CannotParseException(ex);
    }
}

From source file:jmap2gml.GMX.java

/**
 * Generates xml formatted room file that can be read by GMS. Uses
 * external xml file as a references and adds instances for each item.
 *
 * @param items array of items from preview
 * @param os stream to write xml string to
 */// ww  w  .  ja v a2  s.c  o m
public static void itemsToGMX(Item[] items, OutputStream os) {
    String prefix = String.format("inst_%d", System.currentTimeMillis());

    SAXBuilder saxBuilder = new SAXBuilder();
    int count = 0;

    try {
        Element room = saxBuilder.build(new File("template.xml")).getRootElement();
        Element instances = room.getChild("instances");

        for (Item item : items) {
            if (item != null) {
                instances.addContent(new Element("instance").setAttribute("objName", item.itemName)
                        .setAttribute("x", Integer.toString(item.x)).setAttribute("y", Integer.toString(item.y))
                        .setAttribute("name", String.format("%s%d", prefix, count++))
                        .setAttribute("locked", "0").setAttribute("code", item.creationCode)
                        .setAttribute("scaleX", Double.toString(item.xScale))
                        .setAttribute("scaleY", Double.toString(item.yScale))
                        .setAttribute("colour", "4294967295").setAttribute("rotation", "0"));
                instances.addContent("\n");
            }
        }

        XMLOutputter out = new XMLOutputter();
        out.output(room, os);

    } catch (JDOMException | IOException ex) {
    }
}

From source file:jmri.jmrit.vsdecoder.StoreXmlVSDecoderAction.java

License:Open Source License

public void saveVSDecoderProfile(java.io.File f) {

    try {//from  ww  w. j a  v  a2 s  . c  o  m
        Element root = new Element("VSDecoderConfig");
        Document doc = XmlFile.newDocument(root, XmlFile.dtdLocation + "vsdecoder-config.dtd");

        // add XSLT processing instruction
        // <?xml-stylesheet type="text/xsl" href="XSLT/throttle-layout-config.xsl"?>
        /*TODO         java.util.Map<String,String> m = new java.util.HashMap<String,String>();
              m.put("type", "text/xsl");
              m.put("href", jmri.jmrit.XmlFile.xsltLocation + "throttle-layout-config.xsl");
              ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
              doc.addContent(0, p); */
        java.util.ArrayList<Element> children = new java.util.ArrayList<Element>(5);

        for (java.util.Iterator<VSDecoder> i = VSDecoderManager.instance().getVSDecoderList().iterator(); i
                .hasNext();) {
            VSDecoder vsd = i.next();
            children.add(vsd.getXml());
        }

        // Throttle-specific stuff below.  Kept for reference
        /*
              // throttle list window
              children.add(ThrottleFrameManager.instance().getThrottlesListPanel().getXml() );
                
              // throttle windows
              for (Iterator<ThrottleWindow> i = ThrottleFrameManager.instance().getThrottleWindows(); i.hasNext();) {
              ThrottleWindow tw = i.next();
              Element throttleElement = tw.getXml();
              children.add(throttleElement);
              }
              */
        // End Throttle-specific stuff.
        root.setContent(children);

        FileOutputStream o = new java.io.FileOutputStream(f);
        try {
            XMLOutputter fmt = new XMLOutputter();
            fmt.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator"))
                    .setTextMode(Format.TextMode.PRESERVE));
            fmt.output(doc, o);
        } catch (IOException ex) {
            log.warn("Exception in storing VSDecoder xml: " + ex);
        } finally {
            o.close();
        }
    } catch (FileNotFoundException ex) {
        log.warn("Exception in storing VSDecoder xml: " + ex);
    } catch (IOException ex) {
        log.warn("Exception in storing VSDecoder xml: " + ex);
    }
}

From source file:json.JSONConverter.java

License:Apache License

@Override
public final String toString() {
    XMLOutputter sortie = new XMLOutputter();
    return sortie.outputString(document);
}