KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > meshcms > taglib > AdminMenu


1 /*
2  * MeshCMS - A simple CMS based on SiteMesh
3  * Copyright (C) 2004-2007 Luciano Vernaschi
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * You can contact the author at http://www.cromoteca.com
20  * and at info@cromoteca.com
21  */

22
23 package org.meshcms.taglib;
24
25 import java.io.*;
26 import java.util.*;
27 import javax.servlet.jsp.*;
28 import org.meshcms.core.*;
29 import org.meshcms.util.*;
30
31 /**
32  * Creates a menu with the following items:
33  *
34  * <ul>
35  * <li>Login,</li>
36  * <li>Control Panel,</li>
37  * <li>Edit Page,</li>
38  * <li>Edit As Plain Text,</li>
39  * <li>New Page,</li>
40  * <li>New Child Page.</li>
41  * </ul>
42  *
43  * Items are included when appropriate.
44  */

45 public final class AdminMenu extends AbstractTag {
46   public static final String JavaDoc MODE_NORMAL = "normal";
47   public static final String JavaDoc MODE_HIDDEN = "hidden";
48
49   private String JavaDoc mode;
50   private String JavaDoc separator = " ";
51   private String JavaDoc style;
52
53   public void setMode(String JavaDoc mode) {
54     this.mode = mode;
55   }
56
57   public void setSeparator(String JavaDoc separator) {
58     if (separator != null) {
59       this.separator = separator;
60     }
61   }
62
63   public void setStyle(String JavaDoc style) {
64     this.style = style;
65   }
66
67   public void writeTag() throws IOException {
68     UserInfo userInfo = (UserInfo) pageContext.getAttribute("userInfo",
69       PageContext.SESSION_SCOPE);
70     Locale locale = WebUtils.getPageLocale(pageContext);
71     ResourceBundle bundle = ResourceBundle.getBundle("org/meshcms/webui/Locales", locale);
72
73     String JavaDoc a1 = "<a" +
74       (Utils.isNullOrEmpty(style) ? "" : " class=\"" + style + "\"") +
75       " HREF=\"";
76     String JavaDoc a2 = "\">";
77     String JavaDoc a3 = "</a>";
78     List l = new ArrayList();
79
80     if (userInfo == null || userInfo.isGuest()) {
81       if (mode == null || mode.equals(MODE_NORMAL)) {
82         l.add(a1 + afp + "/login.jsp" + a2 + bundle.getString("adminLogin") + a3);
83       }
84     } else {
85       l.add(a1 + afp + "/index.jsp" + a2 + bundle.getString("homeTitle") + a3);
86
87       if (!isEdit) {
88         if (userInfo.canWrite(webSite, pagePath)) {
89           if (webSite.isVisuallyEditable(pagePath)) {
90             l.add(a1 + request.getRequestURI() + '?' + HitFilter.ACTION_NAME +
91                 '=' + HitFilter.ACTION_EDIT + a2 +
92                 bundle.getString("adminEditPage") + a3);
93           }
94
95           if (FileTypes.isPage(pagePath.getLastElement())) {
96             l.add(a1 + afp + "/editsrc.jsp?path=" + pagePath + a2 +
97                 bundle.getString("adminEditText") + a3);
98             Path pathInMenu = webSite.getSiteMap().getPathInMenu(pagePath);
99
100             if (!pathInMenu.isRoot()) {
101               Path parentPath = pathInMenu.getParent();
102
103               if (userInfo.canWrite(webSite, parentPath)) {
104                 l.add(a1 + afp + "/createpage.jsp?popup=false&amp;path=" +
105                     parentPath + a2 + bundle.getString("adminNewPage") + a3);
106               }
107             }
108
109             if (webSite.isDirectory(pathInMenu)) {
110               l.add(a1 + afp + "/createpage.jsp?popup=false&amp;path=" +
111                   pathInMenu + a2 + bundle.getString("adminNewChildPage") + a3);
112             }
113           }
114         }
115       }
116     }
117
118     getOut().write(l.size() > 0 ? Utils.generateList(l, separator) : "&nbsp;");
119   }
120
121   public String JavaDoc getMode() {
122     return mode;
123   }
124
125   public String JavaDoc getSeparator() {
126     return separator;
127   }
128
129   public String JavaDoc getStyle() {
130     return style;
131   }
132 }
133
Popular Tags