2011-06-29 11 views
0

私はnetbeansのWebサイト(サーバの問題のためにオフラインです)でチュートリアルを使用して、XMLを読み込み、それに関する情報を出力するアクションを作成しました。すべてうまくやっていますが、特定のXMLファイルでこのアクションを呼び出すことはできません。このために役立つリソースはありません。たとえば、プログラムを実行すると、マニフェストファイル(xmlでなく、それに応じてエラーが発生します)でアクションを呼び出すことができますが、.xmlファイルでは実行できません。チュートリアルから変更した原因となる可能性のあるコードは次のとおりです。私はそれが "Show XML"メッセージを常に有効にすると考えましたが、xmlファイルではまだ無効になっています。ここでNetbeansプラットフォームの動作が困難

@ActionReferences({ 
    @ActionReference(path = "Editors/Popup", position = 1100) 
}) 

は私SSCCE(原文のまま)です:

/* 
* To change this template, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package com.versifit.udl.xml; 

import java.awt.event.ActionListener; 
import java.awt.event.ActionEvent; 
import java.io.IOException; 
import java.io.InputStream; 
import org.openide.awt.ActionID; 
import org.openide.awt.ActionReference; 
import org.openide.awt.ActionReferences; 
import org.openide.awt.ActionRegistration; 
import org.openide.cookies.EditorCookie; 
import org.openide.util.Exceptions; 
import org.openide.util.NbBundle; 
import org.openide.util.NbBundle.Messages; 
import org.openide.windows.IOProvider; 
import org.openide.windows.InputOutput; 
import org.openide.xml.XMLUtil; 
import org.w3c.dom.Document; 
import org.w3c.dom.NamedNodeMap; 
import org.w3c.dom.NodeList; 
import org.xml.sax.InputSource; 
import org.xml.sax.SAXException; 

@ActionID(category = "Edit", 
id = "com.versifit.udl.xml.ShowXMLStructureAction") 
@ActionRegistration(displayName = "#CTL_ShowXMLStructureAction") 
@ActionReferences({ 
    @ActionReference(path = "Editors/Popup", position = 1100) 
}) 
@Messages("CTL_ShowXMLStructureAction=Show Xml Structure") 

public final class ShowXMLStructureAction implements ActionListener { 

private final EditorCookie context; 

public ShowXMLStructureAction(EditorCookie context) { 
    this.context = context; 
} 

public void actionPerformed(ActionEvent ev) { 
    EditorCookie editorCookie = context; 
    //Get the tab name from the Bundle.prop file: 
    String tabName = NbBundle.getMessage(ShowXMLStructureAction.class, "LBL_tabName"); 
    InputOutput io = IOProvider.getDefault().getIO(tabName, false); 
    io.select(); //"XML Structure" tab is selected 
    try { 
    //Get the InputStream from the EditorCookie: 
    InputStream is = ((org.openide.text.CloneableEditorSupport) editorCookie).getInputStream(); 
    //Use the NetBeans org.openide.xml.XMLUtil class to create a org.w3c.dom.Document: 
    //"XML Structure" tab is created in Output Window for writing the list of tags: 
    Document doc = XMLUtil.parse(new InputSource(is),true,true,null,null); 
    //Create a list of nodes, for all hte elements: 
    NodeList list = doc.getElementsByTagName("*"); 
    //Iterate through the list: 
    for (int i = 0; i < list.getLength(); i++) { 
     //For each node in the list, create a org.w3c.dom.Node: 
     org.w3c.dom.Node mainNode = list.item(i); 
     //Create a map for all the attributes of the org.w3c.dom.Node: 
     NamedNodeMap map = mainNode.getAttributes(); 
     //Get the name of the node: 
     String nodeName = mainNode.getNodeName(); 
     //Create a StringBuilder for the Attributes of the Node: 
     StringBuilder attrBuilder = new StringBuilder(); 
     //Iterate through the map of attributes: 
     for (int j = 0; j < map.getLength(); j++) { 
      //Each iteration, create a new Node: 
      org.w3c.dom.Node attrNode = map.item(j); 
      //Get the name of the current Attribute: 
      String attrName = attrNode.getNodeName(); 
      //Add the current Attribute to the StringBuilder: 
      attrBuilder.append("*").append(attrName).append(" "); 
     } 
     //Print the element and its attributes to the Output window: 
     io.getOut().println("ELEMENT: " + nodeName + 
       " --> ATTRIBUTES: " + attrBuilder.toString()); 
    } 
    //Close the InputStream: 
    is.close(); 
} catch (SAXException ex) { 
    Exceptions.printStackTrace(ex); 
} catch (IOException ex) { 
    Exceptions.printStackTrace(ex); 
} 
} 
} 

答えて

1

これは、何が必要です:

@ActionReferences({ @ActionReference(パス= "編集/テキスト/ XML /ポップアップ" 、位置= 1100) })