Example usage for java.net URI getPath

List of usage examples for java.net URI getPath

Introduction

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

Prototype

public String getPath() 

Source Link

Document

Returns the decoded path component of this URI.

Usage

From source file:com.textocat.textokit.commons.io.IoUtils.java

/**
 * @param uri a source URI/*  ww w. j a va 2s .  c o m*/
 * @return a Path part from the given URI, never null
 */
public static Path extractPath(URI uri) {
    if (uri.isOpaque()) {
        throw new IllegalArgumentException(format("Opaque URIs are not supported: %s", uri));
    }
    String path = uri.getPath();
    Preconditions.checkState(path != null, "URI path is null: " + uri);
    return Paths.get(path);
}

From source file:co.cask.cdap.internal.app.runtime.LocalizationUtils.java

/**
 * Returns a local {@link File} for the specified {@link LocalizeResource}. If the specified {@link LocalizeResource}
 * points to a local file already, it simply returns a {@link File} object for it. If it is not local, then the
 * method will try to download the resource to a local temporary file and return it.
 *
 * @param resource the {@link LocalizeResource} for which a local file is requested
 * @param tempDir the {@link File directory} to download the file to if it is a remote file
 * @return a local {@link File} for the specified resource
 */// ww w . java 2  s . co  m
private static File getFileToLocalize(LocalizeResource resource, File tempDir) throws IOException {
    URI uri = resource.getURI();
    if ("file".equals(uri.getScheme())) {
        // Local file. Just return a File object for the file.
        return new File(uri.getPath());
    }
    URL url = uri.toURL();
    String name = new File(uri.getPath()).getName();
    File tempFile = new File(tempDir, name);
    Files.copy(Resources.newInputStreamSupplier(url), tempFile);
    return tempFile;
}

From source file:com.meltmedia.cadmium.servlets.AbstractSecureRedirectStrategy.java

/**
 * Returns a new URI object, based on the specified URI template, with an updated port (scheme) and port.  If the port
 * number is -1, then the default port is used in the resulting URI. 
 * // ww  w  . j  av  a2s .c  o  m
 * @param protocol the new protocol (scheme) in the resulting URI.
 * @param port the new port in the resulting URI, or the default port if -1 is provided.
 * @param template the source of all other values for the new URI.
 * @return a new URI object with the updated protocol and port.
 * @throws URISyntaxException 
 */
public static URI changeProtocolAndPort(String protocol, int port, URI template) throws URISyntaxException {
    return new URI(protocol, template.getUserInfo(), template.getHost(), port, template.getPath(),
            template.getQuery(), null);
}

From source file:com.intelligentsia.dowsers.entity.store.FileEntityStoreTest.java

public static File getRoot() {
    // Calculates the root directory of the demo project.
    URI uri;
    try {/*from   w ww  .  j  a  v a  2  s  .  co  m*/
        uri = FileEntityStoreTest.class.getResource("FileEntityStoreTest.class").toURI();
    } catch (final URISyntaxException e) {
        throw Throwables.propagate(e);
    }
    final String path = new File(uri.getPath()).getAbsolutePath();
    final String subPath = "\\target\\test-classes\\com\\intelligentsia\\dowsers\\entity\\store\\FileEntityStoreTest.class";
    final File root = new File(new File(path.substring(0, path.length() - subPath.length())),
            File.separator + "target" + File.separator + "output");

    if (root.exists()) {
        try {
            FileUtils.deleteDirectory(root);
        } catch (final IOException e) {
        }
    }

    return root;
}

From source file:onl.area51.httpd.action.Actions.java

static void renderResource(Class<?> clazz, Request r, URI uri, String base) throws IOException {
    String url = uri.getPath();
    if (url.contains("//")) {
        url = url.replace("//", "/");
    }/*  w w w.  j  a  v a  2  s  .c o  m*/
    if (!url.contains("/..")) {
        String path = base + (url.startsWith("/") ? "" : "/") + url;
        if (path.endsWith("/")) {
            path = path + "index.html";
        }
        InputStream is = clazz.getResourceAsStream(path);
        if (is != null) {
            if (r.isResponsePresent()) {
                // Hope the content type is the same, just add to the existing response.
                // This is usually due to including html content into an existing page
                try {
                    r.getResponse().copy(is);
                } finally {
                    is.close();
                }
            } else {
                // Treat as it's own entity
                r.getHttpResponse().setEntity(new InputStreamEntity(is));
            }
        }
    }
}

