📄 cmsjspnavbuilder.java
字号:
CmsJspNavElement e = (CmsJspNavElement)it.next();
e.setNavPosition(pos);
if (e.getResourceName().startsWith(nextfolder)) parentcount = pos;
}
if (parentcount == 0) parentcount = pos;
}
return result;
}
/**
* @see #getNavigationBreadCrumb(String, int, int, boolean)
*/
public ArrayList getNavigationBreadCrumb() {
return getNavigationBreadCrumb(m_requestUriFolder, 0, -1, true);
}
/**
* @see #getNavigationBreadCrumb(String, int, int, boolean)
*/
public ArrayList getNavigationBreadCrumb(int startlevel, int endlevel) {
return getNavigationBreadCrumb(m_requestUriFolder, startlevel, endlevel, true);
}
/**
* @see #getNavigationBreadCrumb(String, int, int, boolean)
*/
public ArrayList getNavigationBreadCrumb(int startlevel, boolean currentFolder) {
return getNavigationBreadCrumb(m_requestUriFolder, startlevel, -1, currentFolder);
}
/**
* Build a "bread crump" path navigation to the given folder.<p>
*
* The startlevel marks the point where the navigation starts from, if negative,
* the count of steps to go down from the given folder.
* The endlevel is the maximum level of the navigation path, set it to -1 to build the
* complete navigation to the given folder.
* You can include the given folder in the navigation by setting currentFolder to true,
* otherwise false.<p>
*
* @param folder the selected folder
* @param startlevel the start level, if negative, go down |n| steps from selected folder
* @param endlevel the end level, if -1, build navigation to selected folder
* @param currentFolder include the selected folder in navigation or not
* @return ArrayList sorted list of navigation elements
*/
public ArrayList getNavigationBreadCrumb(String folder, int startlevel, int endlevel, boolean currentFolder) {
ArrayList result = new ArrayList(0);
int level = CmsResource.getPathLevel(folder);
// decrease folder level if current folder is not displayed
if (!currentFolder) {
level -= 1;
}
// check current level and change endlevel if it is higher or -1
if (level < endlevel || endlevel == -1) {
endlevel = level;
}
// if startlevel is negative, display only |startlevel| links
if (startlevel < 0) {
startlevel = endlevel + startlevel +1;
if (startlevel < 0) {
startlevel = 0;
}
}
// create the list of navigation elements
for (int i=startlevel; i<=endlevel; i++) {
String navFolder = CmsResource.getPathPart(folder, i);
CmsJspNavElement e = getNavigationForResource(navFolder);
// add element to list
result.add(e);
}
return result;
}
/**
* This method builds a complete navigation tree with entries of all branches
* from the specified folder.<p>
*
* For an unlimited depth of the navigation (i.e. no endLevel), set the endLevel to
* a value < 0.<p>
*
*
* @param cms the current CmsJspActionElement.
* @param folder the root folder of the navigation tree.
* @param endLevel the end level of the navigation.
* @return ArrayList of CmsJspNavElement, in depth first order.
*/
public static ArrayList getSiteNavigation(CmsObject cms, String folder, int endLevel){
// check if a specific end level was given, if not, build the complete navigation
boolean noLimit = false;
if (endLevel < 0) {
noLimit = true;
}
ArrayList list = new ArrayList();
// get the navigation for this folder
ArrayList curnav = getNavigationForFolder(cms, folder);
Iterator i = curnav.iterator();
// loop through all nav entrys
while (i.hasNext()) {
CmsJspNavElement ne = (CmsJspNavElement)i.next();
// add the naventry to the result list
list.add(ne);
// check if naventry is a folder and below the max level -> if so, get the navigation from this folder as well
if (ne.isFolderLink() && (noLimit || (ne.getNavTreeLevel() < endLevel))) {
ArrayList subnav = getSiteNavigation(cms, ne.getResourceName(), endLevel);
// copy the result of the subfolder to the result list
list.addAll(subnav);
}
}
return list;
}
/**
* This method builds a complete navigation tree with entries of all branches
* from the specified folder.<p>
*
* @see #getSiteNavigation(CmsObject, String, int)
*
* @param folder folder the root folder of the navigation tree.
* @param endLevel the end level of the navigation.
* @return ArrayList of CmsJspNavElement, in depth first order.
*/
public ArrayList getSiteNavigation(String folder, int endLevel) {
return getSiteNavigation(m_cms, folder, endLevel);
}
/**
* This method builds a complete site navigation tree with entries of all branches.<p>
*
* @see #getSiteNavigation(CmsObject, String, int)
*
* @return ArrayList of CmsJspNavElement, in depth first order.
*/
public ArrayList getSiteNavigation() {
return getSiteNavigation(m_cms, "/", -1);
}
/**
* Returns all subfolders of a sub channel that has
* the given parent channel, or an empty array if
* that combination does not exist or has no subfolders.<p>
*
* @param parentChannel the parent channel
* @param subChannel the sub channel
* @return an unsorted list of CmsResources
*/
public ArrayList getChannelSubFolders(String parentChannel, String subChannel) {
return getChannelSubFolders(m_cms, parentChannel, subChannel);
}
/**
* Returns all subfolders of a sub channel that has
* the given parent channel, or an empty array if
* that combination does not exist or has no subfolders.<p>
*
* @param cms context provider for the current request
* @param parentChannel the parent channel
* @param subChannel the sub channel
* @return an unsorted list of CmsResources
*/
public static ArrayList getChannelSubFolders(CmsObject cms, String parentChannel, String subChannel) {
String channel = null;
if (subChannel == null) {
subChannel = "";
} else if (subChannel.startsWith("/")) {
subChannel = subChannel.substring(1);
}
if (parentChannel == null) parentChannel = "";
if (parentChannel.endsWith("/")) {
channel = parentChannel + subChannel;
} else {
channel = parentChannel + "/" + subChannel;
}
return getChannelSubFolders(cms, channel);
}
/**
* Returns all subfolders of a channel, or an empty array if
* the folder does not exist or has no subfolders.<p>
*
* @param channel the channel to look for subfolders in
* @return an unsorted list of CmsResources
*/
public ArrayList getChannelSubFolders(String channel) {
return getChannelSubFolders(m_cms, channel);
}
/**
* Returns all subfolders of a channel, or an empty array if
* the folder does not exist or has no subfolders.<p>
*
* @param cms context provider for the current request
* @param channel the channel to look for subfolders in
* @return an unsorted list of CmsResources
*/
public static ArrayList getChannelSubFolders(CmsObject cms, String channel) {
if (! channel.startsWith("/")) channel = "/" + channel;
if (! channel.endsWith("/")) channel += "/";
// Now read all subchannels of this channel
java.util.Vector subChannels = new java.util.Vector();
try {
cms.setContextToCos();
subChannels = cms.getSubFolders(channel);
} catch (Exception e) {
System.err.println("Exception: " + e);
} finally {
cms.setContextToVfs();
}
// Create an ArrayList out of the Vector
java.util.ArrayList list = new java.util.ArrayList(subChannels.size());
list.addAll(subChannels);
return list;
}
/**
* Returns all subfolders of a channel,
* sorted by "Title" property ascending, or an empty array if
* the folder does not exist or has no subfolders.
*
* @param channel the parent channel
* @param subChannel the sub channel
* @return a sorted list of CmsResources
*/
public ArrayList getChannelSubFoldersSortTitleAsc(String channel, String subChannel) {
return getChannelSubFoldersSortTitleAsc(m_cms, channel, subChannel);
}
/**
* Returns all subfolders of a channel,
* sorted by "Title" property ascending, or an empty array if
* the folder does not exist or has no subfolders.
*
* @param cms context provider for the current request
* @param channel the parent channel
* @param subChannel the sub channel
* @return a sorted list of CmsResources
*/
public static ArrayList getChannelSubFoldersSortTitleAsc(CmsObject cms, String channel, String subChannel) {
ArrayList subChannels = getChannelSubFolders(cms, channel, subChannel);
// Create an ArrayList out of the Vector
java.util.ArrayList tmpList = new java.util.ArrayList(subChannels.size());
Iterator i = subChannels.iterator();
while (i.hasNext()) {
CmsResource res = (CmsResource)i.next();
ResourceTitleContainer container = new ResourceTitleContainer(cms, res);
tmpList.add(container);
}
Collections.sort(tmpList);
java.util.ArrayList list = new java.util.ArrayList(subChannels.size());
i = tmpList.iterator();
while (i.hasNext()) {
ResourceTitleContainer container = (ResourceTitleContainer)i.next();
list.add(container.m_res);
}
return list;
}
/**
* Internal helper class to get a title - comparable CmsResource for channels.<p>
*/
private static class ResourceTitleContainer implements Comparable {
// member variables
public CmsResource m_res = null;
public String m_title = null;
/**
* @param cms context provider for the current request
* @param res the resource to compare
*/
ResourceTitleContainer(CmsObject cms, CmsResource res) {
m_res = res;
try {
cms.setContextToCos();
m_title = cms.readProperty(res.getAbsolutePath(), com.opencms.core.I_CmsConstants.C_PROPERTY_TITLE);
cms.setContextToVfs();
} catch (Exception e) {
m_title = "";
}
}
/**
* @see java.lang.Comparable#compareTo(Object)
*/
public int compareTo(Object obj) {
if (! (obj instanceof ResourceTitleContainer)) return 0;
if (m_title == null) return 1;
return (m_title.toLowerCase().compareTo(((ResourceTitleContainer)obj).m_title.toLowerCase()));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -