Example usage for java.net URI getSchemeSpecificPart

List of usage examples for java.net URI getSchemeSpecificPart

Introduction

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

Prototype

public String getSchemeSpecificPart() 

Source Link

Document

Returns the decoded scheme-specific part of this URI.

Usage

From source file:com.esri.geoportal.harvester.folder.FolderBroker.java

private File generateFileName(URI brokerUri, URI sourceUri, String id) {
    URI ssp = URI.create(brokerUri.getSchemeSpecificPart());
    String root = StringUtils.defaultIfEmpty(ssp.getHost(), ssp.getPath());
    File rootFolder = definition.getRootFolder().toPath().resolve(root).toFile();

    File fileName = rootFolder;//from   w  w  w . j  a  v  a2 s  . com
    if (sourceUri.getPath() != null) {
        List<String> subFolder = splitPath(sourceUri.getPath().replaceAll("/[a-zA-Z]:/|/$", ""));
        if (!subFolder.isEmpty() && subFolder.get(0).equals(root)) {
            subFolder.remove(0);
        }
        for (String sf : subFolder) {
            fileName = new File(fileName, sf);
        }
        if (!fileName.getName().contains(".")) {
            fileName = fileName.getParentFile().toPath().resolve(fileName.getName() + ".xml").toFile();
        }
    } else {
        fileName = new File(fileName, id + ".xml");
    }

    return fileName;
}

From source file:org.taverna.server.master.notification.NotificationEngine.java

/**
 * Dispatch a message over the notification fabric.
 * //from   ww  w  . j  a  va 2s  .c o m
 * @param originator
 *            What workflow run was the source of this message?
 * @param destination
 *            Where the message should get delivered to. The correct format
 *            of this is either as a URI of some form (where the scheme
 *            determines the dispatcher) or as an invalid URI in which case
 *            it is just tried against the possibilities to see if any
 *            succeeds.
 * @param subject
 *            The subject line of the message.
 * @param message
 *            The plain text body of the message.
 * @throws Exception
 *             If anything goes wrong with the dispatch process.
 */
public void dispatchMessage(TavernaRun originator, String destination, String subject, String message)
        throws Exception {
    if (destination != null && !destination.trim().isEmpty()) {
        try {
            URI toURI = new URI(destination.trim());
            dispatchToChosenTarget(originator, toURI.getScheme(), toURI.getSchemeSpecificPart(), subject,
                    message);
        } catch (java.net.URISyntaxException e) {
            // Ignore
        }
    }
    dispatchUniversally(originator, subject, message);
}

From source file:com.anrisoftware.simplerest.oanda.core.DefaultAccount.java

/**
 * @see DefaultAccountFactory#create(URI)
 *///from   w  w  w .  j  av a  2  s  .  c o  m
@AssistedInject
DefaultAccount(@Assisted URI uri) {
    isTrue(uri.getScheme().equals(URI_SCHEME), URI_MESSAGE);
    String[] split = split(uri.getSchemeSpecificPart(), ":");
    setAccount(split[0]);
    setAccessToken(split[1]);
}

From source file:com.comoyo.emjar.EmJarTest.java

protected File getResourceFile(String name) throws URISyntaxException {
    final ClassLoader cl = getClass().getClassLoader();
    final URI base = cl.getResource("com/comoyo/emjar/").toURI();
    URIBuilder builder = new URIBuilder(base);
    builder.setPath(builder.getPath() + name);
    final URI uri = builder.build();
    if (!"file".equals(uri.getScheme())) {
        throw new IllegalArgumentException("Resource " + name + " not present as file (" + uri + ")");
    }/*from   www  .j av  a  2s .co  m*/
    return new File(uri.getSchemeSpecificPart());
}

From source file:de.openknowledge.cdi.common.property.source.FilePropertySourceLoader.java

public Properties load(URI resource) {
    Properties properties = new Properties();

    try {//w ww.j  a  va 2s.c  o m
        File file;
        if (resource.isOpaque()) {
            file = new File(resource.getSchemeSpecificPart());
        } else {
            file = new File(resource);
        }
        if (file.exists() && file.canRead()) {
            LOG.debug("Loading properties from file " + file);
            loadFromStream(properties, new FileInputStream(file));
        } else {
            LOG.debug("Unable to load properties from file " + file
                    + ". File does not exist or is not readable.");
        }
    } catch (IOException e) {
        LOG.warn("Error loading properties from file resource " + resource + ": " + e.getMessage());
    }

    return properties;
}

