pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1692571 - in /pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane: OperatorMarker.java StreamPane.java
Date Fri, 24 Jul 2015 19:29:13 GMT
Author: tilman
Date: Fri Jul 24 19:29:13 2015
New Revision: 1692571

URL: http://svn.apache.org/r1692571
Log:
PDFBOX-2530: fix SonarQube issues, as done by Khyrul Bashar in GSoC2015

Modified:
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/OperatorMarker.java
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPane.java

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/OperatorMarker.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/OperatorMarker.java?rev=1692571&r1=1692570&r2=1692571&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/OperatorMarker.java
(original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/OperatorMarker.java
Fri Jul 24 19:29:13 2015
@@ -29,15 +29,18 @@ import javax.swing.text.StyleContext;
  */
 final class OperatorMarker
 {
-    private Map<String, Style> operatorStyleMap;
+    public static final String BEGIN_TEXT_OBJECT = "BT";
+    public static final String END_TEXT_OBJECT = "ET";
+    public static final String SAVE_GRAPHICS_STATE = "q";
+    public static final String RESTORE_GRAPHICS_STATE = "Q";
+    public static final String CONCAT = "cm";
+    public static final String INLINE_IMAGE_BEGIN = "BI";
+    public static final String IMAGE_DATA = "ID";
+    public static final String INLINE_IMAGE_END = "EI";
 
-    OperatorMarker()
-    {
-        operatorStyleMap = new HashMap<String, Style>();
-        initOperatorStyles();
-    }
+    private static final Map<String, Style> operatorStyleMap;
 
-    private void initOperatorStyles()
+    static
     {
         StyleContext styleContext = StyleContext.getDefaultStyleContext();
 
@@ -59,27 +62,25 @@ final class OperatorMarker
         Style imageData = styleContext.addStyle("ID", common);
         StyleConstants.setForeground(imageData, new Color(255, 165, 0));
 
-        final String BEGIN_TEXT_OBJECT = "BT";
-        final String END_TEXT_OBJECT = "ET";
-        final String SAVE_GRAPHICS_STATE = "q";
-        final String RESTORE_GRAPHICS_STATE = "Q";
-        final String CONCAT = "cm";
-        final String INLINE_IMAGE_BEGIN = "BI";
-        final String IMAGE_DATA = "ID";
-        final String INLINE_IMAGE_END = "EI";
-
-
-        operatorStyleMap.put(BEGIN_TEXT_OBJECT, textObjectStyle);
-        operatorStyleMap.put(END_TEXT_OBJECT, textObjectStyle);
-        operatorStyleMap.put(SAVE_GRAPHICS_STATE, graphicsStyle);
-        operatorStyleMap.put(RESTORE_GRAPHICS_STATE, graphicsStyle);
-        operatorStyleMap.put(CONCAT, concatStyle);
-        operatorStyleMap.put(INLINE_IMAGE_BEGIN, inlineImage);
-        operatorStyleMap.put(IMAGE_DATA, imageData);
-        operatorStyleMap.put(INLINE_IMAGE_END, inlineImage);
+        Map<String, Style> styleMap = new HashMap<String, Style>();
+
+        styleMap.put(BEGIN_TEXT_OBJECT, textObjectStyle);
+        styleMap.put(END_TEXT_OBJECT, textObjectStyle);
+        styleMap.put(SAVE_GRAPHICS_STATE, graphicsStyle);
+        styleMap.put(RESTORE_GRAPHICS_STATE, graphicsStyle);
+        styleMap.put(CONCAT, concatStyle);
+        styleMap.put(INLINE_IMAGE_BEGIN, inlineImage);
+        styleMap.put(IMAGE_DATA, imageData);
+        styleMap.put(INLINE_IMAGE_END, inlineImage);
+
+        operatorStyleMap = styleMap;
+    }
+
+    private OperatorMarker()
+    {
     }
 
-    Style getStyle(String operator)
+    public static Style getStyle(String operator)
     {
         if (operatorStyleMap.containsKey(operator))
         {

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPane.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPane.java?rev=1692571&r1=1692570&r2=1692571&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPane.java
(original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/streampane/StreamPane.java
Fri Jul 24 19:29:13 2015
@@ -128,8 +128,6 @@ public class StreamPane implements Actio
     {
 
         private final String filterKey;
-        private StyledDocument docu;
-        OperatorMarker marker;
 
         private DocumentCreator(String filterKey)
         {
@@ -200,7 +198,7 @@ public class StreamPane implements Actio
         private StyledDocument getDocument(InputStream inputStream)
         {
             String data = getStringOfStream(inputStream);
-            docu = new DefaultStyledDocument();
+            StyledDocument docu = new DefaultStyledDocument();
             try
             {
                 docu.insertString(0, data, null);
@@ -214,8 +212,7 @@ public class StreamPane implements Actio
 
         private StyledDocument getContentStreamDocument(InputStream inputStream)
         {
-            docu = new DefaultStyledDocument();
-            marker = new OperatorMarker();
+            StyledDocument docu = new DefaultStyledDocument();
 
             PDFStreamParser parser;
             try
@@ -230,12 +227,12 @@ public class StreamPane implements Actio
 
             for (Object obj : parser.getTokens())
             {
-                writeObject(obj);
+                writeObject(obj, docu);
             }
             return docu;
         }
 
-        private void writeObject(Object obj)
+        private void writeObject(Object obj, StyledDocument docu)
         {
             try
             {
@@ -244,24 +241,27 @@ public class StreamPane implements Actio
                     Operator op = (Operator) obj;
                     if (op.getName().equals("BI"))
                     {
-                        docu.insertString(docu.getLength(), "BI" + "\n", marker.getStyle("BI"));
+                        docu.insertString(docu.getLength(), OperatorMarker.INLINE_IMAGE_BEGIN
+ "\n",
+                                OperatorMarker.getStyle(OperatorMarker.INLINE_IMAGE_BEGIN));
                         COSDictionary dic = op.getImageParameters();
                         for (COSName key : dic.keySet())
                         {
                             Object value = dic.getDictionaryObject(key);
                             docu.insertString(docu.getLength(), "/" + key.getName() + " ",
null);
-                            writeObject(value);
+                            writeObject(value, docu);
                             docu.insertString(docu.getLength(), "\n", null);
                         }
-                        docu.insertString(docu.getLength(), "ID\n", marker.getStyle("ID"));
-                        docu.insertString(docu.getLength(), new String(op.getImageData()),
null);
+                        docu.insertString(docu.getLength(), OperatorMarker.IMAGE_DATA +"\n",
+                                OperatorMarker.getStyle(OperatorMarker.IMAGE_DATA));
+                        docu.insertString(docu.getLength(), new String(op.getImageData(),
"ISO-8859-1"), null);
                         docu.insertString(docu.getLength(), "\n", null);
-                        docu.insertString(docu.getLength(), "EI\n", marker.getStyle("EI"));
+                        docu.insertString(docu.getLength(), OperatorMarker.INLINE_IMAGE_END
+"\n",
+                                OperatorMarker.getStyle(OperatorMarker.INLINE_IMAGE_END));
                     }
                     else
                     {
                         String operator = ((Operator) obj).getName();
-                        docu.insertString(docu.getLength(), operator + "\n", marker.getStyle(operator));
+                        docu.insertString(docu.getLength(), operator + "\n", OperatorMarker.getStyle(operator));
                     }
                 }
                 else
@@ -301,6 +301,10 @@ public class StreamPane implements Actio
             {
                 e.printStackTrace();
             }
+            catch (UnsupportedEncodingException e)
+            {
+                e.printStackTrace();
+            }
         }
 
         private String getCOSValue(Object obj)



Mime
View raw message