Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2008-12-16 10:56:09 +0000
committerTomasz Zarna2008-12-16 10:56:09 +0000
commit3d485d841d265aed695b6c52dbe99a14e3bb62b4 (patch)
tree3db459fdb6f1641a41e0cc13427e2f35b6a97fb3 /bundles/org.eclipse.core.net/src
parentacfba0e6c65457d56b870dec762491edd440f7d5 (diff)
downloadeclipse.platform.team-3d485d841d265aed695b6c52dbe99a14e3bb62b4.tar.gz
eclipse.platform.team-3d485d841d265aed695b6c52dbe99a14e3bb62b4.tar.xz
eclipse.platform.team-3d485d841d265aed695b6c52dbe99a14e3bb62b4.zip
bug 255814: [Net] Wrong methods and types used in org.eclipse.core.net
Diffstat (limited to 'bundles/org.eclipse.core.net/src')
-rw-r--r--bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyType.java2
-rw-r--r--bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/StringUtil.java103
-rw-r--r--bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java3
-rw-r--r--bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/win32/winhttp/ProxyBypass.java30
-rw-r--r--bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/win32/winhttp/ProxyProviderUtil.java49
-rw-r--r--bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpCurrentUserIEProxyConfig.java6
6 files changed, 130 insertions, 63 deletions
diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyType.java b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyType.java
index ddd204456..eb2c7d187 100644
--- a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyType.java
+++ b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyType.java
@@ -99,7 +99,7 @@ public class ProxyType implements INodeChangeListener, IPreferenceChangeListener
}
public static String[] convertPropertyStringToHosts(String property) {
- String hosts[] = property.split("\\|"); //$NON-NLS-1$
+ String hosts[] = StringUtil.split(property, new String[] { "|" }); //$NON-NLS-1$
ArrayList ret = new ArrayList();
for (int i = 0; i < hosts.length; i++) {
if (hosts[i].length() != 0) {
diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/StringUtil.java b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/StringUtil.java
new file mode 100644
index 000000000..5746f2abd
--- /dev/null
+++ b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/StringUtil.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.internal.net;
+
+import java.util.ArrayList;
+
+public class StringUtil {
+
+ /**
+ * Splits a string into substrings using a delimiter array.
+ *
+ * @param value
+ * string to be tokenized
+ * @param delimiters
+ * array of delimiters
+ * @return array of tokens
+ */
+ public static String[] split(String value, String[] delimiters) {
+ ArrayList result = new ArrayList();
+ int firstIndex = 0;
+ int separator = 0;
+ while (firstIndex != -1) {
+ firstIndex = -1;
+ for (int i = 0; i < delimiters.length; i++) {
+ int index = value.indexOf(delimiters[i]);
+ if (index != -1 && (index < firstIndex || firstIndex == -1)) {
+ firstIndex = index;
+ separator = i;
+ }
+ }
+ if (firstIndex != -1) {
+ if (firstIndex != 0) {
+ result.add(value.substring(0, firstIndex));
+ }
+ int newStart = firstIndex + delimiters[separator].length();
+ if (newStart <= value.length()) {
+ value = value.substring(newStart);
+ }
+ } else if (value.length() > 0) {
+ result.add(value);
+ }
+ }
+ return (String[]) result.toArray(new String[0]);
+ }
+
+ /**
+ * Tests equality of the given strings.
+ *
+ * @param sequence1
+ * candidate 1, may be null
+ * @param sequence2
+ * candidate 2, may be null
+ * @return true if both sequences are null or the sequences are equal
+ */
+ public static final boolean equals(final CharSequence sequence1,
+ final CharSequence sequence2) {
+ if (sequence1 == sequence2) {
+ return true;
+ } else if (sequence1 == null || sequence2 == null) {
+ return false;
+ }
+ return sequence1.equals(sequence2);
+ }
+
+ /**
+ * Replace within <code>source</code> the occurrences of <code>from</code>
+ * with <code>to</code>.<br>
+ * <b>Note:</b> This has the same behavior as the
+ * <code>String.replace()</code> method within JDK 1.5.
+ *
+ * @param source
+ * @param from
+ * @param to
+ * @return the substituted string
+ */
+ public static String replace(String source, String from, String to) {
+ if (from.length() == 0)
+ return source;
+ StringBuffer buffer = new StringBuffer();
+ int current = 0;
+ int pos = 0;
+ while (pos != -1) {
+ pos = source.indexOf(from, current);
+ if (pos == -1) {
+ buffer.append(source.substring(current));
+ } else {
+ buffer.append(source.substring(current, pos));
+ buffer.append(to);
+ current = pos + from.length();
+ }
+ }
+ return buffer.toString();
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java
index af3838523..77642c15f 100644
--- a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java
+++ b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java
@@ -21,6 +21,7 @@ import org.eclipse.core.internal.net.AbstractProxyProvider;
import org.eclipse.core.internal.net.Activator;
import org.eclipse.core.internal.net.Policy;
import org.eclipse.core.internal.net.ProxyData;
+import org.eclipse.core.internal.net.StringUtil;
import org.eclipse.core.net.proxy.IProxyData;
public class UnixProxyProvider extends AbstractProxyProvider {
@@ -82,7 +83,7 @@ public class UnixProxyProvider extends AbstractProxyProvider {
// First try the environment variable which is a URL
String npEnv = getEnv("no_proxy"); //$NON-NLS-1$
if (npEnv != null) {
- npHosts = npEnv.split(","); //$NON-NLS-1$
+ npHosts = StringUtil.split(npEnv, new String[] { "," }); //$NON-NLS-1$
for (int i = 0; i < npHosts.length; i++)
npHosts[i] = npHosts[i].trim();
if (Policy.DEBUG_SYSTEM_PROVIDERS) {
diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/win32/winhttp/ProxyBypass.java b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/win32/winhttp/ProxyBypass.java
index 2d32b2442..796715129 100644
--- a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/win32/winhttp/ProxyBypass.java
+++ b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/win32/winhttp/ProxyBypass.java
@@ -12,7 +12,8 @@
package org.eclipse.core.internal.net.proxy.win32.winhttp;
import java.net.URI;
-import java.util.regex.Pattern;
+
+import org.eclipse.core.internal.net.StringUtil;
/**
* Encapsulates the windows specific proxy bypass list. It transforms the native
@@ -24,7 +25,7 @@ public class ProxyBypass {
private final String proxyBypass;
- private final Pattern proxyBypassPattern;
+ private final String proxyBypassEntries[];
private final static String BYPASS_LOCAL_ADDESSES_TOKEN = "<local>"; //$NON-NLS-1$
@@ -37,12 +38,10 @@ public class ProxyBypass {
this.proxyBypass = proxyBypass != null ? proxyBypass : ""; //$NON-NLS-1$
if (proxyBypass != null) {
- String regExp = ProxyProviderUtil.replace(proxyBypass, ";", "|"); //$NON-NLS-1$ //$NON-NLS-2$
- regExp = ProxyProviderUtil.replace(regExp, ".", "\\."); //$NON-NLS-1$ //$NON-NLS-2$
- regExp = ProxyProviderUtil.replace(regExp, "*", ".*"); //$NON-NLS-1$ //$NON-NLS-2$
- this.proxyBypassPattern = Pattern.compile(regExp);
+ proxyBypassEntries = StringUtil.split(proxyBypass, new String[] {
+ ";", "|" }); //$NON-NLS-1$ //$NON-NLS-2$
} else {
- this.proxyBypassPattern = Pattern.compile(""); //$NON-NLS-1$
+ proxyBypassEntries = new String[0];
}
}
@@ -66,7 +65,18 @@ public class ProxyBypass {
* @return
*/
private boolean isInBypassList(String host) {
- return proxyBypassPattern.matcher(host).matches();
+ for (int i = 0; i < proxyBypassEntries.length; i++) {
+ String entry = proxyBypassEntries[i];
+ if (entry.endsWith("*")) { //$NON-NLS-1$
+ if (host.toLowerCase().startsWith(
+ entry.substring(0, entry.length() - 1).toLowerCase())) {
+ return true;
+ }
+ } else if (host.equalsIgnoreCase(entry)) {
+ return true;
+ }
+ }
+ return false;
}
/**
@@ -86,8 +96,8 @@ public class ProxyBypass {
}
public String[] getNonProxiedHosts() {
- String ret = ProxyProviderUtil.replace(proxyBypass, "|", ";"); //$NON-NLS-1$ //$NON-NLS-2$
- return ret.split(";"); //$NON-NLS-1$
+ String ret = StringUtil.replace(proxyBypass, "|", ";"); //$NON-NLS-1$ //$NON-NLS-2$
+ return StringUtil.split(ret, new String[] { ";" }); //$NON-NLS-1$
}
}
diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/win32/winhttp/ProxyProviderUtil.java b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/win32/winhttp/ProxyProviderUtil.java
index 9a98c6f92..17e711d52 100644
--- a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/win32/winhttp/ProxyProviderUtil.java
+++ b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/win32/winhttp/ProxyProviderUtil.java
@@ -254,53 +254,4 @@ public final class ProxyProviderUtil {
.indexOf(':') + 1)) : 0;
}
- /**
- * Tests equality of the given strings.
- *
- * @param sequence1
- * candidate 1, may be null
- * @param sequence2
- * candidate 2, may be null
- * @return true if both sequences are null or the sequences are equal
- */
- public static final boolean equals(final CharSequence sequence1,
- final CharSequence sequence2) {
- if (sequence1 == sequence2)
- return true;
- else if (sequence1 == null || sequence2 == null)
- return false;
- else
- return sequence1.equals(sequence2);
- }
-
- /**
- * Replace within <code>source</code> the occurrences of <code>from</code>
- * with <code>to</code>.<br>
- * <b>Note:</b> This has the same behavior as the
- * <code>String.replace()</code> method within JDK 1.5.
- *
- * @param source
- * @param from
- * @param to
- * @return the substituted string
- */
- public static String replace(String source, String from, String to) {
- if (from.length() == 0)
- return source;
- StringBuffer buffer = new StringBuffer();
- int current = 0;
- int pos = 0;
- while (pos != -1) {
- pos = source.indexOf(from, current);
- if (pos == -1) {
- buffer.append(source.substring(current));
- } else {
- buffer.append(source.substring(current, pos));
- buffer.append(to);
- current = pos + from.length();
- }
- }
- return buffer.toString();
- }
-
}
diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpCurrentUserIEProxyConfig.java b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpCurrentUserIEProxyConfig.java
index 91e679bfa..70a77a153 100644
--- a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpCurrentUserIEProxyConfig.java
+++ b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/win32/winhttp/WinHttpCurrentUserIEProxyConfig.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.core.internal.net.proxy.win32.winhttp;
+import org.eclipse.core.internal.net.StringUtil;
+
/**
* Wrapper for Win32 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG structure.<br>
* Plus a few helper methods that enrich the plain C structure.
@@ -96,7 +98,7 @@ public class WinHttpCurrentUserIEProxyConfig {
WinHttpCurrentUserIEProxyConfig proxyConfig) {
if (proxyConfig == null)
return true;
- return !ProxyProviderUtil.equals(autoConfigUrl,
+ return !StringUtil.equals(autoConfigUrl,
proxyConfig.autoConfigUrl);
}
@@ -111,7 +113,7 @@ public class WinHttpCurrentUserIEProxyConfig {
WinHttpCurrentUserIEProxyConfig proxyConfig) {
if (proxyConfig == null)
return true;
- return !(ProxyProviderUtil.equals(proxy, proxyConfig.proxy) && ProxyProviderUtil
+ return !(StringUtil.equals(proxy, proxyConfig.proxy) && StringUtil
.equals(proxyBypass, proxyConfig.proxyBypass));
}

Back to the top