org.rundeck.api.parser.StorageResourceParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rundeck-api-java-client Show documentation
Show all versions of rundeck-api-java-client Show documentation
Java client for the Rundeck REST API
The newest version!
package org.rundeck.api.parser;
import org.dom4j.Element;
import org.dom4j.Node;
import org.rundeck.api.domain.BaseStorageResource;
import org.rundeck.api.domain.StorageResource;
import java.util.HashMap;
/**
* StorageResourceParser is ...
*
* @author Greg Schueler
* @since 2014-04-04
*/
public class StorageResourceParser extends BaseXpathParser {
private BaseStorageResource holder;
public StorageResourceParser() {
}
public StorageResourceParser(BaseStorageResource holder){
this.holder=holder;
}
public StorageResourceParser(String xpath) {
super(xpath);
}
@Override
public StorageResource parse(Node node) {
String path = node.valueOf("@path");
String type = node.valueOf("@type");
String url = node.valueOf("@url");
BaseStorageResource storageResource = null == holder ? new BaseStorageResource() : holder;
storageResource.setDirectory("directory".equals(type));
storageResource.setPath(path);
storageResource.setUrl(url);
if (storageResource.isDirectory()) {
if (node.selectSingleNode("contents") != null) {
storageResource.setDirectoryContents(new ListParser(new StorageResourceParser(),
"contents/resource").parseXmlNode(node));
}
} else {
String name = node.valueOf("@name");
storageResource.setName(name);
Node meta = node.selectSingleNode("resource-meta");
HashMap metamap = new HashMap();
if (null != meta) {
Element metaEl = (Element) meta;
for (Object o : metaEl.elements()) {
Element sub = (Element) o;
metamap.put(sub.getName(), sub.getText().trim());
}
}
storageResource.setMetadata(metamap);
}
return storageResource;
}
}