niyue

Archive for the ‘programming’ Category

developperWorks上面的XML文章

In programming on 2月 17, 2005 at 2:40 下午

在网上查文章的时候不断的看到IBM的developerWorks 中国网站上面的文章,很多都写的很好。下面这位的文章我已经n次找到了,可以去devoloperWorks上面搜索一下“Uche Ogbuji”,可以找到他写的很多文章,都是XML方面相关的,很不错。

关于作者
Uche Ogbuji 的照片Uche Ogbuji 是 Fourthought Inc. 的顾问兼共同创始人,该公司是专为企业知识管理提供 XML 解决方案的软件供应商和咨询公司。Fourthought 开发了 4Suite,这是一个用于 XML、RDF 和知识管理应用程序的开放源码平台。Ogbuji 先生是一名出生于尼日利亚的计算机工程师兼作家,他生活和工作在美国科罗拉多州博耳德。可以通过 uche.ogbuji@fourthought.com 与 Ogbuji 先生联系。

Storing RDF and RDFS in Sesame Repository

In programmingsemanticweb on 2月 7, 2005 at 8:18 上午

Male jeen
Sesame developer

If you store the files in seperate repositories, you will not be able to do queries that return information from both files (since a query is always evaluated against a single repository). On the other hand, if you keep them seperate it is easier to modify one file without disturbing the other.

So it depends on what you want to do. In most cases where querying is involved, putting files in a single repository is the most logical choice though.

Spring – Java/J2EE Application Framework 参考手册

In javaprogramming on 2月 7, 2005 at 6:34 上午

Spring – Java/J2EE Application Framework 参考手册

使用Apache Common Id生成标识符

In javaprogramming on 2月 5, 2005 at 4:10 下午

现在的项目中要用到标识符的生成,早就看到Apache上面Jakarta项目的common子项目下有一个id子子项目(^_^,这就是apache),使用它很容易的就可以完成唯一的标识符的生成。今天稍微花了一点时间试验了一下,很容易就搞定了,基本没碰到什么困难。主要的步骤如下:

  1. 下载Apache-common-id。因为这个sub-sub-project是属于sandbox(沙盒中的项目用户可以自由使用,但是这些项目的维护并不得到保证,很可能会一直处于目前的状态)中的一个项目,所以没有binary的下载。只能下载源代码以后编译得到。我是使用Eclipse中的cvs的客户端访问apache的cvs得到的源代码。cvs站点名称为cvs.apache.org,访问路径为/home/cvspublic,用户名为anoncvs,不需要密码。登录到cvs服务器上后检出id项目的所有相关文件。
  2. 使用ant对源代码进行编译。我开始用Eclipse里面自带的ant进行编译,但是build失败了。编译器报错说我的jre中的类库版本号与需要的版本号不一致(需要的是48.0版的,我用的J2SE5.0,那个类库的版本号显示是49.0)。我满试了一下不用Eclipse里面自带的ant,自己下载一个ant对源代码编译,结果通过编译了居然(编译的时候ant会根据那个build.xml文件从网上下载相关的类库,所以需要连接到Internet才可以成功)。
  3. 然后后面的工作就很轻松了,用jar把编译后的class打包就可以了。
  4. 打包好后就可以很容易的使用了。一行代码就可以生成数字字符混合的id号。
String id=IdentifierUtils.nextStringAlphanumericIdentifier();

编写Javadoc

In javaprogramming on 2月 5, 2005 at 1:09 下午

以下是参考的一些文章:

  1. How to Write Doc Comments for the Javadoc Tool
  2. javadoc,在 Java 的注释上做文章
  3. 在java源码中为Javadoc编写文档注释(1)

v4_java_logo.gif  在java编码规范中,提到了文档注释可被javadoc用来生成API文档。具体的写法,另有说明。下面是学习笔记,主要是摘了一些值得注意的要点。

1、javadoc的获取

只能从相应的JDK中取得,安装后在bin目录下。具体如下:
* Javadoc 1.4 is included in Java 2 SDK, Standard Edition v 1.4
* Javadoc 1.3 is included in Java 2 SDK, Standard Edition v 1.3
* Javadoc 1.2 is included in Java 2 SDK, Standard Edition v 1.2
* Javadoc 1.1 is included in JDK 1.1

2、文档注释编写(principles)

  • Java平台API文档由源码中的文档注释定义,且任何此类文档皆从此类注释取得
  • Java平台API文档是调用者(caller)和实现之间的契约(contract)
  • 除非另有说明,Java平台API文档声明(assertion)应为与具体实现无关(implelementation-independent)
  • Java平台API文档应有足够的声明,以使得软件质量保证部门能写出完全的JCK (Java Compatibility Kit)测试。

3、文档注释编写细则

  1. 每个文档注释的第一句,应是个概要句,简明但无遗地描述API项。第一句在第一个后跟空格的点号前结束。当句中出现非结束意义的点加空格时,需要空格进行转义,如 等。
  2. 自动重利用父类/接口方法(method)的注释,当(1)一个类方法重写(override)父类的方法时,或(2)一个接口方法重写父接口的方法时,或(3)一个类方法实现一个接口方法时。如果当前方法没文档注释,则从父方法复制,如果有,则不复制而是前两者有小标题 “Overrides”,后者有”Specified by”.
  3. 用<code>…</code>来标注关键词或名字
  4. 节约使用行内链接{@link}
  5. 对方法和构建函数的说明,要去掉括号
  6. 可以为了简短使用短语而不是句子
  7. 使用第3人称而不是第2人称
  8. 以一个动词短语开始对一个方法的描述
  9. 对类/接口/字段(field)的描述,可以忽略主语
  10. 用”this”而不是“the”来引用从当前类生成的对象
  11. 不要仅是简单地把API名字里的单词展开来做描述,要增加一些信息。
  12. 当作用”field”一词时,注意它易引起混淆
  13. 避免拉丁语缩写
  14. 标签顺序
    1. @author,多个作者时按参考修改代码的年代为序
    2. @version
    3. @param,多个参数时以方法声明中的顺序为序,单个@param后跟参数名(不要相应的类型),再加描述
    4. @return
    5. @exception,多个异常时以异常名字的字母顺序为序
    6. @see,多个参见时据 #field,#Constructor(Type, Type…),#Constructor(Type id, Type id…),#method(Type, Type,…),#method(Type id, Type, id…),Class,Class#field,Class#Constructor(Type, Type…),Class#Constructor(Type id, Type id),Class#method(Type, Type,…),Class#method(Type id, Type id,…),package.Class,package.Class#field,package.Class#Constructor(Type, Type…),package.Class#Constructor(Type id, Type id),package.Class#method(Type, Type,…),package.Class#method(Type id, Type, id),package排序
    7. @since
    8. @serial
    9. @deprcated
  15. @param和@return(当返回不是void时)都是必须的

在线HTML编辑器

In programming on 2月 4, 2005 at 3:52 下午

内容管理系统中不可避免的会涉及到内容的在线编辑问题,这两天看了不少在线的HTML编辑器。我主要是从车东的内容管理系统(CMS)的设计和选型一文中提到的一篇文章TTW WYSIWYG Editors里面介绍的那些编辑器开始的。虽然文中列举了不少的编辑器,但是也没发现特别满意的。车东推荐的是aynhtml,但是我看了一下,发现它只支持Internet Explorer 5.5以上,并且已经停止开发了似乎(最新版本是2002年的)。我觉得在线编辑器的最重要的一个特性就是TTW WYSIWYG Editors一文中列出的cross platform特性,因为B/S相对与C/S的一个很大优势就在于B/S部署方便,如果编辑器强迫用户使用IE,那么这一优势也就荡然无存了。

于是自己又找寻和比较了一阵,最后感觉比较好的如下:

1 FCKeditor

This HTML text editor brings to the web many of the powerful functionalities of known desktop editors like Word. It’s really lightweight and doesn’t require any kind of installation on the client computer.
As it is Open Source, you are allowed to use it for free wherever you want.

2 Kupu

Kupu is a ‘document-centric’ open source client-side editor for Mozilla, Netscape and Internet Explorer. Inspired by Maik Jablonski’s Epoz editor, it was written by Paul Everitt, Guido Wesdorp and Philipp von Weitershausen (and several other contributors, for a complete list refer to the CREDITS.txt file) to improve the JavaScript code and architecture, pluggability, standards support, support for other webservers than Zope (which was the original target platform for Epoz), configurability and a lot of other issues.

3 Cross-Browser Rich Text Editor

The cross-browser rich-text editor implements the Mozilla Rich Text Editing API included with Mozilla 1.3+. There is NO LICENSE, so just take the code and use it for any purpose. This code is 100% free. Enjoy!

Requires: IE5+/Mozilla 1.3+/Mozilla Firebird/Firefox 0.6.1+/Netscape 7.1+ for all rich-text features to function properly. If browser does not support rich-text, it should display a standard textarea box.

4 TinyMCE

TinyMCE is a platform independent web based Javascript HTML WYSIWYG editor control released as Open Source under LGPL by Moxiecode Systems AB. It has the ability to convert HTML TEXTAREA fields or other HTML elements to editor instances. TinyMCE is very easy to integrate into other CMS systems.

推荐FCKeditor,是sourceforge.net上面最活跃的项目之一,功能十分强大,外观做的也很不错,还支持多语言,最重要的跨平台或者说跨浏览器也还不错。现在出到FCKeditor 2.0 RC2,就是bug似乎还多了一点,希望能尽快改善到稳定的可用版本。

部署FCKeditor时注意,如果部署为客户端Javascript的话,需要:

1. 修改fckeditor.js中的BasePath变量为editor目录所在的目录路径。

2. 调用页面中可以参照_samples目录里面的例子,不过也需要将页面中JavaScript的调用的BasePath做如上更改。同时,页面中的css样式表的路径要使用绝对路径(这个我在一般打开时相对路径可以用,但是部署为Struts应用时就不行了,改成绝对路径才可以,不知道为什么还,应该是和Struts有关)

DriverManagerDataSource in Spring Framework

In programming on 1月 29, 2005 at 3:38 下午

DriverManagerDataSource in Spring Framework

javax.sql Interface DataSource

今天看了一天的spring,想使用里面提供的JdbcTemplate,看上去非常酷的样子,不过其中涉及到了一个DataSource接口,不知道干嘛的,好不容易才找到了一个讲的比较清楚的解释。

Implementation of SmartDataSource that configures a plain old JDBC Driver via bean properties, and returns a new Connection every time.

Useful for test or standalone environments outside of a J2EE container, either as a DataSource bean in a respective ApplicationContext, or in conjunction with a simple JNDI environment. Pool-assuming Connection.close() calls will simply close the connection, so any DataSource-aware persistence code should work.

In a J2EE container, it is recommended to use a JNDI DataSource provided by the container. Such a DataSource can be exported as a DataSource bean in an ApplicationContext via JndiObjectFactoryBean, for seamless switching to and from a local DataSource bean like this class.

If you need a “real” connection pool outside of a J2EE container, consider Apache’s Jakarta Commons DBCP. Its BasicDataSource is a full connection pool bean, supporting the same basic properties as this class plus specific settings. It can be used as a replacement for an instance of this class just by changing the class name of the bean definition to “org.apache.commons.dbcp.BasicDataSource”.

“http session”的定义

In programming on 1月 28, 2005 at 6:44 上午

HTTP State Management Mechanism

STATE AND SESSIONS

This document describes a way to create stateful sessions with HTTP requests and responses. Currently, HTTP servers respond to each client request without relating that request to previous or subsequent requests; the technique allows clients and servers that wish to exchange state information to place HTTP requests and responses within a larger context, which we term a “session”. This context might be used to create, for example, a “shopping cart”, in which user selections can be aggregated before purchase, or a magazine browsing system, in which a user’s previous reading affects which offerings are presented.

There are, of course, many different potential contexts and thus many different potential types of session. The designers’ paradigm for sessions created by the exchange of cookies has these key attributes:

1. Each session has a beginning and an end.

2. Each session is relatively short-lived.

3. Either the user agent or the origin server may terminate a session.

4. The session is implicit in the exchange of state information.

Struts中谈到的session

2.2 JavaBeans and Scope

Within a web-based application, JavaBeans can be stored in (and accessed from) a number of different collections of “attributes”. Each collection has different rules for the lifetime of that collection, and the visibility of the beans stored there. Together, the rules defining lifetime and visibility are called the scope of those beans. The JavaServer Pages (JSP) Specification defines scope choices using the following terms (with the equivalent servlet API concept defined in parentheses):

  • page – Beans that are visible within a single JSP page, for the lifetime of the current request. (Local variables of the service method)
  • request – Beans that are visible within a single JSP page, as well as to any page or servlet that is included in this page, or forwarded to by this page. (Request attributes)
  • session – Beans that are visible to all JSP pages and servlets that participate in a particular user session, across one or more requests. (Session attributes)
  • application – Beans that are visible to all JSP pages and servlets that are part of a web application. (Servlet context attributes)

附录一篇:

Session详解

作者:郎云鹏(dev2dev ID: hippiewolf)

Java Server Faces Resources

In javaprogramming on 1月 21, 2005 at 1:45 下午

JamesHolmes.com
Java Server Faces Resources


Articles
Books
Blog Entries
Chats / Interviews
FAQs
Forums / Mailing Lists
In The News

Links
Presentations
Software – Components
Software – GUI Tools
Software – Implementations
Software – Miscellaneous
Tutorials

 

《I Love Lucene》总结

In javaprogramming on 1月 18, 2005 at 1:57 下午

前几天看到了TheServerSide上面的一篇文章I Love Lucene,感到对自己很有帮助,稍微总结了一下理理思路。

I Love Lucene

by Dion Almaer January 2005

Introduction

简要介绍了TheServerSite原来使用的搜索的方案,并由此引出Lucene

High level infrastructure

从高层介绍Lucene的方案,这一方案主要分成了两大部分,一部分是建立索引,另一部分是对索引进行搜索。分别介绍了这两部分的主要的接口IndexBuilderIndexSearch

Building the Index: Details of the index building process

全文最重要的一个组成部分。该部分介绍了以下四个内容:

1. 应该索引的字段

2. 索引的方式:增量索引、批量索引

3. 索引源的类型

4. 索引结果的rank

What fields should compromise our index?

讲了一下不同的索引字段使用的数据类型的问题

What types of indexing?

采用了增量索引和批量索引结合的方式,定义了一个增量索引的间隔,每隔这一间隔进行一次批量索引,在间隔内的时间内进行增量索引。同时还介绍了一下Lucene中如何删除索引记录。

What to index?

ThreadIndexSource

介绍对不同的索引源索引的问题,如对数据库中的数据索引以及对文件系统中的文件的索引。还介绍了一下索引TheServerSide的论坛中的帖子时引出的一个小技巧。

How to tweak the ranking of records?

对不同的字段赋以不同的权值来对一个文档进行较合理的rank

Searching the index

Lucene的使用主要看来是建立索引比较复杂,搜索索引极其简单,这里稍微花了一点篇幅就讲清了都,主要介绍了IndexSearch类中的search方法和查询解析类CustomQueryParser

Configuration: One place to rule them all

这部分主要介绍如何使用XML文件对搜索中的一些参数(如索引存放位置、字段权值等)进行动态配置,和Lucene其实没什么关系,主要还是说的是IoC(控制反转)的东西,讲了一下Apache Digester的使用。

XML Configuration File

Digester Rules File

Web Tier: TheSeeeeeeeeeeeerverSide?

用户搜索使用的Web界面,MVC结构。

SearchAssembler Web Action

根据用户输入构造查询语句,并讲查询语句交给IndexSearch处理,同时还负责封装查询结果。

Search View

表示层使用JSP ( for legacy reason)。根据TheServerSide上面的帖子回复,似乎说TheServerSide以后要用ApacheTapestry

Conclusion

总结,就是说Lucene很好。