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 longMAX_MEMORY_ARCHIVE_SIZEmax 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 voidclose()Closes this package and destroys all temporary data.intcompareTo(JcrPackage o)voidextract(ImportOptions opts)Extracts the package contents to the repository.@NotNull PackageId[]extractSubpackages(@NotNull ImportOptions opts)Processes this package and extracts all sub packages.@Nullable PropertygetData()Returns the jcr:data property of the packageJcrPackageDefinitiongetDefinition()Returns the package definition of this package@Nullable NodegetDefNode()Returns the definition node ornullif not existsNodegetNode()Returns the underlying nodeVaultPackagegetPackage()Returns the vault package stored in the data of this package.protected @NotNull VaultPackagegetPackage(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.longgetSize()Returns the size of the underlying package.JcrPackagegetSnapshot()Returns the snapshot that was taken when installing this package.Dependency[]getUnresolvedDependencies()Returns the dependencies that are not resolved.voidinstall(ImportOptions opts)Installs the package contents to the repository but creates a snapshot if necessary.booleanisEmpty()Checks if the package has content.booleanisInstalled()Checks if this package is installed.booleanisSealed()Checks if this package is sealed. this is the case, if it was not modified since it was unwrapped.booleanisValid()Checks if the underlying node contains the correct structure.JcrPackagesnapshot(ExportOptions opts, boolean replace)Creates a snapshot of this package.voidtryUnwrap()Tries to unwrap the definition of this package.voiduninstall(ImportOptions opts)Reverts the changes of a prior installation of this package.booleanverifyId(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:
getDefinitionin interfaceJcrPackage- Returns:
- the package definition or
nullif this package is not valid. - Throws:
RepositoryException- if an error occurs
-
compareTo
public int compareTo(JcrPackage o)
- Specified by:
compareToin interfaceComparable<JcrPackage>
-
isValid
public boolean isValid()
Checks if the underlying node contains the correct structure.- Specified by:
isValidin interfaceJcrPackage- Returns:
trueif this package is valid.
-
isInstalled
public boolean isInstalled() throws RepositoryExceptionChecks 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:
isInstalledin interfaceJcrPackage- Returns:
trueif this package is installed.- Throws:
RepositoryException- if an error occurs.
-
isEmpty
public boolean isEmpty()
Checks if the package has content.- Specified by:
isEmptyin interfaceJcrPackage- Returns:
trueif this package doesn't have content
-
getNode
public Node getNode()
Returns the underlying node- Specified by:
getNodein 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:
isSealedin interfaceJcrPackage- Returns:
trueif 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:
verifyIdin interfaceJcrPackage- Parameters:
autoFix-trueto automatically fix the idautoSave-trueto save changes immediately- Returns:
truealways.- Throws:
RepositoryException- if an error occurs.
-
tryUnwrap
public void tryUnwrap() throws IOException, RepositoryExceptionTries 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:
getPackagein 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- iftruea 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:
extractin 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:
installin 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:
extractSubpackagesin 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 theDependencyHandlingis set to strict, the package will not installed if any unresolved dependencies are listed.- Specified by:
getUnresolvedDependenciesin 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:
getResolvedDependenciesin 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:
snapshotin interfaceJcrPackage- Parameters:
opts- export optionsreplace- iftrueany existing snapshot is replaced.- Returns:
- a package that represents the snapshot of this package or
nullif 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:
getSnapshotin 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:
uninstallin 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:
getSizein 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceJcrPackage
-
getData
@Nullable public @Nullable Property getData() throws RepositoryException
Returns the jcr:data property of the package- Specified by:
getDatain interfaceJcrPackage- Returns:
- the jcr:data property
- Throws:
RepositoryException- if an error occurrs
-
getDefNode
@Nullable public @Nullable Node getDefNode() throws RepositoryException
Returns the definition node ornullif not exists- Specified by:
getDefNodein interfaceJcrPackage- Returns:
- the definition node.
- Throws:
RepositoryException- if an error occurrs
-
-