List of usage examples for java.net MalformedURLException MalformedURLException
public MalformedURLException(String msg)
From source file:Main.java
/** * Make a URL from the given string.//from ww w . ja v a 2 s .c o m * * <p> * If the string is a properly formatted file URL, then the file * portion will be made canonical. * * <p> * If the string is an invalid URL then it will be converted into a * file URL. * * @param urlspec The string to construct a URL for. * @param relativePrefix The string to prepend to relative file * paths, or null to disable prepending. * @return A URL for the given string. * * @throws MalformedURLException Could not make a URL for the given string. */ public static URL toURL(String urlspec, final String relativePrefix) throws MalformedURLException { urlspec = urlspec.trim(); URL url; try { url = new URL(urlspec); if (url.getProtocol().equals("file")) { url = makeURLFromFilespec(url.getFile(), relativePrefix); } } catch (Exception e) { // make sure we have a absolute & canonical file url try { url = makeURLFromFilespec(urlspec, relativePrefix); } catch (IOException n) { // // jason: or should we rethrow e? // throw new MalformedURLException(n.toString()); } } return url; }
From source file:org.tinymediamanager.scraper.http.CachedUrl.java
public CachedUrl(String url) throws MalformedURLException { this.url = url; // morph to URI to check syntax of the url try {//from w ww . ja va 2s . co m this.uri = morphStringToUri(url); } catch (URISyntaxException e) { throw new MalformedURLException(url); } }
From source file:Main.java
/** * Make a URL to access LNI WebDAV resource, given a LNI SOAP "endpoint" URL * and a relative WebDAV URI. Since the LNI SOAP interface does not include * any means to submit or disseminate DSpace Items, it relies on the WebDAV * LNI's GET and PUT methods. To make a WebDAV request, the client must * first construct a WebDAV URL; this function makes that step much more * convenient.// www .ja v a2 s . c o m * <p> * This is the inverse of makeLNIURI. * <p> * Since the actual Web servlet supporting the LNI SOAP interface can also * respond to WebDAV GET and PUT methods, there is a straightforward way to * construct the URL: * <p> * 1. Remove the last pathname element from the SOAP "endpoint" URL, * including the '/' (slash) separator character. * <p> * 2. Append the "relative URI" returned e.g. by the SOAP * <code>lookup()</code> function to this URL. * <p> * 3. Add the packager specification and other query arguments, e.g. by * appending "?packager=METS" * * @param endpoint full URL of LNI Soap endpoint, as used with SOAP. * @param davURI relative URI of DAV resource, as returned by lookup(). assumed * to start with "/". May be null. * @param packager name of packager to use to retrieve/submit Item, or null. * * @return new URL. * * @throws MalformedURLException if endpoint is unacceptable URL, or the resulting construct * is not an acceptable URL. */ public static URL makeDAVURL(String endpoint, String davURI, String packager) throws MalformedURLException { /* chop off last path element */ int s = endpoint.lastIndexOf('/'); if (s < 0) { throw new MalformedURLException("Illegal LNI SOAP endpoint, no path separators (/) found: " + endpoint); } /* paste up URL.. */ String result = endpoint.substring(0, s); if (davURI != null) { result += davURI; if (packager != null) { result += "?package=" + packager; } } return new URL(result); }
From source file:com.linkedin.urls.Url.java
/** * Returns a url given a single url.// www. java 2 s. c o m */ public static Url create(String url) throws MalformedURLException { String formattedString = UrlUtil.removeSpecialSpaces(url.trim().replace(" ", "%20")); List<Url> urls = new UrlDetector(formattedString, UrlDetectorOptions.ALLOW_SINGLE_LEVEL_DOMAIN).detect(); if (urls.size() == 1) { return urls.get(0); } else if (urls.size() == 0) { throw new MalformedURLException("We couldn't find any urls in string: " + url); } else { throw new MalformedURLException("We found more than one url in string: " + url); } }
From source file:com.sap.prd.mobile.ios.ota.lib.LibUtils.java
/** * Generates the link to the IPA file based on the referer to the HTML file, the used * ipaClassifier and otaClassifier. If no classifiers are specified the IPA URL will have the same * value as the referer, except of the file extension. * // ww w . j av a 2 s. co m * @param referer * Referer to the HTML file located next to the IPA file * @param ipaClassifier * classifier used in the IPA file. Can be null. * @param otaClassifier * classifier used in the OTA HTML file. Can be null. * @return * @throws MalformedURLException */ public static URL generateDirectIpaUrl(String referer, String ipaClassifier, String otaClassifier) throws MalformedURLException { int idx = referer.lastIndexOf("."); if (idx > 0 && idx > referer.length() - 6) { String ipaUrl = referer.substring(0, idx) + ".ipa"; if (!StringUtils.isEmpty(otaClassifier)) { if (!StringUtils.isEmpty(ipaClassifier)) { ipaUrl = replaceLast(ipaUrl, "-" + otaClassifier, "-" + ipaClassifier); } else { ipaUrl = replaceLast(ipaUrl, "-" + otaClassifier, ""); } } else { if (!StringUtils.isEmpty(ipaClassifier)) { ipaUrl = ipaUrl.substring(0, idx) + "-" + ipaClassifier + ".ipa"; } } return new URL(ipaUrl); } else { throw new MalformedURLException("Referer does not end with a file (e.g. .htm): " + referer); } }
From source file:uk.ac.ucl.cs.cmic.giftcloud.restserver.GiftCloudServer.java
public GiftCloudServer(final PixelDataAnonymiserFilterCache filters, final RestClientFactory restClientFactory, final String giftCloudServerUrlString, final GiftCloudProperties giftCloudProperties, final UserCallback userCallback, final GiftCloudReporter reporter) throws MalformedURLException { this.giftCloudServerUrlString = giftCloudServerUrlString; this.giftCloudProperties = giftCloudProperties; this.reporter = reporter; if (StringUtils.isBlank(giftCloudServerUrlString)) { throw new MalformedURLException("Please set the URL for the GIFT-Cloud server."); }/*from www . ja va 2s. c om*/ try { giftCloudUri = new URI(giftCloudServerUrlString); } catch (URISyntaxException e) { throw new MalformedURLException( "The GIFT-Cloud server name " + giftCloudServerUrlString + " is not a valid URL."); } restClient = restClientFactory.create(giftCloudServerUrlString, giftCloudProperties, userCallback, reporter); projectCache = new ProjectCache(restClient, filters); }
From source file:org.opensextant.xtext.collectors.sharepoint.SPLink.java
/** * TODO: fix site vs. base link// w w w . j a va 2 s. c om * * @param link * a URL * @param base * where the URL was found * @throws MalformedURLException * err that happens if URLs are poorly formatted. * @throws UnsupportedEncodingException * err that happens occasionally * @throws NoSuchAlgorithmException * err that never happens */ public SPLink(String link, URL base) throws MalformedURLException, UnsupportedEncodingException, NoSuchAlgorithmException { super(link, base, base); if (isSharepointFolder()) { urlValue = StringEscapeUtils.unescapeHtml4(URLDecoder.decode(urlValue, "UTF-8")); } if (isAbsolute()) { absoluteURL = new URL(urlValue); } else { if (base == null) { throw new MalformedURLException("Unknown parent URL for arg baseUrl"); } referrerURL = base; // aka Parent or containing page, folder or // other node absoluteURL = new URL(referrerURL, urlValue); } if (isSharepointFolder()) { parseURL(); simplifiedURL = new URL(referrerURL, params.getProperty("RootFolder")); String[] pathParts = simplifiedURL.getPath().split("/"); StringBuilder buf = new StringBuilder(); for (String p : pathParts) { if (p.length() > 0) { buf.append('/'); buf.append(encodePathSegment(p)); } } simplifiedURL = new URL(simplifiedURL, buf.toString()); } }
From source file:org.apache.felix.karaf.deployer.spring.SpringURLHandler.java
/** * Open the connection for the given URL. * * @param url the url from which to open a connection. * @return a connection on the specified URL. * @throws IOException if an error occurs or if the URL is malformed. *//*from w w w . j a v a 2 s . c om*/ @Override public URLConnection openConnection(URL url) throws IOException { if (url.getPath() == null || url.getPath().trim().length() == 0) { throw new MalformedURLException("Path can not be null or empty. Syntax: " + SYNTAX); } springXmlURL = new URL(url.getPath()); logger.debug("Spring xml URL is: [" + springXmlURL + "]"); return new Connection(url); }
From source file:org.apache.felix.karaf.deployer.blueprint.BlueprintURLHandler.java
/** * Open the connection for the given URL. * * @param url the url from which to open a connection. * @return a connection on the specified URL. * @throws IOException if an error occurs or if the URL is malformed. *//*from w ww .j av a 2 s . co m*/ @Override public URLConnection openConnection(URL url) throws IOException { if (url.getPath() == null || url.getPath().trim().length() == 0) { throw new MalformedURLException("Path can not be null or empty. Syntax: " + SYNTAX); } blueprintXmlURL = new URL(url.getPath()); logger.debug("Blueprint xml URL is: [" + blueprintXmlURL + "]"); return new Connection(url); }
From source file:org.apache.nifi.util.file.classloader.ClassLoaderUtils.java
protected static URL[] getURLsForClasspath(List<String> modulePaths, FilenameFilter filenameFilter) throws MalformedURLException { List<URL> additionalClasspath = new LinkedList<>(); if (modulePaths != null) { for (String modulePathString : modulePaths) { // If the path is already a URL, just add it (but don't check if it exists, too expensive and subject to network availability) boolean isUrl = true; try { additionalClasspath.add(new URL(modulePathString)); } catch (MalformedURLException mue) { isUrl = false;/*from w w w.ja va 2 s . co m*/ } if (!isUrl) { File modulePath = new File(modulePathString); if (modulePath.exists()) { additionalClasspath.add(modulePath.toURI().toURL()); if (modulePath.isDirectory()) { File[] files = modulePath.listFiles(filenameFilter); if (files != null) { for (File jarFile : files) { additionalClasspath.add(jarFile.toURI().toURL()); } } } } else { throw new MalformedURLException("Path specified does not exist"); } } } } return additionalClasspath.toArray(new URL[additionalClasspath.size()]); }