xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spepp...@apache.org
Subject svn commit: r1058945 - in /xmlgraphics/fop/trunk: ./ src/documentation/content/xdocs/trunk/ src/java/org/apache/fop/apps/ src/java/org/apache/fop/fonts/ test/
Date Fri, 14 Jan 2011 11:15:17 GMT
Author: spepping
Date: Fri Jan 14 11:15:16 2011
New Revision: 1058945

URL: http://svn.apache.org/viewvc?rev=1058945&view=rev
Log:
Relative URIs in the configuration file are evaluated relative to the base URI of the configuration
file

Modified:
    xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/configuration.xml
    xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactory.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactoryConfigurator.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManagerConfigurator.java
    xmlgraphics/fop/trunk/status.xml
    xmlgraphics/fop/trunk/test/test-no-xml-metrics.xconf

Modified: xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/configuration.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/configuration.xml?rev=1058945&r1=1058944&r2=1058945&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/configuration.xml (original)
+++ xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/configuration.xml Fri Jan
14 11:15:16 2011
@@ -90,6 +90,9 @@
         <td>disabled</td>
       </tr>
 	  <tr>
+		<td colspan="4">Relative URIs for the above three properties are evaluated relative
to the base URI of the configuration file. If the configuration is provided programmatically,
the base URI can be set with <code>FopFactory.setUserConfigBaseURI</code>; default
is the current working directory.</td>
+	  </tr>
+	  <tr>
 		<td>hyphenation-pattern</td>
 		<td>String, attribute lang, attribute country (optional)</td>
 		<td>Register a file name for the hyphenation pattern for the mentioned language and
