code: public String readBestUrlName(CmsDbContext dbc, CmsUUID id, Locale locale, List<Locale> defaultLocales)
      throws CmsDataAccessException {
  
          List<CmsUrlNameMappingEntry> entries = getVfsDriver(dbc).readUrlNameMappingEntries(
              dbc,
              dbc.currentProject().isOnlineProject(),
              CmsUrlNameMappingFilter.ALL.filterStructureId(id));
          if (entries.isEmpty()) {
              return null;
          }
  
          ArrayListMultimap<String, CmsUrlNameMappingEntry> entriesByLocale = ArrayListMultimap.create();
          for (CmsUrlNameMappingEntry entry : entries) {
              entriesByLocale.put(entry.getLocale(), entry);
          }
          List<CmsUrlNameMappingEntry> lastEntries = new ArrayList<CmsUrlNameMappingEntry>();
          Comparator<CmsUrlNameMappingEntry> dateChangedComparator = new UrlNameMappingComparator();
          for (String localeKey : entriesByLocale.keySet()) {
              // for each locale select the latest mapping entry
              CmsUrlNameMappingEntry latestEntryForLocale = Collections.max(
                  entriesByLocale.get(localeKey),
                  dateChangedComparator);
              lastEntries.add(latestEntryForLocale);
          }
          CmsLocaleManager localeManager = OpenCms.getLocaleManager();
          List<Locale> availableLocales = new ArrayList<Locale>();
          for (CmsUrlNameMappingEntry entry : lastEntries) {
              availableLocales.add(CmsLocaleManager.getLocale(entry.getLocale()));
          }
          Locale bestLocale = localeManager.getBestMatchingLocale(locale, defaultLocales, availableLocales);
          String bestLocaleStr = bestLocale.toString();
          for (CmsUrlNameMappingEntry entry : lastEntries) {
              if (entry.getLocale().equals(bestLocaleStr)) {
                  return entry.getName();
              }
          }
          return null;
      }
docs: Selects the best url name for a given resource and locale.<p>
  
  @param dbc the database context
  @param id the resource's structure id
  @param locale the requested locale
  @param defaultLocales the default locales to use if the locale isn't available
  
  @return the URL name which was found
  
  @throws CmsDataAccessException if the database operation failed