Example usage for com.google.common.net UrlEscapers urlPathSegmentEscaper

List of usage examples for com.google.common.net UrlEscapers urlPathSegmentEscaper

Introduction

In this page you can find the example usage for com.google.common.net UrlEscapers urlPathSegmentEscaper.

Prototype

public static Escaper urlPathSegmentEscaper() 

Source Link

Document

Returns an Escaper instance that escapes strings so they can be safely included in <a href="http://goo.gl/swjbR">URL path segments</a>.

Usage

From source file:org.eclipse.packagedrone.repo.aspect.cleanup.web.ConfigController.java

private void fillModel(final Map<String, Object> model, final String channelId) {
    final List<Entry> entries = new LinkedList<>();

    entries.add(new Entry("Home", "/"));
    entries.add(new Entry("Channel",
            "/channel/" + UrlEscapers.urlPathSegmentEscaper().escape(channelId) + "/view"));
    entries.add(new Entry("Cleanup"));

    model.put("breadcrumbs", new Breadcrumbs(entries));
}

From source file:org.kaaproject.kaa.server.admin.services.messaging.MessagingServiceImpl.java

private String generateParamsUrl(Map<String, String> paramsMap) {
    StringBuilder paramsUrl = new StringBuilder();
    for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
        String val = entry.getValue();
        if (paramsUrl.length() > 0) {
            paramsUrl.append("&");
        }//  w w  w  . j  a v a2  s .co  m
        paramsUrl.append(entry.getKey()).append("=").append(UrlEscapers.urlPathSegmentEscaper().escape(val));
    }
    return paramsUrl.toString();
}

From source file:com.linecorp.armeria.server.http.jetty.JettyService.java

private static MetaData.Request toRequestMetadata(ServiceRequestContext ctx, AggregatedHttpMessage aReq) {
    // Construct the HttpURI
    final StringBuilder uriBuf = new StringBuilder();
    final HttpHeaders aHeaders = aReq.headers();

    uriBuf.append(ctx.sessionProtocol().isTls() ? "https" : "http");
    uriBuf.append("://");
    uriBuf.append(aHeaders.authority());
    uriBuf.append(aHeaders.path());/*w  w  w  . ja  v  a 2s .c  o  m*/

    final HttpURI uri = new HttpURI(uriBuf.toString());
    final String encoded = PATH_SPLITTER.splitToList(ctx.mappedPath()).stream()
            .map(UrlEscapers.urlPathSegmentEscaper()::escape).collect(Collectors.joining("/"));
    uri.setPath(encoded);

    // Convert HttpHeaders to HttpFields
    final HttpFields jHeaders = new HttpFields(aHeaders.size());
    aHeaders.forEach(e -> {
        final AsciiString key = e.getKey();
        if (!key.isEmpty() && key.byteAt(0) != ':') {
            jHeaders.add(key.toString(), e.getValue());
        }
    });

    return new MetaData.Request(aHeaders.method().name(), uri, HttpVersion.HTTP_1_1, jHeaders,
            aReq.content().length());
}

From source file:com.pidoco.juri.JURI.java

public StringBuilder buildRawPathString(boolean absolute, boolean slashAtEnd, String[] segments) {
    StringBuilder result = new StringBuilder();
    if (absolute) {
        result.append('/');
    }/*  ww w. j  a v a  2  s  .  c  o m*/
    boolean addedOne = false;
    for (String s : segments) {
        result.append(UrlEscapers.urlPathSegmentEscaper().escape(s));
        result.append('/');
        addedOne = true;
    }
    if (addedOne && !slashAtEnd) {
        result.deleteCharAt(result.length() - 1);
    }
    return result;
}

From source file:com.pidoco.juri.JURI.java

/**
 * Escapes non-path characters. Slash ('/') characters may be included in segments if escaped by backslash.
 * @param completeUnescapedPath e.g. //b\/f//kf/ -> //b%XXf//kf/
 * @return the used string builder.//w  w  w .j a v a 2 s  . com
 */
public static StringBuilder escapeMultiSegmentPath(String completeUnescapedPath) {
    StringBuilder pathBuilder = new StringBuilder();

    StringBuilder temp = new StringBuilder();

    for (int i = 0; i < completeUnescapedPath.length(); i++) {
        char current = completeUnescapedPath.charAt(i);
        if (current == '\\') {
            if (isSlashAtPos(completeUnescapedPath, i + 1)) {
                temp.append('/');
                i++;
                continue;
            }
        }
        if (current == '/') {
            pathBuilder.append(UrlEscapers.urlPathSegmentEscaper().escape(temp.toString()));
            pathBuilder.append('/');
            temp.setLength(0);
            continue;
        }
        temp.append(current);
    }
    if (temp.length() > 0) {
        pathBuilder.append(UrlEscapers.urlPathSegmentEscaper().escape(temp.toString()));
    }

    return pathBuilder;
}

From source file:org.ow2.proactive_grid_cloud_portal.scheduler.client.SchedulerRestClient.java

private String escapeUrlPathSegment(String unescaped) {
    return UrlEscapers.urlPathSegmentEscaper().escape(unescaped);
}

From source file:org.ow2.proactive.scheduler.smartproxy.common.AbstractSmartProxy.java

protected String createNewFolderName() {
    String user = System.getProperty("user.name");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss.SSS");
    Date now = new Date();
    String strDate = sdf.format(now);

    String newFolderName = user + "_" + strDate;
    // escape the characters of the folder path as it is a remote path which will be appended to a url
    return UrlEscapers.urlPathSegmentEscaper().escape(newFolderName);
}

From source file:org.eclipse.packagedrone.repo.channel.web.channel.ChannelController.java

@RequestMapping(value = "/channel/{channelId}/artifact/{artifactId}/attach", method = RequestMethod.POST)
public ModelAndView attachArtifactPost(@PathVariable("channelId") final String channelId,
        @PathVariable("artifactId") final String artifactId,
        @RequestParameter(required = false, value = "name") final String name,
        final @RequestParameter("file") Part file) {
    return withChannel(channelId, ModifiableChannel.class, channel -> {

        String targetName = name;

        final Optional<ChannelArtifactInformation> parentArtifact = channel.getArtifact(artifactId);
        if (!parentArtifact.isPresent()) {
            return CommonController.createNotFound("artifact", artifactId);
        }//from   w  ww .  j av a 2  s .co  m

        try {
            if (targetName == null || targetName.isEmpty()) {
                targetName = file.getSubmittedFileName();
            }

            channel.getContext().createArtifact(artifactId, file.getInputStream(), targetName, null);
        } catch (final IOException e) {
            return new ModelAndView("/error/upload");
        }

        return new ModelAndView(
                "redirect:/channel/" + UrlEscapers.urlPathSegmentEscaper().escape(channelId) + "/view");
    });
}