W3C home > Mailing lists > Public > www-validator-cvs@w3.org > September 2009

2006/unicorn/src/org/w3c/unicorn/tasklisttree XPathCond.java,NONE,1.1

From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
Date: Mon, 21 Sep 2009 12:12:08 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1MphkW-00088P-Mh@lionel-hutz.w3.org>
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/tasklisttree
In directory hutz:/tmp/cvs-serv31247/src/org/w3c/unicorn/tasklisttree

Added Files:
	XPathCond.java 
Log Message:
new condition classes extending TLTCond

--- NEW FILE: XPathCond.java ---
package org.w3c.unicorn.tasklisttree;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;
import org.w3c.unicorn.UnicornCall;
import org.w3c.unicorn.response.Response;

import com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl;

public class XPathCond extends TLTCond {

	@Override
	public boolean check(UnicornCall unicornCall) throws Exception {
		Response res = unicornCall.getResponses().get(observer.getID());
		// Testing if there is a matching response in the map and if it is passed
		if (res != null) {
			String xmlStr = res.getXml().toString();
			DocumentBuilderFactory xmlFact = DocumentBuilderFactory.newInstance();
			xmlFact.setNamespaceAware(false);
			DocumentBuilder builder = xmlFact.newDocumentBuilder();
			Document doc = builder.parse(new java.io.ByteArrayInputStream(xmlStr.getBytes("UTF-8")));
			String xpathStr = value;
			XPathFactory xpathFact = new XPathFactoryImpl();
			XPath xpath = xpathFact.newXPath();
			XPathExpression xpe = xpath.compile(xpathStr);
			return (Boolean) xpe.evaluate(doc, XPathConstants.BOOLEAN);
		}
		
		return false;
	}

}
Received on Monday, 21 September 2009 12:12:17 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 26 April 2012 12:55:14 GMT