1 31 package org.blojsom.plugin.obfuscation; 32 33 import org.apache.commons.codec.binary.Hex; 34 import org.blojsom.blog.Blog; 35 import org.blojsom.blog.Entry; 36 import org.blojsom.plugin.Plugin; 37 import org.blojsom.plugin.PluginException; 38 import org.blojsom.util.BlojsomConstants; 39 40 import javax.servlet.http.HttpServletRequest ; 41 import javax.servlet.http.HttpServletResponse ; 42 import java.io.UnsupportedEncodingException ; 43 import java.util.Map ; 44 45 52 public class SimpleObfuscationPlugin implements Plugin { 53 54 public static final String BLOJSOM_PLUGIN_SIMPLE_OBFUSCATION = "BLOJSOM_PLUGIN_SIMPLE_OBFUSCATION"; 55 56 61 public void init() throws PluginException { 62 } 63 64 70 public String obfuscate(String data) { 71 if (data == null) { 72 return null; 73 } 74 75 if ("".equals(data)) { 76 return ""; 77 } 78 79 StringBuffer result = new StringBuffer (); 80 try { 81 char[] hexString = Hex.encodeHex(data.getBytes(BlojsomConstants.UTF8)); 82 for (int i = 0; i < hexString.length; i++) { 83 if (i % 2 == 0) { 84 result.append("%"); 85 } 86 result.append(hexString[i]); 87 } 88 } catch (UnsupportedEncodingException e) { 89 return data; 90 } 91 92 return result.toString(); 93 } 94 95 106 public Entry[] process(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Blog blog, Map context, Entry[] entries) throws PluginException { 107 context.put(BLOJSOM_PLUGIN_SIMPLE_OBFUSCATION, this); 108 109 return entries; 110 } 111 112 117 public void cleanup() throws PluginException { 118 } 119 120 125 public void destroy() throws PluginException { 126 } 127 } 128 | Popular Tags |