List filteredMenuList = (List) o;
if(filteredMenuList!=null && !filteredMenuList.isEmpty()){
result = new JSONObject();
JSONArray tempFirstLevelMenuList = new JSONArray();
for (int i=0; i<filteredMenuList.size(); i++){
Menu menuElem = (Menu)filteredMenuList.get(i);
String path=MenuUtilities.getMenuPath(menuElem);
if (menuElem.getLevel().intValue() == 1){
JSONObject temp = new JSONObject();
temp.put(NAME, "menu"+i);
temp.put(ID, menuElem.getMenuId());
MessageBuilder msgBuild=new MessageBuilder();
String text = "";
if (!menuElem.isAdminsMenu() || !menuElem.getName().startsWith("#"))
text = msgBuild.getUserMessage(menuElem.getName(),null, locale);
else{
if (menuElem.getName().startsWith("#")){
String titleCode = menuElem.getName().substring(1);
text = msgBuild.getMessage(titleCode, locale);
} else {
text = menuElem.getName();
}
}
temp.put(TEXT, text);
temp.put(PATH, path);
String icon=DetailMenuModule.assignImage(menuElem);
if(menuElem.isViewIcons() && !icon.equalsIgnoreCase("")){
temp.put(ICON, contextName+defaultThemePath+icon);
}
if(menuElem.getObjId()!=null){
temp.put(HREF, "execDirectUrl('"+contextName+"/servlet/AdapterHTTP?ACTION_NAME=MENU_BEFORE_EXEC&MENU_ID="+menuElem.getMenuId()+"', '"+path+"' )");
}else if(menuElem.getStaticPage()!=null){
temp.put(HREF, "execDirectUrl('"+contextName+"/servlet/AdapterHTTP?ACTION_NAME=READ_HTML_FILE&MENU_ID="+menuElem.getMenuId()+"', '"+path+"' )");
}else if(menuElem.getFunctionality()!=null){
temp.put(HREF, "execDirectUrl('"+DetailMenuModule.findFunctionalityUrl(menuElem, contextName)+"', '"+path+"')");
}else if(menuElem.getExternalApplicationUrl()!=null){
temp.put(HREF, "callExternalApp('"+StringEscapeUtils.escapeJavaScript(menuElem.getExternalApplicationUrl())+"', '"+path+"')");
}else if (menuElem.isAdminsMenu() && menuElem.getUrl()!=null){
String url = "javascript:execDirectUrl('"+ menuElem.getUrl()+"'";
url = url.replace("${SPAGOBI_CONTEXT}",contextName);
url = url.replace("${SPAGO_ADAPTER_HTTP}", GeneralUtilities.getSpagoAdapterHttpUrl());
path = path.replace("#","");
temp.put(HREF, url+", '"+path+"')");
}
if (menuElem.getHasChildren()){
List lstChildrenLev2 = menuElem.getLstChildren();
JSONArray tempMenuList =(JSONArray)getChildren(lstChildrenLev2, 1,locale);
temp.put(ITEMS, tempMenuList);
}
tempFirstLevelMenuList.put(temp);
}