info.magnolia.link
Class LinkUtil

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

public class LinkUtil
extends Object

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

Author:
had

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.
 
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 repository)
          Transforms a uuid to a handle beginning with a /.
static String convertUUIDtoURI(String uuid, String repository)
          Transforms a uuid to an uri.
static String createAbsoluteLink(Content content)
          Creates absolute link including context path to the provided content and performing all URI2Repository mappings and applying locales.
static String createAbsoluteLink(NodeData nodedata)
          Creates absolute link including context path for provided node data.
static String createAbsoluteLink(String repository, 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)
          Creates a complete url to access given content from external systems applying all the URI2Repository mappings and locales.
static String createLink(Content node)
          Creates link guessing best possible link format from current site and provided node.
static String createLink(NodeData nodedata)
          Creates link guessing best possible link format from current site and provided node data.
static String createLink(String repository, String uuid)
          Creates link guessing best possible link format from current site and provided content.
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.
 
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.

Constructor Detail

LinkUtil

public LinkUtil()
Method Detail

convertUUIDtoHandle

public static String convertUUIDtoHandle(String uuid,
                                         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 String convertUUIDtoURI(String uuid,
                                      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 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
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(String repository,
                                        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 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 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 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 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 String createLink(String repository,
                                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-2011 Magnolia International Ltd.. All Rights Reserved.