nl.gx.webmanager.services.seo.util
Class SEOUtil

java.lang.Object
  extended by nl.gx.webmanager.services.seo.util.SEOUtil

public final class SEOUtil
extends java.lang.Object

Provides utilities method for the rest of the SEO bundle classes.

Author:
Sander Dahlberg, Hallo Khaznadar

Method Summary
static java.lang.String addSeperatedParts(java.lang.String[] parts)
           
static java.lang.String constructDBEntityOnPageRedirect(java.lang.String prefix, java.lang.String pageRedirectPart, java.lang.String dbEntityRedirectPart, java.lang.String extension)
           
static java.lang.String constructItemOnPageRedirect(java.lang.String prefix, java.lang.String pageRedirectPart, java.lang.String itemRedirectPart, java.lang.String googleId, java.lang.String extension)
           
static java.lang.String constructPageRedirect(java.lang.String prefix, java.lang.String redirectPart, java.lang.String extension)
           
static java.lang.String ensureEndsWithPathSeparator(java.lang.String source)
          Makes sure the given string ends with the path separator, if not empty.
static java.lang.String extractFullPagePart(java.lang.String urlPart, java.lang.String prefix, java.lang.String extension)
           
static java.lang.String extractLastPart(java.lang.String urlPart, java.lang.String extension)
          Returns the part of the given friendlyURL between the last / and the given extension.
static java.lang.String extractLastPath(java.lang.String urlPath)
          Extracts the last path element from the given URL path.
static void extractPageOfArticleParts(java.lang.String url, java.lang.String prefix, java.lang.String extension, java.lang.String article, java.lang.StringBuffer initialPage, java.lang.StringBuffer googleIdORPage)
          Extracts the potential page parts of a URL containing an article as the last part of the URL.
static java.lang.String extractPageOfDbPagePart(java.lang.String url, java.lang.String prefix, java.lang.String extension, java.lang.String dbpageEntity)
           
static java.util.regex.Pattern getAbsoluteHostnamePattern()
          Returns a pattern for matching that part of an URL which makes it absolute.
static java.lang.String getDatabasePageComponentQueryString(java.lang.String internalURL)
          Returns the database page component of the given URL.
static FriendlyURLException getFURLException(java.util.logging.Logger log, java.lang.String message, java.lang.Exception cause, java.lang.String methodName)
          Logs and throws an FriendlyURLException.
static java.lang.IllegalArgumentException getIllegalArgException(java.util.logging.Logger log, java.lang.String methodName)
          Logs and throws an IllegalArgumentException with message Null argument.
static java.lang.IllegalArgumentException getIllegalArgException(java.util.logging.Logger log, java.lang.String message, java.lang.String methodName)
          Logs and throws an IllegalArgumentException.
static java.lang.String getMediaItemComponentQueryString(java.lang.String internalURL)
          Returns the media item component of the given URL.
static java.lang.String getPageComponentQueryString(java.lang.String internalURL)
          Returns the page component of the given URL.
static java.lang.String getPathSeparator()
          Returns the friendly URL path separator.
static java.lang.String getRealURLTitle(InternalSEOService seoService, Page page, Language language)
          Returns URL path a child of the given page in the given language would get.
static java.lang.String getRealURLTitle(InternalSEOService seoService, PageVersion pageVersion)
          Returns the URL title of the given page version.
static java.lang.String getRealURLTitlePath(InternalSEOService seoService, Page page, Language language)
          Returns the URL title path of the given page and language combination.
static java.util.regex.Pattern getURLSlashPattern()
          Returns a pattern for matching slashes in a relative URL.
static boolean hasDatabasePageComponent(java.lang.String internalURL)
          Returns true if the given URL has a database page component, false otherwise.
static boolean hasMediaItemComponent(java.lang.String internalURL)
          Returns true if the given URL has a media item component, false otherwise.
static boolean isFriendlyURL(java.lang.String url, java.lang.String extension)
          Returns true if given URL ends with given extension.
static long logEntering(java.util.logging.Logger log, java.lang.String methodName, java.lang.Object... params)
          Logs a method entering message.
static void logExiting(java.util.logging.Logger log, java.lang.String methodName, long start)
          Logs a method exiting message.
static void logFiner(java.util.logging.Logger log, java.lang.String methodName, java.lang.String message, java.lang.Object param)
          Logs a message through the given log on level FINER.
static void logFiner(java.util.logging.Logger log, java.lang.String methodName, java.lang.String message, java.lang.Object[] params)
          Logs a message through the given log on level FINER.
static java.lang.String normalizeURLPart(java.lang.String urlPart)
          Removes all underscores, dashes and spaces from the given urlPart, then convert the result to lowercase.
