1 13 package info.magnolia.cms.taglibs; 14 15 import info.magnolia.cms.Aggregator; 16 import info.magnolia.cms.core.Content; 17 import info.magnolia.cms.core.HierarchyManager; 18 import info.magnolia.cms.security.SessionAccessControl; 19 import info.magnolia.cms.util.Resource; 20 21 import javax.jcr.RepositoryException; 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.jsp.PageContext ; 24 import javax.servlet.jsp.tagext.BodyTagSupport ; 25 26 import org.apache.commons.lang.StringUtils; 27 import org.apache.log4j.Logger; 28 29 30 37 public class LoadPage extends BodyTagSupport { 38 39 42 private static final long serialVersionUID = 222L; 43 44 47 private static Logger log = Logger.getLogger(LoadPage.class); 48 49 52 private String path; 53 54 57 private String templateName; 58 59 62 private int level; 63 64 68 public void setPath(String path) { 69 this.path = path; 70 } 71 72 76 public void setTemplateName(String templateName) { 77 this.templateName = templateName; 78 } 79 80 84 public void setLevel(int level) { 85 this.level = level; 86 } 87 88 91 public int doEndTag() { 92 HttpServletRequest req = (HttpServletRequest ) pageContext.getRequest(); 93 Content newActpage = Resource.getCurrentActivePage(req); 94 if (StringUtils.isNotEmpty(this.templateName)) { 95 Content startPage; 96 try { 97 startPage = Resource.getCurrentActivePage(req).getAncestor(this.level); 98 HierarchyManager hm = SessionAccessControl.getHierarchyManager(req); 99 newActpage = hm.getPage(startPage.getHandle(), this.templateName); 100 } 101 catch (RepositoryException e) { 102 log.error(e.getMessage()); 103 return EVAL_PAGE; 104 } 105 } 106 else if (StringUtils.isNotEmpty(this.path)) { 107 try { 108 newActpage = SessionAccessControl.getHierarchyManager(req).getContent(this.path); 109 } 110 catch (Exception e) { 111 log.error(e.getMessage()); 112 return EVAL_PAGE; 113 } 114 } 115 else { 116 try { 117 newActpage = Resource.getCurrentActivePage(req).getAncestor(this.level); 118 } 119 catch (Exception e) { 120 log.error(e.getMessage()); 121 return EVAL_PAGE; 122 } 123 } 124 pageContext.setAttribute(Aggregator.CURRENT_ACTPAGE, newActpage, PageContext.REQUEST_SCOPE); 125 return EVAL_PAGE; 126 } 127 128 131 public void release() { 132 super.release(); 133 this.path = null; 134 this.templateName = null; 135 this.level = 0; 136 } 137 } 138 | Popular Tags |