- 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")) {
+ 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 {
+ 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;
+ }
+ }