Skip to content

Commit

Permalink
Switch FOP from 1.1 to 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
adamretter committed Sep 24, 2015
1 parent b4f1a7a commit dc1511a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
2 changes: 1 addition & 1 deletion extensions/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ include.module.xmpp.url = http://www.igniterealtime.org/downloadServlet?filename

# XSL FO transformations (Uses Apache FOP)
include.module.xslfo = true
include.module.xslfo.url = http://apache.cs.uu.nl/xmlgraphics/fop/binaries/fop-1.1-bin.zip
include.module.xslfo.url = http://apache.cs.uu.nl/xmlgraphics/fop/binaries/fop-2.0-bin.zip

# Module to execute external processes (dba users only)
include.module.process = true
Expand Down
6 changes: 4 additions & 2 deletions extensions/modules/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@
<condition property="libs.available.xslfo">
<and>
<available file="${modules.lib}/fop.jar"/>
<available file="${modules.lib}/batik-all-1.7.jar"/>
<available file="${modules.lib}/xmlgraphics-commons-1.5.jar"/>
<available file="${modules.lib}/batik-all-1.8.jar"/>
<available file="${modules.lib}/xmlgraphics-commons-2.0.1.jar"/>
<available file="${modules.lib}/avalon-framework-4.2.0.jar"/>
<available file="${modules.lib}/fontbox-1.8.5.jar"/>
</and>
</condition>
</target>
Expand All @@ -89,6 +90,7 @@
<include name="**/batik-all-*.jar"/>
<include name="**/xmlgraphics-commons-*.jar"/>
<include name="**/avalon-framework-*.jar"/>
<include name="**/fontbox-*.jar"/>
</patternset>
</fetch>

Expand Down
2 changes: 1 addition & 1 deletion extensions/modules/ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<!-- <dependency org="jivesoftware" name="smack" rev="3.1.0"/> -->

<!-- <dependency org="org.apache.xmlgraphics" name="fop" rev="1.1" conf="*->*,!sources,!javadoc">
<!-- <dependency org="org.apache.xmlgraphics" name="fop" rev="2.0" conf="*->*,!sources,!javadoc">
<exclude module="xalan"/>
<exclude module="xml-apis"/>
<exclude module="xml-apis-ext"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.exist.xquery.modules.xslfo;

import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map.Entry;
import java.util.Properties;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.SAXConfigurationHandler;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.*;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.exist.storage.DBBroker;
Expand All @@ -22,28 +22,37 @@ public class ApacheFopProcessorAdapter implements ProcessorAdapter {

private static final Logger LOG = LogManager.getLogger(ApacheFopProcessorAdapter.class);

private final FopFactory fopFactory = FopFactory.newInstance();

@Override
public ContentHandler getContentHandler(DBBroker broker, NodeValue configFile, Properties parameters, String mimeType, OutputStream os) throws SAXException {
public ContentHandler getContentHandler(final DBBroker broker, final NodeValue configFile, final Properties parameters, final String mimeType, final OutputStream os) throws SAXException {

// setup the FopFactory
if(configFile != null) {
FopConfigurationBuilder cfgBuilder = new FopConfigurationBuilder(broker);
Configuration cfg = cfgBuilder.buildFromNode(configFile);
fopFactory.setUserConfig(cfg);
}
final FopFactoryBuilder builder;
try {
if (configFile != null) {
final FopConfigurationBuilder cfgBuilder = new FopConfigurationBuilder(broker);
final Configuration cfg = cfgBuilder.buildFromNode(configFile);
final URI defaultBaseURI = new URI(configFile.getOwnerDocument().getBaseURI());
final EnvironmentProfile environment = EnvironmentalProfileFactory.createDefault(defaultBaseURI, null);
builder = new FopFactoryBuilder(environment).setConfiguration(cfg);
} else {
builder = new FopFactoryBuilder(new URI("/db"));
}

// setup the foUserAgent, using given parameters held in the
// transformer handler
FOUserAgent foUserAgent = setupFOUserAgent(fopFactory.newFOUserAgent(), parameters);
final FopFactory fopFactory = builder.build();

// create new instance of FOP using the mimetype, the created user
// agent, and the output stream
Fop fop = fopFactory.newFop(mimeType, foUserAgent, os);

// Obtain FOP's DefaultHandler
return fop.getDefaultHandler();
// setup the foUserAgent, using given parameters held in the
// transformer handler
final FOUserAgent foUserAgent = setupFOUserAgent(fopFactory.newFOUserAgent(), parameters);

// create new instance of FOP using the mimetype, the created user
// agent, and the output stream
final Fop fop = fopFactory.newFop(mimeType, foUserAgent, os);

// Obtain FOP's DefaultHandler
return fop.getDefaultHandler();
} catch(final URISyntaxException e) {
throw new SAXException("Unable to parse baseURI");
}
}

@Override
Expand All @@ -53,9 +62,7 @@ public void cleanup() {
/**
* Setup the UserAgent for FOP, from given parameters *
*
* @param transformer
* Created based on the XSLT, so containing any parameters to the
* XSL-FO specified in the XQuery
* @param foUserAgent The user agent to set parameters for
* @param parameters
* any user defined parameters to the XSL-FO process
* @return FOUserAgent The generated FOUserAgent to include any parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce

NodeValue configFile = args.length == 4 ? (NodeValue)args[3].itemAt(0) : null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();

ContentHandler contentHandler = adapter.getContentHandler(context.getBroker(), configFile, parameters, mimeType, baos);

// process the XSL-FO
Expand Down

7 comments on commit dc1511a

@hungerburg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like to test, though: I rather not have two full eXist-db source trees locally… Is there a way for me to include this commit into stock eXist the git way? How do I download the patch, there is no link here?

@adamretter
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have a git source base already, you can do -

cd $EXIST_HOME
git remote add adamretter https://github.com/adamretter/exist.git
git fetch adamretter
git checkout fop-2.0

The last command will switch you from the origin/develop branch to the adamretter/fop-2.0 branch. Remember to switch back when you are finished by running git checkout develop.

@hungerburg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked out your branch and copied my stuff over. It uses hyphenation, patterns are in fop-hyph.jar, which will not be found initially. It used only a little tweak for full satisfaction: make builder = new FopFactoryBuilder(new URI("/db")); above read …new URI("file:///db") instead.

The message in browser read: URI is not absolute. Kind of short. According to java doc absolute means, to start with a scheme; experiment shows, the URI must not point to somewhere real in the local installation.

@adamretter
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hungerburg Sorry, I can't really follow what you are saying. I did run an XSL:FO transformation successfully. Can you share a minimal XQuery and XSLT which shows your problem?

@hungerburg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamretter You are welcome: the case should be very easy to reproduce: In your FO set an attribute, eg <fo:block hyphenate="true"> and you will get the "URI not absolute" message. fop-hyph.jar can be downloaded from http://sourceforge.net/projects/offo/ - it is in the zip. I put it into $EXIST_HOME/lib/user/
PS: possibly necessary, set language="de" or "en"… somewhere up the tree.

@dizzzz
Copy link
Member

@dizzzz dizzzz commented on dc1511a Sep 26, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hungerburg is is an additional download of 7meg, which is quite significant.....

@hungerburg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dizzzz Dannes, I do not propose to add it to eXist; Just to change "/db" to "file:///db" in ApacheFopProcessorAdapter.java line 38. Because then, the fop hyphenation plugin (that some may have installed by themselves) continues to work through the 1 → 2 switch.

Please sign in to comment.