1 22 23 package org.meshcms.taglib; 24 25 import java.io.*; 26 import java.util.*; 27 import org.meshcms.core.*; 28 import org.meshcms.util.*; 29 30 33 public final class AlibMenu extends AbstractTag { 34 public static final String PART_HEAD = "head"; 35 public static final String PART_BODY = "body"; 36 public static final String HORIZONTAL = "horizontal"; 37 public static final String VERTICAL = "vertical"; 38 39 private String indentation = " "; 40 private String indentBuffer = ""; 41 42 private String orientation; 43 private String part; 44 private String path; 45 private String current; 46 private String currentPathStyle = "selected"; 47 private String allowHiding = "true"; 48 49 public void writeTag() throws IOException { 50 Writer outWriter = getOut(); 51 boolean horizontal = orientation != null && orientation.equals(HORIZONTAL); 52 53 if (part != null && part.equals(PART_HEAD)) { 54 String sp = request.getContextPath() + 55 webSite.getAdminScriptsPath().getAsLink() + "/alib"; 56 String menuType = horizontal ? HORIZONTAL : VERTICAL; 57 outWriter.write("<script SRC='" + sp + 58 "/alib.common/script.js' type='text/javascript'></script>\n"); 59 outWriter.write("<script SRC='" + sp + 60 "/menu." + menuType + "/script.js' type='text/javascript'></script>\n"); 61 outWriter.write("<link type='text/css' HREF='" + 62 WebUtils.getFullThemeFolder(request) + "/alib.css' rel='stylesheet' />\n"); 63 } else { 64 SiteMap siteMap = webSite.getSiteMap(); 65 SiteInfo siteInfo = webSite.getSiteInfo(); 66 Path rootPath = (path == null) ? siteInfo.getThemeRoot(pagePath) : new Path(path); 67 Path pathInMenu = webSite.getSiteMap().getPathInMenu(pagePath); 68 int baseLevel = rootPath.getElementCount() + 1; 69 int lastLevel = rootPath.getElementCount(); 70 SiteMapIterator iter = new SiteMapIterator(webSite, rootPath); 71 iter.setSkipHiddenSubPages(Utils.isTrue(allowHiding)); 72 boolean liUsed = false; 73 boolean firstUl = true; 74 75 while (iter.hasNext()) { 76 PageInfo current = (PageInfo) iter.next(); 77 Path currentPath = current.getPath(); 78 int level = Math.max(baseLevel, current.getLevel()); 79 80 for (int i = lastLevel; i < level; i++) { 81 if (firstUl) { 82 writeIndented(outWriter, "<ul class=\"" + 83 (horizontal ? "hmenu" : "vmenu") + "\">", i); 84 firstUl = false; 85 } else { 86 writeIndented(outWriter, "<ul>", i); 87 } 88 89 writeIndented(outWriter, "<li>", i + 1); 90 liUsed = false; 91 } 92 93 for (int i = lastLevel - 1; i >= level; i--) { 94 if (liUsed) { 95 outWriter.write("</li>"); 96 liUsed = false; 97 } else { 98 writeIndented(outWriter, "</li>", i + 1); 99 } 100 101 writeIndented(outWriter, "</ul>", i); 102 } 103 104 if (liUsed) { 105 outWriter.write("</li>"); 106 writeIndented(outWriter, "<li>", level); 107 } 108 109 for ( int i = lastLevel - 1; i >= level; i--) { 110 writeIndented(outWriter, "</li>", i); 111 writeIndented(outWriter, "<li>", i); 112 } 113 114 if ( ! Utils.isNullOrEmpty(currentPathStyle) 115 && ( current.getLevel() >= baseLevel 116 && pathInMenu.isContainedIn(currentPath) 117 || current.getPath().equals(pathInMenu) 118 ) ) { 119 outWriter.write("<a HREF=\"" + cp + webSite.getLink(current) + 120 "\" class='" + currentPathStyle + "'>" + 121 siteInfo.getPageTitle(current) + "</a>"); 122 } else { 123 outWriter.write("<a HREF=\"" + cp + webSite.getLink(current) +"\">" + 124 siteInfo.getPageTitle(current) + "</a>"); 125 } 126 127 liUsed = true; 128 lastLevel = level; 129 } 130 131 for (int i = lastLevel - 1; i >= rootPath.getElementCount(); i--) { 132 writeIndented(outWriter, "</li>", i + 1); 133 writeIndented(outWriter, "</ul>", i); 134 } 135 } 136 } 137 138 private void writeIndented(Writer w, String s, int level) throws IOException { 139 while (indentBuffer.length() < indentation.length() * level) { 140 indentBuffer += indentation; 141 } 142 143 w.write('\n'); 144 w.write(indentBuffer, 0, indentation.length() * level); 145 w.write(s); 146 } 147 148 public String getPath() { 149 return path; 150 } 151 152 public void setPath(String path) { 153 this.path = path; 154 } 155 156 public String getCurrent() { 157 return current; 158 } 159 160 public void setCurrent(String current) { 161 this.current = current; 162 } 163 164 public String getOrientation() { 165 return orientation; 166 } 167 168 public void setOrientation(String orientation) { 169 this.orientation = orientation; 170 } 171 172 public String getPart() { 173 return part; 174 } 175 176 public void setPart(String part) { 177 this.part = part; 178 } 179 180 public String getCurrentPathStyle() { 181 return currentPathStyle; 182 } 183 184 public void setCurrentPathStyle(String currentPathStyle) { 185 this.currentPathStyle = currentPathStyle; 186 } 187 188 public String getAllowHiding() { 189 return allowHiding; 190 } 191 192 public void setAllowHiding(String allowHiding) { 193 this.allowHiding = allowHiding; 194 } 195 } 196 | Popular Tags |