]> source.dussan.org Git - poi.git/commitdiff
Fix inconsistent indents
authorNick Burch <nick@apache.org>
Tue, 15 Mar 2016 11:54:16 +0000 (11:54 +0000)
committerNick Burch <nick@apache.org>
Tue, 15 Mar 2016 11:54:16 +0000 (11:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1735061 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java

index e40f4ef3a62ef835ec7675fd1d996c62b96fffd5..ce6d26af829c1f5286af7f6264d9fd754cf8c3f1 100644 (file)
@@ -65,14 +65,14 @@ public final class ZipPackage extends Package {
      * Constructor. Creates a new, empty ZipPackage.
      */
     public ZipPackage() {
-       super(defaultPackageAccess);
-       this.zipArchive = null;
-       
-       try {
-           this.contentTypeManager = new ZipContentTypeManager(null, this);
-       } catch (InvalidFormatException e) {
-                       logger.log(POILogger.WARN,"Could not parse ZipPackage", e);
-               }
+        super(defaultPackageAccess);
+        this.zipArchive = null;
+
+        try {
+            this.contentTypeManager = new ZipContentTypeManager(null, this);
+        } catch (InvalidFormatException e) {
+            logger.log(POILogger.WARN,"Could not parse ZipPackage", e);
+        }
     }
 
     /**
@@ -88,10 +88,10 @@ public final class ZipPackage extends Package {
      *             ZipInputStream.
      */
     ZipPackage(InputStream in, PackageAccess access) throws IOException {
-       super(access);
-       InputStream zis = new ZipInputStream(in);
-       ThresholdInputStream tis = ZipSecureFile.addThreshold(zis);
-       this.zipArchive = new ZipInputStreamZipEntrySource(tis);
+        super(access);
+        InputStream zis = new ZipInputStream(in);
+        ThresholdInputStream tis = ZipSecureFile.addThreshold(zis);
+        this.zipArchive = new ZipInputStreamZipEntrySource(tis);
     }
 
     /**
@@ -103,18 +103,18 @@ public final class ZipPackage extends Package {
      *            The package access mode.
      */
     ZipPackage(String path, PackageAccess access) {
-       super(access);
+        super(access);
 
-       final ZipFile zipFile;
+        final ZipFile zipFile;
 
-       try {
-               zipFile = ZipHelper.openZipFile(path);
-       } catch (IOException e) {
-               throw new InvalidOperationException(
-                               "Can't open the specified file: '" + path + "'", e);
-       }
+        try {
+            zipFile = ZipHelper.openZipFile(path);
+        } catch (IOException e) {
+            throw new InvalidOperationException(
+                    "Can't open the specified file: '" + path + "'", e);
+        }
 
-       this.zipArchive = new ZipFileZipEntrySource(zipFile);
+        this.zipArchive = new ZipFileZipEntrySource(zipFile);
     }
 
     /**
@@ -126,18 +126,18 @@ public final class ZipPackage extends Package {
      *            The package access mode.
      */
     ZipPackage(File file, PackageAccess access) {
-       super(access);
+        super(access);
 
-       final ZipFile zipFile;
+        final ZipFile zipFile;
 
-       try {
-               zipFile = ZipHelper.openZipFile(file);
-       } catch (IOException e) {
-               throw new InvalidOperationException(
-                               "Can't open the specified file: '" + file + "'", e);
-       }
+        try {
+            zipFile = ZipHelper.openZipFile(file);
+        } catch (IOException e) {
+            throw new InvalidOperationException(
+                    "Can't open the specified file: '" + file + "'", e);
+        }
 
-       this.zipArchive = new ZipFileZipEntrySource(zipFile);
+        this.zipArchive = new ZipFileZipEntrySource(zipFile);
     }
 
     /**
@@ -151,207 +151,207 @@ public final class ZipPackage extends Package {
      *            The package access mode.
      */
     ZipPackage(ZipEntrySource zipEntry, PackageAccess access) {
-       super(access);
-       this.zipArchive = zipEntry;
+        super(access);
+        this.zipArchive = zipEntry;
     }
 
-       /**
-        * Retrieves the parts from this package. We assume that the package has not
-        * been yet inspect to retrieve all the parts, this method will open the
-        * archive and look for all parts contain inside it. If the package part
-        * list is not empty, it will be emptied.
-        *
-        * @return All parts contain in this package.
-        * @throws InvalidFormatException
-        *             Throws if the package is not valid.
-        */
-       @Override
-       protected PackagePart[] getPartsImpl() throws InvalidFormatException {
-               if (this.partList == null) {
-                       // The package has just been created, we create an empty part
-                       // list.
-                       this.partList = new PackagePartCollection();
-               }
-
-               if (this.zipArchive == null) {
-                       return this.partList.values().toArray(
-                                       new PackagePart[this.partList.values().size()]);
-               }
-               
-               // First we need to parse the content type part
-               Enumeration<? extends ZipEntry> entries = this.zipArchive.getEntries();
-               while (entries.hasMoreElements()) {
-                       ZipEntry entry = entries.nextElement();
-                       if (entry.getName().equalsIgnoreCase(
-                                       ContentTypeManager.CONTENT_TYPES_PART_NAME)) {
-                               try {
-                                       this.contentTypeManager = new ZipContentTypeManager(
-                                                       getZipArchive().getInputStream(entry), this);
-                               } catch (IOException e) {
-                                       throw new InvalidFormatException(e.getMessage());
-                               }
-                               break;
-                       }
-               }
-
-               // At this point, we should have loaded the content type part
-               if (this.contentTypeManager == null) {
-                   // Is it a different Zip-based format?
-                   boolean hasMimetype = false;
-                   boolean hasSettingsXML = false;
-                   entries = this.zipArchive.getEntries();
-               while (entries.hasMoreElements()) {
-                   ZipEntry entry = entries.nextElement();
-                   if (entry.getName().equals("mimetype")) {
-                       hasMimetype = true;
-                   }
+    /**
+     * Retrieves the parts from this package. We assume that the package has not
+     * been yet inspect to retrieve all the parts, this method will open the
+     * archive and look for all parts contain inside it. If the package part
+     * list is not empty, it will be emptied.
+     *
+     * @return All parts contain in this package.
+     * @throws InvalidFormatException
+     *             Throws if the package is not valid.
+     */
+    @Override
+    protected PackagePart[] getPartsImpl() throws InvalidFormatException {
+        if (this.partList == null) {
+            // The package has just been created, we create an empty part
+            // list.
+            this.partList = new PackagePartCollection();
+        }
+
+        if (this.zipArchive == null) {
+            return this.partList.values().toArray(
+                    new PackagePart[this.partList.values().size()]);
+        }
+
+        // First we need to parse the content type part
+        Enumeration<? extends ZipEntry> entries = this.zipArchive.getEntries();
+        while (entries.hasMoreElements()) {
+            ZipEntry entry = entries.nextElement();
+            if (entry.getName().equalsIgnoreCase(
+                    ContentTypeManager.CONTENT_TYPES_PART_NAME)) {
+                try {
+                    this.contentTypeManager = new ZipContentTypeManager(
+                            getZipArchive().getInputStream(entry), this);
+                } catch (IOException e) {
+                    throw new InvalidFormatException(e.getMessage());
+                }
+                break;
+            }
+        }
+
+        // At this point, we should have loaded the content type part
+        if (this.contentTypeManager == null) {
+            // Is it a different Zip-based format?
+            boolean hasMimetype = false;
+            boolean hasSettingsXML = false;
+            entries = this.zipArchive.getEntries();
+            while (entries.hasMoreElements()) {
+                ZipEntry entry = entries.nextElement();
+                if (entry.getName().equals("mimetype")) {
+                    hasMimetype = true;
+                }
                 if (entry.getName().equals("settings.xml")) {
                     hasSettingsXML = true;
                 }
-               }
-               if (hasMimetype && hasSettingsXML) {
-                   throw new ODFNotOfficeXmlFileException(
-                      "The supplied data appears to be in ODF (Open Document) Format. " +
-                      "Formats like these (eg ODS, ODP) are not supported, try Apache ODFToolkit");
-               }
-                   
-                   // Fallback exception
-                       throw new InvalidFormatException(
-                                       "Package should contain a content type part [M1.13]");
-               }
-
-               // Now create all the relationships
-               // (Need to create relationships before other
-               //  parts, otherwise we might create a part before
-               //  its relationship exists, and then it won't tie up)
-               entries = this.zipArchive.getEntries();
-               while (entries.hasMoreElements()) {
-                       ZipEntry entry = entries.nextElement();
-                       PackagePartName partName = buildPartName(entry);
-                       if(partName == null) continue;
-
-                       // Only proceed for Relationships at this stage
-                       String contentType = contentTypeManager.getContentType(partName);
-                       if (contentType != null && contentType.equals(ContentTypes.RELATIONSHIPS_PART)) {
-                               try {
-                                       partList.put(partName, new ZipPackagePart(this, entry,
-                                               partName, contentType));
-                               } catch (InvalidOperationException e) {
-                                       throw new InvalidFormatException(e.getMessage());
-                               }
-                       }
-               }
-
-               // Then we can go through all the other parts
-               entries = this.zipArchive.getEntries();
-               while (entries.hasMoreElements()) {
-                       ZipEntry entry = entries.nextElement();
-                       PackagePartName partName = buildPartName(entry);
-                       if(partName == null) continue;
-
-                       String contentType = contentTypeManager
-                                       .getContentType(partName);
-                       if (contentType != null && contentType.equals(ContentTypes.RELATIONSHIPS_PART)) {
-                               // Already handled
-                       }
-                       else if (contentType != null) {
-                               try {
-                                       partList.put(partName, new ZipPackagePart(this, entry,
-                                                       partName, contentType));
-                               } catch (InvalidOperationException e) {
-                                       throw new InvalidFormatException(e.getMessage());
-                               }
-                       } else {
-                               throw new InvalidFormatException(
-                                               "The part "
-                                                               + partName.getURI().getPath()
-                                                               + " does not have any content type ! Rule: Package require content types when retrieving a part from a package. [M.1.14]");
-                       }
-               }
-
-               return partList.values().toArray(new ZipPackagePart[partList.size()]);
-       }
-
-       /**
-        * Builds a PackagePartName for the given ZipEntry,
-        *  or null if it's the content types / invalid part
-        */
-       private PackagePartName buildPartName(ZipEntry entry) {
-               try {
-                       // We get an error when we parse [Content_Types].xml
-                       // because it's not a valid URI.
-                       if (entry.getName().equalsIgnoreCase(
-                                       ContentTypeManager.CONTENT_TYPES_PART_NAME)) {
-                               return null;
-                       }
-                       return PackagingURIHelper.createPartName(ZipHelper
-                                       .getOPCNameFromZipItemName(entry.getName()));
-               } catch (Exception e) {
-                       // We assume we can continue, even in degraded mode ...
-                       logger.log(POILogger.WARN,"Entry "
-                                                       + entry.getName()
-                                                       + " is not valid, so this part won't be add to the package.", e);
-                       return null;
-               }
-       }
-
-       /**
-        * Create a new MemoryPackagePart from the specified URI and content type
-        *
-        *
-        * aram partName The part URI.
-        *
-        * @param contentType
-        *            The part content type.
-        * @return The newly created zip package part, else <b>null</b>.
-        */
-       @Override
-       protected PackagePart createPartImpl(PackagePartName partName,
-                       String contentType, boolean loadRelationships) {
-               if (contentType == null)
-                       throw new IllegalArgumentException("contentType");
+            }
+            if (hasMimetype && hasSettingsXML) {
+                throw new ODFNotOfficeXmlFileException(
+                   "The supplied data appears to be in ODF (Open Document) Format. " +
+                   "Formats like these (eg ODS, ODP) are not supported, try Apache ODFToolkit");
+            }
+
+            // Fallback exception
+            throw new InvalidFormatException(
+                    "Package should contain a content type part [M1.13]");
+        }
+
+        // Now create all the relationships
+        // (Need to create relationships before other
+        //  parts, otherwise we might create a part before
+        //  its relationship exists, and then it won't tie up)
+        entries = this.zipArchive.getEntries();
+        while (entries.hasMoreElements()) {
+            ZipEntry entry = entries.nextElement();
+            PackagePartName partName = buildPartName(entry);
+            if(partName == null) continue;
+
+            // Only proceed for Relationships at this stage
+            String contentType = contentTypeManager.getContentType(partName);
+            if (contentType != null && contentType.equals(ContentTypes.RELATIONSHIPS_PART)) {
+                try {
+                    partList.put(partName, new ZipPackagePart(this, entry,
+                                                              partName, contentType));
+                } catch (InvalidOperationException e) {
+                    throw new InvalidFormatException(e.getMessage());
+                }
+            }
+        }
+
+        // Then we can go through all the other parts
+        entries = this.zipArchive.getEntries();
+        while (entries.hasMoreElements()) {
+            ZipEntry entry = entries.nextElement();
+            PackagePartName partName = buildPartName(entry);
+            if(partName == null) continue;
+
+            String contentType = contentTypeManager
+                    .getContentType(partName);
+            if (contentType != null && contentType.equals(ContentTypes.RELATIONSHIPS_PART)) {
+                // Already handled
+            }
+            else if (contentType != null) {
+                try {
+                    partList.put(partName, new ZipPackagePart(this, entry,
+                            partName, contentType));
+                } catch (InvalidOperationException e) {
+                    throw new InvalidFormatException(e.getMessage());
+                }
+            } else {
+                throw new InvalidFormatException(
+                        "The part "
+                                + partName.getURI().getPath()
+                                + " does not have any content type ! Rule: Package require content types when retrieving a part from a package. [M.1.14]");
+            }
+        }
+
+        return partList.values().toArray(new ZipPackagePart[partList.size()]);
+    }
 
-               if (partName == null)
-                       throw new IllegalArgumentException("partName");
+    /**
+     * Builds a PackagePartName for the given ZipEntry,
+     *  or null if it's the content types / invalid part
+     */
+    private PackagePartName buildPartName(ZipEntry entry) {
+        try {
+            // We get an error when we parse [Content_Types].xml
+            // because it's not a valid URI.
+            if (entry.getName().equalsIgnoreCase(
+                    ContentTypeManager.CONTENT_TYPES_PART_NAME)) {
+                return null;
+            }
+            return PackagingURIHelper.createPartName(ZipHelper
+                    .getOPCNameFromZipItemName(entry.getName()));
+        } catch (Exception e) {
+            // We assume we can continue, even in degraded mode ...
+            logger.log(POILogger.WARN,"Entry "
+                                      + entry.getName()
+                                      + " is not valid, so this part won't be add to the package.", e);
+            return null;
+        }
+    }
 
-               try {
-                       return new MemoryPackagePart(this, partName, contentType,
-                                       loadRelationships);
-               } catch (InvalidFormatException e) {
-                       logger.log(POILogger.WARN, e);
-                       return null;
-               }
-       }
+    /**
+     * Create a new MemoryPackagePart from the specified URI and content type
+     *
+     *
+     * aram partName The part URI.
+     *
+     * @param contentType
+     *            The part content type.
+     * @return The newly created zip package part, else <b>null</b>.
+     */
+    @Override
+    protected PackagePart createPartImpl(PackagePartName partName,
+            String contentType, boolean loadRelationships) {
+        if (contentType == null)
+            throw new IllegalArgumentException("contentType");
+
+        if (partName == null)
+            throw new IllegalArgumentException("partName");
+
+        try {
+            return new MemoryPackagePart(this, partName, contentType,
+                    loadRelationships);
+        } catch (InvalidFormatException e) {
+            logger.log(POILogger.WARN, e);
+            return null;
+        }
+    }
 
-       /**
-        * Delete a part from the package
-        *
-        * @throws IllegalArgumentException
-        *             Throws if the part URI is nulll or invalid.
-        */
-       @Override
-       protected void removePartImpl(PackagePartName partName) {
-               if (partName == null)
-                       throw new IllegalArgumentException("partUri");
-       }
+    /**
+     * Delete a part from the package
+     *
+     * @throws IllegalArgumentException
+     *             Throws if the part URI is nulll or invalid.
+     */
+    @Override
+    protected void removePartImpl(PackagePartName partName) {
+        if (partName == null)
+            throw new IllegalArgumentException("partUri");
+    }
 
-       /**
-        * Flush the package. Do nothing.
-        */
-       @Override
-       protected void flushImpl() {
-               // Do nothing
-       }
+    /**
+     * Flush the package. Do nothing.
+     */
+    @Override
+    protected void flushImpl() {
+        // Do nothing
+    }
 
-       /**
-        * Close and save the package.
-        *
-        * @see #close()
-        */
-       @Override
-       protected void closeImpl() throws IOException {
-               // Flush the package
-               flush();
+    /**
+     * Close and save the package.
+     *
+     * @see #close()
+     */
+    @Override
+    protected void closeImpl() throws IOException {
+        // Flush the package
+        flush();
 
                // Save the content
                if (this.originalPackagePath != null
@@ -418,20 +418,20 @@ public final class ZipPackage extends Package {
                }
        }
 
-       /**
-        * Implement the getPart() method to retrieve a part from its URI in the
-        * current package
-        *
-        *
-        * @see #getPart(PackageRelationship)
-        */
-       @Override
-       protected PackagePart getPartImpl(PackagePartName partName) {
-               if (partList.containsKey(partName)) {
-                       return partList.get(partName);
-               }
-               return null;
-       }
+    /**
+     * Implement the getPart() method to retrieve a part from its URI in the
+     * current package
+     *
+     *
+     * @see #getPart(PackageRelationship)
+     */
+    @Override
+    protected PackagePart getPartImpl(PackagePartName partName) {
+        if (partList.containsKey(partName)) {
+            return partList.get(partName);
+        }
+        return null;
+    }
 
        /**
         * Save this package into the specified stream
@@ -525,14 +525,14 @@ public final class ZipPackage extends Package {
                     "Fail to save: an error occurs while saving the package : "
                                                        + e.getMessage(), e);
                }
-       }
+    }
 
-       /**
-        * Get the zip archive
-        *
-        * @return The zip archive.
-        */
-       public ZipEntrySource getZipArchive() {
-               return zipArchive;
-       }
+    /**
+     * Get the zip archive
+     *
+     * @return The zip archive.
+     */
+    public ZipEntrySource getZipArchive() {
+        return zipArchive;
+    }
 }