X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.app.servlet.publish%2Fsrc%2Forg%2Fargeo%2Fapp%2Fservlet%2Fpublish%2FFopServlet.java;h=a4e07ba90a7f27a52c0391f3ffa8241588a129d7;hb=b06a0f5f77d4f126c8e38625882cd68a827dcd70;hp=1ee19f0f58f23688c4b50d1d64dadb5ecf9a1a38;hpb=6f8eb0aefe75025ee896498615cb1275f53d7f5b;p=gpl%2Fargeo-suite.git diff --git a/org.argeo.app.servlet.publish/src/org/argeo/app/servlet/publish/FopServlet.java b/org.argeo.app.servlet.publish/src/org/argeo/app/servlet/publish/FopServlet.java index 1ee19f0..a4e07ba 100644 --- a/org.argeo.app.servlet.publish/src/org/argeo/app/servlet/publish/FopServlet.java +++ b/org.argeo.app.servlet.publish/src/org/argeo/app/servlet/publish/FopServlet.java @@ -35,21 +35,23 @@ 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; import org.argeo.api.acr.ContentRepository; import org.argeo.api.acr.ContentSession; +import org.argeo.api.acr.NamespaceUtils; import org.argeo.app.geo.GeoUtils; import org.argeo.app.geo.GpxUtils; +import org.argeo.app.geo.acr.GeoEntityUtils; import org.argeo.cms.acr.xml.XmlNormalizer; import org.argeo.cms.auth.RemoteAuthUtils; import org.argeo.cms.servlet.ServletHttpRequest; import org.argeo.cms.util.LangUtils; -import org.geotools.data.collection.ListFeatureCollection; -import org.geotools.data.simple.SimpleFeatureCollection; -import org.opengis.feature.simple.SimpleFeature; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.Polygon; + +import net.sf.saxon.BasicTransformerFactory; /** * A servlet transforming an XML view of the data to either FOP or PDF. @@ -92,7 +94,7 @@ public class FopServlet extends HttpServlet { } Source xmlInput = content.adapt(Source.class); - XmlNormalizer.print(xmlInput,0); + XmlNormalizer.print(xmlInput, 0); } Source xmlInput = content.adapt(Source.class); @@ -108,21 +110,35 @@ public class FopServlet extends HttpServlet { return new StreamSource(in); } if (url.getScheme().equals("geo2svg")) { - String includePath = path + url.getPath(); - String geoExt = includePath.substring(includePath.lastIndexOf('.')); - Content geoContent = session.get(includePath); - if (".gpx".equals(geoExt)) { - try (InputStream in = geoContent.open(InputStream.class)) { - SimpleFeature field = GpxUtils.parseGpxToPolygon(in); - SimpleFeatureCollection features = new ListFeatureCollection(field.getType(), field); - try (StringWriter writer = new StringWriter()) { - GeoUtils.exportToSvg(features, writer, 100, 100); - StreamSource res = new StreamSource(new StringReader(writer.toString())); - return res; + int lastDot = url.getPath().lastIndexOf('.'); + Polygon polygon; + if (lastDot > 0) { + String includePath = path + url.getPath(); + Content geoContent = session.get(includePath); + String geoExt = includePath.substring(lastDot); + if (".gpx".equals(geoExt)) { + try (InputStream in = geoContent.open(InputStream.class)) { + polygon = GpxUtils.parseGpxTrackTo(in, Polygon.class); } + } else { + throw new UnsupportedOperationException(geoExt + " is not supported"); } } else { - throw new UnsupportedOperationException(geoExt + " is not supported"); + Content geoContent; + String attrName; + if (url.getPath().startsWith("/@")) { + geoContent = content; + attrName = url.getPath().substring(2);// remove /@ + } else { + throw new IllegalArgumentException("Only direct attributes are currently supported"); + } + polygon = GeoEntityUtils.getGeometry(geoContent, NamespaceUtils.parsePrefixedName(attrName), + Polygon.class); + } + try (StringWriter writer = new StringWriter()) { + GeoUtils.exportToSvg(new Geometry[] { polygon }, writer, 100, 100); + StreamSource res = new StreamSource(new StringReader(writer.toString())); + return res; } } } @@ -131,6 +147,7 @@ public class FopServlet extends HttpServlet { } String p = href.startsWith("/") ? href : path + '/' + href; + p = URLDecoder.decode(p, StandardCharsets.UTF_8); Content subContent = session.get(p); return subContent.adapt(Source.class); }; @@ -191,9 +208,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);