KickJava   Java API By Example, From Geeks To Geeks.

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


1 package info.magnolia.cms.taglibs;
2
3 import info.magnolia.cms.beans.config.Server;
4 import info.magnolia.cms.gui.misc.Sources;
5
6 import java.io.IOException JavaDoc;
7
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9 import javax.servlet.jsp.JspException JavaDoc;
10 import javax.servlet.jsp.JspWriter JavaDoc;
11 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
12
13 import org.apache.commons.lang.exception.NestableRuntimeException;
14
15
16 /**
17  * Draw css and js links for admin controls. Separated from mainbar since css links must be inside html head.
18  * @author Fabrizio Giustina
19  * @version $Revision: 1254 $ ($Author: fgiust $)
20  * @since 2.1
21  */

22 public class LinksTag extends TagSupport JavaDoc {
23
24     /**
25      * Stable serialVersionUID.
26      */

27     private static final long serialVersionUID = 222L;
28
29     /**
30      * Show links only in admin instance, default to <code>true</code>.
31      */

32     private boolean adminOnly = true;
33
34     /**
35      * @see javax.servlet.jsp.tagext.Tag#doStartTag()
36      */

37     public int doStartTag() throws JspException JavaDoc {
38         if (!adminOnly || Server.isAdmin()) {
39
40             HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) this.pageContext.getRequest();
41
42             // check if links have already been added.
43
if (request.getAttribute(Sources.REQUEST_LINKS_DRAWN) == null) {
44
45                 Sources src = new Sources(request.getContextPath());
46                 JspWriter JavaDoc out = this.pageContext.getOut();
47                 try {
48                     out.write(src.getHtmlCss());
49                     out.write(src.getHtmlJs());
50                 }
51                 catch (IOException JavaDoc e) {
52                     // should never happen
53
throw new NestableRuntimeException(e);
54                 }
55
56                 request.setAttribute(Sources.REQUEST_LINKS_DRAWN, Boolean.TRUE);
57             }
58         }
59
60         return EVAL_PAGE;
61     }
62
63     /**
64      * Setter for the <code>adminOnly</code> tag attribute.
65      * @param adminOnly <code>false</code> if links should be written also in a public instance (default to
66      * <code>true</code>).
67      */

68     public void setAdminOnly(boolean adminOnly) {
69         this.adminOnly = adminOnly;
70     }
71
72     /**
73      * @see javax.servlet.jsp.tagext.Tag#release()
74      */

75     public void release() {
76         this.adminOnly = true;
77         super.release();
78     }
79
80 }
81
Popular Tags