KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > jsploader > JspNode


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.web.core.jsploader;
21
22 import java.io.*;
23 import java.beans.PropertyEditor JavaDoc;
24 import java.lang.reflect.InvocationTargetException JavaDoc;
25 import org.openide.ErrorManager;
26 import org.openide.filesystems.*;
27 import org.openide.filesystems.FileObject;
28 import org.openide.nodes.*;
29 import org.openide.loaders.DataNode;
30 import org.openide.loaders.DataObject;
31 import org.openide.loaders.MultiDataObject;
32 import org.openide.actions.OpenAction;
33 import org.openide.util.NbBundle;
34 import org.openide.util.HelpCtx;
35 import org.openide.util.actions.SystemAction;
36 import org.netbeans.modules.web.core.WebExecSupport;
37
38 //import org.netbeans.modules.java.Util;
39

40 /** The node representation of <code>JspDataObject</code> for internet files.
41 *
42 * @author Petr Jiricka
43 */

44 public class JspNode extends DataNode {
45
46     private static final String JavaDoc EXECUTION_SET_NAME = "Execution"; // NOI18N
47
private static final String JavaDoc SHEETNAME_TEXT_PROPERTIES = "textProperties"; // NOI18N
48

49     private static final String JavaDoc ICON_JSP = "org/netbeans/modules/web/core/resources/jsp16"; // NOI18N
50
private static final String JavaDoc ICON_TAG = "org/netbeans/modules/web/core/resources/tag16"; // NOI18N
51
private static final String JavaDoc ICON_JSP_XML = "org/netbeans/modules/web/core/resources/jsp-xml16"; // NOI18N
52
private static final String JavaDoc ICON_JSP_FRAGMENT = "org/netbeans/modules/web/core/resources/jsp-fragment16"; // NOI18N
53

54     public static final String JavaDoc PROP_FILE_ENCODING = "encoding"; //NOI18N
55
public static final String JavaDoc PROP_REQUEST_PARAMS = "requestparams"; // NOI18N
56

57     /** Create a node for the internet data object using the default children.
58     * @param jdo the data object to represent
59     */

60     public JspNode (JspDataObject jdo) {
61         super(jdo, Children.LEAF);
62         initialize();
63     }
64
65     private void initialize () {
66         setIconBase(getIconBase());
67         setDefaultAction (SystemAction.get (OpenAction.class));
68
69         if (isTagFile())
70                 setShortDescription (NbBundle.getMessage(JspNode.class, "LBL_tagNodeShortDesc")); //NOI18N
71
else
72                 setShortDescription (NbBundle.getMessage(JspNode.class, "LBL_jspNodeShortDesc")); //NOI18N
73
}
74
75     private String JavaDoc getExtension(){
76         return getDataObject().getPrimaryFile().getExt();
77     }
78     
79     private boolean isTagFile(){
80         String JavaDoc ext = getExtension();
81         return (ext.equals(JspLoader.TAGF_FILE_EXTENSION)
82             || ext.equals(JspLoader.TAGX_FILE_EXTENSION)
83             || ext.equals(JspLoader.TAG_FILE_EXTENSION));
84     }
85     
86     public DataObject getDataObject() {
87         return super.getDataObject();
88     }
89     
90     /** Create the property sheet.
91     * Subclasses may want to override this and add additional properties.
92     * @return the sheet
93     */

94     protected Sheet createSheet () {
95         Sheet.Set ps;
96
97         Sheet sheet = super.createSheet();
98
99         if (!isTagFile()){
100             ps = new Sheet.Set ();
101             ps.setName(EXECUTION_SET_NAME);
102             ps.setDisplayName(NbBundle.getBundle(JspNode.class).getString("PROP_executionSetName")); //NOI18N
103
ps.setShortDescription(NbBundle.getBundle(JspNode.class).getString("HINT_executionSetName")); //NOI18N
104

105             ps.put(new PropertySupport.ReadWrite (
106                        PROP_REQUEST_PARAMS,
107                        String JavaDoc.class,
108                        NbBundle.getBundle(JspNode.class).getString("PROP_requestParams"), //NOI18N
109
NbBundle.getBundle(JspNode.class).getString("HINT_requestParams") //NOI18N
110
) {
111                        public Object JavaDoc getValue() {
112                            return getRequestParams(((MultiDataObject)getDataObject()).getPrimaryEntry());
113                        }
114                        public void setValue (Object JavaDoc val) throws InvocationTargetException JavaDoc {
115                            if (val instanceof String JavaDoc) {
116                                try {
117                                    setRequestParams(((MultiDataObject)getDataObject()).getPrimaryEntry(), (String JavaDoc)val);
118                                } catch(IOException e) {
119                                    throw new InvocationTargetException JavaDoc (e);
120                                }
121                            }
122                            else {
123                                throw new IllegalArgumentException JavaDoc();
124                            }
125                        }
126                    }
127                   );
128                   sheet.put(ps);
129         }
130         // remove the params property
131
//ps.remove(ExecSupport.PROP_FILE_PARAMS);
132
// remove the debugger type property
133
//ps.remove(ExecSupport.PROP_DEBUGGER_TYPE);
134

135         
136
137         // text sheet
138
ps = new Sheet.Set();
139         ps.setName(SHEETNAME_TEXT_PROPERTIES);
140         ps.setDisplayName(NbBundle.getBundle(JspNode.class).getString("PROP_textfileSetName")); // NOI18N
141
ps.setShortDescription(NbBundle.getBundle(JspNode.class).getString("HINT_textfileSetName")); // NOI18N
142
sheet.put(ps);
143         
144            ps.put(new PropertySupport.ReadWrite(
145                    PROP_FILE_ENCODING,
146                    String JavaDoc.class,
147                    NbBundle.getBundle(JspNode.class).getString("PROP_fileEncoding"), //NOI18N
148
NbBundle.getBundle(JspNode.class).getString("HINT_fileEncoding") //NOI18N
149
) {
150                public Object JavaDoc getValue() {
151                    return ((JspDataObject)getDataObject()).getFileEncoding(false, true);
152                }
153                public void setValue(Object JavaDoc val) throws InvocationTargetException JavaDoc {
154                    if (val instanceof String JavaDoc) {
155                        ((JspDataObject)getDataObject()).setFileEncoding((String JavaDoc)val);
156                    } else {
157                        throw new IllegalArgumentException JavaDoc();
158                    }
159                }
160            }
161            );
162         
163         
164         return sheet;
165     }
166
167     static final void wrapThrowable(Throwable JavaDoc outer, Throwable JavaDoc inner, String JavaDoc message) {
168         ErrorManager.getDefault().annotate(
169             outer, ErrorManager.USER, null, message, inner, null);
170     }
171
172     /** Set request parameters for a given entry.
173     * @param entry the entry
174     * @param args array of arguments
175     * @exception IOException if arguments cannot be set
176     */

177     static void setRequestParams(MultiDataObject.Entry entry, String JavaDoc params) throws IOException {
178         StringBuffer JavaDoc newParams=new StringBuffer JavaDoc();
179         String JavaDoc s=null;
180         if (params!=null){
181             for (int i=0;i<params.length();i++) {
182                 char ch = params.charAt(i);
183                 if ((int)ch!=13 && (int)ch!=10) newParams.append(ch);
184             }
185             s=newParams.toString();
186             if (s.length()==0) s=null;
187         }
188         WebExecSupport.setQueryString(entry.getFile (), s);
189     }
190
191     /** Get the request parameters associated with a given entry.
192     * @param entry the entry
193     * @return the arguments, or an empty string if no arguments are specified
194     */

195     static String JavaDoc getRequestParams(MultiDataObject.Entry entry) {
196         return WebExecSupport.getQueryString(entry.getFile ());
197     }
198
199     /** Get the icon base.
200     * This should be a resource path, e.g. <code>/some/path/</code>,
201     * where icons are held. Subclasses may override this.
202     * @return the icon base
203     * @see #getIcons
204     */

205     protected String JavaDoc getIconBase() {
206         String JavaDoc ext = getDataObject().getPrimaryFile().getExt();
207         
208         if (ext.equals(JspLoader.TAGF_FILE_EXTENSION)
209             || ext.equals(JspLoader.TAGX_FILE_EXTENSION)
210             || ext.equals(JspLoader.TAG_FILE_EXTENSION))
211                 return ICON_TAG;
212         if (ext.equals(JspLoader.JSF_EXTENSION )
213             || ext.equals(JspLoader.JSPF_EXTENSION))
214                 return ICON_JSP_FRAGMENT;
215         if (ext.equals(JspLoader.JSPX_EXTENSION))
216                 return ICON_JSP_XML;
217         return ICON_JSP;
218
219     }
220
221 }
222
223
Popular Tags