pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1625840 - in /pdfbox/trunk: pdfbox/src/main/java/org/apache/pdfbox/encoding/ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/ pdfbox/src/main/java/org/apache/pdfbox/util/ p...
Date Wed, 17 Sep 2014 22:35:38 GMT
Author: jahewson
Date: Wed Sep 17 22:35:37 2014
New Revision: 1625840

URL: http://svn.apache.org/r1625840
Log:
PDFBOX-2358: Remove ResourceLoader usage in PDFBox

Added:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Version.java
Removed:
    pdfbox/trunk/pdfbox/src/main/resources/org/apache/pdfbox/resources/PDDeviceCMYK.properties
Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/encoding/GlyphList.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/ExternalFonts.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/ResourceLoader.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/Version.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/encoding/GlyphList.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/encoding/GlyphList.java?rev=1625840&r1=1625839&r2=1625840&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/encoding/GlyphList.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/encoding/GlyphList.java Wed Sep 17
22:35:37 2014
@@ -16,9 +16,9 @@
  */
 package org.apache.pdfbox.encoding;
 
+import java.net.URL;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.pdfbox.util.ResourceLoader;
 
 import java.io.File;
 import java.io.IOException;
@@ -41,35 +41,42 @@ public class GlyphList
 
     static
     {
-        DEFAULT = new GlyphList();
+        try
+        {
+            DEFAULT = new GlyphList();
 
-        // Loads the official glyph List based on adobes glyph list
-        DEFAULT.loadGlyphs("org/apache/pdfbox/resources/glyphlist.properties");
+            // Loads the official glyph List based on adobes glyph list
+            DEFAULT.loadGlyphs("org/apache/pdfbox/resources/glyphlist.properties");
 
-        // Loads some additional glyph mappings
-        DEFAULT.loadGlyphs("org/apache/pdfbox/resources/additional_glyphlist.properties");
+            // Loads some additional glyph mappings
+            DEFAULT.loadGlyphs("org/apache/pdfbox/resources/additional_glyphlist.properties");
 
-        // Load an external glyph list file that user can give as JVM property
-        try
-        {
-            String location = System.getProperty("glyphlist_ext");
-            if (location != null)
+            // Load an external glyph list file that user can give as JVM property
+            try
             {
-                File external = new File(location);
-                if (external.exists())
+                String location = System.getProperty("glyphlist_ext");
+                if (location != null)
                 {
-                    DEFAULT.loadGlyphs(location);
+                    File external = new File(location);
+                    if (external.exists())
+                    {
+                        DEFAULT.loadGlyphs(location);
+                    }
                 }
             }
+            catch (SecurityException e)  // can occur on System.getProperty
+            {
+                // PDFBOX-1946 ignore and continue
+            }
+
+            // Zapf Dingbats has its own glyph list
+            ZAPF_DINGBATS = new GlyphList();
+            ZAPF_DINGBATS.loadGlyphs("org/apache/pdfbox/resources/zapf_dingbats.properties");
         }
-        catch (SecurityException e)  // can occur on System.getProperty
+        catch (IOException e)
         {
-            // PDFBOX-1946 ignore and continue
+            throw new RuntimeException(e);
         }
-
-        // Zapf Dingbats has its own glyph list
-        ZAPF_DINGBATS = new GlyphList();
-        ZAPF_DINGBATS.loadGlyphs("org/apache/pdfbox/resources/zapf_dingbats.properties");
     }
 
     private final Map<String, String> nameToUnicode = new HashMap<String, String>();
@@ -79,51 +86,48 @@ public class GlyphList
     {
     }
 
-    private void loadGlyphs(String path)
+    private void loadGlyphs(String resourceName) throws IOException
     {
-        try
+        URL url = GlyphList.class.getClassLoader().getResource(resourceName);
+        if (url == null)
+        {
+            throw new MissingResourceException("Glyphlist not found: " + resourceName,
+                    GlyphList.class.getName(), resourceName);
+        }
+
+        Properties properties = new Properties();
+        properties.load(url.openStream());
+
+        Enumeration<?> names = properties.propertyNames();
+        for (Object name : Collections.list(names))
         {
-            Properties glyphProperties = ResourceLoader.loadProperties(path, false);
-            if (glyphProperties == null)
+            String glyphName = name.toString();
+            String unicodeValue = properties.getProperty(glyphName);
+            StringTokenizer tokenizer = new StringTokenizer(unicodeValue, " ", false);
+            StringBuilder value = new StringBuilder();
+            while (tokenizer.hasMoreTokens())
             {
-                throw new MissingResourceException("Glyphlist not found: " + path,
-                        Encoding.class.getName(), path);
+                int characterCode = Integer.parseInt(tokenizer.nextToken(), 16);
+                value.append((char) characterCode);
             }
-            Enumeration<?> names = glyphProperties.propertyNames();
-            for (Object name : Collections.list(names))
-            {
-                String glyphName = name.toString();
-                String unicodeValue = glyphProperties.getProperty(glyphName);
-                StringTokenizer tokenizer = new StringTokenizer(unicodeValue, " ", false);
-                StringBuilder value = new StringBuilder();
-                while (tokenizer.hasMoreTokens())
-                {
-                    int characterCode = Integer.parseInt(tokenizer.nextToken(), 16);
-                    value.append((char) characterCode);
-                }
-                String unicode = value.toString();
+            String unicode = value.toString();
 
-                if (nameToUnicode.containsKey(glyphName))
-                {
-                    LOG.warn("duplicate value for " + glyphName + " -> " + unicode + "
" +
-                             nameToUnicode.get(glyphName));
-                }
-                else
-                {
-                    nameToUnicode.put(glyphName, unicode);
-                }
+            if (nameToUnicode.containsKey(glyphName))
+            {
+                LOG.warn("duplicate value for " + glyphName + " -> " + unicode + " " +
+                        nameToUnicode.get(glyphName));
+            }
+            else
+            {
+                nameToUnicode.put(glyphName, unicode);
+            }
 
-                // reverse mapping
-                if (!unicodeToName.containsKey(unicode))
-                {
-                    unicodeToName.put(unicode, glyphName);
-                }
+            // reverse mapping
+            if (!unicodeToName.containsKey(unicode))
+            {
+                unicodeToName.put(unicode, glyphName);
             }
         }
-        catch (IOException io)
-        {
-            LOG.error("error while reading the glyph property file.", io);
-        }
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/ExternalFonts.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/ExternalFonts.java?rev=1625840&r1=1625839&r2=1625840&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/ExternalFonts.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/ExternalFonts.java Wed
Sep 17 22:35:37 2014
@@ -18,6 +18,7 @@ package org.apache.pdfbox.pdmodel.font;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -36,7 +37,6 @@ import org.apache.fontbox.ttf.Type1Equiv
 import org.apache.fontbox.ttf.TrueTypeFont;
 import org.apache.fontbox.type1.Type1Font;
 import org.apache.pdfbox.io.IOUtils;
-import org.apache.pdfbox.util.ResourceLoader;
 
 /**
  * External font service, locates non-embedded fonts via a pluggable FontProvider.
@@ -65,21 +65,23 @@ public final class ExternalFonts
         {
             // ttf
             String ttfName = "org/apache/pdfbox/resources/ttf/LiberationSans-Regular.ttf";
-            InputStream ttfStream = ResourceLoader.loadResource(ttfName);
-            if (ttfStream == null)
+            URL url = ExternalFonts.class.getClassLoader().getResource(ttfName);
+            if (url == null)
             {
                 throw new IOException("Error loading resource: " + ttfName);
             }
+            InputStream ttfStream = url.openStream();
             TTFParser ttfParser = new TTFParser();
             ttfFallbackFont = ttfParser.parse(ttfStream);
 
             // cff
             String cffName = "org/apache/pdfbox/resources/otf/AdobeBlank.otf";
-            InputStream cffStream = ResourceLoader.loadResource(cffName);
-            if (cffStream == null)
+            url = ExternalFonts.class.getClassLoader().getResource(cffName);
+            if (url == null)
             {
-                throw new IOException("Error loading resource: " + cffName);
+                throw new IOException("Error loading resource: " + ttfName);
             }
+            InputStream cffStream = url.openStream();
             byte[] bytes = IOUtils.toByteArray(cffStream);
             CFFParser cffParser = new CFFParser();
             cidFallbackFont = (CFFCIDFont)cffParser.parse(bytes).get(0);

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java?rev=1625840&r1=1625839&r2=1625840&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java Wed
Sep 17 22:35:37 2014
@@ -19,6 +19,7 @@ package org.apache.pdfbox.pdmodel.font;
 import java.awt.geom.GeneralPath;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URL;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
@@ -34,13 +35,11 @@ import org.apache.pdfbox.cos.COSDictiona
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.encoding.Encoding;
-import org.apache.pdfbox.encoding.GlyphList;
 import org.apache.pdfbox.encoding.StandardEncoding;
 import org.apache.pdfbox.encoding.Type1Encoding;
 import org.apache.pdfbox.encoding.WinAnsiEncoding;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.common.PDStream;
-import org.apache.pdfbox.util.ResourceLoader;
 
 /**
  * A PostScript Type 1 Font.
@@ -57,47 +56,51 @@ public class PDType1Font extends PDSimpl
     private static final Map<String, FontMetrics> AFM_MAP;
     static
     {
-        AFM_MAP = new HashMap<String, FontMetrics>();
-        addMetric("Courier-Bold");
-        addMetric("Courier-BoldOblique");
-        addMetric("Courier");
-        addMetric("Courier-Oblique");
-        addMetric("Helvetica");
-        addMetric("Helvetica-Bold");
-        addMetric("Helvetica-BoldOblique");
-        addMetric("Helvetica-Oblique");
-        addMetric("Symbol");
-        addMetric("Times-Bold");
-        addMetric("Times-BoldItalic");
-        addMetric("Times-Italic");
-        addMetric("Times-Roman");
-        addMetric("ZapfDingbats");
+        try
+        {
+            AFM_MAP = new HashMap<String, FontMetrics>();
+            addMetric("Courier-Bold");
+            addMetric("Courier-BoldOblique");
+            addMetric("Courier");
+            addMetric("Courier-Oblique");
+            addMetric("Helvetica");
+            addMetric("Helvetica-Bold");
+            addMetric("Helvetica-BoldOblique");
+            addMetric("Helvetica-Oblique");
+            addMetric("Symbol");
+            addMetric("Times-Bold");
+            addMetric("Times-BoldItalic");
+            addMetric("Times-Italic");
+            addMetric("Times-Roman");
+            addMetric("ZapfDingbats");
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException(e);
+        }
     }
 
-    private static void addMetric(String name)
+    private static void addMetric(String fontName) throws IOException
     {
-        String prefix = name; // todo: HACK
-        try
+        String resourceName = "org/apache/pdfbox/resources/afm/" + fontName + ".afm";
+        URL url = PDType1Font.class.getClassLoader().getResource(resourceName);
+        if (url != null)
         {
-            String resource = "org/apache/pdfbox/resources/afm/" + prefix + ".afm";
-            InputStream afmStream = ResourceLoader.loadResource(resource);
-            if (afmStream != null)
+            InputStream afmStream = url.openStream();
+            try
             {
-                try
-                {
-                    AFMParser parser = new AFMParser(afmStream);
-                    FontMetrics metric = parser.parse();
-                    AFM_MAP.put(name, metric);
-                }
-                finally
-                {
-                    afmStream.close();
-                }
+                AFMParser parser = new AFMParser(afmStream);
+                FontMetrics metric = parser.parse();
+                AFM_MAP.put(fontName, metric);
+            }
+            finally
+            {
+                afmStream.close();
             }
         }
-        catch (Exception e)
+        else
         {
-            LOG.error("Something went wrong when reading the adobe afm files", e);
+            throw new IOException(resourceName + " not found");
         }
     }
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java?rev=1625840&r1=1625839&r2=1625840&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDDeviceCMYK.java
Wed Sep 17 22:35:37 2014
@@ -16,9 +16,8 @@
  */
 package org.apache.pdfbox.pdmodel.graphics.color;
 
+import java.net.URL;
 import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.io.IOUtils;
-import org.apache.pdfbox.util.ResourceLoader;
 
 import java.awt.color.ICC_ColorSpace;
 import java.awt.color.ICC_Profile;
@@ -27,7 +26,6 @@ import java.awt.image.WritableRaster;
 import java.io.IOException;
 
 import java.io.InputStream;
-import java.util.Properties;
 
 /**
  * Allows colors to be specified according to the subtractive CMYK (cyan, magenta, yellow,
black)
@@ -58,29 +56,39 @@ public class PDDeviceCMYK extends PDDevi
     private PDDeviceCMYK() throws IOException
     {
         // loads the ICC color profile for CMYK
-        InputStream profile = null;
-        try
+        ICC_Profile iccProfile = getICCProfile();
+        if (iccProfile == null)
         {
-            Properties properties = ResourceLoader.loadProperties(
-                    "org/apache/pdfbox/resources/PDDeviceCMYK.properties", new Properties());
-
-            profile = ResourceLoader.loadResource(properties.getProperty("DeviceCMYK"));
-            if (profile == null)
-            {
-                throw new IOException("Default CMYK color profile could not be loaded");
-            }
-            ICC_Profile iccProfile = ICC_Profile.getInstance(profile);
-            awtColorSpace = new ICC_ColorSpace(iccProfile);
-
-            // there is a JVM bug which results in a CMMException which appears to be a race
-            // condition caused by lazy initialization of the color transform, so we perform
-            // an initial color conversion while we're still in a static context, see PDFBOX-2184
-            awtColorSpace.toRGB(new float[] { 0, 0, 0, 0 });
+            throw new IOException("Default CMYK color profile could not be loaded");
         }
-        finally
+        awtColorSpace = new ICC_ColorSpace(iccProfile);
+
+        // there is a JVM bug which results in a CMMException which appears to be a race
+        // condition caused by lazy initialization of the color transform, so we perform
+        // an initial color conversion while we're still in a static context, see PDFBOX-2184
+        awtColorSpace.toRGB(new float[] { 0, 0, 0, 0 });
+    }
+
+    protected ICC_Profile getICCProfile() throws IOException
+    {
+        // Adobe Acrobat uses "U.S. Web Coated (SWOP) v2" as the default
+        // CMYK profile, however it is not available under an open license.
+        // Instead, the "ISO Coated v2 300% (basICColor)" is used, which
+        // is an open alternative to the "ISO Coated v2 300% (ECI)" profile.
+
+        String name = "org/apache/pdfbox/resources/icc/ISOcoated_v2_300_bas.icc";
+
+        URL url = PDDeviceCMYK.class.getClassLoader().getResource(name);
+        if (url == null)
         {
-            IOUtils.closeQuietly(profile);
+            throw new IOException("Error loading resource: " + name);
         }
+
+        InputStream input = url.openStream();
+        ICC_Profile iccProfile = ICC_Profile.getInstance(input);
+        input.close();
+
+        return iccProfile;
     }
 
     @Override

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/ResourceLoader.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/ResourceLoader.java?rev=1625840&r1=1625839&r2=1625840&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/ResourceLoader.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/ResourceLoader.java Wed Sep 17
22:35:37 2014
@@ -31,7 +31,6 @@ import java.util.Properties;
  */
 public class ResourceLoader
 {
-
     /**
      * private constructor for utility class.
      */
@@ -49,7 +48,7 @@ public class ResourceLoader
      *
      * @throws IOException If there is an error while attempting to load the resource.
      */
-    public static InputStream loadResource( String resourceName ) throws IOException
+    private static InputStream loadResource( String resourceName ) throws IOException
     {
         ClassLoader loader = null;
         try
@@ -137,35 +136,4 @@ public class ResourceLoader
         }
         return properties;
     }
-
-    /**
-     * This will attempt to load the resource given the resource name.
-     *
-     * @param resourceName The resource to try and load.
-     * @param defaults A stream of default properties.
-     *
-     * @return The resource as a stream or null if it could not be found.
-     *
-     * @throws IOException If there is an error loading the properties.
-     */
-    public static Properties loadProperties( String resourceName, Properties defaults ) throws
IOException
-    {
-        InputStream is = null;
-        try
-        {
-            is = loadResource( resourceName );
-            if( is != null )
-            {
-                defaults.load( is );
-            }
-        }
-        finally
-        {
-            if( is != null )
-            {
-                is.close();
-            }
-        }
-        return defaults;
-    }
 }

Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Version.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Version.java?rev=1625840&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Version.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Version.java Wed Sep 17 22:35:37
2014
@@ -0,0 +1,58 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
+
+/**
+ * Exposes PDFBox version.
+ */
+public class Version
+{
+    private static final String PDFBOX_VERSION_PROPERTIES =
+            "org/apache/pdfbox/resources/pdfbox.properties";
+
+    private Version()
+    {
+        // static helper
+    }
+
+    /**
+     * Returns the version of PDFBox.
+     */
+    public static String getVersion()
+    {
+        try
+        {
+            URL url = Version.class.getClassLoader().getResource(PDFBOX_VERSION_PROPERTIES);
+            if (url == null)
+            {
+                return null;
+            }
+            Properties properties = new Properties();
+            properties.load(url.openStream());
+            return properties.getProperty("pdfbox.version", null);
+        }
+        catch (IOException io)
+        {
+            return null;
+        }
+    }
+}

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java?rev=1625840&r1=1625839&r2=1625840&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java Wed
Sep 17 22:35:37 2014
@@ -28,7 +28,6 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Properties;
 
 import javax.activation.DataSource;
 import javax.activation.FileDataSource;
@@ -44,7 +43,7 @@ import org.apache.pdfbox.preflight.Valid
 import org.apache.pdfbox.preflight.exception.SyntaxValidationException;
 import org.apache.pdfbox.preflight.parser.PreflightParser;
 import org.apache.pdfbox.preflight.parser.XmlResultParser;
-import org.apache.pdfbox.util.ResourceLoader;
+import org.apache.pdfbox.util.Version;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -141,8 +140,7 @@ public class Validator_A1b
     }
 
     private static void usage () throws IOException {
-        Properties props = ResourceLoader.loadProperties("org/apache/pdfbox/resources/pdfbox.properties",
false);
-        String version = props.getProperty( "pdfbox.version", "unknown" );
+        String version = Version.getVersion();
 
         System.out.println("Usage : java org.apache.pdfbox.preflight.Validator_A1b [xml]
[mode] <file path>");
         System.out.println();

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/Version.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/Version.java?rev=1625840&r1=1625839&r2=1625840&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/Version.java (original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/Version.java Wed Sep 17 22:35:37
2014
@@ -16,24 +16,14 @@
  */
 package org.apache.pdfbox.tools;
 
-import java.io.IOException;
-
-import java.util.Properties;
-
-import org.apache.pdfbox.util.ResourceLoader;
-
-
 /**
  * A simple command line utility to get the version of PDFBox.
  *
  * @author <a href="ben@benlitchfield.com">Ben Litchfield</a>
  * @version $Revision: 1.5 $
  */
-public class Version
+class Version
 {
-    private static final String PDFBOX_VERSION_PROPERTIES =
-        "org/apache/pdfbox/resources/pdfbox.properties";
-
     private Version()
     {
         //should not be constructed.
@@ -46,18 +36,15 @@ public class Version
      */
     public static String getVersion()
     {
-        String version = "unknown";
-        try
+        String version = org.apache.pdfbox.util.Version.getVersion();
+        if (version != null)
         {
-            Properties props = ResourceLoader.loadProperties( PDFBOX_VERSION_PROPERTIES,
false );
-            return props.getProperty( "pdfbox.version", version );
+            return version;
         }
-        catch( IOException io )
+        else
         {
-            //if there is a problem loading the properties then don't throw an
-            //exception, 'unknown' will be returned instead.
+            return "unknown";
         }
-        return version;
     }
 
     /**
@@ -85,5 +72,4 @@ public class Version
     {
         System.err.println( "usage: " + Version.class.getName() );
     }
-
 }



Mime
View raw message