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.adobe.aem.importer.impl.GitListenerImpl.java

public void handleEvent(final Event osgiEvent) {
    Project gitProject = (Project) osgiEvent.getProperty(GitHubPushConstants.EVT_PROJECT);
    GitHubPushEvent gitHubPushEvent = (GitHubPushEvent) osgiEvent.getProperty(GitHubPushConstants.EVT_GHEVENT);

    URI gitRepoUrl = gitHubPushEvent.getRepoUrl();
    String sourcePath = DocImporter.GIT_REPOS_FOLDER_PATH + "/" + gitRepoUrl.getHost() + gitRepoUrl.getPath();

    List<String> added = gitHubPushEvent.getAddedFileNames();
    List<String> modified = gitHubPushEvent.getModifiedFileNames();
    List<String> deleted = gitHubPushEvent.getDeletedFileNames();
    modified.addAll(added);/*from   ww w  .  ja  v a  2  s  .  c om*/

    Session session;
    try {
        session = repository.loginAdministrative(null);
        for (String path : modified) {
            String[] split = path.split("/");
            String fileName = split[split.length - 1];
            int lastForwardSlashPos = path.lastIndexOf("/");

            String parentPath = sourcePath;
            if (lastForwardSlashPos > 0) {
                parentPath = parentPath + "/" + path.substring(0, lastForwardSlashPos);
            }

            File gitFile = gitProject.getFile(EncodeUtil.escapePath(path));
            Node parentNode = JcrUtils.getOrCreateByPath(parentPath, "nt:folder", "nt:folder", session, true);
            InputStream in = IOUtils.toInputStream(gitFile.getContent(), "UTF-8");
            JcrUtils.putFile(parentNode, fileName, "application/xml", in);
            session.save();
        }

        for (String path : deleted) {
            String deleteNodePath = sourcePath + "/" + path;
            if (session.nodeExists(deleteNodePath)) {
                session.getNode(deleteNodePath).remove();
                session.save();
            }
        }
        docImporter.doImport(sourcePath);
    } catch (Exception e) {
        log.error("Exception", e);
    }
}

From source file:org.mobicents.servlet.sip.restcomm.fax.InterFaxService.java

private final String getFileExtension(final URI uri) {
    final String path = uri.getPath();
    final int indexOfSeparator = path.lastIndexOf(".");
    if (indexOfSeparator > -1) {
        return path.substring(indexOfSeparator + 1, path.length());
    } else {/*from   w ww . j ava 2 s  .  c  om*/
        return null;
    }
}

From source file:org.obiba.opal.web.security.AuditInterceptor.java

private void logInfo(HttpRequest request, ServerResponse response) {
    if (!log.isInfoEnabled())
        return;/* w  w w.ja  va 2  s . c  om*/
    if (response.getStatus() >= HttpStatus.SC_BAD_REQUEST)
        return;

    boolean logged = false;
    if (response.getStatus() == HttpStatus.SC_CREATED) {
        URI resourceUri = (URI) response.getMetadata().getFirst(HttpHeaders.LOCATION);
        if (resourceUri != null) {
            String path = resourceUri.getPath().substring(OpalWsConfig.WS_ROOT.length());
            MDC.put("created", path);
            log.info(LOG_FORMAT, getArguments(request, response));
            logged = true;
        }
    }

    if (!logged) {
        log.info(LOG_FORMAT, getArguments(request, response));
    }
}

From source file:ru.histone.spring.mvc.HistoneWebAppResourceLoader.java

@Override
public Resource load(String location, String baseLocation, Node... args) throws ResourceLoadException {
    URI fullLocation = makeFullLocation(location, baseLocation);

    Resource resource = null;//w w  w  . ja  v a2 s. c  o m

    if (fullLocation.getScheme().equals("webapp")) {
        resource = loadWebAppResource(fullLocation.getPath());
    } else {
        resource = super.load(location, baseLocation, args);
    }

    return resource;
}

From source file:net.audumla.scheduler.camel.SchedulerComponent.java

private TriggerKey createTriggerKey(String uri, String remaining, DefaultSchedulerEndpoint endpoint)
        throws Exception {
    // Parse uri for trigger name and group
    URI u = new URI(uri);
    String path = ObjectHelper.after(u.getPath(), "/");
    String host = u.getHost();/*  w w  w  .  j ava2  s . co  m*/

    // host can be null if the uri did contain invalid host characters such as an underscore
    if (host == null) {
        host = ObjectHelper.before(remaining, "/");
        if (host == null) {
            host = remaining;
        }
    }

    // Trigger group can be optional, if so set it to this context's unique name
    String name;
    String group;
    if (ObjectHelper.isNotEmpty(path) && ObjectHelper.isNotEmpty(host)) {
        group = host;
        name = path;
    } else {
        String camelContextName = getCamelContext().getManagementName();
        group = camelContextName == null ? "Camel" : "Camel_" + camelContextName;
        name = host;
    }

    if (prefixJobNameWithEndpointId) {
        name = endpoint.getId() + "_" + name;
    }

    return new TriggerKey(name, group);
}

From source file:com.orange.spring.cloud.connector.s3.heroku.S3ServiceInfoCreator.java

public S3ServiceInfo createServiceInfo(S3DetectableService s3DetectableService) {
    Map<String, String> env = environment.getEnv();
    String accessKeyId = env.get(s3DetectableService.getAccessKeyIdEnvKey());
    String secretAccessKey = env.get(s3DetectableService.getSecretAccessKeyEnvKey());
    String bucketName = env.get(s3DetectableService.getBucketNameEnvKey());
    String finalUrl = this.getFinalUrl(s3DetectableService, bucketName);
    URI finalUri = URI.create(finalUrl);
    return new S3ServiceInfo(bucketName, finalUri.getScheme(), finalUri.getHost(), finalUri.getPort(),
            accessKeyId, secretAccessKey, finalUri.getPath());
}

From source file:net.bluemix.todo.connector.CloudantServiceInfoCreator.java

@Override
public CloudantServiceInfo createServiceInfo(Map<String, Object> serviceData) {
    Map<String, Object> credentials = (Map<String, Object>) serviceData.get("credentials");
    String id = (String) serviceData.get("name");
    try {/*from   w  w w . j  a v  a  2s .  co  m*/
        URI uri = new URI((String) credentials.get("url"));
        String scheme = uri.getScheme();
        int port = uri.getPort();
        String host = uri.getHost();
        String path = uri.getPath();
        String query = uri.getQuery();
        String fragment = uri.getFragment();
        String url = new URI(scheme, "", host, port, path, query, fragment).toString();
        String[] userInfo = uri.getUserInfo().split(":");
        return new CloudantServiceInfo(id, userInfo[0], userInfo[1], url);
    } catch (URISyntaxException e) {
        return null;
    }
}

From source file:jenkins.scm.impl.subversion.SubversionSampleRepoRule.java

public String rootUrl() throws URISyntaxException {
    URI u = repo.toURI();
    // TODO SVN rejects File.toUri syntax (requires blank authority field)
    return new URI(u.getScheme(), "", u.getPath(), u.getFragment()).toString();
}

From source file:com.esri.geoportal.harvester.folder.FolderBroker.java

private File generateFileName(URI brokerUri, URI sourceUri, String id) {
    URI ssp = URI.create(brokerUri.getSchemeSpecificPart());
    String root = StringUtils.defaultIfEmpty(ssp.getHost(), ssp.getPath());
    File rootFolder = definition.getRootFolder().toPath().resolve(root).toFile();

    File fileName = rootFolder;/*ww w  . j a  va2  s  .c  o  m*/
    if (sourceUri.getPath() != null) {
        List<String> subFolder = splitPath(sourceUri.getPath().replaceAll("/[a-zA-Z]:/|/$", ""));
        if (!subFolder.isEmpty() && subFolder.get(0).equals(root)) {
            subFolder.remove(0);
        }
        for (String sf : subFolder) {
            fileName = new File(fileName, sf);
        }
        if (!fileName.getName().contains(".")) {
            fileName = fileName.getParentFile().toPath().resolve(fileName.getName() + ".xml").toFile();
        }
    } else {
        fileName = new File(fileName, id + ".xml");
    }

    return fileName;
}

From source file:com.aurel.track.lucene.LuceneUtil.java

/**
 * Gets the context path of the application
 * @return//from  w ww  .j  a v a2 s  . co  m
 */
public static String getContexPath() {
    URL url = null;
    File file;
    //get the application context path
    url = LuceneUtil.class.getResource("/../..");
    if (url == null) {
        return null;
    }
    if (url.getPath() != null) {
        file = new File(url.getPath());
        if (file.exists()) {
            return stripTrailingPathSeparator(url.getPath());
        }
    }
    //see Bug ID:  4466485 (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4466485) 
    URI uri = null;
    try {
        uri = new URI(url.toString());
    } catch (URISyntaxException e) {
        LOGGER.error("Getting the lucene index root URI from URL failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    if (uri == null) {
        return null;
    }
    //sometimes it is enough
    if (uri.getPath() != null) {
        file = new File(uri.getPath());
        if (file.exists()) {
            return stripTrailingPathSeparator(uri.getPath());
        }
    }

    try {
        url = uri.toURL();
    } catch (MalformedURLException e) {
    }
    if (url != null && url.getPath() != null) {
        file = new File(url.getPath());
        if (file.exists()) {
            return stripTrailingPathSeparator(url.getPath());
        }
    }
    return "";
}