Simple-xml is an object-xml serialization and de-serialization framework. It’s featured by annotation-driven, light-weight and self-contained.
In simple-xml, pojos that will be serialized are annotated with @Root, @Element, @Attribute or @Text. The problem is, when handling with inheritance, if the actual type is different from declared type, simple-xml will add a “class” attribute for de-serialization consideration. That is, the parser will use this attribute to determine the schema of the xml element. However, this is of no useful when we do not parse xml by simple-xml. And there is also risk that the class attribute exposes our program’s internal structure.
Take following code as example:
@Root
public class Response{
@Element
private Object entry;
// getter and setter ...
}
public class OrderItem{
@Element
private String name;
// getter and setter ...
}
When you generate xml from classes above, you will have the entry element of response with an attribute “class”, which value is the qualified class name, like “package.OrderItem”.
This is done by simple-xml’s Strategy interface. By default, the Persister uses TreeStrategy which has an implementation of setElement like:
/**
* This is used to attach a attribute to the provided element
* that is used to identify the class. The attribute name is
* "class" and has the value of the fully qualified class
* name for the object provided. This will only be invoked
* if the object class is different from the field class.
*
* @param type this is the declared class for the field used
* @param value this is the instance variable being serialized
* @param node this is the element used to represent the value
* @param map this is used to maintain contextual information
*
* @return this returns true if serialization is complete
*/
public boolean setElement(Type type, Object value, NodeMap node, Map map){
Class actual = value.getClass();
Class expect = type.getType();
Class real = actual;
if(actual.isArray()) {
real = setArray(expect, value, node);
}
if(actual != expect) {
node.put(label, real.getName());
}
return false;
}
This is where class attributed. So to suppress the attribute, we simply override this method by inherit TreeStrategy. I take a inline class for convenience here.
Serializer s = new Persister(new TreeStrategy(){
@Override
public boolean setElement(Type type, Object value, NodeMap node, Map map){
return false;
}
});
Now it works, however, simple-xml won’t be able to deserialize xml generated by this modified strategy.
This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.
最近琢磨字典多一些,以前一直不知道gnome自带的gnome-dictionary如何使用,因为默认的字典源里都没有中文字典,而且离线更是无法使用。其实不然,字典服务可以自架,并且可以使用自己的字典。
在自己的机器上架设dictionary server,以ubuntu为例:
安装dictd / dict
sudo apt-get install dictd dict
前者是字典服务器,后者是字典服务客户端。还可以从仓库里安装已经打包好的字典,如
sudo apt-get install dict-stardic
是一个英汉字典
dictd安装好后会默认自启动,也可以通过
sudo service dictd start
来控制dictd的启动、重启和关闭。
通过dict测试服务的状况
dict -D
命令会列出可用的数据库(即字典)
在gnome-dictionary中添加字典源 Edit->Preference->Source->Add
Name: 自定义的字典名
Transport: Dictionary Source
Hostname: 127.0.0.1
Port: 2628
Close之后可以到主界面打开侧边栏,在Dictionary Source中双击选定此字典,在Aailable Dictionaries里双击选中目标字典,于是就可以在gnome-dictionary里使用本地的字典服务了。
接下来安装自己的字典。stardict的网站上有很多中文字典,上面也都标示了授权协议。要在dictd里使用这些字典,需要进行一个简单的格式转换。安装一个工具
sudo apt-get install dictconv
它的使用方法:
dictconv -o OUTPUT_FILE INPUT_FILE
在input_file指定stardict的.ifo文件,在output_file指定要生成的dictd的.index文件。这个转换非常耗时,需要有足够的耐心。这个操作将会生成.index和.dict文件。对.dict文件进行压缩:
dictzip OUT.dict
转换完成后,编辑/var/lib/dictd/db.list文件,在其中添加一个database定义
database YOUR_DB_NAME{
data PATH_TO_DICT_DZ
index PATH_TO_INDEX
}
其中PATH_TO_DICT_DZ是上一步的.dz文件,PATH_TO_INDEX是到上一步生成的.index文件的路径。编辑完成后,重启dictd服务
sudo service dictd restart
使用dict -D可以查看启用的字典。
建议备份/var/lib/dictd/db.list文件,因为每次从apt-get安装字典后,这个文件都会被覆盖。
dictd服务也可以在fantasdic里访问。
This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.
经常访问GNU的网站你会发现一些很神奇的东西,比如gNewSense,又比如最新的:

