Package org.xwiki.xar
Class XarPackage
- java.lang.Object
-
- org.xwiki.xar.XarPackage
-
public class XarPackage extends Object
Manipulate package.xml XAR package file.- Since:
- 5.4RC1
- Version:
- $Id: 4fa3564fb43a813df2b066a4817351ee9eb7e893 $
-
-
Constructor Summary
Constructors Constructor Description XarPackage()
Default constructor.XarPackage(File file)
XarPackage(InputStream xarStream)
XarPackage(Collection<XarEntry> entries)
XarPackage(org.apache.commons.compress.archivers.zip.ZipFile zipFile)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addEntry(LocalDocumentReference reference)
Deprecated.since 7.2M1, useaddPackageFile(LocalDocumentReference, int)
insteadvoid
addEntry(LocalDocumentReference reference, String entryName)
Add a new entry to the package.void
addEntry(LocalDocumentReference reference, String entryName, int action)
Add a new entry to the package.void
addPackageFile(LocalDocumentReference reference, int action)
Add a new entry to the package.Collection<XarEntry>
getEntries()
static Collection<XarEntry>
getEntries(File file)
Get all entries found in a XAR file.XarEntry
getEntry(LocalDocumentReference reference)
String
getPackageAuthor()
String
getPackageDescription()
String
getPackageExtensionId()
Collection<XarEntry>
getPackageFiles()
String
getPackageLicense()
String
getPackageName()
String
getPackageVersion()
boolean
isPackageBackupPack()
boolean
isPackagePreserveVersion()
void
read(File directory)
Find and add the entries located in the passed XAR directory.void
read(InputStream xarStream)
Find and add the entries located in the passed XAR file.void
read(org.apache.commons.compress.archivers.zip.ZipFile zipFile)
Find and add the entries located in the passed XAR file.void
readDescriptor(InputStream stream)
Read a XML descriptor of a XAR package (usually names package.xml).void
setPackageAuthor(String packageAuthor)
void
setPackageBackupPack(boolean packageBackupPack)
void
setPackageDescription(String packageDescription)
void
setPackageExtensionId(String packageExtensionId)
void
setPackageLicense(String packageLicense)
void
setPackageName(String packageName)
void
setPackagePreserveVersion(boolean packagePreserveVersion)
void
setPackageVersion(String packageVersion)
void
setPreserveVersion(boolean preserveVersion)
Deprecated.since 7.2M1, usesetPackagePreserveVersion(boolean)
insteadvoid
write(OutputStream stream, String encoding)
Write the package descriptor to the passed stream as XML.void
write(XMLStreamWriter writer)
Write the package descriptor to the passed XML stream.void
write(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zipStream, String encoding)
Write and add the package descriptor to the passed ZIP stream.
-
-
-
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 aZipFile
- Throws:
XarException
- when failing to parse the XAR packageIOException
- when failing to read the file
-
XarPackage
public XarPackage(File file) throws IOException, XarException
- Parameters:
file
- the XAR file- Throws:
IOException
- when failing to read the fileXarException
- when failing to parse the XAR package
-
XarPackage
public XarPackage(InputStream xarStream) throws IOException, XarException
- Parameters:
xarStream
- an input stream the the XAR file- Throws:
IOException
- when failing to read the fileXarException
- when failing to parse the XAR package
-
XarPackage
public XarPackage(Collection<XarEntry> entries)
- Parameters:
entries
- the entries in the XAR file
-
-
Method Detail
-
getEntries
public static Collection<XarEntry> getEntries(File file) throws XarException, IOException
Get all entries found in a XAR file.- Parameters:
file
- the XAR file- Returns:
- the entries of the passed XAR file
- Throws:
XarException
- when failing to parse the XAR packageIOException
- when failing to read the file
-
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 fileXarException
- 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 fileXarException
- 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 fileXarException
- 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, usesetPackagePreserveVersion(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.2M1action
- the default action associated to this XAR (not used at the moment)
-
addEntry
@Deprecated public void addEntry(LocalDocumentReference reference)
Deprecated.since 7.2M1, useaddPackageFile(LocalDocumentReference, int)
insteadAdd a new entry to the package.- Parameters:
reference
- the entry reference
-
addEntry
public void addEntry(LocalDocumentReference reference, String entryName)
Add a new entry to the package.- Parameters:
reference
- the entry referenceentryName
- 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 referenceentryName
- 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 descriptorIOException
- 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 writeencoding
- the encoding to use to write the descriptor- Throws:
XarException
- when failing to parse the descriptorIOException
- 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 fileencoding
- the encoding to use to write the descriptor- Throws:
XarException
- when failing to parse the descriptor
-
write
public void write(XMLStreamWriter writer) throws XMLStreamException
Write the package descriptor to the passed XML stream.- Parameters:
writer
- the XML stream where to write- Throws:
XMLStreamException
- when failing to write the file
-
-