pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1576439 - in /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox: encoding/Encoding.java pdfparser/BaseParser.java util/PDFStreamEngine.java util/PDFTextStripper.java util/ResourceLoader.java
Date Tue, 11 Mar 2014 17:52:49 GMT
Author: tilman
Date: Tue Mar 11 17:52:49 2014
New Revision: 1576439

URL: http://svn.apache.org/r1576439
Log:
PDFBOX-1946: catch SecurityException and resulting null values when run in an applet

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/encoding/Encoding.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/ResourceLoader.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/encoding/Encoding.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/encoding/Encoding.java?rev=1576439&r1=1576438&r2=1576439&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/encoding/Encoding.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/encoding/Encoding.java Tue
Mar 11 17:52:49 2014
@@ -75,15 +75,22 @@ public abstract class Encoding implement
         loadGlyphList("org/apache/pdfbox/resources/additional_glyphlist.txt");
 
         // Load an external glyph list file that user can give as JVM property
-        String location = System.getProperty("glyphlist_ext");
-        if(location != null)
+        try
         {
-            File external = new File(location);
-            if(external.exists())
+            String location = System.getProperty("glyphlist_ext");
+            if(location != null)
             {
-                loadGlyphList(location);
+                File external = new File(location);
+                if(external.exists())
+                {
+                    loadGlyphList(location);
+                }
             }
         }
+        catch (SecurityException e)  // can occur on Sytem.getProperty
+        {
+            // PDFBOX-1946 ignore and continue
+        }
 
         NAME_TO_CHARACTER.put( NOTDEF, "" );
         NAME_TO_CHARACTER.put( "fi", "fi" );

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java?rev=1576439&r1=1576438&r2=1576439&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java Tue
Mar 11 17:52:49 2014
@@ -128,9 +128,22 @@ public abstract class BaseParser
     /**
      * Default value of the {@link #forceParsing} flag.
      */
-    protected static final boolean FORCE_PARSING =
-        Boolean.getBoolean("org.apache.pdfbox.forceParsing");
+    static boolean FORCE_PARSING = true;
 
+    static
+    {
+        // get preferences value for force parsing
+        try
+        {
+            FORCE_PARSING = Boolean.getBoolean("org.apache.pdfbox.forceParsing");
+        }
+        catch (SecurityException e)  
+        {
+            // PDFBOX-1946 since Boolean.getBoolean calls System.getProperty, this can occur
+            /* ignore and use default */
+        }
+    }
+    
     /**
      * This is the stream that will be read from.
      */
@@ -166,8 +179,17 @@ public abstract class BaseParser
     public BaseParser(InputStream input, boolean forceParsingValue)
             throws IOException
     {
+    	int pushbacksize = 65536;
+    	try
+		{
+			pushbacksize = Integer.getInteger( PROP_PUSHBACK_SIZE, 65536 );
+		}
+		catch (SecurityException e)  // getInteger calls System.getProperties, which can get exception
+		{
+			// ignore and use default
+		}
         this.pdfSource = new PushBackInputStream(
-                new BufferedInputStream(input, 16384),  Integer.getInteger( PROP_PUSHBACK_SIZE,
65536 ) );
+        		new BufferedInputStream(input, 16384), pushbacksize );
         this.forceParsing = forceParsingValue;
     }
 

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java?rev=1576439&r1=1576438&r2=1576439&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java Tue
Mar 11 17:52:49 2014
@@ -348,24 +348,29 @@ public class PDFStreamEngine
             glyphSpaceToTextSpaceFactor = 1f/fontMatrix.getValue( 0, 0 );
         }
         float spaceWidthText=0;
