Example usage for org.apache.commons.httpclient.util URIUtil encodeWithinPath

List of usage examples for org.apache.commons.httpclient.util URIUtil encodeWithinPath

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.util URIUtil encodeWithinPath.

Prototype

public static String encodeWithinPath(String unescaped) throws URIException 

Source Link

Document

Escape and encode a string regarded as within the path component of an URI with the default protocol charset.

Usage

From source file:net.hillsdon.reviki.web.dispatching.impl.ResourceHandlerImpl.java

public View handle(final ConsumedPath path, final HttpServletRequest request,
        final HttpServletResponse response) throws Exception {
    if (!path.hasNext()) {
        throw new NotFoundException();
    }//from   w w w .ja va  2 s .  com

    StringBuilder sb = new StringBuilder("/resources");

    while (path.hasNext()) {
        sb.append("/");
        sb.append(URIUtil.encodeWithinPath(path.next()));
    }

    final String resource = sb.toString();

    return new View() {
        public void render(final HttpServletRequest request, final HttpServletResponse response)
                throws Exception {
            RequestDispatcher requestDispatcher = request.getRequestDispatcher(resource);
            requestDispatcher.forward(request, response);
        }
    };
}

From source file:net.hillsdon.reviki.web.handlers.impl.JumpToWikiUrlImpl.java

public View handle(final ConsumedPath path, final HttpServletRequest request,
        final HttpServletResponse response)
        throws PageStoreException, IOException, ServletException, InvalidInputException {
    final String wiki = URIUtil.encodeWithinPath(getRequiredString(request, "name"));
    return new RedirectToPageView(_urls.get(wiki), PAGE_FRONT_PAGE);
}

From source file:net.hillsdon.reviki.web.urls.impl.WikiUrlsImpl.java

public String pagesRoot(final String wikiName) {
    final String givenWikiName = wikiName == null ? _wiki.getWikiName() : wikiName;

    String fixedBaseUrl = _wiki.getFixedBaseUrl(givenWikiName);
    if (fixedBaseUrl != null) {
        if (!fixedBaseUrl.endsWith("/")) {
            fixedBaseUrl += "/";
        }// w w  w .j a  v a2s .  co  m
        return fixedBaseUrl;
    }

    String relative = "/pages/";
    if (givenWikiName != null) {
        try {
            relative += URIUtil.encodeWithinPath(givenWikiName) + "/";
        } catch (URIException e) {
            throw new RuntimeException(e);
        }
    }
    return _applicationUrls.url(relative);
}

From source file:de.dentrassi.pm.jenkins.UploaderV2.java

private URI makeUrl(final String file) throws URIException, IOException {
    final URI fullUri;
    try {/*w ww . j  a v a  2  s  .  c  om*/

        final URIBuilder b = new URIBuilder(this.serverUrl);

        b.setUserInfo("deploy", this.deployKey);

        b.setPath(b.getPath() + String.format("/api/v2/upload/channel/%s/%s",
                URIUtil.encodeWithinPath(this.channelId), file));

        b.addParameter("jenkins:buildUrl", this.runData.getUrl());
        b.addParameter("jenkins:buildId", this.runData.getId());
        b.addParameter("jenkins:buildNumber", String.valueOf(this.runData.getNumber()));
        b.addParameter("jenkins:jobName", this.runData.getFullName());

        final Map<String, String> properties = new HashMap<String, String>();
        fillProperties(properties);

        for (final Map.Entry<String, String> entry : properties.entrySet()) {
            b.addParameter(entry.getKey(), entry.getValue());
        }

        fullUri = b.build();

    } catch (final URISyntaxException e) {
        throw new IOException(e);
    }
    return fullUri;
}

From source file:net.hillsdon.reviki.webtests.TestSearch.java

public void testPageWithSpacesShowsInBacklinks() throws Exception {
    final String refers = uniqueWikiPageName("SearchSpaces BacklinkTesta");
    final String referred = uniqueWikiPageName("SearchSpaces BacklinkTestb");
    editWikiPage(refers, "[[" + referred + "]]", "", "", true);
    final HtmlPage page = getWikiPage(referred);
    getAnchorByHrefContains(page, URIUtil.encodeWithinPath(refers));
}

