为jive2.x写ImageFilter

来源:互联网 发布:php sql注入漏洞修复 编辑:程序博客网 时间:2024/05/16 11:42
<script type="text/javascript">google_ad_client = "pub-8800625213955058";/* 336x280, 创建于 07-11-21 */google_ad_slot = "0989131976";google_ad_width = 336;google_ad_height = 280;//</script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>摘要:简要介绍为jive2.x写插件的方法,并具体实现一个图像过滤器ImageFilter。jive2.x所有的filter都放在com.jivesoftware.forum.filter包下面,这一点与jive3.x不同。利用正则表达式来写这个filter非常简单。1. 继承抽象类ForumMessageFilter在jive2.x里面,要实现的所有filter都应该继承它,ForumMessageFilter实现了ForumMessage接口。因此,(1) 我们所要实现的filter应该提供getBody(),getSubject()方法,如果需要的话,还有getProperty(String)方法。(2) 注意:每个filter都应该指明自己是否是可以缓存的,这通过isCacheable()方法来实现。(3) 另外,你也许要对filter进行一些属性上的设置,也要在这里完成相应的处理。2. 继承JiveBeanInfo类建议你通过继承JiveBeanInfo类来为BeanInfo接口提供必要的信息,比如filter的名称,简短的描述,版本信息,作者等等。这样我们可以在管理台对filter的属性进行设置。比如,我们马上要写一个ImageFilter,(1) 那么我们就还需要再写一个名为ImageFilterBeanInfo辅助类。注意,这种命名模式是固定的,即“filterName+BeanInfo”。(2) 然后,我们再写一个bean_ImageFilter.properties的属性描述文件,一般要包含这些信息:# Name of the filter# Version of the filter# Description of filter# Author of filter# Properties - display name and description以上这些内容会出现在管理台,主要是对你可以进行设置的属性作简短的描述。基本上写filter就是这样了,下面附上我写的Jive2ImageFilter源代码。标签设计为:[ img ]url[ /img ](为了不被转义,多加了空格)regex的匹配格式为:/[img/]([^/[] )/[/img/],把它保存为Jive2ImageFilterRegex文件。1. Jive2ImageFilter.javapackage com.jivesoftware.forum.filter;import com.jivesoftware.forum.*;import java.util.regex.*;import java.io.*;public class Jive2ImageFilter extends ForumMessageFilter { public Jive2ImageFilter() { filteringSubject = false; filteringBody = true; imageRoot = "/";} public ForumMessageFilter clone(ForumMessage message) { Jive2ImageFilter filter = new Jive2ImageFilter();filter.filteringSubject = filteringSubject;filter.filteringBody = filteringBody;filter.message = message;filter.imageRoot = imageRoot; return filter;}public boolean isCacheable() {return true;} public boolean isFilteringSubject() { return filteringSubject; } public void setFilteringSubject(boolean filteringSubject) { this.filteringSubject = filteringSubject; } public boolean isFilteringBody() { return filteringBody; } public void setFilteringBody(boolean filteringBody) { this.filteringBody = filteringBody; }public String getSubject() {if (filteringSubject) { return showImage(message.getSubject());} return message.getSubject();} public String getBody() { if (filteringBody) { return showImage(message.getBody()); } return message.getBody(); } public String getImageRoot() { return imageRoot; } public void setImageRoot(String root) { imageRoot = (root == null) ? "/" : root.endsWith("/") ? root : root '/'; }private String showImage(String input){if (input == null || input.length() == 0) {return input;} InputStream is = this.getClass().getResourceAsStream("Jive2ImageFilterRegex"); BufferedReader br = new BufferedReader(new InputStreamReader(is)); try { REGEX = br.readLine(); } catch (IOException ioe) {}Pattern pattern = Pattern.compile(REGEX);Matcher matcher = pattern.matcher(input);StringBuffer filtered = new StringBuffer();while (matcher.find()) {if (matcher.group(1).startsWith("http://")|| matcher.group(1).startsWith("HTTP://")|| matcher.group(1).startsWith("ftp://")|| matcher.group(1).startsWith("FTP://")) {matcher.appendReplacement(filtered, "");} else { matcher.appendReplacement(filtered, "");}}matcher.appendTail(filtered);return filtered.toString();}private boolean filteringSubject;private boolean filteringBody;private String REGEX;private String imageRoot;}2. Jive2ImageFilterBeanInfo.javapackage com.jivesoftware.forum.filter;import java.beans.*;import com.jivesoftware.forum.util.JiveBeanInfo;public class Jive2ImageFilterBeanInfo extends JiveBeanInfo { public static final String [] PROPERTY_NAMES = { "filteringSubject", "filteringBody", "imageRoot", }; public Jive2ImageFilterBeanInfo() { super(); } public Class getBeanClass() { return com.jivesoftware.forum.filter.Jive2ImageFilter.class; } public String [] getPropertyNames() { return PROPERTY_NAMES; } public String getName() { return "Jive2ImageFilter"; }}3. bean_Jive2ImageFilter.properties# Jive2ImageFilter.properties # Default resource bundle for Jive2ImageFilter# Name of the filterdisplayName=Jive2 Image Filter# Version of the filterversion=1.0# Description of filtershortDescription=Convert [img]path[/img] tags into html image tags. It should comes before URL Converter filter.# Author of filterauthor=ant21# Properties - display name and descriptionfilteringSubject.displayName=Filter Message SubjectfilteringSubject.shortDescription=Toggles whether the subject will be filtered.filteringBody.displayName=Filter Message BodyfilteringBody.shortDescription=Toggles whether the body will be filtered.imageRoot.displayName=Root directory of the images to use.imageRoot.shortDescription=Images in the generated tags are loaded from this directory.需要注意的是,如果你同时使用了jive自带的URL Converter filter,那么Jive2 Image Filter一定要在URL Converter filter的前面,这样才能正确过滤,否则URL Converter filter会把[ img ]url[ /img ]中的url提前过滤掉。
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 电信外勤助手 女生适合做外勤会计吗 外勤人员考勤管理 小步外勤下载app 外勤会计是做什么的 外勤管理系统 外勤会计招聘 外勤助手下载 外勤是做什么的 外勤助手电信下载 外勤会计有前途吗 工商外勤是做什么的 什么是外勤会计 保险公司外勤 保险公司内勤外勤 保险公司内勤与外勤 保险公司内勤和外勤 外包公司 外包公司什么意思 饭堂外包 外包什么意思 2019外包催收敢上门吗 电话销售外包多少钱 电话销售外包 服务外包 劳务外包与劳务派遣 软件外包 外包服务 外包1万相当于普通职工多少 2019我来贷外包催收上门 金融服务外包 外包网 单位食堂外包 员工食堂外包 上海seo外包 seo外包公司哪家好 企业食堂外包 外包服务网 企业外包 项目外包网 程序外包网