Interface I_CmsLinkSubstitutionHandler
- All Known Implementing Classes:
CmsAdvancedLinkSubstitutionHandler
,CmsDefaultLinkSubstitutionHandler
,CmsLocalePrefixLinkSubstitutionHandler
Using this handler, you can completely customize the behavior of the link substitution.
This handler is plugged into
CmsLinkManager.substituteLink(org.opencms.file.CmsObject, String, String, boolean)
,
which is the central method to calculate links from VFS paths,
used by the <cms:link />
tag and the rest of the OpenCms core.
Moreover, this handler is plugged into
CmsLinkManager.getRootPath(CmsObject, String, String)
,
which is the reverse method to calculate a VFS root path from a link.
For any implementation of this interface you must ensure the following:
// path: String that represents a valid VFS resource root path // cms: a valid OpenCms user context String httpLink = OpenCms.getLinkManager().substituteLinkForRootPath(cms, path); String vfsPath = OpenCms.getLinkManager().getRootPath(cms, httpLink); path.equals(vfsPath); // this must be true!The default implementation of this interface is
CmsDefaultLinkSubstitutionHandler
.-
Method Summary
Modifier and TypeMethodDescriptionReturns 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.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.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.
-
Method Details
-
getLink
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 should 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 normally 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 this handler 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:
-
getLink
String getLink(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.The result should 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 normally 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 this handler 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:
-
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 this handler 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 - See Also:
- In case the link starts with a VFS prefix (for example
-