API リファレンス
ダウンロード
- RSSの取り出しに失敗しました:http://sourceforge.jp/projects/paraselene/releases/rss
次に、スケルトン生成時に派生クラスの存在を通知するクラスを作成します。
GrantTag を実装したクラスを作成し、そのクラスを引き渡すために GrantTagProvider を実装したクラスを作成します。
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57:
package lib; import paraselene.tag.*; import paraselene.tag.attr.*; import paraselene.dyna.*; /** * 派生クラスの置き換え方法を提供します。 */ public class Custom implements GrantTagProvider { /** * 複数行テキストボックスの派生クラスを提供します。 */ private class MultiText implements GrantTag { public String getNewString() throws DynamicPageException { return "new lib.CustomMultiTextBox()"; } public Tag getNewTag() throws DynamicPageException { return new CustomMultiTextBox(); } } /** * 単一行テキストボックスの派生クラスを提供します。 */ private class SingleText implements GrantTag { private boolean password; SingleText( boolean pw ) { password = pw; } public String getNewString() throws DynamicPageException { return "new lib.CustomSingleTextBox(" + Boolean.toString( password ) + ")"; } public Tag getNewTag() throws DynamicPageException { return new CustomSingleTextBox( password ); } } public GrantTag getGrantTag( Tag tag ) throws DynamicPageException { Attribute cls = tag.getAttribute( "class" ); if ( cls == null ) return null; // 属性値はnullの可能性もあるため、このような if 文にしています。 if ( !"custom".equals( cls.getString() ) ) return null; if ( tag.getName().equals( "textarea" ) ) { return new MultiText(); } else if ( tag.getName().equals( "input" ) ) { Attribute type = tag.getAttribute( "type" ); if ( "text".equals( type.getString() ) ) { return new SingleText( false ); } else if ( "password".equals( type.getString() ) ) { return new SingleText( true ); } } return null; } }
GrantTag を実装した、次のインナークラスを準備しています。
GrantTag には2つのメソッドを実装する必要があります。
SingleText クラスは、CustomSingleTextBox 用のコンストラクタ引数を保持するための変数を準備しています。
GrantTagProvider には、GrantTag 実装クラスを返すためのメソッドである、getGrantTag を準備します。
今回は、属性"class"の属性値が"custom"であればクラスの置き換えを行うようにしています。
Paraselene は、getGrantTag が null を返すと、デフォルトの Paraseleneで 準備されているクラスを使用します。
このソースでは、
実行例へ