org.rhq.plugins.apache.parser.ApacheDirectiveTree Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rhq-apache-plugin Show documentation
Show all versions of rhq-apache-plugin Show documentation
a plugin for managing Apache web servers (1.3 and later)
package org.rhq.plugins.apache.parser;
import java.util.ArrayList;
import java.util.List;
public class ApacheDirectiveTree implements Cloneable {
private ApacheDirective rootNode;
public ApacheDirectiveTree() {
rootNode = new ApacheDirective();
rootNode.setRootNode(true);
}
public ApacheDirective getRootNode() {
return rootNode;
}
public void setRootNode(ApacheDirective rootNode) {
this.rootNode = rootNode;
}
public List search(ApacheDirective nd, String name) {
return parseExpr(nd, name);
}
public List search(String name) {
if (name.startsWith("/"))
return parseExpr(rootNode, name.substring(1));
else
return parseExpr(rootNode, name);
}
private List parseExpr(ApacheDirective nd, String expr) {
int index = expr.indexOf("/");
String name;
if (index == -1)
name = expr;
else
name = expr.substring(0, index);
List nds = new ArrayList();
for (ApacheDirective dir : nd.getChildByName(name)) {
if (index == -1)
nds.add(dir);
else {
List tempNodes = parseExpr(dir, expr.substring(index + 1));
if (tempNodes != null)
nds.addAll(tempNodes);
}
}
return nds;
}
public ApacheDirective createNode(ApacheDirective parentNode, String name) {
ApacheDirective dir = new ApacheDirective(name);
dir.setParentNode(parentNode);
parentNode.addChildDirective(dir);
return dir;
}
@Override
public ApacheDirectiveTree clone() {
ApacheDirectiveTree copy = new ApacheDirectiveTree();
copy.rootNode = rootNode.clone();
return copy;
}
}