1 |
|
---|
2 | /**
|
---|
3 | * Title: Visualisation<p>
|
---|
4 | * Description: An implementation of some search result visualisations
|
---|
5 | * <p>
|
---|
6 | * Copyright: Copyright (c) Matthew Carey<p>
|
---|
7 | * Company: <p>
|
---|
8 | * @author Matthew Carey
|
---|
9 | * @version 1.0
|
---|
10 | */
|
---|
11 | package vishnu.testvis.evaluate;
|
---|
12 | import vishnu.testvis.object.*;
|
---|
13 | import vishnu.testvis.visual.*;
|
---|
14 | import java.io.*;
|
---|
15 | import java.util.*;
|
---|
16 | import java.text.*;
|
---|
17 |
|
---|
18 | public class Logging
|
---|
19 | {
|
---|
20 | private Vishnu displayFrame;
|
---|
21 | private String _id;
|
---|
22 | String filename;
|
---|
23 | PrintWriter outlog;
|
---|
24 | long startmilli;
|
---|
25 |
|
---|
26 | public Logging(String id, String path, Vishnu d)
|
---|
27 | {
|
---|
28 | displayFrame = d;
|
---|
29 | DateFormat longTime = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL);
|
---|
30 | DateFormat shortTime = DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT);
|
---|
31 | Date todayDate = new Date();
|
---|
32 | String node = replace_chars(
|
---|
33 | replace_chars(id + "_" + shortTime.format(new Date()) + ".xml"," ","_"),
|
---|
34 | "/:","-");
|
---|
35 | if (null==path)filename = node;
|
---|
36 | else filename = path + node;
|
---|
37 | System.out.println(filename);
|
---|
38 | //Properties p = d.getProperties();
|
---|
39 | _id = id;
|
---|
40 | long Time;
|
---|
41 | try
|
---|
42 | {
|
---|
43 | /*outlog =
|
---|
44 | new PrintWriter(
|
---|
45 | new BufferedWriter(
|
---|
46 | new FileWriter(filename)));*/
|
---|
47 | File target = new File(filename);
|
---|
48 | FileWriter fw = new FileWriter(target);
|
---|
49 | outlog = new PrintWriter(fw,true);
|
---|
50 |
|
---|
51 | outlog.println("<LOG>");
|
---|
52 | startmilli=System.currentTimeMillis();
|
---|
53 | log("ID",_id);
|
---|
54 | log("DATE_AND_TIME",longTime.format(todayDate));
|
---|
55 | }
|
---|
56 | catch(Exception e)
|
---|
57 | {
|
---|
58 | e.printStackTrace();
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | private String replace_chars(String target,String oldch, String newch)
|
---|
63 | {
|
---|
64 | StringTokenizer tokenizer = new StringTokenizer(target,oldch);
|
---|
65 | StringBuffer buff = new StringBuffer();
|
---|
66 |
|
---|
67 | while(tokenizer.hasMoreElements())
|
---|
68 | {
|
---|
69 | if(buff.length()>0)
|
---|
70 | buff.append(newch);
|
---|
71 | buff.append(tokenizer.nextToken());
|
---|
72 | }
|
---|
73 | return buff.toString();
|
---|
74 | }
|
---|
75 |
|
---|
76 | public void log(String tag, String value)
|
---|
77 | {
|
---|
78 | String out ="<" + tag + " MILLISECS = \"" +
|
---|
79 | Long.toString(System.currentTimeMillis()-startmilli) + "\">" + value + "</" + tag + ">";
|
---|
80 | outlog.println(out);
|
---|
81 | }
|
---|
82 |
|
---|
83 |
|
---|
84 | public void log(String tag)
|
---|
85 | {
|
---|
86 | String out ="<" + tag + " MILLISECS = \"" +
|
---|
87 | Long.toString(System.currentTimeMillis()-startmilli) + "\"/>";
|
---|
88 | outlog.println(out);
|
---|
89 | }
|
---|
90 |
|
---|
91 | public void endsection(String tag)
|
---|
92 | {
|
---|
93 | outlog.println("</"+tag+">");
|
---|
94 | }
|
---|
95 |
|
---|
96 | public void startsection(String tag)
|
---|
97 | {
|
---|
98 | outlog.println("<"+tag+">");
|
---|
99 | }
|
---|
100 |
|
---|
101 | public void logout()
|
---|
102 | {
|
---|
103 | log("LOGOUT",_id);
|
---|
104 | outlog.println("</LOG>");
|
---|
105 | outlog.close();
|
---|
106 | }
|
---|
107 | }
|
---|