Search in sources :

Example 1 with UserLayer

use of org.geotoolkit.sld.xml.v110.UserLayer in project geotoolkit by Geomatys.

the class SLD110Test method testSLD.

// //////////////////////////////////////////////////////////////////////////
// JAXB TEST MARSHELLING AND UNMARSHELLING FOR STYLE ORDERING //////////////
// //////////////////////////////////////////////////////////////////////////
@Test
public void testSLD() throws JAXBException, FactoryException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test-------------------------------------------------------------
    // ----------------------------------------------------------------------
    Object obj = UNMARSHALLER.unmarshal(FILE_SLD);
    assertNotNull(obj);
    StyledLayerDescriptor jax = (StyledLayerDescriptor) obj;
    MutableStyledLayerDescriptor sld = TRANSFORMER_GT.visit(jax);
    assertNotNull(sld);
    // Details
    assertEquals(sld.getName(), "SLD : name");
    assertEquals(sld.getDescription().getTitle().toString(), "SLD : title");
    assertEquals(sld.getDescription().getAbstract().toString(), "SLD : abstract");
    // libraries
    assertEquals(sld.libraries().size(), 1);
    assertEquals(sld.libraries().get(0).getOnlineResource().getLinkage().toString(), "http://geomayts.fr/anSLDFile.xml");
    // layers
    assertEquals(sld.layers().size(), 2);
    // Named Layer-----------------------------------------------------------
    NamedLayer nl = (NamedLayer) sld.layers().get(0);
    assertEquals(nl.getName(), "Named layer : name");
    assertEquals(nl.getDescription().getTitle().toString(), "Named layer : title");
    assertEquals(nl.getDescription().getAbstract().toString(), "Named layer : abstract");
    List<? extends FeatureTypeConstraint> cons = nl.getConstraints().constraints();
    assertEquals(cons.size(), 1);
    assertNotNull(cons.get(0).getFilter());
    assertTrue(cons.get(0).getFeatureTypeName().toString().endsWith("FeatureName"));
    assertEquals(cons.get(0).getExtent().size(), 3);
    Extent ext = cons.get(0).getExtent().get(0);
    assertEquals(ext.getName(), "Ext : Name 1");
    assertEquals(ext.getValue(), "Ext : Value 1");
    ext = cons.get(0).getExtent().get(1);
    assertEquals(ext.getName(), "Ext : Name 2");
    assertEquals(ext.getValue(), "Ext : Value 2");
    ext = cons.get(0).getExtent().get(2);
    assertEquals(ext.getName(), "Ext : Name 3");
    assertEquals(ext.getValue(), "Ext : Value 3");
    // Named Style-----------------------------------------------------------
    assertEquals(nl.styles().size(), 1);
    NamedStyle ns = (NamedStyle) nl.styles().get(0);
    assertEquals(ns.getName(), "Named style : name");
    assertEquals(ns.getDescription().getTitle().toString(), "Named style : title");
    assertEquals(ns.getDescription().getAbstract().toString(), "Named style : abstract");
    // User Layer------------------------------------------------------------
    UserLayer ul = (UserLayer) sld.layers().get(1);
    assertEquals(ul.getName(), "User layer : name");
    assertEquals(ul.getDescription().getTitle().toString(), "User layer : title");
    assertEquals(ul.getDescription().getAbstract().toString(), "User layer : abstract");
    RemoteOWS source = (RemoteOWS) ul.getSource();
    assertEquals(source.getService(), "WFS");
    assertEquals(source.getOnlineResource().getLinkage().toString(), "http://some.site.com/WFS?");
    cons = ((LayerFeatureConstraints) ul.getConstraints()).constraints();
    assertEquals(cons.size(), 1);
    assertNotNull(cons.get(0).getFilter());
    assertTrue(cons.get(0).getFeatureTypeName().toString().endsWith("FeatureName"));
    assertEquals(cons.get(0).getExtent().size(), 2);
    ext = cons.get(0).getExtent().get(0);
    assertEquals(ext.getName(), "Ext : Name 1");
    assertEquals(ext.getValue(), "Ext : Value 1");
    ext = cons.get(0).getExtent().get(1);
    assertEquals(ext.getName(), "Ext : Name 2");
    assertEquals(ext.getValue(), "Ext : Value 2");
    assertEquals(ul.styles().size(), 1);
    // we dont test the user style, this is done in the SE test
    // Write test------------------------------------------------------------
    // ----------------------------------------------------------------------
    StyledLayerDescriptor pvt = TRANSFORMER_SLD.visit(sld, null);
    assertNotNull(pvt);
    assertEquals(pvt.getName(), "SLD : name");
    assertEquals(String.valueOf(pvt.getDescription().getTitle()), "SLD : title");
    assertEquals(String.valueOf(pvt.getDescription().getAbstract()), "SLD : abstract");
    // layers
    assertEquals(pvt.getNamedLayerOrUserLayer().size(), 2);
    // Named Layer-----------------------------------------------------------
    org.geotoolkit.sld.xml.v110.NamedLayer nlt = (org.geotoolkit.sld.xml.v110.NamedLayer) pvt.getNamedLayerOrUserLayer().get(0);
    assertEquals(nlt.getName(), "Named layer : name");
    assertEquals(String.valueOf(nlt.getDescription().getTitle()), "Named layer : title");
    assertEquals(String.valueOf(nlt.getDescription().getAbstract()), "Named layer : abstract");
    List<org.geotoolkit.sld.xml.v110.FeatureTypeConstraint> constr = nlt.getLayerFeatureConstraints().getFeatureTypeConstraint();
    assertEquals(constr.size(), 1);
    assertNotNull(constr.get(0).getFilter());
    assertTrue(cons.get(0).getFeatureTypeName().toString().endsWith("FeatureName"));
    assertEquals(constr.get(0).getExtent().size(), 3);
    org.geotoolkit.sld.xml.v110.Extent extx = constr.get(0).getExtent().get(0);
    assertEquals(extx.getName(), "Ext : Name 1");
    assertEquals(extx.getValue(), "Ext : Value 1");
    extx = constr.get(0).getExtent().get(1);
    assertEquals(extx.getName(), "Ext : Name 2");
    assertEquals(extx.getValue(), "Ext : Value 2");
    extx = constr.get(0).getExtent().get(2);
    assertEquals(extx.getName(), "Ext : Name 3");
    assertEquals(extx.getValue(), "Ext : Value 3");
    // Named Style-----------------------------------------------------------
    assertEquals(nlt.getNamedStyleOrUserStyle().size(), 1);
    org.geotoolkit.sld.xml.v110.NamedStyle nst = (org.geotoolkit.sld.xml.v110.NamedStyle) nlt.getNamedStyleOrUserStyle().get(0);
    assertEquals(nst.getName(), "Named style : name");
    assertEquals(String.valueOf(nst.getDescription().getTitle()), "Named style : title");
    assertEquals(String.valueOf(nst.getDescription().getAbstract()), "Named style : abstract");
    // User Layer------------------------------------------------------------
    org.geotoolkit.sld.xml.v110.UserLayer ulx = (org.geotoolkit.sld.xml.v110.UserLayer) pvt.getNamedLayerOrUserLayer().get(1);
    assertEquals(ulx.getName(), "User layer : name");
    assertEquals(String.valueOf(ulx.getDescription().getTitle()), "User layer : title");
    assertEquals(String.valueOf(ulx.getDescription().getAbstract()), "User layer : abstract");
    org.geotoolkit.sld.xml.v110.RemoteOWS sourcex = (org.geotoolkit.sld.xml.v110.RemoteOWS) ulx.getRemoteOWS();
    assertEquals(sourcex.getService(), "WFS");
    assertEquals(sourcex.getOnlineResource().getHref(), "http://some.site.com/WFS?");
    constr = ulx.getLayerFeatureConstraints().getFeatureTypeConstraint();
    assertEquals(constr.size(), 1);
    assertNotNull(cons.get(0).getFilter());
    assertEquals(cons.get(0).getFeatureTypeName().tip().toString(), "FeatureName");
    assertEquals(cons.get(0).getExtent().size(), 2);
    ext = cons.get(0).getExtent().get(0);
    assertEquals(ext.getName(), "Ext : Name 1");
    assertEquals(ext.getValue(), "Ext : Value 1");
    ext = cons.get(0).getExtent().get(1);
    assertEquals(ext.getName(), "Ext : Name 2");
    assertEquals(ext.getValue(), "Ext : Value 2");
    assertEquals(ulx.getUserStyle().size(), 1);
    MARSHALLER.marshal(pvt, TEST_FILE_SLD);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : RemoteOWS(org.opengis.sld.RemoteOWS) Marshaller(javax.xml.bind.Marshaller) Extent(org.opengis.sld.Extent) NamedStyle(org.opengis.sld.NamedStyle) MutableStyledLayerDescriptor(org.geotoolkit.sld.MutableStyledLayerDescriptor) StyledLayerDescriptor(org.geotoolkit.sld.xml.v110.StyledLayerDescriptor) FeatureTypeConstraint(org.opengis.sld.FeatureTypeConstraint) Unmarshaller(javax.xml.bind.Unmarshaller) UserLayer(org.opengis.sld.UserLayer) NamedLayer(org.opengis.sld.NamedLayer) MutableStyledLayerDescriptor(org.geotoolkit.sld.MutableStyledLayerDescriptor) Test(org.junit.Test)

