You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by cb...@apache.org on 2019/05/29 18:06:23 UTC
svn commit: r1860363 -
/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BreadcrumbTool.java
Author: cbrisson
Date: Wed May 29 18:06:22 2019
New Revision: 1860363
URL: http://svn.apache.org/viewvc?rev=1860363&view=rev
Log:
[view-tools] BreadcrumbTool: Add overridable method for navigation elements customization
Modified:
velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BreadcrumbTool.java
Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BreadcrumbTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BreadcrumbTool.java?rev=1860363&r1=1860362&r2=1860363&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BreadcrumbTool.java (original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BreadcrumbTool.java Wed May 29 18:06:22 2019
@@ -156,6 +156,7 @@ public class BreadcrumbTool extends Loca
String uri = request.getRequestURI();
// infer extension
String ext = getExtension(uri);
+ // deduce default index page
String index = "index." + ext;
if ("/".equals(uri)) uri = "/" + index;
String elements[] = uri.split("/");
@@ -163,17 +164,36 @@ public class BreadcrumbTool extends Loca
StringBuilder builder = new StringBuilder();
for (String elem : elements)
{
+ // for each URI path element
builder.append(elem);
String currentPath = builder.toString();
if (index.equals(elem)) continue;
if (!elem.endsWith('.' + ext)) currentPath = currentPath + '/' + index;
String name = builder.length() == 0 ? "home" : elem.replace('_', ' ').toLowerCase(getLocale());
- navigationElements.add(new NavigationElement(currentPath, name));
+ NavigationElement navElem = new NavigationElement(currentPath, name);
+ // give a chance to subclasses to customize an item
+ if (customize(navElem, request))
+ {
+ navigationElements.add(navElem);
+ }
builder.append('/');
}
}
/**
+ * <p>Let the user customize programmatically the name and URL of a specific element.</p>
+ * <p>For instance, one can do use query parameters to customize the displayed name or target URL.</p>
+ * @param navElem navigation element
+ * @param request initial request
+ * @return true (default value) to include this navigation element, false to skip it
+ */
+ protected boolean customize(NavigationElement navElem, HttpServletRequest request)
+ {
+ // default implementation does nothing
+ return true;
+ }
+
+ /**
* Configuration
*/
@Override