Example usage for java.net URL getPath

List of usage examples for java.net URL getPath

Introduction

In this page you can find the example usage for java.net URL getPath.

Prototype

public String getPath() 

Source Link

Document

Gets the path part of this URL .

Usage

From source file:com.brightcove.com.zartan.verifier.video.ThumbnailVerifier.java

@ZartanCheck(value = "Thumbnail is a jpg")
public ResultEnum assertVideoStillTypeCorrect(UploadData upData) throws Throwable {
    URL u = getThumbnailUrl(upData);
    assertTrue("type should be jpg of " + u.getPath(), u.getPath().endsWith("jpg"));
    return ResultEnum.PASS;
}

From source file:com.mashape.unirest.request.HttpRequest.java

private URL parseUrl(String s) throws Exception {
    URL u = new URL(s);
    return new URI(u.getProtocol(), u.getAuthority(), u.getPath(), u.getQuery(), u.getRef()).toURL();
}

From source file:net.duckling.ddl.service.url.DefaultURLConstructor.java

public DefaultURLConstructor(String baseURL, String teamCode) {
    this.baseURL = baseURL;
    try {//w w  w .  j  a va  2s .co m
        URL url = new URL(baseURL);
        basePath = url.getPath();
    } catch (MalformedURLException e) {
        basePath = "/ddl";
    }
    this.isRelative = true;
    teamName = teamCode;
}

From source file:com.piaoyou.util.FileUtil.java

public static String getServletClassesPath(String flag) {
    String servletClassesPath = "";
    String strPath = System.getProperty("mvncore.context.path");
    if ((strPath != null) && (strPath.length() > 0)) {
        servletClassesPath = strPath;//from  w w  w .  j  a v a 2 s.  c o m
    } else {
        ClassLoader classLoader = instance.getClass().getClassLoader();
        URL url = null;
        if (flag == null)
            url = classLoader.getResource("/");
        else
            url = classLoader.getResource(flag);
        if (url == null) {
            // not run on the Servlet environment
            servletClassesPath = ".";
        } else {
            servletClassesPath = url.getPath();
        }
    }
    log.debug("servletClassesPath = " + servletClassesPath);

    if (servletClassesPath.contains(":/")) {
        servletClassesPath = servletClassesPath.substring(1).replace("%20", " ");

        //log.warn("servletClassesPath does not end with /: " + servletClassesPath);
    } else if (servletClassesPath.endsWith(File.separator) == false) {
        servletClassesPath = servletClassesPath + File.separatorChar;

    }
    return servletClassesPath;
}

From source file:ar.com.zauber.commons.auth.acegi.LoginController.java

/**
 * Si hubo un error en el login, inyecta la causa (como modelo en la 
 * variable acegiSecurityException) en la vista, y si no muestra el 
 * formulario de login.//from w w  w  . j  a  v a  2  s  . c o m
 * 
 * @see AbstractController#handleRequestInternal(HttpServletRequest,
 *      HttpServletResponse)
 */
@Override
protected ModelAndView handleRequestInternal(final HttpServletRequest request,
        final HttpServletResponse response) throws Exception {
    final Map<String, Object> model = new HashMap<String, Object>();

    addToModel(request, model, AbstractAuthenticationProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY,
            "acegiSecurityException");
    addToModel(request, model, AuthenticationProcessingFilter.SPRING_SECURITY_LAST_USERNAME_KEY, "username");
    addToModel(request, model, DefaultSavedRequest.SPRING_SECURITY_SAVED_REQUEST_KEY, "url");

    String referer = request.getHeader("Referer");

    if (referer != null) {
        int paramIndex = referer.indexOf("?");
        if (paramIndex != -1) {
            referer = referer.substring(0, paramIndex);
        }
        URL url = new URL(referer);
        model.put("refererPath", url.getPath());
    }

    WebUtils.setSessionAttribute(request, AbstractProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY, null);

    // XXX AuthenticationException tiene varios hijos, con lo cual se podria
    // determinar diferentes pginas segun lo que haya pasado (expiracin?)

    return new ModelAndView("login/form", model);
}

From source file:kr.ac.kaist.wala.hybridroid.callgraph.AndroidHybridAnalysisScope.java

private static AndroidHybridAnalysisScope setUpJsAnalysisScope(String dir, AndroidHybridAnalysisScope scope,
        Set<URL> htmls) throws IllegalArgumentException, IOException {

    JavaScriptLoader.addBootstrapFile(WebUtil.preamble);
    if (SystemUtils.IS_OS_WINDOWS) {
        scope.addToScope(scope.getJavaScriptLoader(),
                new SourceURLModule(AndroidHybridAppModel.class.getResource("prologue.js")) {
                    @Override//  www  .  j av  a  2s.c o m
                    public String getName() {
                        return "prologue.js";
                    }
                });
        scope.addToScope(scope.getJavaScriptLoader(),
                new SourceURLModule(AndroidHybridAppModel.class.getResource("preamble.js")) {
                    @Override
                    public String getName() {
                        return "preamble.js";
                    }
                });
    } else {
        scope.addToScope(scope.getJavaScriptLoader(),
                new SourceURLModule(AndroidHybridAppModel.class.getResource("prologue.js")) {
                    @Override
                    public String getName() {
                        return "prologue.js";
                    }
                });
        scope.addToScope(scope.getJavaScriptLoader(),
                new SourceURLModule(AndroidHybridAppModel.class.getResource("preamble.js")) {
                    @Override
                    public String getName() {
                        return "preamble.js";
                    }
                });
        //scope.addToScope(scope.getJavaScriptLoader(), JSCallGraphBuilderUtil.getPrologueFile("prologue.js"));
        //scope.addToScope(scope.getJavaScriptLoader(), JSCallGraphBuilderUtil.getPrologueFile("preamble.js"));
    }
    for (URL url : htmls) {
        try {
            File f = WebUtil.extractScriptFromHTML(url, DefaultSourceExtractor.factory).snd;
            scope.addToScope(scope.getJavaScriptLoader(), new SourceURLModule(f.toURI().toURL()));

            String jspath = f.getCanonicalPath();
            addScopeMap(Atom.findOrCreateAsciiAtom(url.toString()), Atom.findOrCreateAsciiAtom(
                    jspath.substring(jspath.lastIndexOf(File.separator) + 1, jspath.length())));
            if (DEBUG)
                System.err.println("#Loaded html: " + url.getFile());
        } catch (Error | RuntimeException e) {// | UnimplementedError |
            // Error e) {
            if (url.toString().startsWith("http")) {
                System.err.println("Cannot receive the response from the url: " + url);
            } else {
                String path = url.getPath();
                SourceModule dummy = new SourceURLModule(FileWriter
                        .makeHtmlFile(dir,
                                path.substring(path.lastIndexOf(File.separator) + 1, path.length() - 1), "")
                        .toURI().toURL());
                String dummypath = dummy.getName();
                if (DEBUG)
                    System.err.println("make dummy: " + dummypath);
                addScopeMap(Atom.findOrCreateAsciiAtom(url.toString()), Atom
                        .findOrCreateAsciiAtom(dummypath.substring(dummypath.lastIndexOf(File.separator) + 1)));
                scope.addToScope(scope.getJavaScriptLoader(), dummy);
            }
        }
    }

    return scope;
}

From source file:com.esri.geoportal.harvester.waf.WafFolder.java

/**
 * Matches URL// w  w w . j  a v a  2  s . c o  m
 * @param u url
 * @param pattern match patter (glob)
 * @return <code>true</code> if URL matches the pattern
 */
private boolean matchUrl(URL u, String pattern) {
    String[] split = u.getPath().split("(/|\\\\)+");
    List<String> items = Arrays.asList(split).stream().filter(s -> s != null && !s.isEmpty())
            .collect(Collectors.toList());
    if (!items.isEmpty()) {
        String first = items.get(0);
        List<String> subList = items.subList(1, items.size());
        Path path = fileSystem.getPath(first, subList.toArray(new String[] {}));
        PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:" + pattern);
        return pathMatcher.matches(path);
    } else {
        return false;
    }
}

From source file:com.scvngr.levelup.core.net.request.factory.TicketRequestFactoryTest.java

/**
 * Tests building a support request.//w ww .  j ava 2 s.c  o m
 *
 * @throws com.scvngr.levelup.core.net.AbstractRequest.BadRequestException on test failure.
 * @throws java.io.IOException on test failure.
 */
@SmallTest
public void testBuildSupportRequest() throws BadRequestException, IOException {
    final TicketRequestFactory builder = new TicketRequestFactory(getContext(), new MockAccessTokenRetriever());
    final AbstractRequest request = builder.buildSupportRequest(MESSAGE_FIXTURE);

    assertNotNull(request);
    final URL url = request.getUrl(getContext());
    assertTrue("hits /tickets endpoint", url.getPath().endsWith("/tickets"));
    assertTrue(request.getRequestHeaders(getContext()).containsKey(LevelUpRequest.HEADER_AUTHORIZATION));

    assertEquals(RequestUtils.HEADER_CONTENT_TYPE_JSON,
            request.getRequestHeaders(getContext()).get(HTTP.CONTENT_TYPE));

    assertEquals(HttpMethod.POST, request.getMethod());
    assertTrue(url.getPath().startsWith("/v14"));

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        request.writeBodyToStream(getContext(), baos);
        assertTrue("Has expected content", baos.toString().contains(MESSAGE_FIXTURE));
    } finally {
        baos.close();
    }
}

From source file:guru.qas.martini.jmeter.sampler.FeatureMarshaller.java

protected String getResourcePath() throws IOException {
    Martini martini = result.getMartini();
    Recipe recipe = martini.getRecipe();
    Resource resource = recipe.getSource();
    URL url = null == resource ? null : resource.getURL();
    return null == url ? null : url.getPath();
}

From source file:com.fluidops.iwb.api.solution.ZipFileBasedSolutionService.java

private String filePrefixFor(URL solutionArtifact) {
    return FilenameUtils.removeExtension(new File(solutionArtifact.getPath()).getName());
}