KickJava   Java API By Example, From Geeks To Geeks.

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


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
28 import org.meshcms.core.*;
29 import org.meshcms.util.*;
30
31 /**
32  * Creates a simple navigation menu.
33  */

34 public final class SimpleMenu extends AbstractTag {
35   private String JavaDoc path;
36   private String JavaDoc space = "8";
37   private String JavaDoc bullet = "•";
38   private String JavaDoc style;
39   private String JavaDoc expand;
40   private boolean allowHiding = false;
41
42   public void setPath(String JavaDoc path) {
43     this.path = path;
44   }
45
46   public void setBullet(String JavaDoc bullet) {
47     if (bullet != null) {
48       this.bullet = bullet;
49     }
50   }
51
52   public void setStyle(String JavaDoc style) {
53     this.style = style;
54   }
55
56   public void writeTag() throws IOException {
57     SiteMap siteMap = webSite.getSiteMap();
58     SiteInfo siteInfo = webSite.getSiteInfo();
59     Path rootPath = (path == null) ? siteInfo.getThemeRoot(pagePath) : new Path(path);
60     Path pathInMenu = webSite.getSiteMap().getPathInMenu(pagePath);
61     int baseLevel = rootPath.getElementCount() + 1;
62     int spc = Utils.parseInt(space, 8);
63     SiteMapIterator iter = new SiteMapIterator(webSite, rootPath);
64     iter.setSkipHiddenSubPages(allowHiding);
65     Writer outWriter = getOut();
66
67     while (iter.hasNext()) {
68       PageInfo current = (PageInfo) iter.next();
69       Path currentPath = current.getPath();
70       Path parentPath = currentPath.getParent();
71
72       if (parentPath.isRelative() || pathInMenu.isContainedIn(parentPath)) {
73         if (Utils.isTrue(expand) ||
74             pathInMenu.isContainedIn(currentPath) ||
75             currentPath.getElementCount() == baseLevel ||
76             currentPath.getElementCount() >= pathInMenu.getElementCount()) {
77           outWriter.write("<div style=\"padding-left: " +
78             (spc * Math.max(current.getLevel() - baseLevel, 0)) + "px;\">");
79
80           if (style != null) {
81             outWriter.write("<div class=\"" + style + "\">");
82           }
83
84           outWriter.write(bullet + "&nbsp;");
85
86           if (!isEdit && current.getPath().equals(pathInMenu)) {
87             outWriter.write(siteInfo.getPageTitle(current));
88           } else {
89             outWriter.write("<a HREF=\"" + cp + webSite.getLink(current) +
90               "\">" + siteInfo.getPageTitle(current) + "</a>");
91           }
92
93           if (style != null) {
94             outWriter.write("</div>");
95           }
96
97           outWriter.write("</div>\n");
98         }
99       }
100     }
101   }
102
103   public String JavaDoc getPath() {
104     return path;
105   }
106
107   public String JavaDoc getSpace() {
108     return space;
109   }
110
111   public void setSpace(String JavaDoc space) {
112     this.space = space;
113   }
114
115   public String JavaDoc getBullet() {
116     return bullet;
117   }
118
119   public String JavaDoc getStyle() {
120     return style;
121   }
122
123   public String JavaDoc getExpand() {
124     return expand;
125   }
126
127   public void setExpand(String JavaDoc expand) {
128     this.expand = expand;
129   }
130
131   public boolean getAllowHiding() {
132     return allowHiding;
133   }
134
135   public void setAllowHiding(boolean allowHiding) {
136     this.allowHiding = allowHiding;
137   }
138 }
139
Popular Tags