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.sentilo.platform.server.request.SentiloRequest.java

private void parseUri() {
    uri = httpRequest.getRequestLine().getUri();
    final URI parsedUri = URI.create(uri);
    path = parsedUri.getPath();
    processUriParameters(parsedUri);//from  w  ww.  j  a  v  a2  s  . c  om
    // path has the format handler_path_tokens/resources_tokens
    // handlerPath = RequestUtils.extractHandlerPath(path);
    // processResource(path);
}

From source file:com.microsoftopentechnologies.windowsazurestorage.service.UploadService.java

/**
 * Convert the path on local file sytem to relative path on azure storage
 *
 * @param path       the local path//from  www . j  ava  2 s  . c o m
 * @param embeddedVP the embedded virtual path
 * @return
 */
protected String getItemPath(final FilePath path, final String embeddedVP)
        throws IOException, InterruptedException {
    final URI workspaceURI = serviceData.getRemoteWorkspace().toURI();

    // Remove the workspace bit of this path
    final URI srcURI = workspaceURI.relativize(path.toURI());
    final String srcURIPath = srcURI.getPath();
    String prefix = StringUtils.isBlank(serviceData.getVirtualPath()) ? "" : serviceData.getVirtualPath();
    if (!StringUtils.isBlank(embeddedVP)) {
        prefix += embeddedVP;
    }

    return prefix + srcURIPath;
}

From source file:fr.sewatech.sewatoool.impress.service.ImpressService.java

/**
 * Transforme un chemin d'accs au fichier, au format classique, en chemin
 * d'accs compatible OOo//from   w  w w.j a  v  a 2 s  . c o m
 * 
 * @param requestedlocation
 * @param xContext
 * @return
 */
private String getSupportedLocation(String requestedlocation, XComponentContext xContext) {
    // Construit correctement le chemin du fichier
    URI uri = URI.create(requestedlocation);
    File file = new File(uri.getPath());
    String path = file.getAbsolutePath();
    String correctLocation;

    if (System.getProperty("os.name").startsWith("Windows")) {
        // Format Windows
        correctLocation = "file:/" + path.replace('\\', '/');
    } else {
        // Format Unix
        correctLocation = "file://" + path;
    }

    logger.trace("Tentative d'ouverture du fichier " + correctLocation);
    // Resoud des problemes d'encodage
    String internalLocation = ExternalUriReferenceTranslator.create(xContext)
            .translateToInternal(correctLocation);
    return internalLocation;
}

From source file:com.textocat.textokit.corpus.statistics.dao.corpus.XmiFileTreeCorpusDAO.java

private String getDocumentFilename(URI docUri) {
    // sanity check
    if (StringUtils.isBlank(docUri.getPath())) {
        throw new IllegalStateException(String.format("Unexpected doc URI: %s", docUri));
    }/*from   w w w .  ja va2s  .  co m*/
    return String.format("%s.%s", docUri.getPath(), XMI_FILE_EXTENSION);
}

From source file:net.sf.maltcms.chromaui.charts.Chromatogram1DChartProvider.java

/**
 * Retrieve all accessible {@link IVariableFragment} instances starting from
 * the given {@link IFileFragment} and traversing the ancestor tree in
 * breadth-first order, adding all immediate {@link IVariableFragment}
 * instances to the list first, before exploring the next ancestor as given
 * by <em>source_files</em>.
 *
 * @param fragment//from w  w  w  .j  a v  a2  s  .  c o m
 * @return
 */
public static List<IVariableFragment> getAggregatedVariables(IFileFragment fragment) {
    HashMap<String, IVariableFragment> names = new HashMap<>();
    List<IVariableFragment> allVars = new ArrayList<>();
    List<IFileFragment> parentsToExplore = new LinkedList<>();
    // System.out.println("Parent files " + parentsToExplore);
    parentsToExplore.add(fragment);
    while (!parentsToExplore.isEmpty()) {
        IFileFragment parent = parentsToExplore.remove(0);
        try {
            IVariableFragment sf = parent.getChild("source_files", true);
            try {
                Collection<String> c = ArrayTools.getStringsFromArray(sf.getArray());
                for (String s : c) {
                    //               log.debug("Processing file {}", s);
                    URI path = URI.create(FileTools.escapeUri(s));
                    if (path.getScheme() == null || !path.getPath().startsWith("/")) {
                        URI resolved = FileTools.resolveRelativeUri(fragment.getUri(), path);
                        //                  log.debug("Adding resolved relative path: {} to {}", path, resolved);
                        parentsToExplore.add(new FileFragment(resolved));
                    } else {
                        //                  log.debug("Adding absolute path: {}", path);
                        parentsToExplore.add(new FileFragment(path));
                    }

                    //                    File file = new File(s);
                    //                    if (file.isAbsolute()) {
                    //                        parentsToExplore.add(new FileFragment(file));
                    //                    } else {
                    //                        try {
                    //                            file = new File(
                    //                                    cross.datastructures.tools.FileTools.resolveRelativeFile(new File(
                    //                                    fragment.getAbsolutePath()).getParentFile(), new File(
                    //                                    s)));
                    //                            parentsToExplore.add(new FileFragment(file.getCanonicalFile()));
                    //                        } catch (IOException ex) {
                    //                            log.error("{}", ex);
                    //                        }
                    //                    }
                }
            } catch (ConstraintViolationException cve) {
            }
        } catch (ResourceNotAvailableException rnae) {
        }
        // System.out.println("Parent files " + parentsToExplore);
        try {
            for (IVariableFragment ivf : getVariablesFor(parent)) {
                if (!ivf.getName().equals("source_files")) {
                    if (!names.containsKey(ivf.getName())) {
                        names.put(ivf.getName(), ivf);
                        allVars.add(ivf);
                    }
                }
            }
        } catch (IOException ex) {
            //            log.warn("{}", ex);
        }
    }
    return allVars;
}

