Permalink
Browse files

[GEOT-4443] Literal strips CDATA whitespace from the Label

  • Loading branch information...
1 parent 3b09cbe commit 308bfa810c42da2107f2528df30dd8601c12d392 @aaime aaime committed Apr 20, 2013
@@ -208,7 +208,8 @@ public Expression expression(Node root) {
return null;
}
- if (kid.getNodeValue().trim().length() == 0) {
+ // CDATA shouldn't be interpretted
+ if (kid.getNodeType() != Node.CDATA_SECTION_NODE && kid.getNodeValue().trim().length() == 0) {
LOGGER.finest("empty text element");
continue;
@@ -272,6 +272,25 @@ public void testSLDParserWithhMixedContentCDATASpaces() throws Exception {
assertEquals("literal_1\nliteral_2", labelValue);
}
+
+ public void testSLDParserWithFuncConcatenateCDATASpaces() throws Exception {
+ java.net.URL surl = TestData.getResource(this, "funcConcatenateWithCDATASpaces.xml");
+ SLDParser stylereader = new SLDParser(sf, surl);
+ StyledLayerDescriptor sld = stylereader.parseSLD();
+
+ Symbolizer[] symbolizers = ((NamedLayer) sld.getStyledLayers()[0]).getStyles()[0]
+ .getFeatureTypeStyles()[0].getRules()[0].getSymbolizers();
+
+ TextSymbolizer text = (TextSymbolizer) symbolizers[0];
+
+ Expression label = text.getLabel();
+
+ String labelValue = (String) label.evaluate(null, String.class);
+
+ // System.out.println(labelValue);
+
+ assertEquals("literal_1\n literal_2", labelValue);
+ }
public void testStrokeCssParameter() throws Exception {
java.net.URL surl = TestData.getResource(this, "strokeParam.sld");
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<StyledLayerDescriptor version="1.0.0"
+ xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"
+ xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <NamedLayer>
+ <Name>OCEANSEA_1M:Foundation</Name>
+ <UserStyle>
+ <Name>GEOSYM</Name>
+ <FeatureTypeStyle>
+ <Rule>
+ <Name>Polygon fill mixed</Name>
+ <TextSymbolizer>
+ <Label>
+ <!-- this is a label consisting of the concatenation of two expressions with a
+ CDATA section in between to assert we can avoid whitespaces, newlines, etc from being trimmed -->
+ <ogc:Function name="Concatenate">
+ <ogc:Literal>literal_1</ogc:Literal>
+ <ogc:Literal><![CDATA[
+ ]]></ogc:Literal>
+ <ogc:Literal>literal_2</ogc:Literal>
+ </ogc:Function>
+ </Label>
+ </TextSymbolizer>
+ </Rule>
+ </FeatureTypeStyle>
+ </UserStyle>
+ </NamedLayer>
+</StyledLayerDescriptor>

0 comments on commit 308bfa8

Please sign in to comment.