Example usage for java.net URL toExternalForm

List of usage examples for java.net URL toExternalForm

Introduction

In this page you can find the example usage for java.net URL toExternalForm.

Prototype

public String toExternalForm() 

Source Link

Document

Constructs a string representation of this URL .

Usage

From source file:bad.robot.http.apache.ApacheHttpClient.java

@Override
public HttpResponse post(URL url, bad.robot.http.HttpPost message) throws HttpException {
    HttpPost post = new HttpPost(url.toExternalForm());
    for (Header header : message.getHeaders())
        post.addHeader(header.name(), header.value());
    post.setEntity(new HttpRequestToEntity(message).asHttpEntity());
    return execute(post);
}

From source file:com.esri.geoportal.harvester.ckan.CkanBrokerDefinitionAdaptor.java

public void setHostUrl(URL hostUrl) {
    this.hostUrl = hostUrl;
    set(P_HOST_URL, hostUrl.toExternalForm());
}

From source file:org.callimachusproject.fluid.consumers.HttpJavaScriptResponseWriter.java

private String getSystemId(String frag) {
    Class<?> dclass = this.getClass();
    String name = dclass.getSimpleName() + ".class";
    URL url = dclass.getResource(name);
    if (url != null)
        return url.toExternalForm() + "#" + frag;
    return "java:" + dclass.getName() + "#" + frag;
}

From source file:com.appleframework.core.utils.ClassUtility.java

/** class loaderclass? */
public static String locateClass(String className, ClassLoader loader) {
    className = assertNotNull(trimToNull(className), "className");
    if (loader == null) {
        loader = Thread.currentThread().getContextClassLoader();
    }/*w  ww  .ja  v  a 2  s .c o  m*/
    String classFile = className.replace('.', '/') + ".class";
    URL locationURL = loader.getResource(classFile);
    String location = null;
    if (locationURL != null) {
        location = locationURL.toExternalForm();

        if (location.endsWith(classFile)) {
            location = location.substring(0, location.length() - classFile.length());
        }
        location = location.replaceAll("^(jar|zip):|!/$", EMPTY_STRING);
    }
    return location;
}

From source file:fr.gael.dhus.datastore.scanner.FileScanner.java

private void checkList(List<URLExt> list, String root) throws InterruptedException {
    if (isStopped())
        throw new InterruptedException();

    File root_file = new File(root);
    if (!root_file.exists())
        throw new UnsupportedOperationException("cannot access repository path \"" + root + "\".");

    boolean is_root_dir = root_file.isDirectory();
    String uri;/*www.jav  a2 s .c  om*/
    URL url;
    try {
        url = root_file.toURI().toURL();
        uri = url.toExternalForm();
    } catch (MalformedURLException e) {
        throw new UnsupportedOperationException("Cannot convert file \"" + root + "\" to URI.", e);
    }
    DrbNode item = DrbFactory.openURI(uri);
    scannedFiles++;
    boolean accept = matches(item);

    if (accept) {
        list.add(new URLExt(url, is_root_dir));
        retrievedFile++;
    }

    if ((!accept || isForceNavigate()) && is_root_dir) {
        File[] files = root_file.listFiles();
        if (files == null) {
            logger.error("Directory " + root_file + " not accessible.");
            return;
        }
        for (File f : files)
            checkList(list, f.getPath());
    }
}

From source file:com.netflix.spinnaker.clouddriver.artifacts.helm.IndexParser.java

private String resolveReferenceUrl(String ref) {
    String resolvedRef = ref;//  w w  w .  j av  a2s . c  o  m
    String base = repository;
    if (!base.endsWith("/")) {
        base = base.concat("/");
    }
    try {
        URL baseUrl = new URL(base);
        URL resolvedUrl = new URL(baseUrl, ref);
        resolvedRef = resolvedUrl.toExternalForm();
    } catch (MalformedURLException e) {
        log.error("Failed to resolve reference url:" + ref, e);
    }
    return resolvedRef;
}

From source file:net.sf.taverna.t2.workbench.file.impl.actions.PasswordInput.java

