KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > taglibs > LoadPage


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

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 JavaDoc;
23 import javax.servlet.jsp.PageContext JavaDoc;
24 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
25
26 import org.apache.commons.lang.StringUtils;
27 import org.apache.log4j.Logger;
28
29
30 /**
31  * Loads another page into actpage. One usage would be within a site-menu structure. loadPage does not nest pages, so
32  * the corresponding unloadPage-tag will not revert to the previously loaded page, but restore actpage to the currently
33  * displayed page, i.e. the value it held before loadPage was called for the first time.
34  * @author Marcel Salathe
35  * @version $Revision: 1275 $ ($Author: fgiust $)
36  */

37 public class LoadPage extends BodyTagSupport JavaDoc {
38
39     /**
40      * Stable serialVersionUID.
41      */

42     private static final long serialVersionUID = 222L;
43
44     /**
45      * Logger.
46      */

47     private static Logger log = Logger.getLogger(LoadPage.class);
48
49     /**
50      * Tag attribute: path of the page to be loaded.
51      */

52     private String JavaDoc path;
53
54     /**
55      * Tag attribute: template name.
56      */

57     private String JavaDoc templateName;
58
59     /**
60      * Tag attribute: level.
61      */

62     private int level;
63
64     /**
65      * Setter for the "path" tag attribute.
66      * @param path path of the page to be loaded
67      */

68     public void setPath(String JavaDoc path) {
69         this.path = path;
70     }
71
72     /**
73      * Setter for the "templateName" tag attribute.
74      * @param templateName
75      */

76     public void setTemplateName(String JavaDoc templateName) {
77         this.templateName = templateName;
78     }
79
80     /**
81      * Setter for the "level" tag attribute.
82      * @param level
83      */

84     public void setLevel(int level) {
85         this.level = level;
86     }
87
88     /**
89      * @see javax.servlet.jsp.tagext.Tag#doEndTag()
90      */

91     public int doEndTag() {
92         HttpServletRequest JavaDoc req = (HttpServletRequest JavaDoc) 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 JavaDoc 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 JavaDoc 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     /**
129      * @see javax.servlet.jsp.tagext.Tag#release()
130      */

131     public void release() {
132         super.release();
133         this.path = null;
134         this.templateName = null;
135         this.level = 0;
136     }
137 }
138
Popular Tags