Example usage for org.jdom2 JDOMFactory element

List of usage examples for org.jdom2 JDOMFactory element

Introduction

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

Prototype

public Element element(String name, String uri);

Source Link

Document

This will create a new Element with the supplied (local) name, and specifies the URI of the org.jdom2.Namespace the Element should be in, resulting it being unprefixed (in the default namespace).

Usage

From source file:org.kdp.word.transformer.OPFTransformer.java

License:Apache License

private void processMetadata(Context context, Element opf) {

    Element metadata = JDOMUtils.findElement(opf, "metadata");
    JDOMFactory factory = context.getJDOMFactory();
    Parser parser = context.getParser();

    // Title/* w w w . ja v a  2  s  . com*/
    String title = parser.getProperty(Parser.PROPERTY_OPF_METADATA_TITLE);
    IllegalStateAssertion.assertNotNull(title, "Cannot obtain property: " + Parser.PROPERTY_OPF_METADATA_TITLE);
    Element elTitle = factory.element("title", NS_DC);
    elTitle.setText(title != null ? title : "Undefined Title");
    metadata.getChildren().add(elTitle);

    // Creator
    String author = parser.getProperty(Parser.PROPERTY_OPF_METADATA_AUTHOR);
    IllegalStateAssertion.assertNotNull(author,
            "Cannot obtain property: " + Parser.PROPERTY_OPF_METADATA_AUTHOR);
    Element elCreator = factory.element("creator", NS_DC);
    elCreator.getAttributes().add(factory.attribute("role", "aut", NS_OPF));
    elCreator.setText(author != null ? author : "Undefined Author");
    metadata.getChildren().add(elCreator);

    // Language
    String language = parser.getProperty(Parser.PROPERTY_OPF_METADATA_LANGUAGE);
    if (language != null && language.length() > 0) {
        Element elLanguage = factory.element("language", NS_DC);
        elLanguage.setText(language);
        metadata.getChildren().add(elLanguage);
    }
}