use of org.geotools.styling.visitor.DuplicatingStyleVisitor in project sldeditor by robward-scisys.
the class SLDEditorBufferedImageLegendGraphicBuilder method cloneSymbolizer.
/**
* Clones the given (Point)Symbolizer.
*
* @param symbolizer symbolizer to clone
* @return cloned Symbolizer
*/
private Symbolizer cloneSymbolizer(Symbolizer symbolizer) {
DuplicatingStyleVisitor duplicator = new DuplicatingStyleVisitor();
symbolizer.accept(duplicator);
return (Symbolizer) duplicator.getCopy();
}
use of org.geotools.styling.visitor.DuplicatingStyleVisitor in project sldeditor by robward-scisys.
the class SLDUtilsTest method testFindRule.
@Test
public void testFindRule() {
StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
sld.layers().add(DefaultSymbols.createNewNamedLayer());
sld.layers().add(namedLayer);
String expectedNamedLayer = "namedLayer";
namedLayer.setName(expectedNamedLayer);
Style style = DefaultSymbols.createNewStyle();
String expectedStyleLayer = "style";
style.setName(expectedStyleLayer);
namedLayer.addStyle(DefaultSymbols.createNewStyle());
namedLayer.addStyle(style);
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
String expectedFeatureTypeStyleLayer = "feature type style";
fts.setName(expectedFeatureTypeStyleLayer);
style.featureTypeStyles().add(DefaultSymbols.createNewFeatureTypeStyle());
style.featureTypeStyles().add(fts);
Rule rule = DefaultSymbols.createNewRule();
fts.rules().add(DefaultSymbols.createNewRule());
fts.rules().add(rule);
String expectedRule = "rule";
rule.setName(expectedRule);
String expectedSymbolizer = "text symbolizer";
TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
symbolizer.setName(expectedSymbolizer);
rule.symbolizers().add(DefaultSymbols.createDefaultPolygonSymbolizer());
rule.symbolizers().add(symbolizer);
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
symbolizer.setFont(font);
DuplicatingStyleVisitor duplicate = new DuplicatingStyleVisitor();
duplicate.visit(sld);
StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicate.getCopy();
Rule actualRule = SLDUtils.findRule(sld, rule, sldCopy);
assertNotNull(actualRule);
assertEquals(rule.getName(), actualRule.getName());
actualRule = SLDUtils.findRule(sld, null, sldCopy);
assertNull(actualRule);
actualRule = SLDUtils.findRule(sld, rule, null);
assertNull(actualRule);
}
use of org.geotools.styling.visitor.DuplicatingStyleVisitor in project sldeditor by robward-scisys.
the class SLDUtilsTest method testFindSymbolizer.
@Test
public void testFindSymbolizer() {
StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
sld.layers().add(DefaultSymbols.createNewNamedLayer());
sld.layers().add(namedLayer);
String expectedNamedLayer = "namedLayer";
namedLayer.setName(expectedNamedLayer);
Style style = DefaultSymbols.createNewStyle();
String expectedStyleLayer = "style";
style.setName(expectedStyleLayer);
namedLayer.addStyle(DefaultSymbols.createNewStyle());
namedLayer.addStyle(style);
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
String expectedFeatureTypeStyleLayer = "feature type style";
fts.setName(expectedFeatureTypeStyleLayer);
style.featureTypeStyles().add(DefaultSymbols.createNewFeatureTypeStyle());
style.featureTypeStyles().add(fts);
Rule rule = DefaultSymbols.createNewRule();
fts.rules().add(DefaultSymbols.createNewRule());
fts.rules().add(rule);
String expectedRule = "rule";
rule.setName(expectedRule);
String expectedSymbolizer = "text symbolizer";
TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
symbolizer.setName(expectedSymbolizer);
rule.symbolizers().add(DefaultSymbols.createDefaultPolygonSymbolizer());
rule.symbolizers().add(symbolizer);
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
symbolizer.setFont(font);
DuplicatingStyleVisitor duplicate = new DuplicatingStyleVisitor();
duplicate.visit(sld);
StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicate.getCopy();
Symbolizer actualSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, sldCopy);
assertNotNull(actualSymbolizer);
assertEquals(symbolizer.getLabel().toString(), ((TextSymbolizer) actualSymbolizer).getLabel().toString());
actualSymbolizer = SLDUtils.findSymbolizer(sld, null, sldCopy);
assertNull(actualSymbolizer);
actualSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, null);
assertNull(actualSymbolizer);
}
Aggregations