List of usage examples for java.net URL toExternalForm
public String toExternalForm()
From source file:com.gargoylesoftware.htmlunit.javascript.host.dom.Node2Test.java
/** * @throws Exception if the test fails//from w w w .java 2s . com */ @Test @Alerts({ "1", "2" }) public void eventListener_return_false() throws Exception { final String html = "<html><head>\n" + "<script>\n" + " function clicking1() {\n" + " alert(1);\n" + " }\n" + " function clicking2() {\n" + " alert(2);\n" + " return false;\n" + " }\n" + " function test() {\n" + " var e = document.getElementById('myAnchor');\n" + " if (e.addEventListener) {\n" + " e.addEventListener('click', clicking1, false);\n" + " e.addEventListener('click', clicking2, false);\n" + " } else if (e.attachEvent) {\n" + " e.attachEvent('onclick', clicking1);\n" + " e.attachEvent('onclick', clicking2);\n" + " }\n" + " }\n" + "</script></head><body onload='test()'>\n" + " <a href='" + URL_SECOND + "' id='myAnchor'>Click me</a>\n" + "</body></html>"; final List<String> collectedAlerts = new ArrayList<>(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); final HtmlPage page2 = page.getHtmlElementById("myAnchor").click(); //IE doesn't have specific order Collections.sort(collectedAlerts); assertEquals(getExpectedAlerts(), collectedAlerts); final URL expectedURL; if (getBrowserVersion().isIE()) { expectedURL = getDefaultUrl(); } else { expectedURL = URL_SECOND; } assertEquals(expectedURL.toExternalForm(), page2.getUrl().toExternalForm()); }
From source file:fr.free.movierenamer.scrapper.impl.trailer.VideoDetectiveScrapper.java
@Override protected TrailerInfo fetchTrailerInfo(Trailer searchResult) throws Exception { URL url = searchResult.getTrailerUrl(); Matcher matcher = idPattern.matcher(url.toExternalForm()); if (!matcher.find()) { throw new Exception("No id found for " + searchResult); }/*w w w .j a va 2 s. c o m*/ Map<TrailerProperty, String> info = new EnumMap<TrailerProperty, String>(TrailerProperty.class); Map<Quality, URL> streams = new EnumMap<Quality, URL>(Quality.class); String id = matcher.group(1); String urlStr = String.format(infoUrl, cusomerId, id); URL uri = new URL(urlStr); JSONObject json = URIRequest.getJsonDocument(uri.toURI()); List<JSONObject> pnodes = JSONUtils.selectList("playlist", json); info.put(TrailerProperty.title, searchResult.getName()); info.put(TrailerProperty.provider, searchResult.getProviderName()); info.put(TrailerProperty.runtime, searchResult.getRuntime()); info.put(TrailerProperty.overview, JSONUtils.selectString("description", pnodes.get(0))); List<JSONObject> nodes = JSONUtils.selectList("sources", pnodes.get(0)); for (JSONObject node : nodes) { String label = JSONUtils.selectString("label", node); if (label != null) { Bitrate bt; try { bt = Bitrate.valueOf("B_" + (label.replace(" ", "_"))); } catch (Exception ex) { continue; } if (streams.containsKey(bt.getQuality())) { continue; } streams.put(bt.getQuality(), new URL(JSONUtils.selectString("file", node))); } } return new TrailerInfo(info, streams, searchResult.getLang()); }
From source file:com.opensymphony.xwork2.util.finder.UrlSet.java
private void load(Collection<URL> urls) { for (URL location : urls) { try {//from www . j a v a 2 s . c om this.urls.put(location.toExternalForm(), location); } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn("Cannot translate url to external form!", e); } } } }
From source file:com.gargoylesoftware.htmlunit.javascript.host.Node2Test.java
/** * @throws Exception if the test fails//from w w w .j a v a 2s. c o m */ @Test @Alerts({ "1", "2" }) public void eventListener_return_false() throws Exception { final String html = "<html><head>\n" + "<script>\n" + " function clicking1() {\n" + " alert(1);\n" + " }\n" + " function clicking2() {\n" + " alert(2);\n" + " return false;\n" + " }\n" + " function test() {\n" + " var e = document.getElementById('myAnchor');\n" + " if (e.addEventListener) {\n" + " e.addEventListener('click', clicking1, false);\n" + " e.addEventListener('click', clicking2, false);\n" + " } else if (e.attachEvent) {\n" + " e.attachEvent('onclick', clicking1);\n" + " e.attachEvent('onclick', clicking2);\n" + " }\n" + " }\n" + "</script></head><body onload='test()'>\n" + " <a href='" + URL_SECOND + "' id='myAnchor'>Click me</a>\n" + "</body></html>"; final List<String> collectedAlerts = new ArrayList<String>(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); final HtmlPage page2 = page.getHtmlElementById("myAnchor").click(); //IE doesn't have specific order Collections.sort(collectedAlerts); assertEquals(getExpectedAlerts(), collectedAlerts); final URL expectedURL; if (getBrowserVersion().isIE()) { expectedURL = getDefaultUrl(); } else { expectedURL = URL_SECOND; } assertEquals(expectedURL.toExternalForm(), page2.getUrl().toExternalForm()); }
From source file:com.esri.gpt.control.webharvest.client.ckan.CkanIterator.java
public CkanIterator(CkanConfig config, URL baseUrl, String q) { this.config = config; this.baseUrl = baseUrl.toExternalForm().replaceAll("/+$", ""); this.q = q;//from w w w .ja v a2 s.c o m }
From source file:com.marvelution.hudson.plugins.jirareporter.JIRASite.java
/** * Constructor//from w ww. ja v a 2 s . co m * * @param name the JIRA Site name * @param url the JIRA Site {@link URL} * @param username the username to use for Authentication with the JIRA Site * @param password the password for the given username * @param supportsWikiStyle flag is Wiki style texts are supported * @param closeAction the name of the Close action, defaults to Close * @param checkIssueExistence flag to check if an Issue exists before annotating it in the Changelog */ @DataBoundConstructor public JIRASite(String name, URL url, String username, String password, boolean supportsWikiStyle, String closeAction, boolean checkIssueExistence) { this.name = name; if (!url.toExternalForm().endsWith("/")) try { url = new URL(url.toExternalForm() + "/"); } catch (MalformedURLException e) { // Ignore this, cannot happen any way } this.url = url; this.username = username; this.password = password; this.supportsWikiStyle = supportsWikiStyle; this.closeAction = closeAction; this.checkIssueExistence = checkIssueExistence; }
From source file:com.twitter.ambrose.server.ScriptStatusServer.java
/** * Run the server in the current thread. *///from w ww.j a v a2 s.co m @Override public void run() { server = new Server(port); //this needs to be loaded via the jared resources, not the relative dir URL resourcesUrl = this.getClass().getClassLoader().getResource(ROOT_PATH); server.addHandler(new APIHandler()); server.addHandler(new WebAppContext(resourcesUrl.toExternalForm(), SLASH)); server.setStopAtShutdown(false); try { server.start(); server.join(); } catch (Exception e) { LOG.error("Error launching ScriptStatusServer on port " + port, e); } }
From source file:org.picketbox.http.test.config.ProtectedResourceManagerUnitTestCase.java
@Override protected void establishUserApps() { ClassLoader tcl = Thread.currentThread().getContextClassLoader(); if (tcl == null) { tcl = getClass().getClassLoader(); }/*from w w w . j a va 2s. c om*/ 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(); WebAppContext webapp = createWebApp(CONTEXTPATH, warUrlString); this.server.setHandler(webapp); Thread.currentThread().setContextClassLoader(webapp.getClassLoader()); System.setProperty(PicketBoxConstants.USERNAME, "Aladdin"); System.setProperty(PicketBoxConstants.CREDENTIAL, "Open Sesame"); FilterHolder filterHolder = new FilterHolder(DelegatingSecurityFilter.class); webapp.setInitParameter(PicketBoxConstants.AUTHENTICATION_KEY, PicketBoxConstants.HTTP_DIGEST); webapp.setInitParameter(PicketBoxConstants.HTTP_CONFIGURATION_PROVIDER, ProtectedResourcesConfigurationProvider.class.getName()); ServletHandler servletHandler = new ServletHandler(); servletHandler.addFilter(filterHolder, createFilterMapping("/*", filterHolder)); webapp.setServletHandler(servletHandler); }
From source file:com.digitalpebble.storm.crawler.filtering.BasicURLNormalizerTest.java
@Test public void testAnchorFilterFalse() throws MalformedURLException { URLFilter allAllowed = createFilter(false); URL url = new URL("http://www.sourcedomain.com/#0"); Metadata metadata = new Metadata(); String filterResult = allAllowed.filter(url, metadata, url.toExternalForm()); Assert.assertEquals(url.toExternalForm(), filterResult); }
From source file:com.digitalpebble.storm.crawler.filtering.BasicURLNormalizerTest.java
@Test public void testAnchorFilter() throws MalformedURLException { URLFilter allAllowed = createFilter(true); URL url = new URL("http://www.sourcedomain.com/#0"); Metadata metadata = new Metadata(); String filterResult = allAllowed.filter(url, metadata, url.toExternalForm()); String expected = "http://www.sourcedomain.com/"; Assert.assertEquals(expected, filterResult); }