W3C home > Mailing lists > Public > www-xsl-fo@w3.org > November 2016

Unabme to upgrade from 1.1 to 2.1

From: Geoffroy Empain <Geoffroy.Empain@arhs-dev-be.com>
Date: Wed, 16 Nov 2016 15:34:48 +0000
To: "www-xsl-fo@w3.org" <www-xsl-fo@w3.org>
Message-ID: <ee60744551b6406d924c08d39b29d959@arhs-ms1.aris-lux.lan>
Hello,

I have started a StackOverflow (http://stackoverflow.com/questions/40610337/apache-fop-upgrading-from-1-1-to-2-1?noredirect=1#comment68457237_40610337) thread for this issue, but I thought the most appropriate place to ask this question would be here.

I am upgrading from FOP 1.1 to 2.1. I followed thoroughly the migration guide provided on the official website (https://xmlgraphics.apache.org/fop/2.1/upgrading.html) but still can't find any solution.

My code in version 1.1 is:

Configuration cfg = new DefaultConfigurationBuilder().build(XsltFactory.class.getResourceAsStream(FO_CONFIG_FILE));
fopFactory = FopFactory.newInstance();
fopFactory.setURIResolver(new ServletContextURIResolver(context));
fopFactory.setUserConfig(cfg);
Here is my code in 2.1 (which does not work):

ResourceResolver resolver = new URIResolverAdapter(new ServletContextURIResolver(context));
URI baseUri = new URI(ServletContextURIResolver.SERVLET_CONTEXT_PROTOCOL + "///");
FopFactoryBuilder fopFactoryBuilder = new FopFactoryBuilder(baseUri, resolver);

fopFactoryBuilder.setConfiguration(cfg);
fopFactory = fopFactoryBuilder.build();

Here is how my reasoning:

I understand that FopFactory now need to be created using FopFactoryBuilder.. The way the configuration is set changed, but the way the configuration is built does not, so the following code should be valid:

Configuration cfg = new DefaultConfigurationBuilder().build(XsltFactory.class.getResourceAsStream(FO_CONFIG_FILE));
fopFactoryBuilder.setConfiguration(cfg);
fopFactory = fopFactoryBuilder.build();

The question now is, how to create the factory builder, knowing that I want to use a custom resolver. Thus, following the upgrade guide, the only constructor that matches my needs is that with two parameters: baseUri and resolver. For 1.1 I used the  ServletContextURIResolver so I tried to find a way to give that type to the constructor, which happens to be possible with a URIResolverAdapter. So I did the following:

ResourceResolver resolver = new URIResolverAdapter(new ServletContextURIResolver(context));

Finally, comes the problem: the baseUri. I haven't found either in the migration guide or the documentation a relevant information for understanding the meaning of this variable. I have tried many variations but with no success:

URI baseUri = new File(".").toUri() ;
URI baseUri = new URI(ServletContextURIResolver.SERVLET_CONTEXT_PROTOCOL);
URI baseUri = new URI(ServletContextURIResolver.SERVLET_CONTEXT_PROTOCOL + "///");
URI baseUri = null;

I don't understand why a URI is required as I am already providing a configuration file, which looks like this:

<?xml version="1.0"?>
<fop version="1.0">
  <strict-configuration>true</strict-configuration>
  <strict-validation>false</strict-validation>

  <base>.</base>

  <source-resolution>72</source-resolution>
  <target-resolution>72</target-resolution>

  <default-page-settings height="11in" width="8.26in"/>

  <renderers>
    <renderer mime="application/pdf">
      <filterList>
        <!-- provides compression using zlib flate (default is on) -->
        <value>flate</value>

        <!-- encodes binary data into printable ascii characters (default off)
             This provides about a 4:5 expansion of data size -->
        <!-- <value>ascii-85</value> -->

        <!-- encodes binary data with hex representation (default off)
             This filter is not recommended as it doubles the data size -->
        <!-- <value>ascii-hex</value> -->
      </filterList>

      <fonts>
        <font kerning="yes" metrics-url="servlet-context:/WEB-INF/font/arial.xml" embed-url="servlet-context:/WEB-INF/font/arial.ttf">
          <font-triplet name="Arial" style="normal" weight="normal"/>
        </font>
        <font kerning="yes" metrics-url="servlet-context:/WEB-INF/font/arialbd.xml" embed-url="servlet-context:/WEB-INF/font/arialbd.ttf">
          <font-triplet name="Arial" style="normal" weight="bold"/>
        </font>
              <font kerning="yes" metrics-url="servlet-context:/WEB-INF/font/ariblk.xml" embed-url="servlet-context:/WEB-INF/font/ariblk.ttf">
          <font-triplet name="Arial" style="normal" weight="900"/>
        </font>
        <font kerning="yes" metrics-url="servlet-context:/WEB-INF/font/ariali.xml" embed-url="servlet-context:/WEB-INF/font/ariali.ttf">
          <font-triplet name="Arial" style="italic" weight="normal"/>
        </font>
        <font kerning="yes" metrics-url="servlet-context:/WEB-INF/font/arialbi.xml" embed-url="servlet-context:/WEB-INF/font/arialbi.ttf">
          <font-triplet name="Arial" style="italic" weight="bold"/>
        </font>
              <auto-detect/>
      </fonts>

      <!-- This option lets you specify additional options on an XML handler -->
      <!--xml-handler namespace="http://www.w3.org/2000/svg">
        <stroke-text>false</stroke-text>
      </xml-handler-->
    </renderer>
  </renderers>
</fop>

Could anyone help me understand what is not working properly and why it is ?

Thanks a lot for your help.

All the best, and keep the good work !

Geoffroy Empain
Programmer

M. +32 488 272 001
E. geoffroy.empain@arhs-dev-be.com<mailto:geoffroy.empain@arhs-dev-be.com>
A. Woluwedal 30, 1932 Zaventem<https://www.google.com/maps?q=2b,+rue+Nicolas+Bov%C3%A9,+L-1253+Luxembourg&hl=de&ie=UTF8&sll=37.0625,-95.677068&sspn=88.65234,130.253906&hnear=2B+Rue+Nicolas+Bov%C3%A9,+Luxembourg,+Luxemburg&t=m&z=16>

[cid:image001.png@01D24023.CC39D1A0]
[cid:image002.png@01D24023.CC39D1A0]<http://www.arhs-dev.com/>  [cid:image003.png@01D24023.CC39D1A0] <https://twitter.com/arhs_dev>   [cid:image004.png@01D24023.CC39D1A0] <https://www.linkedin.com/company/arhs-developments>






image001.png
(image/png attachment: image001.png)

image002.png
(image/png attachment: image002.png)

image003.png
(image/png attachment: image003.png)

image004.png
(image/png attachment: image004.png)

Received on Thursday, 17 November 2016 18:41:10 UTC

This archive was generated by hypermail 2.3.1 : Thursday, 17 November 2016 18:41:12 UTC