private void findOntologies(File dir, String baseUri, OntologyFolder folder) {
   if (!dir.exists()) {
     dir.mkdirs();
   }
   for (File f : dir.listFiles()) {
     if (f.isFile() && (f.getName().endsWith(".owl") || f.getName().endsWith(".xsd"))) {
       String uri = findOntologyURI(f, baseUri);
       baseOntologyLibrary.importOntology(uri, f, folder);
     } else if (f.isDirectory() && !f.getName().equals("CVS")) {
       OntologyFolder newFolder = new OntologyFolder(f.getName(), folder, baseOntologyLibrary);
       findOntologies(f, baseUri + "/" + f.getName(), newFolder);
     }
   }
 }
 @Override
 public OntologyLibrary retrieveBaseOntologyLibrary() {
   if (baseOntologyLibrary == null) {
     logger.fine("Instanciating BaseOntologyLibrary");
     baseOntologyLibrary = new OntologyLibrary(this, null);
     findOntologies(
         new File(localDirectory, "Ontologies"),
         FLEXO_ONTOLOGY_ROOT_URI,
         baseOntologyLibrary.getRootFolder());
     // baseOntologyLibrary.init();
     logger.fine("Instanciating BaseOntologyLibrary Done. Loading some ontologies...");
     // baseOntologyLibrary.debug();
     baseOntologyLibrary.getRDFSOntology().loadWhenUnloaded();
     baseOntologyLibrary.getRDFOntology().loadWhenUnloaded();
     baseOntologyLibrary.getOWLOntology().loadWhenUnloaded();
     baseOntologyLibrary.THING = baseOntologyLibrary.getClass(OntologyLibrary.OWL_THING_URI);
     baseOntologyLibrary.getRDFSOntology().updateConceptsAndProperties();
     baseOntologyLibrary.getRDFOntology().updateConceptsAndProperties();
     baseOntologyLibrary.getFlexoConceptOntology().loadWhenUnloaded();
     // baseOntologyLibrary.debug();
   }
   return baseOntologyLibrary;
 }
 private void findOntologies(File dir, String baseUri, OntologyFolder folder) {
   if (!dir.exists()) {
     dir.mkdirs();
   }
   if (dir.listFiles().length == 0) {
     copyOntologies(ONTOLOGY_LIBRARY_DIR, dir.getParentFile());
   }
   for (File f : dir.listFiles()) {
     if (f.isFile() && f.getName().endsWith(".owl")) {
       String uri = FlexoOntology.findOntologyURI(f);
       if (uri == null) {
         uri = baseUri + "/" + f.getName();
       }
       baseOntologyLibrary.importOntology(uri, f, folder);
     } else if (f.isDirectory() && !f.getName().equals("CVS")) {
       OntologyFolder newFolder = new OntologyFolder(f.getName(), folder, baseOntologyLibrary);
       findOntologies(f, baseUri + "/" + f.getName(), newFolder);
     }
   }
 }
  @Override
  public OntologyLibrary retrieveBaseOntologyLibrary() {
    if (baseOntologyLibrary == null) {
      File baseOntologyFolder = new File(localDirectory, "Ontologies");
      logger.info("Instantiating BaseOntologyLibrary from " + baseOntologyFolder.getAbsolutePath());
      baseOntologyLibrary = new OntologyLibrary(this, null);
      findOntologies(
          baseOntologyFolder, FLEXO_ONTOLOGY_ROOT_URI, baseOntologyLibrary.getRootFolder());
      // baseOntologyLibrary.init();

      // Bug fix: compatibility with old versions:
      // If some of those ontologies were not found, try to copy default ontologies
      if (baseOntologyLibrary.getRDFSOntology() == null
          || baseOntologyLibrary.getRDFOntology() == null
          || baseOntologyLibrary.getOWLOntology() == null
          || baseOntologyLibrary.getFlexoConceptOntology() == null) {
        copyOntologies(localDirectory, CopyStrategy.REPLACE);
        findOntologies(
            baseOntologyFolder, FLEXO_ONTOLOGY_ROOT_URI, baseOntologyLibrary.getRootFolder());
      }

      logger.fine("Instantiating BaseOntologyLibrary Done. Loading some ontologies...");
      // baseOntologyLibrary.debug();
      baseOntologyLibrary.getRDFSOntology().loadWhenUnloaded();
      baseOntologyLibrary.getRDFOntology().loadWhenUnloaded();
      baseOntologyLibrary.getOWLOntology().loadWhenUnloaded();
      baseOntologyLibrary.getRDFSOntology().updateConceptsAndProperties();
      baseOntologyLibrary.getRDFOntology().updateConceptsAndProperties();
      baseOntologyLibrary.getOWLOntology().updateConceptsAndProperties();
      baseOntologyLibrary.getFlexoConceptOntology().loadWhenUnloaded();
      // baseOntologyLibrary.debug();
    }
    return baseOntologyLibrary;
  }