diff artifacts/src/main/java/org/dive4elements/river/artifacts/common/JRReportSaxParserFactory.java @ 8999:e3b3ce32c825

Work on uinfo
author gernotbelger
date Thu, 12 Apr 2018 19:15:42 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/common/JRReportSaxParserFactory.java	Thu Apr 12 19:15:42 2018 +0200
@@ -0,0 +1,59 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ *  Björnsen Beratende Ingenieure GmbH
+ *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+package org.dive4elements.river.artifacts.common;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import net.sf.jasperreports.engine.component.ComponentsBundle;
+import net.sf.jasperreports.engine.component.ComponentsEnvironment;
+import net.sf.jasperreports.engine.component.ComponentsXmlParser;
+import net.sf.jasperreports.engine.xml.BaseSaxParserFactory;
+import net.sf.jasperreports.engine.xml.JRXmlConstants;
+
+/**
+ * Own sax parser factory, because:
+ * - we do not want xml validation (we know it's good)
+ * - xerxes sax parser complains about two schemas with same namespace...
+ * 
+ * @author Domenico Nardi Tironi
+ */
+public class JRReportSaxParserFactory extends BaseSaxParserFactory {
+
+    @Override
+    protected boolean isValidating() {
+        return false;
+    }
+
+    @Override
+    protected List<String> getSchemaLocations() {
+        final List<String> schemas = new ArrayList<>();
+
+        schemas.add(getResourceURI(JRXmlConstants.JASPERREPORT_XSD_RESOURCE));
+        // schemas.add(getResourceURI(JRXmlConstants.JASPERREPORT_XSD_DTD_COMPAT_RESOURCE));
+
+        final Collection<ComponentsBundle> components = ComponentsEnvironment.getComponentBundles();
+        for (final ComponentsBundle componentManager : components) {
+            final ComponentsXmlParser xmlParser = componentManager.getXmlParser();
+
+            String schemaURI;
+            final String schemaResource = xmlParser.getInternalSchemaResource();
+            if (schemaResource != null) {
+                schemaURI = getResourceURI(schemaResource);
+            } else {
+                schemaURI = xmlParser.getPublicSchemaLocation();
+            }
+
+            schemas.add(schemaURI);
+        }
+        return schemas;
+    }
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org