From source file:com.google.caja.plugin.DataUriFetcher.java

public final byte[] fetchBinary(ExternalReference ref, String mimeType) throws UriFetchException {
    URI uri = ref.getUri();
    if (!isDataUri(uri)) {
        throw new UriFetchException(ref, mimeType);
    }/*w  ww  .j av a  2s  .c o m*/

    String dataUri = uri.getSchemeSpecificPart();
    // We split the data uri into the mimetype and the data portion by
    // searching for the first comma (whether encoded or not).  This is
    // not a complete parse of data URIs - specifically if the mime-type
    // contains a comma
    Matcher m = DATA_URI_RE.matcher(dataUri);
    if (m.find()) {
        try {
            String charset = charsetFromMime(m.group(DATA_URI.TYPE.ordinal()));
            boolean base64 = null != m.group(DATA_URI.BASE64.ordinal());
            byte[] encoded = m.group(DATA_URI.DATA.ordinal()).getBytes(charset);
            byte[] decoded = base64 ? new Base64().decode(encoded) : encoded;
            return decoded;
        } catch (UnsupportedEncodingException e) {
            throw new UriFetcher.UriFetchException(ref, mimeType, e);
        }
    }
    throw new UriFetcher.UriFetchException(ref, mimeType);
}

From source file:de.jfachwert.net.Telefonnummer.java

/**
 * Eine Telefonnummer lasesst sich auch ueber eine URI kreieren. Der
 * RFC 3966 schlaegt dabei "tel:" als Schema vor.
 *
 * @param uri z.B. "tel:+49-30-1234567"//from   w  w  w  . j ava  2s.  c  om
 */
public Telefonnummer(URI uri) {
    this(uri.getSchemeSpecificPart());
}

From source file:com.anrisoftware.globalpom.checkfilehash.CheckFileHash.java

private String readExpectedHash(URI hashResource) throws Exception {
    if (StringUtils.equals(hashResource.getScheme(), "md5")) {
        return hashResource.getSchemeSpecificPart();
    } else if (StringUtils.equals(hashResource.getScheme(), "sha1")) {
        return hashResource.getSchemeSpecificPart();
    } else {//from   w ww. j  a  v  a  2  s  . c o  m
        String line = readLines(hashResource.toURL().openStream()).get(0);
        String hash = StringUtils.split(line, SEP)[0];
        return hash;
    }
}

From source file:org.metaborg.intellij.resources.DefaultIntelliJResourceService.java

/**
 * Returns the path of the URI./* w  w  w  . ja v  a 2  s.  co  m*/
 *
 * @param uri The URI.
 * @return The path of the URI; or <code>null</code> when the URI contains no path.
 */
@Nullable
private String getPath(final URI uri) {
    if (uri.getPath() == null) {
        final String part = uri.getSchemeSpecificPart();
        return getPath(toUri(part));
    }
    return uri.getPath();
}

From source file:com.cliqset.salmon.keyfinder.OpenXRDKeyFinder.java

private MagicKey fetchKey(URI uri) throws MagicSigException {
    if (SCHEME_DATA.equals(uri.getScheme())) {
        String data = uri.getSchemeSpecificPart();

        if (data.contains(",")) {
            String[] split = data.split(",");
            byte[] dataBytes = null;
            try {
                dataBytes = split[1].getBytes("ASCII");
            } catch (UnsupportedEncodingException e) {
            }//www.  j av a 2s  .co m
            return new MagicKey(dataBytes);
            //work around for status.net 
        } else {
            String[] split = data.split(";");
            byte[] dataBytes = null;
            try {
                dataBytes = split[1].getBytes("ASCII");
            } catch (UnsupportedEncodingException e) {
            }
            return new MagicKey(dataBytes);
        }
    } else if (SCHEME_HTTP.equals(uri.getScheme()) || SCHEME_HTTPS.equals(uri.getScheme())) {
        HttpGet get = new HttpGet(uri);
        try {
            HttpResponse response = httpClient.execute(get);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            response.getEntity().writeTo(baos);
            return new MagicKey(baos.toByteArray());
        } catch (ClientProtocolException cpe) {
            throw new MagicSigException(cpe);
        } catch (IOException ioe) {
            throw new MagicSigException(ioe);
        }
    } else {
        throw new MagicSigException(
                "URI Scheme " + uri.getScheme() + " is not supported when resolving magic key.");
    }
}