Package us.codecraft.blackhole.answer

Examples of us.codecraft.blackhole.answer.DomainPatternsContainer


  private Logger logger = Logger.getLogger(getClass());

  public void readConfig(String filename) {
    try {
      DomainPatternsContainer domainPatternsContainer = new DomainPatternsContainer();
            DomainPatternsContainer nsDomainPatternContainer = new DomainPatternsContainer();
      DoubleKeyMap<String, Pattern, String> customAnswerPatternsTemp = new DoubleKeyMap<String, Pattern, String>(
          new ConcurrentHashMap<String, Map<Pattern, String>>(), LinkedHashMap.class);
      DoubleKeyMap<String, String, String> customAnswerTextsTemp = new DoubleKeyMap<String, String, String>(
          new ConcurrentHashMap<String, Map<String, String>>(), HashMap.class);
      BufferedReader bufferedReader = new BufferedReader(new FileReader(filename));
      String line = null;
      while ((line = bufferedReader.readLine()) != null) {
        ZonesPattern zonesPattern = ZonesPattern.parse(line);
        if (zonesPattern == null) {
          continue;
        }
        try {
          if (zonesPattern.getUserIp() == null) {
            for (Pattern pattern : zonesPattern.getPatterns()) {
              domainPatternsContainer.getDomainPatterns().put(pattern, zonesPattern.getTargetIp());
            }
            for (String text : zonesPattern.getTexts()) {
              domainPatternsContainer.getDomainTexts().put(text, zonesPattern.getTargetIp());
            }
          } else {
            for (Pattern pattern : zonesPattern.getPatterns()) {
              customAnswerPatternsTemp.put(zonesPattern.getUserIp(), pattern, zonesPattern.getTargetIp());
            }
            for (String text : zonesPattern.getTexts()) {
              customAnswerTextsTemp.put(zonesPattern.getUserIp(), text, zonesPattern.getTargetIp());
            }
          }
          logger.info("read config success:\t" + line);
        } catch (Exception e) {
          logger.warn("parse config line error:\t" + line + "\t" , e);
        }
        // For NS
        if (line.startsWith("NS")) {
          line = StringUtils.removeStartIgnoreCase(line, "NS").trim();
                    zonesPattern = ZonesPattern.parse(line);
                    if (zonesPattern == null) {
                        continue;
                    }
                    try {
                        for (Pattern pattern : zonesPattern.getPatterns()) {
                            nsDomainPatternContainer.getDomainPatterns().put(pattern,zonesPattern.getTargetIp());
                        }
                        for (String text : zonesPattern.getTexts()) {
                            nsDomainPatternContainer.getDomainTexts().put(text,zonesPattern.getTargetIp());
                        }
                        logger.info("read config success:\t" + line);
                    } catch (Exception e) {
                        logger.warn("parse config line error:\t" + line + "\t" + e);
                    }
View Full Code Here

TOP

Related Classes of us.codecraft.blackhole.answer.DomainPatternsContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.