Example usage for org.jdom2 Document addContent

List of usage examples for org.jdom2 Document addContent

Introduction

In this page you can find the example usage for org.jdom2 Document addContent.

Prototype

@Override
public Document addContent(Collection<? extends Content> c) 

Source Link

Document

Appends all children in the given collection to the end of the content list.

Usage

From source file:ca.nrc.cadc.dali.tables.votable.VOTableWriter.java

License:Open Source License

/**
 * Builds a empty VOTable document with the appropriate namespaces and
 * attributes.//from ww  w . j a v a 2 s  . co m
 *
 * @return VOTable document.
 */
protected Document createDocument() {
    // the root VOTABLE element
    Namespace vot = Namespace.getNamespace(VOTABLE_12_NS_URI);
    Namespace xsi = Namespace.getNamespace("xsi", XSI_SCHEMA);
    Element votable = new Element("VOTABLE", vot);
    votable.setAttribute("version", VOTABLE_VERSION);
    votable.addNamespaceDeclaration(xsi);

    Document document = new Document();
    document.addContent(votable);

    return document;
}

From source file:ca.nrc.cadc.uws.web.restlet.resources.ParameterListResource.java

License:Open Source License

/**
 * Assemble the appropriate XML and build the given Document.
 *
 * @param document      The Document to build.
 *///from   w w  w. j  ava  2s . co  m
protected void buildXML(Document document) {
    JobWriter jobWriter = new JobWriter();
    document.addContent(jobWriter.getParameters(job));
}

From source file:ca.nrc.cadc.uws.web.restlet.resources.ResultListResource.java

License:Open Source License

/**
 * Assemble the XML for this Resource's Representation into the given
 * Document.//w  w w.j  a  va2  s  .  c  o  m
 *
 * @param document The Document to build up.
 */
protected void buildXML(Document document) {
    JobWriter jobWriter = new JobWriter();
    document.addContent(jobWriter.getResults(job));
}

From source file:ca.nrc.cadc.vosi.Availability.java

License:Open Source License

public Document toXmlDocument() {
    DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC);
    Namespace vosi = Namespace.getNamespace("vosi", VOSI.AVAILABILITY_NS_URI);

    Element eleAvailability = new Element("availability", vosi);

    Util.addChild(eleAvailability, vosi, "available", Boolean.toString(_status.isAvailable()));
    if (_status.getUpSince() != null)
        Util.addChild(eleAvailability, vosi, "upSince", df.format(_status.getUpSince()));
    if (_status.getDownAt() != null)
        Util.addChild(eleAvailability, vosi, "downAt", df.format(_status.getDownAt()));
    if (_status.getBackAt() != null)
        Util.addChild(eleAvailability, vosi, "backAt", df.format(_status.getBackAt()));
    if (_status.getNote() != null)
        Util.addChild(eleAvailability, vosi, "note", _status.getNote());

    Document document = new Document();
    document.addContent(eleAvailability);

    return document;
}

From source file:ca.nrc.cadc.vosi.Capabilities.java

License:Open Source License

public Document toXmlDocument() {
    Namespace xsi = Namespace.getNamespace("xsi", VOSI.XSI_NS_URI);
    Namespace cap = Namespace.getNamespace("vosi", VOSI.CAPABILITIES_NS_URI);
    Namespace vod = Namespace.getNamespace("vod", VOSI.VODATASERVICE_NS_URI);

    Element eleCapabilities = new Element("capabilities", cap);
    eleCapabilities.addNamespaceDeclaration(xsi);
    eleCapabilities.addNamespaceDeclaration(cap);
    eleCapabilities.addNamespaceDeclaration(vod);

    //Attribute attSchemaLocation = new Attribute("schemaLocation", XSI_LOC, xsi);
    //eleCapabilities.setAttribute(attSchemaLocation);

    Document document = new Document();
    document.addContent(eleCapabilities);

    for (Capability capability : this._caps) {
        eleCapabilities.addContent(capability.toXmlElement(xsi, cap, vod));
    }/*from ww  w.j a  v  a2 s  . c om*/
    return document;
}

From source file:ca.nrc.cadc.vosi.TableSet.java

License:Open Source License

/**
 * Get a single Table document.// ww  w.ja va2 s .  c o  m
 * 
 * @param root root element for document
 * @return the TapSchema as a document to be rendered as XML
 */
protected Document getDocument(Element root) {
    root.addNamespaceDeclaration(xsi);
    root.addNamespaceDeclaration(vod);

    // ivoa convention but not allowed by the VODataService schema
    //root.setAttribute("version", "1.1");

    Document document = new Document();
    document.addContent(root);
    return document;
}

From source file:cager.parser.test.SimpleTest2.java

License:Open Source License

