Saturday, October 2, 2010

iText 的中文显示问题

iText是用Java建立pdf文档的一个库。对于中日韩字体文档,iText也有相应的支持,按照说明,只需将iTextAsian.jar放在classpath内,然后创建相应字体即可。但昨天试图建立中文pdf的时候,发现创建字体出错。

google结果只说需要正确设置classpath,这应该不是问题。

下载iText源码,然后跟踪,问题出在判断字体是否是cjk部分,接着发现在判断cjk的时候,properties文件并未正确找到,最后发现在CJKFont类里面,properties文件的位置写在com.itextpdf.text.pdf.fonts包内,而iText网站提供的iTextAsian.jar却用了com.lowagie.text.pdf.fonts做包名。

解决办法,自己做一个jar,把iTextAsian中的属性文件展开后再拷贝到正确的目录结构,然后再打包成jar,然后替换程序里引用的那个iTextAsian.jar即可。

Sunday, September 5, 2010

双彩虹






今天下午五点半开始,天空出现双彩虹,差不多持续了两个钟头。彩虹几乎是两个很完整弧形。

Saturday, August 7, 2010

纽约市长布隆伯格关于下曼哈顿清真寺的演讲

“We've come here to Governors Island to stand where the earliest settlers first set foot in New Amsterdam, and where the seeds of religious tolerance were first planted. We come here to see the inspiring symbol of liberty that more than 250 years later would greet millions of immigrants in this harbor. And we come here to state as strongly as ever, this is the freest city in the world. That's what makes New York special and different and strong.
我们来到总督岛,站立在先民第一次踏上新阿姆斯特丹之处,这也是宗教宽容的种子首次播下的地方。我们来到这里,望着这激发人心的自由的象征,二百五十年来,在这个港口,她迎接了数百万计的移民。我们来到这里,也是一如既往地,坚定宣告,这是世界上最自由的城市。这即是纽约独特、不同和强盛的缘由。

“Our doors are open to everyone. Everyone with a dream and a willingness to work hard and play by the rules. New York City was built by immigrants, and it's sustained by immigrants -- by people from more than 100 different countries speaking more than 200 different languages and professing every faith. And whether your parents were born here or you came here yesterday, you are a New Yorker.
我们的大门对所有人敞开。包括所有怀揣着梦想,以及乐意艰苦工作,遵守规则的人。纽约市是移民建立的,也是移民支撑起来的,这些人们来自一百多个国家,操着两百多种语言,持有各种信仰。不管是你的双亲生长于此,还是你昨天才来,你都是纽约人。

“We may not always agree with every one of our neighbors. That's life. And it's part of living in such a diverse and dense city. But we also recognize that part of being a New Yorker is living with your neighbors in mutual respect and tolerance. It was exactly that spirit of openness and acceptance that was attacked on 9/11, 2001.

我们不一定总是赞同每一位邻居。这是现实。这也是在这么一个多元而又稠密的城市生活的一部分。但我们同样意识到,当一个纽约人的一部分,就是要同你的邻人在互相尊重容忍下共同生活。也就是这种开放和接受的精神,在2001年9月11日遭到了攻击。
“On that day, 3,000 people were killed because some murderous fanatics didn't want us to enjoy the freedoms to profess our own faiths, to speak our own minds, to follow our own dreams, and to live our own lives. Of all our precious freedoms, the most important may be the freedom to worship as we wish. And it is a freedom that even here -- in a city that is rooted in Dutch tolerance -- was hard-won over many years.
当日,3000人丧生,因为某些疯狂凶徒不想让我们享有拥有自己信仰,表达自己意愿,实现自己梦想,过自己生活的自由。在我们所有珍贵的自由里,最重要的大概就是按自己的意愿信教的自由。这种自由,即便是在这里,在一个植根于荷兰式的宽容的城市,也是经过长年的奋斗取得的。

“In the mid-1650s, the small Jewish community living in lower Manhattan petitioned Dutch governor Peter Stuyvesant for the right to build a synagogue, and they were turned down. In 1657, when Stuyvesant also prohibited Quakers from holding meetings, a group of non-Quakers in Queens signed the Flushing Remonstrance, a petition in defense of the right of Quakers and others to freely practice their religion. It was perhaps the first formal political petition for religious freedom in the American colonies, and the organizer was thrown in jail and then banished from New Amsterdam.
1650年代中期,住在下曼哈顿的小小犹太社区向荷兰总督Peter Stuyvesant 请愿,要修一座犹太教堂,他们被拒绝了。1657年,Stuyvesant又禁止贵格教徒集会,皇后区的一群非贵格教徒签署了《法拉盛抗议书》,这是捍卫贵格以及其他群体自由行使宗教的请愿书。这可能是在美洲殖民地第一次为宗教自由而进行的政治请愿,组织者被投入监狱后又被逐出新阿姆斯特丹。

