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:com.thoughtworks.go.spark.spa.LoginLogoutHelper.java

public Map<String, Object> buildMeta(Request request) {
    SecurityAuthConfigs securityAuthConfigs = goConfigService.security().securityAuthConfigs();

    List<AuthorizationPluginInfo> webBasedAuthenticationPlugins = securityAuthConfigs.stream()
            .map(configurationProperties -> {
                if (authorizationMetadataStore
                        .doesPluginSupportWebBasedAuthentication(configurationProperties.getPluginId())) {
                    return authorizationMetadataStore.getPluginInfo(configurationProperties.getPluginId());
                } else {
                    return null;
                }/* ww w  .  j a va2 s.c o  m*/
            }).filter(Objects::nonNull).distinct().collect(Collectors.toList());

    List<AuthorizationPluginInfo> passwordBasedAuthenticationPlugins = securityAuthConfigs.stream()
            .map(configurationProperties -> {
                if (authorizationMetadataStore
                        .doesPluginSupportPasswordBasedAuthentication(configurationProperties.getPluginId())) {
                    return authorizationMetadataStore.getPluginInfo(configurationProperties.getPluginId());
                } else {
                    return null;
                }
            }).filter(Objects::nonNull).distinct().collect(Collectors.toList());

    ImmutableMap.Builder<String, Object> metaBuilder = ImmutableMap.<String, Object>builder()
            .put("hasWebBasedPlugins", !webBasedAuthenticationPlugins.isEmpty())
            .put("hasPasswordPlugins", !passwordBasedAuthenticationPlugins.isEmpty())
            .put("webBasedPlugins", webBasedAuthenticationPlugins.stream()
                    .map(authorizationPluginInfo -> ImmutableMap.builder()
                            .put("pluginName", authorizationPluginInfo.getDescriptor().about().name())
                            .put("imageUrl", authorizationPluginInfo.getImage().toDataURI())
                            .put("redirectUrl",
                                    "/go/plugin/" + UrlEscapers.urlPathSegmentEscaper()
                                            .escape(authorizationPluginInfo.getDescriptor().id()) + "/login")
                            .build())
                    .collect(Collectors.toList()));

    if (isNotBlank(SessionUtils.getAuthenticationError(request.raw()))) {
        metaBuilder.put("loginError", SessionUtils.getAuthenticationError(request.raw()));
    }

    return metaBuilder.build();
}

From source file:org.aksw.simba.bengal.triple2nl.converter.URIDereferencer.java

private File getCacheFile(URI uri) {
    String filename = UrlEscapers.urlPathSegmentEscaper().escape(uri.toString()) + "." + cacheFileExtension;
    File cacheFile = new File(cacheDirectory, filename);
    return cacheFile;
}

From source file:brooklyn.networking.vclouddirector.NatMicroserviceClient.java

@Override
public HostAndPort openPortForwarding(PortForwardingConfig args) {
    HttpClient client = HttpTool.httpClientBuilder().uri(microserviceUri).trustSelfSigned().build();

    Escaper escaper = UrlEscapers.urlPathSegmentEscaper();
    URI uri = URI.create(Urls.mergePaths(microserviceUri,
            "/v1/nat" + "?endpoint=" + escaper.escape(endpoint)
                    + (Strings.isNonBlank(vDC) ? "&vdc=" + escaper.escape(vDC) : "") + "&identity="
                    + escaper.escape(identity) + "&credential=" + escaper.escape(credential) + "&protocol="
                    + args.getProtocol() + "&original=" + args.getPublicEndpoint()
                    + (args.getPublicPortRange() == null ? ""
                            : "&originalPortRange=" + args.getPublicPortRange().toString())
                    + "&translated=" + args.getTargetEndpoint()));

    if (LOG.isDebugEnabled())
        LOG.debug("PUT {}", uri.toString().replace(escaper.escape(credential), "xxxxxxxx"));

    HttpToolResponse response = HttpTool.httpPut(client, uri, ImmutableMap.<String, String>of(), new byte[0]);
    if (response.getResponseCode() < 200 || response.getResponseCode() >= 300) {
        String msg = "Open NAT Rule failed for " + args + ": " + response.getResponseCode() + "; "
                + response.getReasonPhrase() + ": " + response.getContentAsString();
        LOG.info(msg + "; rethrowing");
        throw new RuntimeException(msg);
    }/*  www . j a  v  a 2 s  . c  o  m*/
    return HostAndPort.fromString(response.getContentAsString());
}

From source file:org.eclipse.packagedrone.repo.adapter.p2.web.P2RepoController.java

@RequestMapping(value = "/{channelId}/edit", method = RequestMethod.POST)
public ModelAndView editPost(@PathVariable("channelId") final String channelId,
        @Valid @FormData("command") final P2ChannelInformation data, final BindingResult result)
        throws Exception {
    return Channels.withChannel(this.service, channelId, ModifiableChannel.class, channel -> {

        final Map<String, Object> model = new HashMap<>();

        if (result.hasErrors()) {
            model.put("channel", channel.getInformation());
            model.put("command", data);
            fillBreadcrumbs(model, channelId, "Edit");
            return new ModelAndView("p2edit", model);
        }/*from  w  w  w .j  a v a2s. c  o m*/

        final Map<MetaKey, String> providedMetaData = MetaKeys.unbind(data);

        channel.applyMetaData(providedMetaData);

        return new ModelAndView(
                "redirect:/p2.repo/" + UrlEscapers.urlPathSegmentEscaper().escape(channelId) + "/info", model);
    });
}

From source file:org.eclipse.packagedrone.repo.adapter.p2.web.P2MetaDataController.java

@RequestMapping(value = "/{channelId}/edit", method = RequestMethod.POST)
public ModelAndView editPost(@PathVariable("channelId") final String channelId,
        @Valid @FormData("command") final P2MetaDataInformation data, final BindingResult result)
        throws Exception {
    return Channels.withChannel(this.service, channelId, ModifiableChannel.class, channel -> {

        final Map<String, Object> model = new HashMap<>();

        if (result.hasErrors()) {
            model.put("channel", channel.getInformation());
            model.put("command", data);
            fillBreadcrumbs(model, channelId, "Edit");
            return new ModelAndView("p2edit", model);
        }/*  www.  j a v a2s  .  co  m*/

        final Map<MetaKey, String> providedMetaData = MetaKeys.unbind(data);

        channel.applyMetaData(providedMetaData);

        return new ModelAndView(
                "redirect:/p2.metadata/" + UrlEscapers.urlPathSegmentEscaper().escape(channelId) + "/info",
                model);
    });
}

From source file:brooklyn.networking.vclouddirector.NatMicroserviceClient.java

@Override
public HostAndPort closePortForwarding(PortForwardingConfig args) {
    HttpClient client = HttpTool.httpClientBuilder().uri(microserviceUri).trustSelfSigned().build();

    Escaper escaper = UrlEscapers.urlPathSegmentEscaper();
    URI uri = URI.create(Urls.mergePaths(microserviceUri,
            "/v1/nat" + "?endpoint=" + escaper.escape(endpoint)
                    + (Strings.isNonBlank(vDC) ? "&vdc=" + escaper.escape(vDC) : "") + "&identity="
                    + escaper.escape(identity) + "&credential=" + escaper.escape(credential) + "&protocol="
                    + args.getProtocol() + "&original=" + args.getPublicEndpoint() + "&translated="
                    + args.getTargetEndpoint()));

    if (LOG.isDebugEnabled())
        LOG.debug("DELETE {}", uri.toString().replace(escaper.escape(credential), "xxxxxxxx"));

    HttpToolResponse response = HttpTool.httpDelete(client, uri, ImmutableMap.<String, String>of());
    if (response.getResponseCode() < 200 || response.getResponseCode() >= 300) {
        String msg = "Delete NAT Rule failed for " + args + ": " + response.getResponseCode() + "; "
                + response.getReasonPhrase() + ": " + response.getContentAsString();
        LOG.info(msg + "; rethrowing");
        throw new RuntimeException(msg);
    }/*from  w ww  . j a v  a  2 s . c  o  m*/
    return args.getPublicEndpoint();
}

