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

📄 xmlconfigreader.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * </p>
     * 
     * @param contactInfoElement
     *            a DOM tree to convert into a ContactConfig.
     * 
     * @return The resulting ContactConfig object from the DOM tree.
     * 
     * @throws ConfigurationException
     *             When an error occurs.
     */
    protected ContactDTO loadContact(Element contactInfoElement) throws ConfigurationException {
        ContactDTO c = new ContactDTO();

        if (contactInfoElement == null) {
            return c;
        }

        Element elem;
        NodeList nodeList;
        elem = ReaderUtils.getChildElement(contactInfoElement, "ContactPersonPrimary");

        if (elem != null) {
            c.setContactPerson(ReaderUtils.getChildText(elem, "ContactPerson"));
            c.setContactOrganization(ReaderUtils.getChildText(elem, "ContactOrganization"));
        }

        c.setContactPosition(ReaderUtils.getChildText(contactInfoElement, "ContactPosition"));
        elem = ReaderUtils.getChildElement(contactInfoElement, "ContactAddress");

        if (elem != null) {
            c.setAddressType(ReaderUtils.getChildText(elem, "AddressType"));
            c.setAddress(ReaderUtils.getChildText(elem, "Address"));
            c.setAddressCity(ReaderUtils.getChildText(elem, "City"));
            c.setAddressState(ReaderUtils.getChildText(elem, "StateOrProvince"));
            c.setAddressPostalCode(ReaderUtils.getChildText(elem, "PostCode"));
            c.setAddressCountry(ReaderUtils.getChildText(elem, "Country"));
        }

        c.setContactVoice(ReaderUtils.getChildText(contactInfoElement, "ContactVoiceTelephone"));
        c.setContactFacsimile(ReaderUtils.getChildText(contactInfoElement,
                "ContactFacsimileTelephone"));
        c.setContactEmail(ReaderUtils.getChildText(contactInfoElement,
                "ContactElectronicMailAddress"));
        c.setOnlineResource(ReaderUtils.getChildText(contactInfoElement, "ContactOnlineResource"));

        return c;
    }

    /**
     * loadWCS purpose.
     * 
     * <p>
     * Converts a DOM tree into a WCS object.
     * </p>
     * 
     * @param wfsElement
     *            a DOM tree to convert into a WCS object.
     * 
     * @throws ConfigurationException
     *             When an error occurs.
     * 
     * @see GlobalData#getBaseUrl()
     */
    protected void loadWCS(Element wcsElement) throws ConfigurationException {
        wcs = new WCSDTO();
        wcs.setService(loadService(wcsElement));
    }

    /**
     * loadWFS purpose.
     * 
     * <p>
     * Converts a DOM tree into a WFS object.
     * </p>
     * 
     * @param wfsElement
     *            a DOM tree to convert into a WFS object.
     * 
     * @throws ConfigurationException
     *             When an error occurs.
     * 
     * @see GlobalData#getBaseUrl()
     */
    protected void loadWFS(Element wfsElement) throws ConfigurationException {
        wfs = new WFSDTO();

        try {
            wfs.setFeatureBounding(ReaderUtils.getBooleanAttribute(ReaderUtils.getChildElement(
                    wfsElement, "featureBounding"), "value", false, false));

            Element elem = ReaderUtils.getChildElement(wfsElement, "srsXmlStyle", false);

            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine(new StringBuffer("reading srsXmlStyle: ").append(elem).toString());
            }

            if (elem != null) {
                wfs.setSrsXmlStyle(ReaderUtils.getBooleanAttribute(elem, "value", false, true));

                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER
                            .fine(new StringBuffer("set srsXmlStyle to ").append(
                                    ReaderUtils.getBooleanAttribute(elem, "value", false, true))
                                    .toString());
                }
            }

            String serviceLevelValue = ReaderUtils.getChildText(wfsElement, "serviceLevel");
            int serviceLevel = WFSDTO.COMPLETE;

            if ((serviceLevelValue != null) && !serviceLevelValue.equals("")) {
                if (LOGGER.isLoggable(Level.FINER)) {
                    LOGGER.finer(new StringBuffer("reading serviceLevel: ").append(
                            serviceLevelValue).toString());
                }

                if (serviceLevelValue.equalsIgnoreCase("basic")) {
                    serviceLevel = WFSDTO.BASIC;
                } else if (serviceLevelValue.equalsIgnoreCase("complete")) {
                    serviceLevel = WFSDTO.COMPLETE;
                } else if (serviceLevelValue.equalsIgnoreCase("transactional")) {
                    serviceLevel = WFSDTO.TRANSACTIONAL;
                } else {
                    try {
                        serviceLevel = Integer.parseInt(serviceLevelValue);
                    } catch (NumberFormatException nfe) {
                        String mesg = "Could not parse serviceLevel.  It "
                                + "should be one of Basic, Complete, or Transactional"
                                + " or else an integer value";
                        throw new ConfigurationException(mesg, nfe);
                    }
                }
            } else { // TODO: this should probably parse the strings as well,
                serviceLevel = ReaderUtils.getIntAttribute(ReaderUtils.getChildElement(wfsElement,
                        "serviceLevel"), "value", false, WFSDTO.COMPLETE);
            }

            if (LOGGER.isLoggable(Level.FINER)) {
                LOGGER.finer(new StringBuffer("setting service level to ").append(serviceLevel)
                        .toString());
            }

            wfs.setServiceLevel(serviceLevel);

            // get the conformance hacks attribute
            // it might not be there, in which case we just use the default
            // value
            // (see WFSDTO.java)
            Element e = ReaderUtils.getChildElement(wfsElement, "citeConformanceHacks");

            if (e != null) {
                String text = ReaderUtils.getChildText(wfsElement, "citeConformanceHacks");
                boolean citeConformanceHacks = Boolean.valueOf(text).booleanValue(); // just
                                                                                        // get
                                                                                        // the
                                                                                        // value
                                                                                        // and
                                                                                        // parse
                                                                                        // it
                wfs.setCiteConformanceHacks(citeConformanceHacks);

                if (LOGGER.isLoggable(Level.FINER)) {
                    LOGGER.finer(new StringBuffer("setting citeConformanceHacks to ").append(
                            citeConformanceHacks).toString());
                }
            }
        } catch (Exception e) {
            throw new ConfigurationException(e);
        }

        ServiceDTO s = loadService(wfsElement);
        wfs.setService(s);
    }

    /**
     * loadWMS purpose.
     * 
     * <p>
     * Converts a DOM tree into a WMS object.
     * </p>
     * 
     * @param wmsElement
     *            a DOM tree to convert into a WMS object.
     * 
     * @throws ConfigurationException
     *             When an error occurs.
     * 
     * @see GlobalData#getBaseUrl()
     */
    protected void loadWMS(Element wmsElement) throws ConfigurationException {
        wms = new WMSDTO();
        wms.setService(loadService(wmsElement));

        wms.setSvgRenderer(ReaderUtils.getChildText(wmsElement, "svgRenderer"));
        wms.setSvgAntiAlias(!"false".equals(ReaderUtils.getChildText(wmsElement, "svgAntiAlias")));

        try {
            wms.setAllowInterpolation(ReaderUtils.getChildText(wmsElement, "allowInterpolation",
                    true));
        } catch (Exception e) {
            wms.setAllowInterpolation("Nearest");
        }

        loadBaseMapLayers(wmsElement);
    }

    private void loadBaseMapLayers(Element wmsElement) {
        HashMap layerMap = new HashMap();
        HashMap styleMap = new HashMap();
        HashMap envelopeMap = new HashMap();

        Element groupBase = ReaderUtils.getChildElement(wmsElement, "BaseMapGroups");

        if (groupBase == null) {
            LOGGER.config("No baseMap groups defined yet");

            return;
        }

        Element[] groups = ReaderUtils.getChildElements(groupBase, "BaseMapGroup");

        for (int i = 0; i < groups.length; i++) {
            Element group = groups[i];

            try {
                String title = ReaderUtils.getAttribute(group, "baseMapTitle", true);
                String layers = ReaderUtils.getChildText(group, "baseMapLayers");
                String styles = ReaderUtils.getChildText(group, "baseMapStyles");

                Element envelope = ReaderUtils.getChildElement(group, "baseMapEnvelope");
                String srsName = ReaderUtils.getAttribute(envelope, "srsName", true);
                layerMap.put(title, layers);
                styleMap.put(title, styles);
                envelopeMap.put(title, loadEnvelope(envelope, CRS.decode(srsName)));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }

        wms.setBaseMapLayers(layerMap);
        wms.setBaseMapStyles(styleMap);
        wms.setBaseMapEnvelopes(envelopeMap);
    }

    /**
     * loadService purpose.
     * 
     * <p>
     * Converts a DOM tree into a ServiceDTO object.
     * </p>
     * 
     * @param serviceRoot
     *            a DOM tree to convert into a ServiceDTO object.
     * 
     * @return A complete ServiceDTO object loaded from the DOM tree provided.
     * 
     * @throws ConfigurationException
     *             When an error occurs.
     */
    protected ServiceDTO loadService(Element serviceRoot) throws ConfigurationException {
        ServiceDTO s = new ServiceDTO();

        try {
            String name = ReaderUtils.getChildText(serviceRoot, "name", true);
            s.setName(name);
            s.setTitle(ReaderUtils.getChildText(serviceRoot, "title", false));
            s.setAbstract(ReaderUtils.getChildText(serviceRoot, "abstract"));
            s.setKeywords(ReaderUtils.getKeyWords(ReaderUtils.getChildElement(serviceRoot,
                    "keywords")));
            s.setMetadataLink(getMetaDataLink(ReaderUtils.getChildElement(serviceRoot,
                    "metadataLink")));
            s.setFees(ReaderUtils.getChildText(serviceRoot, "fees"));
            s.setAccessConstraints(ReaderUtils.getChildText(serviceRoot, "accessConstraints"));
            s.setMaintainer(ReaderUtils.getChildText(serviceRoot, "maintainer"));
            s.setEnabled(ReaderUtils.getBooleanAttribute(serviceRoot, "enabled", false, true));
            s.setStrategy(ReaderUtils.getChildText(serviceRoot, "serviceStrategy"));
            s.setPartialBufferSize(ReaderUtils.getIntAttribute(serviceRoot, "partialBufferSize",
                    false, 0));

            String url = ReaderUtils.getChildText(serviceRoot, "onlineResource", true);

            try {
                s.setOnlineResource(new URL(url));
            } catch (MalformedURLException e) {
                LOGGER.severe("Invalid online resource URL for service " + name + ": " + url
                        + ". Defaulting to geoserver home.");
                s.setOnlineResource(new URL("http://www.geoserver.org"));
            }
        } catch (Exception e) {
            throw new ConfigurationException(e);
        }

        return s;
    }

    /**
     * loadNameSpaces purpose.
     * 
     * <p>
     * Converts a DOM tree into a Map of NameSpaces.
     * </p>
     * 
     * @param nsRoot
     *            a DOM tree to convert into a Map of NameSpaces.
     * 
     * @return A complete Map of NameSpaces loaded from the DOM tree provided.
     * 
     * @throws ConfigurationException
     *             When an error occurs.
     */
    protected Map loadNameSpaces(Element nsRoot) throws ConfigurationException {
        NodeList nsList = nsRoot.getElementsByTagName("namespace");
        Element elem;
        int nsCount = nsList.getLength();
        Map nameSpaces = new HashMap(nsCount);

        try {
            for (int i = 0; i < nsCount; i++) {
                elem = (Element) nsList.item(i);

                NameSpaceInfoDTO ns = new NameSpaceInfoDTO();
                ns.setUri(ReaderUtils.getAttribute(elem, "uri", true));
                ns.setPrefix(ReaderUtils.getAttribute(elem, "prefix", true));
                ns.setDefault(ReaderUtils.getBooleanAttribute(elem, "default", false, false)
                        || (nsCount == 1));

                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER.config(new StringBuffer("added namespace ").append(ns).toString());
                }

                nameSpaces.put(ns.getPrefix(), ns);
            }
        } catch (Exception e) {
            throw new ConfigurationException(e);
        }

        return nameSpaces;
    }

    /**
     * loadStyles purpose.
     * 
     * <p>
     * Converts a DOM tree into a Map of Styles.
     * </p>
     * 
     * @param stylesElem
     *            a DOM tree to convert into a Map of Styles.
     * @param baseDir
     *            DOCUMENT ME!
     * 
     * @return A complete Map of Styles loaded from the DOM tree provided.
     * 
     * @throws ConfigurationException

⌨️ 快捷键说明

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