示例#1
0
  public void testSchemaCapture() throws Exception {
    __log.debug("GETTING RESOURCE " + TestResources.getRetailerSchema());
    InputStream xsdStream = TestResources.getRetailerSchema().openStream();
    byte[] data;
    try {
      data = StreamUtils.read(xsdStream);
    } finally {
      xsdStream.close();
    }

    Map<URI, byte[]> s =
        XSUtils.captureSchema(
            URI.create("schema.xsd"),
            data,
            new XMLEntityResolver() {
              public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier)
                  throws XNIException, IOException {
                XMLInputSource src = new XMLInputSource(resourceIdentifier);
                String literalUri = resourceIdentifier.getLiteralSystemId();

                if (literalUri != null) {
                  src.setByteStream(getClass().getClassLoader().getResourceAsStream(literalUri));
                }

                return src;
              }
            },
            0);
    // we expect the root schema and three includes
    __log.debug("loaded " + s.keySet());
    assertEquals(5, s.size());
  }