Example 2 with UserLayer

use of org.geotoolkit.sld.xml.v110.UserLayer in project geotoolkit by Geomatys.

the class ProvidersXmlTest method testUnmarshallingWithSLD.

/**
 * Test for the unmarshalling process of a string-representation of a {@link MapContext}.
 *
 * @throws JAXBException
 */
@Test
public void testUnmarshallingWithSLD() throws JAXBException {
    final StringReader sr = new StringReader(RESULT_MARSHALLING_WITH_SLD);
    final Object result = unmarshaller.unmarshal(new StringReader(RESULT_MARSHALLING_WITH_SLD));
    sr.close();
    assertNotNull(result);
    assertTrue(result instanceof MapContext);
    final MapContext mc = (MapContext) result;
    final List<MapItem> mapItems = mc.getMapItem().getMapItems();
    assertNotNull(mapItems);
    assertFalse(mapItems.isEmpty());
    assertEquals(3, mapItems.size());
    final MapLayer ml0 = (MapLayer) mapItems.get(0).getMapItems().get(0);
    assertEquals("postgis_test:my_otherlayer", ml0.getDataReference().getValue());
    assertTrue(ml0.getStyle().getNamedLayerOrUserLayer().get(0) instanceof UserLayer);
    final UserLayer ul = (UserLayer) ml0.getStyle().getNamedLayerOrUserLayer().get(0);
    assertTrue(ul.getUserStyle().get(0).getFeatureTypeStyleOrCoverageStyleOrOnlineResource().get(0) instanceof FeatureTypeStyleType);
    final FeatureTypeStyleType fts = (FeatureTypeStyleType) ul.getUserStyle().get(0).getFeatureTypeStyleOrCoverageStyleOrOnlineResource().get(0);
    assertEquals("ft_test", fts.getName());
    final MapLayer ml1 = (MapLayer) mapItems.get(0).getMapItems().get(1);
    assertEquals("coverage:my_thirdlayer", ml1.getDataReference().getValue());
    assertEquals("my_newstyle", ml1.getStyleReference().getValue());
    assertEquals("postgis_test:my_layer", ((MapLayer) mapItems.get(2)).getDataReference().getValue());
    assertEquals("my_style", ((MapLayer) mapItems.get(2)).getStyleReference().getValue());
}
Also used : StringReader(java.io.StringReader) FeatureTypeStyleType(org.geotoolkit.se.xml.v110.FeatureTypeStyleType) UserLayer(org.geotoolkit.sld.xml.v110.UserLayer)

Example 3 with UserLayer

use of org.geotoolkit.sld.xml.v110.UserLayer in project geotoolkit by Geomatys.

the class ProvidersXmlTest method testMarshallingWithSLD.

/**
 * Test for the marshalling process of a {@link MapContext}.
 *
 * @throws JAXBException
 */
@Test
public void testMarshallingWithSLD() throws JAXBException, Exception {
    final List<MapItem> mapLayers2 = new ArrayList<>();
    final StyledLayerDescriptor sld = new StyledLayerDescriptor();
    final UserStyle us = new UserStyle();
    final DescriptionType title = new DescriptionType();
    title.setTitle("test_sld");
    us.setDescription(title);
    final FeatureTypeStyleType fts = new FeatureTypeStyleType();
    fts.setName("ft_test");
    us.getFeatureTypeStyleOrCoverageStyleOrOnlineResource().add(fts);
    final UserLayer ul = new UserLayer();
    ul.getUserStyle().add(us);
    sld.getNamedLayerOrUserLayer().add(ul);
    mapLayers2.add(new MapLayer(new DataReference("postgis_test:my_otherlayer"), sld));
    mapLayers2.add(new MapLayer(new DataReference("coverage:my_thirdlayer"), new StyleReference("my_newstyle")));
    final List<MapItem> mapItems = new ArrayList<>();
    mapItems.add(new MapItem(mapLayers2));
    final MapLayer ml = new MapLayer(new DataReference("postgis_test:my_layer"), new StyleReference("my_style"));
    mapItems.add(new MapItem());
    mapItems.add(ml);
    final MapItem mapItem = new MapItem(mapItems);
    final MapContext mapContext = new MapContext(mapItem);
    final StringWriter sw = new StringWriter();
    marshaller.marshal(mapContext, sw);
    final String result = sw.toString();
    try {
        sw.close();
    } catch (IOException e) {
        fail("Unable to close the writer");
    }
    assertNotNull(result);
    assertFalse(result.isEmpty());
    DocumentComparator comparator = new DocumentComparator(RESULT_MARSHALLING_WITH_SLD, result.trim());
    comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*");
    comparator.compare();
}
Also used : UserStyle(org.geotoolkit.sld.xml.v110.UserStyle) DescriptionType(org.geotoolkit.se.xml.v110.DescriptionType) ArrayList(java.util.ArrayList) IOException(java.io.IOException) StyledLayerDescriptor(org.geotoolkit.sld.xml.v110.StyledLayerDescriptor) StringWriter(java.io.StringWriter) DocumentComparator(org.apache.sis.test.xml.DocumentComparator) FeatureTypeStyleType(org.geotoolkit.se.xml.v110.FeatureTypeStyleType) UserLayer(org.geotoolkit.sld.xml.v110.UserLayer)

