info.magnolia.link
Class LinkUtil

java.lang.Object
  extended by info.magnolia.link.LinkUtil

public class LinkUtil
extends Object

Utility methods for various operations necessary for link transformations and handling. This is actually a Business Facade providing an entry point to the link transformations. Hence it will be renamed to LinkManager (MAGNOLIA-4765) soon.


Field Summary
static String DEFAULT_EXTENSION
           
static String DEFAULT_REPOSITORY
           
static Pattern EXTERNAL_LINK_PATTERN
          Pattern that matches external and mailto: links.
static Pattern LINK_OR_IMAGE_PATTERN
          Pattern to find a link.
static Pattern LINK_PATTERN
          Pattern to find a link.
static Pattern UUID_PATTERN
          Pattern to find a magnolia formatted uuid link.
 
Constructor Summary
LinkUtil()
           
 
Method Summary
static void addParameter(StringBuffer uri, String name, String value)
          Appends a parameter to the given url, using ?, or & if there are already parameters in the given url.
static String convertAbsoluteLinksToUUIDs(String html)
          Parses provided html and transforms all the links to the magnolia format.
static String convertLinksFromUUIDPattern(String str)
           
static String convertLinksFromUUIDPattern(String str, LinkTransformer transformer)
          Converts provided html with links in UUID pattern format to any other kind of links based on provided link transformer.
static String convertUUIDtoHandle(String uuid, String workspaceName)
          Transforms a uuid to a handle beginning with a /.
static String convertUUIDtoURI(String uuid, String workspaceName)
          Transforms a uuid to an uri.
static String createAbsoluteLink(Content content)
          Deprecated. Since 5.0 use LinkUtil.createAbsoluteLink(Node) instead.
static String createAbsoluteLink(javax.jcr.Node node)
          Creates absolute link including context path to the provided node and performing all URI2Repository mappings and applying locales.
static String createAbsoluteLink(NodeData nodedata)
          Deprecated. Since 5.0 use LinkUtil.createAbsoluteLink(Property) instead.
static String createAbsoluteLink(javax.jcr.Property property)
          Creates absolute link including context path for provided Property.
static String createAbsoluteLink(String workspaceName, String uuid)
          Creates absolute link including context path to the provided content and performing all URI2Repository mappings and applying locales.
static String createExternalLink(Content content)
          Deprecated. Since 5.0 use LinkUtil.createExternalLink(Node) instead.
static String createExternalLink(javax.jcr.Node node)
          Creates a complete url to access given node from external systems applying all the URI2Repository mappings and locales.
static String createLink(Content node)
          Deprecated. Since 5.0 use LinkUtil.createLink(Node) instead.
static String createLink(javax.jcr.Node node)
          Creates link guessing best possible link format from current site and provided node.
static String createLink(NodeData nodedata)
          Deprecated. Since 5.0 use LinkUtil.createAbsoluteLink(Property) instead.
static String createLink(javax.jcr.Property property)
          Creates link guessing best possible link format from current site and provided Property.
static String createLink(String workspaceName, String uuid)
          Creates link guessing best possible link format from current site and provided content.
static Link createLinkInstance(Content node)
          Deprecated. Since 5.0 use LinkUtil.createLinkInstance(Node) instead.
static Link createLinkInstance(javax.jcr.Node node)
          Creates Link to provided Node.
static Link createLinkInstance(NodeData nodeData)
          Deprecated. Since 5.0 use LinkUtil.createLinkInstance(Property) instead.
static Link createLinkInstance(javax.jcr.Property property)
           
static Link createLinkInstance(String workspaceName, String uuid)
          Creates link to the content denoted by repository and uuid.
static Link createLinkInstance(String workspaceName, String path, String extension, String anchor, String parameters)
          Creates link to the content identified by the repository and path.
static Link createLinkInstance(String uuid, String workspaceName, String fallbackHandle, String nodeDataName, String extension, String anchor, String parameters)
          Creates link based on provided parameters.
