1 31 package org.blojsom.plugin.textile; 32 33 import net.sf.textile4j.Textile; 34 import org.apache.commons.logging.Log; 35 import org.apache.commons.logging.LogFactory; 36 import org.blojsom.blog.Blog; 37 import org.blojsom.blog.Entry; 38 import org.blojsom.plugin.Plugin; 39 import org.blojsom.plugin.PluginException; 40 import org.blojsom.util.BlojsomUtils; 41 42 import javax.servlet.http.HttpServletRequest ; 43 import javax.servlet.http.HttpServletResponse ; 44 import java.util.Map ; 45 46 56 public class TextilePlugin implements Plugin { 57 58 private static final String PLUGIN_TEXTILE_PROCESS_ALL_ENTRIES = "plugin-textile-process-all-entries"; 59 60 63 public static final String METADATA_RUN_TEXTILE = "run-textile"; 64 65 68 public static final String TEXTILE_EXTENSION = ".textile"; 69 70 73 private Textile _textile; 74 75 78 private Log _logger = LogFactory.getLog(TextilePlugin.class); 79 80 85 public void init() throws PluginException { 86 _textile = new Textile(); 87 } 88 89 100 public Entry[] process(HttpServletRequest httpServletRequest, 101 HttpServletResponse httpServletResponse, 102 Blog blog, 103 Map context, 104 Entry[] entries) throws PluginException { 105 for (int x = 0; x < entries.length; x++) { 106 Entry entry = entries[x]; 107 if (entry.getPostSlug().endsWith(TEXTILE_EXTENSION) || BlojsomUtils.checkMapForKey(entry.getMetaData(), METADATA_RUN_TEXTILE) 108 || Boolean.valueOf(blog.getProperty(PLUGIN_TEXTILE_PROCESS_ALL_ENTRIES)).booleanValue()) { 109 if (_logger.isDebugEnabled()) { 110 _logger.debug("Textile processing: " + entry.getId()); 111 } 112 entry.setDescription(_textile.process(entry.getDescription())); 113 } 114 } 115 116 return entries; 117 } 118 119 124 public void cleanup() throws PluginException { 125 } 126 127 132 public void destroy() throws PluginException { 133 } 134 } 135 | Popular Tags |