pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1798982 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel: PDPageContentStream.java documentinterchange/logicalstructure/PDAttributeObject.java encryption/StandardSecurityHandler.java
Date Fri, 16 Jun 2017 20:17:18 GMT
Author: tilman
Date: Fri Jun 16 20:17:18 2017
New Revision: 1798982

URL: http://svn.apache.org/viewvc?rev=1798982&view=rev
Log:
PDFBOX-2852: use jdk7 syntax

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDAttributeObject.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java?rev=1798982&r1=1798981&r2=1798982&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java Fri
Jun 16 20:17:18 2017
@@ -966,17 +966,16 @@ public final class PDPageContentStream e
     @Deprecated
     public void fill(int windingRule) throws IOException
     {
-        if (windingRule == PathIterator.WIND_NON_ZERO)
+        switch (windingRule)
         {
-            fill();
-        }
-        else if (windingRule == PathIterator.WIND_EVEN_ODD)
-        {
-            fillEvenOdd();
-        }
-        else
-        {
-            throw new IllegalArgumentException("Error: unknown value for winding rule");
+            case PathIterator.WIND_NON_ZERO:
+                fill();
+                break;
+            case PathIterator.WIND_EVEN_ODD:
+                fillEvenOdd();
+                break;
+            default:
+                throw new IllegalArgumentException("Error: unknown value for winding rule");
         }
     }
 
@@ -1007,17 +1006,16 @@ public final class PDPageContentStream e
         {
             throw new IllegalStateException("Error: clipPath is not allowed within a text
block.");
         }
-        if (windingRule == PathIterator.WIND_NON_ZERO)
-        {
-            writeOperator("W");
-        }
-        else if (windingRule == PathIterator.WIND_EVEN_ODD)
-        {
-            writeOperator("W*");
-        }
-        else
+        switch (windingRule)
         {
-            throw new IllegalArgumentException("Error: unknown value for winding rule");
+            case PathIterator.WIND_NON_ZERO:
+                writeOperator("W");
+                break;
+            case PathIterator.WIND_EVEN_ODD:
+                writeOperator("W*");
+                break;
+            default:
+                throw new IllegalArgumentException("Error: unknown value for winding rule");
         }
         writeOperator("n");
     }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDAttributeObject.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDAttributeObject.java?rev=1798982&r1=1798981&r2=1798982&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDAttributeObject.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDAttributeObject.java
Fri Jun 16 20:17:18 2017
@@ -44,35 +44,31 @@ public abstract class PDAttributeObject
     public static PDAttributeObject create(COSDictionary dictionary)
     {
         String owner = dictionary.getNameAsString(COSName.O);
-        if (PDUserAttributeObject.OWNER_USER_PROPERTIES.equals(owner))
+        if (owner != null)
         {
-            return new PDUserAttributeObject(dictionary);
-        }
-        else if (PDListAttributeObject.OWNER_LIST.equals(owner))
-        {
-            return new PDListAttributeObject(dictionary);
-        }
-        else if (PDPrintFieldAttributeObject.OWNER_PRINT_FIELD.equals(owner))
-        {
-            return new PDPrintFieldAttributeObject(dictionary);
-        }
-        else if (PDTableAttributeObject.OWNER_TABLE.equals(owner))
-        {
-            return new PDTableAttributeObject(dictionary);
-        }
-        else if (PDLayoutAttributeObject.OWNER_LAYOUT.equals(owner))
-        {
-            return new PDLayoutAttributeObject(dictionary);
-        }
-        else if (PDExportFormatAttributeObject.OWNER_XML_1_00.equals(owner)
-            || PDExportFormatAttributeObject.OWNER_HTML_3_20.equals(owner)
-            || PDExportFormatAttributeObject.OWNER_HTML_4_01.equals(owner)
-            || PDExportFormatAttributeObject.OWNER_OEB_1_00.equals(owner)
-            || PDExportFormatAttributeObject.OWNER_RTF_1_05.equals(owner)
-            || PDExportFormatAttributeObject.OWNER_CSS_1_00.equals(owner)
-            || PDExportFormatAttributeObject.OWNER_CSS_2_00.equals(owner))
-        {
-            return new PDExportFormatAttributeObject(dictionary);
+            switch (owner)
+            {
+                case PDUserAttributeObject.OWNER_USER_PROPERTIES:
+                    return new PDUserAttributeObject(dictionary);
+                case PDListAttributeObject.OWNER_LIST:
+                    return new PDListAttributeObject(dictionary);
+                case PDPrintFieldAttributeObject.OWNER_PRINT_FIELD:
+                    return new PDPrintFieldAttributeObject(dictionary);
+                case PDTableAttributeObject.OWNER_TABLE:
+                    return new PDTableAttributeObject(dictionary);
+                case PDLayoutAttributeObject.OWNER_LAYOUT:
+                    return new PDLayoutAttributeObject(dictionary);
+                case PDExportFormatAttributeObject.OWNER_XML_1_00:
+                case PDExportFormatAttributeObject.OWNER_HTML_3_20:
+                case PDExportFormatAttributeObject.OWNER_HTML_4_01:
+                case PDExportFormatAttributeObject.OWNER_OEB_1_00:
+                case PDExportFormatAttributeObject.OWNER_RTF_1_05:
+                case PDExportFormatAttributeObject.OWNER_CSS_1_00:
+                case PDExportFormatAttributeObject.OWNER_CSS_2_00:
+                    return new PDExportFormatAttributeObject(dictionary);
+                default:
+                    break;
+            }
         }
         return new PDDefaultAttributeObject(dictionary);
     }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java?rev=1798982&r1=1798981&r2=1798982&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
