1 19 20 package org.netbeans.modules.web.core.jsploader; 21 22 import java.io.*; 23 import java.beans.PropertyEditor ; 24 import java.lang.reflect.InvocationTargetException ; 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 40 44 public class JspNode extends DataNode { 45 46 private static final String EXECUTION_SET_NAME = "Execution"; private static final String SHEETNAME_TEXT_PROPERTIES = "textProperties"; 49 private static final String ICON_JSP = "org/netbeans/modules/web/core/resources/jsp16"; private static final String ICON_TAG = "org/netbeans/modules/web/core/resources/tag16"; private static final String ICON_JSP_XML = "org/netbeans/modules/web/core/resources/jsp-xml16"; private static final String ICON_JSP_FRAGMENT = "org/netbeans/modules/web/core/resources/jsp-fragment16"; 54 public static final String PROP_FILE_ENCODING = "encoding"; public static final String PROP_REQUEST_PARAMS = "requestparams"; 57 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")); else 72 setShortDescription (NbBundle.getMessage(JspNode.class, "LBL_jspNodeShortDesc")); } 74 75 private String getExtension(){ 76 return getDataObject().getPrimaryFile().getExt(); 77 } 78 79 private boolean isTagFile(){ 80 String 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 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")); ps.setShortDescription(NbBundle.getBundle(JspNode.class).getString("HINT_executionSetName")); 105 ps.put(new PropertySupport.ReadWrite ( 106 PROP_REQUEST_PARAMS, 107 String .class, 108 NbBundle.getBundle(JspNode.class).getString("PROP_requestParams"), NbBundle.getBundle(JspNode.class).getString("HINT_requestParams") ) { 111 public Object getValue() { 112 return getRequestParams(((MultiDataObject)getDataObject()).getPrimaryEntry()); 113 } 114 public void setValue (Object val) throws InvocationTargetException { 115 if (val instanceof String ) { 116 try { 117 setRequestParams(((MultiDataObject)getDataObject()).getPrimaryEntry(), (String )val); 118 } catch(IOException e) { 119 throw new InvocationTargetException (e); 120 } 121 } 122 else { 123 throw new IllegalArgumentException (); 124 } 125 } 126 } 127 ); 128 sheet.put(ps); 129 } 130 135 136 137 ps = new Sheet.Set(); 139 ps.setName(SHEETNAME_TEXT_PROPERTIES); 140 ps.setDisplayName(NbBundle.getBundle(JspNode.class).getString("PROP_textfileSetName")); ps.setShortDescription(NbBundle.getBundle(JspNode.class).getString("HINT_textfileSetName")); sheet.put(ps); 143 144 ps.put(new PropertySupport.ReadWrite( 145 PROP_FILE_ENCODING, 146 String .class, 147 NbBundle.getBundle(JspNode.class).getString("PROP_fileEncoding"), NbBundle.getBundle(JspNode.class).getString("HINT_fileEncoding") ) { 150 public Object getValue() { 151 return ((JspDataObject)getDataObject()).getFileEncoding(false, true); 152 } 153 public void setValue(Object val) throws InvocationTargetException { 154 if (val instanceof String ) { 155 ((JspDataObject)getDataObject()).setFileEncoding((String )val); 156 } else { 157 throw new IllegalArgumentException (); 158 } 159 } 160 } 161 ); 162 163 164 return sheet; 165 } 166 167 static final void wrapThrowable(Throwable outer, Throwable inner, String message) { 168 ErrorManager.getDefault().annotate( 169 outer, ErrorManager.USER, null, message, inner, null); 170 } 171 172 177 static void setRequestParams(MultiDataObject.Entry entry, String params) throws IOException { 178 StringBuffer newParams=new StringBuffer (); 179 String 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 195 static String getRequestParams(MultiDataObject.Entry entry) { 196 return WebExecSupport.getQueryString(entry.getFile ()); 197 } 198 199 205 protected String getIconBase() { 206 String 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 |