Package org.geoserver.wms

Examples of org.geoserver.wms.GetLegendGraphicRequest


        // only intercepting getLegendGraphic invokation
        if (id.equalsIgnoreCase("getLegendGraphic")) {
            final Object[] params = operation.getParameters();
            if (params != null && params.length > 0 && params[0] instanceof GetLegendGraphicRequest) {

                final GetLegendGraphicRequest getLegendRequest = (GetLegendGraphicRequest) params[0];
                final List<Style> styles = getLegendRequest.getStyles();

                // Retrieving the colorRamp definition
                final String colorRamp = getColorRampDefinition(styles);
                Map map = request.getRawKvp();
                if (colorRamp != null && map.containsKey("LAYER")) {
View Full Code Here


            if ((!layers.isEmpty() && !layers.contains(layer.getTitle())) || applicableRules.length == 0) {
                continue;
            }

            BufferedImageLegendGraphicBuilder legendGraphicBuilder = new BufferedImageLegendGraphicBuilder();
            GetLegendGraphicRequest request = new GetLegendGraphicRequest();
            request.setLayer(layer.getFeatureSource().getSchema());
            request.setTransparent(true);
            request.setScale(scaleDenominator);
            request.setStyle(layer.getStyle());

            Map legendOptions = new CaseInsensitiveMap(options);
            legendOptions.putAll(mapContext.getRequest().getFormatOptions());
            request.setLegendOptions(legendOptions);

            LayerLegend legend = new LayerLegend();
            legend.request = request;

            String title = findTitle(layer, wms.getGeoServer().getCatalog());
View Full Code Here

    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Override
    public GetLegendGraphicRequest read(Object req, Map kvp, Map rawKvp) throws Exception {

        GetLegendGraphicRequest request = (GetLegendGraphicRequest) super.read(req, kvp, rawKvp);
        request.setRawKvp(rawKvp);

        if (request.getVersion() == null || request.getVersion().length() == 0) {
            String version = (String) rawKvp.get("WMTVER");
            if (version == null) {
                version = wms.getVersion();
            }
            request.setVersion(version);
        }
       
        final String language = (String) rawKvp.get("LANGUAGE");
        if(language != null) {
            request.setLocale(new Locale(language));
        }

        // Fix for http://jira.codehaus.org/browse/GEOS-710
        // Since at the moment none of the other request do check the version
        // numbers, we
        // disable this check for the moment, and wait for a proper fix once the
        // we support more than one version of WMS/WFS specs
        // if (!GetLegendGraphicRequest.SLD_VERSION.equals(version)) {
        // throw new WmsException("Invalid SLD version number \"" + version
        // + "\"");
        // }
        final String layer = (String) rawKvp.get("LAYER");
        final boolean strict = rawKvp.containsKey("STRICT") ? Boolean.valueOf((String) rawKvp
                .get("STRICT")) : request.isStrict();
        request.setStrict(strict);
        if (strict && layer == null) {
            throw new ServiceException("LAYER parameter not present for GetLegendGraphic",
                    "LayerNotDefined");
        }
        if (strict && request.getFormat() == null) {
            throw new ServiceException("Missing FORMAT parameter for GetLegendGraphic",
                    "MissingFormat");
        }

        // object representing the layer or layer group requested
        Object infoObject=null;
       
        // list of layers to render in the legend (we can have more
        // than one if a layergroup is requested)
        List<FeatureType> layers = new ArrayList<FeatureType>();
        if (layer != null) {
            try {
                LayerInfo layerInfo = wms.getLayerByName(layer);
                if (layerInfo != null) {
                    addLayer(layers,layerInfo,request);
                    infoObject=layerInfo;
                } else {
                    LayerGroupInfo layerGroupInfo = wms.getLayerGroupByName(layer);
                    if(layerGroupInfo != null) {
                        // add all single layers of the group
                        for(LayerInfo singleLayer : layerGroupInfo.layers()) {
                            addLayer(layers,singleLayer,request);
                        }
                        infoObject=layerGroupInfo;
                    } else {
                        throw new ServiceException(layer + " layer does not exist.");
                    }
                }
                request.setLayers(layers);
            } catch (IOException e) {
                throw new ServiceException(e);
            } catch (NoSuchElementException ne) {
                throw new ServiceException(new StringBuffer(layer)
                        .append(" layer does not exists.").toString(), ne);
            } catch (Exception te) {
                throw new ServiceException("Can't obtain the schema for the required layer.", te);
            }
        } else {
            layers.add(null);
            request.setLayers(layers);
        }

        if (request.getFormat() == null) {
            request.setFormat(GetLegendGraphicRequest.DEFAULT_FORMAT);
        }
        if (null == wms.getLegendGraphicOutputFormat(request.getFormat())) {
            throw new ServiceException(new StringBuffer("Invalid graphic format: ").append(
                    request.getFormat()).toString(), "InvalidFormat");
        }

        try {
            parseOptionalParameters(request, infoObject, rawKvp);
           
            if (layers.size() != request.getStyles().size()) {
                String msg = layers.size() + " layers requested, but found " + request.getStyles().size()
                        + " styles specified. ";
                throw new ServiceException(msg, getClass().getName());
            }
           
            if (request.getRules().size()>0 && layers.size() != request.getRules().size()) {
                String msg = layers.size() + " layers requested, but found " + request.getRules().size()
                        + " rules specified. ";
                throw new ServiceException(msg, getClass().getName());
            }
        } catch (IOException e) {
            throw new ServiceException(e);
View Full Code Here

     * @see org.geoserver.ows.Response#canHandle(org.geoserver.platform.Operation)
     */
    @Override
    public boolean canHandle(Operation operation) {
        Object[] parameters = operation.getParameters();
        GetLegendGraphicRequest request = OwsUtils.parameter(parameters,
                GetLegendGraphicRequest.class);
        return request != null && getOutputFormats().contains(request.getFormat());
    }
View Full Code Here

        this.allParameters.put("SLD", remoteSldUrl.toExternalForm());

        this.allParameters.put("LAYER", "cite:Ponds");
        this.allParameters.put("STYLE", "Ponds");

        GetLegendGraphicRequest request = requestReader.read(new GetLegendGraphicRequest(),
                allParameters, allParameters);

        // the style names Ponds is declared in third position on the sld doc
        Style selectedStyle = request.getStyles().get(0);
        assertNotNull(selectedStyle);
        assertEquals("Ponds", selectedStyle.getName());

        this.allParameters.put("LAYER", "cite:Lakes");
        this.allParameters.put("STYLE", "Lakes");

        request = requestReader.read(new GetLegendGraphicRequest(), allParameters, allParameters);

        // the style names Ponds is declared in third position on the sld doc
        selectedStyle = request.getStyles().get(0);
        assertNotNull(selectedStyle);
        assertEquals("Lakes", selectedStyle.getName());
    }
View Full Code Here

   
    @org.junit.Test
    public void testMissingLayerParameter() throws Exception {
        requiredParameters.remove("LAYER");
        try {
            requestReader.read(new GetLegendGraphicRequest(), requiredParameters,
                    requiredParameters);
            fail("Expected ServiceException");
        } catch (ServiceException e) {
            assertEquals("LayerNotDefined", e.getCode());
        }
View Full Code Here

   
    @org.junit.Test
    public void testMissingFormatParameter() throws Exception {
        requiredParameters.remove("FORMAT");
        try {
            requestReader.read(new GetLegendGraphicRequest(), requiredParameters,
                    requiredParameters);
            fail("Expected ServiceException");
        } catch (ServiceException e) {
            assertEquals("MissingFormat", e.getCode());
        }
View Full Code Here

            assertEquals("MissingFormat", e.getCode());
        }
    }
    @org.junit.Test
    public void testStrictParameter() throws Exception {
        GetLegendGraphicRequest request;

        // default value
        request = requestReader.read(new GetLegendGraphicRequest(), allParameters, allParameters);
        assertTrue(request.isStrict());

        allParameters.put("STRICT", "false");
        allParameters.remove("LAYER");
        request = requestReader.read(new GetLegendGraphicRequest(), allParameters, allParameters);
        assertFalse(request.isStrict());
    }
View Full Code Here

        assertFalse(request.isStrict());
    }
   
    @org.junit.Test
    public void testLayerGroup() throws Exception {
        GetLegendGraphicRequest request;
       
        request = requestReader.read(new GetLegendGraphicRequest(), requiredParameters, requiredParameters);
        assertTrue(request.getLayers().size() == 1);
       
        requiredParameters.put("LAYER", NATURE_GROUP);
        request = requestReader.read(new GetLegendGraphicRequest(), requiredParameters, requiredParameters);
        assertTrue(request.getLayers().size() > 1);
    }
View Full Code Here

        assertTrue(request.getLayers().size() > 1);
    }
   
    @org.junit.Test
    public void testLanguage() throws Exception {
        GetLegendGraphicRequest request;
       
        request = requestReader.read(new GetLegendGraphicRequest(), requiredParameters, requiredParameters);
        assertNull(request.getLocale());
       
        request = requestReader.read(new GetLegendGraphicRequest(), allParameters, allParameters);
        assertEquals(Locale.ENGLISH, request.getLocale());
    }
View Full Code Here

TOP

Related Classes of org.geoserver.wms.GetLegendGraphicRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.