Adapt to changes in GeoTools
[gpl/argeo-suite.git] / org.argeo.app.servlet.publish / src / org / argeo / app / servlet / publish / FopServlet.java
index ac4a1b78ce68a071570939e0f9fda6e4fa6b509e..3344d75c112af1ab7a6806c60d3082f421451b30 100644 (file)
@@ -35,7 +35,6 @@ import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.Fop;
 import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.FopFactoryBuilder;
-import org.apache.xalan.processor.TransformerFactoryImpl;
 import org.apache.xmlgraphics.io.Resource;
 import org.apache.xmlgraphics.io.ResourceResolver;
 import org.argeo.api.acr.Content;
@@ -43,12 +42,15 @@ import org.argeo.api.acr.ContentRepository;
 import org.argeo.api.acr.ContentSession;
 import org.argeo.app.geo.GeoUtils;
 import org.argeo.app.geo.GpxUtils;
+import org.argeo.cms.acr.xml.XmlNormalizer;
 import org.argeo.cms.auth.RemoteAuthUtils;
 import org.argeo.cms.servlet.ServletHttpRequest;
-import org.argeo.util.LangUtils;
+import org.argeo.cms.util.LangUtils;
+import org.geotools.api.feature.simple.SimpleFeature;
 import org.geotools.data.collection.ListFeatureCollection;
 import org.geotools.data.simple.SimpleFeatureCollection;
-import org.opengis.feature.simple.SimpleFeature;
+
+import net.sf.saxon.BasicTransformerFactory;
 
 /**
  * A servlet transforming an XML view of the data to either FOP or PDF.
@@ -77,12 +79,9 @@ public class FopServlet extends HttpServlet {
                boolean pdf = ".pdf".equals(ext);
                ContentSession session = RemoteAuthUtils.doAs(() -> contentRepository.get(), new ServletHttpRequest(req));
                Content content = session.get(path);
-               Source xmlInput = content.adapt(Source.class);
-               String systemId = req.getRequestURL().toString();
-               xmlInput.setSystemId(systemId);
 
                // dev only
-               final boolean DEV = true;
+               final boolean DEV = false;
                if (DEV) {
                        try (InputStream in = xslUrl.openStream()) {
                                Source xslSource = new StreamSource(in);
@@ -92,8 +91,15 @@ public class FopServlet extends HttpServlet {
                        } catch (TransformerConfigurationException | IOException e) {
                                throw new IllegalStateException("Cannot instantiate XSL " + xslUrl, e);
                        }
+
+                       Source xmlInput = content.adapt(Source.class);
+                       XmlNormalizer.print(xmlInput, 0);
                }
 
+               Source xmlInput = content.adapt(Source.class);
+               String systemId = req.getRequestURL().toString();
+               xmlInput.setSystemId(systemId);
+
                URIResolver uriResolver = (href, base) -> {
                        try {
                                URI url = URI.create(href);
@@ -115,7 +121,7 @@ public class FopServlet extends HttpServlet {
                                                                        StreamSource res = new StreamSource(new StringReader(writer.toString()));
                                                                        return res;
                                                                }
-                                                       } 
+                                                       }
                                                } else {
                                                        throw new UnsupportedOperationException(geoExt + " is not supported");
                                                }
@@ -124,8 +130,9 @@ public class FopServlet extends HttpServlet {
                        } catch (IOException e) {
                                throw new RuntimeException("Cannot process " + href);
                        }
-                       
-                       String p = href.startsWith("/")?href:path+'/'+href;
+
+                       String p = href.startsWith("/") ? href : path + '/' + href;
+                       p = URLDecoder.decode(p, StandardCharsets.UTF_8);
                        Content subContent = session.get(p);
                        return subContent.adapt(Source.class);
                };
@@ -186,9 +193,7 @@ public class FopServlet extends HttpServlet {
                documentBuilderFactory.setXIncludeAware(true);
                documentBuilderFactory.setNamespaceAware(true);
 
-               // We must explicitly use the non-XSLTC transformer, as XSLTC is not working
-               // with DocBook stylesheets
-               transformerFactory = new TransformerFactoryImpl();
+               transformerFactory = new BasicTransformerFactory();
 //             transformerFactory = TransformerFactory.newDefaultInstance();
                try {
                        String xslStr = LangUtils.get(properties, PROP_ARGEO_FO_XSL);