code: public static Resource getOrCreateChild(Resource resource, String relPath, String primaryTypes)
              throws RepositoryException {
          Resource child = null;
          if (resource != null) {
              ResourceResolver resolver = resource.getResourceResolver();
              String path = resource.getPath();
              while (relPath.startsWith("/")) {
                  relPath = relPath.substring(1);
              }
              if (StringUtils.isNotBlank(relPath)) {
                  path += "/" + relPath;
              }
              child = getOrCreateResource(resolver, path, primaryTypes);
          }
          return child;
      }
docs: Retrieves the resources child resource, creates this child if not existing.
  
  @param resource     the resource to extend
  @param relPath      the path to the requested child resource
  @param primaryTypes the 'path' of primary types for the new nodes (optional, can be 'null')
  @return the requested child