List of usage examples for java.net URL toExternalForm
public String toExternalForm()
From source file:autoupdater.DownloadLatestZipFromRepo.java
/** * Retrieves the latest version of a maven jar file from a maven repository. * * @param downloadFolder the folder to download to * @param groupId the group id * @param artifactId the artifact id * @param iconName name of the shortcut image should one be created * @param args the args that will be passed to the newly downloaded program * when started, cannot be {@code null} * @param jarRepository the maven repository to go look in, cannot be * {@code null} * @param startDownloadedVersion if the newly downloaded version should be * started automatically or not * @param addDesktopIcon if true, a desktop icon will be created * @param fileDAO what implementation of FileDAO should be used in the * updating * @throws IOException should there be problems with reading or writing * files during the updating * @throws XMLStreamException if there was a problem reading the meta data * from the remote maven repository * @throws URISyntaxException//from w ww . j a v a2s .c om */ public static void downloadLatestZipFromRepo(final File downloadFolder, String groupId, String artifactId, String iconName, String[] args, URL jarRepository, boolean startDownloadedVersion, boolean addDesktopIcon, FileDAO fileDAO) throws IOException, XMLStreamException, URISyntaxException { //TL;DR of the next three lines: make the url for the latest version location of a maven jar file String artifactInRepoLocation = new StringBuilder(jarRepository.toExternalForm()) .append(groupId.replaceAll("\\.", "/")).append("/").append(artifactId).toString(); String latestRemoteRelease = WebDAO.getLatestVersionNumberFromRemoteRepo( new URL(new StringBuilder(artifactInRepoLocation).append("/maven-metadata.xml").toString())); String latestArtifactLocation = new StringBuilder(artifactInRepoLocation).append("/") .append(latestRemoteRelease).toString(); // download and unzip the files MavenJarFile downloadedJarFile = downloadAndUnzipJar(downloadFolder, artifactId, new URL(latestArtifactLocation), fileDAO, true, false); final File jarParent = downloadFolder; // add desktop icon if (addDesktopIcon) { fileDAO.createDesktopShortcut(downloadedJarFile, artifactId, iconName, false); } if (startDownloadedVersion) { launchJar(downloadedJarFile, args); } }
From source file:tr.com.turkcellteknoloji.turkcellupdater.UpdaterDialogManager.java
private static void openWebPage(Context context, URL url) { try {/*from w w w . j a v a 2 s . co m*/ context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url.toExternalForm()))); } catch (Exception e) { Log.e("open web page failed", e); } }
From source file:com.gargoylesoftware.htmlunit.WebTestCase.java
/** * Facility to test external form of urls. Comparing external form of URLs is * really faster than URL.equals() as the host doesn't need to be resolved. * @param expectedUrl the expected URL/*from w ww.j a va 2 s. c o m*/ * @param actualUrl the URL to test */ protected static void assertEquals(final URL expectedUrl, final URL actualUrl) { Assert.assertEquals(expectedUrl.toExternalForm(), actualUrl.toExternalForm()); }
From source file:UrlUtils.java
/** * Resolves a given relative URL against a base URL. See * <a href="http://www.faqs.org/rfcs/rfc1808.html">RFC1808</a> * Section 4 for more details.//from w ww .ja v a 2 s . c o m * * @param baseUrl The base URL in which to resolve the specification. * @param relativeUrl The relative URL to resolve against the base URL. * @return the resolved specification. */ public static String resolveUrl(final URL baseUrl, final String relativeUrl) { if (baseUrl == null) { throw new IllegalArgumentException("Base URL must not be null"); } return resolveUrl(baseUrl.toExternalForm(), relativeUrl); }
From source file:WarUtil.java
public static URL createURL(final URL baseURL, String relativeURL) { try {//from w w w. java 2s .c o m String protocol = baseURL.getProtocol(); relativeURL = relativeURL.replace("\\", SLASH); // TODO if (protocol.startsWith(FILE_PROTOCOL)) { if (relativeURL.startsWith(SLASH)) { relativeURL = relativeURL.substring(1, relativeURL.length()); } return new URL(baseURL, relativeURL); } else { // TODO String baseArchivePath = baseURL.toExternalForm(); if (baseArchivePath.endsWith(SLASH)) { baseArchivePath = baseArchivePath.substring(0, baseArchivePath.length() - 1); } if (baseArchivePath.endsWith("!")) { baseArchivePath = baseArchivePath.substring(0, baseArchivePath.length() - 1); } if (!relativeURL.startsWith(SLASH)) { relativeURL = SLASH + relativeURL; } return new URL(baseArchivePath + "!" + relativeURL); } } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:de.betterform.agent.web.WebFactory.java
/** * get the absolute file path for a given relative path in the webapp. Handles some differences in server behavior * with the execution of context.getRealPath on various servers/operating systems * * @param path a path relative to the context root of the webapp * @param context the servletcontext//from w w w . j av a 2s . c o m * @return the absolute file path for given relative webapp path */ public static String getRealPath(String path, ServletContext context) throws XFormsConfigException { if (path == null) { path = "/"; } if (!path.startsWith("/")) { path = "/" + path; } try { URI resourceURI = null; String computedRealPath = null; URL rootURL = Thread.currentThread().getContextClassLoader().getResource("/"); URL resourceURL = context.getResource(path); if (rootURL != null) { resourceURI = rootURL.toURI(); } if (resourceURI != null && resourceURI.getScheme().equalsIgnoreCase("file")) { String resourcePath = rootURL.getPath(); String rootPath = new File(resourcePath).getParentFile().getParent(); computedRealPath = new File(rootPath, path).getAbsolutePath(); } else if (resourceURL != null) { computedRealPath = new File(resourceURL.toExternalForm(), path).getAbsolutePath(); } else { String resourcePath = context.getRealPath("/"); computedRealPath = new File(resourcePath, path).getAbsolutePath(); } return java.net.URLDecoder.decode(computedRealPath, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new XFormsConfigException("path could not be resolved: " + path, e); } catch (URISyntaxException e) { throw new XFormsConfigException("path could not be resolved: " + path, e); } catch (MalformedURLException e) { throw new XFormsConfigException("path could not be resolved: " + path, e); } }
From source file:com.thoughtmetric.tl.TLLib.java
public static TagNode TagNodeFromURLEx2(HtmlCleaner cleaner, URL url, Handler handler, Context context, String fullTag, boolean login) throws IOException { handler.sendEmptyMessage(PROGRESS_CONNECTING); DefaultHttpClient httpclient = new DefaultHttpClient(); if (login) {//from w ww . j a va2 s . c o m httpclient.setCookieStore(cookieStore); } HttpGet httpGet = new HttpGet(url.toExternalForm()); HttpResponse response = httpclient.execute(httpGet); handler.sendEmptyMessage(PROGRESS_DOWNLOADING); HttpEntity httpEntity = response.getEntity(); InputStream is = httpEntity.getContent(); return TagNodeFromURLHelper(is, fullTag, handler, context, cleaner); }
From source file:com.jaeksoft.searchlib.crawler.web.spider.Crawl.java
final private static void addDiscoverLink(UrlManager urlManager, PatternManager inclusionManager, PatternManager exclusionManager, String href, Origin origin, String parentUrl, URL currentURL, UrlFilterItem[] urlFilterList, List<LinkItem> newUrlList) { if (href == null) return;//w w w. jav a2 s. co m try { URL url = currentURL != null ? LinkUtils.getLink(currentURL, href, urlFilterList, false) : LinkUtils.newEncodedURL(href); if (exclusionManager != null) if (exclusionManager.matchPattern(url)) return; if (inclusionManager != null) if (!inclusionManager.matchPattern(url)) return; newUrlList.add(new LinkItem(url.toExternalForm(), origin, parentUrl)); } catch (MalformedURLException e) { Logging.warn(href + " " + e.getMessage(), e); } catch (URISyntaxException e) { Logging.warn(href + " " + e.getMessage(), e); } }
From source file:com.thoughtmetric.tl.TLLib.java
public static Object[] tagNodeWithEditText(HtmlCleaner cleaner, URL url, Handler handler, Context context, String fullTag, boolean login) throws IOException { Object[] ret = new Object[2]; handler.sendEmptyMessage(PROGRESS_CONNECTING); DefaultHttpClient httpclient = new DefaultHttpClient(); if (login) {/*from w w w . j a v a2 s . c om*/ httpclient.setCookieStore(cookieStore); } HttpGet httpGet = new HttpGet(url.toExternalForm()); HttpResponse response = httpclient.execute(httpGet); handler.sendEmptyMessage(PROGRESS_DOWNLOADING); InputStream is = response.getEntity().getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(context.openFileInput(TEMP_FILE_NAME))); ret[0] = TagNodeFromURLHelper(is, fullTag, handler, context, cleaner); ret[1] = parseTextArea(br); return ret; }
From source file:com.aurel.track.util.PropertiesConfigurationHelper.java
/** * Gets the PropertiesConfiguration for a property file from servlet context * @param servletContext/*from ww w .j av a2 s. c o m*/ * @param pathWithinContext * @param propFile * @return * @throws ServletException */ public static PropertiesConfiguration loadServletContextPropFile(ServletContext servletContext, String pathWithinContext, String propFile) throws ServletException { PropertiesConfiguration propertiesConfiguration = null; InputStream in = null; URL propFileURL = null; try { if (servletContext != null && pathWithinContext != null) { if (!pathWithinContext.startsWith("/")) { pathWithinContext = "/" + pathWithinContext; } if (!pathWithinContext.endsWith("/")) { pathWithinContext = pathWithinContext + "/"; } propFileURL = servletContext.getResource(pathWithinContext + propFile); in = propFileURL.openStream(); propertiesConfiguration = new PropertiesConfiguration(); propertiesConfiguration.load(in); in.close(); } } catch (Exception e) { LOGGER.error("Could not read " + propFile + " from servlet context " + propFileURL == null ? "" : propFileURL.toExternalForm() + ". Exiting. " + e.getMessage()); throw new ServletException(e); } return propertiesConfiguration; }