-        try
-        {   
-            // to avoid crash as described in PDFBOX-614
-            // lets see what the space displacement should be
-            spaceWidthText = (font.getSpaceWidth()*glyphSpaceToTextSpaceFactor);
-        }
-        catch (Throwable exception)
+        if (font != null) // PDFBOX-1946 font might still be null if in applet
         {
-            LOG.warn( exception, exception);
+            try
+            {
+                // to avoid crash as described in PDFBOX-614
+                // lets see what the space displacement should be
+                spaceWidthText = (font.getSpaceWidth() * glyphSpaceToTextSpaceFactor);
+            }
+            catch (Throwable exception)
+            {
+                LOG.warn(exception, exception);
+            }
         }
         
         if( spaceWidthText == 0 )
         {
             spaceWidthText = (font.getAverageFontWidth()*glyphSpaceToTextSpaceFactor);
-            //The average space width appears to be higher than necessary
-            //so lets make it a little bit smaller.
+            // The average space width appears to be higher than necessary
+            // so lets make it a little bit smaller.
             spaceWidthText *= .80f;
         }
+        else 
+            spaceWidthText=1.0f; // if could not find font, use a generic value
         
         float maxVerticalDisplacementText = 0;
 

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java?rev=1576439&r1=1576438&r2=1576439&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java Tue
Mar 11 17:52:49 2014
@@ -75,30 +75,39 @@ public class PDFTextStripper extends PDF
     //    pdftextstripper.drop
     static
     {
-        String prop = thisClassName+".indent";
-        String s = System.getProperty(prop);
-        if(s!=null && s.length()>0)
+        String sdrop = null, sindent = null;
+        try
+        {
+            String prop = thisClassName + ".indent";
+            sindent = System.getProperty(prop);
+            prop = thisClassName + ".drop";
+            sdrop = System.getProperty(prop);
+        }
+        catch (SecurityException e)
+        {
+            // PDFBOX-1946 when run in an applet
+            // ignore and use default
+        }
+        if (sindent != null && sindent.length() > 0)
         {
             try
             {
-                float f = Float.parseFloat(s);
+                float f = Float.parseFloat(sindent);
                 DEFAULT_INDENT_THRESHOLD = f;
             }
-            catch(NumberFormatException nfe)
+            catch (NumberFormatException nfe)
             {
-                        //ignore and use default
+                //ignore and use default
             }
         }
-        prop = thisClassName+".drop";
-        s = System.getProperty(prop);
-        if(s!=null && s.length()>0)
+        if (sdrop != null && sdrop.length() > 0)
         {
             try
             {
-                float f = Float.parseFloat(s);
+                float f = Float.parseFloat(sdrop);
                 DEFAULT_DROP_THRESHOLD = f;
             }
-            catch(NumberFormatException nfe)
+            catch (NumberFormatException nfe)
             {
                 //ignore and use default
             }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/ResourceLoader.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/ResourceLoader.java?rev=1576439&r1=1576438&r2=1576439&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/ResourceLoader.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/ResourceLoader.java Tue
Mar 11 17:52:49 2014
@@ -51,8 +51,16 @@ public class ResourceLoader
      */
     public static InputStream loadResource( String resourceName ) throws IOException
     {
-        ClassLoader loader = ResourceLoader.class.getClassLoader();
-
+        ClassLoader loader = null;
+        try
+        {
+            loader = ResourceLoader.class.getClassLoader();
+        }
+        catch (SecurityException ex)
+        {
+            // PDFBOX-1946 ignore and try other alternatives
+        }
+   
         InputStream is = null;
 
         if( loader != null )
@@ -62,24 +70,31 @@ public class ResourceLoader
 
         //see sourceforge bug 863053, this is a fix for a user that
         //needed to have PDFBox loaded by the bootstrap classloader
-        if( is == null )
+        try
         {
-            loader = ClassLoader.getSystemClassLoader();
-            if( loader != null )
+            if (is == null)
             {
-                is = loader.getResourceAsStream( resourceName );
+                loader = ClassLoader.getSystemClassLoader();
+                if( loader != null )
+                {
+                    is = loader.getResourceAsStream( resourceName );
+                }
             }
-        }
 
-        if( is == null )
-        {
-            File f = new File( resourceName );
-            if( f.exists() )
+            if( is == null )
             {
-                is = new FileInputStream( f );
+                File f = new File( resourceName );
+                if( f.exists() )
+                {
+                  is = new FileInputStream( f );
+                }
             }
         }
-
+        catch (SecurityException ex)
+        {
+            // PDFBOX-1946 ignore and continue
+        }
+ 
         return is;
     }
 



Mime
View raw message