【问题标题】:How to get the complete path of a page in AEM?如何在 AEM 中获取页面的完整路径?
【发布时间】:2018-01-24 23:20:11
【问题描述】:

我正在尝试获取页面的完整路径,以便将其转换为 url。

到目前为止我已经尝试过,

private static String PAGE = "/content/geometrixx/en/toolbar";
private static String URL_TO_OPEN;

public static String getUrl(Set<String> pages, ResourceResolver resolver){

  Resource htmlPage = resolver.getResource(PAGE);

  if(htmlPage != null){

  URL_TO_OPEN = htmlPage.getPath().concat(StringConstraints.DOT).concat(StringConstraints.HTML);
  return URL_TO_OPEN;
  }
}

在这种情况下, URL_TO_OPEN = "/content/geometrixx/en/toolbar.html"

但我需要的是,例如,“http://localhost:4502/content/geometrixx/en/toolbar.html

有人可以帮我解决一下如何让它变成这种格式,也就是获取 [hostname]:[port] 吗?

http://[hostname]:[port]/content/geometrixx/en/toolbar.html

【问题讨论】:

标签: java aem


【解决方案1】:

这可以使用 Externalizer OSGi 服务来完成

在外部化服务配置中添加映​​射

local http://localhost:4502
author http://localhost:4502
publish http://localhost:4503

获取网址

String myURL = externalizer.externalLink(resolver, Externalizer.LOCAL, PAGE) + ".html";

这将创建 URL

http://localhost:4502/content/geometrixx/en/toolbar.html

请参考documentation

【讨论】:

    猜你喜欢
    • 2020-08-03
    • 2019-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多