All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.simy4.xpath.dom.spi.DomNavigatorSpi Maven / Gradle / Ivy

There is a newer version: 2.3.9
Show newest version
package com.github.simy4.xpath.dom.spi;

import com.github.simy4.xpath.XmlBuilderException;
import com.github.simy4.xpath.dom.navigator.DomNavigator;
import com.github.simy4.xpath.dom.navigator.DomNode;
import com.github.simy4.xpath.effects.Effect;
import com.github.simy4.xpath.navigator.Navigator;
import com.github.simy4.xpath.spi.NavigatorSpi;
import org.w3c.dom.Node;

/**
 * Standard DOM model navigator extension SPI.
 */
public class DomNavigatorSpi implements NavigatorSpi {

    @Override
    public boolean canHandle(Object o) {
        return o instanceof Node;
    }

    @Override
    public  T process(T xml, Iterable effects) throws XmlBuilderException {
        if (!canHandle(xml)) {
            throw new IllegalArgumentException("XML model is not supported");
        }
        final Node xmlNode = (Node) xml;
        final DomNode node = new DomNode(xmlNode);
        final Navigator navigator = new DomNavigator(xmlNode);
        for (Effect effect : effects) {
            effect.perform(navigator, node);
        }
        return xml;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy