org.opencms.staticexport
Class CmsLinkManager

java.lang.Object
  extended byorg.opencms.staticexport.CmsLinkManager

public class CmsLinkManager
extends java.lang.Object

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.

Since:
6.0.0
Version:
$Revision: 1.62 $
Author:
Alexander Kandzior

Constructor Summary
CmsLinkManager()
          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.
 CmsPointerLinkValidationResult 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 realtive uri from "fromUri" to "toUri", both uri's must be absolute.
static java.lang.String getSitePath(CmsObject cms, java.lang.String relativePath, java.lang.String targetUri)
          Returns the site path for a given uri.
 void setPointerLinkValidationResult(CmsPointerLinkValidationResult externLinkValidationResult)
          Sets the result of a extern link validation.
 java.lang.String substituteLink(CmsObject cms, java.lang.String link)
          Substitutes the contents of a link by adding the context path and servlet name, and in the case of the "online" project also according to the configured static export settings.
 java.lang.String substituteLink(CmsObject cms, java.lang.String link, java.lang.String siteRoot)
          Substitutes the contents of a link by adding the context path and servlet name, and in the case of the "online" project also according to the configured static export settings.
 java.lang.String substituteLink(CmsObject cms, java.lang.String link, java.lang.String siteRoot, boolean forceSecure)
          Substitutes the contents of a link by adding the context path and servlet name, and in the case of the "online" project also according to the configured static export settings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsLinkManager

public CmsLinkManager()
Public constructor.

Method Detail

getAbsoluteUri

public 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.

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 for
baseUri - the base uri, this must be an absolute uri
Returns:
an absolute uri calculated from "relativeUri" and "baseUri"

getRelativeUri

public static java.lang.String getRelativeUri(java.lang.String fromUri,
                                              java.lang.String toUri)
Calculates a realtive uri from "fromUri" to "toUri", both uri's must be absolute.

Parameters:
fromUri - the uri to start
toUri - the uri to calculate a relative path to
Returns:
a realtive uri from "fromUri" to "toUri"

getSitePath

public static java.lang.String getSitePath(CmsObject cms,
                                           java.lang.String relativePath,
                                           java.lang.String targetUri)
Returns the site path for a given uri.

If the uri contains no site information, but starts with the opencms context, the context is removed.

/opencms/opencms/system/further_path -> /system/further_path If the uri contains no site information, the path will be prefixed with the current site (if mysite is the site currently selected in the workplace or in the request).

 /folder/page.html -> /sites/mysite/folder/page.html
 
If the path of the uri is relative, i.e. does not start with "/", the path will be prefixed with the current site and the given relative path, then normalized. If no relative path is given, null is returned. If the normalized path is outsite a site, null is returned.

 page.html -> /sites/mysite/{relativePath}/page.html
 ../page.html -> /sites/mysite/page.html
 ../../page.html -> null
 
If the uri contains a scheme/server name that denotes an opencms site, it is replaced by the appropriate site path.

 http://www.mysite.de/folder/page.html -> /sites/mysite/folder/page.html
 
If the uri contains a scheme/server name that does not match with any site, or if the uri is opaque or invalid, null is returned.

 http://www.elsewhere.com/page.html -> null
 mailto:someone@elsewhere.com -> null
 

Parameters:
cms - the cms object
relativePath - path to use as prefix if neccessary
targetUri - the target uri
Returns:
the root path for the target uri or null

getPointerLinkValidationResult

public CmsPointerLinkValidationResult getPointerLinkValidationResult()
Returns the result of the last extern link validation.

Returns:
the result of the last extern link validation

setPointerLinkValidationResult

public void setPointerLinkValidationResult(CmsPointerLinkValidationResult externLinkValidationResult)
Sets the result of a extern link validation.

Parameters:
externLinkValidationResult - the result a extern link validation

substituteLink

public java.lang.String substituteLink(CmsObject cms,
                                       java.lang.String link)
Substitutes the contents of a link by adding the context path and servlet name, and in the case of the "online" project also according to the configured static export settings.

Parameters:
cms - the cms context
link - the link to process (must be a valid link to a VFS resource with optional parameters)
Returns:
the substituted link

substituteLink

public java.lang.String substituteLink(CmsObject cms,
                                       java.lang.String link,
                                       java.lang.String siteRoot)
Substitutes the contents of a link by adding the context path and servlet name, and in the case of the "online" project also according to the configured static export settings.

A server prefix is prepended if

Parameters:
cms - the cms context
link - the link to process (must be a valid link to a VFS resource with optional parameters)
siteRoot - the site root of the link
Returns:
the substituted link

substituteLink

public java.lang.String substituteLink(CmsObject cms,
                                       java.lang.String link,
                                       java.lang.String siteRoot,
                                       boolean forceSecure)
Substitutes the contents of a link by adding the context path and servlet name, and in the case of the "online" project also according to the configured static export settings.

A server prefix is prepended if

Parameters:
cms - the cms context
link - the link to process (must be a valid link to a VFS resource with optional parameters)
siteRoot - the site root of the link
forceSecure - if true generates always an absolute url (with protocoll and server name) for secure links
Returns:
the substituted link