List of usage examples for java.net URL toExternalForm
public String toExternalForm()
From source file:com.gargoylesoftware.htmlunit.html.HtmlImageTest.java
/** * @throws Exception if the test fails/*from w w w . j a v a 2s. c om*/ */ private void useMapClick(final int x, final int y, final String urlSuffix) throws Exception { final String htmlContent = "<html>\n" + "<head><title>foo</title></head>\n" + "<body>\n" + " <img id='myImg' src='foo.png' usemap='#map1'>\n" + " <map name='map1'>\n" + " <area href='a.html' shape='rect' coords='5,5,20,20'>\n" + " <area href='b.html' shape='circle' coords='25,10,10'>\n" + " </map>\n" + "</body></html>"; final HtmlPage page = loadPage(htmlContent); final HtmlImage img = page.getHtmlElementById("myImg"); final Page page2 = img.click(x, y); final URL url = page2.getUrl(); assertTrue(url.toExternalForm(), url.toExternalForm().endsWith(urlSuffix)); }
From source file:org.jboss.as.test.integration.web.jsp.taglib.jar.TagLibInJarTestCase.java
private void checkJspAvailable(URL url) throws Exception { try (CloseableHttpClient httpClient = HttpClients.createDefault()) { String jspUrl = url.toExternalForm() + JSP; HttpGet httpget = new HttpGet(jspUrl); HttpResponse response = httpClient.execute(httpget); HttpEntity entity = response.getEntity(); String result = EntityUtils.toString(entity); Assert.assertTrue(result, result.contains("Test Tag!")); }/*from ww w . j a v a2 s . c om*/ }
From source file:com.sap.prd.mobile.ios.ota.webapp.OtaHtmlService.java
private URL generateHtmlServiceQRCodeUrl(HttpServletRequest request, Map<String, String> params) throws MalformedURLException { URL htmlServiceUrl = generateHtmlServiceUrl(getHtmlServiceBaseUrl(request), params); return new URL(htmlServiceUrl.toExternalForm() + "&" + KEY_ACTION + "=" + KEY_QRCODE + "&" + QR_ON_COLOR + "=" + QR_ON_COLOR_DEFAULT + "&" + QR_OFF_COLOR + "=" + QR_OFF_COLOR_DEFAULT); }
From source file:org.picketbox.http.test.authentication.jetty.DelegatingSecurityFilterHTTPBasicUnitTestCase.java
@Override protected void establishUserApps() { ClassLoader tcl = Thread.currentThread().getContextClassLoader(); if (tcl == null) { tcl = getClass().getClassLoader(); }/*w w w . java2 s . 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(); /* * Context context = new WebAppContext(warUrlString, CONTEXTPATH); server.setHandler(context); * * Thread.currentThread().setContextClassLoader(context.getClassLoader()); */ this.webapp = createWebApp(CONTEXTPATH, warUrlString); this.server.setHandler(webapp); System.setProperty(PicketBoxConstants.USERNAME, "Aladdin"); System.setProperty(PicketBoxConstants.CREDENTIAL, "Open Sesame"); FilterHolder filterHolder = new FilterHolder(DelegatingSecurityFilter.class); webapp.setInitParameter(PicketBoxConstants.AUTHENTICATION_KEY, PicketBoxConstants.BASIC); webapp.setInitParameter(PicketBoxConstants.HTTP_CONFIGURATION_PROVIDER, HTTPDigestConfigurationProvider.class.getName()); ServletHandler servletHandler = new ServletHandler(); servletHandler.addFilter(filterHolder, createFilterMapping("/", filterHolder)); webapp.setServletHandler(servletHandler); }
From source file:org.jasig.cas.authentication.principal.HttpBasedServiceCredentials.java
/** * Constructor that takes the URL of the HTTP-based service and creates the * Credentials object. Caches the value of URL.toExternalForm so updates to * the URL will not be reflected in a call to toString(). * //ww w . ja v a 2s . c o m * @param callbackUrl the URL representing the service * @throws IllegalArgumentException if the callbackUrl is null. */ public HttpBasedServiceCredentials(final URL callbackUrl) { Assert.notNull(callbackUrl, "callbackUrl cannot be null"); this.callbackUrl = callbackUrl; this.callbackUrlAsString = callbackUrl.toExternalForm(); }
From source file:org.danann.cernunnos.spring.ApplicationContextTask.java
private synchronized ApplicationContext getApplicationContext(URL config, boolean useCache) { if (!useCache || !config.equals(prevUrl)) { prevBeans = new FileSystemXmlApplicationContext(config.toExternalForm()); prevUrl = config;//from w w w .j ava 2 s .co m } return prevBeans; }
From source file:cc.arduino.net.CustomProxySelector.java
private String callFindProxyForURL(URI uri, ScriptEngine nashorn) throws ScriptException, NoSuchMethodException { Invocable script = (Invocable) nashorn; URL url = toUrl(uri); return (String) script.invokeFunction("FindProxyForURL", url.toExternalForm(), url.getHost()); }
From source file:net.sourceforge.dita4publishers.tools.ditadxpmappackager.DitaDxpMapPackager.java
/** * @throws Exception /* ww w . jav a 2 s.c o m*/ * */ private void run() throws Exception { String mapFilepath = commandLine.getOptionValue("i"); File mapFile = new File(mapFilepath).getAbsoluteFile(); checkExistsAndCanReadSystemExit(mapFile); DitaDxpOptions dxpOptions = new DitaDxpOptions(); handleCommonBosProcessorOptions(dxpOptions); if (!dxpOptions.isQuiet()) System.err.println("Processing map \"" + mapFile.getAbsolutePath() + "\"..."); File outputZipFile = null; String outputFilepath = null; if (commandLine.hasOption(OUTPUT_OPTION_ONE_CHAR)) { outputFilepath = commandLine.getOptionValue(OUTPUT_OPTION_ONE_CHAR); outputZipFile = new File(outputFilepath).getAbsoluteFile(); } else { File parentDir = mapFile.getParentFile(); String nameBase = FilenameUtils.getBaseName(mapFile.getName()); outputZipFile = new File(parentDir, nameBase + DXP_EXTENSION); } File parentFile = outputZipFile.getParentFile(); parentFile.mkdirs(); if (!outputZipFile.getParentFile().canWrite()) { throw new RuntimeException("File " + outputZipFile.getAbsolutePath() + " cannot be written to."); } Document rootMap = null; BosConstructionOptions bosOptions = new BosConstructionOptions(log, new HashMap<URI, Document>()); bosOptions.setQuiet(dxpOptions.isQuiet()); boolean failOnAddressingFailure = false; if (commandLine.hasOption(ADDRESSING_FAILURE_OPTION_ONE_CHAR)) failOnAddressingFailure = true; bosOptions.setFailOnAddressResolutionFailure(failOnAddressingFailure); setupCatalogs(bosOptions); try { URL rootMapUrl = mapFile.toURI().toURL(); rootMap = DomUtil.getDomForUri(new URI(rootMapUrl.toExternalForm()), bosOptions); Date startTime = TimingUtils.getNowTime(); DitaBoundedObjectSet mapBos = DitaBosHelper.calculateMapBos(bosOptions, log, rootMap); if (!dxpOptions.isQuiet()) System.err.println("Map BOS construction took " + TimingUtils.reportElapsedTime(startTime)); // Do packaging here DitaDxpHelper.zipMapBos(mapBos, outputZipFile, dxpOptions); } catch (Exception e) { e.printStackTrace(); } finally { // Do final stuff here. } }
From source file:org.picketbox.test.authentication.http.jetty.DelegatingSecurityFilterHTTPDigestUnitTestCase.java
@Override protected void establishUserApps() { ClassLoader tcl = Thread.currentThread().getContextClassLoader(); if (tcl == null) { tcl = getClass().getClassLoader(); }/*from w ww . j a v 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, HTTPDigestAuthenticationSchemeLoader.class.getName()); context.addFilter(filterHolder, "/", 1); }
From source file:com.rapidminer.gui.OperatorDocLoader.java
/** * /*from w w w .j a va 2 s .c o m*/ * @param operatorWikiName * @param opDesc * @return The parsed <tt>Document</tt> (not finally parsed) of the selected operator. * @throws MalformedURLException * @throws ParserConfigurationException */ private static Document parseDocumentForOperator(String operatorWikiName, OperatorDescription opDesc) throws MalformedURLException, ParserConfigurationException { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setIgnoringComments(true); builderFactory.setIgnoringElementContentWhitespace(true); DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder(); documentBuilder.setEntityResolver(new XHTMLEntityResolver()); Document document = null; URL url = new URL(WIKI_PREFIX_FOR_OPERATORS + operatorWikiName); if (url != null) { try { document = documentBuilder.parse(WebServiceTools.openStreamFromURL(url)); } catch (IOException e) { logger.warning("Could not open " + url.toExternalForm() + ": " + e.getMessage()); } catch (SAXException e) { logger.warning("Could not parse operator documentation: " + e.getMessage()); } int i = 0; if (document != null) { Element contentElement = document.getElementById("content"); // removing content element from document if (contentElement != null) { contentElement.getParentNode().removeChild(contentElement); } // removing everything from body NodeList bodies = document.getElementsByTagName("body"); for (int k = 0; k < bodies.getLength(); k++) { Node body = bodies.item(k); while (body.hasChildNodes()) { body.removeChild(body.getFirstChild()); } // read content element to body if (contentElement != null && k == 0) { body.appendChild(contentElement); } } // removing everything from head NodeList heads = document.getElementsByTagName("head"); for (int k = 0; k < heads.getLength(); k++) { Node head = heads.item(k); while (head.hasChildNodes()) { head.removeChild(head.getFirstChild()); } } // removing...<head/> from document if (heads != null) { while (i < heads.getLength()) { Node head = heads.item(i); head.getParentNode().removeChild(head); } } // removing jump-to-nav element from document Element jumpToNavElement = document.getElementById("jump-to-nav"); if (jumpToNavElement != null) { jumpToNavElement.getParentNode().removeChild(jumpToNavElement); } // removing mw-normal-catlinks element from document Element mwNormalCatlinksElement = document.getElementById("mw-normal-catlinks"); if (mwNormalCatlinksElement != null) { mwNormalCatlinksElement.getParentNode().removeChild(mwNormalCatlinksElement); } // removing complete link navigation Element tocElement = document.getElementById("toc"); if (tocElement != null) { tocElement.getParentNode().removeChild(tocElement); } // removing everything from class printfooter NodeList nodeListDiv = document.getElementsByTagName("div"); for (int k = 0; k < nodeListDiv.getLength(); k++) { Element div = (Element) nodeListDiv.item(k); if (div.getAttribute("class").equals("printfooter")) { div.getParentNode().removeChild(div); } } // removing everything from class editsection NodeList spanList = document.getElementsByTagName("span"); for (int k = 0; k < spanList.getLength(); k++) { Element span = (Element) spanList.item(k); if (span.getAttribute("class").equals("editsection")) { span.getParentNode().removeChild(span); } } // Synopsis Header boolean doIt = true; NodeList pList = document.getElementsByTagName("p"); for (int k = 0; k < pList.getLength(); k++) { if (doIt) { Node p = pList.item(k); NodeList pChildList = p.getChildNodes(); for (int j = 0; j < pChildList.getLength(); j++) { Node pChild = pChildList.item(j); if (pChild.getNodeType() == Node.TEXT_NODE && pChild.getNodeValue() != null && StringUtils.isNotBlank(pChild.getNodeValue()) && StringUtils.isNotEmpty(pChild.getNodeValue())) { String pChildString = pChild.getNodeValue(); Element newPWithoutSpaces = document.createElement("p"); newPWithoutSpaces.setTextContent(pChildString); Node synopsis = document.createTextNode("Synopsis"); Element span = document.createElement("span"); span.setAttribute("class", "mw-headline"); span.setAttribute("id", "Synopsis"); span.appendChild(synopsis); Element h2 = document.createElement("h2"); h2.appendChild(span); Element div = document.createElement("div"); div.setAttribute("id", "synopsis"); div.appendChild(h2); div.appendChild(newPWithoutSpaces); Node pChildParentParent = pChild.getParentNode().getParentNode(); Node pChildParent = pChild.getParentNode(); pChildParentParent.replaceChild(div, pChildParent); doIt = false; break; } } } else { break; } } // removing all <br...>-Tags NodeList brList = document.getElementsByTagName("br"); while (i < brList.getLength()) { Node br = brList.item(i); Node parentBrNode = br.getParentNode(); parentBrNode.removeChild(br); } // removing everything from script NodeList scriptList = document.getElementsByTagName("script"); while (i < scriptList.getLength()) { Node scriptNode = scriptList.item(i); Node parentNode = scriptNode.getParentNode(); parentNode.removeChild(scriptNode); } // removing all empty <p...>-Tags NodeList pList2 = document.getElementsByTagName("p"); int ccc = 0; while (ccc < pList2.getLength()) { Node p = pList2.item(ccc); NodeList pChilds = p.getChildNodes(); int kk = 0; while (kk < pChilds.getLength()) { Node pChild = pChilds.item(kk); if (pChild.getNodeType() == Node.TEXT_NODE) { String pNodeValue = pChild.getNodeValue(); if (pNodeValue == null || StringUtils.isBlank(pNodeValue) || StringUtils.isEmpty(pNodeValue)) { kk++; } else { ccc++; break; } } else { ccc++; break; } if (kk == pChilds.getLength()) { Node parentBrNode = p.getParentNode(); parentBrNode.removeChild(p); } } } // removing firstHeading element from document Element firstHeadingElement = document.getElementById("firstHeading"); if (firstHeadingElement != null) { CURRENT_OPERATOR_NAME_READ_FROM_RAPIDWIKI = firstHeadingElement.getFirstChild().getNodeValue() .replaceFirst(".*:", ""); firstHeadingElement.getParentNode().removeChild(firstHeadingElement); } // setting operator plugin name if (opDesc != null && opDesc.getProvider() != null) { CURRENT_OPERATOR_PLUGIN_NAME = opDesc.getProvider().getName(); } // removing sitesub element from document Element siteSubElement = document.getElementById("siteSub"); if (siteSubElement != null) { siteSubElement.getParentNode().removeChild(siteSubElement); } // removing contentSub element from document Element contentSubElement = document.getElementById("contentSub"); if (contentSubElement != null) { contentSubElement.getParentNode().removeChild(contentSubElement); } // removing catlinks element from document Element catlinksElement = document.getElementById("catlinks"); if (catlinksElement != null) { catlinksElement.getParentNode().removeChild(catlinksElement); } // removing <a...> element from document, if they are empty NodeList aList = document.getElementsByTagName("a"); if (aList != null) { int k = 0; while (k < aList.getLength()) { Node a = aList.item(k); Element aElement = (Element) a; if (aElement.getAttribute("class").equals("internal")) { a.getParentNode().removeChild(a); } else { Node aChild = a.getFirstChild(); if (aChild != null && (aChild.getNodeValue() != null && aChild.getNodeType() == Node.TEXT_NODE && StringUtils.isNotBlank(aChild.getNodeValue()) && StringUtils.isNotEmpty(aChild.getNodeValue()) || aChild.getNodeName() != null)) { Element aChildElement = null; if (aChild.getNodeName().startsWith("img")) { aChildElement = (Element) aChild; Element imgElement = document.createElement("img"); imgElement.setAttribute("alt", aChildElement.getAttribute("alt")); imgElement.setAttribute("class", aChildElement.getAttribute("class")); imgElement.setAttribute("height", aChildElement.getAttribute("height")); imgElement.setAttribute("src", WIKI_PREFIX_FOR_IMAGES + aChildElement.getAttribute("src")); imgElement.setAttribute("width", aChildElement.getAttribute("width")); imgElement.setAttribute("border", "1"); Node aParent = a.getParentNode(); aParent.replaceChild(imgElement, a); } else { k++; } } else { a.getParentNode().removeChild(a); } } } } } } return document; }