📄 cmstemplatenavigation.java
字号:
// close sub list and list item
if (!itemClosed) {
result.append("</li>");
itemClosed = true;
}
result.append("\n</ul></li>\n");
}
} else {
// higher level transition, create new sub list
result.append("<ul class=\"navleft\">\n");
}
} else {
// initial list creation
result.append("<ul class=\"navleft\">\n");
}
// create the navigation entry
result.append("<li class=\"");
result.append(styleClass);
result.append("\"><a class=\"");
result.append(styleClass);
result.append("\" href=\"");
result.append(link(resName));
result.append("\" title=\"");
result.append(nav.getNavText());
result.append("\">");
result.append(nav.getNavText());
result.append("</a>");
// set old level for next loop
oldLevel = level;
}
}
for (int i = 0; i < oldLevel; i++) {
// close the remaining lists
result.append("</li></ul>\n");
}
result.append("<!-- End navigation left -->");
}
return result.toString();
}
/**
* Builds the html for the inclusion of the editable element under the left navigation tree.<p>
*
* @throws IOException if writing the output fails
* @throws JspException if including the element fails
*/
public void buildNavLeftIncludeElement() throws IOException, JspException {
JspWriter out = getJspContext().getOut();
if (showNavLeftElement()) {
out.print("\t<div style=\"line-height: 1px; font-size: 1px; display: block; height: 4px;\"> </div>\n");
include(getNavLeftElementUri(), "text1", true);
} else if (!showNavLeftTree()) {
// none of the left navigation elements is shown, add a non breaking space to avoid html display errors
out.print(" ");
}
}
/**
* Returns the template configuration path in the OpenCms VFS.<p>
*
* @return the template configuration path
*/
public String getConfigPath() {
return property(CmsTemplateBean.PROPERTY_CONFIGPATH, "search", "/");
}
/**
* Returns the common configuration properties for the current web site area.<p>
*
* @return the common configuration properties
*/
public CmsXmlContent getConfiguration() {
if (m_globalConfiguration == null) {
m_globalConfiguration = CmsTemplateBean.getConfigurationFile(getConfigPath()
+ CmsTemplateBean.FILE_CONFIG_COMMON, getCmsObject());
}
return m_globalConfiguration;
}
/**
* Returns the value for the specified property key name from the configuration.<p>
*
* Returns the default value argument if the property is not found.<p>
*
* @param key the property key name to look up
* @param defaultValue a default value
* @return the value for the specified property key name
*/
public String getConfigurationValue(String key, String defaultValue) {
String value = null;
try {
value = getConfiguration().getStringValue(null, key, getRequestContext().getLocale());
} catch (Exception e) {
// log error in debug mode
if (LOG.isDebugEnabled()) {
LOG.debug(e.getMessage(), e);
}
}
if (CmsStringUtil.isEmpty(value)) {
value = defaultValue;
}
return value;
}
/**
* Returns the path to the head navigation start folder.<p>
*
* @return the path to the head navigation start folder
*/
public String getHeadNavFolder() {
return m_headNavFolder;
}
/**
* Creates a List of {@link org.opencms.jsp.CmsJspNavElement} objects from a manual XML content configuration file.<p>
*
* A manual configuration file can be used to build a head navigation that does not depend
* on the OpenCms resource structure. The menu level starts with 0 meaning the current level to create,
* the menuIndexes String contains at each char position numbers from 0-9 meaning the xpath index of the submenu
* entries in the XML content configuration file.<p>
*
* To get the first row, call this method like <code>getHeadNavItemsFromConfig(0, "0")</code> ,
* to get the subitems for the second entry in the second row <code>getHeadNavItemsFromConfig(1, "1")</code>.<p>
*
* @param menuLevel the menu level to get the items for, starting with 0
* @param menuIndexes the menu indexes of the submenus for xpath creation, starting with "0"
* @return a sorted list of CmsJspNavElement objects
*/
public List getHeadNavItemsFromConfig(int menuLevel, String menuIndexes) {
if (m_headNavConfiguration == null) {
// get the XML configuration file
m_headNavConfiguration = CmsTemplateBean.getConfigurationFile(
getConfigPath() + FILE_CONFIG_HEADNAV,
getCmsObject());
}
Locale locale = getRequestContext().getLocale();
List navEntries = new ArrayList();
if (menuLevel == 0) {
// create a list with the first level items from the configuration file as CmsJspNavElements
navEntries = m_headNavConfiguration.getValues("link", locale);
} else {
// create the xpath to the menu items and get the list of values fot the desired menu
StringBuffer xPath = new StringBuffer(8);
xPath.append("link");
for (int i = 0; i < menuLevel; i++) {
// get the index of the current menu entry from the indexes String
int menuIndex = Integer.parseInt(String.valueOf(menuIndexes.charAt(i)));
xPath.append("[");
xPath.append(menuIndex + 1);
xPath.append("]/menu");
}
navEntries = m_headNavConfiguration.getValues(xPath.toString(), locale);
}
int navEntriesSize = navEntries.size();
List result = new ArrayList(navEntriesSize);
for (int i = 0; i < navEntriesSize; i++) {
I_CmsXmlContentValue headLink = (I_CmsXmlContentValue)navEntries.get(i);
// get the xpath information of the current link
String linkPath = headLink.getPath();
// get the link URI
String url = m_headNavConfiguration.getStringValue(getCmsObject(), linkPath + "/link.url", locale);
// get the link text
String text = m_headNavConfiguration.getStringValue(getCmsObject(), linkPath + "/link.text", locale);
// get the link target
String target = m_headNavConfiguration.getStringValue(getCmsObject(), linkPath + "/link.target", locale);
if (CmsStringUtil.isEmpty(target)) {
target = "_self";
}
// create property Map to pass to the new CmsJspNavElement
Map properties = new HashMap(3);
properties.put(CmsPropertyDefinition.PROPERTY_NAVTEXT, text);
properties.put(CmsPropertyDefinition.PROPERTY_NAVINFO, target);
if (showHeadNavImages() && menuLevel == 0) {
// put head navigation image info to Map
String image = m_headNavConfiguration.getStringValue(getCmsObject(), linkPath + "/link.image", locale);
if (CmsStringUtil.isEmpty(image)) {
image = "";
}
properties.put(CmsPropertyDefinition.PROPERTY_NAVIMAGE, image);
}
CmsJspNavElement nav = new CmsJspNavElement(url, properties, 1);
result.add(nav);
}
return result;
}
/**
* Returns if the currently active top level folder should be marked in the head navigation.<p>
*
* @return true if the currently active top level folder should be marked in the head navigation, otherwise false
*/
public boolean getHeadNavMarkCurrent() {
return m_headNavMarkCurrent;
}
/**
* Returns if the submenus are expanded on click (true) or mouseover (false).<p>
*
* @return true if the submenus are expanded on click, otherwise false
*/
public boolean getHeadNavMenuClick() {
return m_headNavMenuClick;
}
/**
* Returns the currently active locale.<p>
*
* @return the locale
*/
public String getLocale() {
return m_locale;
}
/**
* Returns the maximum depth of the head navigation sub menu structure.<p>
*
* @return the maximum depth of the head navigation sub menu structure
*/
public int getMenuDepth() {
return m_menuDepth;
}
/**
* This method builds a complete menu navigation with entries of all branches
* from the specified folder.<p>
*
* @param curNav the List of current navigation elements
* @param styleClass the CSS class name of the <div> nodes
* @param prefix the prefix to generate the unique menu node id.
* @param currentDepth the depth of the current submenu
* @param menuIndexes String representing the menu indexes in the manual XML configuration, if null, no manual configuration is used
* @return the HTML to generate menu entries
*/
public StringBuffer getMenuNavigation(
List curNav,
String styleClass,
String prefix,
int currentDepth,
String menuIndexes) {
StringBuffer result = new StringBuffer(64);
String showItemProperty;
int navSize = curNav.size();
if (navSize > 0) {
// at least one navigation entry present, create menu
Map subNav = new HashMap();
Map subIndex = new HashMap();
boolean entryPresent = false;
boolean manualConfig = CmsStringUtil.isNotEmpty(menuIndexes);
// loop through all nav entries
for (int i = 0; i < navSize; i++) {
CmsJspNavElement ne = (CmsJspNavElement)curNav.get(i);
String resName = ne.getResourceName();
String link = resName;
if (link.startsWith("/")) {
link = link(link);
}
showItemProperty = getHeadNavItemDefaultStringValue();
if (getCmsObject().existsResource(resName)) {
showItemProperty = property(PROPERTY_HEADNAV_USE, resName, getHeadNavItemDefaultStringValue());
} else if (LOG.isWarnEnabled()) {
LOG.warn(Messages.get().getBundle().key(
Messages.LOG_NAVIGATION_CONFIG_ERR_2,
resName,
getRequestContext().getUri()));
}
boolean showEntry = manualConfig || Boolean.valueOf(showItemProperty).booleanValue();
if (showEntry) {
entryPresent = true;
List navEntries = new ArrayList();
// check if is depth smaller than maximum depth -> if so, get the navigation from this folder as well
if (currentDepth < getMenuDepth()) {
if (manualConfig) {
// manual configuration, get nav entries from XML configuration file
navEntries = getHeadNavItemsFromConfig(currentDepth + 1, menuIndexes + String.valueOf(i));
} else if (ne.isFolderLink()) {
// entry is folder, get sub navigation
navEntries = getNavigation().getNavigationForFolder(resName);
}
}
String target = ne.getInfo();
if (CmsStringUtil.isEmpty(target)) {
target = "_self";
}
result.append(" <a class=\"mI\" href=\"");
result.append(link);
result.append("\"");
result.append("\" target=\"");
result.append(target);
result.append("\"");
if ((ne.isFolderLink() && hasSubMenuEntries(navEntries)) || (manualConfig && navEntries.size() > 0)) {
// sub menu(s) present, create special entry
result.append(" onmouseover=\"menuItemMouseover(event, '");
result.append(prefix);
result.append("_");
result.append(resName.hashCode());
result.append("');\">");
result.append("<span class=\"mIText\">");
result.append(ne.getNavText());
result.append("</span><span class=\"mIArrow\">▶</span></a>");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -