Class CmsLinkManager
Since this functionality is closely related to the static export, this class resides in the static export package.
- Since:
- 6.0.0
-
Constructor Summary
ConstructorDescriptionCmsLinkManager
(I_CmsLinkSubstitutionHandler linkSubstitutionHandler) Public constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
getAbsoluteUri
(String relativeUri, String baseUri) Calculates the absolute URI for the "relativeUri" with the given absolute "baseUri" as start.static String
getLinkSubsite
(CmsObject cms, String link) Gets the absolute path for the subsite a link links to.getOnlineLink
(CmsObject cms, String resourceName) Returns the online link for the given resource, with full server prefix.getOnlineLink
(CmsObject cms, String resourceName, boolean forceSecure) Returns the online link for the given resource, with full server prefix.getOnlineLink
(CmsObject cms, String resourceName, String targetDetailPage, boolean forceSecure) Returns the online link for the given resource, with full server prefix.getPermalink
(CmsObject cms, String resourceName) Returns the perma link for the given resource.getPermalink
(CmsObject cms, String resourceName, CmsUUID detailContentId) Returns the perma link for the given resource and optional detail content.<p<Returns the perma link for the current page based on the URI and detail content id stored in the CmsObject passed as a parameter.<p<Returns the result of the last extern link validation.static String
getRelativeUri
(String fromUri, String toUri) Calculates a relative URI from "fromUri" to "toUri", both URI must be absolute.getRootPath
(CmsObject cms, String targetUri) Returns the resource root path in the OpenCms VFS for the given target URI link, ornull
in case the link points to an external site.getRootPath
(CmsObject cms, String targetUri, String basePath) Returns the resource root path in the OpenCms VFS for the given target URI link, ornull
in case the link points to an external site.getServerLink
(CmsObject cms, String resourceName) Returns the link for the given resource in the current project, with full server prefix.getServerLink
(CmsObject cms, String resourceName, boolean forceSecure) Returns the link for the given resource in the current project, with full server prefix.static String
getSitePath
(CmsObject cms, String basePath, String targetUri) Deprecated.getWorkplaceLink
(CmsObject cms, String resourceName, boolean forceSecure) Returns the link for the given workplace resource.static boolean
Tests if the given URI starts with a scheme component.static boolean
isAbsoluteUri
(String uri) Returnstrue
in case the given URI is absolute.static boolean
isWorkplaceLink
(String link) Returns if the given link points to the OpenCms workplace UI.static boolean
isWorkplaceUri
(URI uri) Returns if the given URI is pointing to the OpenCms workplace UI.static String
removeOpenCmsContext
(String path) Given a path to a VFS resource, the method removes the OpenCms context, in case the path is prefixed by that context.void
setLinkSubstitutionHandler
(CmsObject cms, I_CmsLinkSubstitutionHandler linkSubstitutionHandler) Sets the internal link substitution handler.void
setPointerLinkValidationResult
(CmsExternalLinksValidationResult externLinkValidationResult) Sets the result of an external link validation.substituteLink
(CmsObject cms, String link) Returns a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the givenlink
in the current site, for use on web pages.substituteLink
(CmsObject cms, String link, String siteRoot) Returns a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the givenlink
andsiteRoot
, for use on web pages.substituteLink
(CmsObject cms, String link, String siteRoot, boolean forceSecure) Returns a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the givenlink
andsiteRoot
, for use on web pages, using the configured link substitution handler.substituteLink
(CmsObject cms, String link, String siteRoot, String targetDetailPage, boolean forceSecure) Returns a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the givenlink
andsiteRoot
, for use on web pages, using the configured link substitution handler.substituteLink
(CmsObject cms, CmsResource resource) Returns a link from the URI stored in the provided OpenCms user context to the given VFS resource, for use on web pages.substituteLinkForRootPath
(CmsObject cms, String rootPath) Returns a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the given root path, for use on web pages.substituteLinkForUnknownTarget
(CmsObject cms, String link) Returns a link from the URI stored in the provided OpenCms user context to the givenlink
, for use on web pages.substituteLinkForUnknownTarget
(CmsObject cms, String link, boolean forceSecure) Returns a link from the URI stored in the provided OpenCms user context to the givenlink
, for use on web pages.substituteLinkForUnknownTarget
(CmsObject cms, String link, String targetDetailPage, boolean forceSecure) Returns a link from the URI stored in the provided OpenCms user context to the givenlink
, for use on web pages.
-
Constructor Details
-
CmsLinkManager
Public constructor.- Parameters:
linkSubstitutionHandler
- the link substitution handler to use
-
-
Method Details
-
getAbsoluteUri
Calculates the absolute URI for the "relativeUri" with the given absolute "baseUri" as start.If "relativeUri" is already absolute, it is returned unchanged. This method also returns "relativeUri" unchanged if it is not well-formed.
- Parameters:
relativeUri
- the relative URI to calculate an absolute URI forbaseUri
- the base URI, this must be an absolute URI- Returns:
- an absolute URI calculated from "relativeUri" and "baseUri"
-
getLinkSubsite
Gets the absolute path for the subsite a link links to.For detail links, the subsite of the detail page is returned, not the subsite of the detail content
If the link is not internal, null will be returned.
- Parameters:
cms
- a CMS contextlink
- the link to check- Returns:
- the subsite path for the link target, or null if not applicable
-
getRelativeUri
Calculates a relative URI from "fromUri" to "toUri", both URI must be absolute.- Parameters:
fromUri
- the URI to starttoUri
- the URI to calculate a relative path to- Returns:
- a relative URI from "fromUri" to "toUri"
-
getSitePath
Deprecated.usegetRootPath(CmsObject, String, String)
instead, obtain the link manager withOpenCms.getLinkManager()
Returns the resource root path for the given target URI in the OpenCms VFS, ornull
in case the target URI points to an external site.- Parameters:
cms
- the current users OpenCms contextbasePath
- path to use as base site for the target URI (can benull
)targetUri
- the target URI- Returns:
- the resource root path for the given target URI in the OpenCms VFS, or
null
in case the target URI points to an external site
-
hasScheme
Tests if the given URI starts with a scheme component.The scheme component is something like
http:
orftp:
.- Parameters:
uri
- the URI to test- Returns:
true
if the given URI starts with a scheme component
-
isAbsoluteUri
Returnstrue
in case the given URI is absolute.An URI is considered absolute if one of the following is true:
- The URI starts with a
'/'
char. - The URI contains a
':'
in the first 10 chars. - The URI is
null
- Parameters:
uri
- the URI to test- Returns:
true
in case the given URI is absolute
- The URI starts with a
-
isWorkplaceLink
Returns if the given link points to the OpenCms workplace UI.- Parameters:
link
- the link to test- Returns:
true
in case the given URI points to the OpenCms workplace UI
-
isWorkplaceUri
Returns if the given URI is pointing to the OpenCms workplace UI.- Parameters:
uri
- the URI- Returns:
true
if the given URI is pointing to the OpenCms workplace UI
-
removeOpenCmsContext
Given a path to a VFS resource, the method removes the OpenCms context, in case the path is prefixed by that context.- Parameters:
path
- the path where the OpenCms context should be removed- Returns:
- the adjusted path
-
getOnlineLink
Returns the online link for the given resource, with full server prefix.Like
http://site.enterprise.com:8080/index.html
.In case the resource name is a full root path, the site from the root path will be used. Otherwise the resource is assumed to be in the current site set be the OpenCms user context.
Please note that this method will always return the link as it will appear in the "Online" project, that is after the resource has been published. In case you need a method that just returns the link with the full server prefix, use
getServerLink(CmsObject, String)
.- Parameters:
cms
- the current OpenCms user contextresourceName
- the resource to generate the online link for- Returns:
- the online link for the given resource, with full server prefix
- See Also:
-
getOnlineLink
Returns the online link for the given resource, with full server prefix.Like
http://site.enterprise.com:8080/index.html
.In case the resource name is a full root path, the site from the root path will be used. Otherwise the resource is assumed to be in the current site set be the OpenCms user context.
Please note that this method will always return the link as it will appear in the "Online" project, that is after the resource has been published. In case you need a method that just returns the link with the full server prefix, use
getServerLink(CmsObject, String)
.- Parameters:
cms
- the current OpenCms user contextresourceName
- the resource to generate the online link forforceSecure
- forces the secure server prefix if the target is secure- Returns:
- the online link for the given resource, with full server prefix
- See Also:
-
getOnlineLink
public String getOnlineLink(CmsObject cms, String resourceName, String targetDetailPage, boolean forceSecure) Returns the online link for the given resource, with full server prefix.Like
http://site.enterprise.com:8080/index.html
.In case the resource name is a full root path, the site from the root path will be used. Otherwise the resource is assumed to be in the current site set be the OpenCms user context.
Please note that this method will always return the link as it will appear in the "Online" project, that is after the resource has been published. In case you need a method that just returns the link with the full server prefix, use
getServerLink(CmsObject, String)
.- Parameters:
cms
- the current OpenCms user contextresourceName
- the resource to generate the online link fortargetDetailPage
- the target detail page, in case of linking to a specific detail pageforceSecure
- forces the secure server prefix if the target is secure- Returns:
- the online link for the given resource, with full server prefix
- See Also:
-
getPermalink
Returns the perma link for the given resource.Like
http://site.enterprise.com:8080/permalink/4b65369f-1266-11db-8360-bf0f6fbae1f8.html
.- Parameters:
cms
- the cms contextresourceName
- the resource to generate the perma link for- Returns:
- the perma link
-
getPermalink
Returns the perma link for the given resource and optional detail content.<p<- Parameters:
cms
- the CMS context to useresourceName
- the page to generate the perma link fordetailContentId
- the structure id of the detail content (may be null)- Returns:
- the perma link
-
getPermalinkForCurrentPage
Returns the perma link for the current page based on the URI and detail content id stored in the CmsObject passed as a parameter.<p<- Parameters:
cms
- the CMS context to use to generate the permalink- Returns:
- the permalink
-
getPointerLinkValidationResult
Returns the result of the last extern link validation.- Returns:
- the result of the last extern link validation
-
getRootPath
Returns the resource root path in the OpenCms VFS for the given target URI link, ornull
in case the link points to an external site.This methods does not support relative target URI links, so the given URI must be an absolute link.
See
getRootPath(CmsObject, String)
for a full explanation of this method.- Parameters:
cms
- the current users OpenCms contexttargetUri
- the target URI link- Returns:
- the resource root path in the OpenCms VFS for the given target URI link, or
null
in case the link points to an external site - Since:
- 7.0.2
- See Also:
-
getRootPath
Returns the resource root path in the OpenCms VFS for the given target URI link, ornull
in case the link points to an external site.The default implementation applies the following transformations to the link:
- In case the link starts with a VFS prefix (for example
/opencms/opencms
, this prefix is removed from the result - In case the link is not a root path, the current site root is appended to the result.
- In case the link is relative, it will be made absolute using the given absolute
basePath
as starting point. - In case the link contains a server schema (for example
http://www.mysite.de/
), which points to a configured site in OpenCms, the server schema is replaced with the root path of the site. - In case the link points to an external site, or in case it is not a valid URI,
then
null
is returned.
CmsDefaultLinkSubstitutionHandler
, which can be fully customized using theI_CmsLinkSubstitutionHandler
interface.- Parameters:
cms
- the current users OpenCms contexttargetUri
- the target URI linkbasePath
- path to use as base in case the target URI is relative (can benull
)- Returns:
- the resource root path in the OpenCms VFS for the given target URI link, or
null
in case the link points to an external site - Since:
- 7.0.2
- See Also:
- In case the link starts with a VFS prefix (for example
-
getServerLink
Returns the link for the given resource in the current project, with full server prefix.Like
http://site.enterprise.com:8080/index.html
.In case the resource name is a full root path, the site from the root path will be used. Otherwise the resource is assumed to be in the current site set be the OpenCms user context.
- Parameters:
cms
- the current OpenCms user contextresourceName
- the resource to generate the online link for- Returns:
- the link for the given resource in the current project, with full server prefix
- See Also:
-
getServerLink
Returns the link for the given resource in the current project, with full server prefix.Like
http://site.enterprise.com:8080/index.html
.In case the resource name is a full root path, the site from the root path will be used. Otherwise the resource is assumed to be in the current site set be the OpenCms user context.
- Parameters:
cms
- the current OpenCms user contextresourceName
- the resource to generate the online link forforceSecure
- forces the secure server prefix- Returns:
- the link for the given resource in the current project, with full server prefix
- See Also:
-
getWorkplaceLink
Returns the link for the given workplace resource. This should only be used for resources under /system or /shared.<p<- Parameters:
cms
- the current OpenCms user contextresourceName
- the resource to generate the online link forforceSecure
- forces the secure server prefix- Returns:
- the link for the given resource
-
setLinkSubstitutionHandler
public void setLinkSubstitutionHandler(CmsObject cms, I_CmsLinkSubstitutionHandler linkSubstitutionHandler) throws CmsRoleViolationException Sets the internal link substitution handler.- Parameters:
cms
- an OpenCms user context that must have the permissions for roleCmsRole.ROOT_ADMIN
.linkSubstitutionHandler
- the handler to set- Throws:
CmsRoleViolationException
- in case the provided OpenCms user context does not have the required permissions
-
setPointerLinkValidationResult
public void setPointerLinkValidationResult(CmsExternalLinksValidationResult externLinkValidationResult) Sets the result of an external link validation.- Parameters:
externLinkValidationResult
- the result an external link validation
-
substituteLink
Returns a link from the URI stored in the provided OpenCms user context to the given VFS resource, for use on web pages.The result will contain the configured context path and servlet name, and in the case of the "online" project it will also be rewritten according to to the configured static export settings.
Should the current site of the given OpenCms user context
cms
be different from the site root of the given resource, the result will contain the full server URL to the target resource.Please note the above text describes the default behavior as implemented by
CmsDefaultLinkSubstitutionHandler
, which can be fully customized using theI_CmsLinkSubstitutionHandler
interface.- Parameters:
cms
- the current OpenCms user contextresource
- the VFS resource the link should point to- Returns:
- a link from the URI stored in the provided OpenCms user context to the given VFS resource, for use on web pages
-
substituteLink
Returns a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the givenlink
in the current site, for use on web pages.The provided
link
is assumed to be the contained in the site currently set in the provided OpenCms user contextcms
.The result will be an absolute link that contains the configured context path and servlet name, and in the case of the "online" project it will also be rewritten according to to the configured static export settings.
In case
link
is a relative URI, the current URI contained in the provided OpenCms user contextcms
is used to make the relativelink
absolute.Please note the above text describes the default behavior as implemented by
CmsDefaultLinkSubstitutionHandler
, which can be fully customized using theI_CmsLinkSubstitutionHandler
interface.- Parameters:
cms
- the current OpenCms user contextlink
- the link to process which is assumed to point to a VFS resource, with optional parameters- Returns:
- a link from the URI stored in the provided OpenCms user context
to the VFS resource indicated by the given
link
in the current site
-
substituteLink
Returns a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the givenlink
andsiteRoot
, for use on web pages.The result will be an absolute link that contains the configured context path and servlet name, and in the case of the "online" project it will also be rewritten according to to the configured static export settings.
In case
link
is a relative URI, the current URI contained in the provided OpenCms user contextcms
is used to make the relativelink
absolute.The provided
siteRoot
is assumed to be the "home" of the link. In case the current site of the given OpenCms user contextcms
is different from the providedsiteRoot
, the full server prefix is appended to the result link.Please note the above text describes the default behavior as implemented by
CmsDefaultLinkSubstitutionHandler
, which can be fully customized using theI_CmsLinkSubstitutionHandler
interface.- Parameters:
cms
- the current OpenCms user contextlink
- the link to process which is assumed to point to a VFS resource, with optional parameterssiteRoot
- the site root of thelink
- Returns:
- the substituted link
-
substituteLink
Returns a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the givenlink
andsiteRoot
, for use on web pages, using the configured link substitution handler.The result will be an absolute link that contains the configured context path and servlet name, and in the case of the "online" project it will also be rewritten according to to the configured static export settings.
In case
link
is a relative URI, the current URI contained in the provided OpenCms user contextcms
is used to make the relativelink
absolute.The provided
siteRoot
is assumed to be the "home" of the link. In case the current site of the given OpenCms user contextcms
is different from the providedsiteRoot
, the full server prefix is appended to the result link.A server prefix is also added if
- the link is contained in a normal document and the link references a secure document
- the link is contained in a secure document and the link references a normal document
CmsDefaultLinkSubstitutionHandler
, which can be fully customized using theI_CmsLinkSubstitutionHandler
interface.- Parameters:
cms
- the current OpenCms user contextlink
- the link to process which is assumed to point to a VFS resource, with optional parameterssiteRoot
- the site root of thelink
forceSecure
- iftrue
generates always an absolute URL (with protocol and server name) for secure links- Returns:
- a link from the URI stored in the provided OpenCms user context
to the VFS resource indicated by the given
link
andsiteRoot
- See Also:
-
substituteLink
public String substituteLink(CmsObject cms, String link, String siteRoot, String targetDetailPage, boolean forceSecure) Returns a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the givenlink
andsiteRoot
, for use on web pages, using the configured link substitution handler.The result will be an absolute link that contains the configured context path and servlet name, and in the case of the "online" project it will also be rewritten according to to the configured static export settings.
In case
link
is a relative URI, the current URI contained in the provided OpenCms user contextcms
is used to make the relativelink
absolute.The provided
siteRoot
is assumed to be the "home" of the link. In case the current site of the given OpenCms user contextcms
is different from the providedsiteRoot
, the full server prefix is appended to the result link.A server prefix is also added if
- the link is contained in a normal document and the link references a secure document
- the link is contained in a secure document and the link references a normal document
CmsDefaultLinkSubstitutionHandler
, which can be fully customized using theI_CmsLinkSubstitutionHandler
interface.- Parameters:
cms
- the current OpenCms user contextlink
- the link to process which is assumed to point to a VFS resource, with optional parameterssiteRoot
- the site root of thelink
targetDetailPage
- the target detail page, in case of linking to a specific detail pageforceSecure
- iftrue
generates always an absolute URL (with protocol and server name) for secure links- Returns:
- a link from the URI stored in the provided OpenCms user context
to the VFS resource indicated by the given
link
andsiteRoot
- See Also:
-
substituteLinkForRootPath
Returns a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the given root path, for use on web pages.The result will contain the configured context path and servlet name, and in the case of the "online" project it will also be rewritten according to to the configured static export settings.
Should the current site of the given OpenCms user context
cms
be different from the site root of the given resource root path, the result will contain the full server URL to the target resource.- Parameters:
cms
- the current OpenCms user contextrootPath
- the VFS resource root path the link should point to- Returns:
- a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the given root path
-
substituteLinkForUnknownTarget
Returns a link from the URI stored in the provided OpenCms user context to the givenlink
, for use on web pages.A number of tests are performed with the
link
in order to find out how to create the link:- If
link
is empty, an empty String is returned. - If
link
starts with an URI scheme component, for examplehttp://
, and does not point to an internal OpenCms site, it is returned unchanged. - If
link
is an absolute URI that starts with a configured site root, the site root is cut from the link and the same result assubstituteLink(CmsObject, String, String)
is returned. - Otherwise the same result as
substituteLink(CmsObject, String)
is returned.
- Parameters:
cms
- the current OpenCms user contextlink
- the link to process- Returns:
- a link from the URI stored in the provided OpenCms user context
to the given
link
- If
-
substituteLinkForUnknownTarget
Returns a link from the URI stored in the provided OpenCms user context to the givenlink
, for use on web pages.A number of tests are performed with the
link
in order to find out how to create the link:- If
link
is empty, an empty String is returned. - If
link
starts with an URI scheme component, for examplehttp://
, and does not point to an internal OpenCms site, it is returned unchanged. - If
link
is an absolute URI that starts with a configured site root, the site root is cut from the link and the same result assubstituteLink(CmsObject, String, String)
is returned. - Otherwise the same result as
substituteLink(CmsObject, String)
is returned.
- Parameters:
cms
- the current OpenCms user contextlink
- the link to processforceSecure
- forces the secure server prefix if the link target is secure- Returns:
- a link from the URI stored in the provided OpenCms user context
to the given
link
- If
-
substituteLinkForUnknownTarget
public String substituteLinkForUnknownTarget(CmsObject cms, String link, String targetDetailPage, boolean forceSecure) Returns a link from the URI stored in the provided OpenCms user context to the givenlink
, for use on web pages.A number of tests are performed with the
link
in order to find out how to create the link:- If
link
is empty, an empty String is returned. - If
link
starts with an URI scheme component, for examplehttp://
, and does not point to an internal OpenCms site, it is returned unchanged. - If
link
is an absolute URI that starts with a configured site root, the site root is cut from the link and the same result assubstituteLink(CmsObject, String, String)
is returned. - Otherwise the same result as
substituteLink(CmsObject, String)
is returned.
- Parameters:
cms
- the current OpenCms user contextlink
- the link to processtargetDetailPage
- the target detail page, in case of linking to a specific detail pageforceSecure
- forces the secure server prefix if the link target is secure- Returns:
- a link from the URI stored in the provided OpenCms user context
to the given
link
- If
-
getRootPath(CmsObject, String, String)
instead, obtain the link manager withOpenCms.getLinkManager()