找不到包含的XSD

时间:2019-02-27 16:36:10

标签: xsd xsd-validation

在升级到Java 8之前,我的项目在Java 6上运行良好。当我尝试加载资源时,出现错误”意外问题:java.lang.RuntimeException:java.io.FileNotFoundException:dynamicFeature。 xsd”。。这是我的XSD的结构。

-- /saa/schemas
   - ISO_191_Schmemas
       -- gml.xsd
       -- dynamicFeature.xsd
SAA-Features.xsd
SAA-Message.xsd

这是我的gml.xsd,其中包含dynamicFeature.xsd。

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gml="http://www.opengis.net/gml" xmlns:sch="http://www.ascc.net/xml/schematron" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="3.0.0">
  <xsd:annotation>
    <xsd:appinfo source="urn:opengis:specification:gml:schema-xsd:gml:v3.0.0">gml.xsd</xsd:appinfo>
    <xsd:documentation>
            Top level GML schema
        </xsd:documentation>
  </xsd:annotation>
  <!-- ====================================================================== -->
  <xsd:include schemaLocation="dynamicFeature.xsd"/>
  <xsd:include schemaLocation="topology.xsd"/>
  <xsd:include schemaLocation="coverage.xsd"/>
  <xsd:include schemaLocation="coordinateReferenceSystems.xsd"/>
  <xsd:include schemaLocation="observation.xsd"/>
  <xsd:include schemaLocation="defaultStyle.xsd"/>
  <!-- ====================================================================== -->
</xsd:schema
  

这是我的ResourceResolver代码,可以在Java 6上正常工作,但是在升级到Java 8之后,我们收到错误消息,它无法找到gml.xsd中包含的dynamicFeature.xsd。还可以找到仅定义了顶级架构的Schemalocations列表。每次代码都会在if语句*** if(schemaName.equals(candidate.getSchema()))****中失败,因为仅在架构位置中定义了顶级架构名称,因此它永远都无法找到我所需要的findResource无法弄清楚它是如何工作的。

public static final String ROOT = "saa/schemas/";

    public static final SchemaLocation SCHEMA_SAA_MESSAGE = new SchemaLocation("urn:us:gov:dot:faa:aim:saa", "SAA-Message.xsd");
    public static final SchemaLocation SCHEMA_SAA_FEATURE = new SchemaLocation("", "SAA-Features.xsd");
    public static final List<SchemaLocation> SAA_SCHEMAS;

        static {
            List<SchemaLocation> schemas = new ArrayList<SchemaLocation>();

            schemas.add(SCHEMA_SAA_FEATURES);
            schemas.add(SCHEMA_SAA_MESSAGE);




            SAA_SCHEMAS = schemas;
        }

EntityResolver代码:

import org.xml.sax.ext.EntityResolver2;

    public class SAAEntityResolver implements EntityResolver2 {

        private static final Log LOG = LogFactory.getLog(SAAEntityResolver.class);

        private EntityResolver2 delegate;

        private List<SchemaLocation> schemaLocations;

        /**
         * Constructs a new xml entity resolver specifying a search path within the classpath.
         * <p>

        public SAAEntityResolver(List<SchemaLocation> searchPath, EntityResolver2 delegate) {
            this.delegate = delegate;
            this.schemaLocations = searchPath;
        }

        /* (non-Javadoc)
         * 
         * Created on Feb 9, 2010 by rcracel
         * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String)
         */
        @Override
        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {

            InputSource result = null;
            String schemaName = systemId;

            if (systemId == null && publicId == null) {
                LOG.error("Cannot resolve schema, both system and public ids are null");
            } else {
                if (schemaName != null) {
                    if (schemaName.contains("/")) {
                        schemaName = schemaName.substring(schemaName.lastIndexOf("/") + 1);
                    }

                    for (int index = 0; index < **schemaLocations**.size() && result == null; index++) {
                        SchemaLocation candidate = schemaLocations.get(index);
                        if (schemaName.equals(candidate.getSchema())) {
                            URL resource = ResourceUtils.findResource(candidate.getAbsolutePath());
                            InputStream stream = resource.openStream();
                            if (stream != null) {
                                result = new InputSource(stream);
                                result.setPublicId(publicId);
                                result.setSystemId(resource.toString());
                            }
                        }
                    }
                } else if (publicId != null) {
                    for (int index = 0; index < schemaLocations.size() && result == null; index++) {
                        SchemaLocation candidate = schemaLocations.get(index);
                        if (publicId.equals(candidate.getPublicId())) {
                            URL resource = ResourceUtils.findResource(candidate.getAbsolutePath());
                            InputStream stream = resource.openStream();
                            if (stream != null) {
                                result = new InputSource(stream);
                                result.setPublicId(publicId);
                                result.setSystemId(resource.toString());
                            }
                        }
                    }
                }
            }

            if (result == null && delegate != null) {
                result = delegate.resolveEntity(publicId, systemId);
            }
            return result;
        }


     * @see org.xml.sax.ext.EntityResolver2#resolveEntity(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
     */
    @Override
    public InputSource resolveEntity(String name, String publicId, String baseURI, String systemId) throws SAXException, IOException {
        LOG.error("name" + name);
        LOG.error("publicId"+ publicId);
        LOG.error("baseURI" + baseURI);
        LOG.error("systemID" + systemId);
        if (LOG.isDebugEnabled())
            LOG.debug(String.format("*************** resolveEntity(\"%s\", \"%s\", \"%s\", \"%s\");", name, publicId, baseURI, systemId));
        return resolveEntity(publicId, systemId);
    }

这是带有findResource方法的ResouceUtils代码:

public static URL findResource(String path) {
    LOG.info("inside ResourceUtils -> findResource method path value"+ path);
   URL resource = ClassLoader.getSystemResource(path);
    LOG.info("ResourceUtils URL1" + resource);

    if (resource == null) {
        LOG.info("resource null");
        resource = ResourceUtils.class.getResource(path);
        LOG.info("ResourceUtils URL2" + resource);
    }

    return resource;
}

我对此错误停留了一段时间,如果有人可以帮助我解决此错误,我们将不胜感激。我可以提供帖子中缺少的任何其他信息。

谢谢

0 个答案:

没有答案