Package org.xwiki.xar

Class XarPackage


  • public class XarPackage
    extends Object
    Manipulate package.xml XAR package file.
    Since:
    5.4RC1
    Version:
    $Id: 4fa3564fb43a813df2b066a4817351ee9eb7e893 $
    • Constructor Detail

      • XarPackage

        public XarPackage()
        Default constructor.
      • XarPackage

        public XarPackage​(org.apache.commons.compress.archivers.zip.ZipFile zipFile)
                   throws XarException,
                          IOException
        Parameters:
        zipFile - the XAR file as a ZipFile
        Throws:
        XarException - when failing to parse the XAR package
        IOException - when failing to read the file
      • XarPackage

        public XarPackage​(Collection<XarEntry> entries)
        Parameters:
        entries - the entries in the XAR file
    • Method Detail

      • read

        public void read​(InputStream xarStream)
                  throws IOException,
                         XarException
        Find and add the entries located in the passed XAR file.
        Parameters:
        xarStream - an input stream to a XAR file
        Throws:
        IOException - when failing to read the file
        XarException - when failing to parse the XAR package
      • read

        public void read​(org.apache.commons.compress.archivers.zip.ZipFile zipFile)
                  throws IOException,
                         XarException
        Find and add the entries located in the passed XAR file.
        Parameters:
        zipFile - the XAR file
        Throws:
        IOException - when failing to read the file
        XarException - when failing to parse the XAR package
      • read

        public void read​(File directory)
                  throws IOException,
                         XarException
        Find and add the entries located in the passed XAR directory.
        Parameters:
        directory - the expended XAR file
        Throws:
        IOException - when failing to read the file
        XarException - when failing to parse the XAR package
        Since:
        9.5RC1
      • getPackageExtensionId

        public String getPackageExtensionId()
        Returns:
        the identifier of the extension stored in the XAR package
      • setPackageExtensionId

        public void setPackageExtensionId​(String packageExtensionId)
        Parameters:
        packageExtensionId - the identifier of the extension stored in the XAR package
      • isPackagePreserveVersion

        public boolean isPackagePreserveVersion()
        Returns:
        true if the history should be preserved by default
      • setPreserveVersion

        @Deprecated
        public void setPreserveVersion​(boolean preserveVersion)
        Deprecated.
        since 7.2M1, use setPackagePreserveVersion(boolean) instead
        Parameters:
        preserveVersion - true if the history should be preserved by default
      • setPackagePreserveVersion

        public void setPackagePreserveVersion​(boolean packagePreserveVersion)
        Parameters:
        packagePreserveVersion - true if the history should be preserved by default
      • getPackageName

        public String getPackageName()
        Returns:
        the name of the package
      • setPackageName

        public void setPackageName​(String packageName)
        Parameters:
        packageName - the name of the package
      • getPackageDescription

        public String getPackageDescription()
        Returns:
        the description of package
      • setPackageDescription

        public void setPackageDescription​(String packageDescription)
        Parameters:
        packageDescription - the description of package
      • getPackageLicense

        public String getPackageLicense()
        Returns:
        the license of the package
      • setPackageLicense

        public void setPackageLicense​(String packageLicense)
        Parameters:
        packageLicense - the license of the package
      • getPackageAuthor

        public String getPackageAuthor()
        Returns:
        the author of the package
      • setPackageAuthor

        public void setPackageAuthor​(String packageAuthor)
        Parameters:
        packageAuthor - the author of the package
      • getPackageVersion

        public String getPackageVersion()
        Returns:
        the version of the package
      • setPackageVersion

        public void setPackageVersion​(String packageVersion)
        Parameters:
        packageVersion - the version of the package
      • isPackageBackupPack

        public boolean isPackageBackupPack()
        Returns:
        true of the package is a backup
      • setPackageBackupPack

        public void setPackageBackupPack​(boolean packageBackupPack)
        Parameters:
        packageBackupPack - true of the package is a backup
      • getPackageFiles

        public Collection<XarEntry> getPackageFiles()
        Returns:
        the entries listed in the package descriptor
        Since:
        7.2M1
      • addPackageFile

        public void addPackageFile​(LocalDocumentReference reference,
                                   int action)
        Add a new entry to the package.
        Parameters:
        reference - the entry reference since 7.2M1
        action - the default action associated to this XAR (not used at the moment)
      • addEntry

        public void addEntry​(LocalDocumentReference reference,
                             String entryName)
        Add a new entry to the package.
        Parameters:
        reference - the entry reference
        entryName - the name of the entry (ZIP style)
        Since:
        7.2M1
      • addEntry

        public void addEntry​(LocalDocumentReference reference,
                             String entryName,
                             int action)
        Add a new entry to the package.
        Parameters:
        reference - the entry reference
        entryName - the name of the entry (ZIP style)
        action - the default action associated to this XAR (not used at the moment)
        Since:
        7.2M1
      • getEntries

        public Collection<XarEntry> getEntries()
        Returns:
        the entries of the package
      • getEntry

        public XarEntry getEntry​(LocalDocumentReference reference)
        Parameters:
        reference - the reference of the document
        Returns:
        the entry associated to the passage reference
      • readDescriptor

        public void readDescriptor​(InputStream stream)
                            throws XarException,
                                   IOException
        Read a XML descriptor of a XAR package (usually names package.xml).
        Parameters:
        stream - the input stream to the XML file to parse
        Throws:
        XarException - when failing to parse the descriptor
        IOException - when failing to read the file
      • write

        public void write​(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zipStream,
                          String encoding)
                   throws XarException,
                          IOException
        Write and add the package descriptor to the passed ZIP stream.
        Parameters:
        zipStream - the ZIP stream in which to write
        encoding - the encoding to use to write the descriptor
        Throws:
        XarException - when failing to parse the descriptor
        IOException - when failing to read the file
      • write

        public void write​(OutputStream stream,
                          String encoding)
                   throws XarException
        Write the package descriptor to the passed stream as XML.
        Parameters:
        stream - the stream to the resulting XML file
        encoding - the encoding to use to write the descriptor
        Throws:
        XarException - when failing to parse the descriptor