Created
January 2, 2019 15:00
-
-
Save sgaem/d912358c2a3aec83f96f5a129872ba6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.aem.project.core.models; | |
import com.day.cq.wcm.api.Page; | |
import org.apache.sling.api.SlingHttpServletRequest; | |
import org.apache.sling.api.resource.Resource; | |
import org.apache.sling.models.annotations.DefaultInjectionStrategy; | |
import org.apache.sling.models.annotations.Model; | |
import org.apache.sling.models.annotations.injectorspecific.RequestAttribute; | |
import org.apache.sling.models.annotations.injectorspecific.ScriptVariable; | |
import org.apache.sling.models.annotations.injectorspecific.SlingObject; | |
import java.util.HashMap; | |
import java.util.Iterator; | |
import java.util.Map; | |
@Model(adaptables = SlingHttpServletRequest.class,defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) | |
public class HelloWorldModel { | |
@SlingObject | |
private Resource resource; | |
@RequestAttribute | |
private String pageTitle; | |
@ScriptVariable | |
private Page currentPage; | |
@RequestAttribute(name = "pageNae") | |
private String name; | |
public String getPageTitle() { | |
return pageTitle; | |
} | |
public String getName() { | |
return name; | |
} | |
public String getPath() { | |
return resource.getPath(); | |
} | |
public Map<String, String> getMap() { | |
Map<String,String> map = new HashMap<>(); | |
Iterator<Page> iterator = currentPage.listChildren(); | |
while (iterator.hasNext()) | |
{ | |
Page child = iterator.next(); | |
map.put(child.getName(),child.getPath()); | |
} | |
return map; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment