use of org.apache.xerces.xs.XSLoader in project winery by eclipse.
the class BackendUtils method getXSModel.
/**
* @param ref the file to read from
*/
public static Optional<XSModel> getXSModel(final RepositoryFileReference ref) {
Objects.requireNonNull(ref);
final InputStream is;
try {
is = RepositoryFactory.getRepository().newInputStream(ref);
} catch (IOException e) {
BackendUtils.LOGGER.debug("Could not create input stream", e);
return Optional.empty();
}
// we rely on xerces to parse the XSD
// idea based on http://stackoverflow.com/a/5165177/873282
XSImplementation impl = new XSImplementationImpl();
XSLoader schemaLoader = impl.createXSLoader(null);
// minimal LSInput implementation sufficient for XSLoader in Oracle's JRE7
LSInput input = new LSInput() {
@Override
public void setSystemId(String systemId) {
}
@Override
public void setStringData(String stringData) {
}
@Override
public void setPublicId(String publicId) {
}
@Override
public void setEncoding(String encoding) {
}
@Override
public void setCharacterStream(Reader characterStream) {
}
@Override
public void setCertifiedText(boolean certifiedText) {
}
@Override
public void setByteStream(InputStream byteStream) {
}
@Override
public void setBaseURI(String baseURI) {
}
@Override
public String getSystemId() {
return null;
}
@Override
public String getStringData() {
return null;
}
@Override
public String getPublicId() {
return BackendUtils.getPathInsideRepo(ref);
}
@Override
public String getEncoding() {
return "UTF-8";
}
@Override
public Reader getCharacterStream() {
try {
return new InputStreamReader(is, "UTF-8");
} catch (UnsupportedEncodingException e) {
System.out.println("exeption");
throw new IllegalStateException("UTF-8 is unkown", e);
}
}
@Override
public boolean getCertifiedText() {
return false;
}
@Override
public InputStream getByteStream() {
return null;
}
@Override
public String getBaseURI() {
return null;
}
};
return Optional.ofNullable(schemaLoader.load(input));
}
Aggregations