diff --git a/src/main/java/widoco/Configuration.java b/src/main/java/widoco/Configuration.java index 1477728..86a0529 100644 --- a/src/main/java/widoco/Configuration.java +++ b/src/main/java/widoco/Configuration.java @@ -578,6 +578,7 @@ private void completeOntologyMetadata(OWLAnnotation a, OWLOntology o) { if (this.currentLanguage.equals(valueLanguage) || (abstractSection == null || "".equals(abstractSection))) { abstractSection = value; + this.setIncludeAbstract(true); // in case users set no place holder text but added their own } } catch (Exception e) { logger.error("Error while getting ontology abstract. No literal provided"); @@ -596,6 +597,7 @@ private void completeOntologyMetadata(OWLAnnotation a, OWLOntology o) { || (mainOntologyMetadata.getDescription() == null || mainOntologyMetadata.getDescription().isEmpty())) { mainOntologyMetadata.setDescription(value); + this.setIncludeDescription(true); } } catch (Exception e) { logger.error("Error while getting ontology description. No literal provided"); @@ -821,6 +823,7 @@ private void completeOntologyMetadata(OWLAnnotation a, OWLOntology o) { if (this.currentLanguage.equals(valueLanguage) || (introText == null || "".equals(introText))) { introText = value; + this.setIncludeIntroduction(true); } } catch (Exception e) { logger.error("Error while introduction annotation. No literal provided"); diff --git a/src/main/java/widoco/WidocoUtils.java b/src/main/java/widoco/WidocoUtils.java index 70983c1..7af6f59 100644 --- a/src/main/java/widoco/WidocoUtils.java +++ b/src/main/java/widoco/WidocoUtils.java @@ -155,55 +155,10 @@ public static void writeModel(OWLOntologyManager m, OWLOntology o, OWLDocumentFo } } - // /** - // * Method that reads a local file and loads it into the configuration. - // * @param model - // * @param ontoPath - // * @param ontoURL - // */ - // private static void readOntModel(OntModel model,Configuration c){ - // String[] serializations = {"RDF/XML", "TTL", "N3"}; - // String ontoPath = c.getOntologyPath(); - // String ext = ""; - // for(String s:serializations){ - // InputStream in; - // try{ - // in = FileManager.get().open(ontoPath); - // if (in == null) { - // System.err.println("Error: Ontology file not found"); - // return; - // } - // model.read(in, null, s); - // System.out.println("Vocab loaded in "+s); - // if(s.equals("RDF/XML")){ - // ext="xml"; - // }else if(s.equals("TTL")){ - // ext="ttl"; - // }else if(s.equals("N3")){ - // ext="n3"; - // } - // c.getMainOntology().addSerialization(s, "ontology."+ext); - // //c.setVocabSerialization(s); - // break; - // }catch(Exception e){ - // System.err.println("Could not open the ontology in "+s); - // } - // } - // - // } - - public static void copyResourceFolder(String[] resources, String savePath) throws IOException { - for (String resource : resources) { - String aux = resource.substring(resource.lastIndexOf("/") + 1, resource.length()); - File b = new File(savePath + File.separator + aux); - b.createNewFile(); - copyLocalResource(resource, b); - } - } public static void copyResourceDir(String resourceFolder, File destinationFolder) throws IOException { // Determine if running from JAR or as source - logger.info("copyResourceFolder from "+resourceFolder+" to "+ destinationFolder); + logger.info("Copying resource folder from "+resourceFolder+" to "+ destinationFolder); URL resourceUrl = WidocoUtils.class.getClassLoader().getResource(resourceFolder); if (!destinationFolder.exists()) destinationFolder.mkdirs(); @@ -300,102 +255,39 @@ public static void copyLocalResource(String resourceName, File dest) { } } + /** - * Copy a file from outside the project into the desired file. - * + * Auxiliary method for reading local resources and returning their content * @param path - * @param dest + * path of the file + * @return + * content of the file */ - public static void copyExternalResource(String path, File dest) { - try { - InputStream is = new FileInputStream(path); - copy(is, dest); - } catch (Exception e) { + public static String readExternalResource(String path) { + String content = ""; + try{ + content = new String ( Files.readAllBytes( Paths.get(path) ) ); + }catch (IOException e){ logger.error("Exception while copying " + path + e.getMessage()); } + return content; } - - public static String readExternalResource(String path) { - String content = ""; - try{ - content = new String ( Files.readAllBytes( Paths.get(path) ) ); - }catch (IOException e){ - logger.error("Exception while copying " + path + e.getMessage()); - } - return content; - } - - /** - * Code to unzip a file. Inspired from - * http://www.mkyong.com/java/how-to-decompress-files-from-a-zip-file/ Taken - * from - * - * @param resourceName - * @param outputFolder - */ - public static void unZipIt(String resourceName, String outputFolder) { - byte[] buffer = new byte[1024]; - - try { - ZipInputStream zis = new ZipInputStream(CreateResources.class.getResourceAsStream(resourceName)); - ZipEntry ze = zis.getNextEntry(); - - while (ze != null) { - String fileName = ze.getName(); - File newFile = new File(outputFolder, fileName); - if (!newFile.toPath().normalize().startsWith(outputFolder)) { - throw new RuntimeException("Bad zip entry"); - } - // System.out.println("file unzip : "+ newFile.getAbsoluteFile()); - if (ze.isDirectory()) { - String temp = newFile.getAbsolutePath(); - new File(temp).mkdirs(); - } else { - String directory = newFile.getParent(); - if (directory != null) { - File d = new File(directory); - if (!d.exists()) { - d.mkdirs(); - } - } - FileOutputStream fos = new FileOutputStream(newFile); - int len; - while ((len = zis.read(buffer)) > 0) { - fos.write(buffer, 0, len); - } - fos.close(); - } - ze = zis.getNextEntry(); - } - - zis.closeEntry(); - zis.close(); - - } catch (IOException ex) { - logger.error("Error while extracting the reosurces: " + ex.getMessage()); - } - - } public static void copy(InputStream is, File dest) throws Exception { - OutputStream os = null; - try { - os = new FileOutputStream(dest); - byte[] buffer = new byte[1024]; - int length; - while ((length = is.read(buffer)) > 0) { - os.write(buffer, 0, length); - } - } catch (Exception e) { - logger.error("Exception while copying resource. " + e.getMessage()); - throw e; - } finally { - if (is != null) - is.close(); - if (os != null) - os.close(); - } + try (OutputStream os = new FileOutputStream(dest)) { + byte[] buffer = new byte[1024]; + int length; + while ((length = is.read(buffer)) > 0) { + os.write(buffer, 0, length); + } + } catch (Exception e) { + logger.error("Exception while copying resource. " + e.getMessage()); + throw e; + } finally { + if (is != null) + is.close(); + } } public static String getValueAsLiteralOrURI(OWLAnnotationValue v) { diff --git a/src/main/resources/lode.zip b/src/main/resources/lode.zip deleted file mode 100644 index 02b46e6..0000000 Binary files a/src/main/resources/lode.zip and /dev/null differ diff --git a/src/main/resources/oops.zip b/src/main/resources/oops.zip deleted file mode 100644 index e2ac877..0000000 Binary files a/src/main/resources/oops.zip and /dev/null differ diff --git a/src/main/resources/webvowl_1.1.7.zip b/src/main/resources/webvowl_1.1.7.zip deleted file mode 100644 index b088fbc..0000000 Binary files a/src/main/resources/webvowl_1.1.7.zip and /dev/null differ diff --git a/src/test/java/widoco/CreateDocInThreadTest.java b/src/test/java/widoco/CreateDocInThreadTest.java index af05424..9c876cf 100644 --- a/src/test/java/widoco/CreateDocInThreadTest.java +++ b/src/test/java/widoco/CreateDocInThreadTest.java @@ -288,6 +288,34 @@ public void testIssue530() { fail("Error while running the test: " +e.getMessage()); } } + + /** + * Test to check if after the -noPlaceHolder flag is used, but the ontology has a custom intro + * the custom introduction annotation works correctly. + * Reference: https://github.com/dgarijo/Widoco/issues/658 + */ + @org.junit.Test + public void testIssue658() { + try { + String pathToOnto = "test" + File.separator + "medatatestont.ttl"; + c.setFromFile(true); + //emulating the flag "-noPlaceHolder" + c.setIncludeIntroduction(false); + c.setIncludeAbstract(false); + c.setIncludeDescription(false); + this.c.setOntologyPath(pathToOnto); + //read the model from file + WidocoUtils.loadModelToDocument(c); + c.loadPropertiesFromOntology(c.getMainOntology().getOWLAPIModel()); + //not needed, but added for consistency with the other tests. + CreateResources.generateDocumentation(c.getDocumentationURI(), c, c.getTmpFile()); + //read from myDoc/doc/sections/introduction.html + String result = WidocoUtils.readExternalResource("myDoc/doc/sections/introduction-en.html"); + assertTrue(result.contains("This is an intro")); + }catch(Exception e){ + fail("Error while running the test: " +e.getMessage()); + } + } // /** * This is a test to see if a big ontology works (several MB)