
2006年3月14日
总共在dearbook买过二次书,上周未晚订了本expert one-on-on J2EE Development without EJB,今天一大早就送过来了。。。
不过75折后加上送货费,又和原价差不了多少了。。
posted @
2006-03-14 09:54 HexUzHoNG 阅读(464) |
评论 (0) |
编辑 收藏

2006年2月3日
Finding the Matching Text
有时候你需要把字符串中匹配正则表达式的那一段找出来,接着前一个例子(4.2)你可以调用“查找”方法成功后,调用下面的方法将匹配的字符串找出来。:)
start(), end() 返回字符串中匹配正则表达式的子串的开始位置和结束位置
groupCount() 返回()号匹配的数目,如果有的话。返回0表示没有使用()组,下面将会有介绍
group(int i) 返回正则表达式()匹配的第i组,如果i小于或等于groupCount()则返回相应的()匹配值,如果调用group(0)或group()则返回整个匹配正则表达式的部分
下面这个例子使用group()直接将整个匹配正则表达式的子字符串取出来:

public static void main(String[] args)
{
// 匹配Q开头,第二个字符不为u,后面接数字1次或多次,后面再.号
String pattern = "Q[^u]\\d+\\.";
Pattern p = Pattern.compile(pattern);

String line = "Order QT300. Now !";

Matcher m = p.matcher(line);

if (m.find())
{
// m.group()须调用相关查找方法成功后才能调用
System.out.println(pattern + " matches \"" + m.group() + "\" in \""
+ line + "\"");

} else
{
System.out.println("NO MATCH");
}
}

// 输出:Q[^u]\d+\. matches "QT300." in "Order QT300. Now !"上面这个例子也可以使用start(), end()方法来完成:

public static void main(String[] args)
{
String pattern = "Q[^u]\\d+\\.";
Pattern p = Pattern.compile(pattern);

String line = "Order QT300. Now!";
Matcher m = p.matcher(line);


if (m.find())
{
System.out.println(pattern + " matches \""
+ line.substring(m.start(), m.end()) + "\" in \"" + line
+ "\"");

} else
{
System.out.println("NO MATCH!");
}
}假设你想将字符串:
Smith, John
通过正则转换为:
John Smith
可以这样做:

public static void main(String[] args)
{
String line = "Smith, John";
// 这就是上面所说的()号,如果调用groupCount()的话,将输出2
// 匹配任何字符0次或多次,然后是","号和空格,再匹配任何字符0次和多次
// 上面的任何字符不包括换行符
Pattern p = Pattern.compile("(.*), (.*)");

Matcher m = p.matcher(line);

if (m.find())
{
// 先取上面正则()中匹配的group 2,也就是John
// 然后再取()中匹配的group 1,也就是Smith
System.out.println(m.group(2) + ' ' + m.group(1));

} else
{
System.out.println("NO MATCH!");
}
}

// 输出: John Smith
posted @
2006-02-03 00:07 HexUzHoNG 阅读(573) |
评论 (0) |
编辑 收藏

2006年2月2日
gmailclipse
近日在cnbeta上看到一个基于eclipse rcp的类似于gmail driver的工具。
-----
Gmailclipse在文件系统的格式上借鉴了Gmail Drive并对其所上传的文件能够完全兼容,但内部采用了不同的实现机制.与Gmail Drive及其它的类似软件相比,Gmailclipse最大的改进就是用户的上传文件不再受10M附件大小的限制,同时实现了对长文件名的支持,从而将 Gmail变成了真正意义上的网络硬盘.
-----
刚刚成功上传了12M左右的tomcat5.0.28。 :)
目前似乎有三款名为gmailclipse的东东。
1.上面介绍的这个是国内一网友编写的(功能类似于gmail driver)
2.eclipse plugins 的 gmailclipse
3.似乎也是RCP的gmailclipse
2和3的功能似乎着重于收信上面,没试过,在http://rapidshare.de/下载速度N慢。。大概是同一帮人写的,分成了两个不同版本,一个plugin,一个application。
2和3是它是基于G4J: http://g4j.sourceforge.net/
------
GMailer API for Java (g4j) is set of API that allows Java programmer to communicate to GMail. With G4J programmers can made Java based application that based on huge storage of GMail.
------
posted @
2006-02-02 16:42 HexUzHoNG 阅读(510) |
评论 (0) |
编辑 收藏
在JDK1.4中添加了java.util.regex这个包,用来处理正则表达式。
在java中我们可以简单的使用String类的 matches() 方法来判断当前字符串是否符合你所给定的正则表达式模式。matches()方法接受正则表达式做为参数,返回boolean类型。

if (inputString.matches(regexPattern))
{
// 字符串inputString匹配regexPattern这个模式
}代码很简单,但是效率不高,如果在程序中使用不止一次,我们可以使用Pattern和Matcher,例子见下:

