⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmscapstransformer.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 4 页
字号:

            handleDcpType(serviceUrl, serviceUrl);
            end("GetCapabilities");

            start("GetMap");

            List sortedFormats = new ArrayList(formats);
            Collections.sort(sortedFormats);
            // this is a hack necessary to make cite tests pass: we need an output format
            // that is equal to the mime type as the first one....
            if( sortedFormats.contains("image/png")) {
                sortedFormats.remove("image/png");
                sortedFormats.add(0, "image/png");
            }
            for (Iterator it = sortedFormats.iterator(); it.hasNext();) {
                element("Format", String.valueOf(it.next()));
            }

            handleDcpType(serviceUrl, null);
            end("GetMap");

            start("GetFeatureInfo");

            for (Iterator it = GetFeatureInfoResponse.getFormats().iterator(); it.hasNext();) {
                element("Format", String.valueOf(it.next()));
            }

            handleDcpType(serviceUrl, serviceUrl);
            end("GetFeatureInfo");

            start("DescribeLayer");
            element("Format", DescribeLayerResponse.DESCLAYER_MIME_TYPE);
            handleDcpType(serviceUrl, null);
            end("DescribeLayer");

            start("GetLegendGraphic");

            for (Iterator it = GetLegendGraphicResponse.getFormats(applicationContext).iterator();
                    it.hasNext();) {
                element("Format", String.valueOf(it.next()));
            }

            handleDcpType(serviceUrl, null);
            end("GetLegendGraphic");

            end("Request");
        }

        /**
         * Encodes a <code>DCPType</code> fragment for HTTP GET and POST
         * methods.
         *
         * @param getUrl the URL of the onlineresource for HTTP GET method
         *        requests
         * @param postUrl the URL of the onlineresource for HTTP POST method
         *        requests
         */
        private void handleDcpType(String getUrl, String postUrl) {
            AttributesImpl orAtts = new AttributesImpl();
            orAtts.addAttribute("", "xmlns:xlink", "xmlns:xlink", "", XLINK_NS);
            orAtts.addAttribute("", "xlink:type", "xlink:type", "", "simple");
            orAtts.addAttribute("", "xlink:href", "xlink:href", "", getUrl);
            start("DCPType");
            start("HTTP");

            if (getUrl != null) {
                start("Get");
                element("OnlineResource", null, orAtts);
                end("Get");
            }

            if (postUrl != null) {
                orAtts.setAttribute(2, "", "xlink:href", "xlink:href", "", postUrl);
                start("Post");
                element("OnlineResource", null, orAtts);
                end("Post");
            }

            end("HTTP");
            end("DCPType");
        }

        /**
         * DOCUMENT ME!
         */
        private void handleException() {
            start("Exception");

            WMS wms = (WMS) request.getServiceRef().getServiceRef();
            Iterator it = Arrays.asList(wms.getExceptionFormats()).iterator();

            while (it.hasNext()) {
                element("Format", String.valueOf(it.next()));
            }

            end("Exception");
        }

        /**
         * DOCUMENT ME!
         */
        private void handleSLD() {
            AttributesImpl sldAtts = new AttributesImpl();
            WMS config = (WMS) request.getServiceRef().getServiceRef();
            String supportsSLD = config.supportsSLD() ? "1" : "0";
            String supportsUserLayer = config.supportsUserLayer() ? "1" : "0";
            String supportsUserStyle = config.supportsUserStyle() ? "1" : "0";
            String supportsRemoteWFS = config.supportsRemoteWFS() ? "1" : "0";
            sldAtts.addAttribute("", "SupportSLD", "SupportSLD", "", supportsSLD);
            sldAtts.addAttribute("", "UserLayer", "UserLayer", "", supportsUserLayer);
            sldAtts.addAttribute("", "UserStyle", "UserStyle", "", supportsUserStyle);
            sldAtts.addAttribute("", "RemoteWFS", "RemoteWFS", "", supportsRemoteWFS);

            start("UserDefinedSymbolization", sldAtts);
            //          djb: this was removed, even though they are correct - the CITE tests have an incorrect DTD
            //       element("SupportedSLDVersion","1.0.0");  //djb: added that we support this.  We support partial 1.1
            end("UserDefinedSymbolization");

            //element("UserDefinedSymbolization", null, sldAtts);
        }

        /**
         * Handles the encoding of the layers elements.
         *
         * <p>
         * This method does a search over the SRS of all the layers to see if
         * there are at least a common one, as needed by the spec: "<i>The root
         * Layer element shall include a sequence of zero or more &lt;SRS&gt;
         * elements listing all SRSes that are common to all subsidiary layers.
         * Use a single SRS element with empty content (like so:
         * "&lt;SRS&gt;&lt;/SRS&gt;") if there is no common SRS."</i>
         * </p>
         *
         * <p>
         * By the other hand, this search is also used to collecto the whole
         * latlon bbox, as stated by the spec: <i>"The bounding box metadata in
         * Capabilities XML specify the minimum enclosing rectangle for the
         * layer as a whole."</i>
         * </p>
         *
         * @task TODO: manage this differently when we have the layer list of
         *       the WMS service decoupled from the feature types configured for
         *       the server instance. (This involves nested layers,
         *       gridcoverages, etc)
         */
        private void handleLayers() {
            WMS wms = (WMS) request.getServiceRef().getServiceRef();
            start("Layer");

            Data catalog = wms.getData();
            Collection ftypes = catalog.getFeatureTypeInfos().values();
            Collection coverages = catalog.getCoverageInfos().values();

            element("Title", wms.getTitle());
            element("Abstract", wms.getAbstract());

            handleRootSRSAndBbox(ftypes, MapLayerInfo.TYPE_VECTOR);

            // now encode each layer individually
            LayerTree featuresLayerTree = new LayerTree(ftypes);
            handleFeaturesTree(featuresLayerTree);

            LayerTree coveragesLayerTree = new LayerTree(coverages);
            handleCoveragesTree(coveragesLayerTree);

            try {
                handleLayerGroups(wms.getBaseMapLayers(), wms.getBaseMapStyles(),
                    wms.getBaseMapEnvelopes());
            } catch (FactoryException e) {
                throw new RuntimeException("Can't obtain Envelope of Layer-Groups: "
                    + e.getMessage(), e);
            } catch (TransformException e) {
                throw new RuntimeException("Can't obtain Envelope of Layer-Groups: "
                    + e.getMessage(), e);
            }

            end("Layer");
        }

        /**
        * Called from <code>handleLayers()</code>, does the first
        * iteration over the available featuretypes to look for common SRS's
        * and summarize their LatLonBBox'es, to state at the root layer.<p>NOTE:
        * by now we just have "layer.getSRS()", so the search is done against
        * this only SRS.</p>
        *
        * @param ftypes DOCUMENT ME!
        * @param TYPE DOCUMENT ME!
        *
        * @throws RuntimeException DOCUMENT ME!
        *
        * @task TODO: figure out how to incorporate multiple SRS using the
        *       reprojection facilities from gt2
        */
        private void handleRootSRSAndBbox(Collection ftypes, int TYPE) {
            String commonSRS = "";
            boolean isCommonSRS = true;
            Envelope latlonBbox = new Envelope();
            Envelope layerBbox = null;

            if (LOGGER.isLoggable(Level.FINER)) {
                LOGGER.finer("Collecting summarized latlonbbox and common SRS...");
            }

            if (TYPE == MapLayerInfo.TYPE_VECTOR) {
                FeatureTypeInfo layer;

                for (Iterator it = ftypes.iterator(); it.hasNext();) {
                    layer = (FeatureTypeInfo) it.next();

                    if (layer.isEnabled()) {
                        try {
                            layerBbox = layer.getLatLongBoundingBox();
                        } catch (IOException e) {
                            throw new RuntimeException("Can't obtain latLonBBox of "
                                + layer.getName() + ": " + e.getMessage(), e);
                        }

                        latlonBbox.expandToInclude(layerBbox);

                        String layerSRS = layer.getSRS();

                        if ("".equals(commonSRS)) {
                            commonSRS = layerSRS;
                        } else if (!commonSRS.equals(layerSRS)) {
                            isCommonSRS = false;
                        }
                    }
                }

                if (isCommonSRS) {
                    commonSRS = EPSG + commonSRS;
                    LOGGER.fine("Common SRS is " + commonSRS);
                } else {
                    commonSRS = "";
                    LOGGER.fine(
                        "No common SRS, don't forget to incorporate reprojection support...");
                }

                if (!(commonSRS.equals(""))) {
                    comment("common SRS:");
                    element("SRS", commonSRS);
                }

                // okay - we've sent out the commonSRS, if it exists.
                comment("All supported EPSG projections:");

                try {
                    Set s = CRS.getSupportedCodes("EPSG");
                    Iterator it = s.iterator();
                    String currentSRS;

                    while (it.hasNext()) {
                        // do not output srs if it was output as common srs
                        // note, if commonSRS is "", this will not match
                        currentSRS = it.next().toString();

                        if (!currentSRS.equals(commonSRS)) {
                            element("SRS", EPSG + currentSRS);
                        }
                    }
                } catch (Exception e) {
                    if (LOGGER.isLoggable(Level.WARNING)) {
                        LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e);
                    }
                }

                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER.fine("Summarized LatLonBBox is " + latlonBbox);
                }

                handleLatLonBBox(latlonBbox);
            } else if (TYPE == MapLayerInfo.TYPE_RASTER) {
                CoverageInfo layer;

                for (Iterator it = ftypes.iterator(); it.hasNext();) {
                    layer = (CoverageInfo) it.next();

                    if (layer.isEnabled()) {
                        final GeneralEnvelope bbox = layer.getWGS84LonLatEnvelope();
                        layerBbox = new Envelope(bbox.getLowerCorner().getOrdinate(0),
                                bbox.getUpperCorner().getOrdinate(0),
                                bbox.getLowerCorner().getOrdinate(1),
                                bbox.getUpperCorner().getOrdinate(1));

                        latlonBbox.expandToInclude(layerBbox);

                        String layerSRS = layer.getSrsName();

                        if ("".equals(commonSRS)) {
                            commonSRS = layerSRS;
                        } else if (!commonSRS.equals(layerSRS)) {
                            isCommonSRS = false;
                        }
                    }
                }

                if (isCommonSRS) {
                    // commonSRS = EPSG + commonSRS;
                    if (LOGGER.isLoggable(Level.FINE)) {
                        LOGGER.fine(new StringBuffer("Common SRS is ").append(commonSRS).toString());
                    }
                } else {
                    commonSRS = "";

                    if (LOGGER.isLoggable(Level.FINE)) {
                        LOGGER.fine(
                            "No common SRS, don't forget to incorporate reprojection support...");
                    }
                }

                if (!(commonSRS.equals(""))) {
                    comment("common SRS:");
                    element("SRS", commonSRS);
                }

                // okay - we've sent out the commonSRS, if it exists.
                comment("All supported EPSG projections:");

                try {
                    String currentSRS;
                    ArrayList SRSs = new ArrayList(ftypes.size());

                    for (Iterator it = ftypes.iterator(); it.hasNext();) {
                        layer = (CoverageInfo) it.next();

                        if (layer.isEnabled()) {
                            List s = layer.getRequestCRSs();
                            Iterator it_1 = s.iterator();

                            while (it_1.hasNext()) {
                                // do not output srs if it was output as common
                                // srs
                                // note, if commonSRS is "", this will not match
                                currentSRS = it_1.next().toString();

                                if (!currentSRS.equals(commonSRS) && !SRSs.contains(currentSRS)) {
                                    SRSs.add(currentSRS);
                                    element("SRS", currentSRS);
                                }
                            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -