Package org.vfny.geoserver.wms.requests

Examples of org.vfny.geoserver.wms.requests.GetMapRequest


    public void setParseStyle(boolean styleRequired) {
        this.parseStyles = styleRequired;
    }

    public Object createRequest() throws Exception {
        GetMapRequest request = new GetMapRequest(wms);
        request.setHttpServletRequest(httpRequest);

        return request;
    }
View Full Code Here


        return request;
    }

    @Override
    public GetMapRequest read(Object request, Map kvp, Map rawKvp) throws Exception {
        GetMapRequest getMap = (GetMapRequest) super.read(request, kvp, rawKvp);

        // do some additional checks

        // srs
        String epsgCode = getMap.getSRS();

        if (epsgCode != null) {
            try {
                // set the crs as well
                CoordinateReferenceSystem mapcrs = CRS.decode(epsgCode);
                getMap.setCrs(mapcrs);
            } catch (Exception e) {
                // couldnt make it - we send off a service exception with the
                // correct info
                throw new WmsException("Error occurred decoding the espg code " + epsgCode,
                        "InvalidSRS", e);
            }
        }

        // remote OWS
        String remoteOwsType = getMap.getRemoteOwsType();
        remoteOwsType = remoteOwsType != null ? remoteOwsType.toUpperCase() : null;
        if (remoteOwsType != null && !"WFS".equals(remoteOwsType)) {
            throw new WmsException("Unsupported remote OWS type '" + remoteOwsType + "'");
        }

        // remote OWS url
        URL remoteOwsUrl = getMap.getRemoteOwsURL();
        if (remoteOwsUrl != null && remoteOwsType == null){
            throw new WmsException("REMOTE_OWS_URL specified, but REMOTE_OWS_TYPE is missing");
        }
       
        final List<Object> requestedLayerInfos = new ArrayList<Object>();
        // layers
        String layerParam = (String) kvp.get("LAYERS");
        if (layerParam != null) {
            List<String> layerNames = KvpUtils.readFlat(layerParam);
            requestedLayerInfos.addAll(parseLayers(layerNames, remoteOwsUrl, remoteOwsType));

            List<MapLayerInfo> layers = new ArrayList<MapLayerInfo>();
            for(Object o : requestedLayerInfos){
                if(o instanceof LayerInfo){
                    layers.add(new MapLayerInfo((LayerInfo)o));
                }else if(o instanceof LayerGroupInfo){
                    for(LayerInfo l : ((LayerGroupInfo)o).getLayers()){
                        layers.add(new MapLayerInfo(l));
                    }
                }else if(o instanceof MapLayerInfo){
                    //it was a remote OWS layer, add it directly
                    layers.add((MapLayerInfo) o);
                }
            }
            getMap.setLayers(layers.toArray(new MapLayerInfo[layers.size()]));
        }


        // raw styles parameter
        String stylesParam = (String) kvp.get("STYLES");
        List<String> styleNameList = new ArrayList<String>();
        if (stylesParam != null) {
            styleNameList.addAll(KvpUtils.readFlat(stylesParam));
        }
       
        // pre parse filters
        List<Filter> filters = parseFilters(getMap);

        // styles
        // process SLD_BODY, SLD, then STYLES parameter
        if (getMap.getSldBody() != null) {
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine("Getting layers and styles from SLD_BODY");
            }

            if (getMap.getValidateSchema().booleanValue()) {
                List errors = validateSld(new ByteArrayInputStream(getMap.getSldBody().getBytes()));

                if (errors.size() != 0) {
                    throw new WmsException(SLDValidator.getErrorMessage(new ByteArrayInputStream(
                            getMap.getSldBody().getBytes()), errors));
                }
            }

            StyledLayerDescriptor sld = parseSld(new ByteArrayInputStream(getMap.getSldBody()
                    .getBytes()));
            processSld(getMap, requestedLayerInfos, sld, styleNameList);
           
            // set filter in, we'll check consistency later
            getMap.setFilter(filters);
        } else if (getMap.getSld() != null) {
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine("Getting layers and styles from reomte SLD");
            }

            URL sldUrl = getMap.getSld();

            if (getMap.getValidateSchema().booleanValue()) {
                InputStream input = Requests.getInputStream(sldUrl);
                List errors = null;

                try {
                    errors = validateSld(input);
                } finally {
                    input.close();
                }

                if ((errors != null) && (errors.size() != 0)) {
                    input = Requests.getInputStream(sldUrl);

                    try {
                        throw new WmsException(SLDValidator.getErrorMessage(input, errors));
                    } finally {
                        input.close();
                    }
                }
            }

            // JD: GEOS-420, Wrap the sldUrl in getINputStream method in order
            // to do compression
            InputStream input = Requests.getInputStream(sldUrl);

            try {
                StyledLayerDescriptor sld = parseSld(input);
                processSld(getMap, requestedLayerInfos, sld, styleNameList);
            } finally {
                input.close();
            }
           
            // set filter in, we'll check consistency later
            getMap.setFilter(filters);
        } else {
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine("Getting layers and styles from LAYERS and STYLES");
            }

            // ok, parse the styles parameter in isolation
            if (styleNameList.size() > 0){
                List<Style> parseStyles = parseStyles(styleNameList);
                getMap.setStyles(parseStyles);
            }
           
            // first, expand base layers and default styles
            if (isParseStyle() && requestedLayerInfos.size() > 0) {
                List<Style> oldStyles = getMap.getStyles() != null ? new ArrayList(getMap.getStyles())
                        : new ArrayList();
                List<Style> newStyles = new ArrayList<Style>();
                List<Filter> newFilters = filters == null ? null : new ArrayList<Filter>();

                for (int i = 0; i < requestedLayerInfos.size(); i++) {
                    Object o = requestedLayerInfos.get(i);
                    Style style = oldStyles.isEmpty() ? null : (Style) oldStyles.get(i);
                   
                    if (o instanceof LayerGroupInfo) {
                        LayerGroupInfo groupInfo = (LayerGroupInfo)o;
                        for(int j = 0; j < groupInfo.getStyles().size(); j++) {
                            StyleInfo si = groupInfo.getStyles().get(j);
                            if(si == null)
                                si = groupInfo.getLayers().get(j).getDefaultStyle();
                            newStyles.add(si.getStyle());
                        }
                        // expand the filter on the layer group to all its sublayers
                        if(filters != null) {
                            for (int j = 0; j < groupInfo.getLayers().size(); j++) {
                                newFilters.add(getFilter(filters, i));
                            }
                        }
                    } else if(o instanceof LayerInfo){
                        style = oldStyles.size() > 0? oldStyles.get(i) : null;
                        if (style != null){
                            newStyles.add(style);
                        }else{
                            StyleInfo defaultStyle = ((LayerInfo)o).getDefaultStyle();
                            newStyles.add(defaultStyle.getStyle());
                        }
                        // add filter if needed
                        if(filters != null)
                            newFilters.add(getFilter(filters, i));
                    } else if(o instanceof MapLayerInfo){
                        style = oldStyles.size() > 0? oldStyles.get(i) : null;
                        if (style != null){
                            newStyles.add(style);
                        } else{
                            throw new WmsException("no style requested for layer "
                                    + ((MapLayerInfo) o).getName(), "NoDefaultStyle");
                        }
                        // add filter if needed
                        if(filters != null)
                            newFilters.add(getFilter(filters, i));
                    }
                }
                getMap.setStyles(newStyles);
                getMap.setFilter(newFilters);
            }

            // then proceed with standard processing
            MapLayerInfo[] layers = getMap.getLayers();
            if (isParseStyle() && (layers != null) && (layers.length > 0)) {
                final List styles = getMap.getStyles();

                if (layers.length != styles.size()) {
                    String msg = layers.length + " layers requested, but found " + styles.size()
                            + " styles specified. ";
                    throw new WmsException(msg, getClass().getName());
                }

                for (int i = 0; i < styles.size(); i++) {
                    Style currStyle = (Style) getMap.getStyles().get(i);
                    if (currStyle == null)
                        throw new WmsException(
                                "Could not find a style for layer "
                                        + getMap.getLayers()[i].getName()
                                        + ", either none was specified or no default style is available for it",
                                "NoDefaultStyle");
                    checkStyle(currStyle, layers[i]);
                    if (LOGGER.isLoggable(Level.FINE)) {
                        LOGGER.fine(new StringBuffer("establishing ").append(currStyle.getName())
                                .append(" style for ").append(layers[i].getName()).toString());
                    }
                }
            }
           
            // check filter size matches with the layer list size
            List mapFilters = getMap.getFilter();
            MapLayerInfo[] mapLayers = getMap.getLayers();
            if (mapFilters != null && mapFilters.size() != mapLayers.length) {
                String msg = mapLayers.length
                        + " layers requested, but found " + mapFilters.size()
                        + " filters specified. ";
                throw new WmsException(msg, getClass().getName());
            }
        }

        // set the raw params used to create the request
        getMap.setRawKvp(rawKvp);

        return getMap;
    }
