1 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 34 public final class SimpleMenu extends AbstractTag { 35 private String path; 36 private String space = "8"; 37 private String bullet = "•"; 38 private String style; 39 private String expand; 40 private boolean allowHiding = false; 41 42 public void setPath(String path) { 43 this.path = path; 44 } 45 46 public void setBullet(String bullet) { 47 if (bullet != null) { 48 this.bullet = bullet; 49 } 50 } 51 52 public void setStyle(String 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 + " "); 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 getPath() { 104 return path; 105 } 106 107 public String getSpace() { 108 return space; 109 } 110 111 public void setSpace(String space) { 112 this.space = space; 113 } 114 115 public String getBullet() { 116 return bullet; 117 } 118 119 public String getStyle() { 120 return style; 121 } 122 123 public String getExpand() { 124 return expand; 125 } 126 127 public void setExpand(String 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
|