[Schmitzm-commits] r1692 - trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Aug 26 00:49:25 CEST 2011


Author: alfonx
Date: 2011-08-26 00:49:25 +0200 (Fri, 26 Aug 2011)
New Revision: 1692

Modified:
   trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StylingUtil.java
Log:
Speichern eines SLD unterst?\195?\188tzt nun einen Optimized mode, wo featureTypes mit gleichen FeatureTypeNames zusammengefasst werden.

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-08-25 22:43:57 UTC (rev 1691)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StylingUtil.java	2011-08-25 22:49:25 UTC (rev 1692)
@@ -48,12 +48,14 @@
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.Vector;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import javax.management.RuntimeErrorException;
 import javax.measure.unit.Unit;
 import javax.xml.transform.TransformerException;
 
@@ -120,6 +122,7 @@
 import org.geotools.styling.visitor.DuplicatingStyleVisitor;
 import org.geotools.util.NumberRange;
 import org.geotools.xml.Parser;
+import org.hsqldb.lib.HashMap;
 import org.jdom.Element;
 import org.jdom.output.XMLOutputter;
 import org.opengis.coverage.grid.GridCoverage;
@@ -152,12 +155,12 @@
 import de.schmitzm.geotools.selection.FeatureMapLayerSelectionSynchronizer;
 import de.schmitzm.io.IOUtil;
 import de.schmitzm.lang.LangUtil;
+import de.schmitzm.swing.ExceptionDialog;
 
 /**
  * Diese Klasse enthaelt Hilfsfunktionen zum GeoTools-Styling
  * 
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
- *         (University of Bonn/Germany)
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
  * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
  * 
  * @version 1.1
@@ -182,15 +185,12 @@
 	}
 
 	/** Standard-Instanz einer {@link StyleFactory} */
-	public static final StyleFactory STYLE_FACTORY = CommonFactoryFinder
-			.getStyleFactory(GeoTools.getDefaultHints());
+	public static final StyleFactory STYLE_FACTORY = CommonFactoryFinder.getStyleFactory(GeoTools.getDefaultHints());
 
 	/** Standard-Instanz eines {@link StyleBuilder}. */
-	public static final StyleBuilder STYLE_BUILDER = new StyleBuilder(
-			STYLE_FACTORY);
+	public static final StyleBuilder STYLE_BUILDER = new StyleBuilder(STYLE_FACTORY);
 
-	public static final DuplicatingStyleVisitor DUPLICATINGSTYLEVISITOR = new DuplicatingStyleVisitor(
-			STYLE_FACTORY);
+	public static final DuplicatingStyleVisitor DUPLICATINGSTYLEVISITOR = new DuplicatingStyleVisitor(STYLE_FACTORY);
 
 	/**
 	 * Lists a few predefined {@link Style}s usefull to mark selected features.
@@ -200,17 +200,14 @@
 	}
 
 	/**
-	 * RegEx Patter to read palette information from gdalinfo output, for images
-	 * wir <code>RGB</code>, @see {@link #parseColormapToSld(URL)} @see
-	 * {@link #parseColormapToSld(File)}
+	 * RegEx Patter to read palette information from gdalinfo output, for images wir <code>RGB</code>, @see
+	 * {@link #parseColormapToSld(URL)} @see {@link #parseColormapToSld(File)}
 	 **/
-	public static final Pattern GDALINFO_COLORMAP_RGB = Pattern
-			.compile("^[^\\d]*(\\d+): (\\d+),(\\d+),(\\d+).*$");
+	public static final Pattern GDALINFO_COLORMAP_RGB = Pattern.compile("^[^\\d]*(\\d+): (\\d+),(\\d+),(\\d+).*$");
 
 	/**
-	 * RegEx Patter to read palette information from gdalinfo output, for images
-	 * wir <code>RGBA</code> @see {@link #parseColormapToSld(URL)} @see
-	 * {@link #parseColormapToSld(File)}
+	 * RegEx Patter to read palette information from gdalinfo output, for images wir <code>RGBA</code> @see
+	 * {@link #parseColormapToSld(URL)} @see {@link #parseColormapToSld(File)}
 	 **/
 	public static final Pattern GDALINFO_COLORMAP_RGBA = Pattern
 			.compile("^[^\\d]*(\\d+): (\\d+),(\\d+),(\\d+),(\\d+).*$");
@@ -222,73 +219,63 @@
 	static final Literal size3 = FeatureUtil.FILTER_FACTORY2.literal(3);
 
 	static final Graphic SELECTION_GRAPHIC1 = STYLE_FACTORY.createGraphic(
-			new ExternalGraphic[0], new Mark[] { STYLE_FACTORY.createMark(
-					FeatureUtil.FILTER_FACTORY2.literal("square"), null,
-					STYLE_FACTORY.createFill(STYLE_BUILDER
-							.colorExpression(Color.WHITE)), size1, zeroLit) },
-			new org.geotools.styling.Symbol[0], FeatureUtil.FILTER_FACTORY2
-					.literal(1), size1, zeroLit);
+			new ExternalGraphic[0],
+			new Mark[] { STYLE_FACTORY.createMark(FeatureUtil.FILTER_FACTORY2.literal("square"), null,
+					STYLE_FACTORY.createFill(STYLE_BUILDER.colorExpression(Color.WHITE)), size1, zeroLit) },
+			new org.geotools.styling.Symbol[0], FeatureUtil.FILTER_FACTORY2.literal(1), size1, zeroLit);
 
 	static final Graphic SELECTION_GRAPHIC2 = STYLE_FACTORY.createGraphic(
-			new ExternalGraphic[0], new Mark[] { STYLE_FACTORY.createMark(
-					FeatureUtil.FILTER_FACTORY2.literal("circle"), null,
-					STYLE_FACTORY.createFill(STYLE_BUILDER
-							.colorExpression(Color.BLACK)), size2, zeroLit) },
-			new org.geotools.styling.Symbol[0], FeatureUtil.FILTER_FACTORY2
-					.literal(1), size2, zeroLit);
-	static final Graphic SELECTION_GRAPHIC3 = STYLE_FACTORY.createGraphic(
-			new ExternalGraphic[0], new Mark[] { STYLE_FACTORY.createMark(
-					FeatureUtil.FILTER_FACTORY2.literal("circle"), null,
-					STYLE_FACTORY.createFill(STYLE_BUILDER
-							.colorExpression(Color.YELLOW.brighter())), size3,
-					zeroLit) }, new org.geotools.styling.Symbol[0],
-			FeatureUtil.FILTER_FACTORY2.literal(1), size3, zeroLit);
+			new ExternalGraphic[0],
+			new Mark[] { STYLE_FACTORY.createMark(FeatureUtil.FILTER_FACTORY2.literal("circle"), null,
+					STYLE_FACTORY.createFill(STYLE_BUILDER.colorExpression(Color.BLACK)), size2, zeroLit) },
+			new org.geotools.styling.Symbol[0], FeatureUtil.FILTER_FACTORY2.literal(1), size2, zeroLit);
+	static final Graphic SELECTION_GRAPHIC3 = STYLE_FACTORY
+			.createGraphic(new ExternalGraphic[0],
+					new Mark[] { STYLE_FACTORY.createMark(FeatureUtil.FILTER_FACTORY2.literal("circle"), null,
+							STYLE_FACTORY.createFill(STYLE_BUILDER.colorExpression(Color.YELLOW.brighter())), size3,
+							zeroLit) }, new org.geotools.styling.Symbol[0], FeatureUtil.FILTER_FACTORY2.literal(1),
+					size3, zeroLit);
 
 	static final Graphic BLINK_GRAPHIC1 = STYLE_FACTORY.createGraphic(
-			new ExternalGraphic[0], new Mark[] { STYLE_FACTORY.createMark(
-					FeatureUtil.FILTER_FACTORY2.literal("circle"), null,
-					STYLE_FACTORY.createFill(STYLE_BUILDER
-							.colorExpression(Color.WHITE)), size0, halfLit) },
-			new org.geotools.styling.Symbol[0], FeatureUtil.FILTER_FACTORY2
-					.literal(1), size0, zeroLit);
+			new ExternalGraphic[0],
+			new Mark[] { STYLE_FACTORY.createMark(FeatureUtil.FILTER_FACTORY2.literal("circle"), null,
+					STYLE_FACTORY.createFill(STYLE_BUILDER.colorExpression(Color.WHITE)), size0, halfLit) },
+			new org.geotools.styling.Symbol[0], FeatureUtil.FILTER_FACTORY2.literal(1), size0, zeroLit);
 	private static final FilterFactory FILTER_FACTORY = FeatureUtil.FILTER_FACTORY;
 
 	/**
-	 * THis string is set as the Name of the Rules that describe selected
-	 * features
+	 * THis string is set as the Name of the Rules that describe selected features
 	 **/
 	public static final String SELECTION_RULE_ID = "SelectionRule";
 
-	//
-	// /** transparent color */
-	// public static final Color TRANSPARENT_COLOR = new Color(0, 0, 0, 0);
+	/**
+	 * This Kommen tis added to all SLDs that are exported as "optimized"
+	 */
+	private static final String OPTIMIZED_COMMENT = "<!-- This SLD has been exported in an 'optimized' version. This version potentially renders faster, but AtlasStyler will not be able to load it correctly.-->";
 
 	/**
-	 * Unless {@link ColorMap} is not sorted automatically, this method calls
-	 * {@link #sortColorMap(ColorMap)} after inserting the color map entry.
+	 * Unless {@link ColorMap} is not sorted automatically, this method calls {@link #sortColorMap(ColorMap)} after
+	 * inserting the color map entry.
 	 * 
 	 * @param colorMap
 	 *            the color map to extend
 	 * @param colorMapEntry
 	 *            the new entry
 	 */
