try {
final RDFXMLOntologyFormat format = new RDFXMLOntologyFormat();
if (owlOntologyManager == null) {
throw new OWLRuntimeException("Cannot parse because OWLOntologyManager is null!");
}
final RDFParser parser = new RDFParser() {
public void startPrefixMapping(String prefix, String uri) throws SAXException {
super.startPrefixMapping(prefix, uri);
format.addPrefixNamespaceMapping(prefix, uri);
}
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws
SAXException {
super.startElement(namespaceURI, localName, qName, atts);
String value = atts.getValue(XMLNS, "base");
if (value != null) {
consumer.setXMLBase(value);
}
}
};
consumer = new OWLRDFConsumer(owlOntologyManager, ontology, new AnonymousNodeChecker() {
public boolean isAnonymousNode(URI uri) {
return parser.isAnonymousNodeURI(uri.toString());
}
public boolean isAnonymousNode(String uri) {
return parser.isAnonymousNodeURI(uri);
}
});
consumer.setOntologyFormat(format);
InputSource is = getInputSource(inputSource);
parser.parse(is, consumer);
return format;
}
catch (SAXException e) {
throw new OWLRDFXMLParserSAXException(e);
}