カスタム・タグ・エディタの作成

独自のカスタム・タグ・エディタを作成して、JDeveloperのコンポーネント・パレットやJSP 1.1および1.2のカスタム・タグ・テクノロジで使用できます。独自のカスタム・タグ・エディタを実装する手順は、次のとおりです。

次の手順では、単純なカスタム・タグ・エディタの作成方法を説明します。この手順では、ワークスペース、プロジェクト、およびファイルの作成など、基本的なJDeveloperの機能を理解していることを前提としています。

単純なカスタム・タグ・エディタを作成するには、次のようにします。

  1. 「ファイル」 次の選択 「新規」 次の選択 「General」 次の選択 「ワークスペース」を選択し、「新規ワークスペース」ダイアログを開き、新規ワークスペースと空のプロジェクトを作成します。
  2. 「ファイル」 次の選択 「新規」 次の選択 「General」 次の選択 「Javaクラス」を選択し、MyTagEditorという名前を付け、プロジェクトに新規クラス・ファイルを作成します。
  3. プロジェクト・ファイル(.jpr)をダブルクリックして、「プロジェクトの設定」ダイアログを開きます。ツリーで「コンフィグレーション」を開き、「開発」を開いて「ライブラリ」を選択し、プロジェクトの選択済のライブラリのリストに「JDeveloper」ライブラリを追加します。
  4. MyTagEditor.javaに次のコードを追加します。

    package package1;

    import java.util.ArrayList;
    import oracle.ide.addin.Context;
    import oracle.jdevimpl.jsp.tags.taglib.model.Tag;
    import oracle.jdevimpl.jsp.wizards.tageditor.TagEditorWizard;
    import oracle.jdevimpl.jsp.tags.wizard.JspTagBuilder;
    import oracle.jdeveloper.jsp.utils.JSPTagUtils;

    public class MyTagEditor extends TagEditorWizard
    {

     public boolean invoke( Context ctx, String[] params )
     {
       String jspTagLibrary  = params[ 0 ];
       String tagName        = params[ 1 ];< /FONT >

       // Sets all necessary getters and setters for you to use.
       setAttributes( jspTagLibrary, tagName );

       // Retrieve Tag
       Tag tag = getTag();
       
       /**
       * Here, you would build your own UI using the Tag object above.
       * You must return an Iterator of Object Arrays contaning both the name
       * of the attribute and it's assigned value, if any.
       * Example for a simple tag with attributes foo and foo1 with assigned values.
       */

       // Hard Coding simple attribute name - value pairing. Would normally be generated
       // by what the user specifies in your UI.
       ArrayList attrList = new ArrayList();
       String[] foo = { "foo", "fooValue" };
       String[] foo1 = { "foo1", "foo1Value" };
       attrList.add( foo );
       attrList.add( foo1 );

       
       // To Insert a Tag WITH Attributes into the Java Code Editor, uncomment the following.
       /*JSPTagUtils.doAll( getLibrary(),
                          JspTagBuilder.buildInsertTag( getTag(),
                                                        getLibrary(),
                                                        attrList.iterator() ) );
       */
       //To Insert a Tag without attributes into the Java Code Editor, uncomment the following

    //JSPTagUtils.doAll( getLibrary(), getTag() );

    return true;

     }
    }

  5. 「プロジェクト」 次の選択 「再ビルド」を選択し、作業内容をコンパイルして保存します。
  6. タグ・エディタをJARファイルとして、<JDEV_INSTALL¥jdev¥lib¥ext>へデプロイします。「ファイル」 次の選択 「新規」 を選択して「General」を開き、「デプロイメント・プロファイル」を選択して「JARファイル - シンプル・アーカイブ」をダブルクリックします。次に、「アプリケーション・ナビゲータ」で.deployファイルを右クリックし、「JARファイルにデプロイ」を選択します。

palette.xmlファイル内の指定されたタグ項目にエディタを追加するには、次のようにします。

  1. <JDEV_INSTALL>¥jdev¥systemにあるpalette.xmlファイルを開きます。
  2. タグ・エディタを使用する<item>タグを検索します。
    たとえば、次のようなタグです。
        <item>
            <icon>/oracle/ideimpl/resource/images/palette/jsp.gif</icon>
            <info>util</info>
            <longLabel>Displays when a JSP page was last modified.</longLabel>
            <shortLabel>lastModified</shortLabel>
            <type>jsptag</type>
         </item>

  3. エディタを指定する<item>要素に、エディタ・タグを追加します。
    たとえば、次のようにします。

        <item>
            <icon>/oracle/ideimpl/resource/images/palette/jsp.gif</icon>
            <info>util</info>
            <longLabel>Displays when a JSP page was last modified.</longLabel>
            <shortLabel>lastModified</shortLabel>
            <type>jsptag</type>
            <editor>package1.MyTagEditor</editor>
       </item>

  4. JDeveloperを終了して再起動し、変更を有効にします。

JDeveloperのJSPカスタム・タグ・ライブラリについて
カスタムJSPタグ・ライブラリの作成
カスタム・タグ・インサイト・エディタの作成

詳細は、次のURLでJavaServer Pages仕様を参照してください。
http://java.sun.com/products/jsp/index.html