Example usage for java.net MalformedURLException MalformedURLException

List of usage examples for java.net MalformedURLException MalformedURLException

Introduction

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

Prototype

public MalformedURLException() 

Source Link

Document

Constructs a MalformedURLException with no detail message.

Usage

From source file:net.yacy.cora.document.id.MultiProtocolURL.java

/**
 * create a standard java URL./*from  w  ww. ja va2 s  .c o m*/
 * Please call isHTTP(), isHTTPS() and isFTP() before using this class
 */
public java.net.URL getURL() throws MalformedURLException {
    if (!(isHTTP() || isHTTPS() || isFTP()))
        throw new MalformedURLException();
    return new java.net.URL(this.toNormalform(false));
}

From source file:net.yacy.cora.document.id.MultiProtocolURL.java

/**
 * create a standard java File./*w w  w  . j ava  2  s.  co  m*/
 * Please call isFile() before using this class
 */
public java.io.File getFSFile() throws MalformedURLException {
    if (!isFile())
        throw new MalformedURLException();
    return new java.io.File(unescape(this.toNormalform(true)).substring("file://".length()));
}

From source file:net.yacy.cora.document.id.MultiProtocolURL.java

/**
 * create a smb File//from www.  jav a  2 s. com
 * Please call isSMB() before using this class
 * @throws MalformedURLException
 */
public SmbFile getSmbFile() throws MalformedURLException {
    if (!isSMB())
        throw new MalformedURLException();
    final String url = unescape(this.toNormalform(true));
    return new SmbFile(url);
}

From source file:org.sakaiproject.citation.tool.CitationHelperAction.java

protected String validateURL(String url) throws MalformedURLException {
    if (url == null || url.trim().equals("")) {
        throw new MalformedURLException();
    }/*from   w w w.ja v a 2s.  c o  m*/

    url = url.trim();

    // does this URL start with a transport?
    if (url.indexOf("://") == -1) {
        // if it's missing the transport, add http://
        url = "http://" + url;
    }

    // valid protocol?
    try {
        // test to see if the input validates as a URL.
        // Checks string for format only.
        URL u = new URL(url);
    } catch (MalformedURLException e1) {
        try {
            Pattern pattern = Pattern.compile("\\s*([a-zA-Z0-9]+)://([^\\n]+)");
            Matcher matcher = pattern.matcher(url);
            if (matcher.matches()) {
                // if URL has "unknown" protocol, check remaider with
                // "http" protocol and accept input it that validates.
                URL test = new URL("http://" + matcher.group(2));
            } else {
                throw e1;
            }
        } catch (MalformedURLException e2) {
            throw e1;
        }
    }
    return url;
}