Example usage for org.jdom2 Parent addContent

List of usage examples for org.jdom2 Parent addContent

Introduction

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

Prototype

public Parent addContent(int index, Collection<? extends Content> c);

Source Link

Document

Inserts the content in a collection into the content list at the given index.

Usage

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

License:Apache License

@Override
public void transform(Context context) {

    Map<String, Footnode> footnodes = new LinkedHashMap<>();

    Element root = context.getSourceRoot();
    for (Element el : root.getChildren()) {
        findFootnodes(context, el, footnodes);
    }//from   w w  w  .  ja v a 2s  .  co  m

    JDOMFactory factory = context.getJDOMFactory();
    for (Footnode fn : footnodes.values()) {

        // Footnode Ref
        Element fnref = fn.fnref;
        String text = getFootnodeText(fnref);
        Parent parent = fnref.getParent();
        int index = parent.indexOf(fnref);
        parent.removeContent(index);
        Element span = factory.element("span");
        span.setAttribute("class", "MsoFootnoteReference");
        Element a = fnref.clone();
        a.removeContent();
        a.setText(text);
        //a.setAttribute("type", "noteref", OPFTransformer.NS_OPF);
        span.addContent(a);
        parent.addContent(index, span);

        /* Footnode Text
        Element fntxt = fn.fntxt;
        Element p = findMsoFootnoteText(fntxt); 
        text = getFootnodeText(p);
        p.getAttributes().clear();
        p.removeContent();
        p.setText(text);
        String divid = fn.id.substring(1);
        Element div = JDOMUtils.findElement(root, "div", "id", divid);
        IllegalStateAssertion.assertSame(p.getParentElement(), div, "Unexpected parent: " + div);
        Parent divparent = div.getParent();
        Element aside = factory.element("aside");
        aside.setAttribute("type", "footnote", OPFTransformer.NS_OPF);
        aside.setAttribute("id", fn.id);
        index = divparent.indexOf(div);
        divparent.removeContent(div);
        aside.addContent(p.clone());
        divparent.addContent(index, aside);
        */
    }
}