1 13 package info.magnolia.cms.taglibs.util; 14 15 import info.magnolia.cms.core.Content; 16 import info.magnolia.cms.util.Resource; 17 18 import java.io.IOException ; 19 20 import javax.jcr.RepositoryException; 21 import javax.servlet.http.HttpServletRequest ; 22 import javax.servlet.jsp.JspException ; 23 import javax.servlet.jsp.JspWriter ; 24 import javax.servlet.jsp.tagext.TagSupport ; 25 26 import org.apache.commons.lang.StringUtils; 27 import org.apache.commons.lang.exception.NestableRuntimeException; 28 import org.apache.log4j.Logger; 29 30 31 37 public class Breadcrumb extends TagSupport { 38 39 42 private static final long serialVersionUID = 222L; 43 44 47 private static Logger log = Logger.getLogger(Breadcrumb.class); 48 49 52 private String delimiter; 53 54 57 private int startLevel = 1; 58 59 62 private boolean excludeCurrent; 63 64 68 public void setDelimiter(String delimiter) { 69 this.delimiter = delimiter; 70 } 71 72 76 public void setStartLevel(String startLevel) { 77 this.startLevel = (new Integer (startLevel)).intValue(); 78 if (this.startLevel < 1) { 79 this.startLevel = 1; 80 } 81 } 82 83 87 public void setExcludeCurrent(boolean excludeCurrent) { 88 this.excludeCurrent = excludeCurrent; 89 } 90 91 94 public int doStartTag() throws JspException { 95 HttpServletRequest request = (HttpServletRequest ) pageContext.getRequest(); 96 Content actpage = Resource.getCurrentActivePage(request); 97 int endLevel = 0; 98 99 try { 100 endLevel = actpage.getLevel(); 101 102 if (this.excludeCurrent) { 103 endLevel--; 104 } 105 106 JspWriter out = pageContext.getOut(); 107 for (int i = this.startLevel; i <= endLevel; i++) { 108 if (i != this.startLevel) { 109 out.print(StringUtils.defaultString(this.delimiter, " > ")); } 111 out.print("<a HREF=\""); out.print(request.getContextPath()); 113 out.print(actpage.getAncestor(i).getHandleWithDefaultExtension()); 114 out.print("\">"); out.print(actpage.getAncestor(i).getTitle()); 116 out.print("</a>"); } 118 } 119 catch (RepositoryException e) { 120 log.debug("Exception caught: " + e.getMessage(), e); } 122 catch (IOException e) { 123 throw new NestableRuntimeException(e); 124 } 125 126 return super.doStartTag(); 127 } 128 129 132 public void release() { 133 this.startLevel = 1; 134 this.delimiter = null; 135 this.excludeCurrent = false; 136 super.release(); 137 } 138 139 } 140 | Popular Tags |