KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > piaget > analyze > Analyzer


1 /*
2  * Main.java
3  *
4  * Created on April 12, 2005, 7:29 PM
5  */

6
7 package org.netbeans.modules.piaget.analyze;
8
9 import java.io.File JavaDoc;
10 import java.io.FileInputStream JavaDoc;
11 import java.io.FileNotFoundException JavaDoc;
12 import java.io.FileWriter JavaDoc;
13 import java.io.IOException JavaDoc;
14 import java.util.Properties JavaDoc;
15
16 /**
17  *
18  * @author loicsegapelli
19  */

20 public class Analyzer {
21     
22     private static StringBuffer JavaDoc commentBuffer, propertyBuffer;
23     
24     public static void writeComment(String JavaDoc s){
25         commentBuffer.append("# " + s + "\n");
26     }
27     
28     public static void writeProperty(String JavaDoc key, String JavaDoc value){
29         propertyBuffer.append(key + "=" + value + "\n");
30     }
31     
32     public static void analyze(File JavaDoc userfile) {
33         File JavaDoc sessionFiles [] = userfile.listFiles();
34         
35         for(int i=0; i<sessionFiles.length; i++){
36             String JavaDoc outFilename = sessionFiles[i].getAbsolutePath();
37             int index = outFilename.lastIndexOf("session");
38             
39             // layout file? Case to treat...
40
if(index < 0) continue;
41             
42             outFilename = outFilename.substring(0,index) + "parsed";
43             
44             commentBuffer = new StringBuffer JavaDoc();
45             propertyBuffer = new StringBuffer JavaDoc();
46             
47             session(sessionFiles[i]);
48             
49             try{
50                 File JavaDoc outFile = new File JavaDoc(outFilename);
51                 String JavaDoc comments = commentBuffer.toString();
52                 String JavaDoc properties = propertyBuffer.toString();
53                 
54                 FileWriter JavaDoc out = new FileWriter JavaDoc(outFile);
55                 out.write(comments);
56                 out.write(properties);
57                 out.write("\n");
58                 out.flush();
59                 out.close();
60             } catch(IOException JavaDoc e){
61                 e.printStackTrace();
62             }
63         }
64     }
65     
66     private static void session(File JavaDoc f){
67         File JavaDoc [] content = f.listFiles();
68         for(int i=0; i<content.length; i++){
69             String JavaDoc name = content[i].getName();
70             if(name.endsWith("COR.log")){
71                 // nothing yet...
72
}else if(name.endsWith("DOC.log")){
73                 new DOCAnalyzer(content[i]);
74             }else if(name.endsWith("TCR.log")){
75                 new TCRAnalyzer(content[i]);
76             }else if(name.endsWith("WM.log")){
77                 new WMAnalyzer(content[i]);
78             }else{
79                 System.out.println("UNEXPECTED CASE:"+content[i].getName());
80             }
81         }
82     }
83 }
Popular Tags