public class CmsResourceTranslator extends java.lang.Object
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>
Constructor and Description |
---|
CmsResourceTranslator(java.lang.String[] translations,
boolean continueMatching)
Constructor for the CmsResourceTranslator.
|
Modifier and Type | Method and Description |
---|---|
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
opencms-vfs.xml . |
public CmsResourceTranslator(java.lang.String[] translations, boolean continueMatching)
translations
- The array of translations read from the
opencms,propertiescontinueMatching
- if true
, matching will continue after
the first match was foundpublic java.lang.String[] getTranslations()
public java.lang.String translateResource(java.lang.String resourceName)
opencms-vfs.xml
. If no match is found,
the resource name is returned unchanged.resourceName
- The resource name to translate