List of usage examples for java.util StringTokenizer nextToken
public String nextToken()
From source file:com.adito.agent.client.ProxyUtil.java
/** * Attempt to proxy settings from Internet Explorer. * //from w ww . jav a 2 s .c o m * @return internet explorer proxy settings * @throws IOException if IE settings could not be obtained for some reason */ public static BrowserProxySettings lookupIEProxySettings() throws IOException { try { Vector addresses = new Vector(); Vector proxies = new Vector(); String proxyServerValue = null; String proxyOveride = null; /* Only use jRegistry if on Windows, running 1.3 or up Java * and NOT Windows Vista with JDK6.0 (because of jvm crash) */ if (Utils.isSupportedJRE("+1.3") && Utils.isSupportedPlatform( "Windows") /*&& !(Utils.isSupportedOSVersion("+6.0") && Utils.isSupportedJRE("+1.6"))*/) { /* * We can use jRegistryKey API to lookup IE settings in the * registry */ // RegistryKey key = new RegistryKey(RootKey.HKEY_CURRENT_USER, // "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); //$NON-NLS-1$ String proxyEnable = WinRegistry.getRegistryValue("user", "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyEnable", "0"); if (proxyEnable != null) { //$NON-NLS-1$ /* * We have ProxyEnable so check to see if we are using a * proxy */ if (proxyEnable.equals("1")) { //$NON-NLS-1$ //$NON-NLS-2$ proxyServerValue = WinRegistry.getRegistryValue("user", "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyServer", null); if (proxyServerValue != null) { //$NON-NLS-1$ /** * We have some proxy settings. The values will be * in the format "server.proxy.net:8888" or */ proxyOveride = WinRegistry.getRegistryValue("user", "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyOverride", null); } } else { } } } else { if (System.getProperty("java.vendor").startsWith("Microsoft")) { //$NON-NLS-1$ //$NON-NLS-2$ try { Class clazz = Class.forName("com.ms.lang.RegKey"); //$NON-NLS-1$ int userRoot = clazz.getField("USER_ROOT").getInt(null); //$NON-NLS-1$ int keyOpenAll = clazz.getField("KEYOPEN_ALL").getInt(null); //$NON-NLS-1$ // #ifdef DEBUG log.info(Messages.getString("ProxyUtil.lookingForRoot")); //$NON-NLS-1$ // #endif Object rootKey = clazz.getMethod("getRootKey", new Class[] { int.class }).invoke(null, //$NON-NLS-1$ new Object[] { new Integer(userRoot) }); // #ifdef DEBUG log.info(Messages.getString("ProxyUtil.getIERegistryKey")); //$NON-NLS-1$ // #endif Object key = clazz.getConstructor(new Class[] { clazz, String.class, int.class }) .newInstance(new Object[] { rootKey, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", //$NON-NLS-1$ new Integer(keyOpenAll) }); // #ifdef DEBUG log.info(Messages.getString("ProxyUtil.checkingIfProxyEnabled")); //$NON-NLS-1$ // #endif if (((Integer) (clazz.getMethod("getIntValue", new Class[] { String.class }).invoke(key, //$NON-NLS-1$ new Object[] { "ProxyEnable" }))).intValue() == 1) { //$NON-NLS-1$ // #ifdef DEBUG log.info(Messages.getString("ProxyUtil.gettingProxyServerList")); //$NON-NLS-1$ // #endif proxyServerValue = (String) (clazz.getMethod("getStringValue", //$NON-NLS-1$ new Class[] { String.class, String.class }) .invoke(key, new Object[] { "ProxyServer", "" })); //$NON-NLS-1$ //$NON-NLS-2$ // #ifdef DEBUG log.info(Messages.getString("ProxyUtil.gettingProxyOverides")); //$NON-NLS-1$ // #endif proxyOveride = (String) (clazz .getMethod("getStringValue", new Class[] { String.class, String.class }) //$NON-NLS-1$ .invoke(key, new Object[] { "ProxyOverride", "" })); //$NON-NLS-1$ //$NON-NLS-2$ } } catch (Throwable t) { t.printStackTrace(); } } else { // #ifdef DEBUG log.info(MessageFormat.format(Messages.getString("ProxyUtil.unsupportedJavaRuntime"), //$NON-NLS-1$ new Object[] { System.getProperty("java.version"), //$NON-NLS-1$ System.getProperty("java.vendor") })); //$NON-NLS-1$ // #endif } } ProxyInfo p; if (proxyServerValue != null && proxyServerValue.indexOf(';') > -1) { /** * Format is multiple * "ftp=ftp.com:4444;gopher=gopher.com:3333;http=198.162.1.119:8888;https=https.com:2222;socks=socks.com:1111" */ StringTokenizer tokens = new StringTokenizer(proxyServerValue, ";"); //$NON-NLS-1$ while (tokens.hasMoreTokens()) { p = createProxyInfo(tokens.nextToken(), "IE Proxy Settings"); //$NON-NLS-1$ proxies.addElement(p); } } else if (proxyServerValue != null) { /** * Format is single "http=server.proxy.net:8888" or * "server.proxy.net:8888" */ p = createProxyInfo(proxyServerValue, "IE Proxy Settings"); //$NON-NLS-1$ proxies.addElement(p); } BrowserProxySettings bps = new BrowserProxySettings(); bps.setBrowser("Internet Explorer"); //$NON-NLS-1$ bps.setProxies(new ProxyInfo[proxies.size()]); proxies.copyInto(bps.getProxies()); if (proxyOveride != null) { StringTokenizer tokens = new StringTokenizer(proxyOveride, ";"); //$NON-NLS-1$ while (tokens.hasMoreTokens()) { addresses.addElement(tokens.nextToken()); } } bps.setBypassAddr(new String[addresses.size()]); addresses.copyInto(bps.getBypassAddr()); return bps; } catch (Throwable t) { t.printStackTrace(); throw new IOException(MessageFormat.format(Messages.getString("ProxyUtil.failedToLookupIEProxies"), //$NON-NLS-1$ new Object[] { t.getMessage() })); } }
From source file:com.glaf.core.util.FtpUtils.java
/** * FTP/*from ww w . ja va 2s.c o m*/ * * @param remotePath * FTP"/" */ public static void deleteFile(String remotePath) { if (!remotePath.startsWith("/")) { throw new RuntimeException(" path must start with '/'"); } try { if (remotePath.indexOf("/") != -1) { String tmp = ""; List<String> dirs = new ArrayList<String>(); StringTokenizer token = new StringTokenizer(remotePath, "/"); while (token.hasMoreTokens()) { String str = token.nextToken(); tmp = tmp + "/" + str; dirs.add(tmp); } for (int i = 0; i < dirs.size() - 1; i++) { getFtpClient().changeWorkingDirectory(dirs.get(i)); } String dir = remotePath.substring(remotePath.lastIndexOf("/") + 1, remotePath.length()); logger.debug("rm " + dir); getFtpClient().deleteFile(dir); } else { getFtpClient().deleteFile(remotePath); } } catch (IOException ex) { ex.printStackTrace(); logger.error("deleteFile error", ex); throw new RuntimeException(ex); } }