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

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

There is a newer version: 4.13.0
Show newest version
package org.rhq.plugins.apache.parser;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.rhq.augeas.util.Glob;

public class ApacheParserImpl implements ApacheParser{

    private ApacheDirectiveStack stack;
    private static String INCLUDE_DIRECTIVE = "Include";
    private String serverRootPath;
    private ApacheDirectiveTree tree;
    
    public ApacheParserImpl(ApacheDirectiveTree tree,String serverRootPath){          
      stack = new ApacheDirectiveStack();
      this.serverRootPath = serverRootPath;
      this.tree = tree;
      stack.addDirective(this.tree.getRootNode());
    }
    
    public void addDirective(ApacheDirective directive) throws Exception{
        if (directive.getName().equals(INCLUDE_DIRECTIVE)){
            List files = getIncludeFiles(directive.getValuesAsString());
            for (File fl : files){
              ApacheConfigReader.searchFile(fl.getAbsolutePath(), this);   
            }
        }
        directive.setParentNode(stack.getLastDirective());
        stack.getLastDirective().addChildDirective(directive);
    }

    public void endNestedDirective(ApacheDirective directive) {       
        stack.removeLastDirective();        
    }

    public void startNestedDirective(ApacheDirective directive) {
      directive.setParentNode(stack.getLastDirective());
      stack.getLastDirective().addChildDirective(directive);
      stack.addDirective(directive);      
    }

    private  List getIncludeFiles(String foundInclude) {
        File check = new File(foundInclude);        
        File root = new File(check.isAbsolute() ? Glob.rootPortion(foundInclude) : serverRootPath);
                 
        return Glob.match(root, foundInclude);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy