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

📄 xmlconfigwriter.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                } else {
                    m.put("dynamic", "true");
                }

                cw.attrTag("latLonBoundingBox", m);
            }

            if (ft.getNativeBBox() != null) {
                m = new HashMap();

                Envelope e = ft.getNativeBBox();

                // from creation, isn't stored otherwise
                if (!e.isNull()) {
                    m.put("dynamic", "false");
                    m.put("minx", e.getMinX() + "");
                    m.put("miny", e.getMinY() + "");
                    m.put("maxx", e.getMaxX() + "");
                    m.put("maxy", e.getMaxY() + "");
                } else {
                    m.put("dynamic", "true");
                }

                cw.attrTag("nativeBBox", m);
            }

            if ((ft.getDefaultStyle() != null) && (ft.getDefaultStyle() != "")) {
                cw.comment("the default style this FeatureTypeInfoDTO can be represented by.\n"
                    + "at least must contain the \"default\" attribute ");
                m = new HashMap();
                m.put("default", ft.getDefaultStyle());

                final ArrayList styles = ft.getStyles();

                if (styles.isEmpty()) {
                    cw.attrTag("styles", m);
                } else {
                    cw.openTag("styles", m);

                    Iterator s_IT = styles.iterator();

                    while (s_IT.hasNext())
                        cw.textTag("style", (String) s_IT.next());

                    cw.closeTag("styles");
                }
            }

            m = new HashMap();

            if (ft.getCacheMaxAge() != null) {
                m.put("maxage", ft.getCacheMaxAge());
            }

            if (ft.isCachingEnabled()) {
                m.put("enabled", "true");
            } else {
                m.put("enabled", "false");
            }

            cw.attrTag("cacheinfo", m);

            if (ft.getDefinitionQuery() != null) {
                cw.openTag("definitionQuery");

                /*
                 * @REVISIT: strongly test this works.
                 */

                /*
                   StringWriter sw = new StringWriter();
                   org.geotools.filter.XMLEncoder xe = new org.geotools.filter.XMLEncoder(sw);
                   xe.encode(ft.getDefinitionQuery());
                   cw.writeln(sw.toString());
                   cw.closeTag("definitionQuery");
                 */
                FilterTransformer ftransformer = new FilterTransformer();
                ftransformer.setOmitXMLDeclaration(true);
                ftransformer.setNamespaceDeclarationEnabled(false);

                String sfilter = ftransformer.transform(ft.getDefinitionQuery());
                cw.writeln(sfilter);
            }

            cw.closeTag("featureType");
            fw.close();
        } catch (IOException e) {
            throw new ConfigurationException(e);
        } catch (TransformerException e) {
            throw new ConfigurationException(e);
        }
    }

    protected static void storeFeatureSchema(FeatureTypeInfoDTO fs, File dir)
        throws ConfigurationException {
        if ((fs.getSchemaBase() == null) || (fs.getSchemaBase() == "")) {
            //LOGGER.info( "No schema base" );
            if (LOGGER.isLoggable(Level.FINER)) {
                LOGGER.finer(new StringBuffer(fs.getKey()).append(" has not schemaBase").toString());
            }

            return;
        }

        if ((fs.getSchemaName() == null) || (fs.getSchemaName() == "")) {
            // Should assume Null?
            //LOGGER.info( "No schema name" ); // Do we even have a field for this?
            if (LOGGER.isLoggable(Level.FINER)) {
                LOGGER.finer(new StringBuffer(fs.getKey()).append(" has not schemaName").toString());
            }

            return;
        }

        File f = WriterUtils.initWriteFile(new File(dir, "schema.xml"), false);

        try {
            Writer fw = new OutputStreamWriter(new FileOutputStream(f), getDefaultEncoding());
            storeFeatureSchema(fs, fw);
            fw.close();
        } catch (IOException e) {
            throw new ConfigurationException(e);
        }
    }

    public static void storeFeatureSchema(FeatureTypeInfoDTO fs, Writer w)
        throws ConfigurationException {
        WriterHelper cw = new WriterHelper(w);
        HashMap m = new HashMap();
        String t = fs.getSchemaName();

        if (t != null) {
            if (!"_Type".equals(t.substring(t.length() - 5))) {
                t = t + "_Type";
            }

            m.put("name", t);
        }

        cw.openTag("xs:complexType", m);
        cw.openTag("xs:complexContent");
        m = new HashMap();
        t = fs.getSchemaBase();

        if (t != null) {
            m.put("base", t);
        }

        cw.openTag("xs:extension", m);
        cw.openTag("xs:sequence");

        for (int i = 0; i < fs.getSchemaAttributes().size(); i++) {
            AttributeTypeInfoDTO ati = (AttributeTypeInfoDTO) fs.getSchemaAttributes().get(i);
            m = new HashMap();
            m.put("nillable", "" + ati.isNillable());
            m.put("minOccurs", "" + ati.getMinOccurs());
            m.put("maxOccurs", "" + ati.getMaxOccurs());

            NameSpaceTranslator nst_xs = NameSpaceTranslatorFactory.getInstance()
                                                                   .getNameSpaceTranslator("xs");
            NameSpaceTranslator nst_gml = NameSpaceTranslatorFactory.getInstance()
                                                                    .getNameSpaceTranslator("gml");

            if (!ati.isComplex()) {
                if (ati.getName() == ati.getType()) {
                    String r = "";
                    NameSpaceElement nse = nst_xs.getElement(ati.getType());

                    if (nse == null) {
                        nse = nst_gml.getElement(ati.getType());
                    }

                    r = nse.getQualifiedTypeRefName();
                    m.put("ref", r);
                } else {
                    m.put("name", ati.getName());

                    String r = "";
                    NameSpaceElement nse = nst_xs.getElement(ati.getType());

                    if (nse == null) {
                        nse = nst_gml.getElement(ati.getType());
                        r = nse.getQualifiedTypeDefName(); // Def
                    } else {
                        r = nse.getQualifiedTypeRefName(); // Ref
                    }

                    m.put("type", r);
                }

                cw.attrTag("xs:element", m);
            } else {
                m.put("name", ati.getName());
                cw.openTag("xs:element", m);
                cw.writeln(ati.getType());
                cw.closeTag("xs:element");
            }
        }

        cw.closeTag("xs:sequence");
        cw.closeTag("xs:extension");
        cw.closeTag("xs:complexContent");
        cw.closeTag("xs:complexType");
    }

    protected static void storeCoverages(File dir, DataDTO data)
        throws ConfigurationException {
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine("In method storeCoverages");
        }

        // write them
        Iterator i = data.getCoverages().keySet().iterator();

        while (i.hasNext()) {
            String s = (String) i.next();
            CoverageInfoDTO cv = (CoverageInfoDTO) data.getCoverages().get(s);

            if (cv != null) {
                File dir2 = WriterUtils.initWriteFile(new File(dir, cv.getDirName()), true);

                storeCoverage(cv, dir2);
            }
        }

        File[] fa = dir.listFiles();

        for (int j = 0; j < fa.length; j++) {
            if (fa[j].isDirectory()) {
                // find dir name
                i = data.getCoverages().values().iterator();

                CoverageInfoDTO cvi = null;

                while ((cvi == null) && i.hasNext()) {
                    CoverageInfoDTO cv = (CoverageInfoDTO) i.next();

                    if (cv.getDirName().equals(fa[j].getName())) {
                        cvi = cv;
                    }
                }

                if (cvi == null) {
                    //delete it
                    File[] t = fa[j].listFiles();

                    if (t != null) {
                        for (int x = 0; x < t.length; x++) {
                            //hold on to the data, but be sure to get rid of the
                            //geoserver config shit, as these were deleted.
                            if (t[x].getName().equals("info.xml")) {
                                //sorry for the hardcodes, I don't remember if/where
                                //we have these file names.
                                t[x].delete();
                            }
                        }
                    }

                    if (fa[j].listFiles().length == 0) {
                        fa[j].delete();
                    }
                }
            }
        }
    }

    protected static void storeCoverage(CoverageInfoDTO cv, File dir)
        throws ConfigurationException {
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine("In method storeCoverage");
        }

        File f = WriterUtils.initWriteFile(new File(dir, "info.xml"), false);

        try {
            Writer fw = new OutputStreamWriter(new FileOutputStream(f), getDefaultEncoding());
            WriterHelper cw = new WriterHelper(fw);
            Map m = new HashMap();

            if ((cv.getFormatId() != null) && (cv.getFormatId() != "")) {
                m.put("format", cv.getFormatId());
            }

            cw.openTag("coverage", m);

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

            if ((cv.getLabel() != null) && (cv.getLabel() != "")) {
                cw.textTag("label", cv.getLabel());
            }

            if ((cv.getDescription() != null) && (cv.getDescription() != "")) {
                cw.textTag("description", cv.getDescription());
            }

            if ((cv.getWmsPath() != null) && (cv.getWmsPath() != "")) {
                cw.textTag("wmspath", cv.getWmsPath());
            }

            m = new HashMap();

            if ((cv.getMetadataLink() != null)) {
                m.put("about", cv.getMetadataLink().getAbout());
                m.put("type", cv.getMetadataLink().getType());
                m.put("metadataType", cv.getMetadataLink().getMetadataType());

                cw.openTag("metadataLink", m);
                cw.writeln(cv.getMetadataLink().getContent());
                cw.closeTag("metadataLink");
            }

            if ((cv.getKeywords() != null) && (cv.getKeywords().size() != 0)) {
                String s = "";
                Iterator i = cv.getKeywords().iterator();

                if (i.hasNext()) {
                    s = i.next().toString();

                    while (i.hasNext()) {
                        s = s + "," + i.next().toString();
                    }
                }

                cw.textTag("keywords", s);
            }

            if ((cv.getDefaultStyle() != null) && (cv.getDefaultStyle() != "")) {
                cw.comment("the default style this CoverageInfoDTO can be represented by.\n"
                    + "at least must contain the \"default\" attribute ");
                m = new HashMap();
                m.put("default", cv.getDefaultStyle());

                final ArrayList styles = cv.getStyles();

                if (styles.isEmpty()) {
                    cw.attrTag("styles", m);
                } else {
                    cw.openTag("styles", m);

                    Iterator s_IT = styles.iterator();

                    while (s_IT.hasNext())
                        cw.textTag("style", (String) s_IT.next());

                    cw.closeTag("styles");
                }

⌨️ 快捷键说明

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