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:
Nick Burch 2016-03-15 11:56:28 +00:00
parent 5f2f0adfae
commit 0fab07ccfc

View File

@ -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))
return entry;
}
return null;
}
// Enumerate through the Zip entries until we find the one named /**
// '[Content_Types].xml'. * Convert a zip name into an OPC name by adding a leading forward slash to
while (entries.hasMoreElements()) { * the specified item name.
ZipEntry entry = entries.nextElement(); *
if (entry.getName().equals( * @param zipItemName
ContentTypeManager.CONTENT_TYPES_PART_NAME)) * Zip item name to convert.
return entry; * @return An OPC compliant name.
} */
return null; public static String getOPCNameFromZipItemName(String zipItemName) {
} if (zipItemName == null)
throw new IllegalArgumentException("zipItemName");
if (zipItemName.startsWith(FORWARD_SLASH)) {
return zipItemName;
}
return FORWARD_SLASH + zipItemName;
}
/** /**
* Convert a zip name into an OPC name by adding a leading forward slash to * Convert an OPC item name into a zip item name by removing any leading
* the specified item name. * forward slash if it exist.
* *
* @param zipItemName * @param opcItemName
* Zip item name to convert. * The OPC item name to convert.
* @return An OPC compliant name. * @return A zip item name without any leading slashes.
*/ */
public static String getOPCNameFromZipItemName(String zipItemName) { public static String getZipItemNameFromOPCName(String opcItemName) {
if (zipItemName == null) if (opcItemName == null)
throw new IllegalArgumentException("zipItemName"); throw new IllegalArgumentException("opcItemName");
if (zipItemName.startsWith(FORWARD_SLASH)) {
return zipItemName;
}
return FORWARD_SLASH + zipItemName;
}
/** String retVal = opcItemName;
* Convert an OPC item name into a zip item name by removing any leading while (retVal.startsWith(FORWARD_SLASH))
* forward slash if it exist. retVal = retVal.substring(1);
* return retVal;
* @param opcItemName }
* The OPC item name to convert.
* @return A zip item name without any leading slashes.
*/
public static String getZipItemNameFromOPCName(String opcItemName) {
if (opcItemName == null)
throw new IllegalArgumentException("opcItemName");
String retVal = opcItemName; /**
while (retVal.startsWith(FORWARD_SLASH)) * Convert an OPC item name into a zip URI by removing any leading forward
retVal = retVal.substring(1); * slash if it exist.
return retVal; *
} * @param opcItemName
* The OPC item name to convert.
* @return A zip URI without any leading slashes.
*/
public static URI getZipURIFromOPCName(String opcItemName) {
if (opcItemName == null)
throw new IllegalArgumentException("opcItemName");
/** String retVal = opcItemName;
* Convert an OPC item name into a zip URI by removing any leading forward while (retVal.startsWith(FORWARD_SLASH))
* slash if it exist. retVal = retVal.substring(1);
* try {
* @param opcItemName return new URI(retVal);
* The OPC item name to convert. } catch (URISyntaxException e) {
* @return A zip URI without any leading slashes. return null;
*/ }
public static URI getZipURIFromOPCName(String opcItemName) { }
if (opcItemName == null)
throw new IllegalArgumentException("opcItemName");
String retVal = opcItemName; /**
while (retVal.startsWith(FORWARD_SLASH)) * Opens the specified file as a zip, or returns null if no such file exists
retVal = retVal.substring(1); *
try { * @param file
return new URI(retVal); * The file to open.
} catch (URISyntaxException e) { * @return The zip archive freshly open.
return null; */
} public static ZipFile openZipFile(File file) throws IOException {
} if (!file.exists()) {
return null;
}
/** return new ZipSecureFile(file);
* Opens the specified file as a zip, or returns null if no such file exists }
*
* @param file
* The file to open.
* @return The zip archive freshly open.
*/
public static ZipFile openZipFile(File file) throws IOException {
if (!file.exists()) {
return null;
}
return new ZipSecureFile(file); /**
} * Retrieve and open a zip file with the specified path.
*
* @param path
* The file path.
* @return The zip archive freshly open.
*/
public static ZipFile openZipFile(String path) throws IOException {
File f = new File(path);
/** if (!f.exists()) {
* Retrieve and open a zip file with the specified path. return null;
* }
* @param path
* The file path.
* @return The zip archive freshly open.
*/
public static ZipFile openZipFile(String path) throws IOException {
File f = new File(path);
if (!f.exists()) { return new ZipSecureFile(f);
return null; }
}
return new ZipSecureFile(f);
}
} }