From source file:com.github.dirkraft.jash.JashResource.java

@POST
@Path("util/uriEncode")
public Response utilUriEncode(String body, byte[] stdin) throws URISyntaxException {
    return Response.ok(UrlEscapers.urlPathSegmentEscaper().escape(body)).build();
}

From source file:org.eclipse.packagedrone.repo.aspect.upgrade.UpgradeTaskProvider.java

private List<Task> updateState() {
    try (Handle handle = Profile.start(this, "updateState")) {
        final Map<String, ChannelAspectInformation> infos = ChannelAspectProcessor
                .scanAspectInformations(this.context);

        final List<Task> result = new LinkedList<>();

        final Multimap<String, ChannelInformation> missing = HashMultimap.create();

        final Multimap<ChannelInformation, String> channels = HashMultimap.create();

        for (final ChannelInformation channel : this.service.list()) {
            logger.debug("Checking channel: {}", channel.getId());

            final Map<String, String> states = channel.getAspectStates();
            for (final Map.Entry<String, String> entry : states.entrySet()) {
                logger.debug("\t{}", entry.getKey());

                final ChannelAspectInformation info = infos.get(entry.getKey());
                if (info == null) {
                    missing.put(entry.getKey(), channel);
                } else {
                    logger.debug("\t{} - {} -> {}", info.getFactoryId(), entry.getValue(), info.getVersion());

                    if (!info.getVersion().equals(Version.valueOf(entry.getValue()))) {
                        result.add(makeUpgradeTask(channel, info, entry.getValue()));
                        channels.put(channel, entry.getKey());
                    }/*from www.  ja v  a 2s . com*/
                }
            }
        }

        for (final Map.Entry<ChannelInformation, Collection<String>> entry : channels.asMap().entrySet()) {
            final ChannelInformation channel = entry.getKey();
            final LinkTarget target = new LinkTarget(String.format("/channel/%s/refreshAllAspects",
                    UrlEscapers.urlPathSegmentEscaper().escape(channel.getId())));
            final String description = "Channel aspects active in this channel have been updated. You can refresh the whole channel.";
            result.add(new BasicTask("Refresh channel: " + channel.makeTitle(), 100, description, target,
                    RequestMethod.GET, PERFORM_ALL_BUTTON));
        }

        for (final Map.Entry<String, Collection<ChannelInformation>> entry : missing.asMap().entrySet()) {
            final String missingChannels = entry.getValue().stream().map(ChannelInformation::getId)
                    .collect(Collectors.joining(", "));
            result.add(new BasicTask(String.format("Fix missing channel aspect: %s", entry.getKey()), 1,
                    String.format(
                            "The channel aspect '%s' is being used but not installed in the system. Channels: %s",
                            entry.getKey(), missingChannels),
                    null));
        }

        if (!channels.isEmpty()) {
            result.add(new BasicTask("Refresh all channels", 1, "Refresh all channels in one big task",
                    new LinkTarget(String.format("/job/%s/create", UpgradeAllChannelsJob.ID)),
                    RequestMethod.POST, PERFORM_ALL_SUPER_BUTTON));
        }

        return result;
    }
}

From source file:ratpack.http.internal.DefaultHttpUrlBuilder.java

private void appendPathString(StringBuilder stringBuilder) {
    if (!pathSegments.isEmpty()) {
        stringBuilder.append("/");
        PATH_JOINER.appendTo(stringBuilder,
                Iterables.transform(pathSegments, input -> UrlEscapers.urlPathSegmentEscaper().escape(input)));
    }/*from ww w  .  j a  va  2 s  .  c o m*/
}

From source file:com.spotify.helios.client.HeliosClient.java

private String path(final String resource, final Object... params) {
    final String path;
    final Escaper escaper = UrlEscapers.urlPathSegmentEscaper();
    if (params.length == 0) {
        path = resource;/* w  w  w .  j  a  v  a2 s.  com*/
    } else {
        final List<String> encodedParams = Lists.newArrayList();
        for (final Object param : params) {
            encodedParams.add(escaper.escape(param.toString()));
        }
        path = format(resource, encodedParams.toArray());
    }
    return path;
}