View Full Code Here

    public Object read(Object request, Reader reader, Map kvp) throws Exception {
        if ( request == null ) {
            throw new IllegalArgumentException( "request must be not null" );
        }
       
        GetMapRequest getMap = (GetMapRequest) request;
        StyledLayerDescriptor sld =
            new SLDParser( styleFactory, reader ).parseSLD();
       
        //process the sld
        GetMapKvpRequestReader.processStandaloneSld(getMap, sld);
View Full Code Here

    protected void execute(FeatureTypeInfo[] requestedLayers, Query[] queries,
        int x, int y) throws WmsException {
        GetFeatureInfoRequest request = getRequest();
        this.format = request.getInfoFormat();

        GetMapRequest getMapReq = request.getGetMapRequest();

        int width = getMapReq.getWidth();
        int height = getMapReq.getHeight();
        Envelope bbox = getMapReq.getBbox();

        Coordinate upperLeft = pixelToWorld(x - 2, y - 2, bbox, width, height);
        Coordinate lowerRight = pixelToWorld(x + 2, y + 2, bbox, width, height);

        Coordinate[] coords = new Coordinate[5];
View Full Code Here

     *
     * @throws ServiceException DOCUMENT ME!
     * @throws WmsException DOCUMENT ME!
     */
    public void execute(Request req) throws ServiceException {
        GetMapRequest request = (GetMapRequest) req;
       
        final String outputFormat = request.getFormat();

        this.delegate = getDelegate(outputFormat, config);

        final FeatureTypeInfo[] layers = request.getLayers();
        final Style[] styles = (Style[])request.getStyles().toArray(new Style[]{});

        //JD:make instance variable in order to release resources later
        //final WMSMapContext map = new WMSMapContext();
        map = new WMSMapContext();
       
        //DJB: the WMS spec says that the request must not be 0 area
        //     if it is, throw a service exception!
        Envelope env = request.getBbox();
        if (env.isNull() || (env.getWidth() <=0)|| (env.getHeight() <=0)){
          throw new WmsException("The request bounding box has zero area: " + env);
        }

        // DJB DONE: replace by setAreaOfInterest(Envelope,
        // CoordinateReferenceSystem)
        // with the user supplied SRS parameter
       
        //if there's a crs in the request, use that.  If not, assume its 4326
       
        CoordinateReferenceSystem mapcrs = request.getCrs();
       
        //DJB: added this to be nicer about the "NONE" srs.
        if (mapcrs !=null)
          map.setAreaOfInterest(request.getBbox(),mapcrs);
        else
          map.setAreaOfInterest(request.getBbox());
        map.setMapWidth(request.getWidth());
        map.setMapHeight(request.getHeight());
        map.setBgColor(request.getBgColor());
        map.setTransparent(request.isTransparent());

        LOGGER.fine("setting up map");

        
        MapLayer layer;
View Full Code Here

TOP

Related Classes of org.vfny.geoserver.wms.requests.GetMapRequest

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.