updated pom.xml
[hudson-sidebar-announcer-plugin:hudson-sidebar-announcer-plugin.git] / sidebar-announcer / src / main / java / org / foobar / bar / AnnouncerWidget.java
1 package org.foobar.bar;
2 import hudson.Extension;
3 import hudson.model.AbstractProject;
4 import hudson.model.Describable;
5 import hudson.model.Descriptor;
6 import hudson.model.Hudson;
7 import hudson.tasks.BuildStepDescriptor;
8 import hudson.tasks.Builder;
9 import hudson.util.FormValidation;
10 import hudson.widgets.Widget;
11 import net.sf.json.JSONObject;
12 import org.kohsuke.stapler.DataBoundConstructor;
13 import org.kohsuke.stapler.QueryParameter;
14 import org.kohsuke.stapler.StaplerRequest;
15
16 import javax.servlet.ServletException;
17 import java.io.BufferedReader;
18 import java.io.FileNotFoundException;
19 import java.io.FileReader;
20 import java.io.IOException;
21
22 /**
23  * Created by IntelliJ IDEA.
24  * User: juhahein
25  * Date: Nov 3, 2010
26  * Time: 2:50:08 PM
27  * To change this template use File | Settings | File Templates.
28  */
29
30 @Extension
31 public class AnnouncerWidget extends Widget {
32
33
34     
35     public AnnouncerWidget()
36     {
37         
38     }
39
40     public String updateFromFile()
41     {
42         String eol = System.getProperty( "line.separator" );
43         String content = this.readfile(AnnounceWidgetHelperPlugin.getFileLoc());
44         content = content.replaceAll(eol,"<br>");
45
46         System.out.println(content);
47
48
49         return content;
50     }
51
52     private String readfile(String file)
53     {
54         String eol = System.getProperty( "line.separator" );
55         StringBuilder result = new StringBuilder();
56           try {
57             BufferedReader input =  new BufferedReader(new FileReader(file));
58             String line = null;
59             while ((line = input.readLine()) != null) {
60                 result.append(line+eol);
61
62             }
63
64         } catch (FileNotFoundException e) {
65             System.out.println("File Not Found:"+file);
66             return "";
67         } catch (IOException e) {
68             System.out.println("IO Exception");
69             return "";
70         }
71
72         return result.toString();
73     }
74
75 }