Fri Jun 16 20:17:18 2017
@@ -927,43 +927,44 @@ public final class StandardSecurityHandl
                                   byte[] id, int encRevision, int length, boolean encryptMetadata)
                                   throws IOException
     {
-        if( encRevision == 2 )
+        switch (encRevision)
         {
-            byte[] passwordBytes = computeUserPassword( password, owner, permissions, id,
encRevision,
-                                                        length, encryptMetadata );
-            return Arrays.equals(user, passwordBytes);
-        }
-        else if( encRevision == 3 || encRevision == 4 )
-        {
-            byte[] passwordBytes = computeUserPassword( password, owner, permissions, id,
encRevision,
-                                                        length, encryptMetadata );
-            // compare first 16 bytes only
-            return Arrays.equals(Arrays.copyOf(user, 16), Arrays.copyOf(passwordBytes, 16));
-        }
-        else if (encRevision == 6 || encRevision == 5)
-        {
-            byte[] truncatedPassword = truncate127(password);
-            
-            byte[] uHash = new byte[32];
-            byte[] uValidationSalt = new byte[8];
-            System.arraycopy(user, 0, uHash, 0, 32);
-            System.arraycopy(user, 32, uValidationSalt, 0, 8);
-
-            byte[] hash;
-            if (encRevision == 5)
+            case 2:
             {
-                hash = computeSHA256(truncatedPassword, uValidationSalt, null);
+                byte[] passwordBytes = computeUserPassword(password, owner, permissions,
id, encRevision,
+                        length, encryptMetadata);
+                return Arrays.equals(user, passwordBytes);
             }
-            else
+            case 3:
+            case 4:
             {
-                hash = computeHash2A(truncatedPassword, uValidationSalt, null);
+                byte[] passwordBytes = computeUserPassword(password, owner, permissions,
id, encRevision,
+                        length, encryptMetadata);
+                // compare first 16 bytes only
+                return Arrays.equals(Arrays.copyOf(user, 16), Arrays.copyOf(passwordBytes,
16));
             }
+            case 5:
+            case 6:
+                byte[] truncatedPassword = truncate127(password);
 
-            return Arrays.equals(hash, uHash);
-        }
-        else
-        {
-            throw new IOException( "Unknown Encryption Revision " + encRevision );
+                byte[] uHash = new byte[32];
+                byte[] uValidationSalt = new byte[8];
+                System.arraycopy(user, 0, uHash, 0, 32);
+                System.arraycopy(user, 32, uValidationSalt, 0, 8);
+
+                byte[] hash;
+                if (encRevision == 5)
+                {
+                    hash = computeSHA256(truncatedPassword, uValidationSalt, null);
+                }
+                else
+                {
+                    hash = computeHash2A(truncatedPassword, uValidationSalt, null);
+                }
+
+                return Arrays.equals(hash, uHash);
+            default:
+                throw new IOException("Unknown Encryption Revision " + encRevision);
         }
     }
 



Mime
View raw message