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

📄 xmlconfigwriter.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * storeService purpose.
     *
     * <p>
     * Writes a service into the WriterUtils provided from the WFS or WMS
     * object provided.
     * </p>
     *
     * @param obj either a WFS or WMS object.
     * @param cw The Configuration Writer
     *
     * @throws ConfigurationException When an IO exception occurs or the object
     *         provided is not of the correct type.
     */
    protected static void storeService(Object obj, WriterHelper cw)
        throws ConfigurationException {
        if (LOGGER.isLoggable(Level.FINER)) {
            LOGGER.finer("In method storeService");
        }

        ServiceDTO s = null;
        String u = null;
        String t = "";

        boolean fBounds = false;
        boolean srsXmlStyle = false;
        int serviceLevel = 0;
        String svgRenderer = null;
        Map baseMapLayers = null;
        Map baseMapStyles = null;
        Map baseMapEnvelopes = null;
        boolean svgAntiAlias = false;
        String allowInterpolation = null;
        boolean citeConformanceHacks = false;

        if (obj instanceof WCSDTO) {
            WCSDTO w = (WCSDTO) obj;
            s = w.getService();
            t = "WCS";

            //citeConformanceHacks = w.getCiteConformanceHacks();
        } else if (obj instanceof WFSDTO) {
            WFSDTO w = (WFSDTO) obj;
            s = w.getService();
            t = "WFS";

            fBounds = w.isFeatureBounding();
            srsXmlStyle = w.isSrsXmlStyle();
            serviceLevel = w.getServiceLevel();
            citeConformanceHacks = w.getCiteConformanceHacks();
        } else if (obj instanceof WMSDTO) {
            WMSDTO w = (WMSDTO) obj;
            s = w.getService();
            t = "WMS";
            svgRenderer = w.getSvgRenderer();
            svgAntiAlias = w.getSvgAntiAlias();
            allowInterpolation = w.getAllowInterpolation();
            baseMapLayers = w.getBaseMapLayers();
            baseMapStyles = w.getBaseMapStyles();
            baseMapEnvelopes = w.getBaseMapEnvelopes();
        } else {
            throw new ConfigurationException("Invalid object: not WMS or WFS or WCS");
        }

        Map atrs = new HashMap();
        atrs.put("type", t);
        atrs.put("enabled", s.isEnabled() + "");
        cw.openTag("service", atrs);
        cw.comment("ServiceDTO elements, needed for the capabilities document\n"
            + "Title and OnlineResource are the two required");

        if ((s.getName() != null) && (s.getName() != "")) {
            cw.textTag("name", s.getName());
        }

        if ((s.getTitle() != null) && (s.getTitle() != "")) {
            cw.textTag("title", s.getTitle());
        }

        if ((s.getAbstract() != null) && (s.getAbstract() != "")) {
            cw.textTag("abstract", s.getAbstract());
        }

        if (s.getMetadataLink() != null) {
            MetaDataLink ml = s.getMetadataLink();
            Map mlAttr = new HashMap();
            mlAttr.put("about", ml.getAbout());
            mlAttr.put("type", ml.getType());
            mlAttr.put("metadataType", ml.getMetadataType());
            cw.textTag("metadataLink", mlAttr, ml.getContent());
        }

        if (!s.getKeywords().isEmpty()) {
            cw.openTag("keywords");

            for (int i = 0; i < s.getKeywords().size(); i++) {
                cw.textTag("keyword", s.getKeywords().get(i).toString());
            }

            cw.closeTag("keywords");
        }

        if (s.getOnlineResource() != null) {
            cw.textTag("onlineResource", s.getOnlineResource().toString());
        }

        if ((s.getFees() != null) && (s.getFees() != "")) {
            cw.textTag("fees", s.getFees());
        }

        if ((s.getAccessConstraints() != null) && (s.getAccessConstraints() != "")) {
            cw.textTag("accessConstraints", s.getAccessConstraints());
        }

        if (fBounds) {
            cw.valueTag("featureBounding", fBounds + "");
        }

        //if (srsXmlStyle) {
        cw.valueTag("srsXmlStyle", srsXmlStyle + "");

        //}
        if (serviceLevel != 0) {
            cw.valueTag("serviceLevel", serviceLevel + "");
        }

        if (obj instanceof WFSDTO) //DJB: this method (storeService) doesnt separate WFS and WMS very well!
         {
            cw.textTag("citeConformanceHacks", citeConformanceHacks + "");
        }

        if ((s.getMaintainer() != null) && (s.getMaintainer() != "")) {
            cw.textTag("maintainer", s.getMaintainer());
        }

        if (svgRenderer != null) {
            cw.textTag("svgRenderer", svgRenderer);
        }

        if ((baseMapLayers != null) && (baseMapStyles != null) && (baseMapEnvelopes != null)) {
            cw.openTag("BaseMapGroups");

            // for each title/layer combo, write it out
            String[] titles = (String[]) baseMapLayers.keySet().toArray(new String[0]);

            for (int i = 0; i < titles.length; i++) {
                HashMap titleMap = new HashMap();
                titleMap.put("baseMapTitle", titles[i]);
                cw.openTag("BaseMapGroup", titleMap);
                cw.textTag("baseMapLayers", (String) baseMapLayers.get(titles[i]));
                cw.textTag("baseMapStyles", (String) baseMapStyles.get(titles[i]));

                GeneralEnvelope e = (GeneralEnvelope) baseMapEnvelopes.get(titles[i]);
                Map m = new HashMap();

                m.put("srsName",
                    e.getCoordinateReferenceSystem().getIdentifiers().toArray()[0].toString());

                if (!e.isNull()) {
                    cw.openTag("baseMapEnvelope", m);
                    cw.textTag("pos",
                        e.getLowerCorner().getOrdinate(0) + " " + e.getLowerCorner().getOrdinate(1));
                    cw.textTag("pos",
                        e.getUpperCorner().getOrdinate(0) + " " + e.getUpperCorner().getOrdinate(1));
                    cw.closeTag("baseMapEnvelope");
                }

                cw.closeTag("BaseMapGroup");
            }

            cw.closeTag("BaseMapGroups");
        }

        if (obj instanceof WMSDTO) {
            cw.textTag("svgAntiAlias", svgAntiAlias + "");

            if (allowInterpolation != null) {
                cw.textTag("allowInterpolation", allowInterpolation);
            }
        }

        if ((s.getStrategy() != null) && !"".equals(s.getStrategy())) {
            cw.textTag("serviceStrategy", s.getStrategy());
        }

        if (s.getPartialBufferSize() != 0) {
            cw.textTag("partialBufferSize", s.getPartialBufferSize() + "");
        }

        cw.closeTag("service");
    }

    /**
     * storeCatalog purpose.
     *
     * <p>
     * Writes a catalog into the WriterUtils provided from Data provided in
     * memory.
     * </p>
     *
     * @param cw The Configuration Writer
     * @param data DOCUMENT ME!
     *
     * @throws ConfigurationException When an IO exception occurs.
     */
    protected static void storeCatalog(WriterHelper cw, DataDTO data)
        throws ConfigurationException {
        if (LOGGER.isLoggable(Level.FINER)) {
            LOGGER.finer("In method storeCatalog");
        }

        cw.writeln("<?config.xml version=\"1.0\" encoding=\"UTF-8\"?>");
        cw.openTag("catalog");

        //DJB: this used to not put in a datastores tag if there were none defined.
        //     this caused the loader to blow up.  I changed it so it puts an empty <datastore> here!
        cw.openTag("datastores");
        cw.comment("a datastore configuration element serves as a common data source connection\n"
            + "parameters repository for all featuretypes it holds.");

        Iterator i = data.getDataStores().keySet().iterator();

        while (i.hasNext()) {
            String s = (String) i.next();
            DataStoreInfoDTO ds = (DataStoreInfoDTO) data.getDataStores().get(s);

            if (ds != null) {
                storeDataStore(cw, ds);
            }
        }

        cw.closeTag("datastores");

        //DJB: since datastore screws up if the tag is missing, I'm fixing it here too
        cw.openTag("formats");
        cw.comment("a format configuration element serves as a common data source\n"
            + "parameters repository for all coverages it holds.");

        i = data.getFormats().keySet().iterator();

        while (i.hasNext()) {
            String s = (String) i.next();
            CoverageStoreInfoDTO df = (CoverageStoreInfoDTO) data.getFormats().get(s);

            if (df != null) {
                storeFormat(cw, df);
            }
        }

        cw.closeTag("formats");
        cw.comment("Defines namespaces to be used by the datastores.");
        cw.openTag("namespaces");

        i = data.getNameSpaces().keySet().iterator();

        while (i.hasNext()) {
            String s = (String) i.next();
            NameSpaceInfoDTO ns = (NameSpaceInfoDTO) data.getNameSpaces().get(s);

            if (ns != null) {
                storeNameSpace(cw, ns);
            }
        }

        cw.closeTag("namespaces");

        //DJB: since datastore screws up if the tag is missing, I'm fixing it here too
        cw.openTag("styles");
        cw.comment("Defines the style ids and file name to be used by the wms.");

        i = data.getStyles().keySet().iterator();

        while (i.hasNext()) {
            String s = (String) i.next();
            StyleDTO st = (StyleDTO) data.getStyles().get(s);

            if (st != null) {
                storeStyle(cw, st);
            }
        }

        cw.closeTag("styles");

        cw.closeTag("catalog");
    }

    /**
     * storeDataStore purpose.
     *
     * <p>
     * Writes a DataStoreInfo into the WriterUtils provided.
     * </p>
     *
     * @param cw The Configuration Writer
     * @param ds The Datastore.
     *
     * @throws ConfigurationException When an IO exception occurs.
     */
    protected static void storeDataStore(WriterHelper cw, DataStoreInfoDTO ds)
        throws ConfigurationException {
        if (LOGGER.isLoggable(Level.FINER)) {
            LOGGER.finer("In method storeDataStore");
        }

        Map temp = new HashMap();

        if (ds.getId() != null) {
            temp.put("id", ds.getId());
        }

        temp.put("enabled", ds.isEnabled() + "");

        if (ds.getNameSpaceId() != null) {
            temp.put("namespace", ds.getNameSpaceId());
        }

        cw.openTag("datastore", temp);

        if ((ds.getAbstract() != null) && (ds.getAbstract() != "")) {
            cw.textTag("abstract", ds.getAbstract());
        }

        if ((ds.getTitle() != null) && (ds.getTitle() != "")) {
            cw.textTag("title", ds.getTitle());
        }

        if (ds.getConnectionParams().size() != 0) {
            cw.openTag("connectionParams");

            Iterator i = ds.getConnectionParams().keySet().iterator();
            temp = new HashMap();

            while (i.hasNext()) {
                String key = (String) i.next();
                temp.put("name", key);
                temp.put("value", ds.getConnectionParams().get(key).toString());
                cw.attrTag("parameter", temp);
            }

            cw.closeTag("connectionParams");
        }

        cw.closeTag("datastore");
    }

    /**
         * storeFormat purpose.
         *
         * <p>

⌨️ 快捷键说明

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