static void reInitializeMediaItemVersion(MediaItemVersion mediaItemVersion)
          Re-initializes the given media item version, so that changes to the underlying data structure of the object are visible through its getters.
static java.lang.String retrieveRemainingComponents(java.lang.String completeQS, java.lang.String extraQS)
          Removes all query string components from the completeQS parameter that presents part of a friendly URL.
static java.lang.String translateEntityTitleToURLId(java.lang.String entityTitle)
          Translates the given entity title to a friendly URL identifier.
static java.lang.String translateEntityTitleToURLTitle(java.lang.String entityTitle)
          Translates the given entity title to a friendly URL title.
static java.lang.String translateURLTitleToFriendlyURL(java.lang.String urlTitle, SEOConfig.FriendlyURLSeparator friendlyURLSeparator)
          Translates an URL title to a friendly URL.
static java.lang.String translateURLTitleToURLId(java.lang.String urlTitle)
          Translates an URL title to an URL identifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getPathSeparator

public static java.lang.String getPathSeparator()
Returns the friendly URL path separator.

Returns:
friendly URL path separator.

getAbsoluteHostnamePattern

public static java.util.regex.Pattern getAbsoluteHostnamePattern()
Returns a pattern for matching that part of an URL which makes it absolute. Takes into account that an URL might contain the special WM hostname tag.

Returns:
The absolute hostname pattern.

getURLSlashPattern

public static java.util.regex.Pattern getURLSlashPattern()
Returns a pattern for matching slashes in a relative URL. Takes into account the URL might contain un-escaped WM personalization tags.

Returns:
The URL slashes pattern.

translateEntityTitleToURLTitle

public static java.lang.String translateEntityTitleToURLTitle(java.lang.String entityTitle)
Translates the given entity title to a friendly URL title. Entity title is typically the title of a page or an article.

Parameters:
entityTitle - Title of an entity to be translated to a friendly URL title.
Returns:
The friendly URL title of an entity title.

normalizeURLPart

public static java.lang.String normalizeURLPart(java.lang.String urlPart)
Removes all underscores, dashes and spaces from the given urlPart, then convert the result to lowercase.

Parameters:
urlPart - holding a url part.
Returns:
the normalized version of the given urlPart.

translateEntityTitleToURLId

public static java.lang.String translateEntityTitleToURLId(java.lang.String entityTitle)
Translates the given entity title to a friendly URL identifier. Entity title is typically the title of a page or an article.

Parameters:
entityTitle - Title of an entity to be translated to a friendly URL identifier.
Returns:
The friendly URL identifier of an entity title.

translateURLTitleToURLId

public static java.lang.String translateURLTitleToURLId(java.lang.String urlTitle)
Translates an URL title to an URL identifier. Space characters are removed, and letters are lower cased.

Parameters:
urlTitle - The URL title of a friendly URL.
Returns:
URL identifier.

isFriendlyURL

public static boolean isFriendlyURL(java.lang.String url,
                                    java.lang.String extension)
Returns true if given URL ends with given extension.

Parameters:
url - to be examined as friendly or not
extension - the last part of the give url must end with this extension in order to be friendly.
Returns:
true if given url ends with given extension, otherwise false.

extractLastPart

public static java.lang.String extractLastPart(java.lang.String urlPart,
                                               java.lang.String extension)
Returns the part of the given friendlyURL between the last / and the given extension. For example friendlyURL = http://www.myhost.com/web/Test/Contact.htm and extension = .htm results in last part = Contact

Parameters:
urlPart - the friendly URL
extension - the friendly URL extension
Returns:
the part of the given friendlyURL between the last / and the given extension

extractFullPagePart

public static java.lang.String extractFullPagePart(java.lang.String urlPart,
                                                   java.lang.String prefix,
                                                   java.lang.String extension)
Parameters:
urlPart -
prefix -
extension -
Returns:

extractPageOfArticleParts

public static void extractPageOfArticleParts(java.lang.String url,
                                             java.lang.String prefix,
                                             java.lang.String extension,
                                             java.lang.String article,
                                             java.lang.StringBuffer initialPage,
                                             java.lang.StringBuffer googleIdORPage)
Extracts the potential page parts of a URL containing an article as the last part of the URL.

the extracted page parts will be appended to the passed initialPage and googleIdORPage parameters. Examples:
example1:
given the following parameters values

will result in setting the initialPage to (paginal1) and the googleIdORPage to (paginal2).

example2:
given the following parameters values

will result in setting the initialPage to (paginal1) and the googleIdORPage will not be set to any thing so it will stay empty.

example3:
given the following parameters values

will result in leaving both initialPage and googleIdORPage empty.
a log message will be generated indicating that the given url has a valid article part and a missing page part.

Parameters:
url - Full URL holding at least an article and a potential page parts.
prefix - The configured prefix for friendly urls.
extension - The configured extension for the friendly urls.
article - The article part of the given url, the url must end with this part followed by the extension.
initialPage - Will be filled by the initial page part if any (see examples).
googleIdORPage - Will be filled by a page part that can be a potential googleId.
Since:
9.6.0

extractPageOfDbPagePart

public static java.lang.String extractPageOfDbPagePart(java.lang.String url,
                                                       java.lang.String prefix,
                                                       java.lang.String extension,
                                                       java.lang.String dbpageEntity)
Parameters:
url -
prefix -
extension -
dbpageEntity -
Returns:

addSeperatedParts

public static java.lang.String addSeperatedParts(java.lang.String[] parts)
Parameters:
parts -
Returns:

constructPageRedirect

public static java.lang.String constructPageRedirect(java.lang.String prefix,
                                                     java.lang.String redirectPart,
                                                     java.lang.String extension)
Parameters:
prefix -
redirectPart -
extension -
Returns:

constructItemOnPageRedirect

public static java.lang.String constructItemOnPageRedirect(java.lang.String prefix,
                                                           java.lang.String pageRedirectPart,
                                                           java.lang.String itemRedirectPart,
                                                           java.lang.String googleId,
                                                           java.lang.String extension)
Parameters:
prefix -
pageRedirectPart -
itemRedirectPart -
googleId -
extension -
Returns:

constructDBEntityOnPageRedirect

public static java.lang.String constructDBEntityOnPageRedirect(java.lang.String prefix,
                                                               java.lang.String pageRedirectPart,
                                                               java.lang.String dbEntityRedirectPart,
                                                               java.lang.String extension)

hasMediaItemComponent

public static boolean hasMediaItemComponent(java.lang.String internalURL)
Returns true if the given URL has a media item component, false otherwise.

Parameters:
internalURL - URL to check.
Returns:
true if the given URL has a media item component, false otherwise.

hasDatabasePageComponent

public static boolean hasDatabasePageComponent(java.lang.String internalURL)
Returns true if the given URL has a database page component, false otherwise.

Parameters:
internalURL - URL to check.
Returns:
true if the given URL has a database page component, false otherwise.

getPageComponentQueryString

public static java.lang.String getPageComponentQueryString(java.lang.String internalURL)
Returns the page component of the given URL. URL must have a page component, or else an IllegalArgumentException is thrown.

Parameters:
internalURL - URL to check.
Returns:
Page component.

getMediaItemComponentQueryString

public static java.lang.String getMediaItemComponentQueryString(java.lang.String internalURL)
Returns the media item component of the given URL.

Parameters:
internalURL - URL to check.
Returns:
Media item component.

getDatabasePageComponentQueryString

public static java.lang.String getDatabasePageComponentQueryString(java.lang.String internalURL)
Returns the database page component of the given URL.

Parameters:
internalURL - URL to check.
Returns:
Database page component.

retrieveRemainingComponents

public static java.lang.String retrieveRemainingComponents(java.lang.String completeQS,
                                                           java.lang.String extraQS)
Removes all query string components from the completeQS parameter that presents part of a friendly URL. Returns the remaining query string components, so that they can be added to an URL. The extraQS parameter is simply added to the remaining query string components. These are typically friendly URL components that due to some error couldn't be transformed to a friendly URL.

If not an empty string the return value starts with a question mark, followed by the query string components concatenated with ampersands.

Parameters:
completeQS - Query string part of an internal URL.
extraQS - Extra query string part to be added to the result.
Returns:
Query string that should be added to the friendly URL.

translateURLTitleToFriendlyURL

public static java.lang.String translateURLTitleToFriendlyURL(java.lang.String urlTitle,
                                                              SEOConfig.FriendlyURLSeparator friendlyURLSeparator)
Translates an URL title to a friendly URL. An URL title can contain spaces, which are used to replace them according to the friendly URL separator.

Parameters:
urlTitle - URL title to translate.
friendlyURLSeparator - The friendly URL separator to use in the friendly URL.
Returns:
friendly URL.

reInitializeMediaItemVersion

public static void reInitializeMediaItemVersion(MediaItemVersion mediaItemVersion)
Re-initializes the given media item version, so that changes to the underlying data structure of the object are visible through its getters. Hack to circumvent GXWM-7487.

Parameters:
mediaItemVersion - Media item version to re-initialize.

extractLastPath

public static java.lang.String extractLastPath(java.lang.String urlPath)
Extracts the last path element from the given URL path. For example, the call extractLastPath("/aa/bb/cc") results in cc being returned.

Parameters:
urlPath - URL path.
Returns:
The last element of the path.

getRealURLTitle

