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.Pipeline2WS;
import org.daisy.pipeline.client.Pipeline2WSException;
import org.daisy.pipeline.client.Pipeline2WSResponse;
import org.daisy.pipeline.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 Pipeline2WSResponse.
	 * Example: http://daisy-pipeline.googlecode.com/hg/webservice/samples/xml-formats/alive.xml
	 * 
	 * @param response
	 * @throws Pipeline2WSException
	 */
	public Alive(Pipeline2WSResponse response) throws Pipeline2WSException {
		if (response.status != 200)
			throw new Pipeline2WSException(response.status+" "+response.statusName+": "+response.statusDescription);
		parseAliveXml(response.asXml());
	}
	
	/**
	 * 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 Pipeline2WSException
	 */
	public Alive(Node aliveXml) throws Pipeline2WSException {
		parseAliveXml(aliveXml);
	}
	
	private void parseAliveXml(Node aliveXml) throws Pipeline2WSException {
		if (XPath.selectNode("/d:error", aliveXml, Pipeline2WS.ns) != 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, Pipeline2WS.ns);
		
		this.authentication = "true".equals(XPath.selectText("@authentication", aliveXml, Pipeline2WS.ns));
		this.localfs = "true".equals(XPath.selectText("@localfs", aliveXml, Pipeline2WS.ns));
		this.version = XPath.selectText("@version", aliveXml, Pipeline2WS.ns);
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy