躺在沙滩上的小猪

快乐的每一天

2006年2月28日 #

2006/06/29 links

FFmpeg:
http://en.wikipedia.org/wiki/FFmpeg

http://videotranscoding.wikispaces.com/



http://soenkerohde.com/tutorials/ffmpeg
http://klaus.geekserver.net/flash/streaming.html

posted @ 2006-06-29 09:56 martin xus| 编辑 收藏

2006/06/28 links

用Ruby 创建领域特定语言(DSL)
         http://uncutstone.blogdriver.com/uncutstone/1196082.html

Rails本地化
         http://blogsite.3322.org/jspwiki/pages/viewblog?id=2540

posted @ 2006-06-28 22:53 martin xus| 编辑 收藏

Postfix: The Definitive Guide



Postfix 的好书,研读中

posted @ 2006-06-03 18:40 martin xus| 编辑 收藏

Dapper release is slated for June 1st.

 
Announcing the Release Candidate for Ubuntu 6.06 LTS
https://lists.ubuntu.com/archives/ubuntu-announce/2006-May/000081.html

2006-05-25, Matt Zimmerman writes:

The Ubuntu team is proud to announce the Releases Candidate of Ubuntu, Kubuntu and Edubuntu 6.06 LTS - codenamed "Dapper Drake". The Release Candidate includes installable live Desktop CDs, server images, alternate text-mode installation CDs and an upgrade wizard for users of the current stable release.

We consider this release candidate complete, stable and suitable for testing by any user. We would especially recommend that current Ubuntu 5.10 ("Breezy Badger") users and developers use the upgrade procedure described in the announcement. Ubuntu, Kubuntu and Edubuntu 6.06 LTS will be the first Ubuntu releases with long-term support: three years on the desktop, and five years on the server.

The purpose of the Release Candidate is to solicit one last round of testing before the final release. Please read the full announcement for download locations and upgrade information. Read more about the features available in this release here.


Dapper Release Schedule
https://wiki.ubuntu.com/DapperReleaseSchedule
 
期待中...

posted @ 2006-05-29 20:49 martin xus| 编辑 收藏

2006/05/23 links

Don't repeat the DAO:
http://www-128.ibm.com/developerworks/java/library/j-genericdao.html

posted @ 2006-05-23 15:04 martin xus| 编辑 收藏

Feedburner

http://feeds.feedburner.com/martinx

posted @ 2006-05-19 09:27 martin xus| 编辑 收藏

Integrate FCKEditor with your Ruby on Rails application

http://www.joshuamcharles.com/rails/fckeditor.html

posted @ 2006-05-17 17:04 martin xus| 编辑 收藏

Rails Document

http://delynnberry.com/pages/rails-chm-documentation/

posted @ 2006-05-16 20:30 martin xus| 编辑 收藏

Post and Get

在《Agile Web Development with Rails》中看到如下的一句话

     If it has no associated data, it will come in as a GET request. If instead it contains form data, we’ll see a POST. Inside a Rails controller, the request information is available in the attribute request. We can check the request type using the methods get?( ) and post?( ).

也就是说当没有数据的时候,是get,而有数据的时候则是post.

例如我们在用户登录的时候,首先转到登录界面,这个时候当然还没有数据,那么

request.get?

为true,输入相应的数据,提交为false,这样我们可以通过一个action来控制流程
 
  def login
      
if request.get?
          session[:user_id]
=nil
          @user 
= User.new
      
else
          @user 
= User.new(params[:user])
          logged_in_user 
= @user.try_to_login
          
if logged_in_user
              session[:user_id]
=logged_in_user.id
              redirect_to :action
=>'index'
          
else
              flash[:notice]
="Invalid user/password combination"
          end
      end
  end 

posted @ 2006-05-16 10:08 martin xus| 编辑 收藏

rails 中文乱码的问题

在使用rails+mysql的时候遇到了中文乱码的问题,google了一下,解决了,把它贴出来,防止以后又忘记了

首先在application.rb中增加utf-8的filter:

class  ApplicationController  <  ActionController::Base
  before_filter :configure_charsets  

    
def  configure_charsets        
        @headers[
" Content-Type " =   " text/html; charset=utf-8 "    
    end
end

修改数据库的编码为utf-8

CHARSET=utf8

其中有一点要说明的是,我看到有人说,不能使用InnoDB,可是我测试下来的结果是,可以正常使用

posted @ 2006-05-16 09:41 martin xus| 编辑 收藏

Ruby on Rails gaining on J2EE

http://pragmatically.net/articles/2006/05/11/ruby-on-rails-gaining-on-j2ee

Ruby on Rails is rapidly gaining in popularity, at least if you believe in lies, damn lies, statistics and Google's new service, Google Trends. In the following image Ruby on Rails is the red line and J2EE the blue.

* Ruby on Rails   * J2EE



It even seems like J2EE has been loosing in popularity, and I'm not surprised at all. J2EE makes developers as happy as communism made... well communists. J2EE is central planning at it's best.

posted @ 2006-05-12 21:06 martin xus| 编辑 收藏

PLEAC

Programming Language Examples Alike Cookbook :http://pleac.sourceforge.net/

posted @ 2006-05-12 16:51 martin xus| 编辑 收藏

原来google可以这么用,太方便了

在google的搜索栏输入:
                    Agile Web Development with Rails
filetype:pdf

今天无意中在道喜技术日记上看到的,试验了一样,真的不错,不用浪费时间:)

posted @ 2006-05-12 11:25 martin xus| 编辑 收藏

install4j Enterprise Edition序列号

这东西搜索了半天才搞到,我安装的是3.2的,下面的序列号一样可以使用,共享一下,省得大家再去找了


install4j Enterprise Edition 3.1.3注册码、序列号、破解版、注册机

S/N: A-G42M#03948F-pzwgavu2ohmw#316
        A-G42M#03948F-pzwgavu2ohmw#508

install4j Proffesional Edition 3.1.2注册码、序列号、破解版、注册机

S/N: A-G4iN#89756F-9qotdnr5rq9a#0015

posted @ 2006-05-06 11:42 martin xus| 编辑 收藏

fireEvent Method

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/fireevent.asp

Fires a specified event on the object.

Syntax

bFired  =  object.fireEvent(sEvent [,oEventObject])

Parameters
sEventRequired. String that specifies the name of the event to fire.
oEventObjectOptional. Object that specifies the event object from which to obtain event object properties.

Return Value

Boolean. Returns one of the following values:

trueEvent fired successfully.
falseEvent was cancelled.

Remarks

If the event being fired cannot be cancelled, fireEvent always returns true.

Regardless of their values specified in the event object, the values of the four event properties—cancelBubble, returnValue, srcElement, and type—are automatically initialized to the values shown in the following table.

Event object propertyValue
cancelBubblefalse
returnValuetrue
srcElementelement on which the event is fired
typename of the event that is fired

Example

<html>
<head>
    
<script>
        
function fnfireevents()
        {
            odiv.innertext 
= " the cursor has moved over me! ";
            obutton.fireevent(
" onclick ");
        }
    
</script>
</head>

<body>
<h1> using the fireevent method </h1>
by moving the cursor over the div below, the button is clicked.
<p>

<div id="odiv" onmouseover="fnfireevents();">
    mouse over this!
</div>

<p>
<button id="obutton" onclick="this.innertext='i have been clicked!'">
    button 
</button>
</body>
</html>  

posted @ 2006-05-05 12:53 martin xus| 编辑 收藏

一次类型转换的错误

RoomType和RoomState的主键是Integer,在get的时候忘记转换为Integer了:

         this .getHibernateTemplate().execute( new  HibernateCallback() {
            
public  Object doInHibernate(Session session)  throws  HibernateException {
                room.setType((RoomType) session.get(RoomType.
class , typeId));
                room.setState((RoomState) session.get(RoomState.
class , stateId));
                session.update(room);
                
return   null ;
            }
        });

没想到hibernate居然大动干做,抛出一大堆的exception

java.sql.SQLException: 索引中丢失  IN 或 OUT 参数:: 1
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:
112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:
146)
    at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:
1681)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:
3280)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:
3329)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:
92)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:
139)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:
1669)
    at org.hibernate.loader.Loader.doQuery(Loader.java:
662)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:
224)
    at org.hibernate.loader.Loader.doList(Loader.java:
2145)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:
2029)
    at org.hibernate.loader.Loader.list(Loader.java:
2024)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:
375)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:
308)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:
153)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:
1129)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:
79)
    at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:
749)
    at com.phopesoft.hms.room.service.impl.RoomServiceImpl$
3.doInHibernate(RoomServiceImpl.java:151)
    at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:
366)
    at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:
334)

这样的错误真是让我一点莫不着头脑,还好从后台打出的hql看到了错误的信息

org.springframework.jdbc.UncategorizedSQLException: Hibernate operation:
 could not execute query; uncategorized SQLException 
for SQL [
 ...
 SQL state [null]; error code [17041]; 索引中丢失  IN 或 OUT 参数::1;
 nested exception is java.sql.SQLException: 索引中丢失  IN 或 OUT 参数:: 
1

不就是没找到吗,干嘛要这样呢

将String类型转换为Integer就没事了
        this.getHibernateTemplate().execute(new HibernateCallback() {
            
public Object doInHibernate(Session session) throws HibernateException {
                room.setType((RoomType) session.get(RoomType.
classnew Integer(typeId)));
                room.setState((RoomState) session.get(RoomState.
classnew Integer(stateId)));
                session.update(room);
                
return null;
            }
        });

posted @ 2006-05-03 11:16 martin xus| 编辑 收藏

JBoss 居然不认识webwork的

在resin和weblogic上跑的很好的程序,今天早上移植到JBoss上 ,页面跑到<ww:if处没法正常运行,报错,换成<c:if 就没有问题了.

一大早的被郁闷了一下

posted @ 2006-05-02 13:35 martin xus| 编辑 收藏

小结一下OpenSessionInView

感谢javaeye差沙和cac的回复.

OpenSessionInView默认的FlushMode为

FlushMode.NEVER 

可以采用在写保存更新删除代码的时候手动更改FlushMode

        this.getHibernateTemplate().execute(new HibernateCallback() { 
            
public Object doInHibernate(Session session) throws HibernateException { 
                session.setFlushMode(FlushMode.AUTO); 
                session.save(user); 
                session.flush(); 
                
return null
            } 
        }); 

但是这样做太繁琐了,第二种方式是采用spring的事务声明

    <bean id="baseTransaction" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" 
          abstract
="true"> 
        
<property name="transactionManager" ref="transactionManager"/> 
        
<property name="proxyTargetClass" value="true"/> 
        
<property name="transactionAttributes"> 
            
<props> 
                
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> 
                
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> 
                
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop> 
                
<prop key="save*">PROPAGATION_REQUIRED</prop> 
                
<prop key="add*">PROPAGATION_REQUIRED</prop> 
                
<prop key="update*">PROPAGATION_REQUIRED</prop> 
                
<prop key="remove*">PROPAGATION_REQUIRED</prop> 
            
</props> 
        
</property> 
    
</bean> 

    <bean id="userService" parent="baseTransaction"> 
        
<property name="target"> 
            
<bean class="com.phopesoft.security.service.impl.UserServiceImpl"/> 
        
</property> 
    
</bean> 

posted @ 2006-05-01 11:43 martin xus| 编辑 收藏

为何OpenSessionInView不能同时保存和删除,郁闷!

因为lazy的问题,还是采用了OpenSessionInView
一开始我的web.xml配置文件如下:

    <filter> 
        
<filter-name>opensession</filter-name> 
        
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> 
    
</filter> 

写了个保存的代码测试了一下,报如下的错误:

org.springframework.dao.InvalidDataAccessApiUsageException: Write operations 
are not allowed in read
-only mode (FlushMode.NEVER) - turn your Session 
into FlushMode.AUTO or remove 
'readOnly' marker from transaction definition 
        at org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:
1076
        at org.springframework.orm.hibernate3.HibernateTemplate$
12.doInHibernate(HibernateTemplate.java:616
        at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:
366
        at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:
614
        at com.phopesoft.security.service.impl.UserServiceImpl.addUser(UserServiceImpl.java:
40
        at com.phopesoft.security.web.UserAction.add(UserAction.java:
52
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25
        at java.lang.reflect.Method.invoke(Method.java:
585
        at com.opensymphony.xwork.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:
365


在javaeye中搜索了一下,发现了Readonly的帖子,将web.xml修改为如下:

<filter> 
        
<filter-name>opensession</filter-name> 
        
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> 
        
<init-param> 
            
<param-name>singleSession</param-name> 
            
<param-value>false</param-value> 
        
</init-param> 
    
</filter> 


保存的代码顺利通过测试,但是删除的代码却不能通过了.出现如下的错误:

org.hibernate.HibernateException: Illegal attempt to associate a collection 
with two open sessions 
        at org.hibernate.collection.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:
410
        at org.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:
40
        at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:
101
        at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:
61
        at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:
55
        at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:
123
        at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:
72
        at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:
790
        at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:
768
        at org.springframework.orm.hibernate3.HibernateTemplate$
25.doInHibernate(HibernateTemplate.java:772
        at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:
366
        at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:
766
        at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:
762

同样在论坛里面搜索到遇到这个问题的朋友,回帖说去掉singleSession!

迷惑了

posted @ 2006-04-30 15:48 martin xus| 编辑 收藏

Ruby for Rails



正好这段时间有空,开始研读rails。本身我没有ruby基础,也一直没有太大的兴趣,这本书正好是对没有ruby基础人写的rails教程。

Thanks manning:)

posted @ 2006-04-28 10:56 martin xus| 编辑 收藏

Better Builds With Maven - Free book about Maven 2



Mergere, Inc. is excited to announce the release of Better Builds with Maven, the ultimate resource to help you unleash the power of the Apache Software Foundation's Maven project. Better Builds with Maven is written by Vincent Massol, Jason van Zyl and other key contributors of the Maven community and combines detailed explanations and code examples to walk you through improving your software development process with Maven 2.0.

Better Builds with Maven covers:

  • An introduction to Maven 2.0
  • Advanced tools for "power" users
  • Creating J2EE builds and using J2EE models
  • Extending builds through plugins
  • Monitoring source code, testing, dependencies and releases
  • Leveraging repositories, continuous integration and transitive dependency
  • Converting existing Ant builds

Whether you are a current Maven user or are interested in changing software development tools, Better Builds with Maven will help you leverage the technologies and best practices found in Apache Maven.


下载:http://www.mergere.com/m2book_download.jsp

posted @ 2006-04-27 20:35 martin xus| 编辑 收藏

Dive into Python 5.4 的官方中文版

今天在python-chinese邮件列表中看到一则好消息,下面的来自maillist
Liang Osmond :
已经和原作者联系好了,Dive into Python 的官方中文版地址为 http://www.woodpecker.org.cn/diveintopython/

现在如果您访问 http://diveintopython.org/
已经是新的地址了。或者http://cn.diveintopython.org/ 直接访问

另外,Dive into Python 的官方中文版将纳入 Ubuntu 6.06 (Dapper),Ubuntu社区的 zhengpeng.hou (zhengpeng.hou AT gmail DOT com)正在制作并测试 deb 包,特表示感谢。

posted @ 2006-04-25 10:16 martin xus| 编辑 收藏

FreeMarker live template for IntelliJ IDEA

个人比较偏好IDEA,虽然eclipse有freemarker的plugin,但是还是舍不得为了一个plugin而选用Eclipse,google了一下发现有人把自己的Live template共享了,呵呵,正好拿来用用

http://weblog.flop.ca/2005/03/27/1111947748000.html

posted @ 2006-04-18 11:19 martin xus| 编辑 收藏

新书入手


好久没有去书店了,一直没空,喜欢看去逛书店,已经养成这个习惯了,每个月都回去看看。
无意中看到一本:《领域驱动设计:软件核心复杂性应对之道》觉得挺不错的,买下来研读中o_o


http://www.douban.com/subject/1629512/

posted @ 2006-04-13 11:21 martin xus| 编辑 收藏

webwork i18n编码的问题

新开发的产品需要考虑多语言的问题,i18n一直只是看过,并没有正在的用到项目中,觉得应该是个很容易的事情,谁知今天却折腾了我一把:(

首先修改webwork.properties:

webwork.locale=zh_CN
webwork.i18n.encoding
=GBK

修改native2ascii的编码
    <target name="i18n">
        
<native2ascii
                
encoding="GBK"
                src
="${src.java.dir}"
                dest
="${classes.dir}"
                includes
="**/*_zh_CN.properties"/>

        
<copy
                
todir="${classes.dir}">
            
<fileset dir="${src.java.dir}">
                
<exclude name="**/*.java"/>
                
<exclude name="**/*_zh_CN.properties"/>
            
</fileset>
        
</copy>
    
</target>

修改页面:
<%@ page contentType="text/html; charset=GBK" %>

搞定了!这个问题居然折腾我好大一会儿,一开始我以为用utf-8就行了,谁知道就是不灵:(

webwork i18n:http://www.opensymphony.com/webwork/wikidocs/Internationalization.html

posted @ 2006-04-07 15:10 martin xus| 编辑 收藏

Hibernate Query

昨天在用hibernate无意中在后台发现一个很奇怪的问题,一条SQL一直在重复执行,跑了好半天也没完成:(
仔细的看了一下,原来是在查询字典表,先执行一次总的查询出id,然后分别根据id分别select,这个字典表的内容太多了,而且本身自关联的。
当然我也知道这个只是第一次加载慢,第一次加载同时会被缓存,可是这个项目刚刚开始,这个字典表的改动是很频繁的,需要根据客户的需求而经常变动,等稳定下来再该回去。

先修改为sql:

 select c.categoryid as {category.Id}, c.categoryname as {category.Name}
           
from Tb_Article_Category c
           
where c.categoryparentid is null

跑了一下,没有通过:(

Hibernate: select c.categoryId as categoryId0_0_,c.categoryName as category2_0_0_ 
                                   from tb_article_category  c where c.categoryParentId is 
null

[
2006 - 03 - 20   09 : 12 : 38 , 812 ] - ERROR (JDBCExceptionReporter.java: 72 ) | Column  ' category3_0_0_ '  not found.

试着将表中所有的字段都写出来便没有错误了,不太明白为什么非要我写出所有字段,可是那并是我想要的,我也怕麻烦。

目前我的做法是直接返回object [],没有对每条记录转化为ArticleCategory对象。
select  c.categoryId,c.categoryName  from  tb_article_category  c  where  c.categoryParentId  is   null  

         for  (Object obj : list)  {
            Object [] str 
=
 (Object[]) obj;
            System.out.println(String.valueOf(str[
1
]));
        }

没有修改之前:

 

修改之后:
 

posted @ 2006-03-20 09:15 martin xus| 编辑 收藏

SVN Service

http://dark.clansoft.dk/~mbn/svnservice/

SVN Service Wrapper for Windows

This is my Win32 Service wrapper for SVN. Source is included, and its in the public domain. No need to copyright this stuff.

Usage instructions:

  SVNService -?                               to display this list
  SVNService -install <svnserve parameters>   to install the service
  SVNService -setup <svnserve parameters>     to change command line parameters for svnserve
  SVNService -remove                          to remove the service
  SVNService -debug                           to run as a console app for debugging

Example:

  SVNService -install -d -r c:\svnrepo
  SVNService -setup -d -r c:\otherplace\svnrepo

IMPORTANT:

  Make sure you place SVNService.exe in the same directory as svnserve.exe

Special thanks go to Craig Link at Microsoft for creating the initial service.c.

-Magnus Norddahl

posted @ 2006-03-17 10:43 martin xus| 编辑 收藏

IDEA Plugin:GroovyJ

在最新的EAP版本下跑不起来,害的我又改用了IDEA5.1
Home Page:
        http://groovy.codehaus.org/IntelliJ+IDEA+Plugin

posted @ 2006-03-16 12:54 martin xus| 编辑 收藏

dwr集成spring

dwr.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
        "http://www.getahead.ltd.uk/dwr/dwr10.dtd"
>
<dwr>
    
<allow>
        
<create creator="spring" javascript="UserDAO">
            
<param name="beanName" value="userDao"/>
            
<include method="addUser"/>
            
<include method="removeUser"/>
            
<include method="findUserByName"/>
        
</create>

        
<convert converter="bean" match="martin.dwr.demo.model.User">
            
<param name="include" value="id,name,password,age"/>
        
</convert>

    
</allow>
</dwr>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd"
>
<web-app>

    
<context-param>
        
<param-name>contextConfigLocation</param-name>
        
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
    
</context-param>

    
<listener>
        
<listener-class>
            org.springframework.web.context.ContextLoaderListener
        
</listener-class>
    
</listener>

    
<servlet>
        
<servlet-name>dwr-invoker</servlet-name>
        
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
        
<init-param>
            
<param-name>debug</param-name>
            
<param-value>true</param-value>
        
</init-param>
        
<init-param>
            
<param-name>config-admin</param-name>
            
<param-value>WEB-INF/classes/dwr.xml</param-value>
        
</init-param>
    
</servlet>

    
<servlet-mapping>
        
<servlet-name>dwr-invoker</servlet-name>
        
<url-pattern>/dwr/*</url-pattern>
    
</servlet-mapping>
</web-app>

applicationContext.xml
    <bean id="userDao" class="martin.dwr.demo.dao.hibernate.HibernateUserDAO">
        
<property name="sessionFactory" ref="sessionFactory"/>
    
</bean>

浏览:http://localhost:8080/demo/dwr/index.html 查看调试信息

posted @ 2006-03-15 22:44 martin xus| 编辑 收藏

配置spring,通过Annotations生成SessionFactory

AnnotationSessionFactoryBean 继承LocalSessionFactoryBean

今天用到,查了一下refrence,顺便把它贴出来:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
        "http://www.springframework.org/dtd/spring-beans.dtd"
>
<beans>
    
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        
<property name="location">
            
<value>classpath:jdbc.properties</value>
        
</property>
    
</bean>

    
<bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
          destroy-method
="close">
        
<property name="driverClass">
            
<value>${db.driverClass}</value>
        
</property>
        
<property name="jdbcUrl">
            
<value>${db.url}</value>
        
</property>
        
<property name="properties">
            
<props>
                
<prop key="c3p0.acquire_increment">5</prop>
                
<prop key="c3p0.idle_test_period">100</prop>
                
<prop key="c3p0.max_size">100</prop>
                
<prop key="c3p0.max_statements">0</prop>
                
<prop key="c3p0.min_size">10</prop>
                
<prop key="user">${db.user}</prop>
                
<prop key="password">${db.pass}</prop>
            
</props>
        
</property>
    
</bean>

    
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        
<property name="hibernateProperties">
            
<props>
                
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
                
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            
</props>
        
</property>
        
<property name="dataSource" ref="c3p0DataSource"/>
        
<property name="annotatedClasses" value="martin.dwr.demo.model.User"/>
    
</bean>

    
<bean id="userDao" class="martin.dwr.demo.dao.hibernate.HibernateUserDAO">
        
<property name="sessionFactory" ref="sessionFactory"/>
    
</bean>
</beans>

posted @ 2006-03-15 22:09 martin xus| 编辑 收藏

Smack Quick Start

Smack is a library for communicating with XMPP servers to perform instant messaging and chat.
 

package cn.martin.xmpp;

import org.jivesoftware.smack.GroupChat;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.packet.Message;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.AfterClass;

/**
 * 
@author martin
 
*/
public class SmackTest {
    
private static XMPPConnection con;

    @BeforeClass
    
public static void getConnection() throws XMPPException {
        con 
= new XMPPConnection("rabbit");
        con.login(
"martinx""1234");
    }

    @Test
    
public void chatWithSingle() throws XMPPException {
        con.createChat(
"martin@rabbit").sendMessage("Simple Message");
    }

    @Test
    
public void chatWithGroup() throws XMPPException {
        String room 
= "dd@conference.rabbit";
        GroupChat groupChat 
= con.createGroupChat(room);
        groupChat.join(
"martinx");
        Message message 
= groupChat.createMessage();
        message.setBody(
"Group Chat Test");
        groupChat.sendMessage(message);
    }

    @Test
    
public void chatWithReturnedMessage() throws XMPPException {
        Chat chat 
= con.createChat("martin@rabbit");

        Message message 
= chat.createMessage();
        message.setBody(
"Hello Martin");
        message.setProperty(
"favoriteColor""red");
        chat.sendMessage(message);

        
//获取回复
        while (true) {
            Message _message 
= chat.nextMessage();
            chat.sendMessage(_message.getBody());
        }
    }

    @AfterClass
    
public static void closeConnection() {
        con.close();
    }
}

看了http://forum.javaeye.com/viewtopic.php?t=19089很是感兴趣,想做一个,明天继续

posted @ 2006-03-15 18:24 martin xus| 编辑 收藏

IDEA's blog

http://blogs.jetbrains.com/idea/

posted @ 2006-03-14 21:14 martin xus| 编辑 收藏

[ZT]JUnit 4.0 in 10 minutes

http://www.instrumentalservices.com/index.php?option=com_content&task=view&id=45&Itemid=52
Gunjan Doshi
Instrumental Services Inc.


Abstract: JUnit needs no introduction. Originally written by Kent Beck and Erich Gamma, the software is the preferred tool of choice for developer testing. Now, the team of Kent Beck and Erich Gamma is back again with a new version of JUnit – 4.0. This quick reference guide is for programmers and testers looking to migrate to JUnit 4.0. If you have a flight to catch or do not want to spend 10 minutes going through the guide, just jump to the summary section and you will learn enough.

For the purpose of this article, I will call JUnit 3.8.1 and its predecessors as the old JUnit and JUnit 4.0 as the new JUnit.

Table of contents:

This guide contains the following sections:

·         Old JUnit revisited

·         Cut the chase to JUnit 4.0

·         Run the tests

·         Set up and tear down

·         One-time set up and tear down

·         Expecting exceptions

·         Other Annotations

o              Ignoring a test

o              Timing out a test

·         Summary

Old JUnit revisited

Using the old JUnit, let us write a test, which verifies the availability of a book in the library.

To summarize the steps:

·         We extend from junit.framework.TestCase.

·         We name the test methods with a prefix of ‘test’.

·         We validate conditions using one of the several assert methods.

Cut the chase to JUnit 4.0

Let us write the same test using JUnit 4.0.

When I upgrade to a new version I look for tasks, I do not have to do anymore. Here is the same code with notes telling us what not to do anymore.

To summarize:

·         We do not extend from junit.framework.TestCase.

·         We do not prefix the test method with ‘test’.

Next, I look for new tasks I must always do. The diagram below summarizes what we must do according to the new JUnit standards:

To summarize:

·         Use a normal class and not extend from junit.framework.TestCase.

·         Use the Test annotation to mark a method as a test method. To use the Test annotation, we need to import org.junit.Test

·         Use one of the assert methods. There is no difference between the old assert methods and the new assert methods. An easy way to use the assert method is to do a static import as shown by point 2 in the code above.

·         Run the test using JUnit4TestAdapter. If you want to learn more about JUnit4TestAdapter, keep reading ahead.

Run the tests

Unfortunately, our favorite development environments are still unaware of JUnit 4. JUnit4Adapter enables compatibility with the old runners so that the new JUnit 4 tests can be run with the old runners. The suite method in the diagram above illustrates the use of JUnit4Adapter.

Alternatively, you can use the JUnitCore class in the org.junit.runner package. JUnit 4 runner can also run tests written using the old JUnit. To run the tests using the JUnitCore class via the command line, type:

java org.junit.runner.JUnitCore LibraryTest

Set up and tear down

The new JUnit provides two new annotations for set up and tear down:

·         @Before: Method annotated with @Before executes before every test.

·         @After: Method annotated with @After executes after every test.

Here is the code that demonstrates the use of @Before and @After:

Two features of @Before and @After annotations that are helpful to learn:

·         You can have any number of @Before and @After as you need.

·         It is possible to inherit the @Before and @After methods. New JUnit executes @Before methods in superclass before the inherited @Before methods. @After methods in subclasses are executed before the inherited @After methods.

One-time set up and tear down

The new JUnit4 provides @BeforeClass and @AfterClass annotations for one-time set up and tear down. This is similar to the TestSetup class in the old junit.extensions package, which ran setup code once before all the tests and cleanup code once after all the tests.

Here is the code that demonstrates @BeforeClass and @AfterClass:

Unlike @Before and @After annotations, only one set of @BeforeClass and @AfterClass annotations are allowed.

Expecting exceptions

The new JUnit makes checking for exceptions very easy. The @Test annotation takes a parameter, which declares the type of Exception that should be thrown. The code below demonstrates this:

In the code above, bookNotAvailableInLibrary is a test, which passes only if BookNotAvailableException is thrown. The test fails if no exception is thrown. Test also fails if a different exception is thrown.

Other Annotations

Ignoring a test

The @Ignore annotation tells the runner to ignore the test and report that it was not run. You can pass in a string as a parameter to @Ignore annotation that explains why the test was ignored. E.g. The new JUnit will not run a test method annotated with @Ignore(“Database is down”) but will only report it. The version of JUnit4Adapter, I used, did not work with @Ignore annotation. Kent Beck has informed me that the next version of JUnitAdapter will fix this problem.

Timing out a test

You can pass in a timeout parameter to the test annotation to specify the timeout period in milliseconds. If the test takes more, it fails. E.g. A method annotated with @Test (timeout=10) fails if it takes more than 10 milliseconds.

Finally, I would like to thank Kent Beck for taking the time to demonstrate and teach the new JUnit to me.

Summary

To summarize the new JUnit style:

  1. It Requires JDK 5 to run.
  2. Test classes do not have to extend from junit.framework.TestCase.
  3. Test methods do not have to be prefixed with ‘test’.
  4. There is no difference between the old assert methods and the new assert methods.
  5. Use @Test annotations to mark a method as a test case.
  6. @Before and @After annotations take care of set up and tear down.
  7. @BeforeClass and @AfterClass annotations take care of one time set up and one time tear down.
  8. @Test annotations can take a parameter for timeout. Test fails if the test takes more time to execute.
  9. @Test annotations can take a parameter that declares the type of exception to be thrown.
  10. JUnit4Adapter enables running the new JUnit4 tests using the old JUnit runners.
  11. Old JUnit tests can be run in the new JUnit4 runner.

posted @ 2006-03-14 10:07 martin xus| 编辑 收藏

Prototype Gets Some Serious Syntactic Sugar

http://encytemedia.com/blog/articles/2006/03/07/prototype-gets-some-serious-syntactic-sugar

posted @ 2006-03-13 14:25 martin xus| 编辑 收藏

It is time to stop listening to James Gosling

http://marcus.ahnve.net/?p=122

总有这样的话题 

posted @ 2006-03-13 09:50 martin xus| 编辑 收藏

Hibernate Annotations(1)

     摘要: 今天有时间大体看了一下Hibernate Annotations,决定放弃xdoclet生成hbm的想法,开始学习annotation.首先大体的来看一下:一:Class Level:1:通过@Entity声明当前pojo为实体Bean2:通过@Table定义对应数据库表的属性   name:表名,默认实体类名   uniqueConstraints:定义表...  阅读全文

posted @ 2006-03-09 22:50 martin xus| 编辑 收藏

应需求添加每天定时生成索引

无非就是两种方法
1:Servlet
2: Listener
 
Servlet:
package 

import org.apache.log4j.Logger;
import javax.servlet.http.HttpServlet;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * 
@author martin
 
*/
public class LuceneTimerServlet extends HttpServlet {
    
private static Logger logger = Logger.getLogger(LuceneTimerServlet.class);
    
private static Timer timer;

    
static {
        timer 
= new Timer(true);
        timer.schedule(
new TimerTask() {
            
public void run() {
                System.out.println(
"开始创建索引@" + getTime(Calendar.getInstance()));
                TaxDocIndexer indexer 
= new TaxDocIndexer();
                indexer.setFirstRun(Boolean.TRUE);
                indexer.fetch();
                System.out.println(
"索引创建成功@" + getTime(Calendar.getInstance()));
            }
        },
                getFirstTime(),
                getPeriod()
        );
    }


    
public void destroy() {
        logger.debug(
"LuceneTimerServlet.destroy() begin");
        timer.cancel();
    }

    
/**
     * 从服务启动起算,第二天零时开始执行
     *
     * 
@return Timer第一次执行时间
     
*/
    
private static Date getFirstTime() {
        Calendar calendar 
= Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_YEAR, 
1);
        calendar.set(Calendar.HOUR_OF_DAY, 
0);
        calendar.set(Calendar.MINUTE, 
0);
        calendar.set(Calendar.SECOND, 
0);
        logger.debug(
"开始执行时间:" + getTime(calendar));
        
return calendar.getTime();
    }

    
/**
     * 
@param calendar
     * 
@return formated time string
     
*/
    
private static String getTime(Calendar calendar) {
        
return new StringBuffer()
                .append(calendar.get(Calendar.YEAR)).append(
"")
                .append(calendar.get(Calendar.MONTH) 
+ 1).append("")
                .append(calendar.get(Calendar.DAY_OF_MONTH)).append(
"日  ")
                .append(calendar.get(Calendar.HOUR_OF_DAY)).append(
"")
                .append(calendar.get(Calendar.MINUTE)).append(
"")
                .append(calendar.get(Calendar.SECOND)).append(
"")
                .toString();
    }

    
/**
     * 计算一天的时间间隔
     * 一天24小时×每小时60分×每分60秒×1000
     *
     * 
@return 一天时间
     
*/
    
private static long getPeriod() {
        
return 86400000;
    }
}

配置web.xml
    <servlet>
        
<servlet-name>luceneTimerServlet</servlet-name>
        
<servlet-class>sompackage.servlet.LuceneTimerServlet</servlet-class>
        
<load-on-startup>1</load-on-startup>
    
</servlet>


如果采用Listener,则是:
    <listener>    
        <listener-class>sompackage.servlet.LuceneTimerServlet</listener-class>
    
</listener>

posted @ 2006-03-08 12:42 martin xus| 编辑 收藏

名人,垃圾!

以前总在珠江路上看到名人专卖店,以为名人还不错,谁知道买了个电子词典,到家就花屏!

NND,骗子!以后肯定不会看名人的产品!

posted @ 2006-03-07 12:51 martin xus| 编辑 收藏

终究还是决定走了

走了,正在准备办理离职手续,心里总觉的有点点失落,也许我还真的对这个公司有点期盼,也许对自己的选择不是太满意,也许我没有做到我自己想做的事太多,也许什么都不是只是我的心情不好,走了,终究决定走了...

该去寻找我自己的天空去了,我不可这样堕落的活下去了,自己对自己得有个交代。

我看中了一家小公司,是我朋友的,我可以按我想法的去给公司开发成品,我可以用我最喜欢的技术,我可以做我任何想做的事,我自由了!

祝自己好运!

posted @ 2006-03-03 11:12 martin xus| 编辑 收藏

Lucene 1.9-final release available

From: Doug Cutting <cutting@apache.org>
To: java-user@lucene.apache.org
------------------------
Release 1.9-final of Lucene is now available from:

http://www.apache.org/dyn/closer.cgi/lucene/java/

This release has many improvements since release 1.4.3, including new
features, performance improvements, bug fixes, etc.  For details, see:

http://svn.apache.org/viewcvs.cgi/*checkout*/lucene/java/tags/lucene_1_9_final/CHANGES.txt

1.9 will be the last 1.x release. It is both back-compatible with 1.4.3
and forward-compatible with the upcoming 2.0 release. Many methods and
classes in 1.4.3 have been deprecated in 1.9 and will be removed in 2.0.
 Applications must compile against 1.9 without deprecation warnings
before they are compatible with 2.0.

Doug

posted @ 2006-03-02 09:12 martin xus| 编辑 收藏

Prototype Documentation

http://www.prototypedoc.com/

Quick Guide to Prototype [particletree.com]
Prototype in script.aculo.us Wiki [wiki.script.aculo.us]

posted @ 2006-03-01 15:02 martin xus| 编辑 收藏

JavaScript 编码规范

http://dojotoolkit.org/js_style_guide.html

http://www.ajaxcn.org/space/start/2006-02-19/1

posted @ 2006-03-01 11:11 martin xus| 编辑 收藏

Encarta® Instant Answers:)

Encarta® Instant Answers says:
Hi again, martin.xus! How can I help you?
Did you know? With only a few exceptions, true cacti are found exclusively in the Western Hemisphere.

今早它突然冒出来这么一句 好玩:)

posted @ 2006-02-28 10:06 martin xus| 编辑 收藏

小结

上一周一直在做全文检索,做个小结:

一:关于Lucene
    这个没什么可说的了,有什么问题看Lucene in Action,要是还没能解答问题,请教mail-list

二:万恶的LOB
    我的情况:JDK1.3.1,本地测试是oracle的驱动,测试机上是weblogic的驱动,必须在提交的时候手工改为
 
OutputStream out =(( weblogic.jdbc.common.OracleBlob)blob).getBinaryOutputStream();

三:另存为word

   在写文件前添加如下代码:
<%@ page contentType="application/vnd.ms-word;charset=gbk" language="java" %>
<html>
<%
    
String docName =new String(request.getParameter("docName") .getBytes("GB2312"),"8859_1");
    response.setHeader(
"Content-disposition""attachment;filename=" + docName + ".doc");
%>

四:XML解析
   XStream


五:AJAX
   prototype

posted @ 2006-02-28 09:58 martin xus| 编辑 收藏