info.magnolia.link
Class LinkUtil

java.lang.Object
  extended by info.magnolia.link.LinkUtil
Direct Known Subclasses:
LinkHelper, LinkUtil

public class LinkUtil
extends java.lang.Object

Utility methods for various operations necessary for link transformations and handling.

Author:
had

Field Summary
static java.lang.String DEFAULT_EXTENSION
           
static java.lang.String DEFAULT_REPOSITORY
           
static java.util.regex.Pattern EXTERNAL_LINK_PATTERN
          Pattern that matches external and mailto: links.
static java.util.regex.Pattern LINK_OR_IMAGE_PATTERN
          Pattern to find a link.
 
Constructor Summary
LinkUtil()
           
 
Method Summary
static void addParameter(java.lang.StringBuffer uri, java.lang.String name, java.lang.String value)
          Appends a parameter to the given url, using ?, or & if there are already parameters in the given url.
static java.lang.String convertAbsoluteLinksToUUIDs(java.lang.String html)
          Parses provided html and transforms all the links to the magnolia format.
static java.lang.String convertLinksFromUUIDPattern(java.lang.String str)
           
static java.lang.String convertLinksFromUUIDPattern(java.lang.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 java.lang.String convertUUIDtoHandle(java.lang.String uuid, java.lang.String repository)
          Transforms a uuid to a handle beginning with a /.
static java.lang.String convertUUIDtoURI(java.lang.String uuid, java.lang.String repository)
          Transforms a uuid to an uri.
static java.lang.String createAbsoluteLink(Content content)
          Creates absolute link including context path to the provided content and performing all URI2Repository mappings and applying locales.
static java.lang.String createAbsoluteLink(NodeData nodedata)
          Creates absolute link including context path for provided node data.
static java.lang.String createAbsoluteLink(java.lang.String repository, java.lang.String uuid)
          Creates absolute link including context path to the provided content and performing all URI2Repository mappings and applying locales.
static java.lang.String createExternalLink(Content content)
          Creates a complete url to access given content from external systems applying all the URI2Repository mappings and locales.
static java.lang.String createLink(Content node)
          Creates link guessing best possible link format from current site and provided node.
static java.lang.String createLink(NodeData nodedata)
          Creates link guessing best possible link format from current site and provided node data.
static java.lang.String createLink(java.lang.String repository, java.lang.String uuid)
          Creates link guessing best possible link format from current site and provided content.
static boolean isExternalLinkOrAnchor(java.lang.String href)
          Determines whether the given link is external link or anchor (i.e.
static boolean isInternalRelativeLink(java.lang.String href)
          Determines if the given link is internal and relative.
static java.lang.String makePathRelative(java.lang.String url, java.lang.String absolutePath)
          Make a absolute path relative.
static java.lang.String mapPathToRepository(java.lang.String path)
          Maps a path to a repository.
 
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 java.util.regex.Pattern EXTERNAL_LINK_PATTERN
Pattern that matches external and mailto: links.


DEFAULT_EXTENSION

public static final java.lang.String DEFAULT_EXTENSION
See Also:
Constant Field Values

DEFAULT_REPOSITORY

public static final java.lang.String DEFAULT_REPOSITORY
See Also:
Constant Field Values

LINK_OR_IMAGE_PATTERN

public static final java.util.regex.Pattern LINK_OR_IMAGE_PATTERN
Pattern to find a link.

Constructor Detail

LinkUtil

public LinkUtil()
Method Detail

convertUUIDtoHandle

public static java.lang.String convertUUIDtoHandle(java.lang.String uuid,
                                                   java.lang.String repository)
                                            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 java.lang.String convertUUIDtoURI(java.lang.String uuid,
                                                java.lang.String repository)
                                         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 java.lang.String convertAbsoluteLinksToUUIDs(java.lang.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 java.lang.String convertLinksFromUUIDPattern(java.lang.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 java.lang.String convertLinksFromUUIDPattern(java.lang.String str)
                                                    throws LinkException
Throws:
LinkException

isInternalRelativeLink

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


isExternalLinkOrAnchor

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


makePathRelative

public static java.lang.String makePathRelative(java.lang.String url,
                                                java.lang.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 java.lang.String mapPathToRepository(java.lang.String path)
Maps a path to a repository.

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

addParameter

public static void addParameter(java.lang.StringBuffer uri,
                                java.lang.String name,
                                java.lang.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 java.lang.String createAbsoluteLink(NodeData nodedata)
                                           throws LinkException
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 java.lang.String createAbsoluteLink(java.lang.String repository,
                                                  java.lang.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.
repository - 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 java.lang.String createAbsoluteLink(Content content)
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

createExternalLink

public static java.lang.String createExternalLink(Content content)
Creates a complete url to access given content from external systems applying all the URI2Repository mappings and locales.

Parameters:
content -
Returns:

createLink

public static java.lang.String createLink(Content node)
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 java.lang.String createLink(NodeData nodedata)
                                   throws LinkException
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 java.lang.String createLink(java.lang.String repository,
                                          java.lang.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.
repository - Name of the repository where content is located.
Returns:
Absolute link to the provided content.
Throws:
javax.jcr.RepositoryException
See Also:
AbstractI18nContentSupport


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