From source file:org.apache.heron.uploader.http.HttpUploaderTest.java

@Test
public void testUploadPackage() {
    HttpUploader httpUploader = new TestHttpUploader();
    httpUploader.initialize(config);//from w  w w .j  a va2  s.c o m
    URI uri = httpUploader.uploadPackage();
    assertTrue(uri.getPath().equals(EXPECTED_URI));
}

From source file:com.aurel.track.util.PluginUtils.java

/**
 * Transforms the given URL which may contain escaping characters (like %20 for space)
 * to an URL which may conatin illegal URL characters (like space) but is valid for creating a file based on the resulting URL
 * The escape characters will be changed back to characters that are illegal in URLs (like space) because the file could be
 * constructed just in such a way in some servlet containers like Tomcat5.5
 * @param url//from  ww  w  .  jav a 2 s. c  om
 * @return
 */
public static URL createValidFileURL(URL url) {
    File file;
    URL fileUrl;
    if (url == null) {
        return null;
    }
    if (url.getPath() != null) {
        file = new File(url.getPath());
        //we have no escape characters or the servlet container can deal with escape characters
        if (file.exists()) {
            //valid url
            return url;
        }
    }
    //valid file through URI?
    //see Bug ID:  4466485 (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4466485)
    URI uri = null;
    try {
        //get rid of spaces
        uri = new URI(url.toString());
    } catch (URISyntaxException e1) {
    }
    if (uri == null) {
        return null;
    }
    if (uri.getPath() != null) {
        //the decoded path component of this URI
        file = new File(uri.getPath());
        if (file.exists()) {
            try {
                //file.toURL() does not automatically escape characters that are illegal in URLs
                fileUrl = file.toURL(); // revert, problems with Windows?
                if (fileUrl != null) {
                    return fileUrl;
                }
            } catch (MalformedURLException e) {
            }
        }
    }
    //back to URL from URI
    try {
        url = uri.toURL();
    } catch (MalformedURLException e) {
    }
    if (url != null && url.getPath() != null) {
        file = new File(url.getPath());
        if (file.exists()) {
            //valid url
            return url;
        }
    }
    return null;
}

From source file:org.gradle.caching.http.internal.HttpBuildCacheService.java

public HttpBuildCacheService(HttpClientHelper httpClientHelper, URI url) {
    if (!url.getPath().endsWith("/")) {
        throw new IncompleteArgumentException("HTTP cache root URI must end with '/'");
    }/*www  .j  a v a  2 s.  com*/
    this.root = url;
    this.httpClientHelper = httpClientHelper;
}

From source file:com.linkedin.d2.balancer.util.LoadBalancerClientCli.java

public static <T> PropertyStore<T> getEphemeralStore(ZKConnection zkclient, String store,
        PropertySerializer<T> serializer, ZooKeeperPropertyMerger<T> merger)
        throws URISyntaxException, IOException, PropertyStoreException {
    URI storeUri = URI.create(store);

    if (storeUri.getScheme() != null) {
        if (storeUri.getScheme().equals("zk")) {

            ZooKeeperEphemeralStore<T> zkStore = new ZooKeeperEphemeralStore<T>(zkclient, serializer, merger,
                    storeUri.getPath());
            startStore(zkStore);/*from w w w .j a v  a2 s .co m*/
            return zkStore;
        } else {
            throw new URISyntaxException(store,
                    "Unable to parse store uri. Only zk and file stores are supported.");
        }
    } else {
        // assume it's a local file
        return new FileStore<T>(storeUri.getPath(), ".json", serializer);
    }

}