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

📄 xmlconfigreader.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                        .toString());
            }

            Reader fr = XmlCharsetDetector.getCharsetAwareReader(new FileInputStream(catalogFile));
            catalogElem = ReaderUtils.parse(fr);
            fr.close();
        } catch (FileNotFoundException e) {
            throw new ConfigurationException(e);
        } catch (IOException e) {
            throw new ConfigurationException(e);
        }

        try {
            data.setNameSpaces(loadNameSpaces(ReaderUtils.getChildElement(catalogElem,
                    "namespaces", true)));
            setDefaultNS();

            try { // try <formats> to be backwards compatible to 1.4

                Element formatElement = ReaderUtils.getChildElement(catalogElem, "formats", true);
                data.setFormats(loadFormats(formatElement));
            } catch (Exception e) {
                // gobble
                LOGGER
                        .warning("Your catalog.xml file is not up to date and is probably from an older "
                                + "version of GeoServer. This problem is now being fixed automatically.");
            }

            data.setDataStores(loadDataStores(ReaderUtils.getChildElement(catalogElem,
                    "datastores", true)));

            data.setStyles(loadStyles(ReaderUtils.getChildElement(catalogElem, "styles", false),
                    styleDir));
            // must be last
            data.setFeaturesTypes(loadFeatureTypes(featureTypeDir));
            data.setCoverages(loadCoverages(coverageDir));
        } catch (Exception e) {
            throw new ConfigurationException(e);
        }
    }

    /**
     * setDefaultNS purpose.
     * 
     * <p>
     * Finds and sets the default namespace. The namespaces in catalog must
     * already be loaded.
     * </p>
     */
    protected void setDefaultNS() {
        Iterator i = data.getNameSpaces().values().iterator();

        while (i.hasNext()) {
            NameSpaceInfoDTO ns = (NameSpaceInfoDTO) i.next();

            if (ns.isDefault()) {
                data.setDefaultNameSpacePrefix(ns.getPrefix());

                if (LOGGER.isLoggable(Level.FINER)) {
                    LOGGER.finer(new StringBuffer("set default namespace pre to ").append(
                            ns.getPrefix()).toString());
                }

                return;
            }
        }
    }

    /**
     * getLoggingLevel purpose.
     * 
     * <p>
     * Parses the LoggingLevel from a DOM tree and converts the level into a
     * Level Object.
     * </p>
     * 
     * @param globalConfigElem
     * 
     * @return The logging Level
     * 
     * @throws ConfigurationException
     *             When an error occurs.
     */
    protected Level getLoggingLevel(Element globalConfigElem) throws ConfigurationException {
        Level level = Logger.getLogger("org.vfny.geoserver").getLevel();
        Element levelElem = ReaderUtils.getChildElement(globalConfigElem, "loggingLevel");

        if (levelElem != null) {
            String levelName = levelElem.getFirstChild().getNodeValue();

            try {
                level = Level.parse(levelName);
            } catch (IllegalArgumentException ex) {
                if (LOGGER.isLoggable(Level.WARNING)) {
                    LOGGER.warning(new StringBuffer("illegal loggingLevel name: ")
                            .append(levelName).toString());
                }
            }
        } else {
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.config("No loggingLevel found, using default logging.properties setting");
            }
        }

        return level;
    }

    /**
     * loadGlobal purpose.
     * 
     * <p>
     * Converts a DOM tree into a GlobalData configuration.
     * </p>
     * 
     * @param globalElem
     *            A DOM tree representing a complete global configuration.
     * 
     * @throws ConfigurationException
     *             When an error occurs.
     */
    protected void loadGlobal(Element globalElem) throws ConfigurationException {
        try {
            geoServer = new GeoServerDTO();

            if (LOGGER.isLoggable(Level.FINER)) {
                LOGGER.finer("parsing global configuration parameters");
            }

            String log4jConfigFile = ReaderUtils.getChildText(globalElem, "log4jConfigFile", false);
            geoServer.setLog4jConfigFile(log4jConfigFile);

            boolean suppressStdOutLogging = false;
            Element elem = null;
            elem = ReaderUtils.getChildElement(globalElem, "suppressStdOutLogging", false);

            if (elem != null) {
                suppressStdOutLogging = ReaderUtils
                        .getBooleanAttribute(elem, "value", false, false);
            }

            String logLocation = ReaderUtils.getChildText(globalElem, "logLocation");

            if ((logLocation != null) && "".equals(logLocation.trim())) {
                logLocation = null;
            }

            geoServer.setSuppressStdOutLogging(suppressStdOutLogging);
            geoServer.setLogLocation(logLocation);

            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine(new StringBuffer("logging config is ").append(log4jConfigFile)
                        .toString());
            }

            if (logLocation != null) {
                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER.fine(new StringBuffer("logging to ").append(logLocation).toString());
                }
            }

            double jaiMemoryCapacity = 0;
            elem = ReaderUtils.getChildElement(globalElem, "JaiMemoryCapacity", false);

            if (elem != null) {
                jaiMemoryCapacity = ReaderUtils.getDoubleAttribute(elem, "value", false);
            }

            double jaiMemoryThreshold = 0.0;
            elem = ReaderUtils.getChildElement(globalElem, "JaiMemoryThreshold", false);

            if (elem != null) {
                jaiMemoryThreshold = ReaderUtils.getDoubleAttribute(elem, "value", false);
            }

            int jaiTileThreads = 7;
            elem = ReaderUtils.getChildElement(globalElem, "JaiTileThreads", false);

            if (elem != null) {
                jaiTileThreads = ReaderUtils.getIntAttribute(elem, "value", false, 7);
            }

            int jaiTilePriority = 5;
            elem = ReaderUtils.getChildElement(globalElem, "JaiTilePriority", false);

            if (elem != null) {
                jaiTilePriority = ReaderUtils.getIntAttribute(elem, "value", false, 5);
            }

            Boolean jaiRecycling = Boolean.FALSE;
            elem = ReaderUtils.getChildElement(globalElem, "JaiRecycling", false);

            if (elem != null) {
                jaiRecycling = Boolean.valueOf(ReaderUtils.getBooleanAttribute(elem, "value",
                        false, false));
            }

            Boolean imageIOCache = Boolean.FALSE;
            elem = ReaderUtils.getChildElement(globalElem, "ImageIOCache", false);

            if (elem != null) {
                imageIOCache = Boolean.valueOf(ReaderUtils.getBooleanAttribute(elem, "value",
                        false, false));
            }

            Boolean jaiJPEGNative = Boolean.TRUE;
            elem = ReaderUtils.getChildElement(globalElem, "JaiJPEGNative", false);

            if (elem != null) {
                jaiJPEGNative = Boolean.valueOf(ReaderUtils.getBooleanAttribute(elem, "value",
                        false, false));
            }

            Boolean jaiPNGNative = Boolean.TRUE;
            elem = ReaderUtils.getChildElement(globalElem, "JaiPNGNative", false);

            if (elem != null) {
                jaiPNGNative = Boolean.valueOf(ReaderUtils.getBooleanAttribute(elem, "value",
                        false, false));
            }

            geoServer.setJaiMemoryCapacity(jaiMemoryCapacity);
            geoServer.setJaiMemoryThreshold(jaiMemoryThreshold);
            geoServer.setJaiTileThreads(jaiTileThreads);
            geoServer.setJaiTilePriority(jaiTilePriority);
            geoServer.setJaiRecycling(jaiRecycling);
            geoServer.setImageIOCache(imageIOCache);
            geoServer.setJaiJPEGNative(jaiJPEGNative);
            geoServer.setJaiPNGNative(jaiPNGNative);

            elem = ReaderUtils.getChildElement(globalElem, "ContactInformation");
            geoServer.setContact(loadContact(elem));

            elem = ReaderUtils.getChildElement(globalElem, "verbose", false);

            if (elem != null) {
                geoServer.setVerbose(ReaderUtils.getBooleanAttribute(elem, "value", false, true));
            }

            elem = ReaderUtils.getChildElement(globalElem, "maxFeatures");

            if (elem != null) {
                // if the element is pressent, it's "value" attribute is
                // mandatory
                geoServer.setMaxFeatures(ReaderUtils.getIntAttribute(elem, "value", true, geoServer
                        .getMaxFeatures()));
            }

            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine(new StringBuffer("maxFeatures is ").append(geoServer.getMaxFeatures())
                        .toString());
            }

            elem = ReaderUtils.getChildElement(globalElem, "numDecimals");

            if (elem != null) {
                geoServer.setNumDecimals(ReaderUtils.getIntAttribute(elem, "value", true, geoServer
                        .getNumDecimals()));
            }

            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine(new StringBuffer("numDecimals returning is ").append(
                        geoServer.getNumDecimals()).toString());
            }

            elem = ReaderUtils.getChildElement(globalElem, "charSet");

            if (elem != null) {
                String chSet = ReaderUtils.getAttribute(elem, "value", true);

                try {
                    Charset cs = Charset.forName(chSet);
                    geoServer.setCharSet(cs);

                    if (LOGGER.isLoggable(Level.FINER)) {
                        LOGGER.finer(new StringBuffer("charSet: ").append(cs.displayName())
                                .toString());
                    }
                } catch (Exception ex) {
                    if (LOGGER.isLoggable(Level.INFO)) {
                        LOGGER.info(ex.getMessage());
                    }
                }
            }

            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine(new StringBuffer("charSet is ").append(geoServer.getCharSet())
                        .toString());
            }

            // Schema base doesn't work - this root thing is wrong. So for 1.2.0
            // I'm
            // just going to leave it out. The GeoServer.getSchemaBaseUrl is
            // never
            // called, Request.getSchemaBaseUrl is used, and it always returns
            // the
            // relative local one. This field was a hack anyways, so I don't
            // think
            // anyone is going to miss it much - though I could be proved wrong.
            // ch
            String schemaBaseUrl = ReaderUtils.getChildText(globalElem, "SchemaBaseUrl");

            if (schemaBaseUrl != null) {
                geoServer.setSchemaBaseUrl(schemaBaseUrl);
            } else {
                // This is wrong - need some key to tell the method to return
                // based
                // on the url passed in.
                geoServer.setSchemaBaseUrl(root.toString() + "/data/capabilities/");
            }

            String proxyBaseUrl = ReaderUtils.getChildText(globalElem, "ProxyBaseUrl");

            if (proxyBaseUrl != null) {
                geoServer.setProxyBaseUrl(proxyBaseUrl);
            } else {
                geoServer.setSchemaBaseUrl(null);
            }

            String adminUserName = ReaderUtils.getChildText(globalElem, "adminUserName");

            if (adminUserName != null) {
                geoServer.setAdminUserName(adminUserName);
            }

            String adminPassword = ReaderUtils.getChildText(globalElem, "adminPassword");

            if (adminPassword != null) {
                geoServer.setAdminPassword(adminPassword);
            }

            elem = ReaderUtils.getChildElement(globalElem, "verboseExceptions", false);

            if (elem != null) {
                geoServer.setVerboseExceptions(ReaderUtils.getBooleanAttribute(elem, "value",
                        false, true));
            }

            String tileCache = ReaderUtils.getChildText(globalElem, "tileCache", false);

            if (tileCache != null) {
                geoServer.setTileCache(tileCache);
            } else {
                geoServer.setTileCache(null);
            }
        } catch (Exception e) {
            throw new ConfigurationException(e);
        }
    }

    /**
     * loadContact purpose.
     * 
     * <p>
     * Converts a DOM tree into a ContactConfig

⌨️ 快捷键说明

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