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:net.sf.jasperreports.eclipse.util.FileUtils.java

public static IFile getInProjectFile(URI uri, IProgressMonitor monitor) throws CoreException {
    IPath location = new Path(uri.getPath());
    IProject project = getProject(monitor);
    IFile file = project.getFile(location.lastSegment());
    file.createLink(location, IResource.REPLACE, null);

    return file;// w  w  w. j ava2 s  . c  o  m
}

From source file:net.sf.jasperreports.eclipse.util.FileUtils.java

public static IFolder getInProjectFolder(URI uri, IProgressMonitor monitor) throws CoreException {
    IPath location = new Path(uri.getPath());
    IProject project = getProject(monitor);
    IFolder file = project.getFolder(location.lastSegment());
    file.createLink(location, IResource.REPLACE, null);

    return file;//from  ww w  . ja va2s . com
}

From source file:com.log4ic.compressor.utils.template.JavascriptTemplateEngine.java

protected static String run(URI uri, String source, RunIt runIt) {
    Map<String, String> params = HttpUtils.getParameterMap(uri);
    String name;//from w  ww .  ja  v a  2s  .  c om
    Mode m = null;
    if (params.containsKey("amd")) {
        name = params.get("amd");
        m = Mode.AMD;
    } else {
        name = params.get("name");
        String mode = params.get("mode");
        if (StringUtils.isBlank(name)) {
            name = uri.getPath();
            int lastI = name.lastIndexOf(".");
            name = name.substring(name.lastIndexOf("/") + 1, lastI);
        }
        if (StringUtils.isNotBlank(mode)) {
            try {
                m = Mode.valueOf(mode.toUpperCase());
            } catch (Exception e) {
                //fuck ide
            }
        }
        if (m == null) {
            m = Mode.COMMON;
        }
    }
    return runIt.run(name, source, m);
}

From source file:com.cloud.utils.UriUtils.java

public static String getUpdateUri(String url, boolean encrypt) {
    String updatedPath = null;/*from www. j  a v  a  2s .  c  om*/
    try {
        String query = URIUtil.getQuery(url);
        URIBuilder builder = new URIBuilder(url);
        builder.removeQuery();

        StringBuilder updatedQuery = new StringBuilder();
        List<NameValuePair> queryParams = getUserDetails(query);
        ListIterator<NameValuePair> iterator = queryParams.listIterator();
        while (iterator.hasNext()) {
            NameValuePair param = iterator.next();
            String value = null;
            if ("password".equalsIgnoreCase(param.getName()) && param.getValue() != null) {
                value = encrypt ? DBEncryptionUtil.encrypt(param.getValue())
                        : DBEncryptionUtil.decrypt(param.getValue());
            } else {
                value = param.getValue();
            }

            if (updatedQuery.length() == 0) {
                updatedQuery.append(param.getName()).append('=').append(value);
            } else {
                updatedQuery.append('&').append(param.getName()).append('=').append(value);
            }
        }

        String schemeAndHost = "";
        URI newUri = builder.build();
        if (newUri.getScheme() != null) {
            schemeAndHost = newUri.getScheme() + "://" + newUri.getHost();
        }

        updatedPath = schemeAndHost + newUri.getPath() + "?" + updatedQuery;
    } catch (URISyntaxException e) {
        throw new CloudRuntimeException("Couldn't generate an updated uri. " + e.getMessage());
    }

    return updatedPath;
}

From source file:org.apache.jena.jdbc.remote.RemoteEndpointDriver.java

/**
 * Get the URI with irrelevant components (Fragment and Querystring)
 * stripped off/*www .ja v  a2 s  . c o m*/
 * 
 * @param input
 *            URI
 * @return URI with irrelevant components stripped off or null if stripping
 *         is impossible
 */
private static String stripIrrelevantComponents(String input) {
    try {
        URI orig = new URI(input);
        return new URI(orig.getScheme(), orig.getUserInfo(), orig.getHost(), orig.getPort(), orig.getPath(),
                null, null).toString();
    } catch (URISyntaxException e) {
        return null;
    }
}

From source file:io.druid.storage.s3.S3DataSegmentPuller.java

