1 31 package org.blojsom.plugin.hyperlink; 32 33 import org.blojsom.blog.*; 34 import org.blojsom.plugin.Plugin; 35 import org.blojsom.plugin.PluginException; 36 37 import javax.servlet.http.HttpServletRequest ; 38 import javax.servlet.http.HttpServletResponse ; 39 import java.util.Map ; 40 41 49 public class HyperlinkURLPlugin implements Plugin { 50 51 54 private static final String URL_PROTOCOLS = "((ftp|http|https|gopher|mailto|news|nntp|telnet|wais|file)"; 55 56 59 private static final String URL_REGEX = "(^|[\t\r\n ])" + URL_PROTOCOLS 60 + ":[A-Za-z0-9/](([A-Za-z0-9$_.+!*(),;/?:@&~=-])|%[A-Fa-f0-9]{2})+)"; 61 62 65 private static final String HREF_EXPRESSION = " <a HREF=\"$2\">$2</a>"; 66 67 72 public void init() throws PluginException { 73 } 74 75 86 public Entry[] process(HttpServletRequest httpServletRequest, 87 HttpServletResponse httpServletResponse, 88 Blog blog, 89 Map context, 90 Entry[] entries) throws PluginException { 91 for (int i = 0; i < entries.length; i++) { 92 Entry entry = entries[i]; 93 94 entry.setDescription(entry.getDescription().replaceAll(URL_REGEX, HREF_EXPRESSION)); 95 } 96 97 return entries; 98 } 99 100 105 public void cleanup() throws PluginException { 106 } 107 108 113 public void destroy() throws PluginException { 114 } 115 } 116 | Popular Tags |