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

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

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

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

  1. 「ファイル」->「新規」->「一般」->「ワークスペース」を選択して「新規のワークスペース」ダイアログを開き、新しいワークスペースと空のプロジェクトを作成します。
  2. 「ファイル」->「新規」->「一般」->「Javaクラス」を選択して、プロジェクトに新しいクラス・ファイルを作成し、MyTagEditorという名前を付けます。
  3. プロジェクト・ファイル(.jpr)をダブルクリックして、「プロジェクトの設定」ダイアログを開きます。ツリーで「構成」を開き、「Development」を開いて「ライブラリ」を選択し、プロジェクトの選択済のライブラリのリストに「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 ];

        // 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 Code Editor, uncomment the following.
        /*JSPTagUtils.doAll( getLibrary(),
                           JspTagBuilder.buildInsertTag( getTag(),
                                                         getLibrary(),
                                                         attrList.iterator() ) );
        */
        //To Insert a Tag without attributes into the Code Editor, uncomment the following

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

        return true;

      }
    }

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

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

  1. <JDEV_HOME>\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 Specificationを参照してください。
http://java.sun.com/products/jsp/index.html