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

jlibs.xml.sax.dog.XPathResults Maven / Gradle / Ivy

/**
 * Copyright 2015 Santhosh Kumar Tekuri
 *
 * The JLibs authors license this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package jlibs.xml.sax.dog;

import jlibs.xml.sax.dog.expr.Evaluation;
import jlibs.xml.sax.dog.expr.EvaluationListener;
import jlibs.xml.sax.dog.expr.Expression;
import jlibs.xml.sax.dog.sniff.Event;

import javax.xml.namespace.NamespaceContext;
import java.io.PrintStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Santhosh Kumar T
 */
public class XPathResults extends EvaluationListener{
    private Event event;
    private Map results = new HashMap();

    public XPathResults(Event event){
        this.event = event;
    }

    @Override
    public void finished(Evaluation evaluation){
        results.put(evaluation.expression, evaluation.getResult());
    }

    public NamespaceContext getNamespaceContext(){
        return event.getNamespaceContext();
    }

    @SuppressWarnings({"unchecked"})
    public Object getResult(Expression expr){
        return results.get(expr);
    }

    /*-------------------------------------------------[ Printing ]---------------------------------------------------*/

    public static void print(PrintStream out, String xpath, Object result){
        out.printf("XPath: %s%n", xpath);
        print(out, result, 2);
    }

    private static void printIndent(PrintStream out, int indent){
        for(int i=0; i expressions, PrintStream out){
        for(Expression expr: expressions){
            print(out, expr.getXPath(), getResult(expr));
            out.println();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy