Beispiel #1
0
  private String path(UriComponentsBuilder builder, Page page, boolean encode) {
    Map<String, Object> params = new HashMap<>();

    PageTree pageTree =
        (PageTree) processingContext.getContext().getVariables().get("PAGE_TREE_ALL");
    //		PageTree pageTree =
    // defaultModelAttributeService.readPageTree(LocaleContextHolder.getLocale().getLanguage());
    List<String> codes = new LinkedList<>();
    Page parent = page.getParent();
    while (parent != null) {
      codes.add(parent.getCode());
      parent =
          (parent.getParent() != null)
              ? pageTree.getPageByCode(parent.getParent().getCode())
              : null;
    }

    Collections.reverse(codes);
    codes.add(page.getCode());

    for (int i = 0; i < codes.size(); i++) {
      String key = "code" + i;
      builder.path("/{" + key + "}");
      params.put(key, codes.get(i));
    }

    UriComponents components = builder.buildAndExpand(params);
    if (encode) {
      components = components.encode();
    }
    return components.toUriString();
  }
Beispiel #2
0
  private String path(UriComponentsBuilder builder, Article article, boolean encode) {
    Map<String, Object> params = new HashMap<>();
    builder.path("/{year}/{month}/{day}/{code}");
    params.put("year", String.format("%04d", article.getDate().getYear()));
    params.put("month", String.format("%02d", article.getDate().getMonthOfYear()));
    params.put("day", String.format("%02d", article.getDate().getDayOfMonth()));
    params.put("code", article.getCode());

    UriComponents components = builder.buildAndExpand(params);
    if (encode) {
      components = components.encode();
    }
    return components.toUriString();
  }