|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opencms.staticexport.CmsLinkManager
public class CmsLinkManager
Does the link replacement for the ≶link> tags.
Since this functionality is closely related to the static export, this class resides in the static export package.
Constructor Summary | |
---|---|
CmsLinkManager(I_CmsLinkSubstitutionHandler linkSubstitutionHandler)
Public constructor. |
Method Summary | |
---|---|
static java.lang.String |
getAbsoluteUri(java.lang.String relativeUri,
java.lang.String baseUri)
Calculates the absolute URI for the "relativeUri" with the given absolute "baseUri" as start. |
java.lang.String |
getOnlineLink(CmsObject cms,
java.lang.String resourceName)
Returns the online link for the given resource, with full server prefix. |
java.lang.String |
getPermalink(CmsObject cms,
java.lang.String resourceName)
Returns the perma link for the given resource. |
CmsExternalLinksValidationResult |
getPointerLinkValidationResult()
Returns the result of the last extern link validation. |
static java.lang.String |
getRelativeUri(java.lang.String fromUri,
java.lang.String toUri)
Calculates a relative URI from "fromUri" to "toUri", both URI must be absolute. |
java.lang.String |
getRootPath(CmsObject cms,
java.lang.String targetUri)
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. |
java.lang.String |
getRootPath(CmsObject cms,
java.lang.String targetUri,
java.lang.String basePath)
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. |
java.lang.String |
getServerLink(CmsObject cms,
java.lang.String resourceName)
Returns the link for the given resource in the current project, with full server prefix. |
static java.lang.String |
getSitePath(CmsObject cms,
java.lang.String basePath,
java.lang.String targetUri)
Deprecated. use getRootPath(CmsObject, String, String) instead, obtain the link manager
with OpenCms.getLinkManager() |
static boolean |
hasScheme(java.lang.String uri)
Tests if the given URI starts with a scheme component. |
static boolean |
isAbsoluteUri(java.lang.String uri)
Returns true in case the given URI is absolute. |
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. |
java.lang.String |
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. |
java.lang.String |
substituteLink(CmsObject cms,
java.lang.String link)
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,
for use on web pages. |
java.lang.String |
substituteLink(CmsObject cms,
java.lang.String link,
java.lang.String siteRoot)
Returns a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the given link and siteRoot ,
for use on web pages. |
java.lang.String |
substituteLink(CmsObject cms,
java.lang.String link,
java.lang.String siteRoot,
boolean forceSecure)
Returns a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the given link and siteRoot ,
for use on web pages, using the configured link substitution handler. |
java.lang.String |
substituteLinkForRootPath(CmsObject cms,
java.lang.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. |
java.lang.String |
substituteLinkForUnknownTarget(CmsObject cms,
java.lang.String link)
Returns a link from the URI stored in the provided OpenCms user context to the given link , for use on web pages. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CmsLinkManager(I_CmsLinkSubstitutionHandler linkSubstitutionHandler)
linkSubstitutionHandler
- the link substitution handler to useMethod Detail |
---|
public static java.lang.String getAbsoluteUri(java.lang.String relativeUri, java.lang.String baseUri)
If "relativeUri" is already absolute, it is returned unchanged. This method also returns "relativeUri" unchanged if it is not well-formed.
relativeUri
- the relative URI to calculate an absolute URI forbaseUri
- the base URI, this must be an absolute URI
public static java.lang.String getRelativeUri(java.lang.String fromUri, java.lang.String toUri)
fromUri
- the URI to starttoUri
- the URI to calculate a relative path to
public static java.lang.String getSitePath(CmsObject cms, java.lang.String basePath, java.lang.String targetUri)
getRootPath(CmsObject, String, String)
instead, obtain the link manager
with OpenCms.getLinkManager()
null
in
case the target URI points to an external site.
cms
- the current users OpenCms contextbasePath
- path to use as base site for the target URI (can be null
)targetUri
- the target URI
null
in
case the target URI points to an external sitepublic static boolean hasScheme(java.lang.String uri)
The scheme component is something like http:
or ftp:
.
uri
- the URI to test
true
if the given URI starts with a scheme componentpublic static boolean isAbsoluteUri(java.lang.String uri)
true
in case the given URI is absolute.An URI is considered absolute if one of the following is true:
'/'
char.
':'
in the first 10 chars.
null
uri
- the URI to test
true
in case the given URI is absolutepublic java.lang.String getOnlineLink(CmsObject cms, java.lang.String resourceName)
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)
.
cms
- the current OpenCms user contextresourceName
- the resource to generate the online link for
getServerLink(CmsObject, String)
public java.lang.String getPermalink(CmsObject cms, java.lang.String resourceName)
Like
http://site.enterprise.com:8080/permalink/4b65369f-1266-11db-8360-bf0f6fbae1f8.html
.
cms
- the cms contextresourceName
- the resource to generate the perma link for
public CmsExternalLinksValidationResult getPointerLinkValidationResult()
public java.lang.String getRootPath(CmsObject cms, java.lang.String targetUri)
null
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.
cms
- the current users OpenCms contexttargetUri
- the target URI link
null
in
case the link points to an external sitegetRootPath(CmsObject, String, String)
public java.lang.String getRootPath(CmsObject cms, java.lang.String targetUri, java.lang.String basePath)
null
in
case the link points to an external site.The default implementation applies the following transformations to the link:
/opencms/opencms
,
this prefix is removed from the result
basePath
as starting point.
http://www.mysite.de/
),
which points to a configured site in OpenCms, the server schema is replaced with
the root path of the site.
null
is returned.
CmsDefaultLinkSubstitutionHandler
, which can be fully customized using
the I_CmsLinkSubstitutionHandler
interface.
cms
- the current users OpenCms contexttargetUri
- the target URI linkbasePath
- path to use as base in case the target URI is relative (can be null
)
null
in
case the link points to an external sitefor the interface that can be used to fully customize the link substitution
,
for the default link substitution handler
public java.lang.String getServerLink(CmsObject cms, java.lang.String resourceName)
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.
cms
- the current OpenCms user contextresourceName
- the resource to generate the online link for
getOnlineLink(CmsObject, String)
public void setLinkSubstitutionHandler(CmsObject cms, I_CmsLinkSubstitutionHandler linkSubstitutionHandler) throws CmsRoleViolationException
cms
- an OpenCms user context that must have the permissions for role CmsRole.ROOT_ADMIN
.linkSubstitutionHandler
- the handler to set
CmsRoleViolationException
- in case the provided OpenCms user context does not have the required permissionspublic void setPointerLinkValidationResult(CmsExternalLinksValidationResult externLinkValidationResult)
externLinkValidationResult
- the result an external link validationpublic java.lang.String substituteLink(CmsObject cms, CmsResource resource)
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 the
I_CmsLinkSubstitutionHandler
interface.
cms
- the current OpenCms user contextresource
- the VFS resource the link should point to
public java.lang.String substituteLink(CmsObject cms, java.lang.String link)
link
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 context cms
.
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 context cms
is used to make the relative link
absolute.
Please note the above text describes the default behavior as implemented by
CmsDefaultLinkSubstitutionHandler
, which can be fully customized using the
I_CmsLinkSubstitutionHandler
interface.
cms
- the current OpenCms user contextlink
- the link to process which is assumed to point to a VFS resource, with optional parameters
link
in the current sitepublic java.lang.String substituteLink(CmsObject cms, java.lang.String link, java.lang.String siteRoot)
link
and siteRoot
,
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 context cms
is used to make the relative link
absolute.
The provided siteRoot
is assumed to be the "home" of the link.
In case the current site of the given OpenCms user context cms
is different from the
provided siteRoot
, 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 the
I_CmsLinkSubstitutionHandler
interface.
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 the link
public java.lang.String substituteLink(CmsObject cms, java.lang.String link, java.lang.String siteRoot, boolean forceSecure)
link
and siteRoot
,
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 context cms
is used to make the relative link
absolute.
The provided siteRoot
is assumed to be the "home" of the link.
In case the current site of the given OpenCms user context cms
is different from the
provided siteRoot
, the full server prefix is appended to the result link.
A server prefix is also added if
CmsDefaultLinkSubstitutionHandler
, which can be fully customized using the
I_CmsLinkSubstitutionHandler
interface.
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 the link
forceSecure
- if true
generates always an absolute URL (with protocol and server name) for secure links
link
and siteRoot
for the interface that can be used to fully customize the link substitution
,
for the default link substitution handler
public java.lang.String substituteLinkForRootPath(CmsObject cms, java.lang.String rootPath)
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.
cms
- the current OpenCms user contextrootPath
- the VFS resource root path the link should point to
public java.lang.String substituteLinkForUnknownTarget(CmsObject cms, java.lang.String link)
link
, for use on web pages.
A number of tests are performed with the link
in order to find out how to create the link:
link
is empty, an empty String is returned.
link
starts with an URI scheme component, for example http://
,
and does not point to an internal OpenCms site, it is returned unchanged.
link
is an absolute URI that starts with a configured site root,
the site root is cut from the link and
the same result as substituteLink(CmsObject, String, String)
is returned.
substituteLink(CmsObject, String)
is returned.
cms
- the current OpenCms user contextlink
- the link to process
link
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |