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:org.fcrepo.apix.jena.impl.JenaServiceRegistry.java

private static boolean hasSameRepresentation(final URI a, final URI b) {
    try {//from w w w.  j  a  va 2  s  .  co  m
        return new URI(a.getScheme(), a.getAuthority(), a.getPath(), null, null)
                .equals(new URI(b.getScheme(), b.getAuthority(), b.getPath(), null, null));
    } catch (final URISyntaxException e) {
        throw new RuntimeException("Shoud never happen", e);
    }
}

From source file:controllers.Common.java

@Util
public static String toSafeRedirectURL(String url) {
    String cleanUrl = "";
    try {/*from   w  w  w.ja  v a2 s . co  m*/
        // Remove Host and port from referrer
        URI uriObject = new URI(url);
        cleanUrl += uriObject.getPath();

        String query = uriObject.getQuery();
        if (!StringUtils.isBlank(query)) {
            cleanUrl += "?" + query;
        }
    } catch (URISyntaxException ignore) {
        Logger.error(ignore.getMessage());
    }

    return cleanUrl;
}

From source file:com.googlesource.gerrit.plugins.supermanifest.JiriManifestParser.java

public static JiriProjects getProjects(GerritRemoteReader reader, String repoKey, String ref, String manifest)
        throws ConfigInvalidException, IOException {

    try (RepoMap<String, Repository> repoMap = new RepoMap<>()) {
        repoMap.put(repoKey, reader.openRepository(repoKey));
        Queue<ManifestItem> q = new LinkedList<>();
        q.add(new ManifestItem(repoKey, manifest, ref, "", false));
        HashMap<String, HashSet<String>> processedRepoFiles = new HashMap<>();
        HashMap<String, JiriProjects.Project> projectMap = new HashMap<>();

        while (q.size() != 0) {
            ManifestItem mi = q.remove();
            Repository repo = repoMap.get(mi.repoKey);
            if (repo == null) {
                repo = reader.openRepository(mi.repoKey);
                repoMap.put(mi.repoKey, repo);
            }//from  ww  w. ja v  a 2 s  .c  o m
            HashSet<String> processedFiles = processedRepoFiles.get(mi.repoKey);
            if (processedFiles == null) {
                processedFiles = new HashSet<String>();
                processedRepoFiles.put(mi.repoKey, processedFiles);
            }
            if (processedFiles.contains(mi.manifest)) {
                continue;
            }
            processedFiles.add(mi.manifest);
            JiriManifest m;
            try {
                m = parseManifest(repo, mi.ref, mi.manifest);
            } catch (JAXBException | XMLStreamException e) {
                throw new ConfigInvalidException("XML parse error", e);
            }

            for (JiriProjects.Project project : m.projects.getProjects()) {
                project.fillDefault();
                if (mi.revisionPinned && project.Key().equals(mi.projectKey)) {
                    project.setRevision(mi.ref);
                }
                if (projectMap.containsKey(project.Key())) {
                    if (!projectMap.get(project.Key()).equals(project))
                        throw new ConfigInvalidException(String.format(
                                "Duplicate conflicting project %s in manifest %s\n%s\n%s", project.Key(),
                                mi.manifest, project.toString(), projectMap.get(project.Key()).toString()));
                } else {
                    projectMap.put(project.Key(), project);
                }
            }

            URI parentURI;
            try {
                parentURI = new URI(mi.manifest);
            } catch (URISyntaxException e) {
                throw new ConfigInvalidException("Invalid parent URI", e);
            }
            for (JiriManifest.LocalImport l : m.imports.getLocalImports()) {
                ManifestItem tw = new ManifestItem(mi.repoKey, parentURI.resolve(l.getFile()).getPath(), mi.ref,
                        mi.projectKey, mi.revisionPinned);
                q.add(tw);
            }

            for (JiriManifest.Import i : m.imports.getImports()) {
                i.fillDefault();
                URI uri;
                try {
                    uri = new URI(i.getRemote());
                } catch (URISyntaxException e) {
                    throw new ConfigInvalidException("Invalid URI", e);
                }
                String iRepoKey = new Project.NameKey(StringUtils.strip(uri.getPath(), "/")).toString();
                String iRef = i.getRevision();
                boolean revisionPinned = true;
                if (iRef.isEmpty()) {
                    iRef = REFS_HEADS + i.getRemotebranch();
                    revisionPinned = false;
                }

                ManifestItem tmi = new ManifestItem(iRepoKey, i.getManifest(), iRef, i.Key(), revisionPinned);
                q.add(tmi);
            }
        }
        return new JiriProjects(projectMap.values().toArray(new JiriProjects.Project[0]));
    }
}

