<?xml version="1.0" encoding="UTF-8" ?>
<feed xml:lang="ja" xmlns="http://www.w3.org/2005/Atom">
	<generator uri="http://nucleuscms.org/" version="Nucleus CMS v3.31SP1-kes">Nucleus CMS v3.31SP1-kes</generator>

	<id>http://fireball.loafer.jp/kes/</id>
	<link rel="self" type="application/atom+xml" href="http://fireball.loafer.jp/kes/atom.xml" />
	<link rel="related" type="text/html" href="http://fireball.loafer.jp/" />
	<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/" />

	<rights>© 2008 Project Loafer/Project Fireball and all blog writers.</rights>

	<title>Entering Passive Mode</title>
	<subtitle>やる気のない受け身なブログ。実験場。</subtitle>

	<updated>2008-06-12T21:19:33+09:00</updated>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Java" scheme="http://fireball.loafer.jp/kes/java/" />
		<content type="html">
<![CDATA[
<p>
今日はネタをひとつ。以下のプログラムを実行すると、<br />
標準出力には何が出力されるだろうか。
</p>
<pre class="prettyprint">
public class Test {
　　static public void main(String[] args) {
　　　　System.out.println((long)(80000 * 90000));
　　}
}
</pre>
<p>
これを即答できた人は、今日の日記に用はない。
</p>
<a href="http://fireball.loafer.jp/kes/java/java-overflow.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/java/java-overflow.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/java/java-overflow.html" />
		<published>2008-06-12T21:19:33+09:00</published>
		<title type="html"><![CDATA[Java とオーバーフロー]]></title>
		<updated>2008-06-12T21:19:33+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Java" scheme="http://fireball.loafer.jp/kes/java/" />
		<content type="html">
<![CDATA[
<div>
<a href="http://fireball.loafer.jp/kes?imagepopup=2/2007-05-21-23-54-0.jpg&amp;width=522&amp;height=533&amp;imagetext=%E3%82%A8%E3%83%A9%E3%83%BC%E3%83%A1%E3%83%83%E3%82%BB%E3%83%BC%E3%82%B8" onclick="window.open(this.href,'imagepopup','status=no,toolbar=no,scrollbars=no,resizable=yes,width=522,height=533');return false;" class="thumbnail"><img src="http://media.fireball.loafer.jp/thumbnail/2_2007-05-21-23-54-0.jpg" width="118" height="120" alt="エラーメッセージ" title="エラーメッセージ" /></a>
</div>
<p>
続いて、作ったルールを Validator 設定に追加する。<br />
別にファイルを用意してもよかったのだが、<br />
とりあえず /WEB-INF/validation.xml に追記しよう。
</p>
<p>
========== /WEB-INF/validation.xml ==========<br />
（…省略…）<br />
&lt;form-validation&gt;
</p>
<p>
&nbsp; &nbsp; &lt;global&gt;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;validator name=&quot;filterNetwork&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; classname=&quot;jp.loafer.test.validators.FilterNetworkValidator&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; method=&quot;execute&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; methodParams=&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; java.lang.Object,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; org.apache.commons.validator.Field,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; org.apache.struts.action.ActionMessages<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msg=&quot;errors.invalid&quot;&nbsp; /&gt;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &lt;/global&gt;
</p>
<a href="http://fireball.loafer.jp/kes/java/article_525.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/java/article_525.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/java/article_525.html" />
		<published>2007-05-21T23:54:00+09:00</published>
		<title type="html"><![CDATA[独自ルール #4: ルールの XML 定義]]></title>
		<updated>2007-05-21T23:54:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Java" scheme="http://fireball.loafer.jp/kes/java/" />
		<content type="html">
<![CDATA[
<p>
フィルタアドレスの検証ルールを実際に作っていこう。
</p>
<p>
検証コードの作成には柔軟性があるので、<br />
簡単にクラスを用意することができるが、<br />
Struts を介して利用するためには従うべきルールがある。
</p>
<p>
Struts では、エラーを ActionMessages で表現する。<br />
Commons Validator には ValidatorResults クラスがあるが、<br />
これは使わず ActionMessages に直接格納することになる。<br />
なので、ActionMessages を引数として受け取る必要がある。
</p>
<a href="http://fireball.loafer.jp/kes/java/article_524.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/java/article_524.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/java/article_524.html" />
		<published>2007-05-20T23:53:00+09:00</published>
		<title type="html"><![CDATA[独自ルール #3: ルールクラスの枠組み]]></title>
		<updated>2007-05-20T23:53:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Java" scheme="http://fireball.loafer.jp/kes/java/" />
		<content type="html">
<![CDATA[
<p>
Commons Validator は、引数の扱いに特徴がある。
</p>
<p>
Commons Validator はインタフェースの実装等を強制せず、<br />
引数や戻り値を、メソッド側が自由に決めることができる。<br />
そのため、既存の検証コードを簡単に利用しやすい。
</p>
<p>
でも、検証を実行するクラスは呼び出される側なので、<br />
その引数を用意するのは呼び出す側である。<br />
では、どのように引数が与えられるのだろうか。
</p>
<p>
自分のコードで Commons Validator を使う場合、<br />
検証コードを呼び出す方法を制御できるのだが、<br />
Struts では ValidatorForm が検証メソッドを呼び出すので、<br />
独自ルールの実装者は、引数を自由に制御できない。
</p>
<a href="http://fireball.loafer.jp/kes/java/article_523.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/java/article_523.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/java/article_523.html" />
		<published>2007-05-19T23:55:00+09:00</published>
		<title type="html"><![CDATA[独自ルール #2: 引数の扱い]]></title>
		<updated>2007-05-19T23:55:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Java" scheme="http://fireball.loafer.jp/kes/java/" />
		<content type="html">
<![CDATA[
<p>
検証ルールは &lt;validator&gt; 要素で定義されている。<br />
独自のルールを作る場合は、自前で用意しなければならない。<br />
そこで、既存のルールを参考にしながら調べてみよう。
</p>
<p>
とりあえず、required ルールの設定を眺めてみる。
</p>
<p>
&nbsp; &nbsp; &nbsp; &nbsp; &lt;validator name=&quot;required&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; classname=&quot;org.apache.struts.validator.FieldChecks&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; method=&quot;validateRequired&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; methodParams=&quot;java.lang.Object,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; org.apache.commons.validator.ValidatorAction,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; org.apache.commons.validator.Field,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; org.apache.struts.action.ActionMessages,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; org.apache.commons.validator.Validator,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; javax.servlet.http.HttpServletRequest&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; msg=&quot;errors.required&quot;/&gt;
</p>
<a href="http://fireball.loafer.jp/kes/java/article_522.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/java/article_522.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/java/article_522.html" />
		<published>2007-05-18T23:56:00+09:00</published>
		<title type="html"><![CDATA[独自ルール #1: validator 要素]]></title>
		<updated>2007-05-18T23:56:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Java" scheme="http://fireball.loafer.jp/kes/java/" />
		<content type="html">
<![CDATA[
<p>
ポートの次は、アドレスの書式の制限と言いたいところだが、<br />
これを正規表現でやるのはさすがにしんどい。
</p>
<p>
(?:\*|(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})(?:\/(?:3[0-2]|[0-2]?\d))?)
</p>
<p>
完全に、バグの元だな、こりゃ。<br />
こんなもん設定ファイルに書いたところで、<br />
多分、後で保守するやつが発狂する程度の効果しかない。
</p>
<p>
ということで、別の手を考えよう。
</p>
<a href="http://fireball.loafer.jp/kes/java/article_521.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/java/article_521.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/java/article_521.html" />
		<published>2007-05-17T23:56:00+09:00</published>
		<title type="html"><![CDATA[Validator のルール]]></title>
		<updated>2007-05-17T23:56:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Java" scheme="http://fireball.loafer.jp/kes/java/" />
		<content type="html">
<![CDATA[
<p>
値の形式を調べなければならない項目はほかにもある。
</p>
<p>
今日取り上げるのは、発信ポートと宛先ポートだ。<br />
これは両方同じ形式であり、全てのポートを示す 「*」、<br />
または 0 から 65535 までの数値を取る。
</p>
<p>
少し複雑な条件だが、正規表現を使って無理やり書いてみよう。<br />
正規表現さえ使えれば mask ルールを適用することができる。
</p>
<p>
(?:\*|6553[0-5]|655[0-2]\d|65[0-4]\d\d|6[0-4]\d{3}|[0-5]?\d{1,4})
</p>
<a href="http://fireball.loafer.jp/kes/java/article_520.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/java/article_520.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/java/article_520.html" />
		<published>2007-05-16T21:27:00+09:00</published>
		<title type="html"><![CDATA[Validator 設定 #8: constant 要素]]></title>
		<updated>2007-05-16T21:27:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Java" scheme="http://fireball.loafer.jp/kes/java/" />
		<content type="html">
<![CDATA[
<p>
今日は maxlength ルールだ。
</p>
<p>
このルールは名前の通り、入力文字数を制限することができる。
</p>
<p>
maxlength ルールの持つパラメータ変数は 2 つある。
</p>
<p>
1 つは、ルールと同じ名前の maxlength 変数で、<br />
制限する文字数を数値で指定する。<br />
これは必須のパラメータである。
</p>
<p>
もう 1 つは省略可能な lineEndLength 変数だ。<br />
これは、改行文字を何文字と計算するかを示す。
</p>
<a href="http://fireball.loafer.jp/kes/java/article_519.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/java/article_519.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/java/article_519.html" />
		<published>2007-05-15T23:56:00+09:00</published>
		<title type="html"><![CDATA[Validator 設定 #7: maxlength ルールとリテラル arg]]></title>
		<updated>2007-05-15T23:56:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Java" scheme="http://fireball.loafer.jp/kes/java/" />
		<content type="html">
<![CDATA[
<p>
引き続き、集合型の検証ついて考える。
</p>
<p>
集合型を扱う場合、そこに含まれる要素数だけでなく、<br />
各要素が取る値も検証しなければならない場合がある。
</p>
<p>
Validator 設定の &lt;field&gt; 要素で指定するプロパティ名は、<br />
集合型の要素を直接指定することが可能である。
</p>
<p>
例えば、プロトコルの場合プロパティ名は rule.protocols。<br />
このプロパティが示す値は String[] 型なので、<br />
最初の要素は、rule.protocols[0]、<br />
次の要素は rule.protocols[1] で表現することができる。
</p>
<a href="http://fireball.loafer.jp/kes/java/article_518.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/java/article_518.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/java/article_518.html" />
		<published>2007-05-14T23:57:00+09:00</published>
		<title type="html"><![CDATA[ Validator 設定 #6: 可変長要素へのルール適用]]></title>
		<updated>2007-05-14T23:57:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Java" scheme="http://fireball.loafer.jp/kes/java/" />
		<content type="html">
<![CDATA[
<p>
そういえば、プロトコルを保留していた。<br />
というのも、プロトコルは集合型の型（String[]）なのだ。
</p>
<p>
こういった単純値ではないプロパティの検証の場合、<br />
ルールがどのように機能するかどうかを知る必要がある。
</p>
<p>
Struts の Validator が用意しているほとんどのルールは、<br />
文字列に対して適用するものなので、<br />
評価する前に強制的に文字列化される。<br />
文字列以外の場合、toString() の値が評価されるのだ。
</p>
<a href="http://fireball.loafer.jp/kes/java/article_517.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/java/article_517.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/java/article_517.html" />
		<published>2007-05-13T23:26:00+09:00</published>
		<title type="html"><![CDATA[Validator 設定 #5: 集合型へのルール適用]]></title>
		<updated>2007-05-13T23:26:00+09:00</updated>
	</entry>

</feed>