mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
WEB-2091
This commit is contained in:
@@ -42,6 +42,8 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.*;
|
||||
@@ -497,6 +499,26 @@ public class VfsUtil extends VfsUtilCore {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return correct URI, must be used only for external communication
|
||||
*/
|
||||
@NotNull
|
||||
public static URI toUri(@NotNull VirtualFile file) {
|
||||
String path = file.getPath();
|
||||
try {
|
||||
if (file.isInLocalFileSystem()) {
|
||||
if (SystemInfo.isWindows && path.charAt(0) != '/') {
|
||||
path = '/' + path;
|
||||
}
|
||||
return new URI(file.getFileSystem().getProtocol(), "", path, null, null);
|
||||
}
|
||||
return new URI(file.getFileSystem().getProtocol(), path, null);
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the relative path from one virtual file to another.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,6 +18,7 @@ package com.intellij.ide.browsers.impl;
|
||||
import com.intellij.ide.browsers.WebBrowserService;
|
||||
import com.intellij.ide.browsers.WebBrowserUrlProvider;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.impl.http.HttpVirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -47,32 +48,28 @@ public class WebBrowserServiceImpl extends WebBrowserService {
|
||||
if (psiFile == null) {
|
||||
return null;
|
||||
}
|
||||
final VirtualFile virtualFile = psiFile.getVirtualFile();
|
||||
VirtualFile virtualFile = psiFile.getVirtualFile();
|
||||
if (virtualFile == null) {
|
||||
return null;
|
||||
}
|
||||
final String localUrl = virtualFile.getUrl();
|
||||
if (virtualFile instanceof HttpVirtualFile) {
|
||||
return localUrl;
|
||||
return virtualFile.getUrl();
|
||||
}
|
||||
|
||||
if (preferLocalUrl && HtmlUtil.isHtmlFile(psiFile)) {
|
||||
return localUrl;
|
||||
}
|
||||
|
||||
final WebBrowserUrlProvider provider = getProvider(psiElement);
|
||||
if (provider == null) {
|
||||
return localUrl;
|
||||
}
|
||||
try {
|
||||
return provider.getUrl(psiElement);
|
||||
}
|
||||
catch (WebBrowserUrlProvider.BrowserException e) {
|
||||
if (HtmlUtil.isHtmlFile(psiFile)) {
|
||||
return localUrl;
|
||||
if (!(preferLocalUrl && HtmlUtil.isHtmlFile(psiFile))) {
|
||||
WebBrowserUrlProvider provider = getProvider(psiElement);
|
||||
if (provider != null) {
|
||||
try {
|
||||
return provider.getUrl(psiElement, psiFile, virtualFile);
|
||||
}
|
||||
catch (WebBrowserUrlProvider.BrowserException e) {
|
||||
if (!HtmlUtil.isHtmlFile(psiFile)) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return VfsUtil.toUri(virtualFile).toASCIIString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -591,17 +591,12 @@ public class HtmlUtil {
|
||||
}
|
||||
|
||||
public static boolean hasHtml(PsiFile file) {
|
||||
if (isHtmlFile(file)) return true;
|
||||
if (file.getViewProvider() instanceof TemplateLanguageFileViewProvider) return true;
|
||||
return false;
|
||||
return isHtmlFile(file) || file.getViewProvider() instanceof TemplateLanguageFileViewProvider;
|
||||
}
|
||||
|
||||
public static boolean isHtmlFile(final PsiFile file) {
|
||||
final Language language = file.getLanguage();
|
||||
if (language == HTMLLanguage.INSTANCE || language == XHTMLLanguage.INSTANCE) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return language == HTMLLanguage.INSTANCE || language == XHTMLLanguage.INSTANCE;
|
||||
}
|
||||
|
||||
public static boolean isHtmlTagContainingFile(PsiElement element) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.ide.browsers;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -37,27 +38,17 @@ public abstract class WebBrowserUrlProvider {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invariant: element has not null containing psi file with not null virtual file
|
||||
* Invariant: element has not null containing psi file with not null virtual file
|
||||
* @deprecated
|
||||
*/
|
||||
@NotNull
|
||||
public String getUrl(@NotNull PsiElement element) throws BrowserException {
|
||||
try {
|
||||
return getUrl(element, false);
|
||||
}
|
||||
catch (BrowserException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated override {@link #getUrl(com.intellij.psi.PsiElement)} instead
|
||||
*/
|
||||
@NotNull
|
||||
public String getUrl(@NotNull PsiElement element, boolean shiftDown) throws Exception {
|
||||
throw new UnsupportedOperationException();
|
||||
public String getUrl(@NotNull PsiElement element, @NotNull PsiFile psiFile, @NotNull VirtualFile virtualFile) throws BrowserException {
|
||||
return getUrl(element);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user