Class JcrPackageImpl
- java.lang.Object
-
- org.apache.jackrabbit.vault.packaging.impl.JcrPackageImpl
-
- All Implemented Interfaces:
AutoCloseable
,Comparable<JcrPackage>
,JcrPackage
public class JcrPackageImpl extends Object implements JcrPackage
Implements a JcrPackage
-
-
Field Summary
Fields Modifier and Type Field Description static long
MAX_MEMORY_ARCHIVE_SIZE
max allowed package size for using a memory archive-
Fields inherited from interface org.apache.jackrabbit.vault.packaging.JcrPackage
MIME_TYPE, NN_VLT_DEFINITION, NT_VLT_PACKAGE, NT_VLT_PACKAGE_DEFINITION
-
-
Constructor Summary
Constructors Constructor Description JcrPackageImpl(@NotNull JcrPackageRegistry mgr, @Nullable Node node)
JcrPackageImpl(@NotNull JcrPackageRegistry mgr, @Nullable Node node, @Nullable ZipVaultPackage pack)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
Closes this package and destroys all temporary data.int
compareTo(JcrPackage o)
void
extract(ImportOptions opts)
Extracts the package contents to the repository.@NotNull PackageId[]
extractSubpackages(@NotNull ImportOptions opts)
Processes this package and extracts all sub packages.@Nullable Property
getData()
Returns the jcr:data property of the packageJcrPackageDefinition
getDefinition()
Returns the package definition of this package@Nullable Node
getDefNode()
Returns the definition node ornull
if not existsNode
getNode()
Returns the underlying nodeVaultPackage
getPackage()
Returns the vault package stored in the data of this package.protected @NotNull VaultPackage
getPackage(boolean forceFileArchive)
Creates a new package by creating the appropriate archive.PackageId[]
getResolvedDependencies()
Returns a list of the installed packages that this package depends on.long
getSize()
Returns the size of the underlying package.JcrPackage
getSnapshot()
Returns the snapshot that was taken when installing this package.Dependency[]
getUnresolvedDependencies()
Returns the dependencies that are not resolved.void
install(ImportOptions opts)
Installs the package contents to the repository but creates a snapshot if necessary.boolean
isEmpty()
Checks if the package has content.boolean
isInstalled()
Checks if this package is installed.boolean
isSealed()
Checks if this package is sealed.boolean
isValid()
Checks if the underlying node contains the correct structure.JcrPackage
snapshot(ExportOptions opts, boolean replace)
Creates a snapshot of this package.void
tryUnwrap()
Tries to unwrap the definition of this package.void
uninstall(ImportOptions opts)
Reverts the changes of a prior installation of this package.boolean
verifyId(boolean autoFix, boolean autoSave)
Deprecated.
-
-
-
Field Detail
-
MAX_MEMORY_ARCHIVE_SIZE
public static final long MAX_MEMORY_ARCHIVE_SIZE
max allowed package size for using a memory archive- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JcrPackageImpl
public JcrPackageImpl(@NotNull @NotNull JcrPackageRegistry mgr, @Nullable @Nullable Node node) throws RepositoryException
- Throws:
RepositoryException
-
JcrPackageImpl
public JcrPackageImpl(@NotNull @NotNull JcrPackageRegistry mgr, @Nullable @Nullable Node node, @Nullable @Nullable ZipVaultPackage pack) throws RepositoryException
- Throws:
RepositoryException
-
-
Method Detail
-
getDefinition
public JcrPackageDefinition getDefinition() throws RepositoryException
Returns the package definition of this package- Specified by:
getDefinition
in interfaceJcrPackage
- Returns:
- the package definition or
null
if this package is not valid. - Throws:
RepositoryException
- if an error occurs
-
compareTo
public int compareTo(JcrPackage o)
- Specified by:
compareTo
in interfaceComparable<JcrPackage>
-
isValid
public boolean isValid()
Checks if the underlying node contains the correct structure.- Specified by:
isValid
in interfaceJcrPackage
- Returns:
true
if this package is valid.
-
isInstalled
public boolean isInstalled() throws RepositoryException
Checks if this package is installed. Note: the default implementation only checks theJcrPackageDefinition.getLastUnpacked()
date. If the package is replaced since it was installed. this method will returnfalse
.- Specified by:
isInstalled
in interfaceJcrPackage
- Returns:
true
if this package is installed.- Throws:
RepositoryException
- if an error occurs.
-
isEmpty
public boolean isEmpty()
Checks if the package has content.- Specified by:
isEmpty
in interfaceJcrPackage
- Returns:
true
if this package doesn't have content
-
getNode
public Node getNode()
Returns the underlying node- Specified by:
getNode
in interfaceJcrPackage
- Returns:
- the node
-
isSealed
public boolean isSealed()
Checks if this package is sealed. this is the case, if it was not modified since it was unwrapped.- Specified by:
isSealed
in interfaceJcrPackage
- Returns:
true
if this package is sealed.
-
verifyId
@Deprecated public boolean verifyId(boolean autoFix, boolean autoSave) throws RepositoryException
Deprecated.Checks if the package id is correct in respect to the installation path and adjusts it accordingly.- Specified by:
verifyId
in interfaceJcrPackage
- Parameters:
autoFix
-true
to automatically fix the idautoSave
-true
to save changes immediately- Returns:
true
always.- Throws:
RepositoryException
- if an error occurs.
-
tryUnwrap
public void tryUnwrap() throws IOException, RepositoryException
Tries to unwrap the definition of this package.- Throws:
IOException
- if an I/O error occurs or if the underlying file is not a packageRepositoryException
- if a repository error occurs
-
getPackage
public VaultPackage getPackage() throws RepositoryException, IOException
Returns the vault package stored in the data of this package. Opens the package implicitly thereforeJcrPackage.close()
needs to be afterwards. This is potentially a costly operation as this requires uncompressing the ZIP stream (and potentially creating temporary files) therefore prefer usingJcrPackage.getDefinition()
whenever possible to access meta data.- Specified by:
getPackage
in interfaceJcrPackage
- Returns:
- the package, this is closed when
JcrPackage.close()
is called on this package - Throws:
RepositoryException
- if an error occursIOException
- if an I/O error occurs
-
getPackage
@NotNull protected @NotNull VaultPackage getPackage(boolean forceFileArchive) throws RepositoryException, IOException
Creates a new package by creating the appropriate archive. This is basically a workaround to ensure that 'rewrap' has a zip file to work on. Ideally rewrap should not rely on the archive format.- Parameters:
forceFileArchive
- iftrue
a file archive is enforced- Returns:
- the package
- Throws:
RepositoryException
- If a repository error occurs.IOException
- if an i/o error occurs.
-
extract
public void extract(ImportOptions opts) throws RepositoryException, PackageException, IOException
Extracts the package contents to the repository. Opens the package implicitly thereforeJcrPackage.close()
needs to be afterwards.- Specified by:
extract
in interfaceJcrPackage
- Parameters:
opts
- import options- Throws:
RepositoryException
- if a repository error during installation occurs.PackageException
- if an error during packaging occursIOException
- if an I/O error occurs
-
install
public void install(ImportOptions opts) throws RepositoryException, PackageException, IOException
Installs the package contents to the repository but creates a snapshot if necessary. Opens the package implicitly thereforeJcrPackage.close()
needs to be afterwards.- Specified by:
install
in interfaceJcrPackage
- Parameters:
opts
- import options- Throws:
RepositoryException
- if a repository error during installation occurs.PackageException
- if an error during packaging occursIOException
- if an I/O error occurs
-
extractSubpackages
@NotNull public @NotNull PackageId[] extractSubpackages(@NotNull @NotNull ImportOptions opts) throws RepositoryException, PackageException, IOException
Processes this package and extracts all sub packages. No content of this package or its sub packages is extracted and not snapshots are taken. IfImportOptions.isNonRecursive()
istrue
, then only the direct sub packages are extracted. The extraction ensures that the sub packages have a dependency to their parent package.- Specified by:
extractSubpackages
in interfaceJcrPackage
- Parameters:
opts
- import options- Returns:
- the list of subpackages that were extracted
- Throws:
RepositoryException
- if a repository error during installation occurs.PackageException
- if an error during packaging occursIOException
- if an I/O error occurs
-
getUnresolvedDependencies
public Dependency[] getUnresolvedDependencies() throws RepositoryException
Returns the dependencies that are not resolved. If theDependencyHandling
is set to strict, the package will not installed if any unresolved dependencies are listed.- Specified by:
getUnresolvedDependencies
in interfaceJcrPackage
- Returns:
- the array of unresolved dependencies.
- Throws:
RepositoryException
- if an error accessing the repository occurrs
-
getResolvedDependencies
public PackageId[] getResolvedDependencies() throws RepositoryException
Returns a list of the installed packages that this package depends on.- Specified by:
getResolvedDependencies
in interfaceJcrPackage
- Returns:
- the array of resolved dependencies
- Throws:
RepositoryException
- if an error accessing the repository occurrs
-
snapshot
public JcrPackage snapshot(ExportOptions opts, boolean replace) throws RepositoryException, PackageException, IOException
Creates a snapshot of this package.- Specified by:
snapshot
in interfaceJcrPackage
- Parameters:
opts
- export optionsreplace
- iftrue
any existing snapshot is replaced.- Returns:
- a package that represents the snapshot of this package or
null
if it wasn't created. - Throws:
RepositoryException
- if a repository error during installation occurs.PackageException
- if an error during packaging occursIOException
- if an I/O error occurs
-
getSnapshot
public JcrPackage getSnapshot() throws RepositoryException
Returns the snapshot that was taken when installing this package.- Specified by:
getSnapshot
in interfaceJcrPackage
- Returns:
- the snapshot package or
null
- Throws:
RepositoryException
- if an error occurs.
-
uninstall
public void uninstall(ImportOptions opts) throws RepositoryException, PackageException, IOException
Reverts the changes of a prior installation of this package.- Specified by:
uninstall
in interfaceJcrPackage
- Parameters:
opts
- import options- Throws:
RepositoryException
- if a repository error during installation occurs.PackageException
- if an error during packaging occurs or if no snapshot is available.IOException
- if an I/O error occurs
-
getSize
public long getSize()
Returns the size of the underlying package.- Specified by:
getSize
in interfaceJcrPackage
- Returns:
- the size in bytes or -1 if not valid.
-
close
public void close()
Closes this package and destroys all temporary data. Only necessary to call whenJcrPackage.getPackage()
,JcrPackage.extract(ImportOptions)
orJcrPackage.install(ImportOptions)
has been called. Is a no-op when none of these methods have been called on this package.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceJcrPackage
-
getData
@Nullable public @Nullable Property getData() throws RepositoryException
Returns the jcr:data property of the package- Specified by:
getData
in interfaceJcrPackage
- Returns:
- the jcr:data property
- Throws:
RepositoryException
- if an error occurrs
-
getDefNode
@Nullable public @Nullable Node getDefNode() throws RepositoryException
Returns the definition node ornull
if not exists- Specified by:
getDefNode
in interfaceJcrPackage
- Returns:
- the definition node.
- Throws:
RepositoryException
- if an error occurrs
-
-