List of usage examples for org.springframework.web.util UriComponentsBuilder fromPath
public static UriComponentsBuilder fromPath(String path)
From source file:org.kmnet.com.fw.web.pagination.PaginationInfo.java
/** * Constructor. Initializes the properties with the arguments passed<br> * @param page/*from w ww . java 2 s. c o m*/ * @param pathTmpl path template of pagination * @param queryTmpl query template of pagination * @param criteriaQuery Query of search criteria * @param disableHtmlEscapeOfCriteriaQuery Flag to indicate whether html escaping of criteriaQuery is to be disabled or * not.IF set to true, html escaping of criteriaQuery is disabled. * @param maxDisplayCount max display count * @since 1.0.1 */ public PaginationInfo(Page<?> page, String pathTmpl, String queryTmpl, String criteriaQuery, boolean disableHtmlEscapeOfCriteriaQuery, int maxDisplayCount) { this.page = page; this.current = page.getNumber(); this.pathTmpl = pathTmpl; this.queryTmpl = queryTmpl; if (disableHtmlEscapeOfCriteriaQuery) { this.criteriaQuery = removeHeadDelimiterOfQueryString(criteriaQuery); } else { this.criteriaQuery = HtmlEscapeUtils.htmlEscape(removeHeadDelimiterOfQueryString(criteriaQuery)); } this.maxDisplayCount = maxDisplayCount; this.pageUri = UriComponentsBuilder.fromPath(pathTmpl).query(queryTmpl).build(); }
From source file:org.terasoluna.gfw.web.el.Functions.java
/** * build query string from map.// ww w .j a v a2s. co m * <p> * query string is encoded with "UTF-8". * </p> * @see ObjectToMapConverter * @param map map * @return query string. if map is not empty, return query string. ex) name1=value&name2=value&... */ public static String mapToQuery(Map<String, Object> map) { if (map == null || map.isEmpty()) { return ""; } UriComponentsBuilder builder = UriComponentsBuilder.fromPath(""); for (Map.Entry<String, Object> e : map.entrySet()) { String name = e.getKey(); Object value = e.getValue(); builder.queryParam(name, value); } String query = builder.build().encode().toString(); // remove the beginning symbol character('?') of the query string. return query.substring(1); }
From source file:org.kmnet.com.fw.web.el.Functions.java
/** * build query string from map with the specified {@link BeanWrapper}. * <p>//w ww. j ava 2 s . c o m * query string is encoded with "UTF-8". * </p> * @param map map * @param beanWrapper beanWrapper which has the definition of each field. * @return query string. if map is not empty, return query string. ex) name1=value&name2=value&... */ public static String mapToQuery(Map<String, Object> map, BeanWrapper beanWrapper) { if (map == null || map.isEmpty()) { return ""; } UriComponentsBuilder builder = UriComponentsBuilder.fromPath(""); Map<String, Object> uriVariables = new HashMap<String, Object>(); for (Map.Entry<String, Object> e : map.entrySet()) { String name = e.getKey(); Object value = e.getValue(); builder.queryParam(name, "{" + name + "}"); TypeDescriptor sourceType; if (beanWrapper != null) { sourceType = beanWrapper.getPropertyTypeDescriptor(name); } else { sourceType = TypeDescriptor.forObject(value); } uriVariables.put(name, CONVERSION_SERVICE.convert(value, sourceType, STRING_DESC)); } String query = builder.buildAndExpand(uriVariables).encode().toString(); // remove the beginning symbol character('?') of the query string. return query.substring(1); }
From source file:com.ctc.storefront.controllers.pages.StorePageController.java
protected void processLocation(@RequestParam(value = "lat", required = false) final Double sourceLatitude, @RequestParam(value = "long", required = false) final Double sourceLongitude, @RequestParam(value = "q", required = false) final String locationQuery, final Model model, final PointOfServiceData pointOfServiceData) throws UnsupportedEncodingException { if (locationQuery != null && !locationQuery.isEmpty()) { model.addAttribute("locationQuery", locationQuery); // Build URL to location query final String storeFinderSearchUrl = UriComponentsBuilder.fromPath("/store-finder") .queryParam("q", locationQuery).build().toString(); model.addAttribute(WebConstants.BREADCRUMBS_KEY, storeBreadcrumbBuilder .getBreadcrumbs(pointOfServiceData, XSSEncoder.encodeURL(storeFinderSearchUrl))); } else {/*from ww w . j a v a2 s.c om*/ // Build URL to position query final String storeFinderSearchUrl = UriComponentsBuilder.fromPath("/store-finder/position") .queryParam("lat", sourceLatitude).queryParam("long", sourceLongitude).build().toString(); model.addAttribute(WebConstants.BREADCRUMBS_KEY, storeBreadcrumbBuilder .getBreadcrumbs(pointOfServiceData, XSSEncoder.encodeURL(storeFinderSearchUrl))); } }
From source file:org.terasoluna.gfw.web.el.Functions.java
/** * build query string from map with the specified {@link BeanWrapper}. * <p>/*www . j a v a 2 s .c o m*/ * query string is encoded with "UTF-8".<br> * <strong>Use {@link #mapToQuery(Map)} instead of this method.</strong> * </p> * @see ObjectToMapConverter * @param map map * @param beanWrapper beanWrapper which has the definition of each field. * @return query string. if map is not empty, return query string. ex) name1=value&name2=value&... * @deprecated (since 5.0.1, to support nested fields in f:query, Use {@link #mapToQuery(Map)} instead of this method.) */ @Deprecated public static String mapToQuery(Map<String, Object> map, BeanWrapper beanWrapper) { if (map == null || map.isEmpty()) { return ""; } UriComponentsBuilder builder = UriComponentsBuilder.fromPath(""); for (Map.Entry<String, Object> e : map.entrySet()) { String name = e.getKey(); Object value = e.getValue(); TypeDescriptor sourceType; if (beanWrapper != null) { sourceType = beanWrapper.getPropertyTypeDescriptor(name); } else { sourceType = TypeDescriptor.forObject(value); } builder.queryParam(name, CONVERSION_SERVICE.convert(value, sourceType, STRING_DESC)); } String query = builder.build().encode().toString(); // remove the beginning symbol character('?') of the query string. return query.substring(1); }
From source file:org.haiku.haikudepotserver.pkg.PkgServiceImpl.java
@Override public String createHpkgDownloadUrl(PkgVersion pkgVersion) { return pkgVersion.tryGetHpkgURL().filter(u -> ImmutableSet.of("http", "https").contains(u.getProtocol())) .map(URL::toString).orElseGet(() -> { UriComponentsBuilder builder = UriComponentsBuilder.fromPath(URL_SEGMENT_PKGDOWNLOAD); pkgVersion.appendPathSegments(builder); builder.path("package.hpkg"); return builder.build().toUriString(); });//from w w w. jav a 2 s . c o m }
From source file:software.coolstuff.springframework.owncloud.service.impl.local.OwncloudLocalResourceServiceImpl.java
private OwncloudLocalResourceExtension createOwncloudResourceOf(Path path) { Path rootPath = getRootLocationOfAuthenticatedUser(); Path relativePath = rootPath.toAbsolutePath().relativize(path.toAbsolutePath()); URI href = URI.create(UriComponentsBuilder.fromPath("/").path(relativePath.toString()).toUriString()); String name = path.getFileName().toString(); MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM; if (Files.isDirectory(path)) { href = URI.create(UriComponentsBuilder.fromUri(href).path("/").toUriString()); mediaType = OwncloudUtils.getDirectoryMediaType(); } else {//from ww w . j a va 2 s .c om FileNameMap fileNameMap = URLConnection.getFileNameMap(); String contentType = fileNameMap.getContentTypeFor(path.getFileName().toString()); if (StringUtils.isNotBlank(contentType)) { mediaType = MediaType.valueOf(contentType); } } try { LocalDateTime lastModifiedAt = LocalDateTime.ofInstant(Files.getLastModifiedTime(path).toInstant(), ZoneId.systemDefault()); Optional<String> checksum = checksumService.getChecksum(path); if (Files.isSameFile(rootPath, path)) { name = "/"; checksum = Optional.empty(); } OwncloudLocalResourceExtension resource = OwncloudLocalResourceImpl.builder().href(href).name(name) .eTag(checksum.orElse(null)).mediaType(mediaType).lastModifiedAt(lastModifiedAt).build(); if (Files.isDirectory(path)) { return resource; } return OwncloudLocalFileResourceImpl.fileBuilder().owncloudResource(resource) .contentLength(Files.size(path)).build(); } catch (NoSuchFileException e) { throw new OwncloudResourceNotFoundException(href, getUsername()); } catch (IOException e) { val logMessage = String.format("Cannot create OwncloudResource from Path %s", path); log.error(logMessage, e); throw new OwncloudLocalResourceException(logMessage, e); } }