public static java.lang.String getRealURLTitle(InternalSEOService seoService,
                                               Page page,
                                               Language language)
                                        throws FriendlyURLException
Returns URL path a child of the given page in the given language would get. It is the real URL title which means it reflects the real page tree state, and not that known to the friendly URL data source.

Parameters:
seoService - Reference to the SEO service.
page - Page to return the URL title for if it is current.
language - Assemble a path in this language.
Returns:
The URL title of the given page if it is current, if not current then return URL title path of the page.
Throws:
FriendlyURLException - If any access to the persistent layer failed.

getRealURLTitle

public static java.lang.String getRealURLTitle(InternalSEOService seoService,
                                               PageVersion pageVersion)
                                        throws FriendlyURLException
Returns the URL title of the given page version. It is the real URL title which means it reflects the real page tree state, and not that known to the friendly URL data source. Useful to synchronize this state with the friendly URL data source.

Parameters:
seoService - Reference to the SEO service.
pageVersion - Get the URL title of this page version.
Returns:
The URL title.
Throws:
FriendlyURLException - If any access to the persistent layer failed.

getRealURLTitlePath

public static java.lang.String getRealURLTitlePath(InternalSEOService seoService,
                                                   Page page,
                                                   Language language)
                                            throws FriendlyURLException
Returns the URL title path of the given page and language combination. The URL title is constructed from the real page tree state, not from the friendly URL data source. Useful to synchronize this state with the friendly URL data source.

Parameters:
seoService - Reference to the SEO service.
page - Get the URL title path to this page (thus this page is not included).
language - Get the URL title path for this language.
Returns:
The URL title path.
Throws:
FriendlyURLException - If any access to the persistent layer failed.

logEntering

public static long logEntering(java.util.logging.Logger log,
                               java.lang.String methodName,
                               java.lang.Object... params)
Logs a method entering message. If the given log's level is FINER then returns the current time in milliseconds, else returns 0.

Parameters:
log - The logger to log the message to.
methodName - Name of the method being entered.
params - Method's parameters.
Returns:
Current time in milliseconds.

logExiting

public static void logExiting(java.util.logging.Logger log,
                              java.lang.String methodName,
                              long start)
Logs a method exiting message. Includes the time spend, when including the start parameter with a value greater than zero.

Parameters:
log - The logger to log the message to.
methodName - Name of the method being exited.
start - Typically the current time in milliseconds when the method was entered.

logFiner

public static void logFiner(java.util.logging.Logger log,
                            java.lang.String methodName,
                            java.lang.String message,
                            java.lang.Object param)
Logs a message through the given log on level FINER. It is assumed that the name of the logger corresponds to the class name the log message is related to.

Parameters:
log - Log to this logger.
methodName - Name of method that executes this method.
message - Log message.
param - Parameter used in the log message.

logFiner

public static void logFiner(java.util.logging.Logger log,
                            java.lang.String methodName,
                            java.lang.String message,
                            java.lang.Object[] params)
Logs a message through the given log on level FINER. It is assumed that the name of the logger corresponds to the class name the log message is related to.

Parameters:
log - Log to this logger.
methodName - Name of method that executes this method.
message - Log message.
params - Parameters used in the log message.

getIllegalArgException

public static java.lang.IllegalArgumentException getIllegalArgException(java.util.logging.Logger log,
                                                                        java.lang.String methodName)
Logs and throws an IllegalArgumentException with message Null argument.

Parameters:
log - Logger to log exception on.
methodName - Method name in which the exception is thrown.
Returns:
IllegalArgumentException

getIllegalArgException

public static java.lang.IllegalArgumentException getIllegalArgException(java.util.logging.Logger log,
                                                                        java.lang.String message,
                                                                        java.lang.String methodName)
Logs and throws an IllegalArgumentException.

Parameters:
log - Logger to log exception on.
message - Exception message.
methodName - Method name in which the exception is thrown.
Returns:
IllegalArgumentException

getFURLException

public static FriendlyURLException getFURLException(java.util.logging.Logger log,
                                                    java.lang.String message,
                                                    java.lang.Exception cause,
                                                    java.lang.String methodName)
                                             throws FriendlyURLException
Logs and throws an FriendlyURLException.

Parameters:
log - Logger to log exception on.
message - Exception message.
cause - Exception cause.
methodName - Method name in which the exception is thrown.
Returns:
FriendlyURLException
Throws:
FriendlyURLException - The thrown exception.

ensureEndsWithPathSeparator

public static java.lang.String ensureEndsWithPathSeparator(java.lang.String source)
Makes sure the given string ends with the path separator, if not empty.

Parameters:
source - Source string.
Returns:
Empty string or string ending with path separator.


Copyright © 2007-2011 GX Software BV. All Rights Reserved.