com.intellij.util.Url Java Examples
The following examples show how to use
com.intellij.util.Url.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GaugeWebBrowserPreview.java From Intellij-Plugin with Apache License 2.0 | 6 votes |
@Nullable private Url previewUrl(OpenInBrowserRequest request, VirtualFile virtualFile, GaugeSettingsModel settings) throws IOException, InterruptedException { ProcessBuilder builder = new ProcessBuilder(settings.getGaugePath(), Constants.DOCS, Spectacle.NAME, virtualFile.getPath()); String projectName = request.getProject().getName(); builder.environment().put("spectacle_out_dir", FileUtil.join(createOrGetTempDirectory(projectName).getPath(), "docs")); File gaugeModuleDir = GaugeUtil.moduleDir(GaugeUtil.moduleForPsiElement(request.getFile())); builder.directory(gaugeModuleDir); GaugeUtil.setGaugeEnvironmentsTo(builder, settings); Process docsProcess = builder.start(); int exitCode = docsProcess.waitFor(); if (exitCode != 0) { String docsOutput = String.format("<pre>%s</pre>", GaugeUtil.getOutput(docsProcess.getInputStream(), " ").replace("<", "<").replace(">", ">")); Notifications.Bus.notify(new Notification("Specification Preview", "Error: Specification Preview", docsOutput, NotificationType.ERROR)); return null; } String relativePath = FileUtil.getRelativePath(gaugeModuleDir, new File(virtualFile.getParent().getPath())); return new UrlImpl(FileUtil.join(createOrGetTempDirectory(projectName).getPath(), "docs", "html", relativePath, virtualFile.getNameWithoutExtension() + ".html")); }
Example #2
Source File: HttpRequestUtil.java From consulo with Apache License 2.0 | 6 votes |
public static boolean parseAndCheckIsLocalHost(String uri, boolean onlyAnyOrLoopback, boolean hostsOnly) { if (uri == null || uri.equals("about:blank")) { return true; } try { Url parsedUri = Urls.parse(uri, false); if (parsedUri == null) { return false; } String host = getHost(parsedUri); return host != null && (isTrustedChromeExtension(parsedUri) || isLocalHost(host, onlyAnyOrLoopback, hostsOnly)); } catch (Exception ignored) { } return false; }
Example #3
Source File: QuarkusModelRegistry.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
public static void zip(String endpoint, String tool, String groupId, String artifactId, String version, String className, String path, QuarkusModel model, File output) throws IOException { Url url = Urls.newFromEncoded(endpoint + "/api/download"); Map<String, String> parameters = new HashMap<>(); parameters.put(CODE_TOOL_PARAMETER_NAME, tool); parameters.put(CODE_GROUP_ID_PARAMETER_NAME, groupId); parameters.put(CODE_ARTIFACT_ID_PARAMETER_NAME, artifactId); parameters.put(CODE_VERSION_PARAMETER_NAME, version); parameters.put(CODE_CLASSNAME_PARAMETER_NAME, className); parameters.put(CODE_PATH_PARAMETER_NAME, path); parameters.put(CODE_EXTENSIONS_SHORT_PARAMETER_NAME, model.getCategories().stream().flatMap(category -> category.getExtensions().stream()). filter(extension -> extension.isSelected() || extension.isDefaultExtension()). map(extension -> extension.getShortId()). collect(Collectors.joining("."))); url = url.addParameters(parameters); RequestBuilder builder = HttpRequests.request(url.toString()).userAgent(QuarkusModelRegistry.USER_AGENT).tuner(connection -> { connection.setRequestProperty(CODE_QUARKUS_IO_CLIENT_NAME_HEADER_NAME, CODE_QUARKUS_IO_CLIENT_NAME_HEADER_VALUE); connection.setRequestProperty(CODE_QUARKUS_IO_CLIENT_CONTACT_EMAIL_HEADER_NAME, CODE_QUARKUS_IO_CLIENT_CONTACT_EMAIL_HEADER_VALUE); }); try { if (ApplicationManager.getApplication().executeOnPooledThread(() -> builder.connect(request -> { ZipUtil.unpack(request.getInputStream(), output, name -> { int index = name.indexOf('/'); return name.substring(index); }); return true; })).get() == null) { throw new IOException(); } } catch (InterruptedException | ExecutionException e) { throw new IOException(e); } }
Example #4
Source File: FlutterSdkUtil.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
@VisibleForTesting public static String parseFlutterSdkPath(String packagesFileContent) { for (String line : packagesFileContent.split("\n")) { // flutter:file:///Users/.../flutter/packages/flutter/lib/ line = line.trim(); if (line.isEmpty() || line.startsWith("#")) { continue; } final String flutterPrefix = "flutter:"; if (line.startsWith(flutterPrefix)) { final String urlString = line.substring(flutterPrefix.length()); if (urlString.startsWith("file:")) { final Url url = Urls.parseEncoded(urlString); if (url == null) { continue; } final String path = url.getPath(); // go up three levels final File file = new File(url.getPath()); return file.getParentFile().getParentFile().getParentFile().getPath(); } } } return null; }
Example #5
Source File: FlutterSdkUtil.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
@VisibleForTesting public static String parseFlutterSdkPath(String packagesFileContent) { for (String line : packagesFileContent.split("\n")) { // flutter:file:///Users/.../flutter/packages/flutter/lib/ line = line.trim(); if (line.isEmpty() || line.startsWith("#")) { continue; } final String flutterPrefix = "flutter:"; if (line.startsWith(flutterPrefix)) { final String urlString = line.substring(flutterPrefix.length()); if (urlString.startsWith("file:")) { final Url url = Urls.parseEncoded(urlString); if (url == null) { continue; } final String path = url.getPath(); // go up three levels final File file = new File(url.getPath()); return file.getParentFile().getParentFile().getParentFile().getPath(); } } } return null; }
Example #6
Source File: SwaggerUiUrlProvider.java From intellij-swagger with MIT License | 5 votes |
@Nullable @Override protected Url getUrl(@NotNull OpenInBrowserRequest request, @NotNull VirtualFile file) { SwaggerFileService swaggerFileService = ServiceManager.getService(SwaggerFileService.class); Optional<Path> swaggerHTMLFolder = swaggerFileService.convertSwaggerToHtml(request.getVirtualFile()); return swaggerHTMLFolder.map(SwaggerFilesUtils::convertSwaggerLocationToUrl).orElse(null); }
Example #7
Source File: SwaggerFilesUtilsTest.java From intellij-swagger with MIT License | 5 votes |
@Test public void test() throws IOException { Path path = Files.createTempDirectory(""); Url url = SwaggerFilesUtils.convertSwaggerLocationToUrl(path); Assert.assertEquals(url.getPath(), path.toString() + File.separator + "index.html"); }
Example #8
Source File: GaugeWebBrowserPreview.java From Intellij-Plugin with Apache License 2.0 | 5 votes |
@Nullable @Override protected Url getUrl(OpenInBrowserRequest request, VirtualFile virtualFile) throws BrowserException { try { if (!request.isAppendAccessToken()) return null; GaugeSettingsModel settings = getGaugeSettings(); Spectacle spectacle = new Spectacle(request.getProject(), settings); if (spectacle.isInstalled()) return previewUrl(request, virtualFile, settings); spectacle.notifyToInstall(); } catch (Exception e) { Messages.showWarningDialog(String.format("Unable to create html file for %s", virtualFile.getName()), "Error"); } return null; }
Example #9
Source File: BuiltInServerManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public Url addAuthToken(@Nonnull Url url) { if (url.getParameters() != null) { // built-in server url contains query only if token specified return url; } return new UrlImpl(url.getScheme(), url.getAuthority(), url.getPath(), "?" + BuiltInWebServerKt.TOKEN_PARAM_NAME + "=" + BuiltInWebServerKt.acquireToken()); }
Example #10
Source File: HttpRequestUtil.java From consulo with Apache License 2.0 | 5 votes |
private static String getHost(Url uri) { String authority = uri.getAuthority(); if (authority != null) { int portIndex = authority.indexOf(':'); if (portIndex > 0) { return authority.substring(0, portIndex); } else { return authority; } } return null; }
Example #11
Source File: HttpRequestUtil.java From consulo with Apache License 2.0 | 5 votes |
private static boolean isTrustedChromeExtension(Url url) { /* FIXME [VISTALL] this is only jetbrains plugins return Comparing.equal(url.getScheme(), "chrome-extension") && (Comparing.equal(url.getAuthority(), "hmhgeddbohgjknpmjagkdomcpobmllji") || Comparing .equal(url.getAuthority(), "offnedcbhjldheanlbojaefbfbllddna")); */ return false; }
Example #12
Source File: HttpRequests.java From leetcode-editor with Apache License 2.0 | 4 votes |
@NotNull public static RequestBuilder request(@NotNull Url url) { return request(url.toExternalForm()); }
Example #13
Source File: SwaggerFilesUtils.java From intellij-swagger with MIT License | 4 votes |
public static Url convertSwaggerLocationToUrl(@NotNull final Path swaggerHtmlDirectory) { return new LocalFileUrl(swaggerHtmlDirectory.toString() + File.separator + "index.html"); }
Example #14
Source File: BuiltInServerManagerImpl.java From consulo with Apache License 2.0 | 4 votes |
@Override public boolean isOnBuiltInWebServer(@Nullable Url url) { return url != null && !StringUtil.isEmpty(url.getAuthority()) && isOnBuiltInWebServerByAuthority(url.getAuthority()); }
Example #15
Source File: BuiltInServerManager.java From consulo with Apache License 2.0 | votes |
public abstract boolean isOnBuiltInWebServer(@Nullable Url url);
Example #16
Source File: BuiltInServerManager.java From consulo with Apache License 2.0 | votes |
public abstract Url addAuthToken(@Nonnull Url url);