mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
CR-IC-3246
This commit is contained in:
@@ -3,8 +3,6 @@ package com.intellij.util;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
// We don't use Java URI due to problem — http://cns-etuat-2.localnet.englishtown.com/school/e12/#school/45383/201/221/382?c=countrycode=cc|culturecode=en-us|partnercode=mkge
|
||||
// it is illegal URI (fragment before query), but we must support such URI
|
||||
// Semicolon as parameters separator is supported (WEB-6671)
|
||||
@@ -14,14 +12,11 @@ public interface Url {
|
||||
|
||||
boolean isInLocalFileSystem();
|
||||
|
||||
String toDecodedForm(boolean skipQueryAndFragment);
|
||||
String toDecodedForm();
|
||||
|
||||
@NotNull
|
||||
String toExternalForm();
|
||||
|
||||
@NotNull
|
||||
String toExternalForm(boolean skipQueryAndFragment);
|
||||
|
||||
@Nullable
|
||||
String getScheme();
|
||||
|
||||
@@ -34,5 +29,5 @@ public interface Url {
|
||||
boolean equalsIgnoreParameters(@Nullable Url url);
|
||||
|
||||
@NotNull
|
||||
URI toJavaUriWithoutParameters();
|
||||
Url trimParameters();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package com.intellij.util;
|
||||
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public final class LocalFileUrl implements Url {
|
||||
private final String path;
|
||||
|
||||
@@ -26,7 +22,7 @@ public final class LocalFileUrl implements Url {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDecodedForm(boolean skipQueryAndFragment) {
|
||||
public String toDecodedForm() {
|
||||
return path;
|
||||
}
|
||||
|
||||
@@ -36,27 +32,6 @@ public final class LocalFileUrl implements Url {
|
||||
return path;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public URI toJavaUriWithoutParameters() {
|
||||
try {
|
||||
String externalPath = path;
|
||||
if (SystemInfo.isWindows && externalPath.charAt(0) != '/') {
|
||||
externalPath = '/' + externalPath;
|
||||
}
|
||||
return new URI("file", "", externalPath, null, null);
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toExternalForm(boolean skipQueryAndFragment) {
|
||||
return toExternalForm();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getScheme() {
|
||||
@@ -75,15 +50,23 @@ public final class LocalFileUrl implements Url {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Url trimParameters() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toExternalForm();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof LocalFileUrl)) {
|
||||
return false;
|
||||
}
|
||||
return path.equals(((LocalFileUrl)o).path);
|
||||
return o instanceof LocalFileUrl && path.equals(((LocalFileUrl)o).path);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,9 +78,4 @@ public final class LocalFileUrl implements Url {
|
||||
public int hashCode() {
|
||||
return path.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toExternalForm();
|
||||
}
|
||||
}
|
||||
@@ -15,18 +15,15 @@
|
||||
*/
|
||||
package com.intellij.util;
|
||||
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.StandardFileSystems;
|
||||
import com.intellij.util.io.URLUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public final class UrlImpl implements Url {
|
||||
private String externalForm;
|
||||
private UrlImpl withoutParameters;
|
||||
|
||||
@Nullable
|
||||
private final String scheme;
|
||||
@@ -38,8 +35,6 @@ public final class UrlImpl implements Url {
|
||||
|
||||
private final String parameters;
|
||||
|
||||
private String externalFormWithoutParameters;
|
||||
|
||||
public UrlImpl(@Nullable String path) {
|
||||
this(null, null, path, null);
|
||||
}
|
||||
@@ -88,7 +83,7 @@ public final class UrlImpl implements Url {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDecodedForm(boolean skipQueryAndFragment) {
|
||||
public String toDecodedForm() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (scheme != null) {
|
||||
builder.append(scheme).append("://");
|
||||
@@ -97,7 +92,7 @@ public final class UrlImpl implements Url {
|
||||
builder.append(authority);
|
||||
}
|
||||
builder.append(getPath());
|
||||
if (!skipQueryAndFragment && parameters != null) {
|
||||
if (parameters != null) {
|
||||
builder.append(parameters);
|
||||
}
|
||||
return builder.toString();
|
||||
@@ -105,57 +100,34 @@ public final class UrlImpl implements Url {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public URI toJavaUriWithoutParameters() {
|
||||
try {
|
||||
String externalPath = path;
|
||||
boolean inLocalFileSystem = isInLocalFileSystem();
|
||||
if (inLocalFileSystem && SystemInfo.isWindows && externalPath.charAt(0) != '/') {
|
||||
externalPath = '/' + externalPath;
|
||||
}
|
||||
return new URI(scheme, inLocalFileSystem ? "" : authority, externalPath, null, null);
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toExternalForm(boolean skipQueryAndFragment) {
|
||||
if (parameters == null || !skipQueryAndFragment) {
|
||||
if (externalForm != null) {
|
||||
return externalForm;
|
||||
}
|
||||
}
|
||||
else if (externalFormWithoutParameters != null) {
|
||||
return externalFormWithoutParameters;
|
||||
public String toExternalForm() {
|
||||
if (externalForm != null) {
|
||||
return externalForm;
|
||||
}
|
||||
|
||||
String result = toJavaUriWithoutParameters().toASCIIString();
|
||||
if (skipQueryAndFragment) {
|
||||
externalFormWithoutParameters = result;
|
||||
if (parameters == null) {
|
||||
externalForm = externalFormWithoutParameters;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (parameters != null) {
|
||||
result += parameters;
|
||||
}
|
||||
externalForm = result;
|
||||
String result = Urls.toUriWithoutParameters(this).toASCIIString();
|
||||
if (parameters != null) {
|
||||
result += parameters;
|
||||
}
|
||||
externalForm = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toExternalForm() {
|
||||
return toExternalForm(false);
|
||||
@NotNull
|
||||
public Url trimParameters() {
|
||||
if (parameters == null) {
|
||||
return this;
|
||||
}
|
||||
else if (withoutParameters == null) {
|
||||
withoutParameters = new UrlImpl(scheme, authority, path, null);
|
||||
}
|
||||
return withoutParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toExternalForm(false);
|
||||
return toExternalForm();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -164,21 +136,11 @@ public final class UrlImpl implements Url {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof UrlImpl)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UrlImpl url = (UrlImpl)o;
|
||||
return equalsIgnoreParameters(url) && (parameters == null ? url.parameters == null : parameters.equals(url.parameters));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsIgnoreParameters(@Nullable Url o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof UrlImpl)) {
|
||||
if (o instanceof LocalFileUrl && isInLocalFileSystem()) {
|
||||
return o.getPath().equals(path);
|
||||
if (o instanceof Url && isInLocalFileSystem()) {
|
||||
Url url = (Url)o;
|
||||
if (url.isInLocalFileSystem()) {
|
||||
return url.getPath().equals(path);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -190,11 +152,15 @@ public final class UrlImpl implements Url {
|
||||
if (authority == null ? url.authority != null : !authority.equals(url.authority)) {
|
||||
return false;
|
||||
}
|
||||
String decodedPath = getPath();
|
||||
if (!decodedPath.equals(url.getPath())) {
|
||||
if (!getPath().equals(url.getPath())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return parameters == null ? url.parameters == null : parameters.equals(url.parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsIgnoreParameters(@Nullable Url url) {
|
||||
return url != null && equals(url.trimParameters());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.util;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.StandardFileSystems;
|
||||
@@ -26,6 +27,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -77,7 +79,7 @@ public final class Urls {
|
||||
}
|
||||
|
||||
try {
|
||||
return asUrl.toJavaUriWithoutParameters();
|
||||
return toUriWithoutParameters(asUrl);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.info("Can't parse " + url, e);
|
||||
@@ -141,4 +143,19 @@ public final class Urls {
|
||||
Url fileUrl = parseUrl(file.getUrl());
|
||||
return fileUrl != null && fileUrl.equalsIgnoreParameters(url);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static URI toUriWithoutParameters(@NotNull Url url) {
|
||||
try {
|
||||
String externalPath = url.getPath();
|
||||
boolean inLocalFileSystem = url.isInLocalFileSystem();
|
||||
if (inLocalFileSystem && SystemInfo.isWindows && externalPath.charAt(0) != '/') {
|
||||
externalPath = '/' + externalPath;
|
||||
}
|
||||
return new URI(inLocalFileSystem ? "file" : url.getScheme(), inLocalFileSystem ? "" : url.getAuthority(), externalPath, null, null);
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,7 +149,7 @@ public class OpenFileInDefaultBrowserAction extends DumbAwareAction {
|
||||
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
|
||||
// todo icons looks good, but is it really suitable for all URLs providers?
|
||||
setIcon(AllIcons.Nodes.Servlet);
|
||||
append(((Url)value).toDecodedForm(false));
|
||||
append(((Url)value).toDecodedForm());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ public class StartBrowserPanel {
|
||||
@NotNull
|
||||
@Override
|
||||
protected String chosenFileToResultingText(@NotNull VirtualFile chosenFile) {
|
||||
return virtualFileToUrl(chosenFile, project).toDecodedForm(false);
|
||||
return virtualFileToUrl(chosenFile, project).toDecodedForm();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user