1 31 package org.blojsom.plugin.limiter; 32 33 import org.blojsom.blog.Blog; 34 import org.blojsom.blog.Entry; 35 import org.blojsom.plugin.Plugin; 36 import org.blojsom.plugin.PluginException; 37 import org.blojsom.util.BlojsomUtils; 38 39 import javax.servlet.http.HttpServletRequest ; 40 import javax.servlet.http.HttpServletResponse ; 41 import java.util.ArrayList ; 42 import java.util.List ; 43 import java.util.Map ; 44 45 56 public class PreviewPlugin implements Plugin { 57 58 private static final String PLUGIN_PREVIEW_TITLE_PREFIX_IP = "plugin-preview-title-prefix"; 59 private static final String PLUGIN_PREVIEW_PREVIEW_PASSWORD_IP = "plugin-preview-preview-password"; 60 61 private static final String DEFAULT_TITLE_PREFIX = "PREVIEW"; 62 private static final String DEFAULT_PREVIEW_PASSWORD = "true"; 63 64 67 private static final String PREVIEW_PARAM = "preview"; 68 69 72 public PreviewPlugin() { 73 } 74 75 81 public void init() throws PluginException { 82 } 83 84 95 public Entry[] process(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Blog blog, Map context, Entry[] entries) throws PluginException { 96 String titlePrefix = blog.getProperty(PLUGIN_PREVIEW_TITLE_PREFIX_IP); 97 if (BlojsomUtils.checkNullOrBlank(titlePrefix)) { 98 titlePrefix = DEFAULT_TITLE_PREFIX; 99 } 100 101 String previewPassword = blog.getProperty(PLUGIN_PREVIEW_PREVIEW_PASSWORD_IP); 102 if (BlojsomUtils.checkNullOrBlank(previewPassword)) { 103 previewPassword = DEFAULT_PREVIEW_PASSWORD; 104 } 105 106 String previewParam = httpServletRequest.getParameter(PREVIEW_PARAM); 108 if (previewParam != null && previewParam.equals(previewPassword)) { 109 return entries; 110 } else { 111 List postedEntries = new ArrayList (entries.length); 112 for (int i = 0; i < entries.length; i++) { 113 Entry entry = entries[i]; 114 if (entry != null && entry.getTitle() != null && !entry.getTitle().startsWith(titlePrefix)) { 115 postedEntries.add(entry); 116 } 117 } 118 119 return (Entry[]) postedEntries.toArray(new Entry[postedEntries.size()]); 120 } 121 } 122 123 128 public void cleanup() throws PluginException { 129 } 130 131 136 public void destroy() throws PluginException { 137 } 138 } 139 | Popular Tags |