List of usage examples for java.net URL toExternalForm
public String toExternalForm()
From source file:com.alibaba.antx.util.ZipUtil.java
/** * ?jar URL/*from w w w . java 2 s . c o m*/ * * @param jarfileURL jarURL * @param path ?jar * @return jar URL */ public static URL getJarURL(URL jarfileURL, String path) throws MalformedURLException { StringBuffer url = new StringBuffer(); url.append("jar:").append(jarfileURL.toExternalForm()).append("!"); if (!path.startsWith("/")) { url.append("/"); } url.append(path.replace('\\', '/')); return new URL(url.toString()); }
From source file:de.akquinet.android.androlog.reporter.PostReporter.java
public static void postReport(URL url, String param) throws IOException { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url.toExternalForm()); try {/*from w w w . ja v a 2s. c om*/ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("report", param)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request httpclient.execute(httppost); } catch (ClientProtocolException e) { throw new IOException(e.getMessage()); } }
From source file:ie.wombat.rt.fireeagle.CookieConsumer.java
public static OAuthConsumer getConsumer(String name, ServletContext context) throws IOException { synchronized (CookieConsumer.class) { if (consumers == null) { String resourceName = "/" + CookieConsumer.class.getPackage().getName().replace(".", "/") + "/consumer.properties"; consumerProperties = ConsumerProperties.getProperties( ConsumerProperties.getResource(resourceName, CookieConsumer.class.getClassLoader())); consumers = new ConsumerProperties(consumerProperties); }//w w w. ja v a 2 s . co m } if (context != null) { synchronized (consumerProperties) { String key = name + ".callbackURL"; String value = consumerProperties.getProperty(key); if (value == null) { // Compute the callbackURL from the servlet context. URL resource = context.getResource(Callback.PATH); if (resource != null) { value = resource.toExternalForm(); } else { value = Callback.PATH; } consumerProperties.setProperty(key, value); } } } OAuthConsumer consumer = consumers.getConsumer(name); return consumer; }
From source file:com.sap.prd.mobile.ios.ota.lib.OtaHtmlGenerator.java
/** * Generates the URL for a specific request to the HTML service. * // w w w . j a v a 2 s . c o m * @param htmlServiceUrl * The base URL to the service. E.g. http://apple-ota.wdf.sap.corp:1080/ota-service/HTML * @param title * The title of the App * @param bundleIdentifier * The bundleIdentifier of the App * @param bundleVersion * The bundleVersion of the App * @param ipaClassifier * The classifier used in the IPA artifact. If null no classifier will be used. * @param otaClassifier * The classifier used in the OTA HTML artifact. If null no classifier will be used. * @return the URL * @throws MalformedURLException */ public static URL generateHtmlServiceUrl(URL htmlServiceUrl, Map<String, String> params) throws MalformedURLException { if (params.get(KEY_REFERER) == null) { return new URL(String.format("%s?%s=%s&%s=%s&%s=%s%s%s", htmlServiceUrl.toExternalForm(), KEY_TITLE, LibUtils.urlEncode(params.get(KEY_TITLE)), KEY_BUNDLE_IDENTIFIER, LibUtils.urlEncode(params.get(KEY_BUNDLE_IDENTIFIER)), KEY_BUNDLE_VERSION, LibUtils.urlEncode(params.get(KEY_BUNDLE_VERSION)), (StringUtils.isEmpty(params.get(KEY_IPA_CLASSIFIER)) ? "" : String.format("&%s=%s", KEY_IPA_CLASSIFIER, LibUtils.urlEncode(params.get(KEY_IPA_CLASSIFIER)))), (StringUtils.isEmpty(params.get(KEY_OTA_CLASSIFIER)) ? "" : String.format("&%s=%s", KEY_OTA_CLASSIFIER, LibUtils.urlEncode(params.get(KEY_OTA_CLASSIFIER)))))); } else { return new URL(String.format("%s?%s=%s&%s=%s&%s=%s&%s=%s%s%s", htmlServiceUrl.toExternalForm(), KEY_REFERER, LibUtils.encode(KEY_REFERER + "=" + params.get(KEY_REFERER)), KEY_TITLE, LibUtils.urlEncode(params.get(KEY_TITLE)), KEY_BUNDLE_IDENTIFIER, LibUtils.urlEncode(params.get(KEY_BUNDLE_IDENTIFIER)), KEY_BUNDLE_VERSION, LibUtils.urlEncode(params.get(KEY_BUNDLE_VERSION)), (StringUtils.isEmpty(params.get(KEY_IPA_CLASSIFIER)) ? "" : String.format("&%s=%s", KEY_IPA_CLASSIFIER, LibUtils.urlEncode(params.get(KEY_IPA_CLASSIFIER)))), (StringUtils.isEmpty(params.get(KEY_OTA_CLASSIFIER)) ? "" : String.format("&%s=%s", KEY_OTA_CLASSIFIER, LibUtils.urlEncode(params.get(KEY_OTA_CLASSIFIER)))))); } }
From source file:com.netflix.config.util.ConfigurationUtils.java
static void loadFromPropertiesFile(AbstractConfiguration config, String baseUrl, Set<String> loaded, String... nextLoadKeys) { String nextLoad = getNextLoad(config, nextLoadKeys); if (nextLoad == null) { return;/*w w w .j a v a2 s . c o m*/ } String[] filesToLoad = nextLoad.split(","); for (String fileName : filesToLoad) { fileName = fileName.trim(); try { URL url = new URL(baseUrl + "/" + fileName); // avoid circle if (loaded.contains(url.toExternalForm())) { logger.warn(url + " is already loaded"); continue; } loaded.add(url.toExternalForm()); PropertiesConfiguration nextConfig = new OverridingPropertiesConfiguration(url); copyProperties(nextConfig, config); logger.info("Loaded properties file " + url); loadFromPropertiesFile(config, baseUrl, loaded, nextLoadKeys); } catch (Throwable e) { logger.warn("Unable to load properties file", e); } } }
From source file:de.nava.informa.parsers.OPMLParser.java
public static Collection<FeedIF> parse(File aFile) throws IOException, ParseException { URL aURL; try {//from ww w . j av a2 s. c o m aURL = aFile.toURI().toURL(); } catch (java.net.MalformedURLException e) { throw new IOException("File " + aFile + " had invalid URL " + "representation."); } return parse(new InputSource(aURL.toExternalForm()), aURL); }
From source file:net.sourceforge.dita4publishers.tools.dxp.DitaDxpHelper.java
/** * Extracts only the local dependencies used from a map from a DXP package. * @param zipFile/*from ww w.j a v a 2 s. com*/ * @param mapEntry * @param outputDir * @param dxpOptions * @throws Exception */ private static void extractMap(ZipFile zipFile, ZipEntry mapEntry, File outputDir, MapBosProcessorOptions dxpOptions) throws Exception { Map<URI, Document> domCache = new HashMap<URI, Document>(); if (!dxpOptions.isQuiet()) log.info("Extracting map " + mapEntry.getName() + "..."); BosConstructionOptions bosOptions = new BosConstructionOptions(log, domCache); InputSource source = new InputSource(zipFile.getInputStream(mapEntry)); File dxpFile = new File(zipFile.getName()); URL baseUri = new URL("jar:" + dxpFile.toURI().toURL().toExternalForm() + "!/"); URL mapUrl = new URL(baseUri, mapEntry.getName()); source.setSystemId(mapUrl.toExternalForm()); Document rootMap = DomUtil.getDomForSource(source, bosOptions, false); DitaBoundedObjectSet mapBos = DitaBosHelper.calculateMapBos(bosOptions, log, rootMap); MapCopyingBosVisitor visitor = new MapCopyingBosVisitor(outputDir); visitor.visit(mapBos); if (!dxpOptions.isQuiet()) log.info("Map extracted."); }
From source file:com.netflix.config.util.ConfigurationUtils.java
public static AbstractConfiguration getConfigFromPropertiesFile(URL startingUrl, Set<String> loaded, String... nextLoadKeys) throws FileNotFoundException { if (loaded.contains(startingUrl.toExternalForm())) { logger.warn(startingUrl + " is already loaded"); return null; }/* ww w. j av a2 s. c o m*/ PropertiesConfiguration propConfig = null; try { propConfig = new OverridingPropertiesConfiguration(startingUrl); logger.info("Loaded properties file " + startingUrl); } catch (ConfigurationException e) { Throwable cause = e.getCause(); if (cause instanceof FileNotFoundException) { throw (FileNotFoundException) cause; } else { throw new RuntimeException(e); } } if (nextLoadKeys == null) { return propConfig; } String urlString = startingUrl.toExternalForm(); String base = urlString.substring(0, urlString.lastIndexOf("/")); loaded.add(startingUrl.toString()); loadFromPropertiesFile(propConfig, base, loaded, nextLoadKeys); return propConfig; }
From source file:com.intuit.tank.tools.debugger.PanelBuilder.java
private static Headers getHeaders(String serviceUrl) { Headers ret = null;/* w w w.j a v a 2 s . c o m*/ if (StringUtils.isNotBlank(serviceUrl)) { InputStream settingsStream = null; try { URL url = new URL(serviceUrl + HEADERS_PATH); LOG.info( "Starting up: making call to tank service url to get settings.xml " + url.toExternalForm()); settingsStream = url.openStream(); JAXBContext ctx = JAXBContext.newInstance(Headers.class.getPackage().getName()); ret = (Headers) ctx.createUnmarshaller().unmarshal(settingsStream); } catch (Exception e) { LOG.error("Error gettting headers: " + e, e); } finally { IOUtils.closeQuietly(settingsStream); } } return ret; }
From source file:com.netflix.config.ConfigurationManager.java
private static String getConfigName(URL propertyFile) { String name = propertyFile.toExternalForm(); name = name.replace('\\', '/'); // Windows final String scheme = propertyFile.getProtocol().toLowerCase(); if ("jar".equals(scheme) || "zip".equals(scheme)) { // Use the unqualified name of the jar file. final int bang = name.lastIndexOf("!"); if (bang >= 0) { name = name.substring(0, bang); }/* w ww . ja v a 2s . co m*/ final int slash = name.lastIndexOf("/"); if (slash >= 0) { name = name.substring(slash + 1); } } else { // Use the URL of the enclosing directory. final int slash = name.lastIndexOf("/"); if (slash >= 0) { name = name.substring(0, slash); } } return name; }