From source file:org.wso2.security.tools.product.manager.handler.HttpRequestHandler.java

/**
 * Send HTTP GET request/*from  www  . ja  v a  2  s  .c o m*/
 *
 * @param request Requested URI
 * @return HTTPResponse after executing the command
 */
public static HttpResponse sendGetRequest(URI request) {
    try {
        HttpClientBuilder clientBuilder = HttpClients.custom();
        HttpClient httpClient = clientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(3, false))
                .build();
        HttpGet httpGetRequest = new HttpGet(request);
        return httpClient.execute(httpGetRequest);
    } catch (IOException e) {
        LOGGER.error("Error occurred while sending GET request to " + request.getPath(), e);
    }
    return null;
}

From source file:edu.stolaf.cs.wmrserver.JobServiceHandler.java

/**
 * Relativize the given path with respect to the WMR home directory
 *///from   www . ja  v a2  s.c o m
public static Path relativizePath(Path parentPath, Path childPath) {
    URI relative = parentPath.toUri().relativize(childPath.toUri());
    return new Path(relative.getScheme(), relative.getAuthority(), relative.getPath());
}

From source file:edu.usc.goffish.gofs.namenode.DataNode.java

private static Path convertLocalURIToPath(URI localURI) throws IOException {
    if (localURI == null || localURI.isOpaque() || !localURI.isAbsolute()
            || !"file".equalsIgnoreCase(localURI.getScheme())) {
        throw new IllegalArgumentException();
    }/*from   w w w  . j a v  a 2  s.co  m*/
    if (!URIHelper.isLocalURI(localURI)) {
        throw new IOException("uri host " + localURI.getHost() + " is not local");
    }

    String path = localURI.getPath();
    if (path == null) {
        path = "/";
    }
    return Paths.get(URI.create("file://" + path));
}

From source file:com.microsoft.gittf.core.util.URIUtil.java

/**
 * Ensures that git tf is connecting to the right hosted server scheme and
 * path.//from  www.  j  a va 2  s.  c  om
 * 
 * @param uri
 * @return
 * @throws URISyntaxException
 */
private static URI updateIfNeededForHostedService(URI uri) throws URISyntaxException {
    Check.notNull(uri, "uri"); //$NON-NLS-1$

    String hostedServer = System.getProperty("tfs.hosted"); //$NON-NLS-1$
    if (hostedServer == null || hostedServer.length() == 0) {
        hostedServer = hostedServerName;
    }

    if (uri.getHost().toLowerCase().contains(hostedServer)
            || uri.getHost().toLowerCase().contains(hostedServerPreviewName)) {
        String uriPath = uri.getPath().replaceAll("[/]+$", ""); //$NON-NLS-1$ //$NON-NLS-2$
        if (uriPath == null || uriPath.length() == 0) {
            uriPath = hostedServerPath;
        }

        return new URI(hostedServerScheme, uri.getHost(), uriPath, null);
    }

    return uri;
}

From source file:com.collective.celos.Util.java

