Home | Syndication | Delicious | Douban | Twitter

Archive for the 'TechNotes' Category

Use KefirBB to Extract Text from BBCode String

March 3rd, 2010

之前写了一篇帖子介绍如何从字符串中去除 BBCode 标签、提取纯文本信息,使用的是 JBoss Portal format 包,虽然可以解决问题,但非常不完美,比如,无法支持大写标签、无法识别自定义标签等。春节前发现了一个专门用于处理 BBCode 的 Java 库 KefirBB,当时的版本是 0.5,只支持 Java 6,我修改了些源码以支持 Java 5,并发了 patch 给其作者 Kefir。很快 Kefir 发布了新版本 0.6,同时支持 Java 5 & 6.

使用 KefirBB 提取纯文本信息非常简单。首先新建配置文件 kefirbb.xml 并放置到 CLASSPATH 中,其内容如下:

<?xml version="1.0" encoding="UTF-8"?>

<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns="http://kefir-bb.sourceforge.net/schemas"
               xsi:schemaLocation="http://kefir-bb.sourceforge.net/schemas http://kefir-bb.sourceforge.net/schemas/kefir-bb-0.5.xsd">
    
  <code>
    <pattern>[<var/>]</pattern>
    <template/>
  </code>

</configuration>

以上配置表示将所有用 中括号 [] 包含起来的部分去除。

然后就可以在 Java 代码中进行操作了:

TextProcessor processor = BBProcessorFactory.getInstance().create();
String txt = processor.process(bbString);

就是这么简单。

其实 KefirBB 的功能远不止如此,通过在配置文件中指明转换规则,KefirBB 可以进行任何文本间的转换。

翻墙必备神器 Tor

January 17th, 2010

Extract Text from BBCode String

January 10th, 2010

Connect Android Phone to LEAP WiFi

November 22nd, 2009

Playing with MLDonkey

May 24th, 2009

Say Goodbye to Partial Content in Google Reader

May 22nd, 2009

Enable OpenSSL Support for PHP on Windows

March 11th, 2009

SpringSource dm Server 1.0.0 GA

October 11th, 2008

“正确”地安装 iTunes

May 12th, 2008