Example usage for org.jdom2 Document Document

List of usage examples for org.jdom2 Document Document

Introduction

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

Prototype

public Document(List<? extends Content> content) 

Source Link

Document

This will create a new Document, with the supplied list of content, and a DocType declaration only if the content contains a DocType instance.

Usage

From source file:org.helm.notation2.tools.xHelmNotationExporter.java

License:Open Source License

/**
 * method to get xhelm for the helm notation, only if it was possible to
 * convert the helm in the old format//from   w  w w  .j ava2  s  . c  om
 *
 * @param helm2notation, HELM2Notation object
 * @return xhelm
 * @throws MonomerException
 * @throws HELM1FormatException
 * @throws JDOMException
 * @throws IOException
 * @throws NotationException
 * @throws CTKException
 * @throws ValidationException
 * @throws ChemistryException if the Chemistry Engine can not be initialized
 */
public static String getXHELM(HELM2Notation helm2notation) throws MonomerException, HELM1FormatException,
        IOException, JDOMException, NotationException, CTKException, ValidationException, ChemistryException {
    set = new HashSet<Monomer>();
    Element root = new Element(xHelmNotationExporter.XHELM_ELEMENT);

    Document doc = new Document(root);

    Element helmElement = new Element(xHelmNotationExporter.HELM_NOTATION_ELEMENT);
    helmElement.setText(HELM1Utils.getStandard(helm2notation));

    root.addContent(helmElement);

    Element monomerListElement = new Element(xHelmNotationExporter.MONOMER_LIST_ELEMENT);

    /* save all adhocMonomers in the set */
    for (MonomerNotation monomernotation : MethodsMonomerUtils
            .getListOfMonomerNotation(helm2notation.getListOfPolymers())) {
        /* get all elements of an rna */
        if (monomernotation instanceof MonomerNotationUnitRNA) {
            for (MonomerNotationUnit unit : ((MonomerNotationUnitRNA) monomernotation).getContents()) {
                addAdHocMonomer(unit);
            }
        } else {
            addAdHocMonomer(monomernotation);
        }
    }

    /* give adhoc monomer's information */
    for (Monomer distinctmonomer : set) {
        Element monomerElement = MonomerParser.getMonomerElement(distinctmonomer);
        monomerListElement.getChildren().add(monomerElement);
    }

    root.addContent(monomerListElement);

    XMLOutputter xmlOutput = new XMLOutputter();
    // display nice
    xmlOutput.setFormat(Format.getPrettyFormat());

    return xmlOutput.outputString(doc);

}

From source file:org.humsat.demo.gssw.sensorlocator.kml.SimpleKMLWriter.java

License:Open Source License

/**
 * Method that creates a simple empty KML document with style information 
 * but without contents. It is useful for using it as a base to which add 
 * new KML nodes.//from  w  w w  . j  a v a  2  s .c o  m
 */
private void createKMLStubDocument() {

    Element kml = new Element("kml", ns);
    this.kmlDocument = new Document(kml);

    // Document
    this.root = new Element("Document", ns);
    kml.addContent(this.root);

    // name
    Element name = new Element("name", ns);
    name.setText("HumSAT-D sensors");
    this.root.addContent(name);

    // Style
    Element style = new Element("Style", ns);
    style.setAttribute("id", "redIcon");
    this.root.addContent(style);

    // IconStyle
    Element iconStyle = new Element("IconStyle", ns);
    style.addContent(iconStyle);

    // color
    Element color = new Element("color", ns);
    color.setText("990000ff");
    iconStyle.addContent(color);

    // Icon
    Element icon = new Element("Icon", ns);
    iconStyle.addContent(icon);

    // href
    Element href = new Element("href", ns);
    href.setText(PLACEMARK_ICON_URL);
    icon.addContent(href);

}

From source file:org.incode.eurocommercial.contactapp.app.services.export.ExportToWordMenu.java

License:Apache License

private Document asInputDocument(final List<Contact> contacts) {

    final Element html = new Element("html");
    final Document document = new Document(html);

    final Element body = new Element("body");
    html.addContent(body);//from w w w  . j a v  a 2  s  .c om

    addPara(body, "ExportedOn", "date", clockService.nowAsLocalDateTime().toString("dd-MMM-yyyy"));

    final Element table = addTable(body, "SimpleObjects");
    for (final Contact quickObject : contacts) {
        addTableRow(table, new String[] { quickObject.getName() });
    }
    return document;
}

