| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 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 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
public class PluginProperties { |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | 4 | private static final Log log = LogFactory.getLog(PluginProperties.class); |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
private Properties properties; |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
private Blog blog; |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | 2720 | public PluginProperties(Blog blog) { |
| 72 | 2720 | this.blog = blog; |
| 73 | 2720 | loadProperties(); |
| 74 | 2720 | } |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
private void loadProperties() { |
| 80 | |
try { |
| 81 | 2720 | properties = new Properties(); |
| 82 | 2720 | properties.setProperty(ContentSpamListener.REGEX_LIST_KEY, ContentSpamListener.DEFAULT_REGEX_LIST); |
| 83 | 2720 | properties.setProperty(ContentSpamListener.THRESHOLD_KEY, "" + ContentSpamListener.DEFAULT_THRESHOLD); |
| 84 | 2720 | properties.setProperty(LinkSpamListener.COMMENT_THRESHOLD_KEY, "" + LinkSpamListener.DEFAULT_THRESHOLD); |
| 85 | 2720 | properties.setProperty(LinkSpamListener.TRACKBACK_THRESHOLD_KEY, "" + LinkSpamListener.DEFAULT_THRESHOLD); |
| 86 | 2720 | properties.setProperty(SpamScoreListener.COMMENT_THRESHOLD_KEY, "" + SpamScoreListener.DEFAULT_THRESHOLD); |
| 87 | 2720 | properties.setProperty(SpamScoreListener.TRACKBACK_THRESHOLD_KEY, "" + SpamScoreListener.DEFAULT_THRESHOLD); |
| 88 | |
|
| 89 | 2720 | File propertiesFile = new File(blog.getPluginPropertiesFile()); |
| 90 | 2720 | if (!propertiesFile.exists()) { |
| 91 | 2720 | return; |
| 92 | |
} |
| 93 | |
|
| 94 | 0 | FileInputStream fin = new FileInputStream(propertiesFile); |
| 95 | 0 | properties.load(fin); |
| 96 | 0 | fin.close(); |
| 97 | 0 | } catch (FileNotFoundException fnfe) { |
| 98 | |
|
| 99 | 0 | } catch (IOException e) { |
| 100 | 0 | log.error(e.getMessage()); |
| 101 | 0 | } |
| 102 | 0 | } |
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
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 | 0 | } |
| 121 | |
|
| 122 | 0 | return buf.toString(); |
| 123 | |
} |
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
public boolean hasProperty(String name) { |
| 132 | 772 | return properties.containsKey(name); |
| 133 | |
} |
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
public String getProperty(String name) { |
| 142 | 2048 | return properties.getProperty(name); |
| 143 | |
} |
| 144 | |
|
| 145 | |
public Properties getProperties() { |
| 146 | 0 | return properties; |
| 147 | |
} |
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
public void setProperty(String name, String value) { |
| 156 | 556 | properties.setProperty(name, value); |
| 157 | 556 | } |
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
public void store() { |
| 163 | |
try { |
| 164 | 140 | FileOutputStream fout = new FileOutputStream(blog.getPluginPropertiesFile()); |
| 165 | 140 | if (fout != null) { |
| 166 | 140 | properties.store(fout, "Plugin properties"); |
| 167 | 140 | fout.flush(); |
| 168 | 140 | fout.close(); |
| 169 | |
} |
| 170 | 0 | } catch (FileNotFoundException fnfe) { |
| 171 | 0 | } catch (IOException e) { |
| 172 | 0 | log.error(e.getMessage()); |
| 173 | 140 | } |
| 174 | 140 | } |
| 175 | |
|
| 176 | |
} |