Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../img/srcFileCovDistChart6.png 36% of files have more coverage
39   176   15   4,88
6   77   0,38   8
8     1,88  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  PluginProperties       Line # 49 39 0% 15 23 56,6% 0.5660377
 
  (190)
 
1    /*
2    * Copyright (c) 2003-2006, Simon Brown
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * - Redistributions of source code must retain the above copyright
9    * notice, this list of conditions and the following disclaimer.
10    *
11    * - Redistributions in binary form must reproduce the above copyright
12    * notice, this list of conditions and the following disclaimer in
13    * the documentation and/or other materials provided with the
14    * distribution.
15    *
16    * - Neither the name of Pebble nor the names of its contributors may
17    * be used to endorse or promote products derived from this software
18    * without specific prior written permission.
19    *
20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30    * POSSIBILITY OF SUCH DAMAGE.
31    */
32    package net.sourceforge.pebble;
33   
34    import net.sourceforge.pebble.domain.Blog;
35    import net.sourceforge.pebble.event.response.ContentSpamListener;
36    import net.sourceforge.pebble.event.response.SpamScoreListener;
37    import net.sourceforge.pebble.event.response.LinkSpamListener;
38    import org.apache.commons.logging.Log;
39    import org.apache.commons.logging.LogFactory;
40   
41    import java.io.*;
42    import java.util.*;
43   
44    /**
45    * Contains properties that can be used by Pebble plugins.
46    *
47    * @author Simon Brown
48    */
 
49    public class PluginProperties {
50   
51    /**
52    * the log used by this class
53    */
54    private static final Log log = LogFactory.getLog(PluginProperties.class);
55   
56    /**
57    * the Properties object that backs this instance
58    */
59    private Properties properties;
60   
61    /**
62    * the owning blog
63    */
64    private Blog blog;
65   
66    /**
67    * Creates a new instance with the specified owning blog.
68    *
69    * @param blog the owning Blog instance
70    */
 
71  1334 toggle public PluginProperties(Blog blog) {
72  1334 this.blog = blog;
73  1334 loadProperties();
74    }
75   
76    /**
77    * Helper method to load the properties from disk.
78    */
 
79  1334 toggle private void loadProperties() {
80  1334 try {
81  1334 properties = new Properties();
82  1334 properties.setProperty(ContentSpamListener.REGEX_LIST_KEY, ContentSpamListener.DEFAULT_REGEX_LIST);
83  1334 properties.setProperty(ContentSpamListener.THRESHOLD_KEY, "" + ContentSpamListener.DEFAULT_THRESHOLD);
84  1334 properties.setProperty(LinkSpamListener.COMMENT_THRESHOLD_KEY, "" + LinkSpamListener.DEFAULT_THRESHOLD);
85  1334 properties.setProperty(LinkSpamListener.TRACKBACK_THRESHOLD_KEY, "" + LinkSpamListener.DEFAULT_THRESHOLD);
86  1334 properties.setProperty(SpamScoreListener.COMMENT_THRESHOLD_KEY, "" + SpamScoreListener.DEFAULT_THRESHOLD);
87  1334 properties.setProperty(SpamScoreListener.TRACKBACK_THRESHOLD_KEY, "" + SpamScoreListener.DEFAULT_THRESHOLD);
88   
89  1334 File propertiesFile = new File(blog.getPluginPropertiesFile());
90  1334 if (!propertiesFile.exists()) {
91  1334 return;
92    }
93   
94  0 FileInputStream fin = new FileInputStream(propertiesFile);
95  0 properties.load(fin);
96  0 fin.close();
97    } catch (FileNotFoundException fnfe) {
98    // do nothing - there are no plugin properties to load
99    } catch (IOException e) {
100  0 log.error(e.getMessage());
101    }
102    }
103   
104    /**
105    * Gets properties file as a String in the format it is saved on disk.
106    *
107    * @return a String
108    */
 
109  0 toggle public String getPropertiesAsString() {
110  0 StringBuffer buf = new StringBuffer();
111  0 List keys = new ArrayList(properties.keySet());
112  0 Collections.sort(keys);
113  0 Iterator it = keys.iterator();
114  0 while (it.hasNext()) {
115  0 String key = (String) it.next();
116  0 buf.append(key);
117  0 buf.append("=");
118  0 buf.append(properties.getProperty(key));
119  0 buf.append(System.getProperty("line.separator"));
120    }
121   
122  0 return buf.toString();
123    }
124   
125    /**
126    * Determines whether a property with the specified name exists.
127    *
128    * @param name the name of th eproperty to test for
129    * @return true if the property exists, false otherwise
130    */
 
131  386 toggle public boolean hasProperty(String name) {
132  386 return properties.containsKey(name);
133    }
134   
135    /**
136    * Gets the named property.
137    *
138    * @param name the name of the property
139    * @return the value of the property, or null if it doesn't exist
140    */
 
141  1024 toggle public String getProperty(String name) {
142  1024 return properties.getProperty(name);
143    }
144   
 
145  0 toggle public Properties getProperties() {
146  0 return properties;
147    }
148   
149    /**
150    * Sets the named property.
151    *
152    * @param name the name of the property
153    * @param value the value of the property
154    */
 
155  278 toggle public void setProperty(String name, String value) {
156  278 properties.setProperty(name, value);
157    }
158   
159    /**
160    * Helper method to store the properties to disk.
161    */
 
162  70 toggle public void store() {
163  70 try {
164  70 FileOutputStream fout = new FileOutputStream(blog.getPluginPropertiesFile());
165  70 if (fout != null) {
166  70 properties.store(fout, "Plugin properties");
167  70 fout.flush();
168  70 fout.close();
169    }
170    } catch (FileNotFoundException fnfe) {
171    } catch (IOException e) {
172  0 log.error(e.getMessage());
173    }
174    }
175   
176    }