code: public static String replaceServerUri(String link, String server) {
  
          String serverUriStr = server;
  
          if (CmsStringUtil.isEmptyOrWhitespaceOnly(serverUriStr)) {
              return link;
          }
          try {
              URI serverUri = new URI(serverUriStr);
              URI linkUri = new URI(link);
              URI result = new URI(
                  serverUri.getScheme(),
                  serverUri.getAuthority(),
                  linkUri.getPath(),
                  linkUri.getQuery(),
                  linkUri.getFragment());
              return result.toString();
          } catch (URISyntaxException e) {
              LOG.error(e.getLocalizedMessage(), e);
              return link;
          }
  
      }
docs: Replaces the protocol/host/port of a link with the ones from the given server URI, if it's not empty.<p>
  
  @param link the link to change
  @param server the server URI string
  
  @return the changed link