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

org.daisy.pipeline.client.models.Alive Maven / Gradle / Ivy

There is a newer version: 5.0.1
Show newest version
package org.daisy.pipeline.client.models;

import org.daisy.pipeline.client.Pipeline2Exception;
import org.daisy.pipeline.client.utils.XPath;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

/**
 * A representation of the "alive" response from the Pipeline 2 Web Service.
 * 
 * @author jostein
 */
public class Alive {
	
	public Boolean error = null;
	public Boolean authentication = null;
	public Boolean localfs = null;
	public String version = null;
	
	// ---------- Constructors ----------
	
	/**
	 * Parse the "alive"-XML described by the provided XML document/node.
	 * Example: http://daisy-pipeline.googlecode.com/hg/webservice/samples/xml-formats/alive.xml
	 * 
	 * @param aliveXml
	 * @throws Pipeline2Exception
	 */
	public Alive(Node aliveXml) throws Pipeline2Exception {
		parseAliveXml(aliveXml);
	}
	
	private void parseAliveXml(Node aliveXml) throws Pipeline2Exception {
		if (XPath.selectNode("/d:error", aliveXml, XPath.dp2ns) != null) {
			error = true;
			return;
		}
		error = false;
		
		// select root element if the node is a document node
		if (aliveXml instanceof Document)
			aliveXml = XPath.selectNode("/d:alive", aliveXml, XPath.dp2ns);
		
		this.authentication = "true".equals(XPath.selectText("@authentication", aliveXml, XPath.dp2ns));
		this.localfs = "true".equals(XPath.selectText("@localfs", aliveXml, XPath.dp2ns));
		this.version = XPath.selectText("@version", aliveXml, XPath.dp2ns);
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy