Class CmsJspNavBuilder
- java.lang.Object
-
- org.opencms.jsp.CmsJspNavBuilder
-
public class CmsJspNavBuilder extends java.lang.Object
Bean to provide a convenient way to build navigation structures based on the
.CmsJspNavElement
Use this together with the
to obtain navigation information based on the current users permissions. For example, useCmsJspActionElement
and pass the value of the current OpenCms user context uri obtained fromgetNavigationForFolder(String)
as argument to obtain a list of all items in the navigation of the current folder. Then use a simple scriptlet to iterate over these items and create a HTML navigation.CmsRequestContext.getUri()
- Since:
- 6.0.0
- See Also:
CmsJspNavElement
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CmsJspNavBuilder.NavContext
Navigation builder context.static class
CmsJspNavBuilder.Visibility
The visibility mode.
-
Field Summary
Fields Modifier and Type Field Description protected CmsObject
m_cms
The current CMS context.protected java.util.Locale
m_locale
The locale for which the property should be read.protected java.lang.String
m_requestUri
The current request URI.protected java.lang.String
m_requestUriFolder
The current request folder.static java.lang.String
NAVIGATION_LEVEL_FOLDER
Default file property value to mark navigation level folders.
-
Constructor Summary
Constructors Constructor Description CmsJspNavBuilder()
Empty constructor, so that this bean can be initialized from a JSP.CmsJspNavBuilder(CmsObject cms)
Default constructor.CmsJspNavBuilder(CmsObject cms, java.util.Locale locale)
Constructor for a version that reads properties according to a locale.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description CmsObject
getCmsObject()
Gets the CMS context used for building the navigation.static java.lang.String
getDefaultFile(CmsObject cms, java.lang.String folder)
Deprecated.useCmsObject.readDefaultFile(String)
insteadjava.util.List<CmsJspNavElement>
getNavigationBreadCrumb()
Build a "bread crumb" path navigation to the current folder.java.util.List<CmsJspNavElement>
getNavigationBreadCrumb(int startlevel, boolean currentFolder)
Build a "bread crumb" path navigation to the current folder.java.util.List<CmsJspNavElement>
getNavigationBreadCrumb(int startlevel, int endlevel)
Build a "bread crumb" path navigation to the current folder.java.util.List<CmsJspNavElement>
getNavigationBreadCrumb(java.lang.String folder, int startlevel, int endlevel, boolean currentFolder)
Build a "bread crumb" path navigation to the given folder.java.util.List<CmsJspNavElement>
getNavigationForFolder()
Collect all navigation elements from the files of the folder of the current request URI.java.util.List<CmsJspNavElement>
getNavigationForFolder(int level)
Build a navigation for the folder that is either minus levels up from of the folder of the current request URI, or that is plus levels down from the root folder towards the current request URI.java.util.List<CmsJspNavElement>
getNavigationForFolder(java.lang.String folder)
Collect all navigation visible elements from the files in the given folder.java.util.List<CmsJspNavElement>
getNavigationForFolder(java.lang.String folder, int level)
Build a navigation for the folder that is either minus levels up from the given folder, or that is plus levels down from the root folder towards the given folder.java.util.List<CmsJspNavElement>
getNavigationForFolder(java.lang.String folder, CmsJspNavBuilder.Visibility visibility, CmsResourceFilter resourceFilter)
Collect all navigation elements from the files in the given folder.static java.util.List<CmsJspNavElement>
getNavigationForFolder(CmsObject cms, java.lang.String folder)
Deprecated.usegetNavigationForFolder(String)
insteadstatic java.util.List<CmsJspNavElement>
getNavigationForFolder(CmsObject cms, java.lang.String folder, int level)
Deprecated.usegetNavigationForFolder(String, int)
insteadCmsJspNavElement
getNavigationForResource()
Returns a navigation element for the resource of the current request URI.CmsJspNavElement
getNavigationForResource(java.lang.String sitePath)
Returns a navigation element for the named resource.CmsJspNavElement
getNavigationForResource(java.lang.String sitePath, CmsResourceFilter reourceFilter)
Returns a navigation element for the named resource.static CmsJspNavElement
getNavigationForResource(CmsObject cms, java.lang.String resource)
Deprecated.usegetNavigationForResource(String)
insteadjava.util.List<CmsJspNavElement>
getNavigationTreeForFolder(int startlevel, int endlevel)
Builds a tree navigation for the folders between the provided start and end level.java.util.List<CmsJspNavElement>
getNavigationTreeForFolder(java.lang.String folder, int startlevel, int endlevel)
Builds a tree navigation for the folders between the provided start and end level.static java.util.List<CmsJspNavElement>
getNavigationTreeForFolder(CmsObject cms, java.lang.String folder, int startlevel, int endlevel)
Deprecated.usegetNavigationForResource(String)
insteadjava.util.List<CmsJspNavElement>
getSiteNavigation()
This method builds a complete site navigation tree with entries of all branches.java.util.List<CmsJspNavElement>
getSiteNavigation(java.lang.String folder, int endLevel)
This method builds a complete navigation tree with entries of all branches from the specified folder.java.util.List<CmsJspNavElement>
getSiteNavigation(java.lang.String folder, CmsJspNavBuilder.Visibility visibility, int endLevel)
This method builds a complete navigation tree with entries of all branches from the specified folder.static java.util.List<CmsJspNavElement>
getSiteNavigation(CmsObject cms, java.lang.String folder, int endLevel)
Deprecated.usegetNavigationForResource(String)
insteadvoid
init(CmsObject cms)
Initializes this bean.void
init(CmsObject cms, java.util.Locale locale)
Initializes this bean.void
init(CmsObject cms, java.util.Locale locale, java.lang.String requestUri)
Initializes this bean.static boolean
isNavLevelFolder(CmsObject cms, CmsResource resource)
Returns whether the given resource is a folder and is marked to be a navigation level folder.
-
-
-
Field Detail
-
NAVIGATION_LEVEL_FOLDER
public static final java.lang.String NAVIGATION_LEVEL_FOLDER
Default file property value to mark navigation level folders.- See Also:
- Constant Field Values
-
m_locale
protected java.util.Locale m_locale
The locale for which the property should be read.
-
m_requestUri
protected java.lang.String m_requestUri
The current request URI.
-
m_requestUriFolder
protected java.lang.String m_requestUriFolder
The current request folder.
-
-
Constructor Detail
-
CmsJspNavBuilder
public CmsJspNavBuilder()
Empty constructor, so that this bean can be initialized from a JSP.
-
CmsJspNavBuilder
public CmsJspNavBuilder(CmsObject cms)
Default constructor.- Parameters:
cms
- context provider for the current request
-
CmsJspNavBuilder
public CmsJspNavBuilder(CmsObject cms, java.util.Locale locale)
Constructor for a version that reads properties according to a locale.- Parameters:
cms
- context provider for the current requestlocale
- the locale for which properties should be accessed
-
-
Method Detail
-
getDefaultFile
@Deprecated public static java.lang.String getDefaultFile(CmsObject cms, java.lang.String folder)
Deprecated.useCmsObject.readDefaultFile(String)
insteadReturns the full name (including VFS path) of the default file for this navigation element ornull
if the navigation element is not a folder.The default file of a folder is determined by the value of the property
default-file
or the system wide property setting.- Parameters:
cms
- the CMS objectfolder
- full name of the folder- Returns:
- the name of the default file
-
getNavigationForFolder
@Deprecated public static java.util.List<CmsJspNavElement> getNavigationForFolder(CmsObject cms, java.lang.String folder)
Deprecated.usegetNavigationForFolder(String)
insteadCollect all navigation elements from the files in the given folder, navigation elements are of classCmsJspNavElement
.- Parameters:
cms
- context provider for the current requestfolder
- the selected folder- Returns:
- a sorted (ascending to navigation position) list of navigation elements
-
getNavigationForFolder
@Deprecated public static java.util.List<CmsJspNavElement> getNavigationForFolder(CmsObject cms, java.lang.String folder, int level)
Deprecated.usegetNavigationForFolder(String, int)
insteadBuild a navigation for the folder that is either minus levels up from the given folder, or that is plus levels down from the root folder towards the given folder.If level is set to zero the root folder is used by convention.
- Parameters:
cms
- context provider for the current requestfolder
- the selected folderlevel
- if negative, walk this many levels up, if positive, walk this many levels down from root folder- Returns:
- a sorted (ascending to navigation position) list of navigation elements
-
getNavigationForResource
@Deprecated public static CmsJspNavElement getNavigationForResource(CmsObject cms, java.lang.String resource)
Deprecated.usegetNavigationForResource(String)
insteadReturns a navigation element for the named resource.- Parameters:
cms
- context provider for the current requestresource
- the resource name to get the navigation information for, must be a full path name, e.g. "/docs/index.html"- Returns:
- a navigation element for the given resource
-
getNavigationTreeForFolder
@Deprecated public static java.util.List<CmsJspNavElement> getNavigationTreeForFolder(CmsObject cms, java.lang.String folder, int startlevel, int endlevel)
Deprecated.usegetNavigationForResource(String)
insteadBuilds a tree navigation for the folders between the provided start and end level.A tree navigation includes all navigation elements that are required to display a tree structure. However, the data structure is a simple list. Each of the navigation elements in the list has the
CmsJspNavElement.getNavTreeLevel()
set to the level it belongs to. Use this information to distinguish between the navigation levels.- Parameters:
cms
- context provider for the current requestfolder
- the selected folderstartlevel
- the start levelendlevel
- the end level- Returns:
- a sorted list of navigation elements with the navigation tree level property set
-
getSiteNavigation
@Deprecated public static java.util.List<CmsJspNavElement> getSiteNavigation(CmsObject cms, java.lang.String folder, int endLevel)
Deprecated.usegetNavigationForResource(String)
insteadThis method builds a complete navigation tree with entries of all branches from the specified folder.For an unlimited depth of the navigation (i.e. no
endLevel
), set theendLevel
to a value < 0.- Parameters:
cms
- the current CMS contextfolder
- the root folder of the navigation treeendLevel
- the end level of the navigation- Returns:
- list of navigation elements, in depth first order
-
isNavLevelFolder
public static boolean isNavLevelFolder(CmsObject cms, CmsResource resource)
Returns whether the given resource is a folder and is marked to be a navigation level folder.- Parameters:
cms
- the cms contextresource
- the resource- Returns:
true
if the resource is marked to be a navigation level folder
-
getCmsObject
public CmsObject getCmsObject()
Gets the CMS context used for building the navigation.- Returns:
- the CMS context
-
getNavigationBreadCrumb
public java.util.List<CmsJspNavElement> getNavigationBreadCrumb()
Build a "bread crumb" path navigation to the current folder.- Returns:
- ArrayList sorted list of navigation elements
- See Also:
getNavigationBreadCrumb(String, int, int, boolean)
-
getNavigationBreadCrumb
public java.util.List<CmsJspNavElement> getNavigationBreadCrumb(int startlevel, boolean currentFolder)
Build a "bread crumb" path navigation to the current folder.- Parameters:
startlevel
- the start level, if negative, go down |n| steps from selected foldercurrentFolder
- include the selected folder in navigation or not- Returns:
- sorted list of navigation elements
- See Also:
getNavigationBreadCrumb(String, int, int, boolean)
-
getNavigationBreadCrumb
public java.util.List<CmsJspNavElement> getNavigationBreadCrumb(int startlevel, int endlevel)
Build a "bread crumb" path navigation to the current folder.- Parameters:
startlevel
- the start level, if negative, go down |n| steps from selected folderendlevel
- the end level, if -1, build navigation to selected folder- Returns:
- sorted list of navigation elements
- See Also:
getNavigationBreadCrumb(String, int, int, boolean)
-
getNavigationBreadCrumb
public java.util.List<CmsJspNavElement> getNavigationBreadCrumb(java.lang.String folder, int startlevel, int endlevel, boolean currentFolder)
Build a "bread crumb" path navigation to the given folder.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
totrue
, otherwisefalse
.- Parameters:
folder
- the selected folderstartlevel
- the start level, if negative, go down |n| steps from selected folderendlevel
- the end level, if -1, build navigation to selected foldercurrentFolder
- include the selected folder in navigation or not- Returns:
- sorted list of navigation elements
-
getNavigationForFolder
public java.util.List<CmsJspNavElement> getNavigationForFolder()
Collect all navigation elements from the files of the folder of the current request URI.- Returns:
- a sorted (ascending to navigation position) list of navigation elements
-
getNavigationForFolder
public java.util.List<CmsJspNavElement> getNavigationForFolder(int level)
Build a navigation for the folder that is either minus levels up from of the folder of the current request URI, or that is plus levels down from the root folder towards the current request URI.If level is set to zero the root folder is used by convention.
- Parameters:
level
- if negative, walk this many levels up, if positive, walk this many levels down from root folder- Returns:
- a sorted (ascending to navigation position) list of navigation elements
-
getNavigationForFolder
public java.util.List<CmsJspNavElement> getNavigationForFolder(java.lang.String folder)
Collect all navigation visible elements from the files in the given folder.- Parameters:
folder
- the selected folder- Returns:
- A sorted (ascending to navigation position) list of navigation elements
-
getNavigationForFolder
public java.util.List<CmsJspNavElement> getNavigationForFolder(java.lang.String folder, int level)
Build a navigation for the folder that is either minus levels up from the given folder, or that is plus levels down from the root folder towards the given folder.If level is set to zero the root folder is used by convention.
- Parameters:
folder
- the selected folderlevel
- if negative, walk this many levels up, if positive, walk this many levels down from root folder- Returns:
- a sorted (ascending to navigation position) list of navigation elements
-
getNavigationForFolder
public java.util.List<CmsJspNavElement> getNavigationForFolder(java.lang.String folder, CmsJspNavBuilder.Visibility visibility, CmsResourceFilter resourceFilter)
Collect all navigation elements from the files in the given folder.- Parameters:
folder
- the selected foldervisibility
- the visibility moderesourceFilter
- the filter to use reading the resources- Returns:
- A sorted (ascending to navigation position) list of navigation elements
-
getNavigationForResource
public CmsJspNavElement getNavigationForResource()
Returns a navigation element for the resource of the current request URI.- Returns:
- a navigation element for the resource of the current request URI
-
getNavigationForResource
public CmsJspNavElement getNavigationForResource(java.lang.String sitePath)
Returns a navigation element for the named resource.- Parameters:
sitePath
- the resource name to get the navigation information for, must be a full path name, e.g. "/docs/index.html"- Returns:
- a navigation element for the given resource
-
getNavigationForResource
public CmsJspNavElement getNavigationForResource(java.lang.String sitePath, CmsResourceFilter reourceFilter)
Returns a navigation element for the named resource.- Parameters:
sitePath
- the resource name to get the navigation information for, must be a full path name, e.g. "/docs/index.html"reourceFilter
- the resource filter- Returns:
- a navigation element for the given resource
-
getNavigationTreeForFolder
public java.util.List<CmsJspNavElement> getNavigationTreeForFolder(int startlevel, int endlevel)
Builds a tree navigation for the folders between the provided start and end level.- Parameters:
startlevel
- the start levelendlevel
- the end level- Returns:
- a sorted list of navigation elements with the navigation tree level property set
- See Also:
getNavigationTreeForFolder(String, int, int)
-
getNavigationTreeForFolder
public java.util.List<CmsJspNavElement> getNavigationTreeForFolder(java.lang.String folder, int startlevel, int endlevel)
Builds a tree navigation for the folders between the provided start and end level.- Parameters:
folder
- the selected folderstartlevel
- the start levelendlevel
- the end level- Returns:
- a sorted list of navigation elements with the navigation tree level property set
-
getSiteNavigation
public java.util.List<CmsJspNavElement> getSiteNavigation()
This method builds a complete site navigation tree with entries of all branches.- Returns:
- list of navigation elements, in depth first order
- See Also:
getSiteNavigation(String, int)
-
getSiteNavigation
public java.util.List<CmsJspNavElement> getSiteNavigation(java.lang.String folder, int endLevel)
This method builds a complete navigation tree with entries of all branches from the specified folder.- Parameters:
folder
- folder the root folder of the navigation treeendLevel
- the end level of the navigation- Returns:
- list of navigation elements, in depth first order
-
getSiteNavigation
public java.util.List<CmsJspNavElement> getSiteNavigation(java.lang.String folder, CmsJspNavBuilder.Visibility visibility, int endLevel)
This method builds a complete navigation tree with entries of all branches from the specified folder.- Parameters:
folder
- folder the root folder of the navigation treevisibility
- controls whether entries hidden from navigation or not in navigation at all should be includedendLevel
- the end level of the navigation- Returns:
- list of navigation elements, in depth first order
-
init
public void init(CmsObject cms)
Initializes this bean.- Parameters:
cms
- the current cms context
-
init
public void init(CmsObject cms, java.util.Locale locale)
Initializes this bean.- Parameters:
cms
- the current cms contextlocale
- the locale for which properties should be read
-
-