in velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BreadcrumbTool.java [197:298]
protected void configure(ValueParser config)
{
if (request == null)
{
getLog().warn("cannot build breadcrumb: no provided request");
return;
}
String encoding = Optional.ofNullable(request.getCharacterEncoding()).orElse("UTF-8");
String uri = request.getRequestURI();
try
{
uri = URLDecoder.decode(uri, encoding);
}
catch (UnsupportedEncodingException uee)
{
getLog().error("Cannot decode URI using encoding {}", encoding);
return;
}
// infer extension
String ext = getExtension(uri);
// deduce default index page
String index = "index." + ext;
if ("/".equals(uri)) uri = "/" + index;
String elements[] = uri.split("/");
navigationElements = new ArrayList<NavigationElement>();
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))
{
elem = elem.substring(0, elem.length() - (ext.length() + 1));
}
else
{
currentPath = currentPath + '/' + index;
if (elem.length() == 0) elem = "home";
}
String name = builder.length() == 0 ? "home" : formatElementName(elem);
NavigationElement navElem = new NavigationElement(currentPath, name);
// give a chance to subclasses to customize an item
if (customize(navElem, request))
{
navigationElements.add(navElem);
// check configuration
Object obj = config.get(elem);
if (obj != null && obj instanceof ValueParser)
{
String queryParamName = null;
String queryParamValue = null;
ValueParser values = (ValueParser) obj;
// customize navigation element name
String newName = values.getString("name");
if (newName != null)
{
if (newName.startsWith("?"))
{
queryParamName = newName.substring(1);
queryParamValue = request.getParameter(queryParamName);
if (queryParamValue != null)
{
navElem.setName(queryParamValue);
}
}
else
{
navElem.setName(newName);
}
}
// customize navigation element URL
String newURL = values.getString("url");
if (queryParamValue == null)
{
if (newURL != null)
{
navElem.setUrl(newURL);
}
}
else
{
if (newURL == null)
{
newURL = navElem.getUrl();
}
newURL += newURL.indexOf('?') == -1 ? '?' : '&';
newURL += queryParamName + '=' + queryParamValue;
navElem.setUrl(newURL);
}
}
}
builder.append('/');
}
}