Search in sources :

Example 1 with MCRTextResolver

use of org.mycore.common.MCRTextResolver in project mycore by MyCoRe-Org.

the class MCRDynamicURIResolver method resolveVariablesFromElement.

/**
 * This method runs through the whole content of the startElement and
 * tries to resolve all variables in texts and attributes.
 *
 * @param startElement where to start to resolve the variables
 * @param variablesMap a map of all variables
 */
protected void resolveVariablesFromElement(Element startElement, Hashtable<String, String> variablesMap) {
    Iterator<Element> it = startElement.getDescendants(Filters.element());
    MCRTextResolver varResolver = new MCRTextResolver(variablesMap);
    while (it.hasNext()) {
        Element element = it.next();
        // text
        String text = element.getText();
        if (text != null && !text.equals("") && text.contains("{")) {
            element.setText(varResolver.resolve(text));
        }
        // attributes
        for (Attribute attrib : element.getAttributes()) {
            String attribValue = attrib.getValue();
            if (attribValue.contains("{")) {
                attrib.setValue(varResolver.resolve(attribValue));
            }
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) MCRTextResolver(org.mycore.common.MCRTextResolver) Element(org.jdom2.Element)

Aggregations

Attribute (org.jdom2.Attribute)1 Element (org.jdom2.Element)1 MCRTextResolver (org.mycore.common.MCRTextResolver)1