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

org.rhq.plugins.apache.parser.ApacheDirectiveTree Maven / Gradle / Ivy

There is a newer version: 4.13.0
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy