CatalogXmlIRIMapper implements OWLOntologyIRIMapper { static Map<IRI, IRI> parseCatalogXml(InputStream inputStream, final File parentFolder) throws IOException { if (inputStream == null) { throw new IllegalArgumentException("InputStream should never be null, missing resource?"); } SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(false); try { final Map<IRI, IRI> mappings = new HashMap<IRI, IRI>(); SAXParser saxParser = factory.newSAXParser(); saxParser.parse(inputStream, new DefaultHandler(){ @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if ("uri".equals(qName)) { IRI original = null; IRI mapped = null; String nameString = attributes.getValue("name"); if (nameString != null) { original = IRI.create(nameString); } String mappedString = attributes.getValue("uri"); if (mappedString != null) { if (parentFolder != null && mappedString.indexOf(":") < 0) { File file = new File(mappedString); if (!file.isAbsolute()) { file = new File(parentFolder, mappedString); } try { file = file.getCanonicalFile(); mapped = IRI.create(file); } catch (IOException e) { logger.warn("Skipping mapping: "+nameString+" "+mappedString, e); } } else { mapped = IRI.create(mappedString); } } if (original != null && mapped != null) { mappings.put(original, mapped); } } } }); return mappings; } catch (ParserConfigurationException e) { throw new IOException(e); } catch (SAXException e) { throw new IOException(e); } finally { inputStream.close(); } } CatalogXmlIRIMapper(Map<IRI, IRI> mappings);  CatalogXmlIRIMapper(String catalogFile);  CatalogXmlIRIMapper(File catalogFile);  CatalogXmlIRIMapper(File catalogFile, File parentFolder);  CatalogXmlIRIMapper(URL catalogURL);  CatalogXmlIRIMapper(URL catalogURL, File parentFolder); @Override IRI getDocumentIRI(IRI ontologyIRI); Map<IRI, IRI> getMappings();  }
@Test public void testParseCatalogXML() throws Exception { File resource = getResource("catalog-v001.xml"); InputStream inputStream = new FileInputStream(resource); File parentFolder = resource.getParentFile(); Map<IRI, IRI> mappings = CatalogXmlIRIMapper.parseCatalogXml(inputStream, parentFolder); assertTrue(mappings.size() > 1); }