%--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--%>
<%@page language="java" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<%@page import="org.apache.commons.lang.StringEscapeUtils"%>
<%@page import="org.apache.commons.logging.Log"%>
<%@page import="org.apache.commons.logging.LogFactory"%>
<%@page import="org.apache.jetspeed.portalsite.PortalSiteRequestContext"%>
<%@page import="org.apache.jetspeed.portalsite.Menu"%>
<%@page import="java.util.Locale"%>
<%@page import="java.util.Iterator"%>
<%@page import="org.apache.jetspeed.portalsite.MenuElement"%>
<%@page import="org.apache.jetspeed.layout.JetspeedPowerTool"%>
<%@page import="javax.portlet.RenderRequest"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@page import="org.apache.jetspeed.portalsite.MenuOption"%>
<%@page import="org.apache.jetspeed.portalsite.MenuSeparator"%>
<%!
/**
* @author Mohan Kannapareddy
*/
private final static int INITIAL_BUFFER = 1024;
/**
* orientation: How the individual menu elements are oriented.
* supported configuration represents the constants below.
*/
private final static int LEFT_TO_RIGHT = 1;
private final static int RIGHT_TO_LEFT = 2;
private final static int TOP_TO_BOTTOM = 10;
private final static int BOTTOM_TO_TOP = 11;
/**
* titleOrder: How the title element text appears
* supported configuration represents the constants below.
*/
private final static int TITLE_ORDER_FIRST = 20;
private final static int TITLE_ORDER_LAST = 21;
private final static int TITLE_ORDER_NONE = 22;
/**
* menuStyle: currently only BREADCRUMBS_STYLE is understood.
*/
private final static int BREADCRUMBS_STYLE = 0;
private final static Map MenuOptionTypes = new HashMap();
private final static int PAGE_TYPE = 0;
private final static int FOLDER_TYPE = 1;
private final static int LINK_TYPE = 2;
private final static Map MenuElementTypes = new HashMap();
private final static int OPTION_TYPE = 0;
private final static int SEPARATOR_TYPE = 1;
private final static int MENU_TYPE = 2;
static {
MenuOptionTypes.put("page", new Integer(PAGE_TYPE));
MenuOptionTypes.put("folder", new Integer(FOLDER_TYPE));
MenuOptionTypes.put("link", new Integer(LINK_TYPE));
MenuElementTypes.put("option", new Integer(OPTION_TYPE));
MenuElementTypes.put("separator", new Integer(SEPARATOR_TYPE));
MenuElementTypes.put("menu", new Integer(MENU_TYPE));
}
/**
*
*/
private String getNormalizedString(String s)
{
return ((s == null) ? "" : s);
}
private String getMenuElementOptionHTML(JetspeedPowerTool jpt,
MenuOption menuElmOption, Locale locale,
boolean addTarget)
{
final String TAB_INDENT_1 = "\t\t\t";
final String TAB_INDENT_2 = "\t\t\t\t";
StringBuffer sb = new StringBuffer(INITIAL_BUFFER);
// get all our text
String lnkTitle = getNormalizedString(menuElmOption.getTitle(locale));
String lnkName = getNormalizedString(menuElmOption.getShortTitle(locale));
String lnkUrl = getNormalizedString(jpt.getAbsoluteUrl(menuElmOption.getUrl()));
// now output accoding to menu type
int menuType = ((Integer)MenuOptionTypes.get(menuElmOption.getType())).intValue();
if (menuType == PAGE_TYPE)
{
sb.append(TAB_INDENT_1).
append("
\n");
}
else if (menuType == LINK_TYPE)
{
String lnkTarget = getNormalizedString(menuElmOption.getTarget());
sb.append(TAB_INDENT_1).
append("\n");
}
else if (menuType == FOLDER_TYPE)
{
sb.append(TAB_INDENT_1).
append("\n");
}
return sb.toString();
} // E: getMenuOptionHTML()
/**
* Helper method to create HTML content supporting the layout decoration
* in which it exists. This is mainly used to create the breadcrumbs.
*/
private String getLinksNavigation(RenderRequest req, Menu menu, Locale locale,
int orientation, int titleOrder,
int style, String delimiter)
{
final String TAB_INDENT_1 = "\t\t";
final String TAB_INDENT_2 = "\t\t ";
final String TAB_INDENT_3 = "\t\t ";
JetspeedPowerTool jpt = (JetspeedPowerTool) req.getAttribute("jpt");
StringBuffer sb = new StringBuffer(INITIAL_BUFFER);
// get the delimiter right
if ((null == delimiter) || delimiter.equalsIgnoreCase(""))
{
if ( style == BREADCRUMBS_STYLE)
{
delimiter = " >> ";
}
else
{
delimiter = " ";
}
}
String menuTitle = getNormalizedString(menu.getTitle(locale));
String menuName = getNormalizedString(menu.getShortTitle(locale));
sb.append(TAB_INDENT_1).
append("\n");
//check title
if (titleOrder == TITLE_ORDER_FIRST)
{
if (orientation == LEFT_TO_RIGHT)
{
sb.append(TAB_INDENT_2).
append("
").
append(StringEscapeUtils.escapeXml(menuName)).append(" \n");
}
else if (orientation == TOP_TO_BOTTOM)
{
sb.append(TAB_INDENT_2).append("
").
append(StringEscapeUtils.escapeXml(menuName)).append(TAB_INDENT_2).
append("
\n");
}
}
//start the menu
Iterator menuIterator = menu.getElements().iterator();
int i = 0;
int size = menu.getElements().size();
while(menuIterator.hasNext())
{
i++;
Object menuElmObj = menuIterator.next();
int menuElmType = ((Integer)MenuElementTypes.get(
((MenuElement)menuElmObj).getElementType())).intValue();
if (menuElmType == OPTION_TYPE)
{
MenuOption menuElm = (MenuOption) menuElmObj;
int menuType = ((Integer)MenuOptionTypes.get(menuElm.getType())).intValue();
// get all our text
String lnkTitle = getNormalizedString(menuElm.getTitle(locale));
String lnkName = getNormalizedString(menuElm.getShortTitle(locale));
String lnkUrl = getNormalizedString(jpt.getAbsoluteUrl(menuElm.getUrl()));
if ( (style != BREADCRUMBS_STYLE) ||
!(menuType == PAGE_TYPE) ||
(i < size) )
{
//start element
if (orientation == LEFT_TO_RIGHT)
{
sb.append(TAB_INDENT_2).append("
");
}
else if (orientation == TOP_TO_BOTTOM)
{
sb.append(TAB_INDENT_2).append("\n");
}
}
else
{
if (orientation == LEFT_TO_RIGHT)
{
sb.append(TAB_INDENT_2).append("").
append(StringEscapeUtils.escapeXml(lnkName)).append(" ").append("\n");
}
else if (orientation == TOP_TO_BOTTOM)
{
sb.append(TAB_INDENT_2).append("").
append(StringEscapeUtils.escapeXml(lnkName)).append("
\n");
}
} // Not BREADCRUMB_STYLE etc.
} // option type
else if(menuElmType == SEPARATOR_TYPE)
{
MenuSeparator menuElm = (MenuSeparator) menuElmObj;
String sepTitle = menuElm.getTitle(locale);
if (null == sepTitle)
sepTitle = "";
String sepText = menuElm.getText(locale);
if (null == sepText)
sepText = "";
if (orientation == LEFT_TO_RIGHT)
{
sb.append(TAB_INDENT_2).append("").
append(StringEscapeUtils.escapeXml(sepText)).append(delimiter).append("\n");
}
else if (orientation == TOP_TO_BOTTOM)
{
sb.append(TAB_INDENT_2).append("").
append(StringEscapeUtils.escapeXml(sepText)).append("
\n");
}
}
} // while menu items
if (titleOrder == TITLE_ORDER_LAST)
{
if (orientation == LEFT_TO_RIGHT)
{
sb.append(TAB_INDENT_2).append("").
append(StringEscapeUtils.escapeXml(menuName)).append(" ").append("\n");
}
else
{
sb.append(TAB_INDENT_2).append("").
append(StringEscapeUtils.escapeXml(menuName)).append("
\n");
}
}
sb.append("\t\t \n");
return sb.toString();
} // getLinksNavigation
/*
* getLinksWithIconNavigation
* This is for tigris, assumes a table already present.
*/
private String getLinksWithIconNavigation(RenderRequest req, Menu menu, Locale locale,
int orientation)
{
JetspeedPowerTool _jpt = (JetspeedPowerTool) req.getAttribute("jpt");
StringBuffer sb = new StringBuffer(INITIAL_BUFFER);
String TR_TD_START = "\n\t\t\t \n \t\t\t\t \n";
String TR_TD_END = "\n\t\t\t\t | \n \t\t\t
\n";
final String DIV_TOOLGROUP = "\t\t\t\t\t\n").
append("\t\t\t\t\t\t\t\n");
}
else if (rowStarted)
{
sb.append("\n").
append(TR_TD_END);
}
return sb.toString();
} //E: getLinksWithIconNavigation
private String getNestedLinksIconNavigation(RenderRequest req, Menu menu, Locale locale,
int orientation)
{
JetspeedPowerTool jpt = (JetspeedPowerTool) req.getAttribute("jpt");
String menuTitle = menu.getTitle(locale);
String menuName = menu.getShortTitle(locale);
StringBuffer sb = new StringBuffer(INITIAL_BUFFER);
if ((null != menuTitle) && !(menuTitle.equalsIgnoreCase("")))
{
sb.append("\t\t\t\t\t\t\t\t\t").
append("").append(StringEscapeUtils.escapeXml(menuName)).
append(StringEscapeUtils.escapeXml(menuName)).append("
\n");
}
sb.append("\t\t\t\t\t\t\t\t\t").append("\n");
//start the menu
Iterator menuIteartor = menu.getElements().iterator();
int i = 0;
while(menuIteartor.hasNext())
{
i++;
Object menuElmObj = menuIteartor.next();
int menuElmType = ((Integer)MenuElementTypes.get(
((MenuElement) menuElmObj).
getElementType())).intValue();
if (menuElmType == OPTION_TYPE)
{
sb.append(
getMenuElementOptionHTML(jpt,(MenuOption)menuElmObj,locale,true));
}
else if (menuElmType == MENU_TYPE)
{
sb.append(
getNestedLinksIconNavigation(req,(Menu)menuElmObj,locale,orientation)
);
}
else if (menuElmType == SEPARATOR_TYPE)
{
MenuSeparator menuElmSeparator = (MenuSeparator) menuElmObj;
String sepTitle = menuElmSeparator.getTitle(locale);
if (null == sepTitle)
sepTitle = "";
String sepText = menuElmSeparator.getText(locale);
if (null == sepText)
sepText = "";
sb.append("\t\t\t\t\t\t\t\t").
append("
").
append(StringEscapeUtils.escapeXml(sepText)).append("
\n");
}
} //while
sb.append("\t\t\t\t\t\t\t\t\t").append("
\n");
return sb.toString();
} //E: getNestedLinksIconNavigation
/**
* Helper method to create HTML content supporting page TABS
*
*/
private String getTabsNavigationContent(RenderRequest req, Menu menu, Locale locale,int orientation)
{
final String TAB_INDENT_1 = "\t\t";
final String TAB_INDENT_2 = "\t\t ";
final String TAB_INDENT_3 = "\t\t ";
JetspeedPowerTool _jpt = (JetspeedPowerTool) req.getAttribute("jpt");
PortalSiteRequestContext site = (PortalSiteRequestContext) req.getAttribute("psrc");
StringBuffer sb = new StringBuffer(INITIAL_BUFFER);
sb.append(TAB_INDENT_1);
sb.append("\n").
append(TAB_INDENT_2).append("\n");
Iterator menuIteartor = menu.getElements().iterator();
int i = 0;
while(menuIteartor.hasNext())
{
i++;
Object menuElmObj = menuIteartor.next();
int menuElmType = ((Integer)MenuElementTypes.get(
((MenuElement) menuElmObj).
getElementType())).intValue();
if (menuElmType != OPTION_TYPE)
{
continue;
}
MenuOption menuElm = (MenuOption) menuElmObj;
String tabTitle = getNormalizedString(menuElm.getTitle(locale));
String tabName = getNormalizedString(menuElm.getShortTitle(locale));
if (orientation == LEFT_TO_RIGHT)
{
if (menuElm.isSelected(site))
{
sb.append(TAB_INDENT_3).
append(" | \n").
append(TAB_INDENT_3).
append("").append(StringEscapeUtils.escapeXml(tabName)).append(" | \n").
append(TAB_INDENT_3).
append(" | \n");
}
else
{
String tabUrl = _jpt.getAbsoluteUrl(menuElm.getUrl());
sb.append(TAB_INDENT_3).
append(" | \n").
append(TAB_INDENT_3).
append("").
append("").
append(StringEscapeUtils.escapeXml(tabName)).
append("").append(" | \n").
append(TAB_INDENT_3).
append(" | \n");
}
}
else
{
}
}
sb.append(TAB_INDENT_2).append("
\n").
append(TAB_INDENT_1).
append("
");
return sb.toString();
}
%>