org.opencms.loader
Class CmsDefaultFileNameGenerator

java.lang.Object
  extended by org.opencms.loader.CmsDefaultFileNameGenerator
All Implemented Interfaces:
I_CmsFileNameGenerator

public class CmsDefaultFileNameGenerator
extends Object
implements I_CmsFileNameGenerator

The default class used for generating file names either for the urlName mapping or when using a "new" operation in the context of the direct edit interface.

Since:
8.0.0

Nested Class Summary
 class CmsDefaultFileNameGenerator.CmsNumberFactory
          Factory to use for resolving the %(number) macro.
 
Field Summary
 
Fields inherited from interface org.opencms.loader.I_CmsFileNameGenerator
MACRO_NUMBER, NUMBER_FORMAT
 
Constructor Summary
CmsDefaultFileNameGenerator()
           
 
Method Summary
 String getNewFileName(CmsObject cms, String namePattern, int defaultDigits)
          Returns a new resource name based on the provided OpenCms user context and name pattern.
protected  String getNewFileNameFromList(List<String> fileNames, String checkPattern, int defaultDigits)
          Internal method for file name generation, decoupled for testing.
 String getUniqueFileName(CmsObject cms, String parentFolder, String baseName)
          Returns a unique filename for the given base name and the parent folder.
 Iterator<String> getUrlNameSequence(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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsDefaultFileNameGenerator

public CmsDefaultFileNameGenerator()
Method Detail

getNewFileName

public String getNewFileName(CmsObject cms,
                             String namePattern,
                             int defaultDigits)
                      throws CmsException
Returns a new resource name based on the provided OpenCms user context and name pattern.

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.

Specified by:
getNewFileName in interface I_CmsFileNameGenerator
Parameters:
cms - the current OpenCms user context
namePattern - the pattern to be used when generating the new resource name
defaultDigits - the default number of digits to use for numbering the created file names
Returns:
a new resource name based on the provided OpenCms user context and name pattern
Throws:
CmsException - in case something goes wrong

getUniqueFileName

public String getUniqueFileName(CmsObject cms,
                                String parentFolder,
                                String baseName)
Description copied from interface: I_CmsFileNameGenerator
Returns a unique filename for the given base name and the parent folder.

Specified by:
getUniqueFileName in interface I_CmsFileNameGenerator
Parameters:
cms - the current OpenCms user context
parentFolder - the parent folder of the file
baseName - the proposed file name
Returns:
the unique file name
See Also:
I_CmsFileNameGenerator.getUniqueFileName(org.opencms.file.CmsObject, java.lang.String, java.lang.String)

getUrlNameSequence

public Iterator<String> getUrlNameSequence(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.

Specified by:
getUrlNameSequence in interface I_CmsFileNameGenerator
Parameters:
baseName - the base name
Returns:
the sequence of URL name candidates
See Also:
I_CmsFileNameGenerator.getUrlNameSequence(java.lang.String)

getNewFileNameFromList

protected String getNewFileNameFromList(List<String> fileNames,
                                        String checkPattern,
                                        int defaultDigits)
Internal method for file name generation, decoupled for testing.

Parameters:
fileNames - the list of file names already existing in the folder
checkPattern - the pattern to be used when generating the new resource name
defaultDigits - the default number of digits to use for numbering the created file names
Returns:
a new resource name based on the provided OpenCms user context and name pattern