code: public static Resource ensurePageIfNotContainingPage(ResourceResolver resolver, String pagePath,
        String resourceType, ConfigurationManagementSettings configurationManagementSettings) {
      Matcher matcher = PAGE_PATH_PATTERN.matcher(pagePath);
      if (matcher.matches()) {
        // ensure that shorted path part that ends with /jcr:content is created as AEM page (if not existent already)
        String detectedPagePath = matcher.group(1);
        ensurePage(resolver, detectedPagePath, null, resourceType, null, configurationManagementSettings);
        return getOrCreateResource(resolver, pagePath, DEFAULT_FOLDER_NODE_TYPE_IN_PAGE, null, configurationManagementSettings);
      }
      return ensurePage(resolver, pagePath, null, resourceType, null, configurationManagementSettings);
    }
docs: Ensure that a page at the given path exists, if the path is not already contained in a page.
  @param resolver Resource resolver
  @param pagePath Page path
  @param resourceType Resource type for page (if not template is set)
  @param configurationManagementSettings Configuration management settings
  @return Resource for AEM page or resource inside a page.