Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#2 xmltask faild on ibm jdk

Unstable (example)
open
nobody
xpath sun (1)
2
2013-08-22
2013-08-22
Jocelyn Gibart
No

There are 2 classes using some sun private classes that should be fixed :
com/oopsconsultancy/xmltask/ant/Regexp.java uses a private import for no reason
src/com/oopsconsultancy/xmltask/jdk15/XPathAnalyser15.java uses the xpath private api , while there are public apis since java 1.6

Here is a fixed version of the class
package com.oopsconsultancy.xmltask.jdk15;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.oopsconsultancy.xmltask.XPathAnalyser;
import com.oopsconsultancy.xmltask.XPathAnalyserClient;

/*
* uses the JDK 1.5 XPath API to analyse XML docs
*
* @author Brian Agnew
* @version $Id: XPathAnalyser15.java,v 1.2 2004/05/18 08:42:17 bagnew Exp $
/
public class XPathAnalyser15 implements XPathAnalyser {

private XPathAnalyserClient client;
private Object callback;

public void registerClient(XPathAnalyserClient client, Object callback) {
    this.client = client;
    this.callback = callback;
}

public int analyse(Node node, String xpath) throws Exception {
    int count = 0;

    XPathFactory factory = XPathFactory.newInstance();
    XPath xpathcomiler = factory.newXPath();
    XPathExpression expr = xpathcomiler.compile(xpath);

    Object result = expr.evaluate(node, XPathConstants.NODESET);

    if (result instanceof NodeList) {
        NodeList nl = ((NodeList) result);
        Node n;
        for (int i = 0; i < nl.getLength(); i++) {
            n = nl.item(i);
            client.applyNode(n, callback);
            count++;
        }
    } else if (result instanceof Boolean || result instanceof Double || result instanceof String) {
        String str = String.valueOf(result);
        client.applyNode(str, callback);
        count++;
    }
    return count;
}

}

Discussion