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

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

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

import java.util.ArrayList;
import java.util.List;

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

/**
 * A representation of the "/admin/properties" response from the Pipeline 2 Web Service.
 * 
 * Example XML:
 * {@code
 * 
 * 
 *     
 *     
 *     
 *     
 * 
 * }
 */
public class Property {

	public String name;
	public String value;
	public long bundleId;
	public String bundleName;

	public static List parsePropertiesXml(Node propertiesNode) {
		List properties = new ArrayList();

		try {
			// select root element if the node is a document node
			if (propertiesNode instanceof Document)
				propertiesNode = XPath.selectNode("/d:jobs", propertiesNode, XPath.dp2ns);

			List propertyNodes = XPath.selectNodes("d:job", propertiesNode, XPath.dp2ns);
			for (Node propertyNode : propertyNodes) {
				Property property = new Property();
				property.name = XPath.selectText("@name", propertyNode, XPath.dp2ns);
				property.value = XPath.selectText("@value", propertyNode, XPath.dp2ns);
				property.bundleId = Long.valueOf(XPath.selectText("@bundleId", propertyNode, XPath.dp2ns));
				property.bundleName = XPath.selectText("@bundleName", propertyNode, XPath.dp2ns);
				properties.add(property);
			}

		} catch (Exception e) {
			Pipeline2Logger.logger().error("Failed to parse the properties XML", e);
		}
		
		return properties;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy