KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > piagetproject > topcomponent > SessionFileWrapper


1 /*
2  * SessionFileWrapper.java
3  *
4  * Created on July 1, 2005, 11:42 AM
5  *
6  * To change this template, choose Tools | Options and locate the template under
7  * the Source Creation and Management node. Right-click the template and choose
8  * Open. You can then make changes to the template in the Source Editor.
9  */

10
11 package org.netbeans.modules.piagetproject.topcomponent;
12 import java.io.File JavaDoc;
13 import java.io.FileInputStream JavaDoc;
14 import java.io.FileNotFoundException JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.util.Enumeration JavaDoc;
17 import java.util.Properties JavaDoc;
18 import org.netbeans.modules.piagetproject.treestructure.SessionNode;
19 import org.netbeans.modules.piagetproject.property.Property;
20
21 /**
22  *
23  * @author loicsegapelli
24  */

25 public class SessionFileWrapper {
26     
27     static File JavaDoc f;
28     static Properties JavaDoc p;
29     static SessionTopComponent tc;
30     private static String JavaDoc level, username;
31     
32     /** Creates a new instance of SessionFileWrapper */
33     public static String JavaDoc wrapFile(String JavaDoc filepath, String JavaDoc myUsername, String JavaDoc myLevel) {
34         username = myUsername;
35         level = myLevel;
36         f = new File JavaDoc(filepath);
37         
38         FileInputStream JavaDoc in = null;
39         try{
40             in = new FileInputStream JavaDoc(f);
41         }catch(FileNotFoundException JavaDoc e){
42             e.printStackTrace(System.out);
43         }
44         
45         Properties JavaDoc p = new Properties JavaDoc();
46         try{
47             p.load(in);
48             Enumeration JavaDoc en = p.keys();
49             Property pd;
50             while(en.hasMoreElements()){
51                 String JavaDoc key = (String JavaDoc) en.nextElement();
52                 Property.addProperty(key, p.getProperty(key));
53             }
54         } catch(IOException JavaDoc e){
55             e.printStackTrace(System.out);
56         }
57         
58         /*now dealing with the log filename*/
59         // filepath = path/date.parsed
60
int sepIndex = filepath.lastIndexOf(File.separator);
61         
62         //filename = date.parsed
63
String JavaDoc filename = filepath.substring(sepIndex+1);
64         
65         String JavaDoc [] parameters = filename.split("\\W");
66         long l = Long.parseLong(parameters[0]);
67         String JavaDoc date = SessionNode.prettyDate(l);
68         String JavaDoc key = Property.LOG_FILE + date + ", " + level + ": ";
69         Property.addProperty(key, username);
70         
71         return date;
72     }
73     
74     
75 }
76
Popular Tags