From source file:de.dentrassi.pm.jenkins.UploaderV3.java

@Override
public boolean complete() {
    if (this.failed) {
        return false;
    }//from   w ww. jav a  2s  .  co  m

    try {
        closeTransfer();

        final URIBuilder uri = new URIBuilder(String.format("%s/api/v3/upload/archive/channel/%s",
                this.serverUrl, URIUtil.encodeWithinPath(this.channelId)));

        this.listener.getLogger().println("API endpoint: " + uri.build().toString());

        final HttpPut httppost = new HttpPut(uri.build());

        final String encodedAuth = Base64
                .encodeBase64String(("deploy:" + this.deployKey).getBytes("ISO-8859-1"));
        httppost.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + encodedAuth);

        final InputStream stream = new FileInputStream(this.tempFile);
        try {
            httppost.setEntity(new InputStreamEntity(stream, this.tempFile.length()));

            final HttpResponse response = this.client.execute(httppost);
            final HttpEntity resEntity = response.getEntity();

            this.listener.getLogger().println("Call returned: " + response.getStatusLine());

            if (resEntity != null) {
                switch (response.getStatusLine().getStatusCode()) {
                case 200:
                    processUploadResult(makeString(resEntity));
                    return true;
                case 404:
                    this.listener.error(
                            "Failed to find upload endpoint V3. This could mean that you configured a wrong server URL or that the server does not support the Upload V3. You will need a version 0.14+ of Eclipse Package Drone. It could also mean that you did use wrong credentials.");
                    return false;
                default:
                    if (!handleError(response)) {
                        addErrorMessage("Failed to upload: " + response.getStatusLine());
                    }
                    return false;
                }
            }

            addErrorMessage("Did not receive a result");

            return false;
        } finally {
            stream.close();
        }
    } catch (final Exception e) {
        e.printStackTrace(this.listener.error("Failed to perform archive upload"));
        return false;
    }
}

From source file:net.hillsdon.reviki.webtests.WebTestSupport.java

/**
 * @param name Name of page.//from   www  .j  a  v  a2  s  .  c om
 * @return That page in the 'test' wiki.
 * @throws IOException On error.
 */
protected HtmlPage getWikiPage(final String name) throws IOException {
    return getWebPage("pages/test/" + URIUtil.encodeWithinPath(name));
}

From source file:net.hillsdon.reviki.webtests.WebTestSupport.java

protected XmlPage getHistoryAtomFeed(final String name) throws IOException {
    return getXmlPage("pages/test/" + URIUtil.encodeWithinPath(name) + "?history&ctype=atom");
}

From source file:net.hillsdon.reviki.search.impl.LuceneSearcher.java

public Set<String> incomingLinks(final String page) throws IOException, PageStoreException {
    if (_dir == null) {
        return Collections.emptySet();
    }//from w w  w .  ja  v  a 2 s .c  om
    try {
        return doReadOperation(new ReadOperation<Set<String>>() {
            public Set<String> execute(final IndexReader reader, final Searcher searcher,
                    final Analyzer analyzer) throws IOException, ParseException {
                final String pageEscaped = escape(URIUtil.encodeWithinPath(page));
                Set<String> results = Sets.newLinkedHashSet(Iterables.transform(
                        query(reader, createAnalyzer(), searcher, FIELD_OUTGOING_LINKS, pageEscaped, false),
                        SearchMatch.TO_PAGE_NAME));
                results.remove(page);
                return results;
            }
        }, false);
    } catch (QuerySyntaxException ex) {
        throw new NoQueryPerformedException(ex);
    }
}

From source file:com.dtolabs.client.services.RundeckAPICentralDispatcher.java

/**
 * Replace a "$var" within a path string with a value, properly encoding it.
 * @param path the URL path to substitute the var within
 * @param var the name of the var in the string
 * @param value the value to substitute/*  w  w  w .  j av a2  s.c  om*/
 */
public static String substitutePathVariable(final String path, final String var, final String value)
        throws CentralDispatcherException {
    final String encoded;
    try {
        encoded = URIUtil.encodeWithinPath(value);
    } catch (URIException e) {
        throw new CentralDispatcherException(e);
    }
    return path.replace("$" + var, encoded);
}