1 19 20 package org.netbeans.test.gui.web.util; 21 22 import org.netbeans.jellytools.actions.OptionsViewAction; 23 24 25 import org.netbeans.jellytools.NbDialogOperator; 26 import org.netbeans.jellytools.OptionsOperator; 27 import org.netbeans.jellytools.Bundle; 28 29 import org.netbeans.jellytools.properties.ComboBoxProperty; 30 import org.netbeans.jellytools.properties.TextFieldProperty; 31 import org.netbeans.jellytools.properties.PropertySheetTabOperator; 32 import org.netbeans.jellytools.properties.PropertySheetOperator; 33 34 import org.netbeans.jemmy.operators.JTextComponentOperator; 35 36 import java.io.File ; 37 38 public class BrowserUtils { 39 private static String iSep = "|"; 40 private String sampleUserAgentNS7="User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02"; 41 private String sampleUserAgentNS4="User-Agent: Mozilla/4.78 [en] (X11; U; Linux 2.4.7-10smp i686)"; 42 private String sampleUserAgentIE6="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"; 43 44 public static final int NETSCAPE4 = 0; 45 public static final int NETSCAPE6 = 1; 46 public static final int NETSCAPE7 = 2; 47 public static final int MSIE6 = 3; 48 public static final int UNKNOWN = 32; 49 50 51 public BrowserUtils() { 52 } 53 54 public static void setExternalUnixBrowser() { 55 String browser = Bundle.getString("org.netbeans.modules.extbrowser.Bundle","CTL_UnixBrowserName"); 56 setBrowser(browser); 57 } 58 public static void setExternalWinBrowser() { 59 String browser = Bundle.getString("org.netbeans.modules.extbrowser.Bundle","CTL_WinBrowserName"); 60 setBrowser(browser); 61 } 62 public static void setSwingBrowser() { 63 String browser = Bundle.getString("org.netbeans.beaninfo.Bundle","CTL_SwingBrowser"); 64 setBrowser(browser); 65 } 66 public static void setCLBrowser() { 67 String browser = Bundle.getString("org.netbeans.modules.extbrowser.Bundle","CTL_SimpleExtBrowser"); 68 setBrowser(browser); 69 } 70 public static void setCLBrowserCommand(String command) { 71 OptionsOperator oo = OptionsOperator.invoke(); 72 String ideConfiguration = Bundle.getString("org.netbeans.core.Bundle", "UI/Services/IDEConfiguration"); 73 String sets = Bundle.getString("org.netbeans.core.Bundle", "UI/Services/IDEConfiguration/ServerAndExternalToolSettings"); 74 String browsers = Bundle.getString("org.netbeans.core.Bundle", "Services/Browsers"); 75 String cl = Bundle.getString("org.netbeans.modules.extbrowser.Bundle","CTL_SimpleExtBrowser"); 76 oo.selectOption(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl); 77 PropertySheetOperator pso = PropertySheetOperator.invoke(); 78 PropertySheetTabOperator psto = new PropertySheetTabOperator(pso); 79 String pnameBrowserExecutable = Bundle.getString("org.netbeans.modules.extbrowser.Bundle" ,"PROP_browserExecutable"); 80 TextFieldProperty pr = new TextFieldProperty(psto, pnameBrowserExecutable); 81 if (!pr.getValue().equals(command)) { 82 pr.setValue(command); 83 } 84 } 85 86 87 public static void setEBUBrowserCommand(String command) { 88 OptionsOperator oo = OptionsOperator.invoke(); 89 String ideConfiguration = Bundle.getString("org.netbeans.core.Bundle", "UI/Services/IDEConfiguration"); 90 String sets = Bundle.getString("org.netbeans.core.Bundle", "UI/Services/IDEConfiguration/ServerAndExternalToolSettings"); 91 String browsers = Bundle.getString("org.netbeans.core.Bundle", "Services/Browsers"); 92 String cl = Bundle.getString("org.netbeans.modules.extbrowser.Bundle","CTL_UnixBrowserName"); 93 oo.selectOption(ideConfiguration + iSep + sets + iSep + browsers + iSep + cl); 94 PropertySheetOperator pso = PropertySheetOperator.invoke(); 95 PropertySheetTabOperator psto = new PropertySheetTabOperator(pso); 96 String pnameBrowserExecutable = Bundle.getString("org.netbeans.modules.extbrowser.Bundle" ,"PROP_browserExecutable"); 97 TextFieldProperty pr = new TextFieldProperty(psto, pnameBrowserExecutable); 98 if (!pr.getValue().equals(command)) { 99 pr.setValue(command); 100 } 101 } 102 103 104 public static void setBrowser(String name) { 105 OptionsOperator oo = OptionsOperator.invoke(); 107 String ideConfiguration = Bundle.getString("org.netbeans.core.Bundle", "UI/Services/IDEConfiguration"); 108 String system = Bundle.getString("org.netbeans.core.Bundle", "UI/Services/IDEConfiguration/System"); 109 String systemSettings = Bundle.getString("org.netbeans.core.Bundle", "Services/org-netbeans-core-IDESettings.settings"); 110 oo.selectOption(ideConfiguration + iSep + system + iSep + systemSettings); 111 PropertySheetOperator pso = PropertySheetOperator.invoke(); 112 PropertySheetTabOperator psto = new PropertySheetTabOperator(pso); 113 String pnameWebBrowser = Bundle.getString("org.netbeans.core.Bundle" ,"PROP_WWW_BROWSER"); 114 ComboBoxProperty pr = new ComboBoxProperty(psto, pnameWebBrowser); 115 if (!pr.getValue().equals(name)) { 116 pr.setValue(name); 117 } 118 } 119 public static boolean handleSwingBrowserDialog() { 120 String title = Bundle.getString("org.openide.Bundle","NTF_InformationTitle"); 121 try { 122 NbDialogOperator dialog = new NbDialogOperator(title); 123 dialog.ok(); 124 return true; 125 }catch(Exception e) { 126 return false; 127 } 128 } 129 130 131 132 133 134 137 public static void setDDEServerExplorer() { 138 System.out.println("#####\nNot implemented yet\n#####"); 139 } 140 public static void setDDEServerNetscape() { 141 System.out.println("#####\nNot implemented yet\n#####"); 142 } 143 144 public static void setDDEServerNetscape6() { 145 System.out.println("#####\nNot implemented yet\n#####"); 146 } 147 148 149 152 153 public static String getIEInPath() { 154 System.out.println("#####\nNot implemented yet\n#####"); 155 return null; 156 } 157 public static String getIEFullPath() { 158 System.out.println("#####\nNot implemented yet\n#####"); 159 return null; 160 } 161 public static String getNetscapeFullPath() { 162 String [] paths = null; 163 String command = null; 164 if(System.getProperty("os.name").indexOf("Windows")!=-1) { 165 System.out.println("##########\nThis test must be extended for Windows platform\n#######"); 166 return null; 167 }else { 168 paths = new String [] {"/usr/bin/netscape","/usr/local/bin/netscape","/bin/netscape"}; 169 } 170 for(int i=0;i<paths.length;i++) { 171 if((new File (paths[i])).exists()) { 172 command = paths[i] + " {URL}"; 173 i = paths.length; 174 } 175 } 176 if(command == null) { 177 StringBuffer reason = new StringBuffer ("Nothing of following commands found on your system : "); 178 for(int i=0;i<paths.length;i++) { 179 reason.append(paths[i] + ";"); 180 } 181 System.out.println("##########\n" + reason.toString() + "\n##########"); 182 return null; 183 } 184 return command; 185 } 186 public static String getNetscapeInPath() { 187 String netscapeWin = "netscape.exe"; 188 String netscapeUx = "netscape"; 189 if(System.getProperty("os.name").indexOf("Windows")!=-1) { 190 return netscapeWin; 191 }else { 192 return netscapeUx; 193 } 194 } 195 public static String getNetscape6FullPath() { 196 String [] paths = null; 197 String command = null; 198 if(System.getProperty("os.name").indexOf("Windows")!=-1) { 199 System.out.println("##########\nThis test must be extended for Windows platform\n#######"); 200 return null; 201 }else { 202 paths = new String [] {"/usr/local/netscape6/netscape","/usr/bin/netscape6","/usr/local/bin/netscape6","/bin/netscape6"}; 203 } 204 for(int i=0;i<paths.length;i++) { 205 if((new File (paths[i])).exists()) { 206 command = paths[i] + " {URL}"; 207 i = paths.length; 208 } 209 } 210 if(command == null) { 211 StringBuffer reason = new StringBuffer ("Nothing of following commands found on your system : "); 212 for(int i=0;i<paths.length;i++) { 213 reason.append(paths[i] + ";"); 214 } 215 System.out.println("##########\n" + reason.toString() + "\n##########"); 216 return null; 217 } 218 return command; 219 } 220 public static String getNetscape6InPath() { 221 String netscapeWin = "netscp6.exe"; 222 String netscapeUx = "netscape6"; 223 if(System.getProperty("os.name").indexOf("Windows")!=-1) { 224 return netscapeWin; 225 }else { 226 return netscapeUx; 227 } 228 } 229 230 231 232 233 234 237 public static boolean handleErrorInCLBrowser() { 238 String title = Bundle.getString("org.openide.Bundle","NTF_WarningTitle"); 239 String text = Bundle.getString("org.netbeans.modules.extbrowser.Bundle","EXC_Invalid_Processor"); 240 NbDialogOperator op = null; 241 try { 242 op = new NbDialogOperator(title); 243 }catch(Exception e) { 244 System.out.println(title + " dialog not found"); 245 return false; 246 } 247 op.ok(); 250 return true; 251 } 252 255 public static boolean handleErrorInUnixBrowser() { 256 String title = Bundle.getString("org.openide.Bundle","NTF_WarningTitle"); 257 String text = Bundle.getString("org.netbeans.modules.extbrowser.Bundle","MSG_Cant_run_netscape"); try { 259 NbDialogOperator op = new NbDialogOperator(title); 260 op.ok(); 261 return true; 262 }catch(Exception e) { 263 return false; 264 } 265 } 266 267 public static int getBrowserVersion(String userAgent) { 268 if(userAgent.indexOf("MSIE 6")!=-1) { 269 return MSIE6; 270 } 271 if(userAgent.indexOf("Mozilla/4")!=-1) { 272 return NETSCAPE4; 273 } 274 if(userAgent.indexOf("Mozilla/5")!=-1) { 275 if(userAgent.indexOf("Netscape/7")!=-1) { 276 return NETSCAPE7; 277 } 278 if(userAgent.indexOf("Netscape6/6")!=-1) { 279 return NETSCAPE6; 280 } 281 } 282 return UNKNOWN; 283 } 284 285 286 public static String getBrowserDescription(int version) { 287 String descr = null; 288 switch(version) { 289 case NETSCAPE4: 290 descr = "Netscape4.x browser"; 291 break; 292 case NETSCAPE6: 293 descr = "Netscape6.x browser"; 294 break; 295 case NETSCAPE7: 296 descr = "Netscape7.x browser"; 297 break; 298 case MSIE6: 299 descr = "Internet Explorer 6"; 300 break; 301 case UNKNOWN: 302 descr = "This browser is unknown by BrowserUtils"; 303 break; 304 default: 305 descr = "Can't understand version " + version; 306 } 307 return descr; 308 } 309 } 310 311 | Popular Tags |