org.opencms.util
Class CmsResourceTranslator

java.lang.Object
  extended by org.opencms.util.CmsResourceTranslator

public class CmsResourceTranslator
extends java.lang.Object

This class provides a resource name translation facility.

Resource name translation is required for backward compatibility to the old OpenCms (pre 5.0 beta 2) directory layout. It can also be used to translate special characters or names automatically.

It is also used for translating new resource names that contain illegal chars to legal names. This feature is most useful (and currently only used) for uploaded files. It is also applied to uploded ZIP directories that are extracted after upload.

The translations can be configured in the opencms.properties.

The default directory translation setting is:

 directory.translation.rules=s#/default/vfs/content/bodys/(.*)#/default/vfs/system/bodies/$1#, \ 
 s#/default/vfs/pics/system/(.*)#/default/vfs/system/workplace/resources/$1#, \ 
 s#/default/vfs/pics/(.*)#/default/vfs/system/galleries/pics/$1#, \ 
 s#/default/vfs/download/(.*)#/default/vfs/system/galleries/download/$1#, \ 
 s#/default/vfs/externallinks/(.*)#/default/vfs/system/galleries/externallinks/$1#, \ 
 s#/default/vfs/htmlgalleries/(.*)#/default/vfs/system/galleries/htmlgalleries/$1#, \ 
 s#/default/vfs/content/(.*)#/default/vfs/system/modules/default/$1#, \ 
 s#/default/vfs/moduledemos/(.*)#/default/vfs/system/moduledemos/$1#, \ 
 s#/default/vfs/system/workplace/config/language/(.*)#/default/vfs/system/workplace/locales/$1#, \ 
 s#/default/vfs/system/workplace/css/(.*)#/default/vfs/system/workplace/resources/$1#, \
 s#/default/vfs/system/workplace/templates/js/(.*)#/default/vfs/system/workplace/scripts/$1#
 

The default file name translation setting is:

 filename.translation.rules=s#[\s]+#_#g, \
 s#\\#/#g, \
 s#[^0-9a-zA-Z_\.\-\/]#!#g, \
 s#!+#x#g
 

Since:
6.0.0
Version:
$Revision: 1.23 $
Author:
Alexander Kandzior

Constructor Summary
CmsResourceTranslator(java.lang.String[] translations, boolean continueMatching)
          Constructor for the CmsResourceTranslator.
 
Method Summary
 java.lang.String[] getTranslations()
          Returns a copy of the initialized translation rules.
 java.lang.String translateResource(java.lang.String resourceName)
          Translate a resource name according to the expressions set in the opencms.properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsResourceTranslator

public CmsResourceTranslator(java.lang.String[] translations,
                             boolean continueMatching)
Constructor for the CmsResourceTranslator.

Parameters:
translations - The array of translations read from the opencms,properties
continueMatching - if true, matching will continue after the first match was found
Method Detail

getTranslations

public java.lang.String[] getTranslations()
Returns a copy of the initialized translation rules.

Returns:
String[] a copy of the initialized translation rules

translateResource

public java.lang.String translateResource(java.lang.String resourceName)
Translate a resource name according to the expressions set in the opencms.properties. If no match is found, the resource name is returned unchanged.

Parameters:
resourceName - The resource name to translate
Returns:
The translated name of the resource