code: private List<CmsResource> getExistingFileCollisions(CmsResource targetFolder, String targetName)
      throws CmsException {
  
          List<CmsResource> collidingResources = new ArrayList<CmsResource>();
  
          String finalTarget = targetFolder.getRootPath();
          if (!finalTarget.endsWith("/")) {
              finalTarget += "/";
          }
          if (targetName == null) {
              for (CmsResource source : m_context.getResources()) {
                  if (finalTarget.equals(CmsResource.getParentFolder(source.getRootPath()))) {
                      // copying to the same folder, a new name will be generated
                      return null;
                  }
                  String fileName = finalTarget + source.getName();
                  if (getRootCms().existsResource(fileName, CmsResourceFilter.ALL)) {
                      collidingResources.add(source);
                  }
              }
          } else {
              String fileName = finalTarget + targetName;
              if (getRootCms().existsResource(fileName, CmsResourceFilter.ALL)) {
                  collidingResources.add(getRootCms().readResource(fileName, CmsResourceFilter.ALL));
              }
          }
          return collidingResources.isEmpty() ? null : collidingResources;
      }
docs: Returns the resources that collide with already existing resources.<p>
  
  @param targetFolder the target folder
  @param targetName name of the target if a single file's copy should be named differently
  
  @return the colliding resources or <code>null</code> if no collisions found
  
  @throws CmsException in case the checking the resources fails