Index: ../magnolia-3.5-trunk/magnolia-taglib-utility/src/main/java/info/magnolia/cms/taglibs/util/SimpleNavigationTag.java =================================================================== --- ../magnolia-3.5-trunk/magnolia-taglib-utility/src/main/java/info/magnolia/cms/taglibs/util/SimpleNavigationTag.java (revision 14491) +++ ../magnolia-3.5-trunk/magnolia-taglib-utility/src/main/java/info/magnolia/cms/taglibs/util/SimpleNavigationTag.java Sat Feb 09 23:58:52 MST 2008 @@ -37,26 +37,24 @@ import info.magnolia.cms.core.ItemType; import info.magnolia.cms.i18n.I18nContentSupportFactory; import info.magnolia.cms.util.Resource; +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.exception.NestableRuntimeException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.jcr.RepositoryException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.JspWriter; +import javax.servlet.jsp.tagext.TagSupport; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; -import javax.jcr.RepositoryException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.jsp.JspException; -import javax.servlet.jsp.JspWriter; -import javax.servlet.jsp.tagext.TagSupport; -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.exception.NestableRuntimeException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - /** * Draws a simple, css based, navigation menu. The menu layout can then be customized using css, and the default menu * should be enough for most uses. Two following page properties will also be used in the menu: @@ -95,12 +93,12 @@ /** * Css class added to active page. */ - private static final String CSS_LI_ACTIVE = "active"; + private static final String CSS_LI_ACTIVE = "active"; //$NON-NLS-1$ /** * Css class added to ancestor of the active page. */ - private static final String CSS_LI_TRAIL = "trail"; + private static final String CSS_LI_TRAIL = "trail"; //$NON-NLS-1$ /** * Css class added to leaf pages. @@ -145,22 +143,34 @@ /** * Expand all expand all the nodes */ - public static final String EXPAND_ALL = "all"; + public static final String EXPAND_ALL = "all"; //$NON-NLS-1$ /** * Expand all expand only page that should be displayed in navigation */ - public static final String EXPAND_SHOW = "show"; + public static final String EXPAND_SHOW = "show"; //$NON-NLS-1$ /** * Do not use expand functions */ - public static final String EXPAND_NONE = "none"; + public static final String EXPAND_NONE = "none"; //$NON-NLS-1$ /** + * Relative mode adjusts the start and end level based on the parent page + */ + public static final String LEVEL_MODE_RELATIVE = "relative"; //$NON-NLS-1$ + + /** + * Normal level mode is the default move + */ + public static final String LEVEL_MODE_NORMAL = "normal"; //$NON-NLS-1$ + + + + /** * Stable serialVersionUID. */ - private static final long serialVersionUID = 223L; + private static final long serialVersionUID = 224L; /** * Logger. @@ -168,6 +178,11 @@ private static Logger log = LoggerFactory.getLogger(SimpleNavigationTag.class); /** + * Active page level. + */ + private int activePageLevel = 0; + + /** * Start level. */ private int startLevel; @@ -209,6 +224,11 @@ private String classProperty; /** + * Property determining how to handle the levels... + */ + private String levelHandlingMode = LEVEL_MODE_NORMAL; + + /** * Setter for the startLevel tag attribute. * @param startLevel the start level for navigation, defaults to 0. */ @@ -249,6 +269,16 @@ } /** + * If the levelHandlingMode is set to "relative" the startLevel and endLevel + * are treated relative to the current active page. + * + * @param levelHandlingMode mode that tells it how to process the level + */ + public void setLevelHandlingMode(String levelHandlingMode) { + this.levelHandlingMode = levelHandlingMode; + } + + /** * @param expandAll The expandAll to set. If the value is different than EXPAND_SHOW then the call * expandAll is set to EXPAND_ALL */ @@ -289,10 +319,19 @@ } try { + activePageLevel = activePage.getLevel(); + + // if we are to treat the start and end level as relative + // to the active page, we adjust them here... + if (this.levelHandlingMode.equals(LEVEL_MODE_RELATIVE)) { + this.startLevel += activePageLevel; + this.endLevel += activePageLevel; + } if (this.startLevel <= activePage.getLevel()) { Content startContent = activePage.getAncestor(this.startLevel); drawChildren(startContent, activePage, out); } + } catch (RepositoryException e) { log.error("RepositoryException caught while drawing navigation: " + e.getMessage(), e); //$NON-NLS-1$ @@ -316,6 +355,8 @@ this.style = null; this.classProperty = null; this.expandAll = EXPAND_NONE; + this.wrapperElement = ""; + this.activePageLevel = 0; super.release(); } @@ -450,7 +491,7 @@ if (StringUtils.isNotEmpty(this.wrapperElement)) { out.print(""); //$NON-NLS-1$ } - + out.print(" "); //$NON-NLS-1$ if (self) { Index: ../magnolia-3.5-trunk/magnolia-taglib-utility/src/main/resources/META-INF/cms-util-taglib.tld =================================================================== --- ../magnolia-3.5-trunk/magnolia-taglib-utility/src/main/resources/META-INF/cms-util-taglib.tld (revision 14491) +++ ../magnolia-3.5-trunk/magnolia-taglib-utility/src/main/resources/META-INF/cms-util-taglib.tld Sun Feb 10 00:00:09 MST 2008 @@ -38,7 +38,7 @@ nodeDataName false true - + node containing the link information atomName @@ -308,6 +308,16 @@ When specified, all links will have the anchortext wrapped in the supplied element (such as "span") + + levelHandlingMode + false + true + + Set this to "relative" if you want to treat the start level and end level as being relative to the active + page. The default value is "normal". + + +