use of org.geotoolkit.se.xml.v110.RuleType in project geotoolkit by Geomatys.
the class SEforSLD110Test method testRule.
@Test
public void testRule() throws JAXBException, FactoryException {
final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
final Marshaller MARSHALLER = POOL.acquireMarshaller();
// Read test
Object obj = UNMARSHALLER.unmarshal(FILE_SE_RULE);
assertNotNull(obj);
JAXBElement<?> jax = (JAXBElement<?>) obj;
MutableRule rule = TRANSFORMER_GT.visitRule(jax.getValue());
assertNotNull(rule);
assertEquals(rule.getName(), valueName);
assertEquals(rule.getDescription().getTitle().toString(), valueTitle);
assertEquals(rule.getDescription().getAbstract().toString(), valueAbstract);
assertEquals(rule.getMinScaleDenominator(), 500d, DELTA);
assertEquals(rule.getMaxScaleDenominator(), 1000d, DELTA);
assertNull(rule.getLegend());
assertNotNull(rule.getFilter());
assertEquals(rule.symbolizers().size(), 4);
// Write test
RuleType pvt = (RuleType) TRANSFORMER_OGC.visit(rule, null);
assertNotNull(pvt);
assertEquals(pvt.getName(), valueName);
assertEquals(String.valueOf(pvt.getDescription().getTitle()), valueTitle);
assertEquals(String.valueOf(pvt.getDescription().getAbstract()), valueAbstract);
assertEquals(pvt.getMinScaleDenominator(), 500d, DELTA);
assertEquals(pvt.getMaxScaleDenominator(), 1000d, DELTA);
assertNull(pvt.getLegendGraphic());
assertEquals(pvt.getSymbolizer().size(), 4);
MARSHALLER.marshal(new ObjectFactory().createRule(pvt), TEST_FILE_SE_RULE);
POOL.recycle(MARSHALLER);
POOL.recycle(UNMARSHALLER);
}
use of org.geotoolkit.se.xml.v110.RuleType in project geotoolkit by Geomatys.
the class SE110toGTTransformer method visitRule.
/**
* Trasnform SLD v1.1 rule in GT Rule.
*/
public MutableRule visitRule(final org.geotoolkit.se.xml.v110.RuleType rt) throws FactoryException {
final MutableRule rule = styleFactory.rule();
rule.setName(rt.getName());
rule.setDescription(visitDescription(rt.getDescription()));
rule.setElseFilter(rt.getElseFilter() != null);
rule.setFilter(visitFilter(rt.getFilter()));
rule.setLegendGraphic(visitLegend(rt.getLegendGraphic()));
rule.setMaxScaleDenominator((rt.getMaxScaleDenominator() == null) ? Double.MAX_VALUE : rt.getMaxScaleDenominator());
rule.setMinScaleDenominator((rt.getMinScaleDenominator() == null) ? 0 : rt.getMinScaleDenominator());
if (rt.getSymbolizer() == null || rt.getSymbolizer().isEmpty()) {
} else {
for (final JAXBElement<?> jax : rt.getSymbolizer()) {
final Object st = jax.getValue();
if (st == null) {
continue;
} else if (st instanceof SymbolizerType) {
rule.symbolizers().add(visit((SymbolizerType) st));
} else if (st instanceof Symbolizer) {
rule.symbolizers().add((Symbolizer) st);
}
}
}
return rule;
}
use of org.geotoolkit.se.xml.v110.RuleType in project geotoolkit by Geomatys.
the class GTtoSE110Transformer method visit.
/**
* Transform a GT rule in jaxb rule or OnlineResource
*/
@Override
public Object visit(final Rule rule, final Object data) {
if (rule.getOnlineResource() != null) {
// we store only the online resource
return visit(rule.getOnlineResource(), null);
}
final RuleType rt = se_factory.createRuleType();
rt.setName(rule.getName());
rt.setDescription(visit(rule.getDescription(), null));
if (rule.isElseFilter()) {
rt.setElseFilter(se_factory.createElseFilterType());
} else if (rule.getFilter() != null) {
rt.setFilter(apply(rule.getFilter()));
}
if (rule.getLegend() != null) {
rt.setLegendGraphic(visit(rule.getLegend(), null));
}
rt.setMaxScaleDenominator(rule.getMaxScaleDenominator());
rt.setMinScaleDenominator(rule.getMinScaleDenominator());
for (final Symbolizer symbol : rule.symbolizers()) {
if (symbol instanceof LineSymbolizer) {
rt.getSymbolizer().add(visit((LineSymbolizer) symbol, null));
} else if (symbol instanceof PolygonSymbolizer) {
rt.getSymbolizer().add(visit((PolygonSymbolizer) symbol, null));
} else if (symbol instanceof PointSymbolizer) {
rt.getSymbolizer().add(visit((PointSymbolizer) symbol, null));
} else if (symbol instanceof RasterSymbolizer) {
rt.getSymbolizer().add(visit((RasterSymbolizer) symbol, null));
} else if (symbol instanceof TextSymbolizer) {
rt.getSymbolizer().add(visit((TextSymbolizer) symbol, null));
} else if (symbol instanceof ExtensionSymbolizer) {
((List) rt.getSymbolizer()).add(visit((ExtensionSymbolizer) symbol, null));
}
}
return rt;
}
Aggregations