static boolean isExternalLinkOrAnchor(String href)
          Determines whether the given link is external link or anchor (i.e.
static boolean isInternalRelativeLink(String href)
          Determines if the given link is internal and relative.
static String makePathRelative(String url, String absolutePath)
          Make a absolute path relative.
static String mapPathToRepository(String path)
          Maps a path to a repository.
static Link parseLink(String link)
          Parses provided URI to the link.
static Link parseUUIDLink(String uuidLink)
          Parses UUID link pattern string and converts it into a Link object.
static String toPattern(Link link)
          Converts provided Link to an UUID link pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXTERNAL_LINK_PATTERN

public static final Pattern EXTERNAL_LINK_PATTERN
Pattern that matches external and mailto: links.


DEFAULT_EXTENSION

public static final String DEFAULT_EXTENSION
See Also:
Constant Field Values

DEFAULT_REPOSITORY

public static final String DEFAULT_REPOSITORY
See Also:
Constant Field Values

LINK_OR_IMAGE_PATTERN

public static final Pattern LINK_OR_IMAGE_PATTERN
Pattern to find a link.


UUID_PATTERN

public static Pattern UUID_PATTERN
Pattern to find a magnolia formatted uuid link.


LINK_PATTERN

public static final Pattern LINK_PATTERN
Pattern to find a link.

Constructor Detail

LinkUtil

public LinkUtil()
Method Detail

convertUUIDtoHandle

public static String convertUUIDtoHandle(String uuid,
                                         String workspaceName)
                                  throws LinkException
Transforms a uuid to a handle beginning with a /. This path is used to get the page from the repository. The editor needs this kind of links.

Throws:
LinkException

convertUUIDtoURI

public static String convertUUIDtoURI(String uuid,
                                      String workspaceName)
                               throws LinkException
Transforms a uuid to an uri. It does not add the context path. In difference from Link.getHandle(), this method will apply all uri to repository mappings as well as i18n.

Throws:
LinkException

convertAbsoluteLinksToUUIDs

public static String convertAbsoluteLinksToUUIDs(String html)
Parses provided html and transforms all the links to the magnolia format. Used during storing.

Parameters:
html - html code with links to be converted
Returns:
html with changed hrefs

convertLinksFromUUIDPattern

public static String convertLinksFromUUIDPattern(String str,
                                                 LinkTransformer transformer)
                                          throws LinkException
Converts provided html with links in UUID pattern format to any other kind of links based on provided link transformer.

Parameters:
str - Html with UUID links
transformer - Link transformer
Returns:
converted html with links as created by provided transformer.
Throws:
LinkException
See Also:
LinkTransformerManager

convertLinksFromUUIDPattern

public static String convertLinksFromUUIDPattern(String str)
                                          throws LinkException
Throws:
LinkException

isInternalRelativeLink

public static boolean isInternalRelativeLink(String href)
Determines if the given link is internal and relative.


isExternalLinkOrAnchor

public static boolean isExternalLinkOrAnchor(String href)
Determines whether the given link is external link or anchor (i.e. returns true for all non translatable links).


makePathRelative

public static String makePathRelative(String url,
                                      String absolutePath)
Make a absolute path relative. It adds ../ until the root is reached

Parameters:
absolutePath - absolute path
url - page to be relative to
Returns:
relative path

mapPathToRepository

public static String mapPathToRepository(String path)
Maps a path to a repository.

Parameters:
path - URI
Returns:
repository denoted by the provided URI.

addParameter

public static void addParameter(StringBuffer uri,
                                String name,
                                String value)
Appends a parameter to the given url, using ?, or & if there are already parameters in the given url. Warning: It does not replace an existing parameter with the same name.


createAbsoluteLink

public static String createAbsoluteLink(NodeData nodedata)
                                 throws LinkException
Deprecated. Since 5.0 use LinkUtil.createAbsoluteLink(Property) instead.

Creates absolute link including context path for provided node data.

Parameters:
nodedata - Node data to create link for.
Returns:
Absolute link to the provided node data.
Throws:
LinkException
See Also:
AbstractI18nContentSupport

createAbsoluteLink

public static String createAbsoluteLink(javax.jcr.Property property)
                                 throws LinkException
Creates absolute link including context path for provided Property.

Returns:
Absolute link to the provided Property.
Throws:
LinkException

createAbsoluteLink

public static String createAbsoluteLink(String workspaceName,
                                        String uuid)
                                 throws javax.jcr.RepositoryException
Creates absolute link including context path to the provided content and performing all URI2Repository mappings and applying locales.

Parameters:
uuid - UUID of content to create link to.
workspaceName - Name of the repository where content is located.
Returns:
Absolute link to the provided content.
Throws:
javax.jcr.RepositoryException
See Also:
AbstractI18nContentSupport

createAbsoluteLink

public static String createAbsoluteLink(Content content)
Deprecated. Since 5.0 use LinkUtil.createAbsoluteLink(Node) instead.

Creates absolute link including context path to the provided content and performing all URI2Repository mappings and applying locales.

Parameters:
content - content to create link to.
Returns:
Absolute link to the provided content.
See Also:
AbstractI18nContentSupport

createAbsoluteLink

public static String createAbsoluteLink(javax.jcr.Node node)
Creates absolute link including context path to the provided node and performing all URI2Repository mappings and applying locales.

Returns:
Absolute link to the provided content.

createExternalLink

public static String createExternalLink(Content content)
Deprecated. Since 5.0 use LinkUtil.createExternalLink(Node) instead.

Creates a complete url to access given content from external systems applying all the URI2Repository mappings and locales.


createExternalLink

public static String createExternalLink(javax.jcr.Node node)
Creates a complete url to access given node from external systems applying all the URI2Repository mappings and locales.


createLink

public static String createLink(Content node)
Deprecated. Since 5.0 use LinkUtil.createLink(Node) instead.

Creates link guessing best possible link format from current site and provided node.

Parameters:
nodedata - Node data to create link for.
Returns:
Absolute link to the provided node data.
See Also:
AbstractI18nContentSupport

createLink

public static String createLink(javax.jcr.Node node)
Creates link guessing best possible link format from current site and provided node.

Parameters:
node - Node to create link for.
Returns:
Absolute link to the provided Node.

createLink

public static String createLink(NodeData nodedata)
                         throws LinkException
Deprecated. Since 5.0 use LinkUtil.createAbsoluteLink(Property) instead.

Creates link guessing best possible link format from current site and provided node data.

Parameters:
nodedata - Node data to create link for.
Returns:
Absolute link to the provided node data.
Throws:
LinkException
See Also:
AbstractI18nContentSupport

createLink

public static String createLink(javax.jcr.Property property)
                         throws LinkException
Creates link guessing best possible link format from current site and provided Property.

Parameters:
property - Property to create link for.
Returns:
Absolute link to the provided Property.
Throws:
LinkException

createLink

public static String createLink(String workspaceName,
                                String uuid)
                         throws javax.jcr.RepositoryException
Creates link guessing best possible link format from current site and provided content.

Parameters:
uuid - UUID of content to create link to.
workspaceName - Name of the repository where content is located.
Returns:
Absolute link to the provided content.
Throws:
javax.jcr.RepositoryException
See Also:
AbstractI18nContentSupport

createLinkInstance

public static Link createLinkInstance(Content node)
Deprecated. Since 5.0 use LinkUtil.createLinkInstance(Node) instead.

Creates Link to provided Content.

Returns:
Link to provided Content.

createLinkInstance

public static Link createLinkInstance(javax.jcr.Node node)
Creates Link to provided Node.

Returns:
Link to provided Node.

createLinkInstance

public static Link createLinkInstance(NodeData nodeData)
                               throws LinkException
Deprecated. Since 5.0 use LinkUtil.createLinkInstance(Property) instead.

Creates Link to provided NodeData.

Returns:
Link to provided NodeData.
Throws:
LinkException

createLinkInstance

public static Link createLinkInstance(javax.jcr.Property property)
                               throws LinkException
Throws:
LinkException

createLinkInstance

public static Link createLinkInstance(String workspaceName,
                                      String uuid)
                               throws LinkException
Creates link to the content denoted by repository and uuid.

Parameters:
workspaceName - Parent repository of the content of interest.
uuid - UUID of the content to create link to.
Returns:
link to the content with provided UUID.
Throws:
LinkException

createLinkInstance

public static Link createLinkInstance(String workspaceName,
                                      String path,
                                      String extension,
                                      String anchor,
                                      String parameters)
                               throws LinkException
Creates link to the content identified by the repository and path. Link will use specified extension and will also contain the anchor and parameters if specified.

Parameters:
workspaceName - Source repository for the content.
path - Path to the content of interest.
extension - Optional extension to be used in the link
anchor - Optional link anchor.
parameters - Optional link parameters.
Returns:
Link pointing to the content denoted by repository and path including extension, anchor and parameters if such were provided.
Throws:
LinkException

createLinkInstance

public static Link createLinkInstance(String uuid,
                                      String workspaceName,
                                      String fallbackHandle,
                                      String nodeDataName,
                                      String extension,
                                      String anchor,
                                      String parameters)
                               throws LinkException
Creates link based on provided parameters. Should the uuid be non existent or the fallback handle invalid, creates nonetheless an "undefined" Link object, pointing to the non existing uuid so that broken link detection tools can find it.

Parameters:
uuid - UUID of the content
workspaceName - Content repository name.
fallbackHandle - Optional fallback content handle.
nodeDataName - Content node data name for binary data.
extension - Optional link extension.
anchor - Optional link anchor.
parameters - Optional link parameters.
Returns:
Link pointing to the content denoted by uuid and repository. Link is created using all provided optional values if present.
Throws:
LinkException

parseUUIDLink

public static Link parseUUIDLink(String uuidLink)
                          throws LinkException
Parses UUID link pattern string and converts it into a Link object.

Parameters:
uuidLink - String containing reference to content as a UUID link pattern.
Returns:
Link to content referenced in the provided text.
Throws:
LinkException

parseLink

public static Link parseLink(String link)
                      throws LinkException
Parses provided URI to the link.

Parameters:
link - URI representing path to piece of content
Returns:
Link pointing to the content represented by provided URI
Throws:
LinkException

toPattern

public static String toPattern(Link link)
Converts provided Link to an UUID link pattern.

Parameters:
link - Link to convert.
Returns:
UUID link pattern representation of provided link.


Copyright © 2003-2014 Magnolia International Ltd.. All Rights Reserved.