code: public String getNewFileName(CmsObject cms, String namePattern, int defaultDigits, boolean explorerMode)
      throws CmsException {
  
          String checkPattern = cms.getRequestContext().removeSiteRoot(namePattern);
          String folderName = CmsResource.getFolderPath(checkPattern);
  
          // must check ALL resources in folder because name doesn't care for type
          List<CmsResource> resources = cms.readResources(folderName, CmsResourceFilter.ALL, false);
  
          // now create a list of all the file names
          List<String> fileNames = new ArrayList<String>(resources.size());
          for (CmsResource res : resources) {
              fileNames.add(cms.getSitePath(res));
          }
  
          return getNewFileNameFromList(fileNames, checkPattern, defaultDigits, explorerMode);
      }
docs: Returns a new resource name based on the provided OpenCms user context and name pattern.<p>
  
  The pattern in this default implementation must be a path which may contain the macro <code>%(number)</code>.
  This will be replaced by the first "n" digit sequence for which the resulting file name is not already
  used. For example the pattern <code>"/file_%(number).xml"</code> would result in something like <code>"/file_00003.xml"</code>.<p>
  
  Alternatively, the macro can have the form <code>%(number:n)</code> with <code>n = {1...9}</code>, for example <code>%(number:6)</code>.
  In this case the default digits will be ignored and instead the digits provided as "n" will be used.<p>
  
  @param cms the current OpenCms user context
  @param namePattern the  pattern to be used when generating the new resource name
  @param defaultDigits the default number of digits to use for numbering the created file names
  @param 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
  
  @return a new resource name based on the provided OpenCms user context and name pattern
  
  @throws CmsException in case something goes wrong