make code more similar between default case and indexed case

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1765536 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-10-19 06:44:09 +00:00
parent 09c13eeefa
commit eada340cbd

View File

@ -559,9 +559,10 @@ public class POIXMLDocumentPart {
OPCPackage pkg = packagePart.getPackage(); OPCPackage pkg = packagePart.getPackage();
try { try {
if (descriptor.getDefaultFileName().equals(descriptor.getFileName(9999))) { String name = descriptor.getDefaultFileName();
if (name.equals(descriptor.getFileName(9999))) {
// Non-index based, check if default is free // Non-index based, check if default is free
PackagePartName ppName = PackagingURIHelper.createPartName(descriptor.getDefaultFileName()); PackagePartName ppName = PackagingURIHelper.createPartName(name);
if (pkg.containPart(ppName)) { if (pkg.containPart(ppName)) {
// Default name already taken, not index based, nothing free // Default name already taken, not index based, nothing free
return -1; return -1;
@ -575,8 +576,9 @@ public class POIXMLDocumentPart {
int idx = minIdx; int idx = minIdx;
if (minIdx < 0) idx = 1; if (minIdx < 0) idx = 1;
while (idx < 1000) { while (idx < 1000) {
String name = descriptor.getFileName(idx); name = descriptor.getFileName(idx);
if (!pkg.containPart(PackagingURIHelper.createPartName(name))) { PackagePartName ppName = PackagingURIHelper.createPartName(name);
if (!pkg.containPart(ppName)) {
return idx; return idx;
} }
idx++; idx++;