private String elementoToString(Element segmento) {

    Document documentJDOM = new Document();
    documentJDOM.addContent(segmento);
    // Vamos a serializar el XML  
    // Lo primero es obtener el formato de salida  
    // Partimos del "Formato bonito", aunque tambin existe el plano y el compacto  
    Format format = Format.getPrettyFormat();
    // Creamos el serializador con el formato deseado  
    XMLOutputter xmloutputter = new XMLOutputter(format);
    // Serializamos el document parseado  
    String docStr = xmloutputter.outputString(documentJDOM);

    FileOutputStream fout;/*from   w w  w. j av a  2  s. co  m*/
    try {
        fout = new FileOutputStream(ruta + "VBParser\\ejemplosKDM\\archivo.kdm");
        //fout = new FileOutputStream("E:\\WorkspaceParser\\VBParser\\ejemplosKDM\\archivo.kdm");
        xmloutputter.output(documentJDOM, fout);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return docStr;
}

From source file:cager.parser.test.SimpleTest3.java

License:Open Source License

private String elementoToString(Element segmento) {

    Document documentJDOM = new Document();
    documentJDOM.addContent(segmento);
    // Vamos a serializar el XML  
    // Lo primero es obtener el formato de salida  
    // Partimos del "Formato bonito", aunque tambin existe el plano y el compacto  
    Format format = Format.getPrettyFormat();
    // Creamos el serializador con el formato deseado  
    XMLOutputter xmloutputter = new XMLOutputter(format);
    // Serializamos el document parseado  
    String docStr = xmloutputter.outputString(documentJDOM);

    FileOutputStream fout;/*from w  ww.  jav a 2  s.c  o  m*/
    try {
        fout = new FileOutputStream(ruta + "VBParser\\ejemplosKDM\\archivo.kdm");
        //fout = new FileOutputStream("E:\\WorkspaceParser\\VBParser\\ejemplosKDM\\archivo.kdm");
        xmloutputter.output(documentJDOM, fout);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return docStr;
}

From source file:com.cybernostics.jsp2thymeleaf.JSP2Thymeleaf.java

private void writeTree(JspTree jspTree, OutputStream outputStream) {
    try {//from   w w w  .j  a  v a 2 s  .c o m
        Document doc = new Document();
        final List<Content> content = rootContentFor(jspTree);

        doc.addContent(content);

        XMLOutputter out = new XMLOutputter(Format.getPrettyFormat().setTextMode(Format.TextMode.NORMALIZE)
                .setLineSeparator(NEWLINE).setOmitDeclaration(true));

        out.output(doc, outputStream);
    } catch (IOException ex) {
        Logger.getLogger(JSP2Thymeleaf.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.github.cat.yum.store.util.YumUtil.java

private static void createRepoMd(String rootPath, RepoModule... repos) throws IOException {
    Document doc = new Document();
    Element root = new Element("repomd", REPONAMESPACE);
    doc.addContent(root);
    root.addNamespaceDeclaration(RPMNAMESPACE);
    long now = System.currentTimeMillis();

    for (RepoModule repo : repos) {
        Element data = new Element("data", REPONAMESPACE);
        data.setAttribute("type", repo.getModule());
        Element location = new Element("location", REPONAMESPACE);
        File xmlGzFie = getXmlGzFile(repo, repo.getXmlGzCode());
        location.setAttribute("href", replacePath(FileUtils.getFileRelativePath(repo.getRootPath(), xmlGzFie)));
        data.addContent(location);//from   ww  w . ja v a 2 s  .  c  o  m
        Element checksum = new Element("checksum", REPONAMESPACE);
        checksum.setAttribute("type", ALGORITHM);
        checksum.setAttribute("pkgid", "YES");
        checksum.setText(repo.getXmlGzCode());
        data.addContent(checksum);
        Element size = new Element("size", REPONAMESPACE);
        size.setText(repo.getXmlGzSize() + "");
        data.addContent(size);
        Element timestamp = new Element("timestamp", REPONAMESPACE);
        timestamp.setText(now + "");
        data.addContent(timestamp);
        Element openCheckSum = new Element("open-checksum", REPONAMESPACE);
        openCheckSum.setAttribute("type", ALGORITHM);
        openCheckSum.setAttribute("pkgid", "YES");
        openCheckSum.setText(repo.getXmlCode());
        data.addContent(openCheckSum);
        Element openSize = new Element("open-size", REPONAMESPACE);
        openSize.setText(repo.getXmlSize() + "");
        data.addContent(openSize);
        Element revision = new Element("revision", REPONAMESPACE);
        data.addContent(revision);
        root.addContent(data);
    }
    File repoMd = new File(rootPath + File.separator + REPOPATH + File.separator + "repomd" + ".xml");
    xmlToFile(doc, repoMd);
}