From source file:org.isisaddons.module.docx.fixture.dom.templates.CustomerConfirmation.java

License:Apache License

private static Document asInputDocument(final Order order) {
    final Element html = new Element("html");
    final Document document = new Document(html);

    final Element body = new Element("body");
    html.addContent(body);//from   w w  w.jav  a2s .c  o m

    addPara(body, "OrderNum", "plain", order.getNumber());
    addPara(body, "OrderDate", "date", order.getDate().toString("dd-MMM-yyyy"));
    addPara(body, "CustomerName", "plain", order.getCustomerName());
    addPara(body, "Message", "plain", "Thank you for shopping with us!");

    final Element table = addTable(body, "Products");
    for (final OrderLine orderLine : order.getOrderLines()) {
        addTableRow(table, new String[] { orderLine.getDescription(), orderLine.getCost().toString(),
                "" + orderLine.getQuantity() });
    }

    final Element ul = addList(body, "OrderPreferences");
    for (final String preference : preferencesFor(order)) {
        addListItem(ul, preference);
    }
    return document;
}

From source file:org.jreserve.gui.wrapper.jdom.JDomUtil.java

License:Open Source License

public static void save(final FileObject file, Element element) throws IOException {
    save(file, new Document(element));
}

From source file:org.jumpmind.metl.core.runtime.component.XsltProcessor.java

License:Open Source License

public static String getBatchXml(Model model, ArrayList<EntityData> inputRows, boolean outputAllAttributes) {
    SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT);
    Element root = new Element("batch");
    Document doc = new Document(root);

    for (ModelEntity entity : getModelEntities(model, inputRows)) {
        Element entityElement = new Element("entity");
        entityElement.setAttribute("name", entity.getName());
        root.addContent(entityElement);/* w w  w. ja v  a 2s. c  o m*/

        for (EntityData entityData : inputRows) {
            List<ModelAttribute> attributes = null;
            if (outputAllAttributes) {
                attributes = entity.getModelAttributes();
            } else {
                attributes = getModelAttributes(model, entity.getId(), entityData.keySet());
            }

            Element recordElement = new Element("record");
            if (attributes.size() > 0) {
                entityElement.addContent(recordElement);
            }

            for (ModelAttribute attribute : attributes) {
                if (attribute != null && attribute.getEntityId().equals(entity.getId())) {
                    Element attributeElement = new Element("attribute");
                    attributeElement.setAttribute("name", attribute.getName());
                    Object object = entityData.get(attribute.getId());
                    String value = null;
                    DataType type = attribute.getDataType();

                    if (object != null) {
                        if (type.isTimestamp() && object instanceof Date) {
                            value = df.format(object);
                        } else {
                            value = object.toString();
                        }
                    }
                    attributeElement.setAttribute("value", value == null ? "" : value);
                    recordElement.addContent(attributeElement);
                }
            }
        }
    }

    StringWriter writer = new StringWriter();
    XMLOutputter xmlOutput = new XMLOutputter();
    xmlOutput.setFormat(Format.getPrettyFormat());
    try {
        xmlOutput.output(doc, writer);
        writer.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return writer.toString();
}

From source file:org.kitodo.docket.ExportXmlLog.java

License:Open Source License

/**
 * This method creates a new xml document with process metadata.
 *
 * @param docketData//from   www  .j  a v  a  2  s.  c om
 *            the docketData to export
 * @return a new xml document
 */