“In the 1700s, even as religious freedom took hold in America, Catholics in New York were effectively prohibited from practicing their religion, and priests could be arrested. Largely as a result, the first Catholic parish in New York City was not established until the 1780s, St. Peter's on Barclay Street, which still stands just one block north of the World Trade Center site, and one block south of the proposed mosque and community center.
1700年代,即使在宗教自由在美国扎根的时候,纽约的天主教徒仍然被禁止进行他们自己的宗教活动,神父也有被抓的危险。其后果就是,纽约市的第一个天主教教区直到1780年代才得以建立。教区座堂,圣彼得教堂设在Barclay街,现在仍矗立在世贸中心北仅仅一个街区,也即是现今要建立的清真寺和社区以南一个街区处。

“This morning, the city's Landmark Preservation Commission unanimously voted to extend -- not to extend -- landmark status to the building on Park Place where the mosque and community center are planned. The decision was based solely on the fact that there was little architectural significance to the building. But with or without landmark designation, there is nothing in the law that would prevent the owners from opening a mosque within the existing building.
今天上午,市标志建筑保护委员会全票通过,不再将计划中要改建为清真寺和社区中心的Park广场建筑物立为标志性建筑。这项决定,仅仅是基于那幢建筑物并无太大建筑上的意义这一事实上做出的。但是不管是否是标志性建筑,都没有法律禁止房主在那里开设清真寺。

“The simple fact is, this building is private property, and the owners have a right to use the building as a house of worship, and the government has no right whatsoever to deny that right. And if it were tried, the courts would almost certainly strike it down as a violation of the U.S. Constitution.
事实很简单,那幢楼是私有地产,屋主有权将其用做宗教场地,政府绝无权力否认屋主的权益。如果此事诉诸法庭,几乎可以肯定法庭将会认定这是侵犯美国宪法。

“Whatever you may think of the proposed mosque and community center, lost in the heat of the debate has been a basic question: Should government attempt to deny private citizens the right to build a house of worship on private property based on their particular religion? That may happen in other countries, but we should never allow it to happen here.
不管你对构想中的清真寺和社区中心怎么想,在激烈争论中被人忘却的是一个基本问题:政府应不应该禁止公民在自己拥有的地产上,按自己所属的宗教信仰,建立宗教场所?或许别的国家会禁止,但我们绝对不应该让这种事情发生在这里。

“This nation was founded on the principle that the government must never choose between religions or favor one over another. The World Trade Center site will forever hold a special place in our city, in our hearts. But we would be untrue to the best part of ourselves and who we are as New Yorkers and Americans if we said no to a mosque in lower Manhattan.
这个国家得以建立的基本原则,就是政府绝不可在宗教中扶持一支打压一支。世贸遗址在我们城市,在我们心中,将永远占据一个特殊位置。可是,如果我们容不下在下曼哈顿设一座清真寺,我们就是在背叛自己最大的善,背叛我们作为纽约人,作为美国人的身份。

“Let us not forget that Muslims were among those murdered on 9/11, and that our Muslim neighbors grieved with us as New Yorkers and as Americans. We would betray our values and play into our enemies' hands if we were to treat Muslims differently than anyone else. In fact, to cave to popular sentiment would be to hand a victory to the terrorists, and we should not stand for that.
让我们不要忘了,在9/11遇难者中,也有穆斯林,我们的穆斯林邻人,同作为纽约人,美国人,和我们一起哀悼。如果我们区别对待穆斯林,那就是背离自己的价值,而正中敌人的下怀。实际上,如果陷入感情用事之地,就等于将胜局奉送给恐怖分子,我们绝不能容忍此事。

"For that reason, I believe that this is an important test of the separation of church and state as we may see in our lifetimes, as important a test. And it is critically important that we get it right.
因此,我相信,此刻是对政教分离原则的重要考验,可能是我们此生中可见证的最重要考验。至关紧要的是我们也必须通过这次考验。

"On Sept. 11, 2001, thousands of first responders heroically rushed to the scene and saved tens of thousands of lives. More than 400 of those first responders did not make it out alive. In rushing into those burning buildings, not one of them asked, 'What God do you pray to?' (Bloomberg's voice cracks here a little as he gets choked up.) 'What beliefs do you hold?'
2001年9月11日,众多救护人员英勇的冲向现场,拯救了成千上万条性命。400多位救护人员献身。在冲入烈火焚烧的大厦的时候,没人问:“你向那个神祈祷?”“你信仰什么?”

"The attack was an act of war, and our first responders defended not only our city, but our country and our constitution. We do not honor their lives by denying the very constitutional rights they died protecting. We honor their lives by defending those rights and the freedoms that the terrorists attacked.
那场袭击即是战争行为,我们的救护人员捍卫的不仅是我们的城市,也是我们的国家和宪法。我们不能以否定他们献身保卫的宪法原则来纪念他们。恐怖分子所攻击的权利和自由,我们要捍卫它们,以慰英灵。

"Of course, it is fair to ask the organizers of the mosque to show some special sensitivity to the situation, and in fact their plan envisions reaching beyond their walls and building an interfaith community. But doing so, it is my hope that the mosque will help to bring our city even closer together, and help repudiate the false and repugnant idea that the attacks of 9/11 were in any ways consistent with Islam.
当然,要求建造清真寺的组织者对事态保持一些特别的敏感,这也不为太过,事实上他们的计划构想了不拘于壁垒,建设一个跨种信仰社区的前景。我希望,此清真寺能帮助我们城市更紧密的团结在一起,并帮助消弭9/11袭击是和伊斯兰有相承关系的虚假恶念。

"Muslims are as much a part of our city and our country as the people of any faith. And they are as welcome to worship in lower Manhattan as any other group. In fact, they have been worshipping at the site for better, the better part of a year, as is their right. The local community board in lower Manhattan voted overwhelmingly to support the proposal. And if it moves forward, I expect the community center and mosque will add to the life and vitality of the neighborhood and the entire city.
穆斯林同其他信仰的人们一样,是我们城市和我们国家的一部分。和其他族群一样,我们也欢迎他们在下曼哈顿进行宗教活动。事实上他们已经在那里正当行使他们的宗教权利有近一年了。下曼哈顿地方社区委员会以压倒多数通过了提议。如果事态继续顺利进行,我期待社区中心和清真寺将会对附近小区,以及整个城市带来新的生机和活力。

"Political controversies come and go, but our values and our traditions endure, and there is no neighborhood in this city that is off-limits to God's love and mercy, as the religious leaders here with us can attest."
政治争议来去无常,但我们的价值和传统长存,在这个城市,没有一个社区不能享有神的仁爱,此间的宗教领袖可为此立证。

Saturday, July 10, 2010

附近河景


河滩上不知名的花。
第一次在附近看到鹳鸟,用手机拍的。




Thursday, June 10, 2010

使用jdb调试webapps

一般如果需要调试Tomcat或者Jboss的Web Application时,多用eclipse等集成环境。但也会碰到某些情况,比如开发环境内存限制等。这时候可以用jdb作简单的调试。
其实方法很简单,基本原则就是在web server或者app server启动jvm的时候,加上jdwp参数,这样jvm会打开一个端口和jdb通讯。然后再启动jdb连接上这个端口就可以了。
具体到tomcat,可以先建立以下一个脚本:

export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket
export JPDA_SUSPEND=y
./catalina.sh jpda start


存成startdebug.sh,放在tomcat的bin目录下

然后用这个脚本启动tomcat

接着就可以用
jdb -attach 8000来启动jdb

用stop 语句设好断点。比如
stop in HelloWorldExample.doGet

然后打开浏览器,进入tomcat自带的例子中的HelloWorld Servlet中,这时候jdb应该执行到断点,就可以用jdb命令跟踪或者打印变量了。

Friday, June 4, 2010

Java日期比较的一个陷阱

昨天在调试程序中,碰到一个问题,简化叙述如下
c是个Calendar对象,d是个Date,程序要判断c是否在d之后,判断条件用了
c.after(d)
当打印出来的时候,c的确是在d之后的,但以上条件却总是不成立。

仔细看了JavaDoc后,发现Calendar类的after方法虽然接受所有类型,但只有参数同是Calendar对象的时候日期比较才有意义。否则一律返回假。

解决办法也很简单,其实Date类也有after函数。只要把c转为Date类即可。
c.getTime().after(d)
这样就可以了。

Friday, May 28, 2010

圣城市的路


如果你的操作系统设定成了中文,那么你访问google地图的时候,就会发现外国的地名都有了中文的翻译。看到平日熟悉的街道变成了似乎是上世纪初翻译小说内的名字,感觉颇为怪异。上面是蒙特利尔街道地图的截屏,注意中间哪条Saint Urbain被翻译成了什么?

其实这个Urbain是名字,应该翻译成乌尔班或者厄本才对。

Tuesday, May 25, 2010

摩托党集会




周末去市中心,下午刚从Eaton Center出来就听到震天响的声音。Saint Catherine上往常拥挤的车辆也没了。Mcgill College上倒是沿街站了一排排围观群众。

走近看才知道是摩托党们抗议省政府提高摩托车注册费。




估计有上千辆摩托,还在不停的集结中。其中还颇有些很漂亮的车子。




Saturday, May 22, 2010

xubuntu多重启动

在机器上装了vista和xubuntu双操作系统。
xubuntu是ubuntu的一个变种,唯一的区别是ubuntu用gnome而xubuntu用xfce。因此使用的资源要少一些。类似的变种还有kubuntu,使用kde。
总的说来安装很简单,安装程序可以压缩现有的ntfs分区。然后创建新的ext4分区。装完后重启动即由grub管理多重启动菜单。

用光盘启动到xubuntu的时候,机器风扇狂响,本以为是系统风扇。准备下载一个风扇控制程序。但后来用了nvidia的显卡驱动程序,意外的发现风扇声音没有了。原来先前是gpu的风扇。

Wednesday, March 3, 2010

谁在改变?

一个社会主体居民该以如何的态度面对移民?移民自身是否应该对自己的文化,宗教等作出调整以适应这个社会?这个问题几年来一直在魁北克公众视野里沉沉浮浮,挥之不去。在一个理想的社会里,对少数要有足够的宽容似乎是天经地义的。但现实的问题总没那么简单。最近的例子正说明了这一点。

本地报纸今天报道了这样一个案例。一位埃及的穆斯林妇女,因为在新移民法语课上拒绝摘下面纱(Niqab,说面纱不太确切,这是那种比较封闭的头饰,完全遮住面孔,只露出眼睛的那种),最后被开除。该妇女向人权委员会申诉,认为这种行为是对她的歧视。

如果仅从这个叙述来看,道理似乎站在该妇女一边。服饰,以及服饰后面代表的文化和宗教信仰,应该是个人自由,理应受到保护。语言课老师以此为理由剥夺了她的受教育权利,是对她权利的侵犯。

然而老师的辩护理由也并非完全无道理:语言课需要很多互动,Niqab非常阻碍这种师生间的交流。老师无法看到学生的嘴形,也就无从纠正起。而且如果对该女生的要求完全迁就的话,就会影响到其他同学的学习。一个细节就是当这位女生做口语表达练习的时候,她要求位于教室后部没人能看到她脸的地方做。教师满足了她的要求,但她认为仍有男性学生看得到她的脸,所以要求把其他同学的位置挪动到别的地方。这个自然会造成她同校方的不愉快关系。

如果一个人的自由必须要别人做出牺牲(尽管可能是很小的牺牲)才能维护,这种自由还应该受到保护么?

事实上,在这个特定例子中,该妇女的要求并非完全不可满足,校方仍有某些退让余地。但不得不问的一个问题是,本土居民和新移民,双方各自的界限在那里?是否能够存在一个两边都能接受的界限?当双方都已经做出某些让步,而仍无法妥协的情况下,应该舍弃哪一方的利益?虽然三年前Hérouxville的充满争议的市政决议就开始问大众这些问题,期间也有Bouchard-Taylor报告试图做出回答,但是似乎起码在可见的将来,这些问题仍然会在魁北克的社会空间内回荡。


Git 版本控制

本想查看Spring Security的源代码,结果发现他们并没用SVN做版本控制,而是用了git
这里是git的eclipse插件。

Wednesday, February 24, 2010

Spring学习笔记 2

Gary Mak的Spring Recipes对IoC和DI的看法和上一篇的见解基本一致,他认为IoC是一个设计原则,而DI则是一种具体的实现。

对于注入的种类,则有setter方法和构建器方法两种。不管是哪一种,都是组建留出一个接口,由Container负责把需要的其他组建“注入”其中。这样就降低了组件本身的耦合度。

Bean就是这些组件的单元,这些Bean可以按生存期分成singleton和prototype等几种。要注意的是这里的singleton和设计模式中的singleton并非完全一致。设计模式中的singleton,一个类只能生成一个对象。但Spring中的singleton Bean则可以几个Bean都是同一个类,它们之间并不一定需要指向一个对象。只是在整个container中,此Bean有唯一性。而prototype的bean则在Container注入的时候,都每次不同。


