Example usage for org.jdom2 Element setAttribute

List of usage examples for org.jdom2 Element setAttribute

Introduction

In this page you can find the example usage for org.jdom2 Element setAttribute.

Prototype

public Element setAttribute(final String name, final String value) 

Source Link

Document

This sets an attribute value for this element.

Usage

From source file:core.ListComponenXml.java

@Override
public void updateFile() {
    try {//from   ww  w.  j  a  v  a  2s . c o  m
        Element root = new Element("listado");
        Document document = new Document();
        for (Xml xml : this.getXmls()) {
            Element autor = new Element("autor");
            autor.addContent(new Element("nombre").setText(xml.getAutor().getNombre()));
            autor.addContent(new Element("descripcion").setText(xml.getAutor().getDescripcion()));
            autor.addContent(new Element("version").setText(xml.getAutor().getVersion()));
            Element cuerpo = new Element("cuerpo");
            Element tipo = new Element("tipo");
            Element status = new Element("status");
            tipo.setAttribute("columnas", "" + xml.getCuerpo().getColumnas());
            tipo.setAttribute("tipodatocolumna", String.join(",", xml.getCuerpo().getTipo_datos()));
            cuerpo.addContent(tipo);
            tipo.addContent(new Element("claseprincipal").setText(xml.getCuerpo().getMain()));
            status.setAttribute("active", String.valueOf(xml.getStatus().getActive()));
            Element parametro = new Element("parametro");
            for (String dato : xml.getCuerpo().getParametros()) {
                parametro.addContent(new Element(dato));
            }
            cuerpo.addContent(parametro);
            Element pluguin = new Element("pluguin");
            pluguin.addContent(autor);
            pluguin.addContent(cuerpo);
            pluguin.addContent(status);
            root.addContent(pluguin);
        }
        ;
        document.setRootElement(root);
        XMLOutputter outter = new XMLOutputter();
        outter.setFormat(Format.getPrettyFormat());
        String basePath = new File("").getAbsolutePath();
        String ruta = basePath + "/src/configuracion/xml_configuracion.xml";
        if (System.getProperty("os.name").toLowerCase().contains("windows")) {
            ruta = basePath + "\\src\\configuracion\\xml_configuracion.xml";
        }
        outter.output(document, new FileWriter(new File(ruta)));
    } catch (IOException ex) {
        Logger.getLogger(ListComponenXml.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:core.WriteComponenXml.java

@Override
public void writeFile(String ruta, Xml xml) {
    FileWriter writer = null;//www. j a  v  a  2  s .c om
    try {
        ValidXml vxml = new ValidXml();
        System.out.println(vxml.exisFile(ruta));
        System.out.println(vxml.validExtencion(ruta));
        if (vxml.exisFile(ruta) && vxml.validExtencion(ruta)) {
            loadingFile(ruta);
            try {
                FileInputStream fis = new FileInputStream(this.getFile());
                setDocument(this.getBuilder().build(fis));
                this.setRootNode(getDocument().detachRootElement());
            } catch (FileNotFoundException ex) {
                Logger.getLogger(WriteComponenXml.class.getName()).log(Level.SEVERE, null, ex);
            } catch (JDOMException ex) {
                Logger.getLogger(WriteComponenXml.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(WriteComponenXml.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            String basePath = new File("").getAbsolutePath();
            ruta = basePath + "/src/configuracion/xml_configuracion.xml";
            if (System.getProperty("os.name").toLowerCase().contains("windows")) {
                ruta = basePath + "\\src\\configuracion\\xml_configuracion.xml";
            }
            Element root = new Element("listado");
            Document doc = new Document();
            doc.setRootElement(root);
            XMLOutputter outter = new XMLOutputter();
            outter.setFormat(Format.getPrettyFormat());
            this.setFile(new File(ruta));
            outter.output(doc, new FileWriter(this.getFile()));
            FileInputStream fis = new FileInputStream(this.getFile());
            setDocument(this.getBuilder().build(this.getFile()));
            this.setRootNode(getDocument().detachRootElement());
            this.setDocument(new Document());
            this.setRootNode(new Element("listado"));
        }
        Element autor = new Element("autor");
        System.out.println("  " + this.getDocument() + "   " + this.getRootNode());
        autor.addContent(new Element("nombre").setText(xml.getAutor().getNombre()));
        autor.addContent(new Element("descripcion").setText(xml.getAutor().getDescripcion()));
        autor.addContent(new Element("version").setText(xml.getAutor().getVersion()));
        Element cuerpo = new Element("cuerpo");
        Element tipo = new Element("tipo");
        Element status = new Element("status");
        tipo.setAttribute("columnas", "" + xml.getCuerpo().getColumnas());
        tipo.setAttribute("tipodatocolumna", String.join(",", xml.getCuerpo().getTipo_datos()));
        cuerpo.addContent(tipo);
        tipo.addContent(new Element("claseprincipal").setText(xml.getCuerpo().getMain()));
        status.setAttribute("active", String.valueOf(xml.getStatus().getActive()));
        Element parametro = new Element("parametro");
        for (String dato : xml.getCuerpo().getParametros()) {
            parametro.addContent(new Element(dato));
        }
        cuerpo.addContent(parametro);
        Element pluguin = new Element("pluguin");
        pluguin.addContent(autor);
        pluguin.addContent(cuerpo);
        pluguin.addContent(status);
        this.getRootNode().addContent(pluguin);
        this.getDocument().setContent(this.getRootNode());
        writer = new FileWriter(ruta);
        XMLOutputter outputter = new XMLOutputter();
        outputter.setFormat(Format.getPrettyFormat());
        outputter.output(this.getDocument(), writer);
        outputter.output(this.getDocument(), System.out);
        writer.close(); // close writer
    } catch (IOException ex) {
        Logger.getLogger(WriteComponenXml.class.getName()).log(Level.SEVERE, null, ex);
    } catch (JDOMException ex) {
        Logger.getLogger(WriteComponenXml.class.getName()).log(Level.SEVERE, null, ex);
    } finally {

    }
}

From source file:cz.lbenda.dataman.db.ExportTableData.java

License:Apache License

/** Write rows from sql query to output stream
 * @param sqlQueryRows rows//ww w .jav  a  2 s  .  com
 * @param outputStream stream to which are data write */
public static void writeSqlQueryRowsToXMLv2(SQLQueryRows sqlQueryRows, OutputStream outputStream)
        throws IOException {
    Element root = new Element("export");
    root.setAttribute("sql", sqlQueryRows.getSQL());
    root.setAttribute("version", "2");
    List<Element> rows = new ArrayList<>(sqlQueryRows.getRows().size());

    sqlQueryRows.getRows().forEach(rowDesc -> {
        Element row = new Element("row");
        List<Element> cols = new ArrayList<>(sqlQueryRows.getMetaData().getColumns().size());
        sqlQueryRows.getMetaData().getColumns().forEach(columnDesc -> {
            Element element = new Element(columnDesc.getName());
            if (rowDesc.isColumnNull(columnDesc)) {
                element.setAttribute("null", "true");
            } else {
                element.setText(rowDesc.getColumnValueStr(columnDesc));
            }
            cols.add(element);
        });
        row.addContent(cols);
        rows.add(row);
    });
    root.addContent(rows);
    XMLOutputter xmlOutputter = new XMLOutputter();
    xmlOutputter.output(new Document(root), outputStream);
}

From source file:cz.lbenda.dbapp.rc.db.ComboBoxTDExtension.java

License:Apache License

@Override
public final Element storeToElement() {
    Element res = new Element("selectBox");
    res.setAttribute("column", columnName).setAttribute("tableOfKeySQL", tableOfKeySQL)
            .setAttribute("column_value", columnValue).setAttribute("column_choice", columnChoice)
            .setAttribute("column_tooltip", columnTooltip);
    return res;//from w  w w . j  av a  2s  .  com
}

From source file:cz.lbenda.dbapp.rc.SessionConfiguration.java

License:Apache License

public final Element storeToElement() {
    Element ses = new Element("session");
    ses.setAttribute("id", getId());
    if (this.connectionTimeout > 0) {
        ses.addContent(new Element("connectionTimeout").setText(Integer.toString(this.connectionTimeout)));
    }//from   www. j a v a  2  s .  c o m
    if (jdbcConfiguration != null) {
        ses.addContent(jdbcConfiguration.storeToElement());
    }
    Element ed = new Element("extendedDescription");
    ed.setAttribute("type", this.getExtendedConfigurationType().name());
    ed.setText(this.getExtendedConfigurationPath());
    ses.addContent(ed);
    if (!librariesPaths.isEmpty()) {
        Element libs = new Element("libraries");
        for (String path : getLibrariesPaths()) {
            Element lib = new Element("library");
            lib.setText(path);
            libs.addContent(lib);
        }
        ses.addContent(libs);
    }
    return ses;
}

From source file:cz.muni.fi.pb138.scxml2voicexmlj.voicexml.ConditionalTransitionsAssembler.java

private void appendExpr(Element cond, String name, String event) {
    cond.setAttribute("expr", name + "=='" + event + "'");
}

From source file:cz.muni.fi.pb138.scxml2voicexmlj.voicexml.ConditionalTransitionsAssembler.java

private Element createClear(List<String> targets) {
    StringBuilder joinedTargets = new StringBuilder();
    for (int i = 0; i < targets.size(); i++) {
        if (i != 0) {
            joinedTargets.append(" ");
        }/*from  ww w  .j a  v a  2  s  . c  o  m*/
        joinedTargets.append(targets.get(i));
    }
    Element clear = new Element("clear", NS_VXML);// parent.createElementNS("http://www.w3.or/2001/vxml", "clear");
    clear.setAttribute("namelist", joinedTargets.toString());
    return clear;
}

From source file:cz.muni.fi.pb138.scxml2voicexmlj.voicexml.XsltStateStackConverter.java

/**
 * Append element pointing to file with srgs grammar to the form
 *//*from www. j av a2  s.  c o m*/
public void appendGrammarFile(Element form, GrammarReference srgsReferences) {
    if (srgsReferences.grammarFile() != null) {
        Element grammar = new Element("grammar", NS_VXML);
        grammar.setAttribute("type", "application/srgs+xml");
        grammar.setAttribute("src", srgsReferences.grammarFile());
        form.addContent(grammar);
    }
}

From source file:cz.muni.fi.pb138.scxml2voicexmlj.voicexml.XsltStateStackConverter.java

/**
 * Append element pointing to reference inside the grammar file to the field
 *///from   w w  w .j a va  2 s  . c  o  m
public void appendGrammarField(Element field, GrammarReference srgsReferences) {
    String name = helper.extractAttribute(field, "name");
    if (!srgsReferences.stateHasGrammarReference(name)) {
        return;
    }
    String reference = srgsReferences.referenceForState(name);
    Element grammar = new Element("grammar", NS_VXML);
    grammar.setAttribute("src", reference);
    grammar.setAttribute("type", "application/srgs+xml");
    field.addContent(grammar);
}

From source file:cz.pecina.retro.cpu.Block.java

License:Open Source License

@Override
public Element marshal() {
    final Element block = new Element(tagName);
    block.setAttribute("name", name);
    getContent(block);//from   w  ww.  j a  v  a  2s. c  o  m
    log.fine("Block '" + name + "' retrieved");
    return block;
}