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

📄 capabilitiestransformer.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
             * </p>
             * @param ftype The FeatureType configuration to report capabilities
             *        on.
             *
             * @throws RuntimeException For any errors.
             */
            private void handleFeatureType(FeatureTypeInfo info) {
                Envelope bbox = null;

                try {
                    bbox = info.getLatLongBoundingBox();
                } catch (IOException e) {
                    String msg = "Could not calculate bbox for: " + info.getName();
                    LOGGER.log(Level.SEVERE, msg, e);

                    return;
                }

                start("FeatureType");
                element("Name", info.getName());
                element("Title", info.getTitle());
                element("Abstract", info.getAbstract());
                handleKeywords(info.getKeywords());

                /**
                 * @task REVISIT: should getSRS() return the full URL?
                 */
                element("SRS", "EPSG:" + info.getSRS());

                String minx = String.valueOf(bbox.getMinX());
                String miny = String.valueOf(bbox.getMinY());
                String maxx = String.valueOf(bbox.getMaxX());
                String maxy = String.valueOf(bbox.getMaxY());

                AttributesImpl bboxAtts = new AttributesImpl();
                bboxAtts.addAttribute("", "minx", "minx", "", minx);
                bboxAtts.addAttribute("", "miny", "miny", "", miny);
                bboxAtts.addAttribute("", "maxx", "maxx", "", maxx);
                bboxAtts.addAttribute("", "maxy", "maxy", "", maxy);

                element("LatLongBoundingBox", null, bboxAtts);

                end("FeatureType");
            }

            /**
             * Encodes the ogc:Filter_Capabilities element.
             * <p>
             * <pre>
             * &lt;xsd:element name="Filter_Capabilities"&gt;
             *        &lt;xsd:complexType&gt;
             *          &lt;xsd:sequence&gt;
             *                &lt;xsd:element name="Spatial_Capabilities" type="ogc:Spatial_CapabilitiesType"/&gt;
             *                &lt;xsd:element name="Scalar_Capabilities" type="ogc:Scalar_CapabilitiesType"/&gt;
             *          &lt;/xsd:sequence&gt;
             *        &lt;/xsd:complexType&gt;
             *&lt;/xsd:element&gt;
             * </pre>
             * </p>
             */
            private void handleFilterCapabilities() {
                String ogc = "ogc:";

                //REVISIT: for now I"m just prepending ogc onto the name element.
                //Is the proper way to only do that for the qname?  I guess it
                //would only really matter if we're going to be producing capabilities
                //documents that aren't qualified, and I don't see any reason to
                //do that.
                start(ogc + "Filter_Capabilities");
                start(ogc + "Spatial_Capabilities");
                start(ogc + "Spatial_Operators");
                element(ogc + "Disjoint", null);
                element(ogc + "Equals", null);
                element(ogc + "DWithin", null);
                element(ogc + "Beyond", null);
                element(ogc + "Intersect", null);
                element(ogc + "Touches", null);
                element(ogc + "Crosses", null);
                element(ogc + "Within", null);
                element(ogc + "Contains", null);
                element(ogc + "Overlaps", null);
                element(ogc + "BBOX", null);
                end(ogc + "Spatial_Operators");
                end(ogc + "Spatial_Capabilities");

                start(ogc + "Scalar_Capabilities");
                element(ogc + "Logical_Operators", null);
                start(ogc + "Comparison_Operators");
                element(ogc + "Simple_Comparisons", null);
                element(ogc + "Between", null);
                element(ogc + "Like", null);
                element(ogc + "NullCheck", null);
                end(ogc + "Comparison_Operators");
                start(ogc + "Arithmetic_Operators");
                element(ogc + "Simple_Arithmetic", null);

                handleFunctions(ogc); //djb: list functions

                end(ogc + "Arithmetic_Operators");
                end(ogc + "Scalar_Capabilities");
                end(ogc + "Filter_Capabilities");
            }

            /**
             * &lt;xsd:complexType name="FunctionsType"&gt;
             *         &lt;xsd:sequence&gt;
             *                 &lt;xsd:element name="Function_Names" type="ogc:Function_NamesType"/&gt;
             *         &lt;/xsd:sequence&gt;
             *         &lt;/xsd:complexType&gt;
             *
             */
            private void handleFunctions(String prefix) {
                start(prefix + "Functions");
                start(prefix + "Function_Names");

                Iterator it = FactoryRegistry.lookupProviders(Function.class);

                //Sort them up for easier visual inspection
                SortedSet sortedFunctions = new TreeSet(new Comparator() {
                            public int compare(Object o1, Object o2) {
                                String n1 = ((Function) o1)
                                    .getName();
                                String n2 = ((Function) o2).getName();

                                return n1.toLowerCase().compareTo(n2.toLowerCase());
                            }
                        });

                while (it.hasNext()) {
                    sortedFunctions.add(it.next());
                }

                //write them now that functions are sorted by name
                it = sortedFunctions.iterator();

                while (it.hasNext()) {
                    Function fe = (Function) it.next();

                    //TODO: as of now the geoapi Function interface 
                    // does not allow use to report back properly the number of 
                    // parameters, so we check for instances of FunctionExpression 
                    // for now
                    if (fe instanceof FunctionExpression) {
                        String funName = fe.getName();
                        int funNArgs = ((FunctionExpression) fe).getArgCount();

                        AttributesImpl atts = new AttributesImpl();
                        atts.addAttribute("", "nArgs", "nArgs", "", funNArgs + "");

                        element(prefix + "Function_Name", funName, atts);
                    }
                }

                end(prefix + "Function_Names");
                end(prefix + "Functions");
            }
        }
    }

    /**
     * Transformer for wfs 1.1 capabilities document.
     *
     * @author Justin Deoliveira, The Open Planning Project
     *
     */
    public static class WFS1_1 extends CapabilitiesTransformer {
        public WFS1_1(WFS wfs, Data catalog) {
            super(wfs, catalog);
        }

        public Translator createTranslator(ContentHandler handler) {
            return new CapabilitiesTranslator1_1(handler);
        }

        class CapabilitiesTranslator1_1 extends TranslatorSupport {
            GetCapabilitiesType request;
            
            public CapabilitiesTranslator1_1(ContentHandler handler) {
                super(handler, null, null);
            }

            public void encode(Object object) throws IllegalArgumentException {
                request = (GetCapabilitiesType)object;
                String proxifiedBaseUrl = RequestUtils.proxifiedBaseURL(request.getBaseUrl(), wfs.getGeoServer().getProxyBaseUrl());
                
                AttributesImpl attributes = attributes(new String[] {
                            "version", "1.1.0", "xmlns:xsi", XSI_URI, "xmlns", WFS_URI, "xmlns:wfs",
                            WFS_URI, "xmlns:ows", OWS.NAMESPACE, "xmlns:gml", GML.NAMESPACE,
                            "xmlns:ogc", OGC.NAMESPACE, "xmlns:xlink", XLINK.NAMESPACE,
                            "xsi:schemaLocation",
                            
                        org.geoserver.wfs.xml.v1_1_0.WFS.NAMESPACE + " "
                            + ResponseUtils.appendPath(proxifiedBaseUrl, "schemas/wfs/1.1.0/wfs.xsd")
                        });

                NameSpaceInfo[] namespaces = catalog.getNameSpaces();

                for (int i = 0; i < namespaces.length; i++) {
                    NameSpaceInfo namespace = namespaces[i];

                    String prefix = namespace.getPrefix();
                    String uri = namespace.getURI();

                    //ignore xml prefix
                    if ("xml".equals(prefix)) {
                        continue;
                    }

                    String prefixDef = "xmlns:" + prefix;

                    attributes.addAttribute("", prefixDef, prefixDef, "", uri);
                }

                start("wfs:WFS_Capabilities", attributes);

                serviceIdentification();
                serviceProvider();
                operationsMetadata();
                featureTypeList();
                //supportsGMLObjectTypeList();
                filterCapabilities();

                end("wfs:WFS_Capabilities");
            }

            /**
             * Encodes the ows:ServiceIdentification element.
             * <p>
             * <pre>
             * &lt;complexType&gt;
             *         &lt;complexContent&gt;
             *           &lt;extension base="ows:DescriptionType"&gt;
             *       &lt;sequence&gt;
             *         &lt;element name="ServiceType" type="ows:CodeType"&gt;
             *         &lt;annotation&gt;
             *             &lt;documentation&gt;A service type name from a registry of services.
             *             For example, the values of the codeSpace URI and name and code string may
             *             be "OGC" and "catalogue." This type name is normally used for
             *             machine-to-machine communication.&lt;/documentation&gt;
             *         &lt;/annotation&gt;
             *         &lt;/element&gt;
             *         &lt;element name="ServiceTypeVersion" type="ows:VersionType" maxOccurs="unbounded"&gt;
             *         &lt;annotation&gt;
             *             &lt;documentation&gt;Unordered list of one or more versions of this service
             *             type implemented by this server. This information is not adequate for
             *             version negotiation, and shall not be used for that purpose. &lt;/documentation&gt;
             *         &lt;/annotation&gt;
             *         &lt;/element&gt;
             *         &lt;element ref="ows:Fees" minOccurs="0"&gt;
             *         &lt;annotation&gt;
             *               &lt;documentation&gt;If this element is omitted, no meaning is implied. &lt;/documentation&gt;
             *         &lt;/annotation&gt;
             *         &lt;/element&gt;
             *         &lt;element ref="ows:AccessConstraints" minOccurs="0" maxOccurs="unbounded"&gt;
             *         &lt;annotation&gt;
             *               &lt;documentation&gt;Unordered list of access constraints applied to assure
             *               the protection of privacy or intellectual property, and any other
             *               restrictions on retrieving or using data from or otherwise using this
             *               server. The reserved value NONE (case insensitive) shall be used to
             *               mean no access constraints are imposed. If this element is omitted,
             *               no meaning is implied. &lt;/documentation&gt;
             *               &lt;/annotation&gt;
             *               &lt;/element&gt;
             *             &lt;/sequence&gt;
             *     &lt;/extension&gt;
             *   &lt;/complexContent&gt;
             *&lt;/complexType&gt;
             * </pre>
             * </p>
             *
             */
            void serviceIdentification() {
                start("ows:ServiceIdentification");

                element("ows:Title", wfs.getTitle());
                element("ows:Abstract", wfs.getAbstract());

                keywords(wfs.getKeywords());

                element("ows:ServiceType", "WFS");
                element("ows:ServiceTypeVersion", "1.1.0");

                element("ows:Fees", wfs.getFees());
                element("ows:AccessConstraints", wfs.getAccessConstraints());

⌨️ 快捷键说明

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