MirrorOperation { public static void mirror(OWLOntology rootOntology, File baseFolder, File catalogFile) throws IOException, OWLOntologyStorageException { logger.info("Mirroring ontologies: " + rootOntology); Map<IRI, String> iriMap = new HashMap<>(); for (OWLOntology ont : rootOntology.getImportsClosure()) { logger.info("Mirroring: " + ont); validateImports(ont); OWLOntologyID ontologyID = ont.getOntologyID(); IRI ontologyIRI = ontologyID.getOntologyIRI().orNull(); if (ontologyIRI == null) { ontologyIRI = IRI.generateDocumentIRI(); } String localFilePath = getMirrorPathOfOntologyIRI(ontologyIRI); IRI outputStream = IRI.create(new File(baseFolder, localFilePath)); ont.getOWLOntologyManager().saveOntology(ont, outputStream); iriMap.put(ontologyIRI, localFilePath); IRI documentIRI = ont.getOWLOntologyManager().getOntologyDocumentIRI(ont); if (!documentIRI.toString().startsWith("file:") && documentIRI != ontologyIRI) { String sourceLocalFile = getMirrorPathOfOntologyIRI(ontologyIRI); logger.info("Mirroring " + documentIRI + " in " + sourceLocalFile); iriMap.put(documentIRI, sourceLocalFile); } } writeCatalog(catalogFile, iriMap); }  static void mirror(OWLOntology rootOntology, File baseFolder, File catalogFile); static void writeCatalog(File catalogFile, Map<IRI, String> iriMap);  }
@Test public void testMirror() throws Exception { testMirror("/import_test.owl"); }