API: repository
Source:
platform/repository.ts
Provides a wrapper for the platform's RepositoryFacade to manage files (Resources) and folders (Collections), including CRUD operations, movement, and content handling.
Usage
import { repository } from "sdk/platform";
import { response } from "sdk/http";
let resource = repository.getResource("/registry/public/modules/src/platform/repository.ts");
response.println("Exists: " + resource.exists());
response.flush();
response.close();Classes
Repository
@class Repository
@description Static utility class providing high-level methods for interacting with the
repository facade to manage resources and collections by path.
Methods
getResource
getResource (path:string):ResourceRetrieves a resource (file) object from the repository by its path.
@param {string} path The absolute path to the resource.
@returns {Resource} A Resource instance wrapping the native repository object.
createResource
createResource (path:string, content:string, contentType:string):ResourceCreates a new resource (file) with content provided as a string.
@param {string} path The absolute path where the resource should be created.
@param {string} content The string content for the resource.
@param {string} contentType The MIME type of the content (e.g., "text/plain").
@returns {Resource} The newly created Resource instance.
createResourceNative
createResourceNative (path:string, content:any[], contentType:string):ResourceCreates a new resource (file) with content provided as a native byte array.
@param {string} path The absolute path where the resource should be created.
@param {any[]} content The native byte array content.
@param {string} contentType The MIME type of the content.
@returns {Resource} The newly created Resource instance.
updateResource
updateResource (path:string, content:string):ResourceUpdates the content of an existing resource using a string.
@param {string} path The absolute path to the resource to update.
@param {string} content The new string content.
@returns {Resource} The updated Resource instance.
updateResourceNative
updateResourceNative (path:string, content:any[]):ResourceUpdates the content of an existing resource using a native byte array.
@param {string} path The absolute path to the resource to update.
@param {any[]} content The new native byte array content.
@returns {Resource} The updated Resource instance.
deleteResource
deleteResource (path:string):voidDeletes the resource (file) at the specified path.
@param {string} path The absolute path of the resource to delete.
getCollection
getCollection (path:string):CollectionRetrieves a collection (folder) object from the repository by its path.
@param {string} path The absolute path to the collection.
@returns {Collection} A Collection instance wrapping the native repository object.
createCollection
createCollection (path:string):CollectionCreates a new collection (folder) at the specified path.
@param {string} path The absolute path where the collection should be created.
@returns {Collection} The newly created Collection instance.
deleteCollection
deleteCollection (path:string):voidDeletes the collection (folder) at the specified path.
@param {string} path The absolute path of the collection to delete.
find
find (path:string, pattern:string):string[]Searches the repository starting from a given path for resources matching a glob pattern.
@param {string} path The starting path for the search.
@param {string} pattern The glob pattern to match resource names against (e.g., "*.js").
@returns {string[]} An array of repository paths (strings) that match the search criteria.
Resource
@class Resource
@description Represents a file or resource (non-collection) within the Repository,
providing instance methods for file operations.
Methods
getName
getName ():stringGets the name of the resource (file name).
@returns {string} The name.
getPath
getPath ():stringGets the full repository path of the resource.
@returns {string} The repository path.
getParent
getParent ():CollectionGets the parent collection (folder) of this resource.
@returns {Collection} The parent Collection instance.
getInformation
getInformation ():EntityInformationGets detailed metadata about the resource.
@returns {EntityInformation} The metadata object.
create
create ():voidCreates the resource if it does not already exist.
delete
delete ():voidDeletes the resource from the repository.
renameTo
renameTo (name:string):voidRenames the resource within its current collection.
@param {string} name The new name for the resource.
moveTo
moveTo (path:string):voidMoves the resource to a new path.
@param {string} path The new absolute path for the resource.
copyTo
copyTo (path:string):voidCopies the resource to a new path.
@param {string} path The new absolute path for the copied resource.
exists
exists ():booleanChecks if the resource currently exists in the repository.
@returns {boolean} True if the resource exists, false otherwise.
isEmpty
isEmpty ():booleanChecks if the resource (file) is empty (has zero size).
@returns {boolean} True if the content is empty, false otherwise.
getText
getText ():stringGets the content of the resource as a text string.
@returns {string} The text content.
getContent
getContent ():any[]Gets the content of the resource as a JavaScript-friendly byte array.
@returns {any[]} The content bytes.
getContentNative
getContentNative ():any[]Gets the content of the resource as its native Java byte array representation.
@returns {any[]} The content bytes.
setText
setText (text:string):voidSets the content of the resource using a text string.
The string is converted to a byte array before saving.
@param {string} text The new text content.
setContent
setContent (content:any[]):voidSets the content of the resource using a JavaScript byte array.
The array is converted to a native byte array before saving.
@param {any[]} content The new content bytes.
setContentNative
setContentNative (content:any[]):voidSets the content of the resource using a native Java byte array.
@param {any[]} content The new native content bytes.
isBinary
isBinary ():booleanChecks if the resource content is determined to be binary.
@returns {boolean} True if binary, false if text.
getContentType
getContentType ():stringGets the content type (MIME type) of the resource.
@returns {string} The content type string.
Collection
@class Collection
@description Represents a directory or folder within the Repository, providing
instance methods for collection and resource management.
Methods
getName
getName ():stringGets the name of the collection (folder name).
@returns {string} The name.
getPath
getPath ():stringGets the full repository path of the collection.
@returns {string} The repository path.
getParent
getParent ():CollectionGets the parent collection (folder) of this collection.
@returns {Collection} The parent Collection instance.
getInformation
getInformation ():EntityInformationGets detailed metadata about the collection.
@returns {EntityInformation} The metadata object.
create
create ():voidCreates the collection if it does not already exist.
delete
delete ():voidDeletes the collection from the repository.
renameTo
renameTo (name:string):voidRenames the collection within its current parent.
@param {string} name The new name for the collection.
moveTo
moveTo (path:string):voidMoves the collection to a new path.
@param {string} path The new absolute path for the collection.
copyTo
copyTo (path:string):voidCopies the collection to a new path.
@param {string} path The new absolute path for the copied collection.
exists
exists ():booleanChecks if the collection currently exists in the repository.
@returns {boolean} True if the collection exists, false otherwise.
isEmpty
isEmpty ():booleanChecks if the collection is empty (contains no files or sub-directories).
@returns {boolean} True if empty, false otherwise.
getCollectionsNames
getCollectionsNames ():string[]Gets the names of all sub-collections (folders) within this collection.
@returns {string[]} An array of sub-collection names.
createCollection
createCollection (name:string):CollectionCreates a new sub-collection (folder) within this collection.
@param {string} name The name of the new sub-collection.
@returns {Collection} The newly created Collection instance.
getCollection
getCollection (name:string):CollectionGets a specific sub-collection by name.
@param {string} name The name of the sub-collection.
@returns {Collection} The child Collection instance.
removeCollection
removeCollection (name:string):voidRemoves a sub-collection by name.
@param {string} name The name of the sub-collection to remove.
getResourcesNames
getResourcesNames ():string[]Gets the names of all resources (files) within this collection.
@returns {string[]} An array of resource names.
getResource
getResource (name:string):ResourceGets a specific resource (file) by name.
@param {string} name The name of the resource.
@returns {Resource} The child Resource instance.
removeResource
removeResource (name:string):voidRemoves a resource (file) by name.
@param {string} name The name of the resource to remove.
createResource
createResource (name:string, content:string):ResourceCreates a new resource (file) within this collection.
@param {string} name The name of the new resource.
@param {string} content The string content for the resource.
@returns {Resource} The newly created Resource instance.
EntityInformation
@class EntityInformation
@description Represents detailed metadata (creation date, size, permissions, etc.) for a
Resource or Collection.
Methods
getName
getName ():stringGets the name of the entity (resource or collection).
@returns {string} The name.
getPath
getPath ():stringGets the full repository path of the entity.
@returns {string} The repository path.
getPermissions
getPermissions ():numberGets the access permissions for the entity (typically an integer bitmask).
@returns {number} The permissions value.
getSize
getSize ():numberGets the size of the resource content in bytes (0 for a collection).
@returns {number} The size in bytes.
getCreatedBy
getCreatedBy ():stringGets the user who created the entity.
@returns {string} The creator's name.
getCreatedAt
getCreatedAt ():DateGets the creation timestamp.
@returns {Date} The creation date and time.
getModifiedBy
getModifiedBy ():stringGets the user who last modified the entity.
@returns {string} The modifier's name.
getModifiedAt
getModifiedAt ():DateGets the last modification timestamp.
@returns {Date} The modification date and time.