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:URISupport.java

/**
 * Creates a URI with the given query//from  w w  w. j a v a 2  s .  c om
 */
public static URI createURIWithQuery(URI uri, String query) throws URISyntaxException {
    return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), query,
            uri.getFragment());
}

From source file:de.metas.ui.web.config.ServletLoggingFilter.java

private static final String extractRequestInfo(final ServletRequest request) {
    String requestInfo;//  www  . j a v a  2  s  .co m
    if (request instanceof HttpServletRequest) {
        final HttpServletRequest httpRequest = (HttpServletRequest) request;
        final String urlStr = httpRequest.getRequestURL().toString();
        URI uri;
        try {
            uri = new URI(urlStr);
        } catch (final URISyntaxException e) {
            uri = null;
        }

        String path = null;
        if (uri != null) {
            path = uri.getPath();
        }
        if (path == null) {
            path = urlStr;
        }

        final String queryString = httpRequest.getQueryString();

        requestInfo = path + (queryString != null ? "?" + queryString : "");
    } else {
        requestInfo = request.toString();
    }

    return requestInfo;
}

From source file:URISupport.java

public static URI changeScheme(URI bindAddr, String scheme) throws URISyntaxException {
    return new URI(scheme, bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), bindAddr.getPath(),
            bindAddr.getQuery(), bindAddr.getFragment());
}

From source file:net.sourceforge.dita4publishers.tools.dxp.DitaDxpHelper.java

/**
 * Given a DITA map bounded object set, zips it up into a DXP Zip package.
 * @param mapBos/*from  ww w  .ja v a  2s .c  o m*/
 * @param outputZipFile
 * @throws Exception 
 */
public static void zipMapBos(DitaBoundedObjectSet mapBos, File outputZipFile, MapBosProcessorOptions options)
        throws Exception {
    /*
     *  Some potential complexities:
     *  
     *  - DXP package spec requires either a map manifest or that 
     *  there be exactly one map at the root of the zip package. This 
     *  means that the file structure of the BOS needs to be checked to
     *  see if the files already conform to this structure and, if not,
     *  they need to be reorganized and have pointers rewritten if a 
     *  map manifest has not been requested.
     *  
     *  - If the file structure of the original data includes files not
     *  below the root map, the file organization must be reworked whether
     *  or not a map manifest has been requested.
     *  
     *  - Need to generate DXP map manifest if a manifest is requested.
     *  
     *  - If user has requested that the original file structure be 
     *  remembered, a manifest must be generated.
     */

    log.debug("Determining zip file organization...");

    BosVisitor visitor = new DxpFileOrganizingBosVisitor();
    visitor.visit(mapBos);

    if (!options.isQuiet())
        log.info("Creating DXP package \"" + outputZipFile.getAbsolutePath() + "\"...");
    OutputStream outStream = new FileOutputStream(outputZipFile);
    ZipOutputStream zipOutStream = new ZipOutputStream(outStream);

    ZipEntry entry = null;

    // At this point, URIs of all members should reflect their
    // storage location within the resulting DXP package. There
    // must also be a root map, either the original map
    // we started with or a DXP manifest map.

    URI rootMapUri = mapBos.getRoot().getEffectiveUri();
    URI baseUri = null;
    try {
        baseUri = AddressingUtil.getParent(rootMapUri);
    } catch (URISyntaxException e) {
        throw new BosException("URI syntax exception getting parent URI: " + e.getMessage());
    }

    Set<String> dirs = new HashSet<String>();

    if (!options.isQuiet())
        log.info("Constructing DXP package...");
    for (BosMember member : mapBos.getMembers()) {
        if (!options.isQuiet())
            log.info("Adding member " + member + " to zip...");
        URI relativeUri = baseUri.relativize(member.getEffectiveUri());
        File temp = new File(relativeUri.getPath());
        String parentPath = temp.getParent();
        if (parentPath != null && !"".equals(parentPath) && !parentPath.endsWith("/")) {
            parentPath += "/";
        }
        log.debug("parentPath=\"" + parentPath + "\"");
        if (!"".equals(parentPath) && parentPath != null && !dirs.contains(parentPath)) {
            entry = new ZipEntry(parentPath);
            zipOutStream.putNextEntry(entry);
            zipOutStream.closeEntry();
            dirs.add(parentPath);
        }
        entry = new ZipEntry(relativeUri.getPath());
        zipOutStream.putNextEntry(entry);
        IOUtils.copy(member.getInputStream(), zipOutStream);
        zipOutStream.closeEntry();
    }

    zipOutStream.close();
    if (!options.isQuiet())
        log.info("DXP package \"" + outputZipFile.getAbsolutePath() + "\" created.");
}

From source file:com.knowledgecode.cordova.websocket.ConnectionTask.java

/**
 * Complement default port number./*  w  w w .  j  av a  2  s  .c  om*/
 *
 * @param url
 * @return URI
 * @throws URISyntaxException
 */
