List of usage examples for org.jdom2 JDOMFactory attribute
public Attribute attribute(String name, String value, AttributeType type);
Attribute
with the specified (local) name, value and type, and does not place the attribute in a org.jdom2.Namespace
. 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 .c om 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); } }
From source file:org.kdp.word.transformer.TOCTransformer.java
License:Apache License
@Override public void transform(Context context) { JDOMFactory factory = context.getJDOMFactory(); Element root = context.getSourceRoot(); for (Element el : root.getChildren()) { transformInternal(context, el);// ww w . j ava2 s. co m } Element first = JDOMUtils.findElement(root, "p", "class", "MsoToc1"); if (first != null) { Element parent = first.getParentElement(); List<Element> children = parent.getChildren(); // Add the nav element Element nav = factory.element("nav"); nav.getAttributes().add(factory.attribute("type", "toc", OPFTransformer.NS_OPF)); int index = children.indexOf(first); children.add(index, nav); // Add the ol element Element ol = factory.element("ol"); ol.setAttribute("class", "Toc"); nav.getChildren().add(ol); Iterator<Element> itel = children.iterator(); while (itel.hasNext()) { Element el = itel.next(); if (JDOMUtils.isElement(el, "p", "class", "MsoToc1")) { Element li = factory.element("li"); li.getAttributes().add(factory.attribute("class", "MsoToc1")); li.addContent(el.cloneContent()); ol.getChildren().add(li); itel.remove(); } } } }