List of usage examples for java.net MalformedURLException MalformedURLException
public MalformedURLException(String msg)
From source file:Main.java
protected static String getProtocol(final String url) throws MalformedURLException { String retVal = null;//from w ww .ja v a 2 s . c o m if (url != null) { final String[] urlArray = url.split(COLON); if (urlArray.length == 2 || urlArray.length == 3) { if (urlArray[0].equals(SELENIUM_PROTOCOL)) { retVal = SELENIUM_PROTOCOL; } else { final String[] portPlusUriArray = splitPortUri(urlArray[1]); if (urlArray[1].contains(DOUBLE_FORWARD_SLASH)) { // second element is a host, which means protocol is not supported throw new MalformedURLException("Unsupported protocol: " + urlArray[0]); } else if (isInteger(portPlusUriArray[0])) { // second element is a port, set protocol to default retVal = SELENIUM_PROTOCOL; } else { // second element is not a port, which means the first element is // not // a host, and // is also not a supported protocol. throw new MalformedURLException("Unsupported protocol: " + urlArray[0]); } } } else if (urlArray.length == 1) { retVal = SELENIUM_PROTOCOL; } else if (urlArray.length > 3) { throw new MalformedURLException("Unexpected number of colons within URL."); } } else { retVal = SELENIUM_PROTOCOL; } return retVal; }
From source file:com.jonbanjo.cupsprint.Util.java
public static URL getURL(String urlStr) throws MalformedURLException { UrlValidator urlValidator = new UrlValidator(); if (urlValidator.isValid(urlStr)) { try {/*from w w w . j a v a2 s.c om*/ return new URL(urlStr); } catch (Exception e) { } } throw new MalformedURLException("Invalid URL\n" + urlStr); }
From source file:Main.java
protected static String getPort(final String url) throws MalformedURLException { String retPort;/*from w w w . java2 s. c o m*/ if (url != null) { final String[] urlArray = url.split(COLON); retPort = null; if (urlArray.length == 1) { retPort = getDefaultPort(urlArray[0]); } else if (urlArray.length == 2) { final String[] portPlusUriArray = splitPortUri(urlArray[1]); if (isInteger(portPlusUriArray[0])) { retPort = portPlusUriArray[0]; } else { retPort = getDefaultPort(urlArray[1]); } } else if (urlArray.length == 3) { final String[] portPlusUriArray = splitPortUri(urlArray[2]); if (isInteger(portPlusUriArray[0])) { retPort = portPlusUriArray[0]; } else { throw new MalformedURLException("Port invalid"); } } } else { retPort = SELENIUM_LOCAL_PORT_DEFAULT; } return retPort; }
From source file:Main.java
/** * Get the API access token request uri//from w w w . j ava 2s .co m * * @param cloudApi type of cloud account * @return Uri */ public static Uri getAccessTokenUri(String cloudApi) throws MalformedURLException { // use reflection for flexibility try { Class clazz = Class.forName(cloudApi); Field tokenUrl = clazz.getField("TOKEN_URL"); return Uri.parse((String) tokenUrl.get(null)); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } throw new MalformedURLException("No url or malformed url for request!"); }
From source file:jsaf.protocol.tftp.TftpURLStreamHandler.java
@Override public URLConnection openConnection(URL url) throws IOException { if ("tftp".equals(url.getProtocol())) { return new TftpURLConnection(url); } else {/*from ww w .j a v a 2s. c om*/ throw new MalformedURLException(Message.getMessage(Message.ERROR_PROTOCOL, url.getProtocol())); } }
From source file:org.matonto.rdf.orm.generate.PackageNamer.java
/** * Convert the IRI string into a package name. * * @param uriString The provided IRI string * @return The {@link String} package name * @throws MalformedURLException If the IRI is malformed, doesn't match our pattern *//* w w w .ja v a 2 s .co m*/ public static String packageFromUrl(final String uriString) throws MalformedURLException { final java.util.regex.Matcher m = PATTERN.matcher(uriString); if (m.matches()) { List<String> elements = removeEmptyElements(Arrays.asList(m.group(2).split("[\\.|/]")), true); elements.addAll(removeEmptyElements(Arrays.asList(m.group(3).split("[\\.|/]")), false)); elements = packageNameCleanup(elements); return StringUtils.join(elements, "."); } else { throw new MalformedURLException("Illegal IRI for ontology: " + uriString); } }
From source file:pcgen.gui2.tools.DesktopBrowserLauncher.java
/** * View a URL in a browser//from www . j av a2s .co m * * @param url URL to display in browser. * @throws IOException if the URL is bad or the browser can not be launched */ public static void viewInBrowser(URL url) throws IOException { try { viewInBrowser(url.toURI()); } catch (final URISyntaxException e) { throw new MalformedURLException(e.getMessage()); } }
From source file:com.gargoylesoftware.htmlunit.util.URLCreator.java
protected URL toNormalUrl(final String url) throws MalformedURLException { final URL response = new URL(url); if (response.getProtocol().startsWith("http") && StringUtils.isEmpty(response.getHost())) { throw new MalformedURLException("Missing host name in url: " + url); }/* www. ja va2s. c om*/ return response; }
From source file:org.eclipse.skalli.commons.URLUtils.java
/** * Converts a given string into a corresponding URL. * <p>/*from w ww. j av a 2 s. com*/ * Encodes path and/or query parts of the given string according to * {@link URI#URI(String, String, String, int, String, String, String)}. * For example, blanks in the path are converted to <tt>%20</tt>. * * @param s the string to convert to an URL. * @return an URL, or <code>null</code> if the string is <code>null</code>, empty or whitespace. * * @throws MalformedURLException if the given string is not a valid URL and cannot be * "sanitized" to yield a valid URL even after proper encoding of its parts. */ public static URL stringToURL(String s) throws MalformedURLException { if (StringUtils.isBlank(s)) { return null; } URI uri = null; try { uri = new URI(s); } catch (URISyntaxException e) { URL url = new URL(s); try { uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); } catch (URISyntaxException e1) { MalformedURLException e2 = new MalformedURLException(e1.getMessage()); e2.initCause(e1); throw e2; } } return new URL(uri.toASCIIString()); }
From source file:at.gv.egiz.pdfas.web.helper.RemotePDFFetcher.java
public static String[] extractSensitiveInformationFromURL(String pdfURL) throws IOException { if (pdfURL.contains("@")) { String lowerURL = pdfURL.toLowerCase(); int startIndex = 0; int atIndex = pdfURL.indexOf("@"); startIndex = lowerURL.indexOf("https://"); if (startIndex >= 0) { startIndex = startIndex + "https://".length(); } else {/*from www .j ava2 s. c om*/ startIndex = lowerURL.indexOf("http://"); if (startIndex >= 0) { startIndex = startIndex + "http://".length(); } } if (startIndex < 0) { throw new MalformedURLException("Username/Password Part found, but no scheme found"); } if (atIndex < 0) { throw new MalformedURLException("@ Part found, but index not found"); } String usernamePasswordPart = pdfURL.substring(startIndex, atIndex); pdfURL = pdfURL.substring(0, startIndex) + pdfURL.substring(atIndex + 1); logger.debug("Modified URL: {}", pdfURL); String[] usernamePassword = usernamePasswordPart.split(":"); if (usernamePassword.length == 2) { return new String[] { pdfURL, URLDecoder.decode(usernamePassword[0]), URLDecoder.decode(usernamePassword[1]) }; } else { throw new MalformedURLException("Wrong or empty username/password part"); } } else { return new String[] { pdfURL }; } }