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

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

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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ApacheConfigReader {
    private static final String EMPTY_LINE = "^[\t ]*$";
    private static final Pattern emptyLinePattern = Pattern.compile(EMPTY_LINE);
    private static final Log log = LogFactory.getLog(ApacheConfigReader.class);

    public static void buildTree(String path, ApacheParser parser) {
        searchFile(path, parser);
    }

    public static void searchFile(String path, ApacheParser parser) {
        File configFile = new File(path);
        if (!configFile.exists()) {
            log.warn("Apache configuration file " + path + " was not found.");
            throw new ApacheParserException("Apache configuration file " + path + " was not found.");
        }

        BufferedReader br = null;

        try {
            FileInputStream fstream = new FileInputStream(configFile);
            br = new BufferedReader(new InputStreamReader(fstream));
            String strLine;

            while ((strLine = br.readLine()) != null) {
                Matcher matcher = emptyLinePattern.matcher(strLine);
                if (!matcher.matches()) {
                    ApacheDirective dir = new ApacheDirective(strLine);
                    dir.setFile(path);
                    String name = dir.getName();
                    if (!name.equals("#")) {
                        if (name.startsWith("




© 2015 - 2024 Weber Informatics LLC | Privacy Policy