added tests and changed the java package names
[hudson-sidebar-announcer-plugin:hudson-sidebar-announcer-plugin.git] / sidebar-announcer / src / main / java / hudson / plugins / AnnouncerWidget.java
1 package hudson.plugins;
2 import hudson.Extension;
3 import hudson.widgets.Widget;
4
5 import java.io.BufferedReader;
6 import java.io.FileNotFoundException;
7 import java.io.FileReader;
8 import java.io.IOException;
9
10 /**
11  * Created by IntelliJ IDEA.
12  * User: JuhaH
13  * Date: Nov 3, 2010
14  * Time: 2:50:08 PM
15  */
16
17 @Extension
18 public class AnnouncerWidget extends Widget {
19
20
21     
22     public AnnouncerWidget()
23     {
24         
25     }
26
27     public String updateFromFile()
28     {
29         String eol = System.getProperty( "line.separator" );
30         String content = this.readfile(AnnounceWidgetHelperPlugin.getFileLoc());
31         content = content.replaceAll(eol,"<br>");
32
33         System.out.println(content);
34
35
36         return content;
37     }
38
39     private String readfile(String file)
40     {
41         if (file == null)
42             return "";
43
44         String eol = System.getProperty( "line.separator" );
45         StringBuilder result = new StringBuilder();
46           try {
47             BufferedReader input =  new BufferedReader(new FileReader(file));
48             String line;
49             while ((line = input.readLine()) != null) {
50                 result.append(line).append(eol);
51
52             }
53
54         } catch (FileNotFoundException e) {
55             System.out.println("File Not Found:"+file);
56             return "";
57         } catch (IOException e) {
58             System.out.println("IO Exception");
59             return "";
60         }
61
62         return result.toString();
63     }
64
65 }