KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.xml.tools.actions;
20
21 import java.util.*;
22
23 import org.openide.*;
24 import org.openide.nodes.*;
25 import org.openide.util.HelpCtx;
26 import org.openide.util.actions.CookieAction;
27 import org.openide.loaders.*;
28
29 import org.netbeans.tax.*;
30 import org.netbeans.modules.xml.core.*;
31 import org.netbeans.modules.xml.core.actions.*;
32
33 import org.netbeans.api.xml.cookies.*;
34 import org.openide.util.RequestProcessor;
35
36
37 /**
38  * checks DTD file sending results to output window.
39  *
40  * @author Petr Kuzel
41  * @version 1.0
42  */

43 public class CheckDTDAction extends CookieAction implements CollectDTDAction.DTDAction {
44
45     /** serialVersionUID */
46     private static final long serialVersionUID = -8772119268950444992L;
47
48     /** Be hooked on XMLDataObjectLook narking XML nodes. */
49     protected Class JavaDoc[] cookieClasses () {
50         return new Class JavaDoc[] { CheckXMLCookie.class };
51     }
52
53     /** All selected nodes must be XML one to allow this action */
54     protected int mode () {
55         return MODE_ALL;
56     }
57
58     /** Check all selected nodes. */
59     protected void performAction (Node[] nodes) {
60
61         if (nodes == null) return;
62         
63         RequestProcessor.postRequest(
64                new CheckDTDAction.RunAction (nodes));
65
66     }
67     
68     protected boolean asynchronous() {
69         return false;
70     }
71
72     /** Human presentable name. */
73     public String JavaDoc getName() {
74         return Util.THIS.getString("NAME_Validate_DTD");
75     }
76
77     protected String JavaDoc iconResource () {
78         return "org/netbeans/modules/xml/tools/resources/checkDTDAction.gif"; // NOI18N
79
}
80
81     /** Provide accurate help. */
82     public HelpCtx getHelpCtx () {
83         return new HelpCtx (CheckDTDAction.class);
84     }
85
86     private class RunAction implements Runnable JavaDoc{
87         private Node[] nodes;
88
89         RunAction (Node[] nodes){
90             this.nodes = nodes;
91         }
92
93         public void run() {
94             InputOutputReporter console = new InputOutputReporter();
95             
96             console.message(Util.THIS.getString("MSG_DTD_valid_start"));
97             console.moveToFront();
98             
99             for (int i = 0; i<nodes.length; i++) {
100                 Node node = nodes[i];
101                 CheckXMLCookie cake = (CheckXMLCookie) node.getCookie(CheckXMLCookie.class);
102                 if (cake == null) continue;
103                 console.setNode(node); //??? how can console determine which editor to highlight
104
cake.checkXML(console);
105             }
106
107             console.message(Util.THIS.getString("MSG_DTD_valid_end"));
108             console.moveToFront(true);
109        }
110     }
111 }
112
Popular Tags