- URL url = new URL(href);
- if (url.getProtocol().equals("file")) {
- InputStream in = Files.newInputStream(Paths.get(URI.create(url.toString())));
- return new StreamSource(in);
+ URI url = URI.create(href);
+ if (url.getScheme() != null) {
+ if (url.getScheme().equals("file")) {
+ InputStream in = Files.newInputStream(Paths.get(URI.create(url.toString())));
+ 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;
+ }
+ }
+ } else {
+ throw new UnsupportedOperationException(geoExt + " is not supported");
+ }
+ }