com.opencms.util
Class Utils

java.lang.Object
  |
  +--com.opencms.util.Utils

public class Utils
extends Object

This is a general helper class.

Author:
Andreas Schouten, Alexander Lucas

Field Summary
static int C_SORT_LASTMODIFIED_DOWN
          Constant for sorting files downward by lastmodified date
static int C_SORT_LASTMODIFIED_UP
          Constant for sorting files upward by lastmodified date
static int C_SORT_NAME_DOWN
          Constant for sorting files downward by name
static int C_SORT_NAME_UP
          Constant for sorting files upward by name
 
Constructor Summary
Utils()
           
 
Method Summary
static void bubblesort(Vector names, Vector data)
          Sorts two vectors using bubblesort.
static String getFullName(CmsUser user)
          Returns a string representation of the full name of a user.
static void getModulPublishMethods(CmsObject cms, Vector changedLinks)
           
static void getModulShutdownMethods(I_CmsRegistry reg)
          Calls the startup methode on all module classes that are registerd in the registry.
static void getModulStartUpMethods(CmsObject cms)
          Calls the startup methode on all module classes that are registerd in the registry.
static String getNiceDate(long time)
          Gets a formated time string form a long time value.
static String getNiceShortDate(long time)
          Gets a formated time string form a long time value.
static String getStackTrace(Throwable e)
          Gets the stack-trace of a exception, and returns it as a string.
static boolean isHttpsResource(CmsObject cms, CmsResource res)
          Checks if a resource needs the https scheme.
static String mergeAbsolutePath(String basePath, String relativePath)
          Returns the AbsolutePath of an resource based on the base and the relative Path to the resource.
static String removeLineBreaks(String s)
          Replaces all line breaks in a given string object by white spaces.
static String replace(String toReplace, String replaceKey, String replaceWith)
          This method replaces all occurences of the replaceKey in the toReplace string with the replaceWith String.
static Vector sort(Vector unsortedFiles, int sorting)
          Deprecated. this method is deprecated and will be removed in a later OpenCms release
static String[] split(String toSplit, String at)
          This method splits a overgiven string into substrings.
static long splitDate(String dateString)
          Converts date string to a long value.
static void validateNewPassword(CmsObject cms, String password, String oldPassword)
          This method checks if a new password sticks to the rules for new passwords (i.e. a new password must have at least 4 characters).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

C_SORT_NAME_UP

public static final int C_SORT_NAME_UP
Constant for sorting files upward by name

See Also:
Constant Field Values

C_SORT_NAME_DOWN

public static final int C_SORT_NAME_DOWN
Constant for sorting files downward by name

See Also:
Constant Field Values

C_SORT_LASTMODIFIED_UP

public static final int C_SORT_LASTMODIFIED_UP
Constant for sorting files upward by lastmodified date

See Also:
Constant Field Values

C_SORT_LASTMODIFIED_DOWN

public static final int C_SORT_LASTMODIFIED_DOWN
Constant for sorting files downward by lastmodified date

See Also:
Constant Field Values
Constructor Detail

Utils

public Utils()
Method Detail

mergeAbsolutePath

public static String mergeAbsolutePath(String basePath,
                                       String relativePath)
Returns the AbsolutePath of an resource based on the base and the relative Path to the resource. There are three cases for the relative path: case 1: a / at the beginning of the relPath -> return the relPath case 2: one or more ../ at the beginning! of the relPath -> return the absolute path to the resource case 3: ./ or something else at the beginning -> return base + relpath (without the ./ of course)

Parameters:
basePath - The folder where the relativePath starts (or the absolute path of a file (no folder) in this path)
relativePath - The relative path to a reaource.

getFullName

public static String getFullName(CmsUser user)
Returns a string representation of the full name of a user.

Parameters:
user - The user to get the full name from
Returns:
a string representation of the user fullname.

getNiceDate

public static String getNiceDate(long time)
Gets a formated time string form a long time value.

Parameters:
time - The time value as a long.
Returns:
Formated time string.

getNiceShortDate

public static String getNiceShortDate(long time)
Gets a formated time string form a long time value.

Parameters:
time - The time value as a long.
Returns:
Formated time string.

getModulPublishMethods

public static void getModulPublishMethods(CmsObject cms,
                                          Vector changedLinks)
                                   throws CmsException
Parameters:
changedLinks - A vector of STrings with the links that have changed during the publishing.
CmsException

getModulStartUpMethods

public static void getModulStartUpMethods(CmsObject cms)
                                   throws CmsException
Calls the startup methode on all module classes that are registerd in the registry.

CmsException

getModulShutdownMethods

public static void getModulShutdownMethods(I_CmsRegistry reg)
                                    throws CmsException
Calls the startup methode on all module classes that are registerd in the registry.

CmsException

getStackTrace

public static String getStackTrace(Throwable e)
Gets the stack-trace of a exception, and returns it as a string.

Parameters:
e - The exception to get the stackTrace from.
Returns:
the stackTrace of the exception.

removeLineBreaks

public static String removeLineBreaks(String s)
                               throws CmsException
Replaces all line breaks in a given string object by white spaces. All lines will be trimed to delete all unnecessary white spaces.

Parameters:
s - Input string
Returns:
Output String
Throws:
CmsException

isHttpsResource

public static boolean isHttpsResource(CmsObject cms,
                                      CmsResource res)
                               throws CmsException
Checks if a resource needs the https scheme. Thats the case if the resource itself or a parent folder has the property 'export' set to 'https'.

Parameters:
cms - The cms Object, used for reading the parent folder and the properties.
res - The resource to be checked.
Throws:
CmsException.
CmsException

sort

public static Vector sort(Vector unsortedFiles,
                          int sorting)
Deprecated. this method is deprecated and will be removed in a later OpenCms release

Sorts a Vector of CmsFile objects according to an included sorting method.

Parameters:
unsortedFiles - Vector containing a list of unsorted files
sorting - The sorting method to be used.
Returns:
Vector of sorted CmsFile objects

split

public static final String[] split(String toSplit,
                                   String at)
This method splits a overgiven string into substrings.

Parameters:
toSplit - the String to split.
at - the delimeter.
Returns:
an Array of Strings.

replace

public static final String replace(String toReplace,
                                   String replaceKey,
                                   String replaceWith)
This method replaces all occurences of the replaceKey in the toReplace string with the replaceWith String.

Parameters:
toReplace - the String to replace something in.
replaceKey - the String that will be replaced.
replaceWith - The string that is inserted in the place marked with the replaceKey.
Returns:
String.

splitDate

public static long splitDate(String dateString)
Converts date string to a long value.

Parameters:
dateString - The date as a string.
Returns:
long value of date.

bubblesort

public static void bubblesort(Vector names,
                              Vector data)
Sorts two vectors using bubblesort. This is a quick hack to display templates sorted by title instead of by name in the template dropdown, because it is the title that is shown in the dropdown. Creation date: (10/24/00 13:55:12)

Parameters:
names - The vector to sort
data - Vector with data that accompanies names.

validateNewPassword

public static void validateNewPassword(CmsObject cms,
                                       String password,
                                       String oldPassword)
                                throws CmsException
This method checks if a new password sticks to the rules for new passwords (i.e. a new password must have at least 4 characters). For this purpose a class defined in the opencms.properties is called. If this class throws no exception the password is ok. The default class only checks for the min 4 characters rule.

Parameters:
cms - The CmsObject.
password - The new password that has to be checked.
oldPassword - The old password or null if not needed.
Throws:
CmsException - is thrown if the password is not valid.