[slf4j-dev] svn commit: r821 - slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter

jncharpin at slf4j.org jncharpin at slf4j.org
Fri Jun 8 17:22:51 CEST 2007


Author: jncharpin
Date: Fri Jun  8 17:22:51 2007
New Revision: 821

Added:
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/PatternWrapper.java
Removed:
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Converterold.java
Modified:
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/AbstractMatcher.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Converter.java
   slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/JCLMatcher.java

Log:
on going work  

Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/AbstractMatcher.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/AbstractMatcher.java	(original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/AbstractMatcher.java	Fri Jun  8 17:22:51 2007
@@ -1,7 +1,7 @@
 package org.slf4j.converter;
 
-import java.util.HashMap;
 import java.util.Iterator;
+import java.util.TreeMap;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -11,10 +11,13 @@
 
   protected Logger logger;
 
-  protected HashMap<Pattern, String> rulesMap;
+  protected TreeMap<PatternWrapper, String> rulesMap;
 
   protected Writer writer;
 
+  public AbstractMatcher() {
+  }
+
   public static AbstractMatcher getMatcherImpl() {
     // TODO criterias
     return new JCLMatcher();
@@ -25,23 +28,32 @@
   }
 
   public void matches(String text) {
+    PatternWrapper patternWrapper;
     Pattern pattern;
     Matcher matcher;
     String replacement;
     Iterator rulesIter = rulesMap.keySet().iterator();
     boolean found = false;
-    while (rulesIter.hasNext()) {      
-      pattern = (Pattern) rulesIter.next();
-      matcher = pattern.matcher(text);//
-      if (matcher.find()) {        
-        logger.info("found " + text);
-        replacement = (String) rulesMap.get(pattern);
-        writer.rewrite(matcher, replacement);        
-        found = true;  
+    while (rulesIter.hasNext()) {
+      patternWrapper = (PatternWrapper) rulesIter.next();
+      pattern = patternWrapper.getPattern();      
+      matcher = pattern.matcher(text);
+      if (matcher.matches()) {
+        logger.info("match " + text);
+        replacement = (String) rulesMap.get(patternWrapper);
+        writer.rewrite(matcher, replacement);
+        found = true;
         break;
-      }      
+      } 
+//      else if (matcher.find()) {
+//        logger.info("found " + text + " pattern " + pattern.toString());
+//        replacement = (String) rulesMap.get(patternWrapper);
+//        writer.rewrite(matcher, replacement);
+//        found = true;
+//        break;
+//      }
     }
-    if(!found){
+    if (!found) {
       writer.write(text);
     }
   }

Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Converter.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Converter.java	(original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/Converter.java	Fri Jun  8 17:22:51 2007
@@ -187,7 +187,7 @@
     while (itFile.hasNext()) {
       File currentFile = itFile.next();
       File newFile = new File(currentFile.getAbsolutePath()+"new");
-      logger.info("reading file " + currentFile.getAbsolutePath());
+      //logger.info("reading file " + currentFile.getAbsolutePath());
       try {
         boolean isEmpty = false;
         writer.initFileWriter(newFile);

Modified: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/JCLMatcher.java
==============================================================================
--- slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/JCLMatcher.java	(original)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/JCLMatcher.java	Fri Jun  8 17:22:51 2007
@@ -1,5 +1,6 @@
 package org.slf4j.converter;
 
+import java.util.TreeMap;
 import java.util.HashMap;
 import java.util.regex.Pattern;
 
@@ -7,15 +8,28 @@
 
 public class JCLMatcher extends AbstractMatcher {
 
+  private static PatternWrapper p1 =  new PatternWrapper("1",Pattern.compile("import org.apache.commons.logging.LogFactory;"));
+  private static PatternWrapper p2 =  new PatternWrapper("2",Pattern.compile("import org.apache.commons.logging.Log"));
+  private static PatternWrapper p3 =  new PatternWrapper("3",Pattern.compile("LogFactory.getFactory().getInstance"));
+  private static PatternWrapper p4 =  new PatternWrapper("4",Pattern.compile("LogFactory.getLog"));
+  private static PatternWrapper p5 =  new PatternWrapper("5",Pattern.compile("Log"));
+//private static Pattern p6 = new PatternWrapper("6",Pattern.compile("fatal\("));
+//private static Pattern p7 = new PatternWrapper("7",Pattern.compile("isFatalEnabled\("));
+  
   public JCLMatcher() {
     super();
-    logger = LoggerFactory.getLogger(JCLMatcher.class);
+    logger = LoggerFactory.getLogger(JCLMatcher.class);    
     initRules();
   }
 
-  protected void initRules() {
-    rulesMap = new HashMap<Pattern, String>();
-    rulesMap.put(Pattern.compile("import org.slf4j.Logger;"), "import org.toto.Log;");
-    rulesMap.put(Pattern.compile("Logger"), "Log");    
+  protected void initRules() {    
+    rulesMap = new TreeMap<PatternWrapper, String>();
+    rulesMap.put(p1,"import org.slf4j.LoggerFactory;");
+    rulesMap.put(p2,"import org.slf4j.Logger;");    
+    rulesMap.put(p3,"LoggerFactory.getLogger");
+    rulesMap.put(p4,"LoggerFactory.getLogger");
+    rulesMap.put(p5,"Logger");
+//    rulesMap.put(p6,"error(");
+//    rulesMap.put(p7,"isErrorEnabled(");    
   }
 }

Added: slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/PatternWrapper.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-converter/src/main/java/org/slf4j/converter/PatternWrapper.java	Fri Jun  8 17:22:51 2007
@@ -0,0 +1,27 @@
+package org.slf4j.converter;
+
+import java.util.regex.Pattern;
+
+public class PatternWrapper implements Comparable {
+
+  private String  index;
+  private Pattern pattern;
+  
+  public PatternWrapper(String index, Pattern pattern){
+    this.index = index;
+    this.pattern = pattern;
+  }
+  
+  public String getIndex(){
+    return index;
+  }
+  
+  public Pattern getPattern(){
+    return pattern;
+  }
+
+  public int compareTo(Object o) {    
+    String oIndex = ((PatternWrapper)o).index;  
+    return this.index.compareTo(oIndex);
+  }
+}



More information about the slf4j-dev mailing list