com.opencms.flex.util
Class CmsStringSubstitution

java.lang.Object
  |
  +--com.opencms.flex.util.CmsStringSubstitution

public class CmsStringSubstitution
extends Object

Provides a String substitution functionality with Perl regular expressions.

Since:
5.0
Version:
$Revision: 1.6 $
Author:
Andreas Zahner (a.zahner@alkacon.com)

Constructor Summary
CmsStringSubstitution()
          Default constructor (empty).
 
Method Summary
static String escapePattern(String source)
          Escapes a String so it may be used as a Perl5 regular expression.
static String substitute(String content, String searchString, String replaceItem)
          Substitutes searchString in content with replaceItem.
static String substituteContextPath(String htmlContent, String context)
          Substitutes the OpenCms context path (e.g.
static String substituteFirst(String content, String searchString, String replaceItem)
          Substitutes first occurance of searchString in content with replaceItem.
static String substitutePerl(String content, String searchString, String replaceItem, String occurences)
          Substitutes searchString in content with replaceItem.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsStringSubstitution

public CmsStringSubstitution()
Default constructor (empty).

Method Detail

substitute

public static String substitute(String content,
                                String searchString,
                                String replaceItem)
Substitutes searchString in content with replaceItem.

Parameters:
content - the content which is scanned
searchString - the String which is searched in content
replaceItem - the new String which replaces searchString
Returns:
String the substituted String

substituteFirst

public static String substituteFirst(String content,
                                     String searchString,
                                     String replaceItem)
Substitutes first occurance of searchString in content with replaceItem.

Parameters:
content - the content which is scanned
searchString - the String which is searched in content
replaceItem - the new String which replaces searchString
Returns:
String the substituted String

substitutePerl

public static String substitutePerl(String content,
                                    String searchString,
                                    String replaceItem,
                                    String occurences)
Substitutes searchString in content with replaceItem.

Parameters:
content - the content which is scanned
searchString - the String which is searched in content
replaceItem - the new String which replaces searchString
occurences - must be a "g" if all occurences of searchString shall be replaced
Returns:
String the substituted String

substituteContextPath

public static String substituteContextPath(String htmlContent,
                                           String context)
Substitutes the OpenCms context path (e.g. /opencms/opencms/) in a HTML page with a special variable so that the content also runs if the context path of the server changes.

Parameters:
htmlContent - the HTML to replace the context path in
Returns:
the HTML with the replaced context path

escapePattern

public static String escapePattern(String source)
Escapes a String so it may be used as a Perl5 regular expression.

This method replaces the following characters in a String:
{}[]()\$^.*+/

Parameters:
source - the string to escape
Returns:
the escaped string