Example usage for org.jdom2 Element setName

List of usage examples for org.jdom2 Element setName

Introduction

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

Prototype

public Element setName(final String name) 

Source Link

Document

Sets the (local) name of the element.

Usage

From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.FormulaConverter.java

License:Open Source License

/**
 * Replaces all formulas with the html representation of the mapped formula objects
 *
 * @param doc        JDOM Document where to replace the formulas
 * @param formulaMap Map of the indexed Formula Objects
 * @return JDOM Document with replaced formulas
 *///from  w w  w.  j av  a 2  s . c o m
public Document replaceFormulas(Document doc, Map<Integer, Formula> formulaMap) {
    List<Element> foundFormulas = xpath.evaluate(doc);

    if (foundFormulas.size() > 0) {
        Map<String, Element> formulaMarkupMap = new HashMap<>();

        // Initialize markup map
        for (Element element : foundFormulas) {
            formulaMarkupMap.put(element.getAttribute("id").getValue(), element);
        }

        // Replace all found formulas
        Iterator<Integer> formulaIterator = formulaMap.keySet().iterator();
        while (formulaIterator.hasNext()) {
            Integer id = formulaIterator.next();

            Element formulaMarkupRoot = formulaMarkupMap.get(FORMULA_ID_PREFIX + id);
            Formula formula = formulaMap.get(id);

            formulaMarkupRoot.removeAttribute("class");
            formulaMarkupRoot.removeContent();
            formulaMarkupRoot.setName("div");

            Element div = (Element) formulaMarkupRoot.getParent();
            div.setName("div");
            div.setAttribute("class", "formula");

            // Potentially there's text inside the paragraph...
            List<Text> texts = div.getContent(Filters.textOnly());
            if (texts.isEmpty() == false) {
                String textString = "";
                for (Text text : texts) {
                    textString += text.getText();
                }
                Element textSpan = new Element("span");
                textSpan.setAttribute("class", "text");
                textSpan.setText(textString);
                div.addContent(textSpan);

                List<Content> content = div.getContent();
                content.removeAll(texts);
            }

            if (generateDebugMarkup) {
                div.setAttribute("style", "border: 1px solid black;");

                // Header
                Element h4 = new Element("h4");
                h4.setText("DEBUG - Formula #" + formula.getId());
                div.addContent(h4);

                // Render LaTeX source
                Element latexPre = new Element("pre");
                latexPre.setAttribute("class", "debug-latex");
                latexPre.setText(formula.getLatexCode());
                div.addContent(latexPre);

                // Render MathML markup
                Element mathmlPre = new Element("pre");
                mathmlPre.setAttribute("class", "debug-mathml");
                mathmlPre.setText(formula.getMathMl());
                div.addContent(mathmlPre);

                // Render HTML Markup
                Element htmlPre = new Element("pre");
                htmlPre.setAttribute("class", "debug-html");
                XMLOutputter xmlOutputter = new XMLOutputter();
                xmlOutputter.setFormat(Format.getRawFormat());
                htmlPre.setText(xmlOutputter.outputString(formula.getHtml()));

                div.addContent(htmlPre);

            }

            // Set formula into
            formulaMarkupRoot.addContent(formula.getHtml());
        }
    }
    return doc;
}

From source file:com.cybernostics.jsp2thymeleaf.api.elements.JspTagElementConverter.java

@Override
protected Optional<Element> createElement(JspElementContext node, JSPElementNodeConverter context) {
    Optional<Element> element = super.createElement(node, context);
    if (element.isPresent()) {
        if (isElementEmbeddedInAttribute(node)) {

            HtmlAttributeValueContext parent = (HtmlAttributeValueContext) node.parent;
            String parentAttributeToReplace = getAttributeNamefor(parent);
            Element el = element.get();
            el.setAttribute("data-replace-parent-attribute-name", parentAttributeToReplace);
            el.setName("deleteme");

        }/*from   w w  w  . jav a  2  s.c om*/
    }
    return element;
}

From source file:de.dfki.iui.mmds.core.emf.persistence.EmfPersistence.java

License:Creative Commons License

/**
 * Update member contents with resolved data
 * /* www .  j  a  va 2  s .c o m*/
 * @param node
 * @param memberReference
 * @param memberDocument
 * @return
 * @throws Exception
 */
private static Element updateMember(Element node, EReference memberReference, int id, EObject memberObject,
        Document memberDocument) throws Exception {
    Namespace namespace = node.getNamespace(modelMetaData.getNamespace(memberReference));

    List<Element> children = null;
    if (namespace == null) {
        children = node.getChildren(modelMetaData.getName(memberReference));
    } else
        throw new IllegalArgumentException();
    if (id < children.size()) {
        // Inserting resolved contents to the member
        Element element = children.get(id);
        Element clone = memberDocument.getRootElement().clone();
        clone.setName(memberReference.getName());
        node.setContent(node.indexOf(element), clone);
        // Setting xsi:type
        clone.setAttribute("type",
                memberObject.eClass().getEPackage().getName() + ":" + memberObject.eClass().getName(),
                node.getNamespace("xsi"));
    }

    return node;
}

From source file:de.nava.informa.utils.ParserUtils.java

License:Open Source License

/**
 * Converts names of child-tags mentioned in <code>childrenNames</code> list
 * to that given case./*from  w  w w .j ava  2s. c o  m*/
 *
 * @param root          root element.
 * @param childrenNames names of child tags to convert.
 */
public static void matchCaseOfChildren(Element root, String[] childrenNames) {
    if (root == null || childrenNames.length == 0)
        return;

    // Prepare list of names
    int namesCount = childrenNames.length;
    Map<String, String> names = new HashMap<>(namesCount);
    for (String childName : childrenNames) {
        if (childName != null) {
            String lower = childName.toLowerCase();
            if (!names.containsKey(lower))
                names.put(lower, childName);
        }
    }

    // Walk through the children elements
    List elements = root.getChildren();
    for (Object element : elements) {
        Element child = (Element) element;
        String childName = child.getName().toLowerCase();
        if (names.containsKey(childName))
            child.setName(names.get(childName));
    }
}

From source file:de.nava.informa.utils.ParserUtils.java

License:Open Source License

/**
 * Converts names of child-tags mentioned in <code>childName</code> list
 * to that given case.//from w w w.j  a  v a 2 s .c  o m
 *
 * @param root      root element.
 * @param childName name of child tags to convert.
 */
public static void matchCaseOfChildren(Element root, String childName) {
    if (root == null || childName == null)
        return;

    // Walk through the children elements
    List elements = root.getChildren();
    for (Object element : elements) {
        Element child = (Element) element;
        String name = child.getName().toLowerCase();
        if (name.equalsIgnoreCase(childName))
            child.setName(childName);
    }
}

From source file:delfos.group.io.xml.groupformationtechnique.GroupFormationTechniqueXML.java

License:Open Source License

public static Element getElement(GroupFormationTechnique validationTechnique) {
    Element element = ParameterOwnerXML.getElement(validationTechnique);
    element.setName(ELEMENT_NAME);
    return element;
}

From source file:delfos.group.io.xml.grs.GroupRecommenderSystemXML.java

License:Open Source License

/**
 * Devuelve el elemento que describe totalmente el sistema de recomendacin,
 * almacenando tambin los parmetros que posee y su valor
 *
 * @param grs Sistema de recomendacin a almacenar
 * @return Objeto XML que lo describe//from   w  w  w.j a  v a  2s. c  om
 */
public static Element getElement(GroupRecommenderSystem<Object, Object> grs) {
    Element element = ParameterOwnerXML.getElement(grs);
    element.setName(ELEMENT_NAME);
    return element;
}

From source file:delfos.group.io.xml.predictionprotocol.GroupPredictionProtocolXML.java

License:Open Source License

public static Element getElement(GroupPredictionProtocol validationTechnique) {
    Element element = ParameterOwnerXML.getElement(validationTechnique);
    element.setName(ELEMENT_NAME);
    return element;
}

From source file:delfos.io.xml.dataset.DatasetLoaderXML.java

License:Open Source License

public static Element getElement(DatasetLoader<? extends Rating> datasetLoader) {
    Element element = ParameterOwnerXML.getElement(datasetLoader);
    element.setName(ELEMENT_NAME);
    return element;
}

From source file:delfos.io.xml.predictionprotocol.PredictionProtocolXML.java

License:Open Source License

public static Element getElement(PredictionProtocol predictionProtocol) {
    Element element = ParameterOwnerXML.getElement(predictionProtocol);
    element.setName(ELEMENT_NAME);
    return element;
}