Class ContentLoader

java.lang.Object
org.apache.sling.testing.mock.sling.loader.ContentLoader

public final class ContentLoader extends Object
Imports JSON data and binary data into Sling resource hierarchy. After all import operations from json or binaries ResourceResolver.commit() is called (when autocommit mode is active).
  • Constructor Summary

    Constructors
    Constructor
    Description
    ContentLoader(@NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver)
     
    ContentLoader(@NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver, @Nullable org.osgi.framework.BundleContext bundleContext)
     
    ContentLoader(@NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver, @Nullable org.osgi.framework.BundleContext bundleContext, boolean autoCommit)
     
    ContentLoader(@NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver, @Nullable org.osgi.framework.BundleContext bundleContext, boolean autoCommit, @Nullable ResourceResolverType resourceResolverType)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull org.apache.sling.api.resource.Resource
    binaryFile(@NotNull InputStream inputStream, @NotNull String path)
    Import binary file as nt:file binary node into repository.
    @NotNull org.apache.sling.api.resource.Resource
    binaryFile(@NotNull InputStream inputStream, @NotNull String path, @NotNull String mimeType)
    Import binary file as nt:file binary node into repository.
    @NotNull org.apache.sling.api.resource.Resource
    binaryFile(@NotNull InputStream inputStream, @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull String name)
    Import binary file as nt:file binary node into repository.
    @NotNull org.apache.sling.api.resource.Resource
    binaryFile(@NotNull InputStream inputStream, @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull String name, @NotNull String mimeType)
    Import binary file as nt:file binary node into repository.
    @NotNull org.apache.sling.api.resource.Resource
    binaryFile(@NotNull String classpathResourceOrFile, @NotNull String path)
    Import binary file as nt:file binary node into repository.
    @NotNull org.apache.sling.api.resource.Resource
    binaryFile(@NotNull String classpathResourceOrFile, @NotNull String path, @NotNull String mimeType)
    Import binary file as nt:file binary node into repository.
    @NotNull org.apache.sling.api.resource.Resource
    binaryResource(@NotNull InputStream inputStream, @NotNull String path)
    Import binary file as nt:resource binary node into repository.
    @NotNull org.apache.sling.api.resource.Resource
    binaryResource(@NotNull InputStream inputStream, @NotNull String path, @NotNull String mimeType)
    Import binary file as nt:resource binary node into repository.
    @NotNull org.apache.sling.api.resource.Resource
    binaryResource(@NotNull InputStream inputStream, @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull String name)
    Import binary file as nt:resource binary node into repository.
    @NotNull org.apache.sling.api.resource.Resource
    binaryResource(@NotNull InputStream inputStream, @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull String name, @NotNull String mimeType)
    Import binary file as nt:resource binary node into repository.
    @NotNull org.apache.sling.api.resource.Resource
    binaryResource(@NotNull String classpathResourceOrFile, @NotNull String path)
    Import binary file as nt:resource binary node into repository.
    @NotNull org.apache.sling.api.resource.Resource
    binaryResource(@NotNull String classpathResourceOrFile, @NotNull String path, @NotNull String mimeType)
    Import binary file as nt:resource binary node into repository.
    @NotNull org.apache.sling.api.resource.Resource
    fileVaultXml(@NotNull InputStream inputStream, @NotNull String destPath)
    Import content of FileVault XML file into repository.
    @NotNull org.apache.sling.api.resource.Resource
    fileVaultXml(@NotNull InputStream inputStream, @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull String childName)
    Import content of FileVault XML file into repository.
    @NotNull org.apache.sling.api.resource.Resource
    fileVaultXml(@NotNull String classpathResourceOrFile, @NotNull String destPath)
    Import content of FileVault XML file into repository.
    @NotNull org.apache.sling.api.resource.Resource
    fileVaultXml(@NotNull String classpathResourceOrFile, @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull String childName)
    Import content of FileVault XML file into repository.
    void
    folderFileVaultXml(@NotNull File mountFolder, @NotNull String destPath)
    Mount a folder containing content in FileVault XML format in repository.
    void
    folderFileVaultXml(@NotNull File mountFolder, @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull String childName)
    Mount a folder containing content in FileVault XML format in repository.
    void
    folderFileVaultXml(@NotNull String mountFolderPath, @NotNull String destPath)
    Mount a folder (file system) containing content in FileVault XML format in repository.
    void
    folderFileVaultXml(@NotNull String mountFolderPath, @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull String childName)
    Mount a folder (file system) containing content in FileVault XML format in repository.
    void
    folderJson(@NotNull File mountFolder, @NotNull String destPath)
    Mount a folder containing content in JSON (Sling-Initial-Content) format in repository.
    void
    folderJson(@NotNull File mountFolder, @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull String childName)
    Mount a folder containing content in JSON (Sling-Initial-Content) format in repository.
    void
    folderJson(@NotNull String mountFolderPath, @NotNull String destPath)
    Mount a folder (file system) containing content in JSON (Sling-Initial-Content) format in repository.
    void
    folderJson(@NotNull String mountFolderPath, @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull String childName)
    Mount a folder (file system) containing content in JSON (Sling-Initial-Content) format in repository.
    @NotNull org.apache.sling.api.resource.Resource
    json(@NotNull InputStream inputStream, @NotNull String destPath)
    Import content of JSON file into repository.
    @NotNull org.apache.sling.api.resource.Resource
    json(@NotNull InputStream inputStream, @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull String childName)
    Import content of JSON file into repository.
    @NotNull org.apache.sling.api.resource.Resource
    json(@NotNull String classpathResourceOrFile, @NotNull String destPath)
    Import content of JSON file into repository.
    @NotNull org.apache.sling.api.resource.Resource
    json(@NotNull String classpathResourceOrFile, @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull String childName)
    Import content of JSON file into repository.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ContentLoader

      public ContentLoader(@NotNull @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver)
      Parameters:
      resourceResolver - Resource resolver
    • ContentLoader

      public ContentLoader(@NotNull @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver, @Nullable @Nullable org.osgi.framework.BundleContext bundleContext)
      Parameters:
      resourceResolver - Resource resolver
      bundleContext - Bundle context
    • ContentLoader

      public ContentLoader(@NotNull @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver, @Nullable @Nullable org.osgi.framework.BundleContext bundleContext, boolean autoCommit)
      Parameters:
      resourceResolver - Resource resolver
      bundleContext - Bundle context
      autoCommit - Automatically commit changes after loading content (default: true)
    • ContentLoader

      public ContentLoader(@NotNull @NotNull org.apache.sling.api.resource.ResourceResolver resourceResolver, @Nullable @Nullable org.osgi.framework.BundleContext bundleContext, boolean autoCommit, @Nullable @Nullable ResourceResolverType resourceResolverType)
      Parameters:
      resourceResolver - Resource resolver
      bundleContext - Bundle context
      autoCommit - Automatically commit changes after loading content (default: true)
      resourceResolverType - Resource resolver type.
  • Method Details

    • json

      @NotNull public @NotNull org.apache.sling.api.resource.Resource json(@NotNull @NotNull String classpathResourceOrFile, @NotNull @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull @NotNull String childName)
      Import content of JSON file into repository.
      • The imported resources support reading and writing.
      Parameters:
      classpathResourceOrFile - Classpath resource URL or file path for JSON content
      parentResource - Parent resource
      childName - Name of child resource to create with JSON content
      Returns:
      Resource
    • json

      @NotNull public @NotNull org.apache.sling.api.resource.Resource json(@NotNull @NotNull String classpathResourceOrFile, @NotNull @NotNull String destPath)
      Import content of JSON file into repository.
      • Auto-creates parent hierarchies as nt:unstrucured nodes if missing.
      • The imported resources support reading and writing.
      Parameters:
      classpathResourceOrFile - Classpath resource URL or file path for JSON content
      destPath - Path to import the JSON content to
      Returns:
      Resource
    • json

      @NotNull public @NotNull org.apache.sling.api.resource.Resource json(@NotNull @NotNull InputStream inputStream, @NotNull @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull @NotNull String childName)
      Import content of JSON file into repository.
      • The imported resources support reading and writing.
      Parameters:
      inputStream - Input stream with JSON content
      parentResource - Parent resource
      childName - Name of child resource to create with JSON content
      Returns:
      Resource
    • json

      @NotNull public @NotNull org.apache.sling.api.resource.Resource json(@NotNull @NotNull InputStream inputStream, @NotNull @NotNull String destPath)
      Import content of JSON file into repository.
      • Auto-creates parent hierarchies as nt:unstrucured nodes if missing.
      • The imported resources support reading and writing.
      Parameters:
      inputStream - Input stream with JSON content
      destPath - Path to import the JSON content to
      Returns:
      Resource
    • fileVaultXml

      @NotNull public @NotNull org.apache.sling.api.resource.Resource fileVaultXml(@NotNull @NotNull String classpathResourceOrFile, @NotNull @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull @NotNull String childName)
      Import content of FileVault XML file into repository.
      • The imported resources support reading and writing.
      Parameters:
      classpathResourceOrFile - Classpath resource URL or file path to single FileVault XML file (usually .content.xml)
      parentResource - Parent resource
      childName - Name of child resource to create with Filevault content
      Returns:
      Resource
    • fileVaultXml

      @NotNull public @NotNull org.apache.sling.api.resource.Resource fileVaultXml(@NotNull @NotNull String classpathResourceOrFile, @NotNull @NotNull String destPath)
      Import content of FileVault XML file into repository.
      • Auto-creates parent hierarchies as nt:unstrucured nodes if missing.
      • The imported resources support reading and writing.
      Parameters:
      classpathResourceOrFile - Classpath resource URL or file path to single FileVault XML file (usually .content.xml)
      destPath - Path to import the Filevault content to
      Returns:
      Resource
    • fileVaultXml

      @NotNull public @NotNull org.apache.sling.api.resource.Resource fileVaultXml(@NotNull @NotNull InputStream inputStream, @NotNull @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull @NotNull String childName)
      Import content of FileVault XML file into repository.
      • The imported resources support reading and writing.
      Parameters:
      inputStream - Input stream with Filevault content
      parentResource - Parent resource
      childName - Name of child resource to create with Filevault content
      Returns:
      Resource
    • fileVaultXml

      @NotNull public @NotNull org.apache.sling.api.resource.Resource fileVaultXml(@NotNull @NotNull InputStream inputStream, @NotNull @NotNull String destPath)
      Import content of FileVault XML file into repository.
      • Auto-creates parent hierarchies as nt:unstrucured nodes if missing.
      • The imported resources support reading and writing.
      Parameters:
      inputStream - Input stream with Filevault content
      destPath - Path to import the Filevault content to
      Returns:
      Resource
    • binaryFile

      @NotNull public @NotNull org.apache.sling.api.resource.Resource binaryFile(@NotNull @NotNull String classpathResourceOrFile, @NotNull @NotNull String path)
      Import binary file as nt:file binary node into repository.
      • Auto-creates parent hierarchies as nt:unstrucured nodes if missing.
      • Mime type is auto-detected from either classpathResourceOrFile or path.
      • The imported resources support reading and writing.
      Parameters:
      classpathResourceOrFile - Classpath resource URL or file path for binary file.
      path - Path to mount binary data to (parent nodes created automatically)
      Returns:
      Resource with binary data
    • binaryFile

      @NotNull public @NotNull org.apache.sling.api.resource.Resource binaryFile(@NotNull @NotNull String classpathResourceOrFile, @NotNull @NotNull String path, @NotNull @NotNull String mimeType)
      Import binary file as nt:file binary node into repository.
      • Auto-creates parent hierarchies as nt:unstrucured nodes if missing.
      • The imported resources support reading and writing.
      Parameters:
      classpathResourceOrFile - Classpath resource URL or file path for binary file.
      path - Path to mount binary data to (parent nodes created automatically)
      mimeType - Mime type of binary data
      Returns:
      Resource with binary data
    • binaryFile

      @NotNull public @NotNull org.apache.sling.api.resource.Resource binaryFile(@NotNull @NotNull InputStream inputStream, @NotNull @NotNull String path)
      Import binary file as nt:file binary node into repository.
      • Auto-creates parent hierarchies as nt:unstrucured nodes if missing.
      • Mime type is auto-detected from resource name.
      • The imported resources support reading and writing.
      Parameters:
      inputStream - Input stream for binary data
      path - Path to mount binary data to (parent nodes created automatically)
      Returns:
      Resource with binary data
    • binaryFile

      @NotNull public @NotNull org.apache.sling.api.resource.Resource binaryFile(@NotNull @NotNull InputStream inputStream, @NotNull @NotNull String path, @NotNull @NotNull String mimeType)
      Import binary file as nt:file binary node into repository.
      • Auto-creates parent hierarchies as nt:unstrucured nodes if missing.
      • The imported resources support reading and writing.
      Parameters:
      inputStream - Input stream for binary data
      path - Path to mount binary data to (parent nodes created automatically)
      mimeType - Mime type of binary data
      Returns:
      Resource with binary data
    • binaryFile

      @NotNull public @NotNull org.apache.sling.api.resource.Resource binaryFile(@NotNull @NotNull InputStream inputStream, @NotNull @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull @NotNull String name)
      Import binary file as nt:file binary node into repository.
      • Auto-creates parent hierarchies as nt:unstrucured nodes if missing.
      • Mime type is auto-detected from resource name.
      • The imported resources support reading and writing.
      Parameters:
      inputStream - Input stream for binary data
      parentResource - Parent resource
      name - Resource name for nt:file
      Returns:
      Resource with binary data
    • binaryFile

      @NotNull public @NotNull org.apache.sling.api.resource.Resource binaryFile(@NotNull @NotNull InputStream inputStream, @NotNull @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull @NotNull String name, @NotNull @NotNull String mimeType)
      Import binary file as nt:file binary node into repository.
      • Auto-creates parent hierarchies as nt:unstrucured nodes if missing.
      • The imported resources support reading and writing.
      Parameters:
      inputStream - Input stream for binary data
      parentResource - Parent resource
      name - Resource name for nt:file
      mimeType - Mime type of binary data
      Returns:
      Resource with binary data
    • binaryResource

      @NotNull public @NotNull org.apache.sling.api.resource.Resource binaryResource(@NotNull @NotNull String classpathResourceOrFile, @NotNull @NotNull String path)
      Import binary file as nt:resource binary node into repository.
      • Auto-creates parent hierarchies as nt:unstrucured nodes if missing.
      • Mime type is auto-detected from classpathResourceOrFile or path.
      • The imported resources support reading and writing.
      Parameters:
      classpathResourceOrFile - Classpath resource URL or file path for binary file.
      path - Path to mount binary data to (parent nodes created automatically)
      Returns:
      Resource with binary data
    • binaryResource

      @NotNull public @NotNull org.apache.sling.api.resource.Resource binaryResource(@NotNull @NotNull String classpathResourceOrFile, @NotNull @NotNull String path, @NotNull @NotNull String mimeType)
      Import binary file as nt:resource binary node into repository.
      • Auto-creates parent hierarchies as nt:unstrucured nodes if missing.
      • The imported resources support reading and writing.
      Parameters:
      classpathResourceOrFile - Classpath resource URL or file path for binary file.
      path - Path to mount binary data to (parent nodes created automatically)
      mimeType - Mime type of binary data
      Returns:
      Resource with binary data
    • binaryResource

      @NotNull public @NotNull org.apache.sling.api.resource.Resource binaryResource(@NotNull @NotNull InputStream inputStream, @NotNull @NotNull String path)
      Import binary file as nt:resource binary node into repository.
      • Auto-creates parent hierarchies as nt:unstrucured nodes if missing.
      • Mime type is auto-detected from resource name.
      • The imported resources support reading and writing.
      Parameters:
      inputStream - Input stream for binary data
      path - Path to mount binary data to (parent nodes created automatically)
      Returns:
      Resource with binary data
    • binaryResource

      @NotNull public @NotNull org.apache.sling.api.resource.Resource binaryResource(@NotNull @NotNull InputStream inputStream, @NotNull @NotNull String path, @NotNull @NotNull String mimeType)
      Import binary file as nt:resource binary node into repository.
      • Auto-creates parent hierarchies as nt:unstrucured nodes if missing.
      • The imported resources support reading and writing.
      Parameters:
      inputStream - Input stream for binary data
      path - Path to mount binary data to (parent nodes created automatically)
      mimeType - Mime type of binary data
      Returns:
      Resource with binary data
    • binaryResource

      @NotNull public @NotNull org.apache.sling.api.resource.Resource binaryResource(@NotNull @NotNull InputStream inputStream, @NotNull @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull @NotNull String name)
      Import binary file as nt:resource binary node into repository.
      • Auto-creates parent hierarchies as nt:unstrucured nodes if missing.
      • Mime type is auto-detected from resource name.
      • The imported resources support reading and writing.
      Parameters:
      inputStream - Input stream for binary data
      parentResource - Parent resource
      name - Resource name for nt:resource
      Returns:
      Resource with binary data
    • binaryResource

      @NotNull public @NotNull org.apache.sling.api.resource.Resource binaryResource(@NotNull @NotNull InputStream inputStream, @NotNull @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull @NotNull String name, @NotNull @NotNull String mimeType)
      Import binary file as nt:resource binary node into repository.
      • Auto-creates parent hierarchies as nt:unstrucured nodes if missing.
      • The imported resources support reading and writing.
      Parameters:
      inputStream - Input stream for binary data
      parentResource - Parent resource
      name - Resource name for nt:resource
      mimeType - Mime type of binary data
      Returns:
      Resource with binary data
    • folderJson

      public void folderJson(@NotNull @NotNull String mountFolderPath, @NotNull @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull @NotNull String childName)
      Mount a folder (file system) containing content in JSON (Sling-Initial-Content) format in repository.
      • The resources are not imported, but mounted via FS Resource Provider.
      • The mounted resource tree is read-only.
      Parameters:
      mountFolderPath - Root folder path to mount
      parentResource - Parent resource
      childName - Name of child resource to mount folder into
    • folderJson

      public void folderJson(@NotNull @NotNull String mountFolderPath, @NotNull @NotNull String destPath)
      Mount a folder (file system) containing content in JSON (Sling-Initial-Content) format in repository.
      • The resources are not imported, but mounted via FS Resource Provider.
      • The mounted resource tree is read-only.
      Parameters:
      mountFolderPath - Root folder path to mount
      destPath - Path to mount folder into
    • folderJson

      public void folderJson(@NotNull @NotNull File mountFolder, @NotNull @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull @NotNull String childName)
      Mount a folder containing content in JSON (Sling-Initial-Content) format in repository.
      • The resources are not imported, but mounted via FS Resource Provider.
      • The mounted resource tree is read-only.
      Parameters:
      mountFolder - Root folder to mount
      parentResource - Parent resource
      childName - Name of child resource to mount folder into
    • folderJson

      public void folderJson(@NotNull @NotNull File mountFolder, @NotNull @NotNull String destPath)
      Mount a folder containing content in JSON (Sling-Initial-Content) format in repository.
      • The resources are not imported, but mounted via FS Resource Provider.
      • The mounted resource tree is read-only.
      Parameters:
      mountFolder - Root folder to mount
      destPath - Path to mount folder into
    • folderFileVaultXml

      public void folderFileVaultXml(@NotNull @NotNull String mountFolderPath, @NotNull @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull @NotNull String childName)
      Mount a folder (file system) containing content in FileVault XML format in repository.
      • The resources are not imported, but mounted via FS Resource Provider.
      • The mounted resource tree is read-only.
      Parameters:
      mountFolderPath - Root folder path to mount. Path needs to point to the root folder of the content package structure.
      parentResource - Parent resource
      childName - Name of child resource of subtree path that should be mounted from FileVault XML structure
    • folderFileVaultXml

      public void folderFileVaultXml(@NotNull @NotNull String mountFolderPath, @NotNull @NotNull String destPath)
      Mount a folder (file system) containing content in FileVault XML format in repository.
      • The resources are not imported, but mounted via FS Resource Provider.
      • The mounted resource tree is read-only.
      Parameters:
      mountFolderPath - Root folder path to mount. Path needs to point to the root folder of the content package structure.
      destPath - Subtree path that should be mounted from FileVault XML structure
    • folderFileVaultXml

      public void folderFileVaultXml(@NotNull @NotNull File mountFolder, @NotNull @NotNull org.apache.sling.api.resource.Resource parentResource, @NotNull @NotNull String childName)
      Mount a folder containing content in FileVault XML format in repository.
      • The resources are not imported, but mounted via FS Resource Provider.
      • The mounted resource tree is read-only.
      Parameters:
      mountFolder - Root folder to mount. Path needs to point to the root folder of the content package structure.
      parentResource - Parent resource
      childName - Name of child resource of subtree path that should be mounted from FileVault XML structure
    • folderFileVaultXml

      public void folderFileVaultXml(@NotNull @NotNull File mountFolder, @NotNull @NotNull String destPath)
      Mount a folder containing content in FileVault XML format in repository.
      • The resources are not imported, but mounted via FS Resource Provider.
      • The mounted resource tree is read-only.
      Parameters:
      mountFolder - Root folder to mount. Path needs to point to the root folder of the content package structure.
      destPath - Subtree path that should be mounted from FileVault XML structure