public class CmsDefaultFileNameGenerator extends java.lang.Object implements I_CmsFileNameGenerator
urlName
mapping
or when using a "new" operation in the context of the direct edit interface.Modifier and Type | Class and Description |
---|---|
class |
CmsDefaultFileNameGenerator.CmsNumberFactory
Factory to use for resolving the %(number) macro.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
COPY_FILE_NAME_INSERT
The copy file name insert.
|
MACRO_NUMBER, NUMBER_FORMAT
Constructor and Description |
---|
CmsDefaultFileNameGenerator() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getCopyFileName(CmsObject cms,
java.lang.String parentFolder,
java.lang.String baseName)
Returns a unique copy filename for the given base name and the parent folder.
|
java.lang.String |
getNewFileName(CmsObject cms,
java.lang.String namePattern,
int defaultDigits)
Generates a new file name based on the provided OpenCms user context and name pattern.
|
java.lang.String |
getNewFileName(CmsObject cms,
java.lang.String namePattern,
int defaultDigits,
boolean explorerMode)
Returns a new resource name based on the provided OpenCms user context and name pattern.
|
protected java.lang.String |
getNewFileNameFromList(java.util.List<java.lang.String> fileNames,
java.lang.String checkPattern,
int defaultDigits,
boolean explorerMode)
Internal method for file name generation, decoupled for testing.
|
java.lang.String |
getUniqueFileName(CmsObject cms,
java.lang.String parentFolder,
java.lang.String baseName)
Returns a unique filename for the given base name and the parent folder.
|
java.util.Iterator<java.lang.String> |
getUrlNameSequence(java.lang.String baseName)
This default implementation will just generate a 5 digit sequence that is appended to the resource name in case
of a collision of names.
|
static boolean |
hasNumberMacro(java.lang.String pattern)
Checks the given pattern for the number macro.
|
static java.lang.String |
removeExtension(java.lang.String path)
Removes the file extension if it only consists of letters.
|
public static final java.lang.String COPY_FILE_NAME_INSERT
public CmsDefaultFileNameGenerator()
public static boolean hasNumberMacro(java.lang.String pattern)
pattern
- the pattern to checktrue
if the pattern contains the macropublic static java.lang.String removeExtension(java.lang.String path)
path
- the path from which to remove the file extensionpublic java.lang.String getCopyFileName(CmsObject cms, java.lang.String parentFolder, java.lang.String baseName)
I_CmsFileNameGenerator
For example from the given baseName 'test.txt' the copy file name 'test_copy.txt' will be generated.
getCopyFileName
in interface I_CmsFileNameGenerator
cms
- the current OpenCms user contextparentFolder
- the parent folder of the filebaseName
- the base file nameI_CmsFileNameGenerator.getCopyFileName(org.opencms.file.CmsObject, java.lang.String, java.lang.String)
public java.lang.String getNewFileName(CmsObject cms, java.lang.String namePattern, int defaultDigits) throws CmsException
I_CmsFileNameGenerator
Used by the collector API as well as the galleries introduced with OpenCms 8 (ADE).
getNewFileName
in interface I_CmsFileNameGenerator
cms
- the current OpenCms user contextnamePattern
- the pattern to be used when generating the new resource namedefaultDigits
- the default number of digits to use for numbering the created file namesCmsException
- in case something goes wrongI_CmsFileNameGenerator.getNewFileName(org.opencms.file.CmsObject, java.lang.String, int)
public java.lang.String getNewFileName(CmsObject cms, java.lang.String namePattern, int defaultDigits, boolean explorerMode) throws CmsException
The pattern in this default implementation must be a path which may contain the macro %(number)
.
This will be replaced by the first "n" digit sequence for which the resulting file name is not already
used. For example the pattern "/file_%(number).xml"
would result in something like "/file_00003.xml"
.
Alternatively, the macro can have the form %(number:n)
with n = {1...9}
, for example %(number:6)
.
In this case the default digits will be ignored and instead the digits provided as "n" will be used.
getNewFileName
in interface I_CmsFileNameGenerator
cms
- the current OpenCms user contextnamePattern
- the pattern to be used when generating the new resource namedefaultDigits
- the default number of digits to use for numbering the created file namesexplorerMode
- if true, the file name is first tried without a numeric macro, also underscores are inserted automatically before the number macro and don't need to be part of the name patternCmsException
- in case something goes wrongpublic java.lang.String getUniqueFileName(CmsObject cms, java.lang.String parentFolder, java.lang.String baseName)
I_CmsFileNameGenerator
getUniqueFileName
in interface I_CmsFileNameGenerator
cms
- the current OpenCms user contextparentFolder
- the parent folder of the filebaseName
- the proposed file nameI_CmsFileNameGenerator.getUniqueFileName(org.opencms.file.CmsObject, java.lang.String, java.lang.String)
public java.util.Iterator<java.lang.String> getUrlNameSequence(java.lang.String baseName)
getUrlNameSequence
in interface I_CmsFileNameGenerator
baseName
- the base nameI_CmsFileNameGenerator.getUrlNameSequence(java.lang.String)
protected java.lang.String getNewFileNameFromList(java.util.List<java.lang.String> fileNames, java.lang.String checkPattern, int defaultDigits, boolean explorerMode)
fileNames
- the list of file names already existing in the foldercheckPattern
- the pattern to be used when generating the new resource namedefaultDigits
- the default number of digits to use for numbering the created file namesexplorerMode
- if true, first the file name without a number is tried, and also an underscore is automatically inserted before the number macro