public static FileObject buildFileObject(final URI uri, final RestS3Service s3Client)
        throws S3ServiceException {
    final S3Coords coords = new S3Coords(checkURI(uri));
    final S3Object s3Obj = s3Client.getObject(coords.bucket, coords.path);
    final String path = uri.getPath();

    return new FileObject() {
        volatile boolean streamAcquired = false;

        @Override// www.  j  a v  a2s .c  o m
        public URI toUri() {
            return uri;
        }

        @Override
        public String getName() {
            final String ext = Files.getFileExtension(path);
            return Files.getNameWithoutExtension(path) + (Strings.isNullOrEmpty(ext) ? "" : ("." + ext));
        }

        @Override
        public InputStream openInputStream() throws IOException {
            try {
                streamAcquired = true;
                return s3Obj.getDataInputStream();
            } catch (ServiceException e) {
                throw new IOException(String.format("Could not load S3 URI [%s]", uri), e);
            }
        }

        @Override
        public OutputStream openOutputStream() throws IOException {
            throw new UOE("Cannot stream S3 output");
        }

        @Override
        public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
            throw new UOE("Cannot open reader");
        }

        @Override
        public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
            throw new UOE("Cannot open character sequence");
        }

        @Override
        public Writer openWriter() throws IOException {
            throw new UOE("Cannot open writer");
        }

        @Override
        public long getLastModified() {
            return s3Obj.getLastModifiedDate().getTime();
        }

        @Override
        public boolean delete() {
            throw new UOE(
                    "Cannot delete S3 items anonymously. jetS3t doesn't support authenticated deletes easily.");
        }

        @Override
        public void finalize() throws Throwable {
            try {
                if (!streamAcquired) {
                    s3Obj.closeDataInputStream();
                }
            } finally {
                super.finalize();
            }
        }
    };
}

From source file:com.kegare.caveworld.util.CaveUtils.java

public static boolean archiveDirZip(final File dir, final File dest) {
    final Path dirPath = dir.toPath();
    final String parent = dir.getName();
    Map<String, String> env = Maps.newHashMap();
    env.put("create", "true");
    URI uri = dest.toURI();

    try {/*www.j a  v  a  2 s  .com*/
        uri = new URI("jar:" + uri.getScheme(), uri.getPath(), null);
    } catch (Exception e) {
        return false;
    }

    try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {
        Files.createDirectory(zipfs.getPath(parent));

        for (File file : dir.listFiles()) {
            if (file.isDirectory()) {
                Files.walkFileTree(file.toPath(), new SimpleFileVisitor<Path>() {
                    @Override
                    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                        Files.copy(file, zipfs.getPath(parent, dirPath.relativize(file).toString()),
                                StandardCopyOption.REPLACE_EXISTING);

                        return FileVisitResult.CONTINUE;
                    }

                    @Override
                    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
                            throws IOException {
                        Files.createDirectory(zipfs.getPath(parent, dirPath.relativize(dir).toString()));

                        return FileVisitResult.CONTINUE;
                    }
                });
            } else {
                Files.copy(file.toPath(), zipfs.getPath(parent, file.getName()),
                        StandardCopyOption.REPLACE_EXISTING);
            }
        }

        return true;
    } catch (Exception e) {
        e.printStackTrace();

        return false;
    }
}

From source file:com.amalto.core.storage.datasource.RDBMSDataSource.java