-	public static ColorMap addColorMapEntryAndSort(ColorMap colorMap,
-			ColorMapEntry colorMapEntry) {
+	public static ColorMap addColorMapEntryAndSort(ColorMap colorMap, ColorMapEntry colorMapEntry) {
 		colorMap.addColorMapEntry(colorMapEntry);
 		return sortColorMap(colorMap);
 	}
 
 	/**
-	 * Applies general properties (color map type and extended colors) to a
-	 * {@link ColorMap}.
+	 * Applies general properties (color map type and extended colors) to a {@link ColorMap}.
 	 * 
 	 * @param sourceColorMap
 	 *            color map the properties are taken from
 	 * @param destColormap
 	 *            color map the properties are set
 	 */
-	public static void applyColorMapProperties(ColorMap sourceColorMap,
-			ColorMap destColormap) {
+	public static void applyColorMapProperties(ColorMap sourceColorMap, ColorMap destColormap) {
 		if (sourceColorMap == null || destColormap == null)
 			return;
 		destColormap.setExtendedColors(sourceColorMap.getExtendedColors());
@@ -296,8 +283,7 @@
 	}
 
 	/**
-	 * Removes all label information from the {@link ColorMapEntry}s of the
-	 * given {@link ColorMap}
+	 * Removes all label information from the {@link ColorMapEntry}s of the given {@link ColorMap}
 	 * 
 	 * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 */
@@ -348,8 +334,7 @@
 	/**
 	 * Kopiert eine {@link ColorMap}.
 	 * 
-	 * @return <code>null</code> wenn die uebergebene ColorMap <code>null</code>
-	 *         ist
+	 * @return <code>null</code> wenn die uebergebene ColorMap <code>null</code> ist
 	 */
 	public static ColorMap cloneColorMap(ColorMap colorMap) {
 		// MS: Leider kommt der DuplicatingStyleVisitor nicht damit klar, dass
@@ -376,8 +361,7 @@
 	/**
 	 * Kopiert einen {@link ColorMapEntry}.
 	 * 
-	 * @return <code>null</code> wenn der uebergebene ColorMapEntry
-	 *         <code>null</code> ist
+	 * @return <code>null</code> wenn der uebergebene ColorMapEntry <code>null</code> ist
 	 * 
 	 *         TODO doppelt mit copy( ColorMapEntry? )
 	 */
@@ -385,24 +369,20 @@
 		if (colorMapEntry == null)
 			return null;
 
-		return createColorMapEntry(colorMapEntry.getLabel(),
-				getQuantityFromColorMapEntry(colorMapEntry),
-				getColorFromColorMapEntry(colorMapEntry),
-				getOpacityFromColorMapEntry(colorMapEntry));
+		return createColorMapEntry(colorMapEntry.getLabel(), getQuantityFromColorMapEntry(colorMapEntry),
+				getColorFromColorMapEntry(colorMapEntry), getOpacityFromColorMapEntry(colorMapEntry));
 	}
 
 	/**
-	 * Prueft, ob zwei {@link ColorMapEntry}-Instanzen gleich sind. Dies ist der
-	 * Fall, wenn ihnen der gleiche Wert, die gleiche Farbe, die gleiche
-	 * Transparenz und das gleiche Label zugeordnet ist.
+	 * Prueft, ob zwei {@link ColorMapEntry}-Instanzen gleich sind. Dies ist der Fall, wenn ihnen der gleiche Wert, die
+	 * gleiche Farbe, die gleiche Transparenz und das gleiche Label zugeordnet ist.
 	 * 
 	 * @param cme1
 	 *            ein Farbpaletten-Eintrag
 	 * @param cme2
 	 *            ein anderer Farbpaletten-Eintrag
 	 */
-	public static boolean colorMapEntriesEqual(ColorMapEntry cme1,
-			ColorMapEntry cme2) {
+	public static boolean colorMapEntriesEqual(ColorMapEntry cme1, ColorMapEntry cme2) {
 		if (cme1 == null ^ cme2 == null)
 			return false;
 		if (cme1 == cme2)
@@ -420,8 +400,7 @@
 		// Wert auf Gleichheit testen
 		Double quan1 = getQuantityFromColorMapEntry(cme1);
 		Double quan2 = getQuantityFromColorMapEntry(cme2);
-		if (quan1 == null ^ quan2 == null || quan1 != null
-				&& !quan1.equals(quan2))
+		if (quan1 == null ^ quan2 == null || quan1 != null && !quan1.equals(quan2))
 			return false;
 		// Transparenz auf Gleichheit testen
 		Double op1 = getOpacityFromColorMapEntry(cme1);
@@ -435,8 +414,7 @@
 	/**
 	 * Kopiert einen {@link ColorMapEntry}.
 	 * 
-	 * @return <code>null</code> wenn der uebergebene ColorMapEntry
-	 *         <code>null</code> ist
+	 * @return <code>null</code> wenn der uebergebene ColorMapEntry <code>null</code> ist
 	 */
 	public static ColorMapEntry copy(ColorMapEntry colorMapEntry) {
 		DuplicatingStyleVisitor duplicatingStyleVisitor = new DuplicatingStyleVisitor();
@@ -478,9 +456,8 @@
 	}
 
 	/**
-	 * Since GT2.6, the AttributeNames are case sensitive. Also the raster
-	 * Styles need GeometryProperty set to "geom" to work. This method checks
-	 * all referenced AttributeNames.
+	 * Since GT2.6, the AttributeNames are case sensitive. Also the raster Styles need GeometryProperty set to "geom" to
+	 * work. This method checks all referenced AttributeNames.
 	 * 
 	 * @param Schema
 	 *            may be <code>null</code>, e.g. for raster layers
@@ -492,17 +469,15 @@
 	}
 
 	/**
-	 * Since GT2.6, the AttributeNames are case sensitive. Also the raster
-	 * Styles need GeometryProperty set to "geom" to work. This method checks
-	 * all referenced AttributeNames and checks them against the schema.
+	 * Since GT2.6, the AttributeNames are case sensitive. Also the raster Styles need GeometryProperty set to "geom" to
+	 * work. This method checks all referenced AttributeNames and checks them against the schema.
 	 * 
 	 * @param Schema
 	 *            may be <code>null</code>, e.g. for raster layers
 	 * 
 	 *            TODO Rename to correctStye
 	 */
-	public static Style correctPropertyNames(Style style,
-			final SimpleFeatureType schema) {
+	public static Style correctPropertyNames(Style style, final SimpleFeatureType schema) {
 
 		DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor() {
 			@Override
@@ -524,9 +499,8 @@
 				} else if (expression instanceof PropertyName) {
 					PropertyName pName = (PropertyName) expression;
 
-					Name correctedName = FeatureUtil
-							.findBestMatchingAttributeFallBackFirst(schema,
-									pName.getPropertyName());
+					Name correctedName = FeatureUtil.findBestMatchingAttributeFallBackFirst(schema,
+							pName.getPropertyName());
 
 					return ff.property(correctedName);
 				}
@@ -541,8 +515,7 @@
 					divFilter.setExpression2(copy(divFilter.getExpression2()));
 				} else if (filter instanceof IsNullImpl) {
 					IsNullImpl isNullFilter = (IsNullImpl) filter;
-					isNullFilter.setExpression1(copy(isNullFilter
-							.getExpression1()));
+					isNullFilter.setExpression1(copy(isNullFilter.getExpression1()));
 				} else if (filter instanceof NotImpl) {
 					NotImpl notFilter = (NotImpl) filter;
 					List<Filter> children = notFilter.getChildren();
@@ -575,8 +548,7 @@
 					// TODO noch viel mehr faelle!!
 					if (filter instanceof IsBetweenImpl) {
 						IsBetweenImpl isbetween = (IsBetweenImpl) filter;
-						isbetween
-								.setExpression(copy(isbetween.getExpression()));
+						isbetween.setExpression(copy(isbetween.getExpression()));
 					}
 
 				}
@@ -633,8 +605,8 @@
 	}
 
 	/**
-	 * @return A {@link FeatureTypeStyle} that can be used style the given
-	 *         geoObject during a blink or highlight process.
+	 * @return A {@link FeatureTypeStyle} that can be used style the given geoObject during a blink or highlight
+	 *         process.
 	 */
 	public static FeatureTypeStyle createBlinkFeatureTypeStyle(Object geoObject) {
 		if (geoObject instanceof GridCoverage2D
@@ -670,65 +642,52 @@
 
 		case NONE:
 		default:
-			throw new IllegalArgumentException(
-					"Provide a suitable GeometryForm object, NONE not allowed");
+			throw new IllegalArgumentException("Provide a suitable GeometryForm object, NONE not allowed");
 		}
 
-		return STYLE_BUILDER.createFeatureTypeStyle(symbolizers, Double.NaN,
-				Double.NaN);
+		return STYLE_BUILDER.createFeatureTypeStyle(symbolizers, Double.NaN, Double.NaN);
 	}
 
-	private static Symbolizer[] createBlinkFeatureTypeStyleLine(
-			Symbolizer[] symbolizers) {
+	private static Symbolizer[] createBlinkFeatureTypeStyleLine(Symbolizer[] symbolizers) {
 		LineSymbolizer ls = STYLE_BUILDER.createLineSymbolizer(Color.red, 6.);
 		symbolizers = LangUtil.extendArray(symbolizers, ls);
 
-		LineSymbolizer ls2 = STYLE_BUILDER
-				.createLineSymbolizer(Color.black, 4.);
+		LineSymbolizer ls2 = STYLE_BUILDER.createLineSymbolizer(Color.black, 4.);
 		symbolizers = LangUtil.extendArray(symbolizers, ls2);
 
-		LineSymbolizer ls3 = STYLE_BUILDER
-				.createLineSymbolizer(Color.white, 2.);
+		LineSymbolizer ls3 = STYLE_BUILDER.createLineSymbolizer(Color.white, 2.);
 		symbolizers = LangUtil.extendArray(symbolizers, ls3);
 		return symbolizers;
 	}
 
-	private static Symbolizer[] createBlinkFeatureTypeStylePolygon(
-			Symbolizer[] symbolizers) {
-		PolygonSymbolizer pol1 = STYLE_BUILDER.createPolygonSymbolizer(
-				STYLE_BUILDER.createStroke(Color.red, 4), null);
+	private static Symbolizer[] createBlinkFeatureTypeStylePolygon(Symbolizer[] symbolizers) {
+		PolygonSymbolizer pol1 = STYLE_BUILDER.createPolygonSymbolizer(STYLE_BUILDER.createStroke(Color.red, 4), null);
 		symbolizers = LangUtil.extendArray(symbolizers, pol1);
 
-		PolygonSymbolizer pol2 = STYLE_BUILDER.createPolygonSymbolizer(
-				STYLE_BUILDER.createStroke(Color.black, 2),
+		PolygonSymbolizer pol2 = STYLE_BUILDER.createPolygonSymbolizer(STYLE_BUILDER.createStroke(Color.black, 2),
 				STYLE_BUILDER.createFill(Color.WHITE, .5));
 		symbolizers = LangUtil.extendArray(symbolizers, pol2);
 		return symbolizers;
 	}
 
-	private static Symbolizer[] createBlinkFeatureTypeStylePoint(
-			Symbolizer[] symbolizers) {
+	private static Symbolizer[] createBlinkFeatureTypeStylePoint(Symbolizer[] symbolizers) {
 		Graphic bg2;
 		Literal size0 = FeatureUtil.FILTER_FACTORY2.literal(26);
 		Literal size1 = FeatureUtil.FILTER_FACTORY2.literal(28);
 
-		Graphic bg1 = STYLE_FACTORY.createGraphic(new ExternalGraphic[0],
-				new Mark[] { STYLE_FACTORY.createMark(
-						FeatureUtil.FILTER_FACTORY2.literal("circle"),
-						STYLE_BUILDER.createStroke(Color.red, 2.), null, size1,
-						halfLit) }, new org.geotools.styling.Symbol[0],
-				FeatureUtil.FILTER_FACTORY2.literal(1), size1, zeroLit);
+		Graphic bg1 = STYLE_FACTORY.createGraphic(
+				new ExternalGraphic[0],
+				new Mark[] { STYLE_FACTORY.createMark(FeatureUtil.FILTER_FACTORY2.literal("circle"),
+						STYLE_BUILDER.createStroke(Color.red, 2.), null, size1, halfLit) },
+				new org.geotools.styling.Symbol[0], FeatureUtil.FILTER_FACTORY2.literal(1), size1, zeroLit);
 
 		PointSymbolizer ps1 = STYLE_FACTORY.createPointSymbolizer();
 		ps1.setGraphic(bg1);
 		symbolizers = LangUtil.extendArray(symbolizers, ps1);
 
-		bg2 = STYLE_FACTORY.createGraphic(new ExternalGraphic[0],
-				new Mark[] { STYLE_FACTORY.createMark(
-						FeatureUtil.FILTER_FACTORY2.literal("circle"),
-						STYLE_BUILDER.createStroke(Color.black, 2.),
-						STYLE_BUILDER.createFill(Color.WHITE, 0.3), size0,
-						halfLit) }, new org.geotools.styling.Symbol[0],
+		bg2 = STYLE_FACTORY.createGraphic(new ExternalGraphic[0], new Mark[] { STYLE_FACTORY.createMark(
+				FeatureUtil.FILTER_FACTORY2.literal("circle"), STYLE_BUILDER.createStroke(Color.black, 2.),
+				STYLE_BUILDER.createFill(Color.WHITE, 0.3), size0, halfLit) }, new org.geotools.styling.Symbol[0],
 				FeatureUtil.FILTER_FACTORY2.literal(1), size0, zeroLit);
 
 		PointSymbolizer ps2 = STYLE_FACTORY.createPointSymbolizer();
@@ -739,13 +698,11 @@
 	}
 
 	/**
-	 * Creates a new {@link BrewerPalette} with only one scheme (which includes
-	 * all colors). The suitablity of the palette is set to "unknown" for all
-	 * viewer types.
+	 * Creates a new {@link BrewerPalette} with only one scheme (which includes all colors). The suitablity of the
+	 * palette is set to "unknown" for all viewer types.
 	 * 
 	 * @param name
-	 *            name for the palette (also the description is set to this
-	 *            value)
+	 *            name for the palette (also the description is set to this value)
 	 * @param colors
 	 *            colors for the palette
 	 */
@@ -758,13 +715,10 @@
 		// set suitability to UNKNOWN for all viewers
 		PaletteSuitability suitability = new PaletteSuitability();
 		try {
-			suitability.setSuitability(colors.length, new String[] { "?", "?",
-					"?", "?", "?", "?" });
+			suitability.setSuitability(colors.length, new String[] { "?", "?", "?", "?", "?", "?" });
 			palette.setPaletteSuitability(suitability);
 		} catch (IOException e) {
-			LOGGER.error(
-					"Unabel to PaletteSuitability.setSuitablility for colors.length="
-							+ colors, e);
+			LOGGER.error("Unabel to PaletteSuitability.setSuitablility for colors.length=" + colors, e);
 		}
 
 		// Create the trivial scheme for the palette (requested colors equals
@@ -797,8 +751,7 @@
 	 * @param opacity
 	 *            Transparenz fuer die Farbe des Farbpaletten-Eintrag
 	 */
-	public static ColorMapEntry createColorMapEntry(String label,
-			Double quantity, Color color, double opacity) {
+	public static ColorMapEntry createColorMapEntry(String label, Double quantity, Color color, double opacity) {
 		ColorMapEntry newEntry = STYLE_FACTORY.createColorMapEntry();
 		try {
 			newEntry.setLabel(label);
@@ -812,28 +765,23 @@
 	}
 
 	/**
-	 * Erstellt einen Default-Style fuer die Klassen/Interfaces:
-	 * StyledFeaturesInterface, GridCoverage2D, FeatureCollection, FeatureSource
-	 * und GeometryAttributeType.
+	 * Erstellt einen Default-Style fuer die Klassen/Interfaces: StyledFeaturesInterface, GridCoverage2D,
+	 * FeatureCollection, FeatureSource und GeometryAttributeType.
 	 * 
 	 * @param object
-	 *            {@link GridCoverage2D},
-	 *            {@link org.geotools.coverage.grid.io.AbstractGridCoverage2DReader}
-	 *            oder {@link FeatureCollection}
+	 *            {@link GridCoverage2D}, {@link org.geotools.coverage.grid.io.AbstractGridCoverage2DReader} oder
+	 *            {@link FeatureCollection}
 	 * @return {@code null} falls kein Style generiert werden kann
 	 * 
-	 * @Deprectated Use FeatureUtil.createDefaultStyle and
-	 *              FeatureUtil.getGeometryForm
+	 * @Deprectated Use FeatureUtil.createDefaultStyle and FeatureUtil.getGeometryForm
 	 */
 	public static Style createDefaultStyle(Object object) {
 
 		if (object instanceof StyledFeaturesInterface)
-			return FeatureUtil
-					.createDefaultStyle(((StyledFeaturesInterface<?>) object)
-							.getSchema().getGeometryDescriptor());
+			return FeatureUtil.createDefaultStyle(((StyledFeaturesInterface<?>) object).getSchema()
+					.getGeometryDescriptor());
 
-		if (object instanceof GridCoverage2D
-				|| object instanceof AbstractGridCoverage2DReader
+		if (object instanceof GridCoverage2D || object instanceof AbstractGridCoverage2DReader
 				|| object instanceof StyledRasterInterface)
 			return GridUtil.createDefaultStyle();
 
@@ -842,18 +790,15 @@
 		}
 
 		if (object instanceof FeatureCollection)
-			return FeatureUtil
-					.createDefaultStyle((FeatureCollection<SimpleFeatureType, SimpleFeature>) object);
+			return FeatureUtil.createDefaultStyle((FeatureCollection<SimpleFeatureType, SimpleFeature>) object);
 
 		if (object instanceof FeatureSource)
-			return FeatureUtil.createDefaultStyle(((FeatureSource) object)
-					.getSchema().getGeometryDescriptor());
+			return FeatureUtil.createDefaultStyle(((FeatureSource) object).getSchema().getGeometryDescriptor());
 
 		if (object instanceof GeometryDescriptor)
 			return FeatureUtil.createDefaultStyle((GeometryDescriptor) object);
 
-		LOGGER.warn("createDefaultStyle could not handle " + object
-				+ " and returned an empty (invalid) Style");
+		LOGGER.warn("createDefaultStyle could not handle " + object + " and returned an empty (invalid) Style");
 		return STYLE_BUILDER.createStyle();
 	}
 
@@ -863,19 +808,15 @@
 	 * @param name
 	 *            Name fuer die {@link GridSampleDimension}
 	 * @param colorMap
-	 *            fuer jeden Eintrag der {@link ColorMap} wird eine
-	 *            {@link Category} erzeugt
+	 *            fuer jeden Eintrag der {@link ColorMap} wird eine {@link Category} erzeugt
 	 * @param noDataValues
-	 *            Werte fuer die zusaetzliche {@link Category Categorys}
-	 *            erstellt werden, welche die transparent dargestellt werden
-	 *            (wenn {@code null} wird keine zusaetzliche {@link Category}
-	 *            erstellt)
+	 *            Werte fuer die zusaetzliche {@link Category Categorys} erstellt werden, welche die transparent
+	 *            dargestellt werden (wenn {@code null} wird keine zusaetzliche {@link Category} erstellt)
 	 * @param unit
-	 *            Einheit der Werte in der {@link GridSampleDimension} (kann
-	 *            {@code null} sein)
+	 *            Einheit der Werte in der {@link GridSampleDimension} (kann {@code null} sein)
 	 */
-	public static GridSampleDimension createDiscreteGridSampleDimension(
-			String name, ColorMap colorMap, double[] noDataValues, Unit<?> unit) {
+	public static GridSampleDimension createDiscreteGridSampleDimension(String name, ColorMap colorMap,
+			double[] noDataValues, Unit<?> unit) {
 		if (colorMap.getColorMapEntries().length == 0)
 			return null;
 
@@ -897,9 +838,8 @@
 			// label = String.valueOf(intValue);
 			if (label == null)
 				label = "";
-			categories.put(intValue, new Category(label, new Color[] { color },
-					new NumberRange(intValue, intValue), new NumberRange(
-							intValue, intValue)));
+			categories.put(intValue, new Category(label, new Color[] { color }, new NumberRange(intValue, intValue),
+					new NumberRange(intValue, intValue)));
 		}
 
 		// If NoData-Value is set, create an additional Category
@@ -917,15 +857,12 @@
 		// double higherEnd = colorMapMax + 10000*colorMapRange;
 		final int lowerStart = Integer.MIN_VALUE;
 		final int higherEnd = Integer.MAX_VALUE;
-		categories.put(colorMapMax + 10, new Category("_autoNoData1_",
-				new Color[] { new Color(0, 0, 0, 0) }, new NumberRange(
-						colorMapMax + 1, colorMapMax + 2), new NumberRange(
-						colorMapMax + 1, higherEnd)));
+		categories.put(colorMapMax + 10, new Category("_autoNoData1_", new Color[] { new Color(0, 0, 0, 0) },
+				new NumberRange(colorMapMax + 1, colorMapMax + 2), new NumberRange(colorMapMax + 1, higherEnd)));
 		if (colorMapMin < colorMapMax)
-			categories.put(colorMapMin - 10, new Category("_autoNoData2_",
-					new Color[] { new Color(0, 0, 0, 0) },
-					// new NumberRange(colorMapMin-2, colorMapMin-1), //
-					// logischer, aber klappt nicht!?
+			categories.put(colorMapMin - 10, new Category("_autoNoData2_", new Color[] { new Color(0, 0, 0, 0) },
+			// new NumberRange(colorMapMin-2, colorMapMin-1), //
+			// logischer, aber klappt nicht!?
 					NumberRange.create(colorMapMax + 3, colorMapMax + 4),
 					// new NumberRange(colorMapMax + 3, colorMapMax + 4),
 					NumberRange.create(lowerStart, colorMapMin - 1)
@@ -933,8 +870,8 @@
 					));
 
 		// Create the GridSampleDimension
-		GridSampleDimension gsd = new GridSampleDimension(name, categories
-				.values().toArray(new Category[0]), unit).geophysics(true);
+		GridSampleDimension gsd = new GridSampleDimension(name, categories.values().toArray(new Category[0]), unit)
+				.geophysics(true);
 
 		for (Category c : gsd.getCategories())
 			LOGGER.debug(c.toString());
@@ -943,8 +880,7 @@
 	}
 
 	/**
-	 * Erzeugt eine {@link Category} fuer die NoData-Werte transparent
-	 * dargestellt werden.
+	 * Erzeugt eine {@link Category} fuer die NoData-Werte transparent dargestellt werden.
 	 * 
 	 * @param geoValue
 	 *            Geo-Wert, der NoData repraesentiert
@@ -954,8 +890,7 @@
 	}
 
 	/**
-	 * Erzeugt eine {@link Category} fuer die NoData-Werte transparent
-	 * dargestellt werden.
+	 * Erzeugt eine {@link Category} fuer die NoData-Werte transparent dargestellt werden.
 	 * 
 	 * @param value
 	 *            Sample-Wert der Category
@@ -963,50 +898,38 @@
 	 *            Geo-Wert, der NoData repraesentiert
 	 */
 	public static Category createNoDataCategory(int value, double geoValue) {
-		return new Category(
-				Vocabulary.formatInternational(VocabularyKeys.NODATA),
-				new Color[] { new Color(0, 0, 0, 0) }, new NumberRange(value,
-						value), new NumberRange(geoValue, geoValue));
+		return new Category(Vocabulary.formatInternational(VocabularyKeys.NODATA),
+				new Color[] { new Color(0, 0, 0, 0) }, new NumberRange(value, value), new NumberRange(geoValue,
+						geoValue));
 	}
 
 	/**
 	 * @param geoObject
-	 *            the {@link GeometryForm} the selection style shall be created
-	 *            for.
+	 *            the {@link GeometryForm} the selection style shall be created for.
 	 * @param type
-	 *            define the look of the selection style by choosing a constant
-	 *            from {@link SelectionStylesTypes}
+	 *            define the look of the selection style by choosing a constant from {@link SelectionStylesTypes}
 	 * 
-	 * @return a {@link Style} that is suitable to identify features of the
-	 *         given type as selected items.
+	 * @return a {@link Style} that is suitable to identify features of the given type as selected items.
 	 */
-	public static FeatureTypeStyle createSelectionFTStyle(
-			GeometryForm geometryForm, SelectionStylesTypes type) {
-		Symbolizer[] symbolizers = createSelectionSymbolizers(geometryForm,
-				type);
+	public static FeatureTypeStyle createSelectionFTStyle(GeometryForm geometryForm, SelectionStylesTypes type) {
+		Symbolizer[] symbolizers = createSelectionSymbolizers(geometryForm, type);
 
-		return STYLE_BUILDER.createFeatureTypeStyle(symbolizers, 0.0,
-				Double.POSITIVE_INFINITY);
+		return STYLE_BUILDER.createFeatureTypeStyle(symbolizers, 0.0, Double.POSITIVE_INFINITY);
 	}
 
 	/**
 	 * @param geoObject
-	 *            {@link GridCoverage2D}, {@link AbstractGridCoverage2DReader},
-	 *            {@link FeatureCollection}, {@link GeometryAttributeType} or
-	 *            {@link FeatureSource}
+	 *            {@link GridCoverage2D}, {@link AbstractGridCoverage2DReader}, {@link FeatureCollection},
+	 *            {@link GeometryAttributeType} or {@link FeatureSource}
 	 * 
 	 * @param type
-	 *            define the look of the selection style by choosing a constant
-	 *            from {@link SelectionStylesTypes}
+	 *            define the look of the selection style by choosing a constant from {@link SelectionStylesTypes}
 	 * 
-	 * @return a {@link Style} that is suitable to identify features of the
-	 *         given type as selected items.
+	 * @return a {@link Style} that is suitable to identify features of the given type as selected items.
 	 */
-	public static FeatureTypeStyle createSelectionFTStyle(Object geoObject,
-			SelectionStylesTypes type) {
+	public static FeatureTypeStyle createSelectionFTStyle(Object geoObject, SelectionStylesTypes type) {
 
-		if (geoObject instanceof AbstractCoverage
-				|| geoObject instanceof AbstractGridCoverage2DReader) {
+		if (geoObject instanceof AbstractCoverage || geoObject instanceof AbstractGridCoverage2DReader) {
 			// Wenn irgendwann mal selection für raster möglich ist, dann hier
 			// einen schöneren style erstellen.
 			return GridUtil.createDefaultStyle().featureTypeStyles().get(0);
@@ -1032,8 +955,7 @@
 	 * @param selectionIds
 	 * @return
 	 */
-	public static Rule createSelectionRule(GeometryForm geometryForm,
-			String idPropertyName, List<String> selectionIds,
+	public static Rule createSelectionRule(GeometryForm geometryForm, String idPropertyName, List<String> selectionIds,
 			SelectionStylesTypes type) {
 
 		if (idPropertyName == null)
@@ -1052,8 +974,7 @@
 		if (selectionIds.size() > 0) {
 			for (String id : selectionIds) {
 				PropertyIsEqualTo equal = FilterUtil.FILTER_FAC2.equals(
-						FilterUtil.FILTER_FAC2.property(idPropertyName),
-						FilterUtil.FILTER_FAC2.literal(id));
+						FilterUtil.FILTER_FAC2.property(idPropertyName), FilterUtil.FILTER_FAC2.literal(id));
 				equals.add(equal);
 			}
 			rule.setFilter(FilterUtil.FILTER_FAC2.or(equals));
@@ -1063,16 +984,14 @@
 		}
 
 		// Symboizers
-		Symbolizer[] symbolizers = createSelectionSymbolizers(geometryForm,
-				type);
+		Symbolizer[] symbolizers = createSelectionSymbolizers(geometryForm, type);
 
 		rule.symbolizers().addAll(Arrays.asList(symbolizers));
 
 		return rule;
 	}
 
-	public static Style createSelectionStyle(Object geoObject,
-			SelectionStylesTypes type) {
+	public static Style createSelectionStyle(Object geoObject, SelectionStylesTypes type) {
 		FeatureTypeStyle fts = createSelectionFTStyle(geoObject, type);
 		Style style = STYLE_FACTORY.createStyle();
 		style.featureTypeStyles().clear();
@@ -1081,8 +1000,7 @@
 
 	}
 
-	public static Symbolizer[] createSelectionSymbolizers(
-			GeometryForm geometryForm, SelectionStylesTypes type) {
+	public static Symbolizer[] createSelectionSymbolizers(GeometryForm geometryForm, SelectionStylesTypes type) {
 		Symbolizer[] symbolizers = new Symbolizer[0];
 
 		double size = 15.;
@@ -1101,8 +1019,7 @@
 			break;
 
 		case POLYGON:
-			symbolizers = addSelectionSymbolizersPolygon(type, symbolizers,
-					size);
+			symbolizers = addSelectionSymbolizersPolygon(type, symbolizers, size);
 			break;
 
 		case LINE:
@@ -1110,8 +1027,7 @@
 			break;
 
 		case ANY:
-			symbolizers = addSelectionSymbolizersPolygon(type, symbolizers,
-					size);
+			symbolizers = addSelectionSymbolizersPolygon(type, symbolizers, size);
 			symbolizers = addSelectionSymbolizersPoint(symbolizers);
 			// symbolizers = addSelectionSymbolizersLine(symbolizers);
 			break;
@@ -1123,19 +1039,17 @@
 		return symbolizers;
 	}
 
-	private static Symbolizer[] addSelectionSymbolizersLine(
-			Symbolizer[] symbolizers) {
+	private static Symbolizer[] addSelectionSymbolizersLine(Symbolizer[] symbolizers) {
 		LineSymbolizer ls = STYLE_BUILDER.createLineSymbolizer(Color.red, 3.);
 		symbolizers = LangUtil.extendArray(symbolizers, ls);
 
-		LineSymbolizer ls2 = STYLE_BUILDER
-				.createLineSymbolizer(Color.white, 1.);
+		LineSymbolizer ls2 = STYLE_BUILDER.createLineSymbolizer(Color.white, 1.);
 		symbolizers = LangUtil.extendArray(symbolizers, ls2);
 		return symbolizers;
 	}
 
-	private static Symbolizer[] addSelectionSymbolizersPolygon(
-			SelectionStylesTypes type, Symbolizer[] symbolizers, double size) {
+	private static Symbolizer[] addSelectionSymbolizersPolygon(SelectionStylesTypes type, Symbolizer[] symbolizers,
+			double size) {
 		String markShapeName = "";
 		if (type == SelectionStylesTypes.LeftTop2RightBottom_lines
 				|| type == SelectionStylesTypes.LeftTop2RightBottom_lines_smallgaps
@@ -1157,8 +1071,7 @@
 				Mark fillMark = STYLE_BUILDER.createMark(markShapeName);
 				fillMark.setStroke(STYLE_BUILDER.createStroke(Color.red, 3.));
 
-				Graphic fillGraphic = STYLE_BUILDER.createGraphic(null,
-						fillMark, null);
+				Graphic fillGraphic = STYLE_BUILDER.createGraphic(null, fillMark, null);
 
 				fillGraphic.setSize(FILTER_FACTORY.literal(size));
 
@@ -1166,39 +1079,33 @@
 				fill.setGraphicFill(fillGraphic);
 			}
 
-			PolygonSymbolizer polS0 = STYLE_BUILDER.createPolygonSymbolizer(
-					outline, fill);
+			PolygonSymbolizer polS0 = STYLE_BUILDER.createPolygonSymbolizer(outline, fill);
 
 			symbolizers = LangUtil.extendArray(symbolizers, polS0);
 		}
 
 		{ // White
-			Stroke outline = STYLE_BUILDER.createStroke(
-					Color.yellow.brighter(), 1);
+			Stroke outline = STYLE_BUILDER.createStroke(Color.yellow.brighter(), 1);
 
 			Fill fill = null;
 
 			if (type != SelectionStylesTypes.Outline_only) {
 				Mark fillMark = STYLE_BUILDER.createMark(markShapeName);
-				fillMark.setStroke(STYLE_BUILDER.createStroke(
-						Color.yellow.brighter(), 1.));
-				Graphic fillGraphic = STYLE_BUILDER.createGraphic(null,
-						fillMark, null);
+				fillMark.setStroke(STYLE_BUILDER.createStroke(Color.yellow.brighter(), 1.));
+				Graphic fillGraphic = STYLE_BUILDER.createGraphic(null, fillMark, null);
 				fillGraphic.setSize(FILTER_FACTORY.literal(size));
 				fill = STYLE_BUILDER.createFill();
 				fill.setGraphicFill(fillGraphic);
 			}
 
-			PolygonSymbolizer polS0 = STYLE_BUILDER.createPolygonSymbolizer(
-					outline, fill);
+			PolygonSymbolizer polS0 = STYLE_BUILDER.createPolygonSymbolizer(outline, fill);
 			// polS0.setGeometry(offsetFunction);
 			symbolizers = LangUtil.extendArray(symbolizers, polS0);
 		}
 		return symbolizers;
 	}
 
-	private static Symbolizer[] addSelectionSymbolizersPoint(
-			Symbolizer[] symbolizers) {
+	private static Symbolizer[] addSelectionSymbolizersPoint(Symbolizer[] symbolizers) {
 		PointSymbolizer ps = STYLE_FACTORY.createPointSymbolizer();
 		ps.setGraphic(SELECTION_GRAPHIC1);
 		symbolizers = LangUtil.extendArray(symbolizers, ps);
@@ -1214,18 +1121,16 @@
 	}
 
 	/**
-	 * Creates a {@link Style} for a {@link Grid} layer from a {@link ColorMap}
-	 * Title will be set to {@link GridUtil#UNTITLED_RASTER_STYLE_TITLE}
+	 * Creates a {@link Style} for a {@link Grid} layer from a {@link ColorMap} Title will be set to
+	 * {@link GridUtil#UNTITLED_RASTER_STYLE_TITLE}
 	 * 
 	 * @param colorMap
 	 *            If null, then defaultStyle for Grid will be used
 	 * @param name
-	 *            The name to give to the Style. null will result in name
-	 *            {@link GridUtil#UNTITLED_RASTER_STYLE_TITLE}
+	 *            The name to give to the Style. null will result in name {@link GridUtil#UNTITLED_RASTER_STYLE_TITLE}
 	 * 
-	 * @return Always a Style that you can apply to a {@link GridCoverage}.
-	 *         Style has name {@link GridUtil#DEFAULT_RASTER_STYLE_NAME} if no
-	 *         colormap was provided.
+	 * @return Always a Style that you can apply to a {@link GridCoverage}. Style has name
+	 *         {@link GridUtil#DEFAULT_RASTER_STYLE_NAME} if no colormap was provided.
 	 * 
 	 * 
 	 * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
@@ -1240,23 +1145,19 @@
 	 * @param colorMap
 	 *            If null, then defaultStyle for Grid will be used
 	 * @param name
-	 *            The name to give to the Style. null will result in name=
-	 *            {@link GridUtil#UNNAMED_RASTER_STYLE_NAME} or
+	 *            The name to give to the Style. null will result in name= {@link GridUtil#UNNAMED_RASTER_STYLE_NAME} or
 	 *            GridUtil#DEFAULT_RASTER_STYLE_NAME} (if no colorMap is given).
 	 * 
 	 * @param title
 	 *            The Title to give to the Style. null will result in title=
-	 *            {@link GridUtil#UNTITLED_RASTER_STYLE_TITLE} or
-	 *            {@link GridUtil#DEFAULT_RASTER_STYLE_TITLE} (if no colorMap is
-	 *            given)
+	 *            {@link GridUtil#UNTITLED_RASTER_STYLE_TITLE} or {@link GridUtil#DEFAULT_RASTER_STYLE_TITLE} (if no
+	 *            colorMap is given)
 	 * 
-	 * @return Always a {@link Style} that you can be applyed to a
-	 *         {@link GridCoverage}.
+	 * @return Always a {@link Style} that you can be applyed to a {@link GridCoverage}.
 	 * 
 	 * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 */
-	public static Style createStyleFromColorMap(ColorMap colorMap, String name,
-			String title) {
+	public static Style createStyleFromColorMap(ColorMap colorMap, String name, String title) {
 		if (colorMap == null)
 			return GridUtil.createDefaultStyle();
 
@@ -1284,8 +1185,7 @@
 		RuleImpl ruleImpl = new RuleImpl(symbolizers) {
 		};
 		Rule[] rules = { ruleImpl };
-		FeatureTypeStyleImpl featureTypeStyleImpl = new FeatureTypeStyleImpl(
-				rules) {
+		FeatureTypeStyleImpl featureTypeStyleImpl = new FeatureTypeStyleImpl(rules) {
 		};
 
 		Style style = STYLE_FACTORY.createStyle();
@@ -1296,8 +1196,7 @@
 	}
 
 	/**
-	 * Erzeugt einen {@link Style} aus einem {@linkplain Element JDOM-Element},
-	 * des eine SLD-Definition enthaelt
+	 * Erzeugt einen {@link Style} aus einem {@linkplain Element JDOM-Element}, des eine SLD-Definition enthaelt
 	 * 
 	 * @param element
 	 *            Element mit SLD-Definition
@@ -1320,8 +1219,7 @@
 		}
 	}
 
-	public static Style createStyleSimple(Object geoObject, Color color,
-			Color color2) {
+	public static Style createStyleSimple(Object geoObject, Color color, Color color2) {
 		if (geoObject instanceof GridCoverage2D
 				|| geoObject instanceof org.geotools.coverage.grid.io.AbstractGridCoverage2DReader) {
 			// Wenn irgendwann mal selection für raster möglich ist, dann hier
@@ -1344,14 +1242,12 @@
 
 			break;
 		case POLYGON:
-			PolygonSymbolizer polS = STYLE_BUILDER.createPolygonSymbolizer(
-					STYLE_BUILDER.createStroke(color2),
+			PolygonSymbolizer polS = STYLE_BUILDER.createPolygonSymbolizer(STYLE_BUILDER.createStroke(color2),
 					STYLE_BUILDER.createFill(color));
 			symbolizers = LangUtil.extendArray(symbolizers, polS);
 
 		case LINE:
-			LineSymbolizer ls = STYLE_BUILDER
-					.createLineSymbolizer(STYLE_BUILDER.createStroke(color));
+			LineSymbolizer ls = STYLE_BUILDER.createLineSymbolizer(STYLE_BUILDER.createStroke(color));
 			symbolizers = LangUtil.extendArray(symbolizers, ls);
 			break;
 
@@ -1359,8 +1255,7 @@
 			// In case of ANY, create a Style with polygon and point
 			// symbolizers.
 
-			polS = STYLE_BUILDER.createPolygonSymbolizer(
-					STYLE_BUILDER.createStroke(color2),
+			polS = STYLE_BUILDER.createPolygonSymbolizer(STYLE_BUILDER.createStroke(color2),
 					STYLE_BUILDER.createFill(color));
 			ps = createPointSymbolizer(color, color2);
 
@@ -1373,75 +1268,60 @@
 		}
 
 		style.featureTypeStyles().get(0).rules().clear();
-		style.featureTypeStyles().get(0).rules()
-				.add(STYLE_FACTORY.createRule());
+		style.featureTypeStyles().get(0).rules().add(STYLE_FACTORY.createRule());
 
 		style.featureTypeStyles().get(0).rules().get(0).symbolizers().clear();
-		style.featureTypeStyles().get(0).rules().get(0).symbolizers()
-				.addAll(Arrays.asList(symbolizers));
+		style.featureTypeStyles().get(0).rules().get(0).symbolizers().addAll(Arrays.asList(symbolizers));
 
 		return style;
 	}
 
-	private static PointSymbolizer createPointSymbolizer(Color color,
-			Color color2) {
-		PointSymbolizer ps = STYLE_BUILDER.createPointSymbolizer(STYLE_BUILDER
-				.createGraphic(null, STYLE_BUILDER.createMark("circle"), null));
-		ps.getGraphic().getMarks()[0].setFill(STYLE_BUILDER.createFill(color,
-				0.5));
-		ps.getGraphic().getMarks()[0].setSize(STYLE_BUILDER
-				.literalExpression(8.));
+	private static PointSymbolizer createPointSymbolizer(Color color, Color color2) {
+		PointSymbolizer ps = STYLE_BUILDER.createPointSymbolizer(STYLE_BUILDER.createGraphic(null,
+				STYLE_BUILDER.createMark("circle"), null));
+		ps.getGraphic().getMarks()[0].setFill(STYLE_BUILDER.createFill(color, 0.5));
+		ps.getGraphic().getMarks()[0].setSize(STYLE_BUILDER.literalExpression(8.));
 		ps.getGraphic().setSize(STYLE_BUILDER.literalExpression(8.));
-		ps.getGraphic().getMarks()[0].setStroke(STYLE_BUILDER
-				.createStroke(color2));
+		ps.getGraphic().getMarks()[0].setStroke(STYLE_BUILDER.createStroke(color2));
 		return ps;
 	}
 
 	/**
-	 * 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
-	 * SimpleFeature evt. nur Scalenabhängig zeichnen.<br/>
-	 * SK 19.6.2009:Bei einem {@link PolygonSymbolizer} zählt nicht der Rand,
-	 * sondern nur ob eine Füllung vorhanden ist! Man kann dann zwar leider
-	 * nicht auf ein Rand eines Polygons ohne Fill klicken, aber dafür kann man
-	 * durch die ungefüllte Fläche klicken.
+	 * Kommentar: "Sichtbarkeit" bezieht es nicht darauf, ob die Elemente auf dem Kartenausschnitt sichtbar sind,
+	 * sondern um die SLD Regeln, welche das SimpleFeature evt. nur Scalenabhängig zeichnen.<br/>
+	 * SK 19.6.2009:Bei einem {@link PolygonSymbolizer} zählt nicht der Rand, sondern nur ob eine Füllung vorhanden ist!
+	 * Man kann dann zwar leider nicht auf ein Rand eines Polygons ohne Fill klicken, aber dafür kann man durch die
+	 * ungefüllte Fläche klicken.
 	 * 
 	 * @param fc
-	 *            Die zu filternde FeatureCollection. Diese wird nicht
-	 *            verändert.
+	 *            Die zu filternde FeatureCollection. Diese wird nicht verändert.
 	 * @param style
-	 *            Der Style, mit dem die Features gerendert werden (z.b.
-	 *            layer.getStyle() )
+	 *            Der Style, mit dem die Features gerendert werden (z.b. 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
 	 * 
-	 * @return Eine FeatureCollection in welcher nur die Features enthalten
-	 *         sind, welche bei aktuellen Scale mit dem übergebenen Style
-	 *         gerendert werden.
+	 * @return Eine FeatureCollection in welcher nur die Features enthalten sind, welche bei aktuellen Scale mit dem
+	 *         übergebenen Style gerendert werden.
 	 * 
 	 *         TODO Was ist mit raster?!
 	 * 
-	 *         TODO Das sollte man besser machen: Zuerst die FIlter der
-	 *         sichtbaren regeln raussuchen, und dann direkt am anfang damitmit
-	 *         mitfiltern...
+	 *         TODO Das sollte man besser machen: Zuerst die FIlter der sichtbaren regeln raussuchen, und dann direkt am
+	 *         anfang damitmit mitfiltern...
 	 * 
 	 * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 */
 	public static MemoryFeatureCollection filterSLDVisibleOnly(
-			final FeatureCollection<SimpleFeatureType, SimpleFeature> fc,
-			final Style style, final Double scaleDenominator) {
+			final FeatureCollection<SimpleFeatureType, SimpleFeature> fc, final Style style,
+			final Double scaleDenominator) {
 
 		// Eine im Speicher gehaltene FeatureCollection der sichtbaren
-		final MemoryFeatureCollection fcVisible = new MemoryFeatureCollection(
-				fc.getSchema());
+		final MemoryFeatureCollection fcVisible = new MemoryFeatureCollection(fc.getSchema());
 
 		// Prüfen aller Features in der Collection
 		final Iterator<SimpleFeature> fcIt = fc.iterator();
@@ -1455,22 +1335,18 @@
 
 					// Leave out FTSs that are selection related
 					if (fts.getName() != null
-							&& fts.getName()
-									.equals(FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME))
+							&& fts.getName().equals(FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME))
 						continue;
 
 					final List<Rule> rules = fts.rules();
 
 					for (final Rule rule : rules) {
-						final double maxScaleDenominator = rule
-								.getMaxScaleDenominator();
-						final double minScaleDenominator = rule
-								.getMinScaleDenominator();
+						final double maxScaleDenominator = rule.getMaxScaleDenominator();
+						final double minScaleDenominator = rule.getMinScaleDenominator();
 
 						// 1. Check: Trifft die Rule auf den aktuellen Scale der
 						// JMapPane?
-						if ((minScaleDenominator > scaleDenominator)
-								|| (scaleDenominator > maxScaleDenominator)) {
+						if ((minScaleDenominator > scaleDenominator) || (scaleDenominator > maxScaleDenominator)) {
 							continue;
 						}
 
@@ -1489,25 +1365,21 @@
 						boolean passt = false;
 						for (final Symbolizer symb : rule.getSymbolizers()) {
 
-							final Geometry geom = (Geometry) feature
-									.getDefaultGeometry();
+							final Geometry geom = (Geometry) feature.getDefaultGeometry();
 
-							if ((geom instanceof MultiPoint)
-									|| (geom instanceof com.vividsolutions.jts.geom.Point)) {
+							if ((geom instanceof MultiPoint) || (geom instanceof com.vividsolutions.jts.geom.Point)) {
 								if (symb instanceof PointSymbolizer) {
 									if (((PointSymbolizer) symb).getGraphic() != null)
 										passt = true;
 									break;
 								}
-							} else if ((geom instanceof MultiLineString)
-									|| (geom instanceof LineString)) {
+							} else if ((geom instanceof MultiLineString) || (geom instanceof LineString)) {
 								if (symb instanceof LineSymbolizer) {
 									if (((LineSymbolizer) symb).getStroke() != null)
 										passt = true;
 									break;
 								}
-							} else if ((geom instanceof MultiPolygon)
-									|| (geom instanceof Polygon)) {
+							} else if ((geom instanceof MultiPolygon) || (geom instanceof Polygon)) {
 
 								if (symb instanceof PolygonSymbolizer) {
 									if (((PolygonSymbolizer) symb).getFill() != null)
@@ -1540,22 +1412,16 @@
 		} catch (final java.lang.IllegalStateException e) {
 			LOGGER.error("Iterating over the features", e);
 			/**
-			 * SK: 14.Apri 2009. It happened a few time to that fcIt.hasNext
-			 * suddenly threw an exception for the "africa countries.shp":
-			 * Exception in thread "AWT-EventQueue-0"
-			 * java.lang.IllegalStateException: ShapeType changed illegally from
-			 * Polygon to Undefined at org.geotools.
-			 * data.shapefile.shp.ShapefileReader.nextRecord(ShapefileReader
-			 * .java:452) at org.geotools.data.shapefile.indexed.
-			 * IndexedShapefileDataStore$Reader
+			 * SK: 14.Apri 2009. It happened a few time to that fcIt.hasNext suddenly threw an exception for the
+			 * "africa countries.shp": Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: ShapeType
+			 * changed illegally from Polygon to Undefined at org.geotools.
+			 * data.shapefile.shp.ShapefileReader.nextRecord(ShapefileReader .java:452) at
+			 * org.geotools.data.shapefile.indexed. IndexedShapefileDataStore$Reader
 			 * .next(IndexedShapefileDataStore.java:1272) at
-			 * org.geotools.data.FIDFeatureReader.next(FIDFeatureReader.java:92)
-			 * at org .geotools.data.FilteringFeatureReader.hasNext(
-			 * FilteringFeatureReader .java:125) at
-			 * org.geotools.data.store.FeatureReaderIterator.hasNext(
-			 * FeatureReaderIterator.java:44) at
-			 * schmitzm.geotools.feature.FeatureUtil
-			 * .filterSLDVisibleOnly(FeatureUtil.java:216) *
+			 * org.geotools.data.FIDFeatureReader.next(FIDFeatureReader.java:92) at org
+			 * .geotools.data.FilteringFeatureReader.hasNext( FilteringFeatureReader .java:125) at
+			 * org.geotools.data.store.FeatureReaderIterator.hasNext( FeatureReaderIterator.java:44) at
+			 * schmitzm.geotools.feature.FeatureUtil .filterSLDVisibleOnly(FeatureUtil.java:216) *
 			 * 
 			 */
 		}
@@ -1567,50 +1433,40 @@
 	}
 
 	/**
-	 * 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
-	 *            verändert.
+	 *            Die zu filternde FeatureCollection. Diese wird nicht verändert.
 	 * @param style
-	 *            Der Style, mit dem die Features gerendert werden (z.b.
-	 *            layer.getStyle() )
+	 *            Der Style, mit dem die Features gerendert werden (z.b. layer.getStyle() )
 	 * 
-	 * @return Eine FeatureCollection in welcher nur die Features enthalten
-	 *         sind, welche bei aktuellen Scale mit dem übergebenen Style
-	 *         gerendert werden.
+	 * @return Eine FeatureCollection in welcher nur die Features enthalten sind, welche bei aktuellen Scale mit dem
+	 *         übergebenen Style gerendert werden.
 	 * 
 	 * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 */
 	public static FeatureCollection<SimpleFeatureType, SimpleFeature> filterSLDVisibleOnly(
-			final FeatureCollection<SimpleFeatureType, SimpleFeature> fc,
-			final Style style, XMapPane xMapPane) {
+			final FeatureCollection<SimpleFeatureType, SimpleFeature> fc, final Style style, XMapPane xMapPane) {
 
 		if (xMapPane == null || style == null)
 			return new EmptyFeatureCollection(fc.getSchema());
 
 		// Der "scaleDenominator" der aktuellen JMapPane
-		Double scaleDenominator = RendererUtilities.calculateOGCScale(
-				new ReferencedEnvelope(xMapPane.getMapArea(), xMapPane
-						.getMapContext().getCoordinateReferenceSystem()),
-				xMapPane.getBounds().width, null);
+		Double scaleDenominator = RendererUtilities.calculateOGCScale(new ReferencedEnvelope(xMapPane.getMapArea(),
+				xMapPane.getMapContext().getCoordinateReferenceSystem()), xMapPane.getBounds().width, null);
 
 		return filterSLDVisibleOnly(fc, style, scaleDenominator);
 	}
 
 	/**
-	 * Ermittelt fuer einen Wert den {@link ColorMapEntry} aus einer
-	 * {@link ColorMap}.
+	 * Ermittelt fuer einen Wert den {@link ColorMapEntry} aus einer {@link ColorMap}.
 	 * 
 	 * @param value
 	 *            Wert
-	 * @return {@code null}, wenn in der {@link ColorMap} kein expliziter
-	 *         Eintrag fuer den Wert hinterlegt ist
+	 * @return {@code null}, wenn in der {@link ColorMap} kein expliziter Eintrag fuer den Wert hinterlegt ist
 	 */
-	public static ColorMapEntry findColorMapEntry(ColorMap colorMap,
-			double value) {
+	public static ColorMapEntry findColorMapEntry(ColorMap colorMap, double value) {
 		for (ColorMapEntry entry : colorMap.getColorMapEntries())
 			if (value == getQuantityFromColorMapEntry(entry))
 				return entry;
@@ -1624,8 +1480,7 @@
 	 *            Farbpaletten-Eintrag
 	 */
 	public static Color getColorFromColorMapEntry(ColorMapEntry entry) {
-		if (entry == null || entry.getColor() == null
-				|| entry.getColor().evaluate(null) == null)
+		if (entry == null || entry.getColor() == null || entry.getColor().evaluate(null) == null)
 			return null;
 
 		// // Transparenz
@@ -1660,14 +1515,11 @@
 	}
 
 	/**
-	 * Liefert die Farbpalette zu einem Style, wenn der Style aus einem
-	 * {@link RasterSymbolizer} erzeugt wurde.
+	 * Liefert die Farbpalette zu einem Style, wenn der Style aus einem {@link RasterSymbolizer} erzeugt wurde.
 	 * 
 	 * @param style
-	 *            Style Wenn <code>null</code>, dann wird style auf
-	 *            {@link GridUtil}.createDefaultStyle() gesetzt
-	 * @return <code>null</code> wenn der Style nicht auf einem
-	 *         {@link RasterSymbolizer} basiert.
+	 *            Style Wenn <code>null</code>, dann wird style auf {@link GridUtil}.createDefaultStyle() gesetzt
+	 * @return <code>null</code> wenn der Style nicht auf einem {@link RasterSymbolizer} basiert.
 	 */
 	public static ColorMap getColorMapFromStyle(final Style style) {
 		final List<ColorMap> colorMapsFromStyle = getColorMapsFromStyle(style);
@@ -1679,12 +1531,10 @@
 	}
 
 	/**
-	 * Liefert alle Farbpaletten aus einem Style, wenn irgendo
-	 * {@link RasterSymbolizer} enthalten sind.
+	 * Liefert alle Farbpaletten aus einem Style, wenn irgendo {@link RasterSymbolizer} enthalten sind.
 	 * 
 	 * @param style
-	 *            Style Wenn <code>null</code>, dann wird style auf
-	 *            {@link GridUtil}.createDefaultStyle() gesetzt
+	 *            Style Wenn <code>null</code>, dann wird style auf {@link GridUtil}.createDefaultStyle() gesetzt
 	 * @return Leere Liste wenn keine RasterSymbolizer enthalten ist.
 	 */
 	public static List<ColorMap> getColorMapsFromStyle(Style style) {
@@ -1714,8 +1564,7 @@
 	 */
 	public static int getColorMapType(String typeStr) {
 		if (typeStr == null)
-			throw new IllegalArgumentException("Unknown color map type: "
-					+ typeStr);
+			throw new IllegalArgumentException("Unknown color map type: " + typeStr);
 
 		typeStr = typeStr.trim().toLowerCase();
 		if (typeStr.equals("ramp") || typeStr.equals("type_ramp"))
@@ -1759,14 +1608,11 @@
 
         </code>
 	 * 
-	 * Returns the first attribute found in the label expression of the given
-	 * {@link TextSymbolizer}. If non is found for some reason, the method tries
-	 * to return the first attribute from the schema. We expect the layer to
-	 * have some attributes, because otherwise AS shouldn't even create the
-	 * LabellingTab.
+	 * Returns the first attribute found in the label expression of the given {@link TextSymbolizer}. If non is found
+	 * for some reason, the method tries to return the first attribute from the schema. We expect the layer to have some
+	 * attributes, because otherwise AS shouldn't even create the LabellingTab.
 	 */
-	public static PropertyName getFirstPropertyName(final SimpleFeatureType ft,
-			final TextSymbolizer textSymbolizer) {
+	public static PropertyName getFirstPropertyName(final SimpleFeatureType ft, final TextSymbolizer textSymbolizer) {
 		final Expression labelExpression = textSymbolizer.getLabel();
 		try {
 			if (labelExpression instanceof PropertyName) {
@@ -1774,8 +1620,7 @@
 				return (PropertyName) labelExpression;
 			} else if (labelExpression instanceof Function) {
 				final Function filterExpression = (Function) labelExpression;
-				final FilterAttributeExtractor attExVid = new FilterAttributeExtractor(
-						ft);
+				final FilterAttributeExtractor attExVid = new FilterAttributeExtractor(ft);
 
 				attExVid.visit(filterExpression, null);
 
@@ -1790,8 +1635,8 @@
 					prop1 = attributeNames[0];
 				} else {
 
-					if (filterExpression.toString().indexOf(attributeNames[0]) < filterExpression
-							.toString().indexOf(attributeNames[1])) {
+					if (filterExpression.toString().indexOf(attributeNames[0]) < filterExpression.toString().indexOf(
+							attributeNames[1])) {
 						prop1 = attributeNames[0];
 						// prop2 = attributeNames[1];
 					} else {
@@ -1808,13 +1653,11 @@
 		}
 
 		// TODO this is not rockhard.. could NPE
-		return FilterUtil.FILTER_FAC2.property(ft.getAttributeDescriptors()
-				.get(1).getLocalName());
+		return FilterUtil.FILTER_FAC2.property(ft.getAttributeDescriptors().get(1).getLocalName());
 	}
 
 	/**
-	 * @return the {@link Color} used in the {@link Graphic} or null, if an
-	 *         {@link ExternalGraphic} is used.
+	 * @return the {@link Color} used in the {@link Graphic} or null, if an {@link ExternalGraphic} is used.
 	 * 
 	 * @param graphic
 	 *            If <code>null</code> returns <code>null</code>
@@ -1862,8 +1705,7 @@
 	}
 
 	/**
-	 * Super smart metod ;-) Needs to be extended to look at the graphic width
-	 * and Geometry type.
+	 * Super smart metod ;-) Needs to be extended to look at the graphic width and Geometry type.
 	 * 
 	 * @param geometryDescriptor
 	 * @param avgNn
@@ -1874,8 +1716,7 @@
 	}
 
 	/**
-	 * Super smart metod ;-) Needs to be extended to look at the graphic width
-	 * and Geometry type.
+	 * Super smart metod ;-) Needs to be extended to look at the graphic width and Geometry type.
 	 * 
 	 * @param geometryDescriptor
 	 * @param avgNn
@@ -1936,9 +1777,7 @@
 			return 1.0;
 		Object exprValue = expression.evaluate(null);
 
-		return (exprValue instanceof String) ? Double
-				.valueOf((String) exprValue) : ((Number) exprValue)
-				.doubleValue();
+		return (exprValue instanceof String) ? Double.valueOf((String) exprValue) : ((Number) exprValue).doubleValue();
 	}
 
 	/**
@@ -2003,15 +1842,12 @@
 			return null;
 		Object exprValue = expression.evaluate(null);
 
-		return (exprValue instanceof String) ? Double
-				.valueOf((String) exprValue) : ((Number) exprValue)
-				.doubleValue();
+		return (exprValue instanceof String) ? Double.valueOf((String) exprValue) : ((Number) exprValue).doubleValue();
 	}
 
 	/**
-	 * Returns all {@link RasterSymbolizer} that are contained in a
-	 * {@link Style}. {@link RasterSymbolizer} from {@link FeatureTypeStyle}s
-	 * that are selection related are ignored.
+	 * Returns all {@link RasterSymbolizer} that are contained in a {@link Style}. {@link RasterSymbolizer} from
+	 * {@link FeatureTypeStyle}s that are selection related are ignored.
 	 */
 	public static List<RasterSymbolizer> getRasterSymbolizers(Style style) {
 		final List<RasterSymbolizer> rsList = new ArrayList<RasterSymbolizer>();
@@ -2022,12 +1858,10 @@
 		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()
-						.equals(FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME))
+				&& fts.getName().equals(FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME))
 			return;
 
 		for (Rule r : fts.rules()) {
@@ -2043,11 +1877,10 @@
 	 * Geopublisher allows to use one or two attributes for labeling, like
 	 * 
 	 * 
-	 * Returns the second attribute found in the label expression of the given
-	 * {@link TextSymbolizer} or <code>null</code>.
+	 * Returns the second attribute found in the label expression of the given {@link TextSymbolizer} or
+	 * <code>null</code>.
 	 */
-	public static PropertyName getSecondPropertyName(
-			final SimpleFeatureType ft, final TextSymbolizer textSymbolizer) {
+	public static PropertyName getSecondPropertyName(final SimpleFeatureType ft, final TextSymbolizer textSymbolizer) {
 		try {
 
 			final Expression labelExpression = textSymbolizer.getLabel();
@@ -2056,8 +1889,7 @@
 				return null;
 			} else if (labelExpression instanceof Function) {
 				final Function filterExpression = (Function) labelExpression;
-				final FilterAttributeExtractor attExVid = new FilterAttributeExtractor(
-						ft);
+				final FilterAttributeExtractor attExVid = new FilterAttributeExtractor(ft);
 
 				attExVid.visit(filterExpression, null);
 
@@ -2066,8 +1898,8 @@
 					return null;
 
 				String prop2 = null;
-				if (filterExpression.toString().indexOf(attributeNames[0]) < filterExpression
-						.toString().indexOf(attributeNames[1])) {
+				if (filterExpression.toString().indexOf(attributeNames[0]) < filterExpression.toString().indexOf(
+						attributeNames[1])) {
 					prop2 = attributeNames[1];
 				} else {
 					prop2 = attributeNames[0];
@@ -2085,13 +1917,12 @@
 	}
 
 	/**
-	 * Returns <code>null</code> or any {@link FeatureTypeStyle} contained in
-	 * the given {@link Style} that is SELECTION related.
+	 * Returns <code>null</code> or any {@link FeatureTypeStyle} contained in the given {@link Style} that is SELECTION
+	 * related.
 	 * 
 	 * @see {@link FeatureMapLayerSelectionSynchronizer#SELECTION_STYLING_FTS_NAME}
 	 */
-	public static FeatureTypeStyle getSelectionFeatureTypeStyle(
-			final Style style) {
+	public static FeatureTypeStyle getSelectionFeatureTypeStyle(final Style style) {
 
 		if (style == null)
 			return null;
@@ -2102,8 +1933,7 @@
 			FeatureTypeStyle fts = style.featureTypeStyles().get(ii);
 
 			if (fts.getName() != null
-					&& fts.getName()
-							.equals(FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME)) {
+					&& fts.getName().equals(FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME)) {
 				return style.featureTypeStyles().get(ii);
 			}
 		}
@@ -2205,16 +2035,15 @@
 
 	/**
 	 * @param style
-	 *            A {@link Style} to search for the first {@link TextSymbolizer}
-	 *            that will be used for the given {@link SimpleFeature}.
+	 *            A {@link Style} to search for the first {@link TextSymbolizer} that will be used for the given
+	 *            {@link SimpleFeature}.
 	 * 
 	 * @author Stefan A. Tzeggai (wikisquare.de) für CPA Systems GmbH A. Tzeggai
 	 * 
-	 * @return <code>null</code> or the first {@link TextSymbolizer} found in
-	 *         the style that applies to the {@link SimpleFeature}.
+	 * @return <code>null</code> or the first {@link TextSymbolizer} found in the style that applies to the
+	 *         {@link SimpleFeature}.
 	 */
-	public static TextSymbolizer getTextSymbolizer(final Style style,
-			final SimpleFeature f) {
+	public static TextSymbolizer getTextSymbolizer(final Style style, final SimpleFeature f) {
 		if (f == null)
 			return null;
 		try {
@@ -2249,14 +2078,12 @@
 
 	/**
 	 * @param style
-	 *            A {@link Style} to search for all {@link TextSymbolizer}s . No
-	 *            guarantee, that any one of them will ever be used for any
-	 *            feature (think about filters).
+	 *            A {@link Style} to search for all {@link TextSymbolizer}s . No guarantee, that any one of them will
+	 *            ever be used for any feature (think about filters).
 	 * 
 	 * @author Stefan A. Tzeggai (wikisquare.de) für CPA Systems GmbH A. Tzeggai
 	 * 
-	 * @return {@link List} or all {@link TextSymbolizer}s found in the
-	 *         {@link Style}.
+	 * @return {@link List} or all {@link TextSymbolizer}s found in the {@link Style}.
 	 */
 	public static List<TextSymbolizer> getTextSymbolizers(final Style style) {
 		List<TextSymbolizer> results = new ArrayList<TextSymbolizer>();
@@ -2280,17 +2107,14 @@
 
 	/**
 	 * @param symbolizers
-	 *            List of Symbolizers to search for all {@link TextSymbolizer}s
-	 *            . No guarantee, that any one of them will ever be used for any
-	 *            feature (think about filters).
+	 *            List of Symbolizers to search for all {@link TextSymbolizer}s . No guarantee, that any one of them
+	 *            will ever be used for any feature (think about filters).
 	 * 
 	 * @author Stefan A. Tzeggai (wikisquare.de) für CPA Systems GmbH A. Tzeggai
 	 * 
-	 * @return {@link List} or all {@link TextSymbolizer}s found in the given
-	 *         symbolizers.
+	 * @return {@link List} or all {@link TextSymbolizer}s found in the given symbolizers.
 	 */
-	public static List<TextSymbolizer> getTextSymbolizers(
-			Symbolizer[] symbolizers) {
+	public static List<TextSymbolizer> getTextSymbolizers(Symbolizer[] symbolizers) {
 		List<TextSymbolizer> results = new ArrayList<TextSymbolizer>();
 		try {
 			if (symbolizers != null) {
@@ -2312,17 +2136,14 @@
 
 	/**
 	 * @param style
-	 *            A {@link Style} to search for all {@link TextSymbolizer}s . No
-	 *            guarantee, that any one of them will ever be used for any
-	 *            feature (think about filters).
+	 *            A {@link Style} to search for all {@link TextSymbolizer}s . No guarantee, that any one of them will
+	 *            ever be used for any feature (think about filters).
 	 * 
 	 * @author Stefan A. Tzeggai (wikisquare.de) für CPA Systems GmbH A. Tzeggai
 	 * 
-	 * @return {@link List} or all {@link TextSymbolizer}s found in the
-	 *         {@link Style}.
+	 * @return {@link List} or all {@link TextSymbolizer}s found in the {@link Style}.
 	 */
-	public static List<TextSymbolizer> getVisibleTextSymbolizers(
-			final Style style) {
+	public static List<TextSymbolizer> getVisibleTextSymbolizers(final Style style) {
 		List<TextSymbolizer> results = new ArrayList<TextSymbolizer>();
 		try {
 			if (style != null) {
@@ -2335,9 +2156,8 @@
 							/*
 							 * We are comparing it to AsUtil.alwaysfalsefilter
 							 * 
-							 * public static final PropertyIsEqualTo
-							 * allwaysFalseFilter = ff2.equals(ff2
-							 * .literal("1"), ff2.literal("2"));
+							 * public static final PropertyIsEqualTo allwaysFalseFilter = ff2.equals(ff2 .literal("1"),
+							 * ff2.literal("2"));
 							 */
 							try {
 
@@ -2345,20 +2165,14 @@
 								if (f instanceof And) {
 									And and = (And) f;
 									if (and.getChildren() != null) {
-										Filter candidateF = and.getChildren()
-												.get(0);
+										Filter candidateF = and.getChildren().get(0);
 										if (candidateF instanceof PropertyIsEqualTo) {
 											final PropertyIsEqualTo compare = (PropertyIsEqualTo) candidateF;
 											if (compare.getExpression1() instanceof Literal
 													&& compare.getExpression2() instanceof Literal) {
-												Literal test1 = (Literal) compare
-														.getExpression1();
-												Literal test2 = (Literal) compare
-														.getExpression2();
-												if (test1.toString()
-														.equals("1")
-														&& test2.toString()
-																.equals("2")) {
+												Literal test1 = (Literal) compare.getExpression1();
+												Literal test2 = (Literal) compare.getExpression2();
+												if (test1.toString().equals("1") && test2.toString().equals("2")) {
 													// This TextSymbolizer is
 													// disabled using
 													// ASUtil.allwaysFalseFilter
@@ -2372,9 +2186,7 @@
 									}
 								}
 							} catch (Exception e) {
-								LOGGER.debug(
-										"Checking for textSymbolizer allwaysFalseFilter",
-										e);
+								LOGGER.debug("Checking for textSymbolizer allwaysFalseFilter", e);
 							}
 						}
 
@@ -2398,8 +2210,7 @@
 	 *            The first {@link Style}
 	 * @param style2file
 	 *            A {@link File} pointing to the second {@link Style}
-	 * @return <code>true</code> is they are different, ignoring any XML
-	 *         fomatting.
+	 * @return <code>true</code> is they are different, ignoring any XML fomatting.
 	 */
 	public static boolean isStyleDifferent(Style style1, File style2file) {
 		try {
@@ -2431,8 +2242,7 @@
 	 *            The first {@link Style}
 	 * @param style2
 	 *            The second {@link Style} to compare to
-	 * @return <code>true</code> is they are different, ignoring any XML
-	 *         fomatting.
+	 * @return <code>true</code> is they are different, ignoring any XML fomatting.
 	 */
 	public static boolean isStyleDifferent(Style style1, Style style2) {
 		try {
@@ -2443,8 +2253,8 @@
 			return !style1string.equals(style2string);
 
 		} catch (Exception e) {
-			LOGGER.debug("Compating styles " + style1 + " and " + style2
-					+ " failed. So we assume they are different.", e);
+			LOGGER.debug("Compating styles " + style1 + " and " + style2 + " failed. So we assume they are different.",
+					e);
 			return true;
 		}
 
@@ -2478,8 +2288,7 @@
 	 * @param inputStream
 	 *            {@link InputStream} to read the SLD from
 	 * 
-	 * @return An {@link Array} of {@link Style}s, can be length==0. null if
-	 *         file not exists
+	 * @return An {@link Array} of {@link Style}s, can be length==0. null if file not exists
 	 * 
 	 * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 */
@@ -2487,14 +2296,11 @@
 
 		Style[] styles = null;
 		try {
-			SLDParser stylereader = new SLDParser(StylingUtil.STYLE_FACTORY,
-					inputStream);
+			SLDParser stylereader = new SLDParser(StylingUtil.STYLE_FACTORY, inputStream);
 			styles = stylereader.readXML();
 			return styles;
 		} catch (Exception e) {
-			LOGGER.warn(
-					" ... no styles recognized. Return 'new Style[] { null }' ",
-					e);
+			LOGGER.warn(" ... no styles recognized. Return 'new Style[] { null }' ", e);
 			return new Style[] { null };
 		}
 
@@ -2506,8 +2312,8 @@
 	 * @param url
 	 *            {@link URL} to read the SLD from
 	 * 
-	 * @return An {@link Array} of {@link Style}s, can be length==0 if no
-	 *         UserStyles in SLD file. null if file not exists
+	 * @return An {@link Array} of {@link Style}s, can be length==0 if no UserStyles in SLD file. null if file not
+	 *         exists
 	 * 
 	 * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 */
@@ -2523,18 +2329,14 @@
 		}
 	}
 
-	public static StyledLayerDescriptor loadStyledLayerDescriptor(
-			InputStream inputStream) {
+	public static StyledLayerDescriptor loadStyledLayerDescriptor(InputStream inputStream) {
 		StyledLayerDescriptor sld = null;
 		try {
-			SLDParser stylereader = new SLDParser(StylingUtil.STYLE_FACTORY,
-					inputStream);
+			SLDParser stylereader = new SLDParser(StylingUtil.STYLE_FACTORY, inputStream);
 			sld = stylereader.parseSLD();
 			return sld;
 		} catch (Exception e) {
-			LOGGER.warn(
-					" ... no StyledLayerDescriptor recognized. Returning null ",
-					e);
+			LOGGER.warn(" ... no StyledLayerDescriptor recognized. Returning null ", e);
 			return sld;
 		}
 	}
@@ -2542,27 +2344,22 @@
 	public static StyledLayerDescriptor loadStyledLayerDescriptor(Reader reader) {
 		StyledLayerDescriptor sld = null;
 		try {
-			SLDParser stylereader = new SLDParser(StylingUtil.STYLE_FACTORY,
-					reader);
+			SLDParser stylereader = new SLDParser(StylingUtil.STYLE_FACTORY, reader);
 			sld = stylereader.parseSLD();
 			return sld;
 		} catch (Exception e) {
-			LOGGER.warn(
-					" ... no StyledLayerDescriptor recognized. Returning null ",
-					e);
+			LOGGER.warn(" ... no StyledLayerDescriptor recognized. Returning null ", e);
 			return sld;
 		}
 	}
 
-	static public ColorMap parseColormapToSld(File colormapFile)
-			throws IOException {
+	static public ColorMap parseColormapToSld(File colormapFile) throws IOException {
 		return parseColormapToSld(DataUtilities.fileToURL(colormapFile));
 	}
 
 	/**
-	 * Creates a Geotools Colormap containing all the Color Palette definitions
-	 * defined in the File. The File may have different formats. Supported
-	 * formats are<br/>
+	 * Creates a Geotools Colormap containing all the Color Palette definitions defined in the File. The File may have
+	 * different formats. Supported formats are<br/>
 	 * <ul>
 	 * <li>gdalinfo output</li>
 	 * </ul>
@@ -2572,9 +2369,7 @@
 	 * 
 	 * TODO Stefan Tzeggai Support gdal xml.aux format!
 	 * 
-	 * @see http 
-	 *      ://osgeo-org.1803224.n2.nabble.com/gdal-dev-Color-palette-file-for
-	 *      -use-in-rgb2pct-td4493744.html
+	 * @see http ://osgeo-org.1803224.n2.nabble.com/gdal-dev-Color-palette-file-for -use-in-rgb2pct-td4493744.html
 	 */
 	static public ColorMap parseColormapToSld(URL url) throws IOException {
 
@@ -2593,66 +2388,56 @@
 
 				Matcher matcher = GDALINFO_COLORMAP_RGBA.matcher(line);
 				if (matcher.find()) {
-					Color color = new Color(Integer.valueOf(matcher.group(2)),
-							Integer.valueOf(matcher.group(3)),
-							Integer.valueOf(matcher.group(4)),
-							Integer.valueOf(matcher.group(5)));
+					Color color = new Color(Integer.valueOf(matcher.group(2)), Integer.valueOf(matcher.group(3)),
+							Integer.valueOf(matcher.group(4)), Integer.valueOf(matcher.group(5)));
 
 					// Arrays verlängern
 					labels = LangUtil.extendArray(labels, "");
 					colors = LangUtil.extendArray(colors, color);
-					quantities = LangUtil.extendArray(quantities,
-							Double.valueOf(matcher.group(1)));
+					quantities = LangUtil.extendArray(quantities, Double.valueOf(matcher.group(1)));
 
 					// Zur nächsten Zeile springen
 					continue;
 				}
 			} catch (Exception e) {
-				LOGGER.warn("Error parsing a line to ColorMapEntry. Line = '"
-						+ line + "'. Skipped.", e);
+				LOGGER.warn("Error parsing a line to ColorMapEntry. Line = '" + line + "'. Skipped.", e);
 			}
 
 			try {
 				Matcher matcher = GDALINFO_COLORMAP_RGB.matcher(line);
 				if (matcher.find()) {
-					Color color = new Color(Integer.valueOf(matcher.group(2)),
-							Integer.valueOf(matcher.group(3)),
+					Color color = new Color(Integer.valueOf(matcher.group(2)), Integer.valueOf(matcher.group(3)),
 							Integer.valueOf(matcher.group(4)));
 
 					// Arrays verlängern
 					labels = LangUtil.extendArray(labels, "");
 					colors = LangUtil.extendArray(colors, color);
-					quantities = LangUtil.extendArray(quantities,
-							Double.valueOf(matcher.group(1)));
+					quantities = LangUtil.extendArray(quantities, Double.valueOf(matcher.group(1)));
 
 					// Zur nächsten Zeile springen
 					continue;
 
 				}
 			} catch (Exception e) {
-				LOGGER.warn("Error parsing a line to ColorMapEntry. Line = '"
-						+ line + "'. Skipped.", e);
+				LOGGER.warn("Error parsing a line to ColorMapEntry. Line = '" + line + "'. Skipped.", e);
 			}
 		}
 
 		int type = ColorMap.TYPE_VALUES;
-		ColorMap createColorMap = STYLE_BUILDER.createColorMap(labels,
-				quantities, colors, type);
+		ColorMap createColorMap = STYLE_BUILDER.createColorMap(labels, quantities, colors, type);
 		return createColorMap;
 	}
 
 	/**
-	 * Unless {@link ColorMap} has no methods to remove an entry this method
-	 * creates a new {@link ColorMap} with the identical entries except the one
-	 * to remove.
+	 * Unless {@link ColorMap} has no methods to remove an entry this method creates a new {@link ColorMap} with the
+	 * identical entries except the one to remove.
 	 * 
 	 * @param colorMap
 	 *            the color map to remove entries from
 	 * @param colorMapEntry
 	 *            the entry to remove
 	 */
-	public static ColorMap removeColorMapEntry(ColorMap colorMap,
-			ColorMapEntry colorMapEntry) {
+	public static ColorMap removeColorMapEntry(ColorMap colorMap, ColorMapEntry colorMapEntry) {
 		ColorMap newColorMap = new ColorMapImpl();
 		applyColorMapProperties(colorMap, newColorMap);
 
@@ -2665,9 +2450,8 @@
 	}
 
 	/**
-	 * Unless {@link ColorMap} has no methods to remove an entry this method
-	 * creates a new {@link ColorMap} with the identical entries except the one
-	 * to remove.
+	 * Unless {@link ColorMap} has no methods to remove an entry this method creates a new {@link ColorMap} with the
+	 * identical entries except the one to remove.
 	 * 
 	 * @param colorMap
 	 *            the color map to remove entries from
@@ -2687,8 +2471,8 @@
 	}
 
 	/**
-	 * Creates a copy of the given {@link Style}, removing any
-	 * {@link FeatureTypeStyle}s that are only SELECTION related.
+	 * Creates a copy of the given {@link Style}, removing any {@link FeatureTypeStyle}s that are only SELECTION
+	 * related.
 	 * 
 	 * @see {@link FeatureMapLayerSelectionSynchronizer#SELECTION_STYLING_FTS_NAME}
 	 */
@@ -2705,8 +2489,7 @@
 			FeatureTypeStyle fts = style.featureTypeStyles().get(ii);
 
 			if (fts.getName() != null
-					&& fts.getName()
-							.equals(FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME)) {
+					&& fts.getName().equals(FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING_FTS_NAME)) {
 				cleanStyle.featureTypeStyles().remove(ii);
 				break;
 			}
@@ -2722,13 +2505,11 @@
 	 * @param oldColor
 	 * @param newColor
 	 */
-	public static void replaceFillColor(Fill fill, Color oldColor,
-			Color newColor) {
+	public static void replaceFillColor(Fill fill, Color oldColor, Color newColor) {
 		if (fill == null)
 			return;
 
-		if ((fill.getColor() != null)
-				&& (getColorFromExpression(fill.getColor()).equals(oldColor)))
+		if ((fill.getColor() != null) && (getColorFromExpression(fill.getColor()).equals(oldColor)))
 			fill.setColor(STYLE_BUILDER.colorExpression(newColor));
 
 		replaceGraphicColor(fill.getGraphicFill(), oldColor, newColor);
@@ -2744,8 +2525,7 @@
 	 * 
 	 * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 */
-	public static void replaceGraphicColor(Graphic graphic, Color oldColor,
-			Color newColor) {
+	public static void replaceGraphicColor(Graphic graphic, Color oldColor, Color newColor) {
 		if (graphic == null)
 			return;
 
@@ -2767,8 +2547,7 @@
 	 * 
 	 * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 */
-	public static void replaceLineSymbolizerColor(LineSymbolizer ps,
-			Color oldColor, Color newColor) {
+	public static void replaceLineSymbolizerColor(LineSymbolizer ps, Color oldColor, Color newColor) {
 		if (ps == null)
 			return;
 
@@ -2780,8 +2559,7 @@
 	 * 
 	 * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 */
-	public static void replacePointSymbolizerColor(PointSymbolizer ps,
-			Color oldColor, Color newColor) {
+	public static void replacePointSymbolizerColor(PointSymbolizer ps, Color oldColor, Color newColor) {
 		if (ps == null)
 			return;
 
@@ -2796,8 +2574,7 @@
 	 * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 * @param ps
 	 */
-	public static void replacePolygonSymbolizerColor(PolygonSymbolizer ps,
-			Color oldColor, Color newColor) {
+	public static void replacePolygonSymbolizerColor(PolygonSymbolizer ps, Color oldColor, Color newColor) {
 		replaceFillColor(ps.getFill(), oldColor, newColor);
 		replaceStrokeColor(ps.getStroke(), oldColor, newColor);
 	}
@@ -2809,14 +2586,11 @@
 	 * @param oldColor
 	 * @param newColor
 	 */
-	public static void replaceStrokeColor(Stroke stroke, Color oldColor,
-			Color newColor) {
+	public static void replaceStrokeColor(Stroke stroke, Color oldColor, Color newColor) {
 		if (stroke == null)
 			return;
 
-		if ((stroke.getColor() != null)
-				&& (StylingUtil.getColorFromExpression(stroke.getColor())
-						.equals(oldColor)))
+		if ((stroke.getColor() != null) && (StylingUtil.getColorFromExpression(stroke.getColor()).equals(oldColor)))
 			stroke.setColor(StylingUtil.STYLE_BUILDER.colorExpression(newColor));
 
 		replaceGraphicColor(stroke.getGraphicFill(), oldColor, newColor);
@@ -2830,8 +2604,7 @@
 	 * 
 	 * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 */
-	public static void replaceSymbolizerColor(Symbolizer symb, Color oldColor,
-			Color newColor) {
+	public static void replaceSymbolizerColor(Symbolizer symb, Color oldColor, Color newColor) {
 		if (symb == null)
 			return;
 
@@ -2853,72 +2626,131 @@
 	}
 
 	/**
-	 * Saves the {@link Style} to OGC SLD. Overwrites any existing file. If a
-	 * FeatureTypeStyle for selection is used, it is automatically removed. This
-	 * 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/>
+	 * Saves the {@link Style} to OGC SLD. Overwrites any existing file. If a FeatureTypeStyle for selection is used, it
+	 * is automatically removed. This 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/>
 	 * All text ist converted to UTF-8.
 	 * 
 	 * @param origStyle
-	 *            {@link Style} to save. Any selectino related FeatureTypeStyle
-	 *            will be removed.
+	 *            {@link Style} to save. Any selectino related FeatureTypeStyle will be removed.
 	 * 
 	 * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 * 
-	 * @return <code>true</code> if the file was really written.
-	 *         <code>false</code> means, that the existing file already
-	 *         contained the same content and was not touched.
+	 * @return <code>true</code> if the file was really written. <code>false</code> means, that the existing file
+	 *         already contained the same content and was not touched.
 	 * @throws IOException
 	 */
-	public static final boolean saveStyleToSld(Style origStyle, File exportFile)
-			throws IOException {
+	public static final boolean saveStyleToSld(Style origStyle, File exportFile) throws IOException {
+		return saveStyleToSld(origStyle, exportFile, false);
+	}
+
+	/**
+	 * Saves the {@link Style} to OGC SLD. Overwrites any existing file. If a FeatureTypeStyle for selection is used, it
+	 * is automatically removed. This 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/>
+	 * All text ist converted to UTF-8.
+	 * 
+	 * @param origStyle
+	 *            {@link Style} to save. Any selectino related FeatureTypeStyle will be removed.
+	 * 
+	 * @param optimized
+	 *            If <code>true</code> any redundant information (typically used by AtlasStyler for GUI state and
+	 *            internal information) is thrown away.
+	 * 
+	 * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
+	 * 
+	 * @return <code>true</code> if the file was really written. <code>false</code> means, that the existing file
+	 *         already contained the same content and was not touched.
+	 * @throws IOException
+	 */
+	public static final boolean saveStyleToSld(Style origStyle, File exportFile, boolean optimized) throws IOException {
 		try {
 
 			// Wenn Datei nicht mit .sld endet, die Dateierweiterung
 			// anhängen
-			exportFile = IOUtil.appendFileExt(exportFile, ".sld");
+			if (!exportFile.getName().endsWith(".sld"))
+				exportFile = IOUtil.appendFileExt(exportFile, ".sld");
 
 			Style exportStyle = removeSelectionFeatureTypeStyle(origStyle);
 
-			// Nur in Datei speichern, wenn
+			if (optimized) {
+				exportStyle = optimizeStyle(exportStyle);
+			}
+
+			// Nur in Datei speichern, wenn auch eine Änderung vorliegt.
 			if (!isStyleDifferent(exportStyle, exportFile)) {
 				return false;
 			}
 
 			SLDTRANSFORMER.setEncoding(Charset.forName("UTF-8"));
 			StringWriter nativeWritten = new StringWriter();
-				SLDTRANSFORMER.transform(exportStyle, nativeWritten);
-			
+			SLDTRANSFORMER.transform(exportStyle, nativeWritten);
 
 			FileOutputStream output = new FileOutputStream(exportFile);
 			try {
-				IOUtils.write(nativeWritten.getBuffer().toString(),
-						output, "UTF-8");
+				String string = nativeWritten.getBuffer().toString();
+
+				if (optimized) {
+					string = string.replaceFirst("\\<sld", OPTIMIZED_COMMENT + "\n<sld");
+				}
+				IOUtils.write(string, output, "UTF-8");
 			} finally {
 				output.flush();
 				output.close();
 			}
 
 			LOGGER.debug("Validating stored file " + exportFile + "... ");
-			List<Exception> validateSld = validateSld(new FileInputStream(
-					exportFile));
+			List<Exception> validateSld = validateSld(new FileInputStream(exportFile));
 			if (validateSld.size() > 0) {
-				LOGGER.error(exportFile + " is not valid SLD: "
-						+ validateSld.size() + " exceptions");
+				LOGGER.error(exportFile + " is not valid SLD: " + validateSld.size() + " exceptions");
 			}
 			for (Exception e : validateSld) {
 				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;
 	}
 
+	/**
+	 * United multiple feature type styles that work on the same feature type
+	 */
+	private static Style optimizeStyle(Style style) {
+
+		Style oStyle = STYLE_BUILDER.createStyle();
+		
+		// TODO
+		/*
+		 * Wenn ich ein "AND (A,B)" finde, wo A eines meine Immertrue ist, dann mache daraus B 
+		 * Wenn ich ein "AND (A,B)" finde, wo A eines meine False ist, dann schmeisse die ganze Rule weg?!?! 
+		 * Wenn ich ein "ODER(A,A)" finde, dann mache daraus A 
+		 */
+		
+
+		Map<Name, List<Rule>> ftsRules = new java.util.HashMap<Name, List<Rule>>();
+
+		for (FeatureTypeStyle fts : style.featureTypeStyles()) {
+			for (Name name : fts.featureTypeNames()) {
+				if (ftsRules.get(name) == null)
+					ftsRules.put(name, fts.rules());
+				else 
+					ftsRules.get(name).addAll(fts.rules());
+			}
+		}
+
+		for (Name ftsName : ftsRules.keySet()) {
+			oStyle.featureTypeStyles()
+					.add(STYLE_BUILDER.createFeatureTypeStyle(ftsName.toString(),
+							ftsRules.get(ftsName).toArray(new Rule[0])));
+		}
+
+		return oStyle;
+	}
+
 	final static Parser parser = new Parser(SLD_CONFIGURATION);
+
 	/**
 	 * XMl coming from the {@link InputStream} validates against SLD 1.0
 	 */
@@ -2934,9 +2766,7 @@
 				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;
 		}
@@ -2945,30 +2775,35 @@
 	}
 
 	/**
-	 * True if the given XMl coming from the {@link InputStream} is validates
-	 * against SLD 1.0
+	 * 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.
+	 * Exports the {@link Style} to OGC SLD. If a FeatureTypeStyle for selection is used, it is automatically removed.
 	 * 
-	 * @param style
-	 *            {@link Style} to save. Any selectino related FeatureTypeStyle
-	 *            will be removed.
+	 * @param exportStyle
+	 *            {@link Style} to save. Any selectino related FeatureTypeStyle will be removed.
 	 * 
+	 * @param optimized
+	 *            If <code>true</code> any redundant information (typically used by AtlasStyler for GUI state and
+	 *            internal information) is thrown away.
+	 * 
 	 * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 * @throws TransformerException
 	 */
-	public static final void saveStyleToSLD(Style style,
-			OutputStream exportStream) throws TransformerException {
+	public static final void saveStyleToSLD(Style exportStyle, OutputStream exportStream, boolean optimized)
+			throws TransformerException {
 
-		style = removeSelectionFeatureTypeStyle(style);
+		exportStyle = removeSelectionFeatureTypeStyle(exportStyle);
 
-		SLDTRANSFORMER.transform(style, exportStream);
+		if (optimized) {
+			exportStyle = optimizeStyle(exportStyle);
+		}
+
+		SLDTRANSFORMER.transform(exportStyle, exportStream);
 	}
 
 	/**
@@ -2985,9 +2820,8 @@
 	}
 
 	/**
-	 * AtlasStyler has a fixed system that allows to use one or two label
-	 * attributes. If two are used, the are seperated by ": ". This mehtod stes
-	 * one or two ProperybaName fields.
+	 * AtlasStyler has a fixed system that allows to use one or two label attributes. If two are used, the are seperated
+	 * by ": ". This mehtod stes one or two ProperybaName fields.
 	 * 
 	 * @param symbolizer
 	 *            the {@link TextSymbolizer} to call setLabel(Expression) on.
@@ -2996,17 +2830,13 @@
 	 * @param literalLabelField2
 	 *            may be <code>null</code>
 	 */
-	public static void setDoublePropertyName(final TextSymbolizer symbolizer,
-			final PropertyName literalLabelField1,
+	public static void setDoublePropertyName(final TextSymbolizer symbolizer, final PropertyName literalLabelField1,
 			final PropertyName literalLabelField2) {
-		if (literalLabelField2 != null
-				&& !literalLabelField2.getPropertyName().isEmpty()
+		if (literalLabelField2 != null && !literalLabelField2.getPropertyName().isEmpty()
 				&& !literalLabelField2.toString().equalsIgnoreCase("-")) {
 			final Literal trenner = FilterUtil.FILTER_FAC2.literal(": ");
-			final Function f3 = FilterUtil.FILTER_FAC2.function("strConcat",
-					trenner, literalLabelField2);
-			final Function bothExpression = FilterUtil.FILTER_FAC2.function(
-					"strConcat", literalLabelField1, f3);
+			final Function f3 = FilterUtil.FILTER_FAC2.function("strConcat", trenner, literalLabelField2);
+			final Function bothExpression = FilterUtil.FILTER_FAC2.function("strConcat", literalLabelField1, f3);
 			LOGGER.debug("Extended label expression is now: " + bothExpression);
 			symbolizer.setLabel(bothExpression);
 		} else {
@@ -3022,8 +2852,7 @@
 	 * @param opacity
 	 *            Transparenzwert
 	 */
-	public static void setOpacityForColorMapEntry(ColorMapEntry entry,
-			double opacity) {
+	public static void setOpacityForColorMapEntry(ColorMapEntry entry, double opacity) {
 		if (entry != null)
 			entry.setOpacity(STYLE_BUILDER.literalExpression(opacity));
 	}
@@ -3036,8 +2865,7 @@
 	 * @param quantity
 	 *            neuer Wert
 	 */
-	public static void setQuantityForColorMapEntry(ColorMapEntry entry,
-			double quantity) {
+	public static void setQuantityForColorMapEntry(ColorMapEntry entry, double quantity) {
 		if (entry != null)
 			entry.setQuantity(STYLE_BUILDER.literalExpression(quantity));
 	}
@@ -3075,8 +2903,7 @@
 	}
 
 	/**
-	 * Converts a {@link StyledLayerDescriptor} or any of it's subcomponents to
-	 * XML.
+	 * Converts a {@link StyledLayerDescriptor} or any of it's subcomponents to XML.
 	 * 
 	 * @throws TransformerException
 	 */
@@ -3084,8 +2911,7 @@
 		return SLDTRANSFORMER.transform(sld);
 	}
 
-	public static boolean validates(FeatureTypeStyle fts) throws IOException,
-			TransformerException {
+	public static boolean validates(FeatureTypeStyle fts) throws IOException, TransformerException {
 		// Bytestream not file!
 		Style s = STYLE_BUILDER.createStyle();
 		s.featureTypeStyles().add(fts);
@@ -3095,12 +2921,15 @@
 	public static boolean validates(Style style) throws IOException {
 		// Bytestream not file!
 		File tempFile = File.createTempFile("testing", ".sld");
-		saveStyleToSld(style, tempFile);
-		return validates(new FileInputStream(tempFile));
+		try {
+			saveStyleToSld(style, tempFile, false);
+			return validates(new FileInputStream(tempFile));
+		} finally {
+			tempFile.delete();
+		}
 	}
 
-	public static boolean isStyleDifferent(FeatureTypeStyle fts1,
-			FeatureTypeStyle fts2) {
+	public static boolean isStyleDifferent(FeatureTypeStyle fts1, FeatureTypeStyle fts2) {
 		Style style1 = STYLE_BUILDER.createStyle();
 		style1.featureTypeStyles().add(fts1);
 
@@ -3115,20 +2944,17 @@
 		return xml;
 	}
 
-	public static void correctGeometryPropertyname(
-			final SimpleFeatureType schema, Symbolizer sym) {
+	public static void correctGeometryPropertyname(final SimpleFeatureType schema, Symbolizer sym) {
 		String newGpn = sym.getGeometryPropertyName();
 
 		if (schema != null) {
 			// If we have a schema,
-			GeometryDescriptor geometryDescriptor = schema
-					.getGeometryDescriptor();
+			GeometryDescriptor geometryDescriptor = schema.getGeometryDescriptor();
 			if (geometryDescriptor != null)
 				newGpn = geometryDescriptor.getName().toString();
 
 			if (newGpn != null) {
-				NameImpl found = FeatureUtil.findBestMatchingAttribute(schema,
-						newGpn);
+				NameImpl found = FeatureUtil.findBestMatchingAttribute(schema, newGpn);
 				if (found != null)
 					newGpn = found.getLocalPart();
 				else
@@ -3141,8 +2967,7 @@
 	}
 
 	/***************************************************************************
-	 * Copies all Values from one {@link TextSymbolizer} to another
-	 * {@link TextSymbolizer}
+	 * Copies all Values from one {@link TextSymbolizer} to another {@link TextSymbolizer}
 	 * 
 	 * @param from
 	 *            {@link TextSymbolizer} source
@@ -3152,8 +2977,7 @@
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 */
 
-	public static void copyAllValues(final TextSymbolizer from,
-			final TextSymbolizer to) {
+	public static void copyAllValues(final TextSymbolizer from, final TextSymbolizer to) {
 		to.setLabel(from.getLabel());
 		to.setPriority(from.getPriority());
 
@@ -3161,14 +2985,10 @@
 
 		final FilterFactory2 ff2 = FeatureUtil.FILTER_FACTORY2;
 
-		to.getFonts()[0].setFontFamily(ff2.literal(from.getFonts()[0]
-				.getFontFamily().toString()));
-		to.getFonts()[0].setFontSize(ff2.literal(from.getFonts()[0]
-				.getFontSize().toString()));
-		to.getFonts()[0].setFontWeight(ff2.literal(from.getFonts()[0]
-				.getFontWeight().toString()));
-		to.getFonts()[0].setFontStyle(ff2.literal(from.getFonts()[0]
-				.getFontStyle().toString()));
+		to.getFonts()[0].setFontFamily(ff2.literal(from.getFonts()[0].getFontFamily().toString()));
+		to.getFonts()[0].setFontSize(ff2.literal(from.getFonts()[0].getFontSize().toString()));
+		to.getFonts()[0].setFontWeight(ff2.literal(from.getFonts()[0].getFontWeight().toString()));
+		to.getFonts()[0].setFontStyle(ff2.literal(from.getFonts()[0].getFontStyle().toString()));
 	}
 
 }



More information about the Schmitzm-commits mailing list