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

📄 xmlconfigreader.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     *             When an error occurs.
     */
    protected Map loadStyles(Element stylesElem, File baseDir) throws ConfigurationException {
        Map styles = new HashMap();

        NodeList stylesList = null;

        if (stylesElem != null) {
            stylesList = stylesElem.getElementsByTagName("style");
        }

        if ((stylesList == null) || (stylesList.getLength() == 0)) {
            // no styles where defined, just add a default one
            StyleDTO s = new StyleDTO();
            s.setId("normal");
            s.setFilename(new File(baseDir, "normal.sld"));
            s.setDefault(true);
            styles.put("normal", s);
        }

        int styleCount = stylesList.getLength();
        Element styleElem;

        for (int i = 0; i < styleCount; i++) {
            try {
                styleElem = (Element) stylesList.item(i);

                StyleDTO s = new StyleDTO();
                s.setId(ReaderUtils.getAttribute(styleElem, "id", true));
                s.setFilename(new File(baseDir, ReaderUtils.getAttribute(styleElem, "filename",
                        true)));
                s.setDefault(ReaderUtils.getBooleanAttribute(styleElem, "default", false, false));
                styles.put(s.getId(), s);

                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER.config(new StringBuffer("Loaded style ").append(s.getId()).toString());
                }
            } catch (Exception e) {
                LOGGER.log(Level.WARNING, "Ignored misconfigured style", e);
            }
        }

        return styles;
    }

    /**
     * loadFormats purpose.
     * 
     * <p>
     * Converts a DOM tree into a Map of Formats.
     * </p>
     * 
     * @param fmRoot
     *            a DOM tree to convert into a Map of Formats.
     * 
     * @return A complete Map of Formats loaded from the DOM tree provided.
     * 
     * @throws ConfigurationException
     *             When an error occurs.
     */
    protected Map loadFormats(Element fmRoot) throws ConfigurationException {
        Map formats = new HashMap();

        if (fmRoot == null) { // if there are no formats (they are using
            // v.1.4)

            return formats; // just return the empty list
        }

        NodeList fmElements = fmRoot.getElementsByTagName("format");
        int fmCnt = fmElements.getLength();
        CoverageStoreInfoDTO fmConfig;
        Element fmElem;

        for (int i = 0; i < fmCnt; i++) {
            fmElem = (Element) fmElements.item(i);

            try {
                fmConfig = loadFormat(fmElem);

                if (formats.containsKey(fmConfig.getId())) {
                    LOGGER.warning("Ignored duplicated format "
                            + data.getNameSpaces().get(fmConfig.getNameSpaceId()));
                } else {
                    formats.put(fmConfig.getId(), fmConfig);
                }
            } catch (ConfigurationException e) {
                LOGGER.log(Level.WARNING, "Ignored a misconfigured coverage.", e);
            }
        }

        return formats;
    }

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

        if (LOGGER.isLoggable(Level.FINER)) {
            LOGGER.finer("creating a new FormatDTO configuration");
        }

        try {
            fm.setId(ReaderUtils.getAttribute(fmElem, "id", true));

            String namespacePrefix = ReaderUtils.getAttribute(fmElem, "namespace", true);

            if (data.getNameSpaces().containsKey(namespacePrefix)) {
                fm.setNameSpaceId(namespacePrefix);
            } else {
                LOGGER.warning("Could not find namespace " + namespacePrefix + " defaulting to "
                        + data.getDefaultNameSpacePrefix());
                fm.setNameSpaceId(data.getDefaultNameSpacePrefix());
            }

            fm.setType(ReaderUtils.getChildText(fmElem, "type", true));
            fm.setUrl(ReaderUtils.getChildText(fmElem, "url", false));
            fm.setEnabled(ReaderUtils.getBooleanAttribute(fmElem, "enabled", false, true));
            fm.setTitle(ReaderUtils.getChildText(fmElem, "title", false));
            fm.setAbstract(ReaderUtils.getChildText(fmElem, "description", false));

            if (LOGGER.isLoggable(Level.FINER)) {
                LOGGER.finer(new StringBuffer("loading parameters for FormatDTO ").append(
                        fm.getId()).toString());
            }
        } catch (Exception e) {
            throw new ConfigurationException(e);
        }

        return fm;
    }

    /**
     * loadDataStores purpose.
     * 
     * <p>
     * Converts a DOM tree into a Map of DataStores.
     * </p>
     * 
     * @param dsRoot
     *            a DOM tree to convert into a Map of DataStores.
     * 
     * @return A complete Map of DataStores loaded from the DOM tree provided.
     * 
     * @throws ConfigurationException
     *             When an error occurs.
     */
    protected Map loadDataStores(Element dsRoot) throws ConfigurationException {
        Map dataStores = new HashMap();

        NodeList dsElements = dsRoot.getElementsByTagName("datastore");
        int dsCnt = dsElements.getLength();
        DataStoreInfoDTO dsConfig = null;
        Element dsElem;

        for (int i = 0; i < dsCnt; i++) {
            dsElem = (Element) dsElements.item(i);

            try {
                dsConfig = loadDataStore(dsElem);

                if (dataStores.containsKey(dsConfig.getId())) {
                    LOGGER.warning("Ignored duplicated datastore with id " + dsConfig.getId());
                } else {
                    dataStores.put(dsConfig.getId(), dsConfig);
                }
            } catch (ConfigurationException e) {
                LOGGER.log(Level.WARNING, "Ignored a misconfigured datastore.", e);
            }
        }

        return dataStores;
    }

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

        try {
            if (LOGGER.isLoggable(Level.FINER)) {
                LOGGER.finer("creating a new DataStoreDTO configuration");
            }

            ds.setId(ReaderUtils.getAttribute(dsElem, "id", true));

            String namespacePrefix = ReaderUtils.getAttribute(dsElem, "namespace", true);

            if (data.getNameSpaces().containsKey(namespacePrefix)) {
                ds.setNameSpaceId(namespacePrefix);
            } else {
                LOGGER.warning("Could not find namespace " + namespacePrefix + " defaulting to "
                        + data.getDefaultNameSpacePrefix());
                ds.setNameSpaceId(data.getDefaultNameSpacePrefix());
            }

            ds.setEnabled(ReaderUtils.getBooleanAttribute(dsElem, "enabled", false, true));
            ds.setTitle(ReaderUtils.getChildText(dsElem, "title", false));
            ds.setAbstract(ReaderUtils.getChildText(dsElem, "description", false));

            if (LOGGER.isLoggable(Level.FINER)) {
                LOGGER.finer(new StringBuffer("loading connection parameters for DataStoreDTO ")
                        .append(ds.getNameSpaceId()).toString());
            }

            ds.setConnectionParams(loadConnectionParams(ReaderUtils.getChildElement(dsElem,
                    "connectionParams", true)));
        } catch (Exception e) {
            throw new ConfigurationException(e);
        }

        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.config(new StringBuffer("Loaded datastore ").append(ds.getId()).toString());
        }

        return ds;
    }

    /**
     * loadConnectionParams purpose.
     * 
     * <p>
     * Converts a DOM tree into a Map of Strings which represent connection
     * parameters.
     * </p>
     * 
     * @param connElem
     *            a DOM tree to convert into a Map of Strings which represent
     *            connection parameters.
     * 
     * @return A complete Map of Strings which represent connection parameters
     *         loaded from the DOM tree provided.
     * 
     * @throws ConfigurationException
     *             When an error occurs.
     */
    protected Map loadConnectionParams(Element connElem) throws ConfigurationException {
        Map connectionParams = new HashMap();

        if (connElem == null) {
            return connectionParams;
        }

        NodeList paramElems = connElem.getElementsByTagName("parameter");
        int pCount = paramElems.getLength();
        Element param;
        String paramKey;
        String paramValue;

        try {
            for (int i = 0; i < pCount; i++) {
                param = (Element) paramElems.item(i);
                paramKey = ReaderUtils.getAttribute(param, "name", true);
                paramValue = ReaderUtils.getAttribute(param, "value", false);
                if ("shapefile url".equals(paramKey))
                    paramKey = "url";
                connectionParams.put(paramKey, paramValue);

                if (LOGGER.isLoggable(Level.FINER)) {
                    LOGGER.finer(new StringBuffer("added parameter ").append(paramKey)
                            .append(": '").append(paramValue.replaceAll("'", "\"")).append("'")
                            .toString());
                }
            }
        } catch (Exception e) {
            throw new ConfigurationException(e);
        }

        return connectionParams;
    }

    /**
     * Load map of FeatureTypeDTO instances from a directory.
     * 
     * <p>
     * Expected directory structure:
     * </p>
     * 
     * <ul>
     * <li> rootDir </li>
     * <li> rootDir/featureType1/info.xml - required </li>
     * <li> rootDir/featureType1/schema.xml - optional </li>
     * <li> rootDir/featureType2/info.xml - required </li>
     * <li> rootDir/featureType2/schema.xml - optional </li>
     * </ul>
     * 
     * <p>
     * If a schema.xml file is not used, the information may be generated from a
     * FeatureType using DataTransferObjectFactory.
     * </p>
     * 
     * @param featureTypeRoot
     *            Root FeatureType directory
     * 
     * @return Map of FeatureTypeInfoDTO by <code>dataStoreId:typeName</code>
     * 
     * @throws ConfigurationException
     *             When an error occurs.
     * @throws IllegalArgumentException
     *             DOCUMENT ME!
     */
    protected Map loadFeatureTypes(File featureTypeRoot) throws ConfigurationException {
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.finest(new StringBuffer("examining: ").append(featureTypeRoot.getAbsolutePath())
                    .toString());
            LOGGER.finest(new StringBuffer("is dir: ").append(featureTypeRoot.isDirectory())
                    .toString());
        }

        if (!featureTypeRoot.isDirectory()) {
            throw new IllegalArgumentException("featureTypeRoot must be a directoy");
        }

        File[] directories = featureTypeRoot.listFiles(new FileFilter() {
            public boolean accept(File pathname) {
                return pathname.isDirectory();
            }
        });

        Map map = new HashMap();

        for (int i = 0, n = directories.length; i < n; i++) {
            File info = new File(directories[i], "info.xml");

            if (info.exists() && info.isFile()) {

⌨️ 快捷键说明

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