private static void replacePlaceholder(DataSource dataSource, String placeholderName, String value) {
    RDBMSDataSource rdbmsDataSource = (RDBMSDataSource) dataSource;
    // JDBC URL//from   w ww  . j  a v  a  2 s. co  m
    String connectionURL = rdbmsDataSource.getConnectionURL();
    String processedConnectionURL;
    RDBMSDataSource.DataSourceDialect dialect = ((RDBMSDataSource) dataSource).getDialectName();
    switch (dialect) {
    case POSTGRES:
        // Postgres always creates lower case database name
        processedConnectionURL = connectionURL.replace(placeholderName, value).toLowerCase();
        break;
    case MYSQL:
        // TMDM-6559: MySQL doesn't like '-' in database name
        processedConnectionURL = connectionURL.replace(placeholderName, value);
        if (processedConnectionURL.indexOf('-') > 0) {
            // Uses URI-based parsing to prevent replace of '-' in host name.
            URI uri = URI.create(processedConnectionURL.substring(5));
            if (uri.getPath().indexOf('-') > 0) {
                String previousURL = processedConnectionURL;
                processedConnectionURL = processedConnectionURL.replace(uri.getPath(),
                        uri.getPath().replace('-', '_'));
                LOGGER.warn("JDBC URL '" + previousURL //$NON-NLS-1$
                        + "' contains character(s) not supported by MySQL (replaced with '" //$NON-NLS-1$
                        + processedConnectionURL + "' by MDM)."); //$NON-NLS-1$
            }
        }
        break;
    case H2:
    case ORACLE_10G:
    case SQL_SERVER:
    default: // default for all databases
        processedConnectionURL = connectionURL.replace(placeholderName, value);
        break;
    }
    rdbmsDataSource.setConnectionURL(processedConnectionURL);
    // Database name
    String databaseName = rdbmsDataSource.getDatabaseName();
    String processedDatabaseName = databaseName.replace(placeholderName, value);
    switch (dialect) {
    case POSTGRES:
        // Postgres always creates lower case database name
        processedDatabaseName = processedDatabaseName.toLowerCase();
        break;
    case MYSQL:
        if (processedDatabaseName.indexOf('-') > 0) {
            LOGGER.warn("Database name '" + processedDatabaseName //$NON-NLS-1$
                    + "' contains character(s) not supported by MySQL."); //$NON-NLS-1$
        }
        processedDatabaseName = processedDatabaseName.replace('-', '_'); // TMDM-6559: MySQL doesn't like '-' in
        // database name
        break;
    case H2:
    case ORACLE_10G:
    case SQL_SERVER:
    case DB2:
    default:
        // Nothing to do for other databases
        break;
    }
    rdbmsDataSource.setDatabaseName(processedDatabaseName);
    // User name
    rdbmsDataSource.setUserName(rdbmsDataSource.getUserName().replace(placeholderName, value));
    // Advanced properties
    Map<String, String> advancedProperties = rdbmsDataSource.getAdvancedProperties();
    for (Map.Entry<String, String> entry : advancedProperties.entrySet()) {
        advancedProperties.put(entry.getKey(), entry.getValue().replace(placeholderName, value));
    }
}

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

public static String getHttpsUrlFromHttpUrl(final String httpUrl) {
    final URI uri = createUri(httpUrl);
    String httpsUrl = httpUrl;/*from  www .  j  a  v a  2s.com*/
    if (uri != null && StringUtils.equalsIgnoreCase(uri.getScheme(), "http")) {
        final URI httpsUri = createUri("https://" + uri.getAuthority() + uri.getPath());
        httpsUrl = httpsUri.toString();
    }

    if (StringUtils.startsWithIgnoreCase(httpsUrl, "https://")) {
        return httpsUrl;
    } else {
        return null;
    }
}

From source file:com.igormaznitsa.mindmap.model.ModelUtils.java

@Nonnull
public static File toFile(@Nonnull final URI uri) {
    final List<String> pathItems = new ArrayList<String>();

    final String authority = uri.getAuthority();
    if (authority != null && !authority.isEmpty()) {
        pathItems.add(authority);/*  w  w  w. j a  va  2s.c o  m*/
    }

    final String[] splittedPath = uri.getPath().split("\\/");
    boolean separator = false;
    if (splittedPath.length == 0) {
        separator = true;
    } else {
        for (final String s : splittedPath) {
            if (!s.isEmpty()) {
                pathItems.add(separator ? File.separatorChar + s : s);
                separator = false;
            } else {
                separator = true;
            }
        }
    }

    if (separator) {
        pathItems.add(File.separator);
    }

    final String[] fullArray = pathItems.toArray(new String[pathItems.size()]);
    final String[] next = Arrays.copyOfRange(fullArray, 1, fullArray.length);
    return Paths.get(fullArray[0], next).toFile();
}