1 32 33 package com.jeantessier.diff; 34 35 import java.io.*; 36 import java.util.*; 37 38 import org.apache.log4j.*; 39 40 public class ListBasedValidator implements Validator { 41 private Collection allowedElements = new HashSet(); 42 43 public ListBasedValidator() { 44 } 46 47 public ListBasedValidator(String filename) throws IOException { 48 load(filename); 49 } 50 51 public ListBasedValidator(File file) throws IOException { 52 load(file); 53 } 54 55 public ListBasedValidator(BufferedReader in) throws IOException { 56 load(in); 57 } 58 59 public void load(String filename) throws IOException { 60 BufferedReader in = null; 61 62 try { 63 in = new BufferedReader(new FileReader(filename)); 64 load(in); 65 } catch (FileNotFoundException ex) { 66 } finally { 68 if (in != null) { 69 in.close(); 70 } 71 } 72 } 73 74 public void load(File file) throws IOException { 75 BufferedReader in = null; 76 77 try { 78 in = new BufferedReader(new FileReader(file)); 79 load(in); 80 } catch (FileNotFoundException ex) { 81 } finally { 83 if (in != null) { 84 in.close(); 85 } 86 } 87 } 88 89 public void load(BufferedReader in) throws IOException { 90 String line; 91 while ((line = in.readLine()) != null) { 92 if (line.length() > 0) { 93 line = line.trim(); 94 int pos = line.lastIndexOf(" ["); 95 if (pos != -1) { 96 allowedElements.add(line.substring(0, pos)); 97 } else { 98 allowedElements.add(line); 99 } 100 } 101 } 102 } 103 104 public boolean isPackageAllowed(String name) { 105 return isAllowed(name); 106 } 107 108 public boolean isClassAllowed(String name) { 109 return isAllowed(name); 110 } 111 112 public boolean isFeatureAllowed(String name) { 113 return isAllowed(name); 114 } 115 116 public boolean isAllowed(String name) { 117 Logger.getLogger(getClass()).debug("IsAllowed(\"" + name + "\")"); 118 Logger.getLogger(getClass()).debug("allowed_elements.size() = " + allowedElements.size()); 119 Logger.getLogger(getClass()).debug("allowed_elements.contains(\"" + name + "\") = " + allowedElements.contains(name)); 120 return allowedElements.size() == 0 || allowedElements.contains(name); 121 } 122 } 123 | Popular Tags |