Example 4 with UserLayer

use of org.geotoolkit.sld.xml.v110.UserLayer in project geotoolkit by Geomatys.

the class SLD100toGTTransformer method visitLayers.

/**
 * Transform a jaxb v1.0.0 layers in a GT Layer objects.
 */
public Collection<? extends MutableLayer> visitLayers(final List<Object> layers) {
    if (layers == null || layers.isEmpty()) {
        return Collections.emptyList();
    } else {
        final Collection<MutableLayer> sldLayers = new ArrayList<MutableLayer>();
        for (final Object obj : layers) {
            if (obj instanceof NamedLayer) {
                final NamedLayer nl = (NamedLayer) obj;
                final MutableNamedLayer mnl = sldFactory.createNamedLayer();
                mnl.setName(nl.getName());
                mnl.getConstraints().constraints().addAll(visitFeatureConstraints(nl.getLayerFeatureConstraints()));
                mnl.styles().addAll(visitStyles(nl.getNamedStyleOrUserStyle()));
                sldLayers.add(mnl);
            } else if (obj instanceof UserLayer) {
                final UserLayer ul = (UserLayer) obj;
                final MutableUserLayer mul = sldFactory.createUserLayer();
                mul.setName(ul.getName());
                mul.styles().addAll(visitUserStyles(ul.getUserStyle()));
                if (ul.getLayerFeatureConstraints() != null) {
                    final MutableLayerFeatureConstraints consts = sldFactory.createLayerFeatureConstraints();
                    consts.constraints().addAll(visitFeatureConstraints(ul.getLayerFeatureConstraints()));
                    mul.setConstraints(consts);
                }
                if (ul.getRemoteOWS() != null) {
                    mul.setSource(visiteRemoteOWS(ul.getRemoteOWS()));
                }
                sldLayers.add(mul);
            }
        }
        return sldLayers;
    }
}
Also used : ArrayList(java.util.ArrayList) MutableNamedLayer(org.geotoolkit.sld.MutableNamedLayer) UserLayer(org.geotoolkit.sld.xml.v100.UserLayer) MutableUserLayer(org.geotoolkit.sld.MutableUserLayer) NamedLayer(org.geotoolkit.sld.xml.v100.NamedLayer) MutableNamedLayer(org.geotoolkit.sld.MutableNamedLayer) MutableUserLayer(org.geotoolkit.sld.MutableUserLayer) MutableLayerFeatureConstraints(org.geotoolkit.sld.MutableLayerFeatureConstraints) MutableLayer(org.geotoolkit.sld.MutableLayer)