country. Language ll and country CC must both consist of two letters.</td>

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactory.java?rev=1058945&r1=1058944&r2=1058945&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactory.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactory.java Fri Jan 14 11:15:16
2011
@@ -24,6 +24,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.MalformedURLException;
+import java.net.URI;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -701,6 +702,15 @@ public class FopFactory implements Image
     }
 
     /**
+     * Set the base URI for the user configuration
+     * Useful for programmatic configurations
+     * @param baseURI the base URI
+     */
+    public void setUserConfigBaseURI(URI baseURI) {
+        config.setBaseURI(baseURI);
+    }
+
+    /**
      * Get the user configuration.
      * @return the user configuration
      */

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactoryConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactoryConfigurator.java?rev=1058945&r1=1058944&r2=1058945&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactoryConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactoryConfigurator.java Fri Jan
14 11:15:16 2011
@@ -22,6 +22,8 @@ package org.apache.fop.apps;
 import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -78,6 +80,9 @@ public class FopFactoryConfigurator {
     /** Fop factory configuration */
     private Configuration cfg = null;
 
+    /** The base URI of the configuration file **/
+    private URI baseURI = null;
+
     /**
      * Default constructor
      * @param factory fop factory
@@ -130,17 +135,23 @@ public class FopFactoryConfigurator {
 
         // base definitions for relative path resolution
         if (cfg.getChild("base", false) != null) {
+            String path = cfg.getChild("base").getValue(null);
+            if (baseURI != null) {
+                path = baseURI.resolve(path).normalize().toString();
+            }
             try {
-                factory.setBaseURL(
-                        cfg.getChild("base").getValue(null));
+                factory.setBaseURL(path);
             } catch (MalformedURLException mfue) {
                 LogUtil.handleException(log, mfue, strict);
             }
         }
         if (cfg.getChild("hyphenation-base", false) != null) {
+            String path = cfg.getChild("hyphenation-base").getValue(null);
+            if (baseURI != null) {
+                path = baseURI.resolve(path).normalize().toString();
+            }
             try {
-                factory.setHyphenBaseURL(
-                        cfg.getChild("hyphenation-base").getValue(null));
+                factory.setHyphenBaseURL(path);
             } catch (MalformedURLException mfue) {
                 LogUtil.handleException(log, mfue, strict);
             }
@@ -259,7 +270,7 @@ public class FopFactoryConfigurator {
         }
 
         // configure font manager
-        new FontManagerConfigurator(cfg).configure(factory.getFontManager(), strict);
+        new FontManagerConfigurator(cfg, baseURI).configure(factory.getFontManager(), strict);
 
         // configure image loader framework
         configureImageLoading(cfg.getChild("image-loading", false), strict);
@@ -339,6 +350,7 @@ public class FopFactoryConfigurator {
      */
     public void setUserConfig(Configuration cfg) throws FOPException {
         this.cfg = cfg;
+        setBaseURI();
         configure(this.factory);
     }
 
@@ -349,4 +361,34 @@ public class FopFactoryConfigurator {
     public Configuration getUserConfig() {
         return this.cfg;
     }
+
+    /**
+     * @return the baseURI
+     */
+    public URI getBaseURI() {
+        return baseURI;
+    }
+
+    /**
+     * @param baseURI the baseURI to set
+     */
+    public void setBaseURI(URI baseURI) {
+        this.baseURI = baseURI;
+    }
+
+    private void setBaseURI() throws FOPException {
+        String[] locationParts = cfg.getLocation().split(":");
+        try {
+            if (locationParts != null && locationParts.length >= 2
+                    && "file".equals(locationParts[0])) {
+                baseURI = new URI(locationParts[0], locationParts[1], null);
+            }
+            if (baseURI == null) {
+                baseURI = new File(System.getProperty("user.dir")).toURI();
+            }
+        } catch (URISyntaxException e) {
+            throw new FOPException(e);
+        }
+    }
+
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManagerConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManagerConfigurator.java?rev=1058945&r1=1058944&r2=1058945&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManagerConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManagerConfigurator.java Fri Jan
14 11:15:16 2011
@@ -21,6 +21,7 @@ package org.apache.fop.fonts;
 
 import java.io.File;
 import java.net.MalformedURLException;
+import java.net.URI;
 import java.util.List;
 import java.util.regex.Pattern;
 
@@ -43,6 +44,8 @@ public class FontManagerConfigurator {
 
     private final Configuration cfg;
 
+    private URI baseURI = null;
+
     /**
      * Main constructor
      * @param cfg the font manager configuration object
@@ -52,6 +55,16 @@ public class FontManagerConfigurator {
     }
 
     /**
+     * Main constructor
+     * @param cfg the font manager configuration object
+     * @param baseURI the base URI of the configuration
+     */
+    public FontManagerConfigurator(Configuration cfg, URI baseURI) {
+        this.cfg = cfg;
+        this.baseURI = baseURI;
+    }
+
+    /**
      * Initializes font settings from the user configuration
      * @param fontManager a font manager
      * @param strict true if strict checking of the configuration is enabled
@@ -74,8 +87,12 @@ public class FontManagerConfigurator {
             }
         }
         if (cfg.getChild("font-base", false) != null) {
+            String path = cfg.getChild("font-base").getValue(null);
+            if (baseURI != null) {
+                path = baseURI.resolve(path).normalize().toString();
+            }
             try {
-                fontManager.setFontBaseURL(cfg.getChild("font-base").getValue(null));
+                fontManager.setFontBaseURL(path);
             } catch (MalformedURLException mfue) {
                 LogUtil.handleException(log, mfue, true);
             }

Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=1058945&r1=1058944&r2=1058945&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Fri Jan 14 11:15:16 2011
@@ -49,6 +49,7 @@
     <context id="API" title="Changes to the End-User API"/>
     <context id="Extensions" title="Changes to the Bundled Extensions"/>
     <context id="Images" title="Changes to the Image Support"/>
+	<context id="Config" title="Changes to the User Configuration"/>
   </contexts>
 
   <changes>
@@ -58,6 +59,9 @@
       documents. Example: the fix of marks layering will be such a case when it's done.
     -->
     <release version="FOP Trunk" date="TBD">
+	  <action context="Config" dev="SP" type="fix">
+		Bugfix: relative URIs in the configuration file (base, font-base, hyphenation-base) are
evaluated relative to the base URI of the configuration file.
+	  </action>
       <action context="Layout" dev="AD" type="fix" fixes-bug="49848">
         Bugfix: correct behavior of keep-together.within-line in case there are nested inlines
       </action>

Modified: xmlgraphics/fop/trunk/test/test-no-xml-metrics.xconf
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/test-no-xml-metrics.xconf?rev=1058945&r1=1058944&r2=1058945&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/test-no-xml-metrics.xconf (original)
+++ xmlgraphics/fop/trunk/test/test-no-xml-metrics.xconf Fri Jan 14 11:15:16 2011
@@ -7,7 +7,7 @@
   <base>./</base>
 
   <!-- Font Base URL for resolving relative font URLs -->
-  <font-base>./test/resources/fonts</font-base>
+  <font-base>./resources/fonts</font-base>
   
   <renderers>
     <renderer mime="application/pdf">



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message