private static URI complementPort(String url) throws URISyntaxException {
    URI uri = new URI(url);
    int port = uri.getPort();

    if (port < 0) {
        if ("ws".equals(uri.getScheme())) {
            port = 80;
        } else if ("wss".equals(uri.getScheme())) {
            port = 443;
        }
        uri = new URI(uri.getScheme(), "", uri.getHost(), port, uri.getPath(), uri.getQuery(), "");
    }
    return uri;
}

From source file:com.cyberway.issue.net.UURI.java

/**
 * @param pathOrUri A file path or a URI.
 * @return Path parsed from passed <code>pathOrUri</code>.
 * @throws URISyntaxException/*from  www. j av a 2  s  .  com*/
 */
public static String parseFilename(final String pathOrUri) throws URISyntaxException {
    String path = pathOrUri;
    if (UURI.hasScheme(pathOrUri)) {
        URI url = new URI(pathOrUri);
        path = url.getPath();
    }
    return (new File(path)).getName();
}

From source file:com.microsoft.alm.common.utils.UrlHelper.java

public static URI resolveEndpointUri(URI baseUri, String endpointPath) {
    if (!baseUri.getPath().endsWith("/")) {
        baseUri = createUri(baseUri.toString() + "/");
    }/*from w  w  w.  j a  v a2  s .c o  m*/

    if (endpointPath.startsWith("/")) {
        endpointPath = endpointPath.substring(1);
    }

    return baseUri.resolve(endpointPath);
}

From source file:com.google.caja.precajole.StaticPrecajoleMap.java

public static String normalizeUri(String uri) {
    try {//  ww w .  j  a  v  a2  s . c o  m
        URI u = new URI(uri).normalize();
        if (u.getHost() != null) {
            u = new URI(lowercase(u.getScheme()), u.getUserInfo(), lowercase(u.getHost()), u.getPort(),
                    u.getPath(), u.getQuery(), u.getFragment());
        } else if (u.getScheme() != null) {
            u = new URI(lowercase(u.getScheme()), u.getSchemeSpecificPart(), u.getFragment());
        }
        return u.toString();
    } catch (URISyntaxException e) {
        return uri;
    }
}

From source file:net.adamcin.recap.replication.RecapReplicationUtil.java

/**
 * Builds a RecapAddress from related properties of the provided AgentConfig
 * @param config//from   w w w  .  jav a  2  s  .co  m
 * @return
 * @throws com.day.cq.replication.ReplicationException
 */
public static RecapAddress getAgentAddress(AgentConfig config) throws ReplicationException {

    final String uri = config.getTransportURI();

    if (!uri.startsWith(TRANSPORT_URI_SCHEME_PREFIX)) {
        throw new ReplicationException("uri must start with " + TRANSPORT_URI_SCHEME_PREFIX);
    }

    final String user = config.getTransportUser();
    final String pass = config.getTransportPassword();

    try {

        final URI parsed = new URI(uri.substring(TRANSPORT_URI_SCHEME_PREFIX.length()));
        final boolean https = "https".equals(parsed.getScheme());
        final String host = parsed.getHost();
        final int port = parsed.getPort() < 0 ? (https ? 443 : 80) : parsed.getPort();
        final String prefix = StringUtils.isEmpty(parsed.getPath()) ? null : parsed.getPath();

        return new DefaultRecapAddress() {
            @Override
            public boolean isHttps() {
                return https;
            }

            @Override
            public String getHostname() {
                return host;
            }

            @Override
            public Integer getPort() {
                return port;
            }

            @Override
            public String getUsername() {
                return user;
            }

            @Override
            public String getPassword() {
                return pass;
            }

            @Override
            public String getServletPath() {
                return prefix;
            }
        };
    } catch (URISyntaxException e) {
        throw new ReplicationException(e);
    }
}

From source file:com.eucalyptus.blockstorage.entities.SnapshotInfo.java

/**
 * Parse the snapshot location uri such as snapshots://server/bucket/key and return bucket and key
 * /* w  ww.  j a va  2s. co m*/
 * @param snapshotUriString
 * @return 
 * @throws URISyntaxException
 * @throws EucalyptusCloudException
 */
public static String[] getSnapshotBucketKeyNames(String snapshotUriString)
        throws URISyntaxException, EucalyptusCloudException {
    if (StringUtils.isNotBlank(snapshotUriString)) {
        URI snapshotUri = new URI(snapshotUriString);
        String[] parts = snapshotUri.getPath().split("/");
        // Path would be in the format /snapshot-bucket/snapshot-key. Splitting it on '/' returns 3 strings, the first should be blank
        if (parts.length >= 3) {
            if (StringUtils.isBlank(parts[0]) && StringUtils.isNotBlank(parts[1])
                    && StringUtils.isNotBlank(parts[2])) {
                return new String[] { parts[1], parts[2] };
            } else {
                throw new EucalyptusCloudException(
                        "Bucket and or key name not found in snapshot location: " + snapshotUriString);
            }
        } else {
            throw new EucalyptusCloudException(
                    "Failed to parse bucket and key names from snapshot location: " + snapshotUriString);
        }
    } else {
        throw new EucalyptusCloudException("Invalid snapshot location: " + snapshotUriString);
    }
}