Fix inconsistent indents
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1735063 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5f2f0adfae
commit
0fab07ccfc
@ -32,146 +32,145 @@ import org.apache.poi.openxml4j.opc.ZipPackage;
|
|||||||
import org.apache.poi.openxml4j.util.ZipSecureFile;
|
import org.apache.poi.openxml4j.util.ZipSecureFile;
|
||||||
|
|
||||||
public final class ZipHelper {
|
public final class ZipHelper {
|
||||||
|
/**
|
||||||
|
* Forward slash use to convert part name between OPC and zip item naming
|
||||||
|
* conventions.
|
||||||
|
*/
|
||||||
|
private final static String FORWARD_SLASH = "/";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forward slash use to convert part name between OPC and zip item naming
|
* Buffer to read data from file. Use big buffer to improve performaces. the
|
||||||
* conventions.
|
* InputStream class is reading only 8192 bytes per read call (default value
|
||||||
*/
|
* set by sun)
|
||||||
private final static String FORWARD_SLASH = "/";
|
*/
|
||||||
|
public static final int READ_WRITE_FILE_BUFFER_SIZE = 8192;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Buffer to read data from file. Use big buffer to improve performaces. the
|
* Prevent this class to be instancied.
|
||||||
* InputStream class is reading only 8192 bytes per read call (default value
|
*/
|
||||||
* set by sun)
|
private ZipHelper() {
|
||||||
*/
|
// Do nothing
|
||||||
public static final int READ_WRITE_FILE_BUFFER_SIZE = 8192;
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prevent this class to be instancied.
|
* Retrieve the zip entry of the core properties part.
|
||||||
*/
|
*
|
||||||
private ZipHelper() {
|
* @throws OpenXML4JException
|
||||||
// Do nothing
|
* Throws if internal error occurs.
|
||||||
}
|
*/
|
||||||
|
public static ZipEntry getCorePropertiesZipEntry(ZipPackage pkg) {
|
||||||
|
PackageRelationship corePropsRel = pkg.getRelationshipsByType(
|
||||||
|
PackageRelationshipTypes.CORE_PROPERTIES).getRelationship(0);
|
||||||
|
|
||||||
/**
|
if (corePropsRel == null)
|
||||||
* Retrieve the zip entry of the core properties part.
|
return null;
|
||||||
*
|
|
||||||
* @throws OpenXML4JException
|
|
||||||
* Throws if internal error occurs.
|
|
||||||
*/
|
|
||||||
public static ZipEntry getCorePropertiesZipEntry(ZipPackage pkg) {
|
|
||||||
PackageRelationship corePropsRel = pkg.getRelationshipsByType(
|
|
||||||
PackageRelationshipTypes.CORE_PROPERTIES).getRelationship(0);
|
|
||||||
|
|
||||||
if (corePropsRel == null)
|
return new ZipEntry(corePropsRel.getTargetURI().getPath());
|
||||||
return null;
|
}
|
||||||
|
|
||||||
return new ZipEntry(corePropsRel.getTargetURI().getPath());
|
/**
|
||||||
}
|
* Retrieve the Zip entry of the content types part.
|
||||||
|
*/
|
||||||
|
public static ZipEntry getContentTypeZipEntry(ZipPackage pkg) {
|
||||||
|
Enumeration<? extends ZipEntry> entries = pkg.getZipArchive().getEntries();
|
||||||
|
|
||||||
/**
|
// Enumerate through the Zip entries until we find the one named
|
||||||
* Retrieve the Zip entry of the content types part.
|
// '[Content_Types].xml'.
|
||||||
*/
|
while (entries.hasMoreElements()) {
|
||||||
public static ZipEntry getContentTypeZipEntry(ZipPackage pkg) {
|
ZipEntry entry = entries.nextElement();
|
||||||
Enumeration<? extends ZipEntry> entries = pkg.getZipArchive().getEntries();
|
if (entry.getName().equals(
|
||||||
|
ContentTypeManager.CONTENT_TYPES_PART_NAME))
|
||||||
// Enumerate through the Zip entries until we find the one named
|
return entry;
|
||||||
// '[Content_Types].xml'.
|
}
|
||||||
while (entries.hasMoreElements()) {
|
return null;
|
||||||
ZipEntry entry = entries.nextElement();
|
}
|
||||||
if (entry.getName().equals(
|
|
||||||
ContentTypeManager.CONTENT_TYPES_PART_NAME))
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a zip name into an OPC name by adding a leading forward slash to
|
* Convert a zip name into an OPC name by adding a leading forward slash to
|
||||||
* the specified item name.
|
* the specified item name.
|
||||||
*
|
*
|
||||||
* @param zipItemName
|
* @param zipItemName
|
||||||
* Zip item name to convert.
|
* Zip item name to convert.
|
||||||
* @return An OPC compliant name.
|
* @return An OPC compliant name.
|
||||||
*/
|
*/
|
||||||
public static String getOPCNameFromZipItemName(String zipItemName) {
|
public static String getOPCNameFromZipItemName(String zipItemName) {
|
||||||
if (zipItemName == null)
|
if (zipItemName == null)
|
||||||
throw new IllegalArgumentException("zipItemName");
|
throw new IllegalArgumentException("zipItemName");
|
||||||
if (zipItemName.startsWith(FORWARD_SLASH)) {
|
if (zipItemName.startsWith(FORWARD_SLASH)) {
|
||||||
return zipItemName;
|
return zipItemName;
|
||||||
}
|
}
|
||||||
return FORWARD_SLASH + zipItemName;
|
return FORWARD_SLASH + zipItemName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an OPC item name into a zip item name by removing any leading
|
* Convert an OPC item name into a zip item name by removing any leading
|
||||||
* forward slash if it exist.
|
* forward slash if it exist.
|
||||||
*
|
*
|
||||||
* @param opcItemName
|
* @param opcItemName
|
||||||
* The OPC item name to convert.
|
* The OPC item name to convert.
|
||||||
* @return A zip item name without any leading slashes.
|
* @return A zip item name without any leading slashes.
|
||||||
*/
|
*/
|
||||||
public static String getZipItemNameFromOPCName(String opcItemName) {
|
public static String getZipItemNameFromOPCName(String opcItemName) {
|
||||||
if (opcItemName == null)
|
if (opcItemName == null)
|
||||||
throw new IllegalArgumentException("opcItemName");
|
throw new IllegalArgumentException("opcItemName");
|
||||||
|
|
||||||
String retVal = opcItemName;
|
String retVal = opcItemName;
|
||||||
while (retVal.startsWith(FORWARD_SLASH))
|
while (retVal.startsWith(FORWARD_SLASH))
|
||||||
retVal = retVal.substring(1);
|
retVal = retVal.substring(1);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an OPC item name into a zip URI by removing any leading forward
|
* Convert an OPC item name into a zip URI by removing any leading forward
|
||||||
* slash if it exist.
|
* slash if it exist.
|
||||||
*
|
*
|
||||||
* @param opcItemName
|
* @param opcItemName
|
||||||
* The OPC item name to convert.
|
* The OPC item name to convert.
|
||||||
* @return A zip URI without any leading slashes.
|
* @return A zip URI without any leading slashes.
|
||||||
*/
|
*/
|
||||||
public static URI getZipURIFromOPCName(String opcItemName) {
|
public static URI getZipURIFromOPCName(String opcItemName) {
|
||||||
if (opcItemName == null)
|
if (opcItemName == null)
|
||||||
throw new IllegalArgumentException("opcItemName");
|
throw new IllegalArgumentException("opcItemName");
|
||||||
|
|
||||||
String retVal = opcItemName;
|
String retVal = opcItemName;
|
||||||
while (retVal.startsWith(FORWARD_SLASH))
|
while (retVal.startsWith(FORWARD_SLASH))
|
||||||
retVal = retVal.substring(1);
|
retVal = retVal.substring(1);
|
||||||
try {
|
try {
|
||||||
return new URI(retVal);
|
return new URI(retVal);
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the specified file as a zip, or returns null if no such file exists
|
* Opens the specified file as a zip, or returns null if no such file exists
|
||||||
*
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* The file to open.
|
* The file to open.
|
||||||
* @return The zip archive freshly open.
|
* @return The zip archive freshly open.
|
||||||
*/
|
*/
|
||||||
public static ZipFile openZipFile(File file) throws IOException {
|
public static ZipFile openZipFile(File file) throws IOException {
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ZipSecureFile(file);
|
return new ZipSecureFile(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve and open a zip file with the specified path.
|
* Retrieve and open a zip file with the specified path.
|
||||||
*
|
*
|
||||||
* @param path
|
* @param path
|
||||||
* The file path.
|
* The file path.
|
||||||
* @return The zip archive freshly open.
|
* @return The zip archive freshly open.
|
||||||
*/
|
*/
|
||||||
public static ZipFile openZipFile(String path) throws IOException {
|
public static ZipFile openZipFile(String path) throws IOException {
|
||||||
File f = new File(path);
|
File f = new File(path);
|
||||||
|
|
||||||
if (!f.exists()) {
|
if (!f.exists()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ZipSecureFile(f);
|
return new ZipSecureFile(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user