public class WidgetPackageUtils
extends java.lang.Object
| Constructor and Description |
|---|
WidgetPackageUtils() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
convertIdToFolderName(java.lang.String id)
Converts a widget identifier (usually a URI) into a form suitable for use as a file system folder name
|
static java.lang.String |
convertPathToPlatform(java.lang.String path) |
static java.lang.String |
convertPathToRelativeUri(java.lang.String path) |
static java.io.File |
createTempDirectory() |
static java.io.File |
createUnpackedWidgetFolder(java.io.File widgetFolder,
java.lang.String id)
Returns a File representing the unpacked folder for a widget with the given identifier.
|
static java.lang.String |
extractManifest(org.apache.commons.compress.archivers.zip.ZipFile zipFile)
Retrieves the Manifest entry as a String
|
static java.lang.String[] |
getDefaults(org.apache.commons.compress.archivers.zip.ZipFile zip,
java.lang.String[] locales,
java.lang.String[] defaults)
Return the set of valid default files for each locale in the zip
|
static java.io.InputStream |
getEntryStream(java.lang.String entry,
org.apache.commons.compress.archivers.zip.ZipFile zipFile)
Gets the input stream for an entry in the zip
|
static java.lang.String[] |
getLocalesFromPackage(java.io.File file)
Give a directory, assumed to be the root of a widget package, iterate over
the contents of the "locales" folder, should it exist, and return the names
of all the subdirectories, assumed to be localized content folders.
|
static java.lang.String[] |
getLocalesFromZipFile(org.apache.commons.compress.archivers.zip.ZipFile zipFile)
Given a zipfile, iterate over the contents of the "locales" folder within the
archive, should it exist, and return the names of all the subdirectories,
assumed to be localized content folders.
|
static java.lang.String |
getURLForWidget(java.lang.String widgetFolder,
java.lang.String id,
java.lang.String file)
Returns the local URL for a widget
|
static boolean |
hasManifest(org.apache.commons.compress.archivers.zip.ZipFile zipfile)
Checks for the existence of the Manifest.
|
static java.lang.String |
languageTagForPath(java.lang.String path)
Return the language tag for a given path
|
static java.lang.String |
locateFilePath(java.lang.String path,
java.lang.String[] locales,
org.apache.commons.compress.archivers.zip.ZipFile zip)
Implements the rule for finding a file within a widget; it returns the first localized version
first before returning a root version.
|
static java.lang.String[] |
locateFilePaths(java.lang.String path,
java.lang.String[] locales,
org.apache.commons.compress.archivers.zip.ZipFile zip)
Returns the set of valid file paths for a given resource.
|
static void |
repackZip(java.io.File source,
java.io.File target)
Packages the source file/folder up as a new Zip file
|
static void |
unpackZip(org.apache.commons.compress.archivers.zip.ZipFile zipfile,
java.io.File targetFolder)
uses apache commons compress to unpack all the zip entries into a target folder
partly adapted from the examples on the apache commons compress site, and an
example of generic Zip unpacking.
|
public static java.lang.String locateFilePath(java.lang.String path,
java.lang.String[] locales,
org.apache.commons.compress.archivers.zip.ZipFile zip)
throws java.lang.Exception
path - locales - the supported locales, in list of preferencezip - java.lang.Exceptionpublic static java.lang.String[] locateFilePaths(java.lang.String path,
java.lang.String[] locales,
org.apache.commons.compress.archivers.zip.ZipFile zip)
throws java.lang.Exception
path - locales - zip - java.lang.Exceptionpublic static java.lang.String languageTagForPath(java.lang.String path)
path - public static java.io.File createTempDirectory()
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String[] getLocalesFromZipFile(org.apache.commons.compress.archivers.zip.ZipFile zipFile)
throws java.io.IOException
zipFile - java.io.IOExceptionpublic static java.lang.String[] getLocalesFromPackage(java.io.File file)
file - public static java.lang.String[] getDefaults(org.apache.commons.compress.archivers.zip.ZipFile zip,
java.lang.String[] locales,
java.lang.String[] defaults)
zip - locales - defaults - public static java.io.File createUnpackedWidgetFolder(java.io.File widgetFolder,
java.lang.String id)
throws java.io.IOException
widgetFolder - the folder that contains unpacked widgetsid - the widget identifier URIjava.io.IOExceptionpublic static java.lang.String getURLForWidget(java.lang.String widgetFolder,
java.lang.String id,
java.lang.String file)
widgetFolder - the folder that contains unpacked widgetsid - the widget identifier URIfile - a file in the widget package; use "" to obtain the root of the widget folderpublic static java.lang.String convertIdToFolderName(java.lang.String id)
id - the widget identifier URIpublic static java.lang.String convertPathToRelativeUri(java.lang.String path)
public static java.lang.String convertPathToPlatform(java.lang.String path)
public static boolean hasManifest(org.apache.commons.compress.archivers.zip.ZipFile zipfile)
zipfile - public static java.lang.String extractManifest(org.apache.commons.compress.archivers.zip.ZipFile zipFile)
throws java.io.IOException
zipFile - the zip file from which to extract the manifestjava.io.IOExceptionpublic static java.io.InputStream getEntryStream(java.lang.String entry,
org.apache.commons.compress.archivers.zip.ZipFile zipFile)
throws java.util.zip.ZipException,
java.io.IOException
entry - the name of the entryzipFile - java.util.zip.ZipExceptionjava.io.IOExceptionpublic static void unpackZip(org.apache.commons.compress.archivers.zip.ZipFile zipfile,
java.io.File targetFolder)
throws java.io.IOException
zipfile - the Zip File to unpacktargetFolder - the folder into which to unpack the Zip filejava.io.IOExceptionpublic static void repackZip(java.io.File source,
java.io.File target)
throws java.io.IOException
source - the source file or folder to be zippedtarget - the zip file to createjava.io.IOException2012 Apache Software Foundation.