public static String augmentHdfsPath(String hdfsPrefix, String path) throws URISyntaxException {

    if (hdfsPrefix.isEmpty() || hdfsPrefix.equals("/")) {
        return path;
    }// ww w .  ja v a2 s  .  c om

    for (String ch : conversions.keySet()) {
        path = path.replace(ch.toString(), conversions.get(ch).toString());
    }
    URI oldUri = URI.create(path);

    String host = oldUri.getHost();
    if (oldUri.getRawSchemeSpecificPart().startsWith("///") && host == null) {
        host = "";
    }

    URI newUri = new URI(oldUri.getScheme(), oldUri.getUserInfo(), host, oldUri.getPort(),
            hdfsPrefix + oldUri.getPath(), oldUri.getQuery(), oldUri.getFragment());
    path = newUri.toString();
    for (String ch : backConversions.keySet()) {
        path = path.replace(ch.toString(), backConversions.get(ch).toString());
    }
    return path;
}

From source file:com.mymita.vaadlets.VaadletsBuilder.java

private static void setEmbeddedAttributes(final com.vaadin.ui.Component vaadinComponent,
        final com.mymita.vaadlets.core.Component vaadletsComponent) {
    if (vaadletsComponent instanceof com.mymita.vaadlets.ui.Embedded) {
        final String source = ((com.mymita.vaadlets.ui.Embedded) vaadletsComponent).getSource();
        if (source.startsWith("theme:")) {
            try {
                final URI uri = new URI(source);
                final String theme = uri.getHost();
                final String path = uri.getPath();
                final String resourceId = URLDecoder.decode(path.replaceFirst("/", ""),
                        Charsets.UTF_8.toString());
                ((com.vaadin.ui.Embedded) vaadinComponent).setSource(new ThemeResource(resourceId));
            } catch (final URISyntaxException e) {
            } catch (final UnsupportedEncodingException e) {
            }/*from w ww .j a  va2  s. c  o  m*/
        }
    }
}

From source file:sh.calaba.driver.server.CalabashNodeConfiguration.java

/**
 * Reads the the driver configuration from the specified URI. The file is expected to be in JSON
 * format.//from  w  w w . j  av  a 2  s .c o  m
 * 
 * @param driverConfigFileURI The file name of the driver configuration file URI.
 * @return The Calabash node configuration.
 * @throws CalabashConfigurationException On IO and Parsing errors.
 * @throws InvalidParameterException if parameter is null or empty
 */
public static CalabashNodeConfiguration readFromURI(URI driverConfigFileURI)
        throws CalabashConfigurationException {
    if (driverConfigFileURI == null) {
        throw new InvalidParameterException("Calabash-Driver Configuration-URI is missing.");
    }
    if (driverConfigFileURI.getHost() == null || driverConfigFileURI.getPath() == null) {
        throw new InvalidParameterException("Calabash-Driver Configuration-URI is invalid.");
    }
    String driverConfiguration;
    try {
        HttpClient client = getDefaultHttpClient();
        HttpGet request = new HttpGet(driverConfigFileURI);
        HttpResponse response = client.execute(request);

        driverConfiguration = IOUtils.toString(response.getEntity().getContent());
    } catch (IOException e1) {
        logger.error("Error occured while reading config from URI:", e1);
        throw new CalabashConfigurationException(
                "Error reading file content. Did you have specified the right URI?", e1);
    } catch (KeyManagementException e) {
        logger.error("Error occured while creating httpclient:", e);
        throw new CalabashConfigurationException("Error occured while creating httpclient", e);
    } catch (NoSuchAlgorithmException e) {
        logger.error("Error occured while creating httpclient:", e);
        throw new CalabashConfigurationException("Error occured while creating httpclient", e);
    }

    try {
        return new CalabashNodeConfiguration(new JSONObject(driverConfiguration));
    } catch (JSONException e) {
        logger.error("Error occured while parsing config file: ", e);
        throw new CalabashConfigurationException("Error occured during parsing json file from URI: '"
                + driverConfigFileURI + "'. Pls make sure you are using a valid JSON file!", e);
    }
}