我声明了LanguageManager类,但没有得到如何实例化它。
ResourceResolver res = resource.getResourceResolver();
**LanguageManager languagemanager= null;**
final PageManager pageManager = resource.getResourceResolver().adaptTo(
PageManager.class);
final Page currentPage = pageManager.getContainingPage(resource);
String currentPagePath = currentPage.getPath();
SlingBindings bindings = (SlingBindings) request
.getAttribute(SlingBindings.class.getName());
for (final Page page : languagemanager.getLanguageRoots(res,
currentPagePath)) {
languagePages.put(page.getLanguage(false), page);
}
答案 0 :(得分:1)
有一个实现LanguageManager接口的OSGi服务(com.day.cq.wcm.core.impl.LanguageManagerImpl),因此您应该能够在Sling模型中使用@Inject注释引用它。 / p>
@Inject
private final LanguageManager languageManager;