Class CmsResourceTranslator
This facility is used for translating new file 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 rules that are used for resource name translation are available from
CmsRequestContext.getFileTranslator()
.
Optionally, resource name translation is also applied to all files read
from the VFS, so it can be used for accessing files out of teir usual context.
This feature is called directoy translation, and the configured directory
translations are available from CmsRequestContext.getDirectoryTranslator()
.
Directory translation was originally required for backward compatibility to the directory layout before OpenCms 5.0 beta 2. In a modern installation, directory translation is usually disabled.
The translations can be configured in opencms-vfs.xml
in the opencms\vfs\resources\translations
node.
The default file name translation setting is:
<filetranslations enabled="true"> <translation>s#[\s]+#_#g</translation> <translation>s#\\#/#g</translation> <translation>s#ä#ae#g</translation> <translation>s#Ä#Ae#g</translation> <translation>s#ö#oe#g</translation> <translation>s#Ö#Oe#g</translation> <translation>s#ü#ue#g</translation> <translation>s#Ü#Ue#g</translation> <translation>s#ß#ss#g</translation> <translation>s#[^0-9a-zA-Z_$~\.\-\/]#!#g</translation> <translation>s#!+#x#g</translation> </filetranslations>
Directory translation is now usually not required and since disabled by default.
The directory translation setting to convert an OpenCms 5.0 to 6.0 VFS is:
<foldertranslations enabled="true"> <translation>s#/content/bodys/(.*)#/system/bodies/$1#</translation> <translation>s#/pics/system/(.*)#/system/workplace/resources/$1#</translation> <translation>s#/pics/(.*)#/system/galleries/pics/$1#</translation> <translation>s#/download/(.*)#/system/galleries/download/$1#</translation> <translation>s#/externallinks/(.*)#/system/galleries/externallinks/$1#</translation> <translation>s#/htmlgalleries/(.*)#/system/galleries/htmlgalleries/$1#</translation> <translation>s#/content/(.*)#/system/$1#</translation> </foldertranslations>
- Since:
- 6.0.0
-
Constructor Summary
ConstructorDescriptionCmsResourceTranslator
(String[] translations, boolean continueMatching) Constructor for the CmsResourceTranslator. -
Method Summary
Modifier and TypeMethodDescriptionString[]
Returns a copy of the initialized translation rules.translateResource
(String resourceName) Translate a resource name according to the expressions set inopencms-vfs.xml
.
-
Constructor Details
-
CmsResourceTranslator
Constructor for the CmsResourceTranslator.- Parameters:
translations
- The array of translations read from the opencms,propertiescontinueMatching
- iftrue
, matching will continue after the first match was found
-
-
Method Details
-
getTranslations
Returns a copy of the initialized translation rules.- Returns:
- String[] a copy of the initialized translation rules
-
translateResource
Translate a resource name according to the expressions set inopencms-vfs.xml
. 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
-