﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-Thinking</title><link>http://www.blogjava.net/kawaii/</link><description>快乐编程，开心生活</description><language>zh-cn</language><lastBuildDate>Tue, 28 Apr 2026 19:03:43 GMT</lastBuildDate><pubDate>Tue, 28 Apr 2026 19:03:43 GMT</pubDate><ttl>60</ttl><item><title>CCP Review-Javascript</title><link>http://www.blogjava.net/kawaii/archive/2007/11/27/163576.html</link><dc:creator>lixw</dc:creator><author>lixw</author><pubDate>Tue, 27 Nov 2007 15:41:00 GMT</pubDate><guid>http://www.blogjava.net/kawaii/archive/2007/11/27/163576.html</guid><wfw:comment>http://www.blogjava.net/kawaii/comments/163576.html</wfw:comment><comments>http://www.blogjava.net/kawaii/archive/2007/11/27/163576.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kawaii/comments/commentRss/163576.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kawaii/services/trackbacks/163576.html</trackback:ping><description><![CDATA[CCP Review-Javascript<br />
1、对于div中的input标签，如果div的style.display属性为'none'，那么调用input标签的focus方法在IE6.0上会报错，首先应该让其display属性为''或者'block'再调用；<br />
2、当HTML元素的name属性唯一时可以利用document.getElementById()调用获得这个元素；<br />
3、如果异步提交耗时较长，可在异步提交之前显示等待提示，在回调函数中根据返回值更新提示；<br />
4、在JS中function也是可以作为变量的，所以我们可以在自己封装的框架中预留回调函数供自定义使用，如下面的代码：<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #008080;">&nbsp;1</span>&nbsp;<span style="color: #008000;">//</span><span style="color: #008000;">common.js</span><span style="color: #008000;"><br />
</span><span style="color: #008080;">&nbsp;2</span>&nbsp;<span style="color: #0000ff;">var</span><span style="color: #000000;">&nbsp;callback&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">null</span><span style="color: #000000;">;<br />
</span><span style="color: #008080;">&nbsp;3</span>&nbsp;<span style="color: #0000ff;">function</span><span style="color: #000000;">&nbsp;commonUse(){<br />
</span><span style="color: #008080;">&nbsp;4</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;<img src="http://www.blogjava.net/Images/dot.gif" alt="" /><br />
</span><span style="color: #008080;">&nbsp;5</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(</span><span style="color: #0000ff;">typeof</span><span style="color: #000000;">(callback)&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">function</span><span style="color: #000000;">"</span><span style="color: #000000;">){<br />
</span><span style="color: #008080;">&nbsp;6</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;callback(<img src="http://www.blogjava.net/Images/dot.gif" alt="" />);<br />
</span><span style="color: #008080;">&nbsp;7</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;}<br />
</span><span style="color: #008080;">&nbsp;8</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;<img src="http://www.blogjava.net/Images/dot.gif" alt="" /><br />
</span><span style="color: #008080;">&nbsp;9</span>&nbsp;<span style="color: #000000;">}<br />
</span><span style="color: #008080;">10</span>&nbsp;<span style="color: #000000;"><br />
</span><span style="color: #008080;">11</span>&nbsp;<span style="color: #008000;">//</span><span style="color: #008000;">self.js</span><span style="color: #008000;"><br />
</span><span style="color: #008080;">12</span>&nbsp;<span style="color: #0000ff;">function</span><span style="color: #000000;">&nbsp;selfUse(){<br />
</span><span style="color: #008080;">13</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;<img src="http://www.blogjava.net/Images/dot.gif" alt="" /><br />
</span><span style="color: #008080;">14</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;callback&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">function</span><span style="color: #000000;">(<img src="http://www.blogjava.net/Images/dot.gif" alt="" />){<br />
</span><span style="color: #008080;">15</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">do&nbsp;something&nbsp;before</span><span style="color: #008000;"><br />
</span><span style="color: #008080;">16</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;}<br />
</span><span style="color: #008080;">17</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;commonUse();<br />
</span><span style="color: #008080;">18</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;<img src="http://www.blogjava.net/Images/dot.gif" alt="" /><br />
</span><span style="color: #008080;">19</span>&nbsp;<span style="color: #000000;">}</span></div>
<br />
5、JS中可以使用正则表达式来校验数字域、日期域和EMail等。代码示例如下：<br />
校验日期的例子：<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #008080;">&nbsp;1</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">function</span><span style="color: #000000;">&nbsp;isDate(date){<br />
</span><span style="color: #008080;">&nbsp;2</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">对日期格式进行验证&nbsp;要求为2000-2099年&nbsp;&nbsp;格式为&nbsp;yyyy-mm-dd&nbsp;并且可以正常转换成正确的日期</span><span style="color: #008000;"><br />
</span><span style="color: #008080;">&nbsp;3</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">var</span><span style="color: #000000;">&nbsp;regex</span><span style="color: #000000;">=/^</span><span style="color: #000000;">(</span><span style="color: #000000;">19</span><span style="color: #000000;">|</span><span style="color: #000000;">20</span><span style="color: #000000;">)\d{</span><span style="color: #000000;">2</span><span style="color: #000000;">}</span><span style="color: #000000;">-</span><span style="color: #000000;">((</span><span style="color: #000000;">0</span><span style="color: #000000;">[</span><span style="color: #000000;">1</span><span style="color: #000000;">-</span><span style="color: #000000;">9</span><span style="color: #000000;">]{</span><span style="color: #000000;">1</span><span style="color: #000000;">})</span><span style="color: #000000;">|</span><span style="color: #000000;">(</span><span style="color: #000000;">1</span><span style="color: #000000;">[</span><span style="color: #000000;">0</span><span style="color: #000000;">-</span><span style="color: #000000;">2</span><span style="color: #000000;">]{</span><span style="color: #000000;">1</span><span style="color: #000000;">}))</span><span style="color: #000000;">-</span><span style="color: #000000;">((</span><span style="color: #000000;">0</span><span style="color: #000000;">[</span><span style="color: #000000;">1</span><span style="color: #000000;">-</span><span style="color: #000000;">9</span><span style="color: #000000;">]{</span><span style="color: #000000;">1</span><span style="color: #000000;">})</span><span style="color: #000000;">|</span><span style="color: #000000;">([</span><span style="color: #000000;">1</span><span style="color: #000000;">-</span><span style="color: #000000;">2</span><span style="color: #000000;">]{</span><span style="color: #000000;">1</span><span style="color: #000000;">}[</span><span style="color: #000000;">0</span><span style="color: #000000;">-</span><span style="color: #000000;">9</span><span style="color: #000000;">]{</span><span style="color: #000000;">1</span><span style="color: #000000;">})</span><span style="color: #000000;">|</span><span style="color: #000000;">(</span><span style="color: #000000;">3</span><span style="color: #000000;">[</span><span style="color: #000000;">0</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">]{</span><span style="color: #000000;">1</span><span style="color: #000000;">}))$</span><span style="color: #000000;">/</span><span style="color: #000000;">;<br />
</span><span style="color: #008080;">&nbsp;4</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #008080;">&nbsp;5</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(</span><span style="color: #000000;">!</span><span style="color: #000000;">regex.test(date)){<br />
</span><span style="color: #008080;">&nbsp;6</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">false</span><span style="color: #000000;">;<br />
</span><span style="color: #008080;">&nbsp;7</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080;">&nbsp;8</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">var</span><span style="color: #000000;">&nbsp;arr_</span><span style="color: #000000;">=</span><span style="color: #000000;">date.split(</span><span style="color: #000000;">"</span><span style="color: #000000;">-</span><span style="color: #000000;">"</span><span style="color: #000000;">);<br />
</span><span style="color: #008080;">&nbsp;9</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">var</span><span style="color: #000000;">&nbsp;tmp&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">new</span><span style="color: #000000;">&nbsp;Date(arr_[</span><span style="color: #000000;">0</span><span style="color: #000000;">],&nbsp;parseFloat(arr_[</span><span style="color: #000000;">1</span><span style="color: #000000;">])</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">,&nbsp;parseFloat(arr_[</span><span style="color: #000000;">2</span><span style="color: #000000;">]));<br />
</span><span style="color: #008080;">10</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(tmp.getFullYear()</span><span style="color: #000000;">!=</span><span style="color: #000000;">parseFloat(arr_[</span><span style="color: #000000;">0</span><span style="color: #000000;">])&nbsp;<br />
</span><span style="color: #008080;">11</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">||</span><span style="color: #000000;">&nbsp;tmp.getMonth()</span><span style="color: #000000;">!=</span><span style="color: #000000;">parseFloat(arr_[</span><span style="color: #000000;">1</span><span style="color: #000000;">])</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">&nbsp;<br />
</span><span style="color: #008080;">12</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">||</span><span style="color: #000000;">&nbsp;tmp.getDate()</span><span style="color: #000000;">!=</span><span style="color: #000000;">parseFloat(arr_[</span><span style="color: #000000;">2</span><span style="color: #000000;">])){<br />
</span><span style="color: #008080;">13</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">false</span><span style="color: #000000;">;<br />
</span><span style="color: #008080;">14</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080;">15</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #008080;">16</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">true</span><span style="color: #000000;">;<br />
</span><span style="color: #008080;">17</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;}</span></div>
&nbsp; 这篇文章有详细的说明：<a target="_blank" href="http://www.blogjava.net/byterat/archive/2006/12/20/89143.html">http://www.blogjava.net/byterat/archive/2006/12/20/89143.html</a><br />
&nbsp; 这本电子书是讲解正则表达式的：<a target="_blank" href="http://www.blogjava.net/Files/kawaii/RegularExpressions.zip">http://www.blogjava.net/Files/kawaii/RegularExpressions.zip</a>&nbsp;  <br />
6、在JS编码中，如果代码量较大，要注意防止function名称重复，包括直接在页面上编写的和引用外部JS文件的，不然会出现一些莫名奇妙的问题；<br />
7、注意JS代码中的函数返回语句return的使用；<br />
8、尽量把JS代码写在外部公共的文件中，而在页面中引入，好处有：a.函数复用；b.JS文件缓存；c.提供页面解析速度。基于b，我们在修改JS代码后，要看IE的设置是否将原先的JS文件缓存造成问题；<br />
9、对于同一个页面的多个表单提交，我们可以在第一个表单中设置相应的隐藏域，在表单提交之前利用JS脚本把其他表单的数据设置到第一个表单的隐藏域中；<br />
10、对于异步校验的文本框，我们一般设置触发事件为onblur而不是onchange或者onpropertychange，以减少客户端和服务器的交互次数，但应该注意如果这个文本框最初没有获得焦点，那么onblur就不会触发，可以先调用以下onfocus，再调用onblur手动触发；<br />
11、JS中不存在trim()函数，自定义如下：<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #008080;">&nbsp;1</span>&nbsp;<span style="color: #008000;">//</span><span style="color: #008000;">JS去除首尾空格（同VBS的Trim)</span><span style="color: #008000;"><br />
</span><span style="color: #008080;">&nbsp;2</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">function</span><span style="color: #000000;">&nbsp;trim(inputString)&nbsp;{&nbsp;&nbsp;&nbsp;<br />
</span><span style="color: #008080;">&nbsp;3</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(</span><span style="color: #0000ff;">typeof</span><span style="color: #000000;">&nbsp;inputString&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">string</span><span style="color: #000000;">"</span><span style="color: #000000;">)&nbsp;{<br />
</span><span style="color: #008080;">&nbsp;4</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;inputString;&nbsp;<br />
</span><span style="color: #008080;">&nbsp;5</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080;">&nbsp;6</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">var</span><span style="color: #000000;">&nbsp;retValue&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;inputString;<br />
</span><span style="color: #008080;">&nbsp;7</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">var</span><span style="color: #000000;">&nbsp;ch&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;retValue.substring(</span><span style="color: #000000;">0</span><span style="color: #000000;">,&nbsp;</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br />
</span><span style="color: #008080;">&nbsp;8</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">&nbsp;(ch&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">)&nbsp;{<br />
</span><span style="color: #008080;">&nbsp;9</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">检查字符串开始部分的空格</span><span style="color: #008000;"><br />
</span><span style="color: #008080;">10</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;retValue&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;retValue.substring(</span><span style="color: #000000;">1</span><span style="color: #000000;">,&nbsp;retValue.length);<br />
</span><span style="color: #008080;">11</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ch&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;retValue.substring(</span><span style="color: #000000;">0</span><span style="color: #000000;">,&nbsp;</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br />
</span><span style="color: #008080;">12</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080;">13</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ch&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;retValue.substring(retValue.length</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">,&nbsp;retValue.length);<br />
</span><span style="color: #008080;">14</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">&nbsp;(ch&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">)&nbsp;{<br />
</span><span style="color: #008080;">15</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">检查字符串结束部分的空格</span><span style="color: #008000;"><br />
</span><span style="color: #008080;">16</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;retValue&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;retValue.substring(</span><span style="color: #000000;">0</span><span style="color: #000000;">,&nbsp;retValue.length</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">);<br />
</span><span style="color: #008080;">17</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ch&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;retValue.substring(retValue.length</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">,&nbsp;retValue.length);<br />
</span><span style="color: #008080;">18</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080;">19</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">while</span><span style="color: #000000;">&nbsp;(retValue.indexOf(</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">)&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">1</span><span style="color: #000000;">)&nbsp;{<br />
</span><span style="color: #008080;">20</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">将文字中间多个相连的空格变为一个空格</span><span style="color: #008000;"><br />
</span><span style="color: #008080;">21</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;retValue&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;retValue.substring(</span><span style="color: #000000;">0</span><span style="color: #000000;">,&nbsp;retValue.indexOf(</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">))&nbsp;<br />
</span><span style="color: #008080;">22</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">+</span><span style="color: #000000;">&nbsp;retValue.substring(retValue.indexOf(</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">)</span><span style="color: #000000;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">,&nbsp;retValue.length);<br />
</span><span style="color: #008080;">23</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
</span><span style="color: #008080;">24</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;retValue;<br />
</span><span style="color: #008080;">25</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;}</span></div>
12、JS中显示模式窗口，代码如下：<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #008080;">&nbsp;1</span>&nbsp;<span style="color: #0000ff;">function</span><span style="color: #000000;">&nbsp;showMyDialog(){<br />
</span><span style="color: #008080;">&nbsp;2</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #0000ff;">var</span><span style="color: #000000;">&nbsp;dialogProperty&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;'dialogWidth:800px;dialogHeight:600px;status:no';<br />
</span><span style="color: #008080;">&nbsp;3</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #0000ff;">var</span><span style="color: #000000;">&nbsp;windowProperty&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">height=800,width=800,status=no,toolbar=no,menubar=yes,location=yes,resizable=yes,scrollbars=yes</span><span style="color: #000000;">"</span><span style="color: #000000;">;<br />
</span><span style="color: #008080;">&nbsp;4</span>&nbsp;<span style="color: #000000;"><br />
</span><span style="color: #008080;">&nbsp;5</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #0000ff;">var</span><span style="color: #000000;">&nbsp;url&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">SomeAction.do?id=</span><span style="color: #000000;">"</span><span style="color: #000000;">+</span><span style="color: #000000;">id</span><span style="color: #000000;">+</span><span style="color: #000000;">"</span><span style="color: #000000;">&amp;flag=true</span><span style="color: #000000;">"</span><span style="color: #000000;">;<br />
</span><span style="color: #008080;">&nbsp;6</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #0000ff;">var</span><span style="color: #000000;">&nbsp;returnVal&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;window.showModalDialog(url,</span><span style="color: #000000;">""</span><span style="color: #000000;">,&nbsp;dialogProperty);<br />
</span><span style="color: #008080;">&nbsp;7</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(</span><span style="color: #0000ff;">typeof</span><span style="color: #000000;">(returnVal)&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">undefined</span><span style="color: #000000;">"</span><span style="color: #000000;">){<br />
</span><span style="color: #008080;">&nbsp;8</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">;<br />
</span><span style="color: #008080;">&nbsp;9</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;}<br />
</span><span style="color: #008080;">10</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">(returnVal&nbsp;</span><span style="color: #000000;">!=</span><span style="color: #000000;">&nbsp;&nbsp;</span><span style="color: #000000;">""</span><span style="color: #000000;">){<br />
</span><span style="color: #008080;">11</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;">//</span><span style="color: #008000;">do&nbsp;something&nbsp;&nbsp;&nbsp;</span><span style="color: #008000;"><br />
</span><span style="color: #008080;">12</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;}<br />
</span><span style="color: #008080;">13</span>&nbsp;<span style="color: #000000;">}<br />
</span><span style="color: #008080;">14</span>&nbsp;</div>
在新打开的模式窗口中，我们通过<span style="color: red;">window.returnValue</span>设置返回值，然后在父页面中我们通过returnVal可以拿到返回值。<br />
<img src ="http://www.blogjava.net/kawaii/aggbug/163576.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kawaii/" target="_blank">lixw</a> 2007-11-27 23:41 <a href="http://www.blogjava.net/kawaii/archive/2007/11/27/163576.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DB2常用命令</title><link>http://www.blogjava.net/kawaii/archive/2007/04/27/113978.html</link><dc:creator>lixw</dc:creator><author>lixw</author><pubDate>Fri, 27 Apr 2007 00:54:00 GMT</pubDate><guid>http://www.blogjava.net/kawaii/archive/2007/04/27/113978.html</guid><wfw:comment>http://www.blogjava.net/kawaii/comments/113978.html</wfw:comment><comments>http://www.blogjava.net/kawaii/archive/2007/04/27/113978.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kawaii/comments/commentRss/113978.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kawaii/services/trackbacks/113978.html</trackback:ping><description><![CDATA[&nbsp; 1． 启动数据库&nbsp; &nbsp;<br>&nbsp; db2start&nbsp; &nbsp;<br>&nbsp; 2． 停止数据库&nbsp; &nbsp;<br>&nbsp; db2stop&nbsp; &nbsp;<br>&nbsp; 3． 连接数据库&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; connect&nbsp;&nbsp; to&nbsp;&nbsp; o_yd&nbsp;&nbsp; user&nbsp;&nbsp; db2&nbsp;&nbsp; using&nbsp;&nbsp; pwd&nbsp; &nbsp;<br>&nbsp; 4． 读数据库管理程序配置&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; get&nbsp;&nbsp; dbm&nbsp;&nbsp; cfg&nbsp; &nbsp;<br>&nbsp; 5． 写数据库管理程序配置&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; update&nbsp;&nbsp; dbm&nbsp;&nbsp; cfg&nbsp;&nbsp; using&nbsp;&nbsp; 参数名&nbsp;&nbsp; 参数值&nbsp; &nbsp;<br>&nbsp; 6． 读数据库的配置&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; connect&nbsp;&nbsp; to&nbsp;&nbsp; o_yd&nbsp;&nbsp; user&nbsp;&nbsp; db2&nbsp;&nbsp; using&nbsp;&nbsp; pwd&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; get&nbsp;&nbsp; db&nbsp;&nbsp; cfg&nbsp;&nbsp; for&nbsp;&nbsp; o_yd&nbsp; &nbsp;<br>&nbsp; 7． 写数据库的配置&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; connect&nbsp;&nbsp; to&nbsp;&nbsp; o_yd&nbsp;&nbsp; user&nbsp;&nbsp; db2&nbsp;&nbsp; using&nbsp;&nbsp; pwd&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; update&nbsp;&nbsp; db&nbsp;&nbsp; cfg&nbsp;&nbsp; for&nbsp;&nbsp; o_yd&nbsp;&nbsp; using&nbsp;&nbsp; 参数名&nbsp;&nbsp; 参数值&nbsp; &nbsp;<br>&nbsp; 8． 关闭所有应用连接&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; force&nbsp;&nbsp; application&nbsp;&nbsp; all&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; force&nbsp;&nbsp; application&nbsp;&nbsp; ID1,ID2,,,Idn&nbsp;&nbsp; MODE&nbsp;&nbsp; ASYNC&nbsp; &nbsp;<br>&nbsp; (db2&nbsp;&nbsp; list&nbsp;&nbsp; application&nbsp;&nbsp; for&nbsp;&nbsp; db&nbsp;&nbsp; o_yd&nbsp;&nbsp; show&nbsp;&nbsp; detail)&nbsp; &nbsp;<br>&nbsp; 9． 备份数据库&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; force&nbsp;&nbsp; application&nbsp;&nbsp; all&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; backup&nbsp;&nbsp; db&nbsp;&nbsp; o_yd&nbsp;&nbsp; to&nbsp;&nbsp; d:&nbsp; &nbsp;<br>&nbsp; (db2&nbsp;&nbsp; initialize&nbsp;&nbsp; tape&nbsp;&nbsp; on&nbsp;&nbsp; \\.\tape0)&nbsp; &nbsp;<br>&nbsp; (db2&nbsp;&nbsp; rewind&nbsp;&nbsp; tape&nbsp;&nbsp; on&nbsp;&nbsp; \\.\tape0)&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; backup&nbsp;&nbsp; db&nbsp;&nbsp; o_yd&nbsp;&nbsp; to&nbsp;&nbsp; \\.\tape0&nbsp; &nbsp;<br>&nbsp; 10． 恢复数据库&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; restore&nbsp;&nbsp; db&nbsp;&nbsp; o_yd&nbsp;&nbsp; from&nbsp;&nbsp; d:&nbsp;&nbsp; to&nbsp;&nbsp; d:&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; restore&nbsp;&nbsp; db&nbsp;&nbsp; o_yd&nbsp;&nbsp; from&nbsp;&nbsp; \\.\tape0&nbsp;&nbsp; to&nbsp;&nbsp; d:&nbsp; &nbsp;<br>&nbsp; 11． 绑定存储过程&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; connect&nbsp;&nbsp; to&nbsp;&nbsp; o_yd&nbsp;&nbsp; user&nbsp;&nbsp; db2&nbsp;&nbsp; using&nbsp;&nbsp; pwd&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; bind&nbsp;&nbsp; c:\dfplus.bnd&nbsp; &nbsp;<br>&nbsp; 拷贝存储过程到服务器上的C:\sqllib\function目录中&nbsp; &nbsp;<br>&nbsp; 12． 整理表&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; connect&nbsp;&nbsp; to&nbsp;&nbsp; o_yd&nbsp;&nbsp; user&nbsp;&nbsp; db2&nbsp;&nbsp; using&nbsp;&nbsp; pwd&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; reorg&nbsp;&nbsp; table&nbsp;&nbsp; ydd&nbsp; &nbsp;<br>&nbsp; db2&nbsp;&nbsp; runstats&nbsp;&nbsp; on&nbsp;&nbsp; table&nbsp;&nbsp; ydd&nbsp;&nbsp; with&nbsp;&nbsp; distribution&nbsp;&nbsp; and&nbsp;&nbsp; indexes&nbsp;&nbsp; all&nbsp;&nbsp; &nbsp;&nbsp;  <br>&nbsp; 13． 导出表数据&nbsp;&nbsp; <br>&nbsp; db2&nbsp;&nbsp; export&nbsp;&nbsp; to&nbsp;&nbsp; c:\sw.txt&nbsp;&nbsp; of&nbsp;&nbsp; del&nbsp;&nbsp; select&nbsp;&nbsp; *&nbsp;&nbsp; from&nbsp;&nbsp; dftz&nbsp;&nbsp; <br>&nbsp; db2&nbsp;&nbsp; export&nbsp;&nbsp; to&nbsp;&nbsp; c:\sw.ixf&nbsp;&nbsp; of&nbsp;&nbsp; ixf&nbsp;&nbsp; select&nbsp;&nbsp; *&nbsp;&nbsp; from&nbsp;&nbsp; dftz&nbsp;&nbsp; <br>&nbsp; 14． 导入表数据&nbsp;&nbsp; <br>&nbsp; db2&nbsp;&nbsp; import&nbsp;&nbsp; from&nbsp;&nbsp; c:\sw.txt&nbsp;&nbsp; of&nbsp;&nbsp; del&nbsp;&nbsp; insert&nbsp;&nbsp; into&nbsp;&nbsp; ylbx.czyxx&nbsp;&nbsp; <br>&nbsp; db2&nbsp;&nbsp; import&nbsp;&nbsp; to&nbsp;&nbsp; c:\sw.txt&nbsp;&nbsp; of&nbsp;&nbsp; del&nbsp;&nbsp; commitcount&nbsp;&nbsp; 5000&nbsp;&nbsp; messages&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c:\dftz.msg&nbsp;&nbsp; insert&nbsp;&nbsp; into&nbsp;&nbsp; dftz&nbsp;&nbsp; <br>&nbsp; db2&nbsp;&nbsp; import&nbsp;&nbsp; to&nbsp;&nbsp; c:\dftz.ixf&nbsp;&nbsp; of&nbsp;&nbsp; ixf&nbsp;&nbsp; commitcount&nbsp;&nbsp; 5000&nbsp;&nbsp; messages&nbsp;&nbsp; c:\dftz.msg&nbsp;&nbsp; insert&nbsp;&nbsp; into&nbsp;&nbsp; dftz&nbsp;&nbsp; <br>&nbsp; db2&nbsp;&nbsp; import&nbsp;&nbsp; to&nbsp;&nbsp; c:\dftz.ixf&nbsp;&nbsp; of&nbsp;&nbsp; ixf&nbsp;&nbsp; commitcount&nbsp;&nbsp; 5000&nbsp;&nbsp; insert&nbsp;&nbsp; into&nbsp;&nbsp; dftz&nbsp;&nbsp; <br>&nbsp; db2&nbsp;&nbsp; import&nbsp;&nbsp; to&nbsp;&nbsp; c:\dftz.ixf&nbsp;&nbsp; of&nbsp;&nbsp; ixf&nbsp;&nbsp; commitcount&nbsp;&nbsp; 5000&nbsp;&nbsp; insert_update&nbsp;&nbsp; into&nbsp;&nbsp; dftz&nbsp;&nbsp; <br>&nbsp; db2&nbsp;&nbsp; import&nbsp;&nbsp; to&nbsp;&nbsp; c:\dftz.ixf&nbsp;&nbsp; of&nbsp;&nbsp; ixf&nbsp;&nbsp; commitcount&nbsp;&nbsp; 5000&nbsp;&nbsp; replace&nbsp;&nbsp; into&nbsp;&nbsp; dftz&nbsp;&nbsp; <br>&nbsp; db2&nbsp;&nbsp; import&nbsp;&nbsp; to&nbsp;&nbsp; c:\dftz.ixf&nbsp;&nbsp; of&nbsp;&nbsp; ixf&nbsp;&nbsp; commitcount&nbsp;&nbsp; 5000&nbsp;&nbsp; create&nbsp;&nbsp; into&nbsp;&nbsp; dftz&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (仅IXF)&nbsp;&nbsp; <br>&nbsp; db2&nbsp;&nbsp; import&nbsp;&nbsp; to&nbsp;&nbsp; c:\dftz.ixf&nbsp;&nbsp; of&nbsp;&nbsp; ixf&nbsp;&nbsp; commitcount&nbsp;&nbsp; 5000&nbsp;&nbsp; replace_create&nbsp;&nbsp; into&nbsp;&nbsp; dftz&nbsp;&nbsp;&nbsp;&nbsp; (仅IXF)&nbsp;&nbsp; <br>&nbsp; 15． 执行一个批处理文件&nbsp;&nbsp; <br>&nbsp; db2&nbsp;&nbsp; &#8211;tf&nbsp;&nbsp; 批处理文件名&nbsp;&nbsp; <br>&nbsp; （文件中每一条命令用&nbsp;&nbsp; ；结束）&nbsp;&nbsp; <br>&nbsp; 16． 自动生成批处理文件&nbsp;&nbsp; <br>&nbsp; 建文本文件：temp.sql&nbsp;&nbsp; <br>&nbsp; select&nbsp;&nbsp; 'runstats&nbsp;&nbsp; on&nbsp;&nbsp; table&nbsp;&nbsp; DB2.'&nbsp;&nbsp; ||&nbsp;&nbsp; tabname&nbsp;&nbsp; ||&nbsp;&nbsp; '&nbsp;&nbsp; with&nbsp;&nbsp; distribution&nbsp;&nbsp; and&nbsp;&nbsp; detailed&nbsp;&nbsp; indexes&nbsp;&nbsp; all;'&nbsp;&nbsp; from&nbsp;&nbsp; syscat.tables&nbsp;&nbsp; where&nbsp;&nbsp; tabschema='DB2'&nbsp;&nbsp; and&nbsp;&nbsp; type='T';  <br>&nbsp; db2&nbsp;&nbsp; &#8211;tf&nbsp;&nbsp; temp.sql&gt;runstats.sql&nbsp;&nbsp; <br>&nbsp; 17． 自动生成建表（视图）语句&nbsp;&nbsp; <br>&nbsp; 在服务器上：C:\sqllib\misc目录中&nbsp;&nbsp; <br>&nbsp; db2&nbsp;&nbsp; connect&nbsp;&nbsp; to&nbsp;&nbsp; o_yd&nbsp;&nbsp; user&nbsp;&nbsp; db2&nbsp;&nbsp; using&nbsp;&nbsp; pwd&nbsp;&nbsp; <br>&nbsp; db2look&nbsp;&nbsp; &#8211;d&nbsp;&nbsp; o_yd&nbsp;&nbsp; &#8211;u&nbsp;&nbsp; db2&nbsp;&nbsp; &#8211;e&nbsp;&nbsp; &#8211;p&nbsp;&nbsp; &#8211;c&nbsp;&nbsp; c:\o_yd.txt&nbsp;&nbsp; &nbsp;&nbsp;  <br>&nbsp; db2look&nbsp;&nbsp; -d&nbsp;&nbsp; lys&nbsp;&nbsp; -e&nbsp;&nbsp; -a&nbsp;&nbsp; -x&nbsp;&nbsp; -i&nbsp;&nbsp; db2admin&nbsp;&nbsp; -o&nbsp;&nbsp; c:\aa.txt&nbsp;&nbsp; <br>&nbsp; 18． 其他命令&nbsp;&nbsp; <br>&nbsp; grant&nbsp;&nbsp; dbadm&nbsp;&nbsp; on&nbsp;&nbsp; database&nbsp;&nbsp; to&nbsp;&nbsp; user&nbsp;&nbsp; bb  &nbsp;&nbsp;  <br>&nbsp; 19.&nbsp;&nbsp;&nbsp; select&nbsp;&nbsp; *&nbsp;&nbsp; from&nbsp;&nbsp; czyxx&nbsp;&nbsp; fetch&nbsp;&nbsp; first&nbsp;&nbsp; 1&nbsp;&nbsp; rows&nbsp;&nbsp; only&nbsp;&nbsp; <br>&nbsp; 20.&nbsp;&nbsp;&nbsp; db2look&nbsp;&nbsp; &#8211;d&nbsp;&nbsp; lys&nbsp;&nbsp; &#8211;u&nbsp;&nbsp; db2admin&nbsp;&nbsp; &#8211;w&nbsp;&nbsp; &#8211;asd&nbsp;&nbsp; &#8211;a&nbsp;&nbsp; &#8211;e&nbsp;&nbsp; &#8211;o&nbsp;&nbsp; c:\mytable.txt&nbsp;&nbsp;&nbsp; <br><br> <img src ="http://www.blogjava.net/kawaii/aggbug/113978.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kawaii/" target="_blank">lixw</a> 2007-04-27 08:54 <a href="http://www.blogjava.net/kawaii/archive/2007/04/27/113978.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>log4j简介</title><link>http://www.blogjava.net/kawaii/archive/2007/04/25/113581.html</link><dc:creator>lixw</dc:creator><author>lixw</author><pubDate>Wed, 25 Apr 2007 09:34:00 GMT</pubDate><guid>http://www.blogjava.net/kawaii/archive/2007/04/25/113581.html</guid><wfw:comment>http://www.blogjava.net/kawaii/comments/113581.html</wfw:comment><comments>http://www.blogjava.net/kawaii/archive/2007/04/25/113581.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kawaii/comments/commentRss/113581.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kawaii/services/trackbacks/113581.html</trackback:ping><description><![CDATA[1.在应用程序中使用日志的三个目的：<br>应用程序中添加日志的三个目的：监视代码中变量的变化情况，周期性的记录到文件中供其他应用进行统计分析工作；<br>跟踪代码运行时轨迹，作为日后审计的依据；<br>担当集成开发环境中的调试器的作用，向文件或控制台打印代码的调试信息。<br><br>2.log4j由三个重要的组件构成：日志信息的优先级，日志信息的输出目的地，日志信息的输出格式。<br>使用Java特性文件做为配置文件的方法：<br>2.1. 配置根Logger，其语法为：<br>log4j.rootLogger = [ level ] , appenderName, appenderName, ...<br>其中，level 是日志记录的优先级，分为OFF、FATAL、ERROR、WARN、INFO、DEBUG、ALL或者您定义的级别。<br>Log4j建议只使用四个级别，优先级从高到低分别是ERROR、WARN、INFO、DEBUG。<br>通过在这里定义的级别，您可以控制到应用程序中相应级别的日志信息的开关。<br>比如在这里定义了INFO级别，则应用程序中所有DEBUG级别的日志信息将不被打印出来。<br>appenderName就是指定日志信息输出到哪个地方。您可以同时指定多个输出目的地。<br>2.2. 配置日志信息输出目的地Appender，其语法为<br>log4j.appender.appenderName = fully.qualified.name.of.appender.class<br>log4j.appender.appenderName.option1 = value1<br>...<br>log4j.appender.appenderName.option = valueN<br><br>其中，Log4j提供的appender有以下几种：<br>org.apache.log4j.ConsoleAppender（控制台），<br>org.apache.log4j.FileAppender（文件），<br>org.apache.log4j.DailyRollingFileAppender（每天产生一个日志文件），<br>org.apache.log4j.RollingFileAppender（文件大小到达指定尺寸的时候产生一个新的文件），<br>org.apache.log4j.WriterAppender（将日志信息以流格式发送到任意指定的地方）<br><br>2.3. 配置日志信息的格式（布局），其语法为：<br>log4j.appender.appenderName.layout = fully.qualified.name.of.layout.class<br>log4j.appender.appenderName.layout.option1 = value1<br>...<br>log4j.appender.appenderName.layout.option = valueN<br><br>其中，Log4j提供的layout有以下几种：<br>org.apache.log4j.HTMLLayout（以HTML表格形式布局），<br>org.apache.log4j.PatternLayout（可以灵活地指定布局模式），<br>org.apache.log4j.SimpleLayout（包含日志信息的级别和信息字符串），<br>org.apache.log4j.TTCCLayout（包含日志产生的时间、线程、类别等等信息）<br><br>3.在代码中使用Log4j,下面将讲述在程序代码中怎样使用Log4j。<br><br>3.1.得到记录器<br>使用Log4j，第一步就是获取日志记录器，这个记录器将负责控制日志信息。其语法为：<br>public static Logger getLogger( String name)，<br>通过指定的名字获得记录器，如果必要的话，则为这个名字创建一个新的记录器。Name一般取本类的名字，比如：<br>static Logger logger = Logger.getLogger ( ServerWithLog4j.class.getName () ) ;<br><br>3.2.读取配置文件<br>当获得了日志记录器之后，第二步将配置Log4j环境，其语法为：<br>BasicConfigurator.configure ()： 自动快速地使用缺省Log4j环境。<br>PropertyConfigurator.configure ( String configFilename) ：读取使用Java的特性文件编写的配置文件。<br>DOMConfigurator.configure ( String filename ) ：读取XML形式的配置文件。<br><br>3.3.插入记录信息（格式化日志信息）<br>当上两个必要步骤执行完毕，您就可以轻松地使用不同优先级别的日志记录语句插入到您想记录日志的任何地方，其语法如下：<br>Logger.debug ( Object message ) ;<br>Logger.info ( Object message ) ;<br>Logger.warn ( Object message ) ;<br>Logger.error ( Object message ) ;
<br><br>一个配置的例子:<br>log4j.rootLogger=INFO, stdout ,R
<br>log4j.appender.stdout.Threshold=ERROR
<br>log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[QC] %p [%t] %C.%M(%L) | %m%n
log4j.appender.R.Threshold=INFO
<br>log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
<br>log4j.appender.R.File=c:/log.log
<br>log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d-[TS] %p %t %c - %m%n  <img src ="http://www.blogjava.net/kawaii/aggbug/113581.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kawaii/" target="_blank">lixw</a> 2007-04-25 17:34 <a href="http://www.blogjava.net/kawaii/archive/2007/04/25/113581.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>多线程监听文件改动</title><link>http://www.blogjava.net/kawaii/archive/2007/02/08/98668.html</link><dc:creator>lixw</dc:creator><author>lixw</author><pubDate>Thu, 08 Feb 2007 02:07:00 GMT</pubDate><guid>http://www.blogjava.net/kawaii/archive/2007/02/08/98668.html</guid><wfw:comment>http://www.blogjava.net/kawaii/comments/98668.html</wfw:comment><comments>http://www.blogjava.net/kawaii/archive/2007/02/08/98668.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/kawaii/comments/commentRss/98668.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kawaii/services/trackbacks/98668.html</trackback:ping><description><![CDATA[一种比较简陋的方法：<br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 0);">ActionListener taskPerformer </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ActionListener() {<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> actionPerformed(ActionEvent evt) {<br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);">                log.info(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">monitor is running at </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> java.util.Date());<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);">                String configfile </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (String)getServletContext().getAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">configfile</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(configfile </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);"> configfile.length()</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">){<br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">                    </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);">{<br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">                        File file </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> File(configfile);<br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">                        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(file.lastModified() </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> lastModifyTime){<br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">                            lastModifyTime </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> file.lastModified();<br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">                            loadProp();<br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">                        }<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">                    }</span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);">(Exception e){<br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);">                        log.error(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">construct file:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> configfile </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> exception</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);">                        e.printStackTrace();<br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">                    }<br /></span><span style="color: rgb(0, 128, 128);">16</span> <span style="color: rgb(0, 0, 0);">                }<br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 0, 0);">            }<br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 0, 0);"> };<br /></span><span style="color: rgb(0, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);">20</span>  <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">启动监听线程</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Timer(delay, taskPerformer).start();</span></div><br /><br />来自geosoft.no的解决方法：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.io.File;<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 128, 0);"> * Interface for listening to disk file changes.<br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 128, 0);"> * </span><span style="color: rgb(128, 128, 128);">@see</span><span style="color: rgb(0, 128, 0);"> FileMonitor<br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 128, 0);"> * <br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 128, 0);"> * </span><span style="color: rgb(128, 128, 128);">@author</span><span style="color: rgb(0, 128, 0);"> &lt;a href="mailto:jacob.dreyer@geosoft.no"&gt;Jacob Dreyer&lt;/a&gt;<br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 128, 0);"> </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);">   <br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">interface</span><span style="color: rgb(0, 0, 0);"> FileListener<br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">{<br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 128, 0);">   * Called when one of the monitored files are created, deleted<br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 128, 0);">   * or modified.<br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 128, 0);">   * <br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 128, 0);">   * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> file  File which has been changed.<br /></span><span style="color: rgb(0, 128, 128);">16</span> <span style="color: rgb(0, 128, 0);">   </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> fileChanged (File file);<br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 0, 0);">}</span></div><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);">  1</span> <span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);">  2</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.io.File;<br /></span><span style="color: rgb(0, 128, 128);">  3</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.lang.ref.WeakReference;<br /></span><span style="color: rgb(0, 128, 128);">  4</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">  5</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">  6</span> <span style="color: rgb(0, 128, 0);"> * Class for monitoring changes in disk files.<br /></span><span style="color: rgb(0, 128, 128);">  7</span> <span style="color: rgb(0, 128, 0);"> * Usage:<br /></span><span style="color: rgb(0, 128, 128);">  8</span> <span style="color: rgb(0, 128, 0);"> *<br /></span><span style="color: rgb(0, 128, 128);">  9</span> <span style="color: rgb(0, 128, 0);"> *    1. Implement the FileListener interface.<br /></span><span style="color: rgb(0, 128, 128);"> 10</span> <span style="color: rgb(0, 128, 0);"> *    2. Create a FileMonitor instance.<br /></span><span style="color: rgb(0, 128, 128);"> 11</span> <span style="color: rgb(0, 128, 0);"> *    3. Add the file(s)/directory(ies) to listen for.<br /></span><span style="color: rgb(0, 128, 128);"> 12</span> <span style="color: rgb(0, 128, 0);"> *<br /></span><span style="color: rgb(0, 128, 128);"> 13</span> <span style="color: rgb(0, 128, 0);"> * fileChanged() will be called when a monitored file is created,<br /></span><span style="color: rgb(0, 128, 128);"> 14</span> <span style="color: rgb(0, 128, 0);"> * deleted or its modified time changes.<br /></span><span style="color: rgb(0, 128, 128);"> 15</span> <span style="color: rgb(0, 128, 0);"> *<br /></span><span style="color: rgb(0, 128, 128);"> 16</span> <span style="color: rgb(0, 128, 0);"> * </span><span style="color: rgb(128, 128, 128);">@author</span><span style="color: rgb(0, 128, 0);"> &lt;a href="mailto:jacob.dreyer@geosoft.no"&gt;Jacob Dreyer&lt;/a&gt;<br /></span><span style="color: rgb(0, 128, 128);"> 17</span> <span style="color: rgb(0, 128, 0);"> </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);">   <br /></span><span style="color: rgb(0, 128, 128);"> 18</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> FileMonitor<br /></span><span style="color: rgb(0, 128, 128);"> 19</span> <span style="color: rgb(0, 0, 0);">{<br /></span><span style="color: rgb(0, 128, 128);"> 20</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> Timer       timer_;<br /></span><span style="color: rgb(0, 128, 128);"> 21</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> HashMap     files_;       </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> File -&gt; Long</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 22</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> Collection  listeners_;   </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> of WeakReference(FileListener)</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 23</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">   <br /></span><span style="color: rgb(0, 128, 128);"> 24</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 25</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 26</span> <span style="color: rgb(0, 128, 0);">   * Create a file monitor instance with specified polling interval.<br /></span><span style="color: rgb(0, 128, 128);"> 27</span> <span style="color: rgb(0, 128, 0);">   * <br /></span><span style="color: rgb(0, 128, 128);"> 28</span> <span style="color: rgb(0, 128, 0);">   * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> pollingInterval  Polling interval in milli seconds.<br /></span><span style="color: rgb(0, 128, 128);"> 29</span> <span style="color: rgb(0, 128, 0);">   </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 30</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> FileMonitor (</span><span style="color: rgb(0, 0, 255);">long</span><span style="color: rgb(0, 0, 0);"> pollingInterval)<br /></span><span style="color: rgb(0, 128, 128);"> 31</span> <span style="color: rgb(0, 0, 0);">  {<br /></span><span style="color: rgb(0, 128, 128);"> 32</span> <span style="color: rgb(0, 0, 0);">    files_     </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> HashMap();<br /></span><span style="color: rgb(0, 128, 128);"> 33</span> <span style="color: rgb(0, 0, 0);">    listeners_ </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ArrayList();<br /></span><span style="color: rgb(0, 128, 128);"> 34</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 35</span> <span style="color: rgb(0, 0, 0);">    timer_ </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Timer (</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);"> 36</span> <span style="color: rgb(0, 0, 0);">    timer_.schedule (</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileMonitorNotifier(), </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, pollingInterval);<br /></span><span style="color: rgb(0, 128, 128);"> 37</span> <span style="color: rgb(0, 0, 0);">  }<br /></span><span style="color: rgb(0, 128, 128);"> 38</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 39</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 40</span> <span style="color: rgb(0, 0, 0);">  <br /></span><span style="color: rgb(0, 128, 128);"> 41</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 42</span> <span style="color: rgb(0, 128, 0);">   * Stop the file monitor polling.<br /></span><span style="color: rgb(0, 128, 128);"> 43</span> <span style="color: rgb(0, 128, 0);">   </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 44</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> stop()<br /></span><span style="color: rgb(0, 128, 128);"> 45</span> <span style="color: rgb(0, 0, 0);">  {<br /></span><span style="color: rgb(0, 128, 128);"> 46</span> <span style="color: rgb(0, 0, 0);">    timer_.cancel();<br /></span><span style="color: rgb(0, 128, 128);"> 47</span> <span style="color: rgb(0, 0, 0);">  }<br /></span><span style="color: rgb(0, 128, 128);"> 48</span> <span style="color: rgb(0, 0, 0);">  <br /></span><span style="color: rgb(0, 128, 128);"> 49</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 50</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 51</span> <span style="color: rgb(0, 128, 0);">   * Add file to listen for. File may be any java.io.File (including a<br /></span><span style="color: rgb(0, 128, 128);"> 52</span> <span style="color: rgb(0, 128, 0);">   * directory) and may well be a non-existing file in the case where the<br /></span><span style="color: rgb(0, 128, 128);"> 53</span> <span style="color: rgb(0, 128, 0);">   * creating of the file is to be trepped.<br /></span><span style="color: rgb(0, 128, 128);"> 54</span> <span style="color: rgb(0, 128, 0);">   * &lt;p&gt;<br /></span><span style="color: rgb(0, 128, 128);"> 55</span> <span style="color: rgb(0, 128, 0);">   * More than one file can be listened for. When the specified file is<br /></span><span style="color: rgb(0, 128, 128);"> 56</span> <span style="color: rgb(0, 128, 0);">   * created, modified or deleted, listeners are notified.<br /></span><span style="color: rgb(0, 128, 128);"> 57</span> <span style="color: rgb(0, 128, 0);">   * <br /></span><span style="color: rgb(0, 128, 128);"> 58</span> <span style="color: rgb(0, 128, 0);">   * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> file  File to listen for.<br /></span><span style="color: rgb(0, 128, 128);"> 59</span> <span style="color: rgb(0, 128, 0);">   </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 60</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> addFile (File file)<br /></span><span style="color: rgb(0, 128, 128);"> 61</span> <span style="color: rgb(0, 0, 0);">  {<br /></span><span style="color: rgb(0, 128, 128);"> 62</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 0);">files_.containsKey (file)) {<br /></span><span style="color: rgb(0, 128, 128);"> 63</span> <span style="color: rgb(0, 0, 0);">      </span><span style="color: rgb(0, 0, 255);">long</span><span style="color: rgb(0, 0, 0);"> modifiedTime </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> file.exists() </span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);"> file.lastModified() : </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);"> 64</span> <span style="color: rgb(0, 0, 0);">      files_.put (file, </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Long (modifiedTime));<br /></span><span style="color: rgb(0, 128, 128);"> 65</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);"> 66</span> <span style="color: rgb(0, 0, 0);">  }<br /></span><span style="color: rgb(0, 128, 128);"> 67</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 68</span> <span style="color: rgb(0, 0, 0);">  <br /></span><span style="color: rgb(0, 128, 128);"> 69</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 70</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 71</span> <span style="color: rgb(0, 128, 0);">   * Remove specified file for listening.<br /></span><span style="color: rgb(0, 128, 128);"> 72</span> <span style="color: rgb(0, 128, 0);">   * <br /></span><span style="color: rgb(0, 128, 128);"> 73</span> <span style="color: rgb(0, 128, 0);">   * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> file  File to remove.<br /></span><span style="color: rgb(0, 128, 128);"> 74</span> <span style="color: rgb(0, 128, 0);">   </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 75</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> removeFile (File file)<br /></span><span style="color: rgb(0, 128, 128);"> 76</span> <span style="color: rgb(0, 0, 0);">  {<br /></span><span style="color: rgb(0, 128, 128);"> 77</span> <span style="color: rgb(0, 0, 0);">    files_.remove (file);<br /></span><span style="color: rgb(0, 128, 128);"> 78</span> <span style="color: rgb(0, 0, 0);">  }<br /></span><span style="color: rgb(0, 128, 128);"> 79</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 80</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 81</span> <span style="color: rgb(0, 0, 0);">  <br /></span><span style="color: rgb(0, 128, 128);"> 82</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 83</span> <span style="color: rgb(0, 128, 0);">   * Add listener to this file monitor.<br /></span><span style="color: rgb(0, 128, 128);"> 84</span> <span style="color: rgb(0, 128, 0);">   * <br /></span><span style="color: rgb(0, 128, 128);"> 85</span> <span style="color: rgb(0, 128, 0);">   * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> fileListener  Listener to add.<br /></span><span style="color: rgb(0, 128, 128);"> 86</span> <span style="color: rgb(0, 128, 0);">   </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 87</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> addListener (FileListener fileListener)<br /></span><span style="color: rgb(0, 128, 128);"> 88</span> <span style="color: rgb(0, 0, 0);">  {<br /></span><span style="color: rgb(0, 128, 128);"> 89</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Don't add if its already there</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 90</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (Iterator i </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> listeners_.iterator(); i.hasNext(); ) {<br /></span><span style="color: rgb(0, 128, 128);"> 91</span> <span style="color: rgb(0, 0, 0);">      WeakReference reference </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (WeakReference) i.next();<br /></span><span style="color: rgb(0, 128, 128);"> 92</span> <span style="color: rgb(0, 0, 0);">      FileListener listener </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (FileListener) reference.get();<br /></span><span style="color: rgb(0, 128, 128);"> 93</span> <span style="color: rgb(0, 0, 0);">      </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (listener </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> fileListener)<br /></span><span style="color: rgb(0, 128, 128);"> 94</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);"> 95</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);"> 96</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 97</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Use WeakReference to avoid memory leak if this becomes the<br /></span><span style="color: rgb(0, 128, 128);"> 98</span> <span style="color: rgb(0, 128, 0);">    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> sole reference to the object.</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 99</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">    listeners_.add (</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> WeakReference (fileListener));<br /></span><span style="color: rgb(0, 128, 128);">100</span> <span style="color: rgb(0, 0, 0);">  }<br /></span><span style="color: rgb(0, 128, 128);">101</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">102</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">103</span> <span style="color: rgb(0, 0, 0);">  <br /></span><span style="color: rgb(0, 128, 128);">104</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">105</span> <span style="color: rgb(0, 128, 0);">   * Remove listener from this file monitor.<br /></span><span style="color: rgb(0, 128, 128);">106</span> <span style="color: rgb(0, 128, 0);">   * <br /></span><span style="color: rgb(0, 128, 128);">107</span> <span style="color: rgb(0, 128, 0);">   * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> fileListener  Listener to remove.<br /></span><span style="color: rgb(0, 128, 128);">108</span> <span style="color: rgb(0, 128, 0);">   </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">109</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> removeListener (FileListener fileListener)<br /></span><span style="color: rgb(0, 128, 128);">110</span> <span style="color: rgb(0, 0, 0);">  {<br /></span><span style="color: rgb(0, 128, 128);">111</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (Iterator i </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> listeners_.iterator(); i.hasNext(); ) {<br /></span><span style="color: rgb(0, 128, 128);">112</span> <span style="color: rgb(0, 0, 0);">      WeakReference reference </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (WeakReference) i.next();<br /></span><span style="color: rgb(0, 128, 128);">113</span> <span style="color: rgb(0, 0, 0);">      FileListener listener </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (FileListener) reference.get();<br /></span><span style="color: rgb(0, 128, 128);">114</span> <span style="color: rgb(0, 0, 0);">      </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (listener </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> fileListener) {<br /></span><span style="color: rgb(0, 128, 128);">115</span> <span style="color: rgb(0, 0, 0);">        i.remove();<br /></span><span style="color: rgb(0, 128, 128);">116</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">break</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);">117</span> <span style="color: rgb(0, 0, 0);">      }<br /></span><span style="color: rgb(0, 128, 128);">118</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);">119</span> <span style="color: rgb(0, 0, 0);">  }<br /></span><span style="color: rgb(0, 128, 128);">120</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">121</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">122</span> <span style="color: rgb(0, 0, 0);">  <br /></span><span style="color: rgb(0, 128, 128);">123</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">124</span> <span style="color: rgb(0, 128, 0);">   * This is the timer thread which is executed every n milliseconds<br /></span><span style="color: rgb(0, 128, 128);">125</span> <span style="color: rgb(0, 128, 0);">   * according to the setting of the file monitor. It investigates the<br /></span><span style="color: rgb(0, 128, 128);">126</span> <span style="color: rgb(0, 128, 0);">   * file in question and notify listeners if changed.<br /></span><span style="color: rgb(0, 128, 128);">127</span> <span style="color: rgb(0, 128, 0);">   </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">128</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> FileMonitorNotifier </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> TimerTask<br /></span><span style="color: rgb(0, 128, 128);">129</span> <span style="color: rgb(0, 0, 0);">  {<br /></span><span style="color: rgb(0, 128, 128);">130</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> run()<br /></span><span style="color: rgb(0, 128, 128);">131</span> <span style="color: rgb(0, 0, 0);">    {<br /></span><span style="color: rgb(0, 128, 128);">132</span> <span style="color: rgb(0, 0, 0);">      </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Loop over the registered files and see which have changed.<br /></span><span style="color: rgb(0, 128, 128);">133</span> <span style="color: rgb(0, 128, 0);">      </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Use a copy of the list in case listener wants to alter the<br /></span><span style="color: rgb(0, 128, 128);">134</span> <span style="color: rgb(0, 128, 0);">      </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> list within its fileChanged method.</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">135</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">      Collection files </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ArrayList (files_.keySet());<br /></span><span style="color: rgb(0, 128, 128);">136</span> <span style="color: rgb(0, 0, 0);">      <br /></span><span style="color: rgb(0, 128, 128);">137</span> <span style="color: rgb(0, 0, 0);">      </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (Iterator i </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> files.iterator(); i.hasNext(); ) {<br /></span><span style="color: rgb(0, 128, 128);">138</span> <span style="color: rgb(0, 0, 0);">        File file </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (File) i.next();<br /></span><span style="color: rgb(0, 128, 128);">139</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">long</span><span style="color: rgb(0, 0, 0);"> lastModifiedTime </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ((Long) files_.get (file)).longValue();<br /></span><span style="color: rgb(0, 128, 128);">140</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">long</span><span style="color: rgb(0, 0, 0);"> newModifiedTime  </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> file.exists() </span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);"> file.lastModified() : </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);">141</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">142</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Chek if file has changed</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">143</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (newModifiedTime </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> lastModifiedTime) {<br /></span><span style="color: rgb(0, 128, 128);">144</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">145</span> <span style="color: rgb(0, 0, 0);">          </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Register new modified time</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">146</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">          files_.put (file, </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Long (newModifiedTime));<br /></span><span style="color: rgb(0, 128, 128);">147</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">148</span> <span style="color: rgb(0, 0, 0);">          </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Notify listeners</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">149</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">          </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (Iterator j </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> listeners_.iterator(); j.hasNext(); ) {<br /></span><span style="color: rgb(0, 128, 128);">150</span> <span style="color: rgb(0, 0, 0);">            WeakReference reference </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (WeakReference) j.next();<br /></span><span style="color: rgb(0, 128, 128);">151</span> <span style="color: rgb(0, 0, 0);">            FileListener listener </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (FileListener) reference.get();<br /></span><span style="color: rgb(0, 128, 128);">152</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">153</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Remove from list if the back-end object has been GC'd</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">154</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (listener </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)<br /></span><span style="color: rgb(0, 128, 128);">155</span> <span style="color: rgb(0, 0, 0);">              j.remove();<br /></span><span style="color: rgb(0, 128, 128);">156</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">157</span> <span style="color: rgb(0, 0, 0);">              listener.fileChanged (file);<br /></span><span style="color: rgb(0, 128, 128);">158</span> <span style="color: rgb(0, 0, 0);">          }<br /></span><span style="color: rgb(0, 128, 128);">159</span> <span style="color: rgb(0, 0, 0);">        }<br /></span><span style="color: rgb(0, 128, 128);">160</span> <span style="color: rgb(0, 0, 0);">      }<br /></span><span style="color: rgb(0, 128, 128);">161</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);">162</span> <span style="color: rgb(0, 0, 0);">  }<br /></span><span style="color: rgb(0, 128, 128);">163</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">164</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">165</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">166</span> <span style="color: rgb(0, 128, 0);">   * Test this class.<br /></span><span style="color: rgb(0, 128, 128);">167</span> <span style="color: rgb(0, 128, 0);">   * <br /></span><span style="color: rgb(0, 128, 128);">168</span> <span style="color: rgb(0, 128, 0);">   * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> args  Not used.<br /></span><span style="color: rgb(0, 128, 128);">169</span> <span style="color: rgb(0, 128, 0);">   </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">170</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main (String args[])<br /></span><span style="color: rgb(0, 128, 128);">171</span> <span style="color: rgb(0, 0, 0);">  {<br /></span><span style="color: rgb(0, 128, 128);">172</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Create the monitor</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">173</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">    FileMonitor monitor </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileMonitor (</span><span style="color: rgb(0, 0, 0);">1000</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">174</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">175</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Add some files to listen for</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">176</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">    monitor.addFile (</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> File (</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">D:\\myjava\\JCreatorWorkspace\\FileMonitor\\test.txt</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br /></span><span style="color: rgb(0, 128, 128);">177</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">178</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Add a dummy listener</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">179</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">    monitor.addListener (monitor.</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> TestListener());<br /></span><span style="color: rgb(0, 128, 128);">180</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">181</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Avoid program exit</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">182</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">) ;<br /></span><span style="color: rgb(0, 128, 128);">183</span> <span style="color: rgb(0, 0, 0);">  }<br /></span><span style="color: rgb(0, 128, 128);">184</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">185</span> <span style="color: rgb(0, 0, 0);">  <br /></span><span style="color: rgb(0, 128, 128);">186</span> <span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> TestListener<br /></span><span style="color: rgb(0, 128, 128);">187</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);"> FileListener<br /></span><span style="color: rgb(0, 128, 128);">188</span> <span style="color: rgb(0, 0, 0);">  {<br /></span><span style="color: rgb(0, 128, 128);">189</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> fileChanged (File file)<br /></span><span style="color: rgb(0, 128, 128);">190</span> <span style="color: rgb(0, 0, 0);">    {<br /></span><span style="color: rgb(0, 128, 128);">191</span> <span style="color: rgb(0, 0, 0);">      System.out.println (</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">File [</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> file.getName() </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">] changed At:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> java.util.Date());<br /></span><span style="color: rgb(0, 128, 128);">192</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);">193</span> <span style="color: rgb(0, 0, 0);">  }<br /></span><span style="color: rgb(0, 128, 128);">194</span> <span style="color: rgb(0, 0, 0);">}<br /></span><span style="color: rgb(0, 128, 128);">195</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">196</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">197</span> <span style="color: rgb(0, 0, 0);"></span></div><br /><img src ="http://www.blogjava.net/kawaii/aggbug/98668.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kawaii/" target="_blank">lixw</a> 2007-02-08 10:07 <a href="http://www.blogjava.net/kawaii/archive/2007/02/08/98668.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>根据不同Locale值读取不同的Properties配置文件</title><link>http://www.blogjava.net/kawaii/archive/2007/02/08/98652.html</link><dc:creator>lixw</dc:creator><author>lixw</author><pubDate>Thu, 08 Feb 2007 01:43:00 GMT</pubDate><guid>http://www.blogjava.net/kawaii/archive/2007/02/08/98652.html</guid><wfw:comment>http://www.blogjava.net/kawaii/comments/98652.html</wfw:comment><comments>http://www.blogjava.net/kawaii/archive/2007/02/08/98652.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kawaii/comments/commentRss/98652.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kawaii/services/trackbacks/98652.html</trackback:ping><description><![CDATA[
		<br />
		<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
				<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
				<span style="color: rgb(0, 128, 128);">1</span> <span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">file may be named basename_locale.properties</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">2</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">ResourceBundle bundle </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ResourceBundle.getBundle(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">basename</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">3</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Enumerate contents of resource bundle<br /></span><span style="color: rgb(0, 128, 128);">4</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">The next two lines should be in one line.</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">5</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (Enumeration props </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> bundle.getKeys();props.hasMoreElements(); ) {<br /></span><span style="color: rgb(0, 128, 128);">6</span> <span style="color: rgb(0, 0, 0);">    String key </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (String)props.nextElement();<br /></span><span style="color: rgb(0, 128, 128);">7</span> <span style="color: rgb(0, 0, 0);">    process(key, bundle.getObject(key));<br /></span><span style="color: rgb(0, 128, 128);">8</span> <span style="color: rgb(0, 0, 0);">}</span></div>
		<br />
<img src ="http://www.blogjava.net/kawaii/aggbug/98652.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kawaii/" target="_blank">lixw</a> 2007-02-08 09:43 <a href="http://www.blogjava.net/kawaii/archive/2007/02/08/98652.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>