From source file:de.metas.procurement.webui.ui.view.PasswordResetView.java

public static final URI buildPasswordResetURI(final String passwordResetKey) {
    try {//from   ww w. ja v  a  2 s.  co m
        final URI uri = Page.getCurrent().getLocation();
        final String query = null;
        final String fragment = MFNavigator.createURIFragment(NAME, passwordResetKey);
        final URI resetURI = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), query, fragment);
        System.out.println(resetURI);
        return resetURI;
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}

From source file:com.textocat.textokit.commons.util.CorpusUtils.java

/**
 * @param baseDir/*  w w w.  j  a  v a2  s. c  o  m*/
 * @return function that returns the URI of an arg File relative to the URI
 * of the given baseDir.
 * @see #relativePathFunction(File)
 */
public static Function<File, URI> relativeURIFunction(final File baseDir) {
    return new Function<File, URI>() {
        private URI baseURI = baseDir.toURI();

        @Override
        public URI apply(File arg) {
            URI relURI = baseURI.relativize(arg.toURI());
            try {
                return new URI("file", relURI.getPath(), null);
            } catch (URISyntaxException e) {
                throw new IllegalStateException(e);
            }
        }
    };
}

From source file:cat.calidos.morfeu.model.transform.injection.StringFormatModule.java

@Produces
@Named("EffectiveContent")
public static String produceEffectiveContent(@Named("DestinationContentURI") URI uri,
        @Named("TransformedContent") Producer<String> transformedContentProducer,
        @Named("Content") Producer<String> contentProducer) throws TransformException {

    String name = FilenameUtils.getName(uri.getPath());

    try {//from w  ww  .j a  va2s.c o  m
        if (name.endsWith("yaml")) {

            return transformedContentProducer.get().get();

        } else {

            return contentProducer.get().get(); // no transformation required

        }
    } catch (InterruptedException | ExecutionException e) {
        log.error("Could not get effective content for '{}' ({})", uri, e);
        throw new TransformException("Problem when getting effective content to save '" + uri + "'", e);
    }

}

From source file:de.mpg.imeji.presentation.util.SearchAndExportHelper.java

public static String getCitation(Publication publication) {
    URI uri = publication.getUri();
    URI searchAndExportUri = URI.create("http://" + uri.getHost() + "/search/SearchAndExport");
    String itemId = null;//from w w w .java2 s .c o  m
    if (uri.getQuery() != null && uri.getQuery().contains("itemId=")) {
        itemId = uri.getQuery().split("itemId=")[1];
    } else if (uri.getPath() != null && uri.getPath().contains("/item/")) {
        itemId = uri.getPath().split("/item/")[1];
    }
    if (UrlHelper.isValidURI(searchAndExportUri)) {
        try {
            HttpClient client = new HttpClient();
            String exportUri = searchAndExportUri.toString() + "?cqlQuery=" + URLEncoder.encode(
                    "escidoc.objid=" + itemId + " or escidoc.property.version.objid=" + itemId, "ISO-8859-1")
                    + "&exportFormat=" + publication.getExportFormat() + "&outputFormat=html_linked";
            GetMethod method = new GetMethod(exportUri);
            client.executeMethod(method);
            return method.getResponseBodyAsString();
        } catch (Exception e) {
            return null;
        }
    }
    return null;
}

From source file:net.sf.jasperreports.eclipse.wizard.project.ProjectUtil.java

/**
 * Checks if a possible project could contain existing resources.
 * /*from  www  .j  a  v a2 s .  c  om*/
 * @param prjName
 *          the project name
 * @return
 */
public static boolean hasExistingContent(String prjName) {
    try {
        URI rootLocation = ResourcesPlugin.getWorkspace().getRoot().getLocationURI();
        URI prjLocation = new URI(rootLocation.getScheme(), null,
                Path.fromPortableString(rootLocation.getPath()).append(prjName).toString(), null);
        IFileStore file = EFS.getStore(prjLocation);
        return file.fetchInfo().exists();
    } catch (URISyntaxException e) {
        JasperReportsPlugin.getDefault().logError(e);
    } catch (CoreException e) {
        JasperReportsPlugin.getDefault().logError(e);
    }
    return false;
}