private Document createDocument(DocketData docketData, boolean addNamespace) {

    Element processElm = new Element("process");
    final Document doc = new Document(processElm);

    processElm.setAttribute("processID", String.valueOf(docketData.getProcessId()));

    Namespace xmlns = Namespace.getNamespace(NAMESPACE);
    processElm.setNamespace(xmlns);
    // namespace declaration
    if (addNamespace) {

        Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        processElm.addNamespaceDeclaration(xsi);
        Attribute attSchema = new Attribute("schemaLocation", NAMESPACE + " XML-logfile.xsd", xsi);
        processElm.setAttribute(attSchema);
    }
    // process information

    ArrayList<Element> processElements = new ArrayList<>();
    Element processTitle = new Element("title", xmlns);
    processTitle.setText(docketData.getProcessName());
    processElements.add(processTitle);

    Element project = new Element("project", xmlns);
    project.setText(docketData.getProjectName());
    processElements.add(project);

    Element date = new Element("time", xmlns);
    date.setAttribute("type", "creation date");
    date.setText(String.valueOf(docketData.getCreationDate()));
    processElements.add(date);

    Element ruleset = new Element("ruleset", xmlns);
    ruleset.setText(docketData.getRulesetName());
    processElements.add(ruleset);

    Element comment = new Element("comment", xmlns);
    comment.setText(docketData.getComment());
    processElements.add(comment);

    List<Element> processProperties = prepareProperties(docketData.getProcessProperties(), xmlns);

    if (!processProperties.isEmpty()) {
        Element properties = new Element(PROPERTIES, xmlns);
        properties.addContent(processProperties);
        processElements.add(properties);
    }

    // template information
    ArrayList<Element> templateElements = new ArrayList<>();
    Element template = new Element("original", xmlns);

    ArrayList<Element> templateProperties = new ArrayList<>();
    if (docketData.getTemplateProperties() != null) {
        for (Property prop : docketData.getTemplateProperties()) {
            Element property = new Element(PROPERTY, xmlns);
            property.setAttribute(PROPERTY_IDENTIFIER, prop.getTitle());
            if (prop.getValue() != null) {
                property.setAttribute(VALUE, replacer(prop.getValue()));
            } else {
                property.setAttribute(VALUE, "");
            }

            Element label = new Element(LABEL, xmlns);

            label.setText(prop.getTitle());
            property.addContent(label);

            templateProperties.add(property);
            if (prop.getTitle().equals("Signatur")) {
                Element secondProperty = new Element(PROPERTY, xmlns);
                secondProperty.setAttribute(PROPERTY_IDENTIFIER, prop.getTitle() + "Encoded");
                if (prop.getValue() != null) {
                    secondProperty.setAttribute(VALUE, "vorl:" + replacer(prop.getValue()));
                    Element secondLabel = new Element(LABEL, xmlns);
                    secondLabel.setText(prop.getTitle());
                    secondProperty.addContent(secondLabel);
                    templateProperties.add(secondProperty);
                }
            }
        }
    }
    if (!templateProperties.isEmpty()) {
        Element properties = new Element(PROPERTIES, xmlns);
        properties.addContent(templateProperties);
        template.addContent(properties);
    }
    templateElements.add(template);

    Element templates = new Element("originals", xmlns);
    templates.addContent(templateElements);
    processElements.add(templates);

    // digital document information
    ArrayList<Element> docElements = new ArrayList<>();
    Element dd = new Element("digitalDocument", xmlns);

    List<Element> docProperties = prepareProperties(docketData.getWorkpieceProperties(), xmlns);

    if (!docProperties.isEmpty()) {
        Element properties = new Element(PROPERTIES, xmlns);
        properties.addContent(docProperties);
        dd.addContent(properties);
    }
    docElements.add(dd);

    Element digdoc = new Element("digitalDocuments", xmlns);
    digdoc.addContent(docElements);
    processElements.add(digdoc);

    processElm.setContent(processElements);
    return doc;
}

From source file:org.knoxcraft.database.xml.XmlDatabase.java

License:Open Source License

private Document initFile(File file, String rootName) throws IOException {
    Document doc = new Document(new Element(rootName));
    write(file, doc);//from   www . jav  a2s . co  m
    return doc;
}

From source file:org.mycore.common.content.MCRJDOMContent.java

License:Open Source License

/**
 * Alternative constructor for newly created root elements
 * that do not have a Document parent yet, which is a very 
 * common use case.//w  w  w .jav a 2 s.  c o m
 * 
 * @param jdom the JDOM XML root element to read from 
 */
public MCRJDOMContent(Element jdom) {
    this(new Document(jdom));
}

From source file:org.mycore.datamodel.ifs.MCRDirectoryXML.java

License:Open Source License

/**
 * returns a error document to display error messages
 * TODO:should be extended to provide stacktraces etc.
 * @return JDOM Document with root element "mcr_error"
 *///from   w w  w . j a va2 s  .c o  m
private Document getErrorDocument(String msg) {
    return new Document(new Element("mcr_error").setText(msg));
}