[Schmitzm-commits] r1528 - trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sat Mar 19 18:27:17 CET 2011
Author: alfonx
Date: 2011-03-19 18:27:16 +0100 (Sat, 19 Mar 2011)
New Revision: 1528
Modified:
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StylingUtil.java
Log:
When saving a .SLD file, the content is not explicitly converted to UTF8
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StylingUtil.java 2011-03-19 16:58:07 UTC (rev 1527)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StylingUtil.java 2011-03-19 17:27:16 UTC (rev 1528)
@@ -34,11 +34,12 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
+import java.io.StringWriter;
import java.lang.reflect.Array;
import java.net.URL;
import java.nio.charset.Charset;
@@ -135,7 +136,6 @@
import org.opengis.filter.expression.Function;
import org.opengis.filter.expression.Literal;
import org.opengis.filter.expression.PropertyName;
-import org.xml.sax.SAXParseException;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
@@ -1396,9 +1396,9 @@
}
/**
- * SLD Rules können die Paramter MinScaleDenominator und MaxScaleDenominator
- * enthalten. Dadurch können Elemente für manche Zoom-Stufen deaktiviert
- * werden.
+ * SLD Rules können die Paramter MinScaleDenominator und
+ * MaxScaleDenominator enthalten. Dadurch können Elemente für manche
+ * Zoom-Stufen deaktiviert werden.
*
* Kommentar: "Sichtbarkeit" bezieht es nicht darauf, ob die Elemente auf
* dem Kartenausschnitt sichtbar sind, sondern um die SLD Regeln, welche das
@@ -1416,8 +1416,8 @@
* layer.getStyle() )
*
* @param scaleDenominator
- * Der aktuelle ScaleDenomitor für den die Sichtbarkeit ermittelt
- * wird.
+ * Der aktuelle ScaleDenomitor für den die Sichtbarkeit
+ * ermittelt wird.
*
* @see RendererUtilities.calculateOGCScale
*
@@ -1565,9 +1565,9 @@
}
/**
- * SLD Rules können die Paramter MinScaleDenominator und MaxScaleDenominator
- * enthalten. Dadurch können Elemente für manche Zoom-Stufen deaktiviert
- * werden.
+ * SLD Rules können die Paramter MinScaleDenominator und
+ * MaxScaleDenominator enthalten. Dadurch können Elemente für manche
+ * Zoom-Stufen deaktiviert werden.
*
* @param fc
* Die zu filternde FeatureCollection. Diese wird nicht
@@ -2021,8 +2021,8 @@
return rsList;
}
- public static void getRasterSymbolizers(final List<RasterSymbolizer> rsList,
- FeatureTypeStyle fts) {
+ public static void getRasterSymbolizers(
+ final List<RasterSymbolizer> rsList, FeatureTypeStyle fts) {
// Leave out FTSs that are selection related
if (fts.getName() != null
&& fts.getName()
@@ -2585,7 +2585,7 @@
String[] labels = new String[0];
double[] quantities = new double[0];
Color[] colors = new Color[0];
-
+
for (String line : someTxt.split("\\n")) {
try {
@@ -2857,8 +2857,7 @@
* method also checks, whether the style is actually differing from any
* existing style in the {@link File}. If there is no difference, the file
* is not saved again (that is more svn friendly).<br/>
- * The charset is defined by the {@link #SLDTRANSFORMER} charset, which is
- * set it <code>UTF-8</code> by default.
+ * All text ist converted to UTF-8.
*
* @param origStyle
* {@link Style} to save. Any selectino related FeatureTypeStyle
@@ -2886,16 +2885,21 @@
return false;
}
- FileWriter out = new FileWriter(exportFile);
-// SLDTRANSFORMER.setEncoding(Charset.forName("UTF-8"));
+ SLDTRANSFORMER.setEncoding(Charset.forName("UTF-8"));
+ StringWriter nativeWritten = new StringWriter();
+ SLDTRANSFORMER.transform(exportStyle, nativeWritten);
+
+
+ FileOutputStream output = new FileOutputStream(exportFile);
try {
- SLDTRANSFORMER.transform(exportStyle, out);
- } finally {
- out.flush();
- out.close();
+ IOUtils.write(nativeWritten.getBuffer().toString(),
+ output, "UTF-8");
+ } finally {
+ output.flush();
+ output.close();
}
- LOGGER.debug("Validating stored file "+exportFile+"... ");
+ LOGGER.debug("Validating stored file " + exportFile + "... ");
List<Exception> validateSld = validateSld(new FileInputStream(
exportFile));
if (validateSld.size() > 0) {
@@ -2903,10 +2907,11 @@
+ validateSld.size() + " exceptions");
}
for (Exception e : validateSld) {
- LOGGER.warn(exportFile + " " +e.getLocalizedMessage(), e);
+ LOGGER.warn(exportFile + " " + e.getLocalizedMessage(), e);
}
} catch (TransformerException te) {
- LOGGER.warn("TransformerException while saving Style to SLD file "+exportFile, te);
+ LOGGER.warn("TransformerException while saving Style to SLD file "
+ + exportFile, te);
return false;
}
return true;
@@ -2920,17 +2925,19 @@
try {
parser.validate(is);
} catch (Exception e) {
- LOGGER.error("Got a seriouse Parsing exception",e);
+ LOGGER.error("Got a seriouse Parsing exception", e);
ArrayList<Exception> el = new ArrayList<Exception>();
el.add(e);
-
+
if (is != null)
try {
is.close();
} catch (IOException e1) {
- LOGGER.error("Closing the InputStream after the Seriouse Exception failed",e1);
+ LOGGER.error(
+ "Closing the InputStream after the Seriouse Exception failed",
+ e1);
}
- return el;
+ return el;
}
return parser.getValidationErrors();
More information about the Schmitzm-commits
mailing list