[Schmitzm-commits] r1207 - in trunk: . src/schmitzm/geotools/styling
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Nov 3 00:53:44 CET 2010
Author: alfonx
Date: 2010-11-03 00:53:44 +0100 (Wed, 03 Nov 2010)
New Revision: 1207
Modified:
trunk/pom.xml
trunk/src/schmitzm/geotools/styling/StylingUtil.java
Log:
StylingUtil now supports validatin of XML InputStream against SLD XSD (new pom dependency!)
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-11-02 23:48:07 UTC (rev 1206)
+++ trunk/pom.xml 2010-11-02 23:53:44 UTC (rev 1207)
@@ -1,6 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
+
<modelVersion>4.0.0</modelVersion>
<groupId>de.schmitzm</groupId>
<artifactId>schmitzm-library</artifactId>
@@ -71,6 +71,14 @@
</dependency>
<dependency>
+ <groupId>org.geotools.xsd</groupId>
+ <artifactId>gt-xsd-sld</artifactId>
+ <version>${geotools.version}</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-shapefile-renderer</artifactId>
<version>${geotools.version}</version>
Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java 2010-11-02 23:48:07 UTC (rev 1206)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java 2010-11-02 23:53:44 UTC (rev 1207)
@@ -86,6 +86,7 @@
import org.geotools.renderer.lite.RendererUtilities;
import org.geotools.resources.i18n.Vocabulary;
import org.geotools.resources.i18n.VocabularyKeys;
+import org.geotools.sld.SLDConfiguration;
import org.geotools.styling.ColorMap;
import org.geotools.styling.ColorMapEntry;
import org.geotools.styling.ColorMapImpl;
@@ -113,6 +114,7 @@
import org.geotools.styling.TextSymbolizer;
import org.geotools.styling.visitor.DuplicatingStyleVisitor;
import org.geotools.util.NumberRange;
+import org.geotools.xml.Parser;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
import org.jfree.util.Log;
@@ -2945,10 +2947,43 @@
}
SLDTRANSFORMER.transform(exportStyle, new FileWriter(exportFile));
+
+ List<Exception> validateSld = validateSld(new FileInputStream(
+ exportFile));
+ if (validateSld.size() > 0) {
+ LOGGER.error(exportFile + " is not SLD valid: "
+ + validateSld.size() + " exceptions");
+ }
+ for (Exception e : validateSld) {
+ LOGGER.warn(exportFile + e.getLocalizedMessage(), e);
+ }
+
return true;
}
/**
+ * XMl coming from the {@link InputStream} validates against SLD 1.0
+ */
+ public static List<Exception> validateSld(InputStream is) {
+ Parser parser = new Parser(new SLDConfiguration());
+ try {
+ parser.validate(is);
+ } catch (Exception e) {
+ return Arrays.asList(e);
+ }
+
+ return parser.getValidationErrors();
+ }
+
+ /**
+ * True if the given XMl coming from the {@link InputStream} is validates
+ * against SLD 1.0
+ */
+ public static boolean validates(InputStream is) {
+ return validateSld(is).size() == 0;
+ }
+
+ /**
* Exports the {@link Style} to OGC SLD. If a FeatureTypeStyle for selection
* is used, it is automatically removed.
*
@@ -2961,6 +2996,9 @@
*/
public static final void saveStyleToSLD(Style style,
OutputStream exportStream) throws TransformerException {
+
+ style = removeSelectionFeatureTypeStyle(style);
+
SLDTRANSFORMER.setIndentation(2);
SLDTRANSFORMER.transform(style, exportStream);
}
@@ -3077,4 +3115,15 @@
SLDTRANSFORMER.setIndentation(1);
return SLDTRANSFORMER.transform(sld);
}
+
+ public static boolean validates(FeatureTypeStyle fts) throws IOException,
+ TransformerException {
+ // Bytestream not file!
+ Style s = STYLE_BUILDER.createStyle();
+ s.featureTypeStyles().add(fts);
+ File tempFile = File.createTempFile("testing", ".sld");
+ tempFile.createNewFile();
+ saveStyleToSLD(s, tempFile);
+ return validates(new FileInputStream(tempFile));
+ }
}
More information about the Schmitzm-commits
mailing list