怎么样,够震撼啊,GNUzilla套件里的第一个发布,IceCat。IceCat是嘛?你知道Firefox吧,那拉开冰箱门,把Firefox塞进去,带上冰箱门,嗯,那就是IceCat了。当然是开玩笑了,GNU IceCat is the GNU version of the Firefox browser. Its main advantage is an ethical one: it is entirely free software.
现在已经可以在Ubuntu中使用这个病猫,哦不,冰猫了:
sudo add-apt-repository ppa:gnuzilla-team/ppa
sudo apt-get update
sudo apt-get install icecat
This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.
I found fantasdic a great powerful dictionary tool with friendly UI and supports multiply sources. Unfortunately, this project seems to be no longer maintained. The latest version is 1.0-beta7.

The google translate source was created in 2007. As the google translate service page changed, this module doesn’t work any more, so I just picked up my vim then created this patch for those still want to use it.
This patch has dependency with ruby’s json module, so before you apply it, run:
sudo gem install json
or
sudo apt-get install libjson-ruby1.8
Download the patch at:
https://bugzilla.gnome.org/attachment.cgi?id=152835
Patch it (Ubuntu installation as example):
cd /usr/lib/ruby/1.8/fantasdic/sources/
sudo patch google_translate.rb /home/sun/google_translate.rb.diff
Restart fantasdic, then your get it works! And this bug is tracked at:
https://bugzilla.gnome.org/show_bug.cgi?id=605641
This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.
翻译一个po文件。确认安装了gettext工具包。
cd到po目录,创建pot
intltool-update –pot
创建相应的语言文件,例如zh_CN
msginit -l zh_CN.utf8
程序会提示选择或输入邮箱,之后就会生成zh_CN.po文件,打开文件,逐条编辑msgstr即可。
手动编辑LINGUAS文件,按顺序将zh_CN添加到其中。
可以通过这个命令查看翻译的进度
msgfmt -cv zh_CN.po
对于更新pot更新的情况,可以使用命令更新po文件
intltool-update zh_CN
参考:
- http://live.gnome.org/TranslationProject/LocalisationGuidezh
- http://blog.chinaunix.net/u1/37261/showart_476642.html
This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.
自从libchamplain / geoclue等库发布之后,gnome桌面的地理信息工具和支持发展很迅速:例如之前提到过的eye-of-gnome的地理信息插件,根据EXIF信息在地图上显示。现在gnome桌面上终于有一个专门的地图查看器了,仍然是基于libchamplain,名字叫做emerillon
仍然是使用open street maps,这两年上海的地图发展的非常不错,连最新的二号线东延都已经被标注出来了。相比之下,南京的地图就还是一片空白。
在Ubuntu上安装emerillon,可以从其网站上下载源码编译安装:
http://www.novopia.com/emerillon/download.html
emerillon的几个主要依赖:
- libchamplain
- librest
- ethos
libchamplain在ubuntu 9.10的仓库已经包含
librest也在软件仓库中,不过需要注意的是ubuntu将librest安装在pkg-config里时的名字叫做rest.pc,而emerillon查找的是rest-0.6.pc,所以需要手动建立一个软连接:
sudo ln -s /usr/lib/pkgconfig/rest.pc /usr/lib/pkgconfig/rest-0.6.pc
ethos是一个Gtk的插件框架,目前还不在软件仓库中,需要从网站下载代码编译:
http://git.dronelabs.com/ethos/
ethos网站上提到的PPA源中的版本偏旧,不建议使用。
实际上也可以直接添加emerillon的PPA源:
deb http://ppa.launchpad.net/mathieu-tl/emerillon/ubuntu karmic main
deb-src http://ppa.launchpad.net/mathieu-tl/emerillon/ubuntu karmic main
另外,也可以通过Ubuntu Tweak安装。
作者Blog:
http://blog.pierlux.com/en/
This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.






GeoTagged RSS
on
on
on