SchemaLSResourceResolver implements LSResourceResolver { @Override public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { LOG.info("Trying to resolve XML entity with public ID [{}] and system ID [{}]", publicId, systemId); isValidSystemID(systemId); InputStream source = null; try { source = resolveFromClassPath(systemId); } catch (URISyntaxException | IOException exClasspath) { LOG.error("{}", exClasspath.getMessage()); LOG.debug("Exception: {}", exClasspath); try { source = resolveFromURL(systemId); } catch (IOException exURL) { MappingUtils.throwMappingException(exURL); } } InputStreamLSInput lsInput = null; try { lsInput = new InputStreamLSInput(publicId, systemId, baseURI, new StringReader(IOUtils.toString(source, Charset.forName("UTF-8")))); LOG.info("Resolved public ID [{}] and system ID [{}]", publicId, systemId); } catch (IOException ex) { MappingUtils.throwMappingException("Could not resolve bean-mapping XML Schema [" + systemId + "]", ex); } finally { IOUtils.closeQuietly(source); } return lsInput; } SchemaLSResourceResolver(BeanContainer beanContainer); @Override LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI);  }
@Test public void handlesNullSystemId() { handlesNullSystemId.expectMessage(Matchers.containsString(nullSystemIdMessage)); handlesNullSystemId.expect(MappingException.class); LSResourceResolver resolver = new SchemaLSResourceResolver(new BeanContainer()); resolver.resolveResource(null, null, null, null, null); }
@Test public void handlesV5Schema() { handlesV5Schema.expectMessage(Matchers.containsString(v5Message)); handlesV5Schema.expect(MappingException.class); String systemId = "http: LSResourceResolver resolver = new SchemaLSResourceResolver(new BeanContainer()); resolver.resolveResource(null, null, null, systemId, null); }
@Test public void canResolveViaClasspath() { URL systemId = getClass().getClassLoader().getResource("schema/bean-mapping.xsd"); LSResourceResolver resolver = new SchemaLSResourceResolver(new BeanContainer()); LSInput answer = resolver.resolveResource(null, null, null, systemId.toString(), null); assertNotNull(answer); assertNotNull(answer.getByteStream()); assertNotNull(answer.getCharacterStream()); }
@Test public void canResolveViaURL() { String systemId = "https: LSResourceResolver resolver = new SchemaLSResourceResolver(new BeanContainer()); LSInput answer = resolver.resolveResource(null, null, null, systemId, null); assertNotNull(answer); assertNotNull(answer.getByteStream()); assertNotNull(answer.getCharacterStream()); }