]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-3028: Set values in fopFactoryBuilder setConfiguration
authorSimon Steiner <ssteiner@apache.org>
Tue, 30 Nov 2021 15:46:24 +0000 (15:46 +0000)
committerSimon Steiner <ssteiner@apache.org>
Tue, 30 Nov 2021 15:46:24 +0000 (15:46 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1895426 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/apps/FopConfParser.java
fop-core/src/main/java/org/apache/fop/apps/FopFactoryBuilder.java
fop-core/src/test/java/org/apache/fop/apps/FopFactoryBuilderTestCase.java

index 642b76f575c26e4f1043b056a5815c85185c5089..019250c17728ebbf20bc51594377d61ef21feb02 100644 (file)
@@ -154,10 +154,15 @@ public class FopConfParser {
             throw new FOPException(e);
         }
         // The default base URI is taken from the directory in which the fopConf resides
-        fopFactoryBuilder = new FopFactoryBuilder(enviro).setConfiguration(cfg);
+        fopFactoryBuilder = new FopFactoryBuilder(enviro).setConfiguration(cfg, false);
         configure(baseURI, enviro.getResourceResolver(), cfg);
     }
 
+    public FopConfParser(Configuration cfg, FopFactoryBuilder fopFactoryBuilder) throws SAXException {
+        this.fopFactoryBuilder = fopFactoryBuilder;
+        configure(fopFactoryBuilder.getBaseURI(), ResourceResolverFactory.createDefaultResourceResolver(), cfg);
+    }
+
     private void configure(final URI baseURI, final ResourceResolver resourceResolver,
             Configuration cfg) throws FOPException {
         if (log.isDebugEnabled()) {
index 0e7498df25a122fd97c0117eafa7c1cbb49ae185..aa8c741168428d85f32d6fa8bde46639ed389344 100644 (file)
@@ -26,6 +26,8 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+import org.xml.sax.SAXException;
+
 import org.apache.xmlgraphics.image.loader.ImageContext;
 import org.apache.xmlgraphics.image.loader.ImageManager;
 import org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext.FallbackResolver;
@@ -301,7 +303,18 @@ public final class FopFactoryBuilder {
      * @return <code>this</code>
      */
     public FopFactoryBuilder setConfiguration(Configuration cfg) {
+        return setConfiguration(cfg, true);
+    }
+
+    protected FopFactoryBuilder setConfiguration(Configuration cfg, boolean parse) {
         fopFactoryConfigBuilder.setConfiguration(cfg);
+        if (parse) {
+            try {
+                new FopConfParser(cfg, this);
+            } catch (SAXException e) {
+                throw new RuntimeException(e);
+            }
+        }
         return this;
     }
 
index 86b4e7c04bc30e1399652be51006f2beea32ab8e..470091f6c3cbff1fbb03277004e873fea6765867 100644 (file)
@@ -19,6 +19,8 @@
 
 package org.apache.fop.apps;
 
+import java.io.ByteArrayInputStream;
+import java.io.File;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
@@ -36,6 +38,8 @@ import static org.junit.Assert.fail;
 import org.apache.fop.apps.io.ResourceResolverFactory;
 import org.apache.fop.area.AreaTreeHandler;
 import org.apache.fop.area.Block;
+import org.apache.fop.configuration.Configuration;
+import org.apache.fop.configuration.DefaultConfigurationBuilder;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.extensions.ExternalDocument;
 import org.apache.fop.fo.pagination.Flow;
@@ -288,4 +292,14 @@ public class FopFactoryBuilderTestCase {
             // Expected
         }
     }
+
+    @Test
+    public void testSetConfiguration() throws Exception {
+        String fopxconf = "<fop version=\"1.0\">\n"
+                + "<source-resolution>288</source-resolution>"
+                + "</fop>";
+        Configuration cfg = new DefaultConfigurationBuilder().build(new ByteArrayInputStream(fopxconf.getBytes()));
+        FopFactory fopFactory = new FopFactoryBuilder(new File(".").toURI()).setConfiguration(cfg).build();
+        assertEquals((int)fopFactory.getSourceResolution(), 288);
+    }
 }