String jspFileName = jspFilePath.substring(lastIndexofSlash+1, jspFilePath.length());
//save query string for current url
String queryString = request.getQueryString();
//creating a new breadcrumb item for page request
BreadCrumbItem breadCrumbItem = new BreadCrumbItem();
//creating breadcrumb id using jsp file path
//This is guaranteed to be unique for a subcontext (eg: /modulemgt,/service-listing)
breadCrumbItem.setId(jspFileName);
Locale locale = CarbonUIUtil.getLocaleFromSession(request);
String text = CarbonUIUtil.geti18nString(label, resourceBundle, locale);
breadCrumbItem.setConvertedText(text);
//if request contains parameter 'toppage', override the value of this.topPage with
//the value set in request.
//This is useful when same page is being used @ different levels.
//eg: wsdl2code/index.jsp
//This page is being called from Tools -> WSDL2Code & Service Details -> Generate Client
String topPageParameter = request.getParameter("toppage");
if(topPageParameter != null){
boolean topPageParamValue = Boolean.valueOf(topPageParameter).booleanValue();
if(log.isDebugEnabled()){
log.debug("toppage value set from request parameter.("+topPageParamValue+").");
}
this.topPage = topPageParamValue;
}
if(! topPage){
// need to add this url as a breadcrumb
HashMap<String,List<BreadCrumbItem>> links = (HashMap<String,List<BreadCrumbItem>>) request
.getSession().getAttribute("page-breadcrumbs");
String partUrl = "";
if(queryString != null){
partUrl = jspFilePath + "?" + queryString ;
}else{
partUrl = jspFilePath;
}
if (links != null) {
//check if a breadcrumb exists for given sub context
List<BreadCrumbItem> breadcrumbsForSubContext = links.get(subContextToJSP);
int size = 0;
if(breadcrumbsForSubContext != null){
int sizeOfSubContextBreadcrumbs = breadcrumbsForSubContext.size();
//removing to stop this array getting grown with duplicates
ArrayList idsToRemove = new ArrayList();
for(int a = 0;a < sizeOfSubContextBreadcrumbs;a++){
if(breadcrumbsForSubContext.get(a).getId().equals(jspFileName)){
idsToRemove.add(a);
}
}
if(idsToRemove.size() > 0){
for (Object anIdsToRemove : idsToRemove) {
Integer i = (Integer) anIdsToRemove;
breadcrumbsForSubContext.remove(i.intValue());
}
}
size = breadcrumbsForSubContext.size();
breadCrumbItem.setOrder(size + 1);
breadCrumbItem.setLink(partUrl);
breadcrumbsForSubContext.add(breadCrumbItem);
links.put(subContextToJSP,breadcrumbsForSubContext);
request.getSession().setAttribute("page-breadcrumbs", links);
}else{
breadcrumbsForSubContext = new ArrayList<BreadCrumbItem>();
breadCrumbItem.setOrder(size + 1);
breadCrumbItem.setLink(partUrl);
breadcrumbsForSubContext.add(breadCrumbItem);
links.put(subContextToJSP,breadcrumbsForSubContext);
request.getSession().setAttribute("page-breadcrumbs", links);
}
} else {
HashMap<String,List<BreadCrumbItem>> tmp = new HashMap<String,List<BreadCrumbItem>>();
// Going inside for the first time
breadCrumbItem.setOrder(1);
breadCrumbItem.setLink(partUrl);
List<BreadCrumbItem> list = new ArrayList<BreadCrumbItem>();
list.add(breadCrumbItem);
tmp.put(subContextToJSP,list);
request.getSession().setAttribute("page-breadcrumbs", tmp);
}