code: public String getPermalink(CmsObject cms, String resourceName, CmsUUID detailContentId) {
  
          String permalink = "";
          try {
              permalink = substituteLink(cms, CmsPermalinkResourceHandler.PERMALINK_HANDLER);
              String id = cms.readResource(resourceName, CmsResourceFilter.ALL).getStructureId().toString();
              permalink += id;
              if (detailContentId != null) {
                  permalink += ":" + detailContentId;
              }
              String ext = CmsFileUtil.getExtension(resourceName);
              if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(ext)) {
                  permalink += ext;
              }
              CmsSite currentSite = OpenCms.getSiteManager().getCurrentSite(cms);
              String serverPrefix = null;
              if (currentSite == OpenCms.getSiteManager().getDefaultSite()) {
                  Optional<CmsSite> siteForDefaultUri = OpenCms.getSiteManager().getSiteForDefaultUri();
                  if (siteForDefaultUri.isPresent()) {
                      serverPrefix = siteForDefaultUri.get().getServerPrefix(cms, resourceName);
                  } else {
                      serverPrefix = OpenCms.getSiteManager().getWorkplaceServer();
                  }
              } else {
                  serverPrefix = currentSite.getServerPrefix(cms, resourceName);
              }
  
              if (!permalink.startsWith(serverPrefix)) {
                  permalink = serverPrefix + permalink;
              }
          } catch (CmsException e) {
              // if something wrong
              permalink = e.getLocalizedMessage();
              if (LOG.isErrorEnabled()) {
                  LOG.error(e.getLocalizedMessage(), e);
              }
          }
          return permalink;
      }
docs: Returns the perma link for the given resource and optional detail content.<p<
  
  @param cms the CMS context to use
  @param resourceName the page to generate the perma link for
  @param detailContentId the structure id of the detail content (may be null)
  
  @return the perma link