public void setUrl(URL url) {
    this.url = url;
    urlLabel.setText(url.toExternalForm());
}

From source file:org.picketbox.test.authentication.http.jetty.DelegatingSecurityFilterHTTPBasicUnitTestCase.java

@Override
protected void establishUserApps() {
    ClassLoader tcl = Thread.currentThread().getContextClassLoader();
    if (tcl == null) {
        tcl = getClass().getClassLoader();
    }/*from w  w w. j av  a2  s.  c  o m*/

    final String WEBAPPDIR = "auth/webapp";

    final String CONTEXTPATH = "/auth";

    // for localhost:port/admin/index.html and whatever else is in the webapp directory
    final URL warUrl = tcl.getResource(WEBAPPDIR);
    final String warUrlString = warUrl.toExternalForm();

    Context context = new WebAppContext(warUrlString, CONTEXTPATH);
    server.setHandler(context);

    Thread.currentThread().setContextClassLoader(context.getClassLoader());

    System.setProperty(PicketBoxConstants.USERNAME, "Aladdin");
    System.setProperty(PicketBoxConstants.CREDENTIAL, "Open Sesame");

    FilterHolder filterHolder = new FilterHolder(DelegatingSecurityFilter.class);
    filterHolder.setInitParameter(PicketBoxConstants.AUTH_MGR,
            SimpleCredentialAuthenticationManager.class.getName());
    filterHolder.setInitParameter(PicketBoxConstants.AUTH_SCHEME_LOADER,
            HTTPBasicAuthenticationSchemeLoader.class.getName());
    context.addFilter(filterHolder, "/", 1);
}

From source file:com.esri.geoportal.harvester.waf.HtmlUrlScrapper.java

/**
 * Scrap HTML page for URL's// w w w .ja v  a2s .  c om
 * @param root root of the page
 * @return list of found URL's
 * @throws IOException if error reading data
 * @throws URISyntaxException if invalid URL
 */
public List<URL> scrap(URL root) throws IOException, URISyntaxException {
    ContentAnalyzer analyzer = new ContentAnalyzer(root);
    HttpGet method = new HttpGet(root.toExternalForm());
    method.setConfig(DEFAULT_REQUEST_CONFIG);
    HttpClientContext context = creds != null && !creds.isEmpty() ? createHttpClientContext(root, creds) : null;

    try (CloseableHttpResponse httpResponse = httpClient.execute(method, context);
            InputStream input = httpResponse.getEntity().getContent();) {
        if (httpResponse.getStatusLine().getStatusCode() >= 400) {
            throw new HttpResponseException(httpResponse.getStatusLine().getStatusCode(),
                    httpResponse.getStatusLine().getReasonPhrase());
        }
        String content = IOUtils.toString(input, "UTF-8");
        return analyzer.analyze(content);
    }
}

From source file:org.jahia.modules.sitemap.SitemapJob.java

/**
 * Execute the actual job. The job data map will already have been
 * applied as bean property values by execute. The contract is
 * exactly the same as for the standard Quartz execute method.
 *
 * @see #execute/*ww  w.ja  va2s. co  m*/
 */
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
    JobDataMap mergedJobDataMap = context.getMergedJobDataMap();
    List<String> searchEnginesList = (List<String>) mergedJobDataMap.get("searchEngines");
    List<String> sites = (List<String>) mergedJobDataMap.get("sites");
    for (String site : sites) {
        for (String s : searchEnginesList) {
            try {
                URL url = new URL(s + URLEncoder.encode(site + "/sitemap.xml", "UTF-8"));
                logger.debug("Calling " + url.toExternalForm());
                URLConnection urlConnection = url.openConnection();
                Source source = new Source(urlConnection);
                logger.debug(source.getTextExtractor().toString());
            } catch (MalformedURLException e) {
                logger.error(e.getMessage(), e);
            } catch (UnsupportedEncodingException e) {
                logger.error(e.getMessage(), e);
            } catch (IOException e) {
                logger.error(e.getMessage(), e);
            }
        }
    }

}