Есть довольно много сообщений на эту тему, и я не мог найти удовлетворительное решение. Вот как это работает для меня. Дайте SchemaFactory собственный распознаватель ресурсов
<code>
Source source = new StreamSource(this.getClass().getResourceAsStream("ebics.xsd"));
LSResourceResolver resolver = new ResourceResolver(schemaFactory.getResourceResolver());
schemaFactory.setResourceResolver(resolver);
и разбирать только схему верхнего уровня. Затем распознаватель может (надеюсь) разрешить встроенные ссылки
public class ResourceResolver implements LSResourceResolver {
private LSResourceResolver parent = null;
private Set returnedResources = new HashSet();
public ResourceResolver(LSResourceResolver r){
parent = r;
}
private ResourceResolver() {
}
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
LSInput input = new LSInputImpl();
if (returnedResources.contains(systemId)) {
return null;
} else if (systemId.equals("ebics_hev.xsd")) {
input.setByteStream(this.getClass().getResourceAsStream("ebics_hev.xsd"));
} else if (systemId.equals("ebics_keymgmt_request.xsd")) {
input.setByteStream(this.getClass().getResourceAsStream("ebics_keymgmt_request.xsd"));
} else if (systemId.equals("ebics_keymgmt_response.xsd")) {
input.setByteStream(this.getClass().getResourceAsStream("ebics_keymgmt_response.xsd"));
} else if (systemId.equals("ebics_orders.xsd")) {
input.setByteStream(this.getClass().getResourceAsStream("ebics_orders.xsd"));
} else if (systemId.equals("ebics_request.xsd")) {
input.setByteStream(this.getClass().getResourceAsStream("ebics_request.xsd"));
} else if (systemId.equals("ebics_response.xsd")) {
input.setByteStream(this.getClass().getResourceAsStream("ebics_response.xsd"));
} else if (systemId.equals("ebics_signature.xsd")) {
input.setByteStream(this.getClass().getResourceAsStream("ebics_signature.xsd"));
} else if (systemId.equals("ebics_types.xsd")) {
input.setByteStream(this.getClass().getResourceAsStream("ebics_types.xsd"));
} else if (systemId.equals("ebics.xsd")) {
input.setByteStream(this.getClass().getResourceAsStream("ebics.xsd"));
} else if (systemId.equals("xmldsig-core-schema.xsd")) {
input.setByteStream(this.getClass().getResourceAsStream("xmldsig-core-schema.xsd"));
} else {
return parent.resolveResource(type, namespaceURI, publicId, systemId, baseURI);
}
returnedResources.add(systemId);
return input;
}
}
Вот LSInputImpl
public class LSInputImpl implements LSInput
{
public Reader getCharacterStream () {
return null;
}
public void setCharacterStream ( Reader characterStream ) {}
public InputStream getByteStream () {
InputStream retval = null;
if ( byteStream != null ) {
retval = byteStream;
}
return retval;
}
public void setByteStream ( InputStream byteStream ) {
this.byteStream = byteStream;
}
public String getStringData () {
return null;
}
public void setStringData ( String stringData ) {}
public String getSystemId () {
return systemId;
}
public void setSystemId ( String systemId ) {
this.systemId = systemId;
}
public String getPublicId () {
return null;
}
public void setPublicId ( String publicId ) {}
public String getBaseURI () {
return null;
}
public void setBaseURI ( String baseURI ) {}
public String getEncoding () {
return null;
}
public void setEncoding ( String encoding ) {}
public boolean getCertifiedText () {
return false;
}
public void setCertifiedText ( boolean certifiedText ) {}
private String systemId = null;
private InputStream byteStream = null;
}