KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > tools > actions > ValidateAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.tools.actions;
21
22 import org.netbeans.api.xml.cookies.ValidateXMLCookie;
23 import org.netbeans.modules.xml.core.actions.CollectXMLAction;
24 import org.netbeans.modules.xml.core.actions.InputOutputReporter;
25 import org.openide.nodes.Node;
26 import org.openide.util.HelpCtx;
27 import org.openide.util.RequestProcessor;
28 import org.openide.util.actions.CookieAction;
29
30 /**
31  * Validates XML file sending results to output window.
32  *
33  * @author Petr Kuzel
34  */

35 public class ValidateAction extends CookieAction implements CollectXMLAction.XMLAction {
36
37     /** Serial Version UID */
38     private static final long serialVersionUID = -8772119268950444993L;
39
40     
41     /** Be hooked on XMLDataObjectLook narking XML nodes. */
42     protected Class JavaDoc[] cookieClasses () {
43         return new Class JavaDoc[] { ValidateXMLCookie.class };
44     }
45
46     /** All selected nodes must be XML one to allow this action */
47     protected int mode () {
48         return MODE_ALL;
49     }
50
51     /** Check all selected nodes. */
52     protected void performAction (Node[] nodes) {
53
54         if (nodes == null) return;
55
56         RequestProcessor.getDefault().post(
57                new ValidateAction.RunAction (nodes)
58         );
59     }
60
61     /** Human presentable name. */
62     public String JavaDoc getName() {
63         return Util.THIS.getString("NAME_Validate_XML");
64     }
65
66     protected String JavaDoc iconResource () {
67         return "org/netbeans/modules/xml/tools/resources/validate_xml.png"; // NOI18N
68
}
69
70     /** Provide accurate help. */
71     public HelpCtx getHelpCtx () {
72         return new HelpCtx (ValidateAction.class);
73     }
74
75     protected boolean asynchronous() {
76         return false;
77     }
78
79     private class RunAction implements Runnable JavaDoc{
80         private Node[] nodes;
81
82         RunAction (Node[] nodes){
83             this.nodes = nodes;
84         }
85
86         public void run() {
87             InputOutputReporter console = new InputOutputReporter();
88             console.message(Util.THIS.getString("MSG_XML_valid_start"));
89             console.moveToFront();
90             for (int i = 0; i<nodes.length; i++) {
91                 Node node = nodes[i];
92                 ValidateXMLCookie cake = (ValidateXMLCookie) node.getCookie(ValidateXMLCookie.class);
93                 if (cake == null) continue;
94                 console.setNode(node); //??? how can console determine which editor to highlight
95
cake.validateXML(console);
96             }
97
98             console.message(Util.THIS.getString("MSG_XML_valid_end"));
99             console.moveToFront(true);
100        }
101     }
102 }
103
Popular Tags