Monday, February 22, 2010

某日的晚餐

某日的晚餐,测试一下图片功能。

西红柿炒鸡蛋,蒜苗肉丝,酱汤。酱汤是用干料包冲的。

Saturday, February 20, 2010

VirtualBox内的Ubuntu安装

昨天在VirtualBox内装了Ubuntu,整个过程比较顺利。唯一要注意的是装完后缺省分辨率是800*600,而且不能更改。
解决方法也很简单,在VirtualBox内提供了virtualbox addition 的一个组件,把它在Guest OS上安装一下即可。这个组件装完后还提供了一些其他功能,比如鼠标移动到VirtualBox内操作系统的窗口时自动捕捉并激活(否则需要点击一下)等。

Thursday, February 18, 2010

新闻法语: 尼日尔军事政变

原文

Des militaires ont arrêté jeudi le président nigérien Mamadou Tandja lors d'un coup d'Etat dirigé par un officier, le commandant Adamou Harouna, a-t-on appris de trois sources militaires. Une source diplomatique française avait peu après déclaré : "Il y a encore un peu de confusion mais il semblerait que le président Tandja est aux mains des mutins ainsi que ses ministres, qui sont retenus dans un autre endroit."

Voix du Sahel, la radio d'Etat a suspendu ses programmes pour diffuser de la musique militaire dès 18 h 40. Lors des coups d'Etat de 1974, 1996 et 1999, la radio d'Etat avait diffusé de la musique militaire avant que les mutins ne prennent la parole sur ses ondes.

链接
http://www.lemonde.fr/afrique/article/2010/02/18/au-niger-des-tirs-de-mitrailleuses-autour-du-palais-presidentiel_1308078_3212.html

译文:

根据三个军方的消息源,尼日尔总统Mamadou Tandja星期四在一次军事政变中被逮捕,此次政变是一位军官Adamou Harouna司令发动的。法国外交界某消息源不久后称:“局势仍有些不明朗,但似乎Tandja总统已经落入叛军手中,他的内阁部长也被关押在另一处场所。”

当地时间18时40分起,国家电台《Sahel之声》中断了正常节目,开始播放军乐。在1974,1996和1999年的政变时,国家电台也是在叛军发布广播消息之前播放军乐的。
单词:
mutin:叛军
onde:波浪,这里指无线电电波。

Monday, February 15, 2010

spring framework学习笔记

随时记录一下spring framework 学习的点滴,以免忘记。现在正在看的是Apress的Pro Spring 2.5


1: IoC和DI, 按照书上第三章的看法,IoC(控制反转)分成依赖性查找和DI(依赖注入)两种,这两大类又各分为Dependency Pull和上下文依赖性查找两种实现。而DI又分为构建器DI和setter DI两种。

我觉得依赖性查找已经不属于控制反转了,因为所需要的部件仍然是调用方负责生成或者获取的。


2:Spring Ioc的基本核心部分,也就是Bean和BeanFactories了。 基本思想是一切组件都是Bean,这些Bean是由Spring来控制它们的生存周期的。

BeanFactory起到一个容器的作用,但从Bean的定义到容器内的Bean,需要有BeanDefinitionReader完成。有趣的是BeanFactory本身也是一个被注入的部件,BeanDefinitionReader 只管解析Bean的定义(可以是xml文件格式的,也可以是属性文件格式的。)生成出来的BeanDefinition交给BeanDefinitionRegistry再做簿记性质的处理。而BeanFactory正是要实现BeanDefinitionRegistry的。


Sunday, February 14, 2010

两场庆典

星期五温哥华冬奥会开幕。很自然的,大家一定会同北京夏奥会开幕比较。但毕竟冬奥会规模小很多,按照这个级别来说也算成功了。可总的感觉是略有拖沓,从Yanofsky的爵士版本国歌,到几乎成为加拿大第二国歌的<哈里路亚>,以及最后点火装置的失误。总是给人带来遗憾的感觉。

星期六早上又是春晚。当然是一场更加政治意义上的晚会。除去少数节目外,大多数歌舞都有“盛世”“和谐”之类的关键词。唯一让人觉得有点新意的倒是午夜过后的相声大话捧逗,白凯南的表演有相当的水准。

Friday, February 12, 2010

再次开始

过去的blogger是msn电邮帐号注册的,已经找不回来了。只好再次开始。