public static void main(String[] args) throws PatternSyntaxException
{
String pattern = "^Q[^u]\\d+\\.";
String input = "Qa777. is the next flight. It is on time.";

Pattern p = Pattern.compile(pattern);
boolean found = p.matcher(input).lookingAt();

System.out.println("'" + pattern + "'"
+ (found ? " matches '" : " doesn't match '") + input + "'");
}
在程序中使用正则表达式的步骤一般如下:
1. 建立Pattern对象,通过静态方法Pattern.compile();
2. 取得Matcher对象,通过pattern.matcher(CharSequence charSequence);
3. 调用Matcher对象的相关查找方法。
java.lang.CharSequence接口是在JDK1.4版本中被添加进来的,它为不同种类的char序列提供了统一的只读访问。实现的类有String, StringBuffer, java.nio.CharBuffer
Matcher提供几个有不同的查找方法,比String类的matches()方法更灵活,如下:
match() 使用整个字符串与相关模式相比较,和String的matches()差不多
lookingAt() 从字符串开头的地方与相关模式比较
find() 匹配字符串,没有必要从字符串的第一个字符开始,如果前一个操作匹配,而且匹配器没有重置的话,则从不匹配的第一个字符开始。
上面每个方法都返回boolean类型,返回true则意味的匹配,返回false则不匹配。
要检测给定的String是否匹配给定的模式,只须下面这样就可以了:
Matcher m = Pattern.compile(yourPattern).matcher(yourString);


if (m.find())
{
System.out.println("match");

} else
{
System.out.println("no match");
}
posted @
2006-02-02 13:02 HexUzHoNG 阅读(559) |
评论 (0) |
编辑 收藏

2006年1月28日
弄hibernate时,想显示sql语句,可以设置show_sql为true来达到这个目的,但是参数值全是像PreparedStatement一样,用?来代替的。
用p6spy可以达到显示的那些参数原值的目的,但可读性差。可以利用SQL Profiler来处理这个事情。
p6spy: http://www.p6spy.com
SQL Profile: http://www.jahia.net/jahia/page597.html
p6spy安装:
* 将p6spy.jar放到WEB-INF/lib目录下,将spy.properties放到WEB-INF/classes目录下。
* 修改你 原有 JDBC Driver为:com.p6spy.engine.spy.P6SpyDriver
* 修改 spy.properties 中的 realdriver 值为 原有 的JDBC Driver,比如我的是:com.mysql.jdbc.Driver
* 完成,运行web server。
我的日志记录产生在 %TOMCAT_HOME%\bin下,此log位置可以能过修改 logfile = x:\x_dir\spy.log 来控制
打开看看,看里面的日志是不是看起来比较不爽?下面我们安装SQL Profiler来让自已的视线爽一点。
SQL Profiler安装:(须p6spy成功安装)
* 将SQL Profiler自带的spy.properties覆盖原来的classes目录下文件
* 修改现在spy.properties中realdriver 值为 原有 的JDBC Driver
看后看看readme注意这几句 ^__^ :
1. Start the GUI
2. Start the webapp, in starts doing some JDBC requests we will ignore
3. Press the "reset" button on the GUI
4. Make a request to the webapp
5. Press the "pause" button after the request has finished executing
6. Press the "report" button to save profiling results as a CSV file
* 我们先用java -jar sqlprofiler.jar 运行 sql profiler
* 然后启动web server :-)
一切尽在眼前了吧?
当然,p6spy 和 sql profiler 能做的不止这些,sql profiler还能根据你的query来帮你生成建立合适的index功能等等。
PS: 祝大家新年快乐,万事如意。
posted @
2006-01-28 23:05 HexUzHoNG 阅读(5291) |
评论 (4) |
编辑 收藏

2006年1月1日
Quote:
Subversion是一个优秀的版本控制工具,因为关于版本许多人把这个单词想当然的理解为“子版本”,实际上subversion本身是一个单词,并不是合成词,它的意思是颠覆。
这本身就是个很酷的单词,而我们也要颠覆许多我们习以为常的事情,用Subversion改变我们的工作和生活。
http://www.javaforge.com 提供免费的Subversion服务器申请,对于公司来说也许没什么很大的用处,但对网上朋友小型的团队开发,而又没有自已的版本控制服务器的朋友来说还是挺有用的。
昨天申请了个试了试:注册帐号,建立项目,就可以即时开通这项服务了,无需提交给管理员验证。爽!
申请后,可以通过svn客户端(如eclipse的subclipse)访问
http://svn.javaforge.com:80/svn/项目名 来进行管理了。
posted @
2006-01-01 10:10 HexUzHoNG 阅读(4137) |
评论 (6) |
编辑 收藏