Class CmsDefaultFileNameGenerator

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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 userCms, 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.Set<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.
      void setAdminCms​(CmsObject cms)
      Initializes this instance with an admin CMS context.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • hasNumberMacro

        public static boolean hasNumberMacro​(java.lang.String pattern)
        Checks the given pattern for the number macro.

        Parameters:
        pattern - the pattern to check
        Returns:
        true if the pattern contains the macro
      • removeExtension

        public static java.lang.String removeExtension​(java.lang.String path)
        Removes the file extension if it only consists of letters.

        Parameters:
        path - the path from which to remove the file extension
        Returns:
        the path without the file extension
      • getNewFileName

        public java.lang.String getNewFileName​(CmsObject userCms,
                                               java.lang.String namePattern,
                                               int defaultDigits,
                                               boolean explorerMode)
                                        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
        explorerMode - 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 pattern
        Returns:
        a new resource name based on the provided OpenCms user context and name pattern
        Throws:
        CmsException - in case something goes wrong
      • getNewFileNameFromList

        protected java.lang.String getNewFileNameFromList​(java.util.Set<java.lang.String> fileNames,
                                                          java.lang.String checkPattern,
                                                          int defaultDigits,
                                                          boolean explorerMode)
        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
        explorerMode - if true, first the file name without a number is tried, and also an underscore is automatically inserted before the number macro
        Returns:
        a new resource name based on the provided OpenCms user context and name pattern