if (pathProxies != null)
{
Iterator pathProxiesIter = pathProxies.iterator();
while (pathProxiesIter.hasNext())
{
Node pathProxy = (Node)pathProxiesIter.next();
if ((locatorName == null) || locatorName.equals(MenuOptionsDefinition.ANY_PROFILE_LOCATOR) ||
locatorName.equals(view.getProfileLocatorName(pathProxy)))
{
if (elementProxies == null)
{
elementProxies = new ArrayList();
}
appendMenuElementProxies(pathProxy, elementProxies);
}
}
}
}
else
{
// get visible proxy for path from view and append to
// list if unique and pass profile locator name filter
Node pathProxy = null;
try
{
pathProxy = view.getNodeProxy(optionPath, context.getPage(), true, true);
}
catch (NodeNotFoundException nnfe)
{
}
catch (SecurityException se)
{
}
if ((pathProxy != null) &&
((locatorName == null) || locatorName.equals(MenuOptionsDefinition.ANY_PROFILE_LOCATOR) ||
locatorName.equals(view.getProfileLocatorName(pathProxy))))
{
if (elementProxies == null)
{
elementProxies = new ArrayList();
}
appendMenuElementProxies(pathProxy, elementProxies);
}
}
// set relative element flag if path is relative
elementRelative = (elementRelative || !optionPath.startsWith(Folder.PATH_SEPARATOR));
}
}
// return if no proxies available
if (elementProxies == null)
{
return null;
}
}
// sort elements proxies using url and/or names if order
// specified and more than one element proxy in list
if ((order != null) && (elementProxies.size() > 1))
{
// create ordered element proxies
List orderedElementProxies = new ArrayList(elementProxies.size());
// split multiple comma separated elements orderings
// after converted to regexp pattern
String [] orderings = orderRegexpPattern(order).split(",");
// copy ordered proxies per ordering
for (int i=0; ((i < orderings.length) && (elementProxies.size() > 1)); i++)
{
String ordering = orderings[i].trim();
if (ordering.length() > 0)
{
// get ordering pattern and matcher
Pattern pattern = Pattern.compile(ordering);
Matcher matcher = null;
// use regular expression to match urls or names of
// element proxies; matched proxies are removed and
// placed in the ordered elements proxies list
Iterator elementProxiesIter = elementProxies.iterator();
while (elementProxiesIter.hasNext())
{
Node elementProxy = (Node)elementProxiesIter.next();
// get url or name to test ordering match against
String test = null;
if (ordering.charAt(0) == Folder.PATH_SEPARATOR_CHAR)
{
test = elementProxy.getUrl();
}
else
{
test = elementProxy.getName();
}
// construct or reset ordering matcher
if (matcher == null)
{
matcher = pattern.matcher(test);
}
else
{
matcher.reset(test);
}
// move proxy to ordered list if matched
if (matcher.matches())
{
orderedElementProxies.add(elementProxy);
elementProxiesIter.remove();
}
}
}
}
// copy remaining unordered proxies
orderedElementProxies.addAll(elementProxies);
// replace element proxies with ordered list
elementProxies = orderedElementProxies;
}
// expand paths if single page or folder element proxy
// has been specified in elements with no depth expansion
if (paths && (depth == 0) && (elementProxies.size() == 1) &&
((elementProxies.get(0) instanceof Folder) || (elementProxies.get(0) instanceof Page)))
{
Node parentNode = ((Node)elementProxies.get(0)).getParent();
while (parentNode != null)
{
elementProxies.add(0, parentNode);
parentNode = parentNode.getParent();
}
}
// convert elements proxies into menu elements
DefaultMenuOptionsDefinition defaultMenuOptionsDefinition = null;
ListIterator elementProxiesIter = elementProxies.listIterator();
while (elementProxiesIter.hasNext())
{
Node elementProxy = (Node)elementProxiesIter.next();
MenuElement menuElement = null;
// convert folders into nested menus if depth specified
// with no paths expansion, (negative depth values are
// interpreted as complete menu expansion)
if ((elementProxy instanceof Folder) && ((depth < 0) || (depth > 1)) && !paths)
{
// construct menu definition and associated menu
MenuDefinition nestedMenuDefinition = new DefaultMenuDefinition(elementProxy.getUrl(), depth - 1, locatorName);
menuElement = new MenuImpl(this, nestedMenuDefinition, context, null);
}
else
{
// construct shared default menu option definition and menu option