You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2016/03/10 18:37:45 UTC

svn commit: r1734436 - in /pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger: PDFDebugger.java flagbitspane/EncryptFlag.java flagbitspane/FlagBitsPane.java

Author: tilman
Date: Thu Mar 10 17:37:42 2016
New Revision: 1734436

URL: http://svn.apache.org/viewvc?rev=1734436&view=rev
Log:
PDFBOX-2941: support encrypt flags

Added:
    pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/flagbitspane/EncryptFlag.java   (with props)
Modified:
    pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
    pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/flagbitspane/FlagBitsPane.java

Modified: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java?rev=1734436&r1=1734435&r2=1734436&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java (original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java Thu Mar 10 17:37:42 2016
@@ -707,9 +707,21 @@ public class PDFDebugger extends JFrame
         if (selectedNode instanceof MapEntry)
         {
             Object key = ((MapEntry) selectedNode).getKey();
-            return (COSName.FLAGS.equals(key) && isFontDescriptor(parentNode))
-                    || (COSName.F.equals(key) && isAnnot(parentNode)) || COSName.FF.equals(key)
-                    || COSName.PANOSE.equals(key);
+            return (COSName.FLAGS.equals(key) && isFontDescriptor(parentNode)) || 
+                    (COSName.F.equals(key) && isAnnot(parentNode)) || 
+                    COSName.FF.equals(key) || 
+                    COSName.PANOSE.equals(key) ||
+                    (COSName.P.equals(key) && isEncrypt(parentNode));
+        }
+        return false;
+    }
+
+    private boolean isEncrypt(Object obj)
+    {
+        if (obj instanceof MapEntry)
+        {
+            MapEntry entry = (MapEntry) obj;
+            return (entry.getKey() instanceof COSName && entry.getValue() instanceof COSDictionary);
         }
         return false;
     }

Added: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/flagbitspane/EncryptFlag.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/flagbitspane/EncryptFlag.java?rev=1734436&view=auto
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/flagbitspane/EncryptFlag.java (added)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/flagbitspane/EncryptFlag.java Thu Mar 10 17:37:42 2016
@@ -0,0 +1,70 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements.  See the NOTICE file distributed with
+ *   this work for additional information regarding copyright ownership.
+ *   The ASF licenses this file to You under the Apache License, Version 2.0
+ *   (the "License"); you may not use this file except in compliance with
+ *   the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ */
+
+package org.apache.pdfbox.debugger.flagbitspane;
+
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
+
+/**
+ * @author Tilman Hausherr
+ *
+ * A class that provides Encrypt flag bits.
+ */
+public class EncryptFlag extends Flag
+{
+    private final COSDictionary encryptDictionary;
+
+    /**
+     * Constructor
+     * @param encryptDict COSDictionary instance.
+     */
+    EncryptFlag(COSDictionary encryptDict)
+    {
+        encryptDictionary = encryptDict;
+    }
+
+    @Override
+    String getFlagType()
+    {
+        return "Encrypt flag";
+    }
+
+    @Override
+    String getFlagValue()
+    {
+        return "Flag value:" + encryptDictionary.getInt(COSName.P);
+    }
+
+    @Override
+    Object[][] getFlagBits()
+    {
+        int p = encryptDictionary.getInt(COSName.P);
+        AccessPermission ap = new AccessPermission(encryptDictionary.getInt(COSName.P));
+        return new Object[][]{
+                new Object[]{3, "can print", ap.canPrint()},
+                new Object[]{4, "can modify", ap.canModify()},
+                new Object[]{5, "can extract content", ap.canExtractContent()},
+                new Object[]{6, "can modify annotations", ap.canModifyAnnotations()},
+                new Object[]{9, "can fill in form fields", ap.canFillInForm()},
+                new Object[]{10, "can extract for accessibility", ap.canExtractForAccessibility()},
+                new Object[]{11, "can assemble document", ap.canAssembleDocument()},
+                new Object[]{12, "can print degraded", ap.canPrintDegraded()},
+        };
+    }
+}

Propchange: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/flagbitspane/EncryptFlag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/flagbitspane/FlagBitsPane.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/flagbitspane/FlagBitsPane.java?rev=1734436&r1=1734435&r2=1734436&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/flagbitspane/FlagBitsPane.java (original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/flagbitspane/FlagBitsPane.java Thu Mar 10 17:37:42 2016
@@ -70,6 +70,13 @@ public class FlagBitsPane
             view = new FlagBitsPaneView(
                     flag.getFlagType(), flag.getFlagValue(), flag.getFlagBits(), flag.getColumnNames());
         }
+
+        if (COSName.P.equals(flagType))
+        {
+            flag = new EncryptFlag(dictionary);
+            view = new FlagBitsPaneView(
+                    flag.getFlagType(), flag.getFlagValue(), flag.getFlagBits(), flag.getColumnNames());
+        }
     }
 
     /**