Example 5 with UserLayer

use of org.geotoolkit.sld.xml.v110.UserLayer in project geotoolkit by Geomatys.

the class GTtoSLD110Transformer method visit.

@Override
public org.geotoolkit.sld.xml.v110.StyledLayerDescriptor visit(final StyledLayerDescriptor sld, final Object data) {
    final org.geotoolkit.sld.xml.v110.StyledLayerDescriptor versionned = sld_factory.createStyledLayerDescriptor();
    versionned.setName(sld.getName());
    // versionned.setVersion(sld.getVersion());
    versionned.setDescription(visit(sld.getDescription(), null));
    for (final SLDLibrary lib : sld.libraries()) {
        versionned.getUseSLDLibrary().add(visit(lib, null));
    }
    for (final Layer layer : sld.layers()) {
        if (layer instanceof NamedLayer) {
            final NamedLayer named = (NamedLayer) layer;
            versionned.getNamedLayerOrUserLayer().add(visit(named, null));
        } else if (layer instanceof UserLayer) {
            final UserLayer user = (UserLayer) layer;
            versionned.getNamedLayerOrUserLayer().add(visit(user, null));
        }
    }
    return versionned;
}
Also used : SLDLibrary(org.opengis.sld.SLDLibrary) UseSLDLibrary(org.geotoolkit.sld.xml.v110.UseSLDLibrary) UserLayer(org.opengis.sld.UserLayer) Layer(org.opengis.sld.Layer) NamedLayer(org.opengis.sld.NamedLayer) UserLayer(org.opengis.sld.UserLayer) NamedLayer(org.opengis.sld.NamedLayer)

Aggregations

ArrayList (java.util.ArrayList)3 UserLayer (org.geotoolkit.sld.xml.v110.UserLayer)3 FeatureTypeStyleType (org.geotoolkit.se.xml.v110.FeatureTypeStyleType)2 MutableLayer (org.geotoolkit.sld.MutableLayer)2 MutableLayerFeatureConstraints (org.geotoolkit.sld.MutableLayerFeatureConstraints)2 MutableNamedLayer (org.geotoolkit.sld.MutableNamedLayer)2 MutableUserLayer (org.geotoolkit.sld.MutableUserLayer)2 StyledLayerDescriptor (org.geotoolkit.sld.xml.v110.StyledLayerDescriptor)2 NamedLayer (org.opengis.sld.NamedLayer)2 UserLayer (org.opengis.sld.UserLayer)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 DocumentComparator (org.apache.sis.test.xml.DocumentComparator)1 DescriptionType (org.geotoolkit.se.xml.v110.DescriptionType)1 MutableLayerCoverageConstraints (org.geotoolkit.sld.MutableLayerCoverageConstraints)1 MutableStyledLayerDescriptor (org.geotoolkit.sld.MutableStyledLayerDescriptor)1 NamedLayer (org.geotoolkit.sld.xml.v100.NamedLayer)1