From c21971160034d126938567a0b9006e0089d11b89 Mon Sep 17 00:00:00 2001 From: pmcb55 Date: Mon, 20 Sep 2021 11:32:18 +0100 Subject: [PATCH] Only show legend entries if relevant --- src/main/java/widoco/Constants.java | 50 ++++++++++++++++++----- src/main/java/widoco/CreateResources.java | 38 +++++++++++------ 2 files changed, 65 insertions(+), 23 deletions(-) diff --git a/src/main/java/widoco/Constants.java b/src/main/java/widoco/Constants.java index 1a2693a..2f9ddcb 100644 --- a/src/main/java/widoco/Constants.java +++ b/src/main/java/widoco/Constants.java @@ -1265,18 +1265,48 @@ public static String get406(Configuration c, Properties lang) { return page406; } - public static String getLegend(Properties lang) { + public static String getLegend( + Properties lang, + final boolean includesClass, + final boolean includesProperty, + final boolean includesDatatypeProperty, + final boolean includesAnnotation, + final boolean includesNamedIndividual) { + + // If our ontology is empty, then no point in a legend at all! + if (!includesClass && !includesProperty && !includesDatatypeProperty && + !includesAnnotation && !includesNamedIndividual) { + return ""; + } + + // TODO: Currently legend has no entry for Annotations - I don't know if this is intended or + // not ...? return "
\n" + "

" + lang.getProperty(Constants.LANG_LEGEND) + " " + lang.getProperty(Constants.LANG_BACK) - + " ToC

\n" + "
\n" - + "c: " - + lang.getProperty(Constants.LANG_CLASSES) + "
\n" + "op: " - + lang.getProperty(Constants.LANG_OBJ_PROP) + "
\n" + "dp: " - + lang.getProperty(Constants.LANG_DATA_PROP) + "
\n" + "ni: " - + lang.getProperty(Constants.LANG_NAMED_INDIV) + "\n" + "
\n" + "
"; + + " ToC\n" + + "
\n" + + (includesClass ? + "c: " + lang.getProperty(Constants.LANG_CLASSES) + "
\n" + : "") + + (includesProperty ? + "op: " + + lang.getProperty(Constants.LANG_OBJ_PROP) + "
\n" + : "") + + (includesDatatypeProperty ? + "dp: " + + lang.getProperty(Constants.LANG_DATA_PROP) + "
\n" + : "") + + (includesNamedIndividual ? + "ni: " + + lang.getProperty(Constants.LANG_NAMED_INDIV) + "\n" + : "") + + "
\n" + "" + + "\n"; } public static String getAnalyticsCode(String code) { diff --git a/src/main/java/widoco/CreateResources.java b/src/main/java/widoco/CreateResources.java index be4fabe..e4da0ea 100644 --- a/src/main/java/widoco/CreateResources.java +++ b/src/main/java/widoco/CreateResources.java @@ -306,28 +306,40 @@ private static String createDescriptionSection(String path, Configuration c, Pro private static String createCrossReferenceSection(String path, LODEParser lodeParser, Configuration c, Properties lang) { - // cross reference section has to be included always. + // Cross reference section has to be included always. String textToWrite = Constants.getCrossReferenceSectionTitleAndPlaceHolder(c, lang); + String classesList = lodeParser.getClassList(), propList = lodeParser.getPropertyList(), dataPropList = lodeParser.getDataPropList(), annotationPropList = lodeParser.getAnnotationPropList(), namedIndividualList = lodeParser.getNamedIndividualList(); - if (classesList != null && !"".equals(classesList)) { - textToWrite += lodeParser.getClasses(); + + final boolean includesClass = classesList != null && !"".equals(classesList); + final boolean includesProperty = propList != null && !"".equals(propList); + final boolean includesDatatypeProperty = dataPropList != null && !"".equals(dataPropList); + final boolean includesAnnotation = + c.isIncludeAnnotationProperties() && annotationPropList != null && !"".equals(annotationPropList); + final boolean includesNamedIndividual = + c.isIncludeNamedIndividuals() && namedIndividualList != null && !"".equals(namedIndividualList); + + if (includesClass) { + textToWrite += lodeParser.getClasses(); } - if (propList != null && !"".equals(propList)) { - textToWrite += lodeParser.getProperties(); + if (includesProperty) { + textToWrite += lodeParser.getProperties(); } - if (dataPropList != null && !"".equals(dataPropList)) { - textToWrite += lodeParser.getDataProp(); + if (includesDatatypeProperty) { + textToWrite += lodeParser.getDataProp(); } - if (c.isIncludeAnnotationProperties() && annotationPropList != null && !"".equals(annotationPropList)) { - textToWrite += lodeParser.getAnnotationProp(); + if (includesAnnotation) { + textToWrite += lodeParser.getAnnotationProp(); } - if (c.isIncludeNamedIndividuals() && namedIndividualList != null && !"".equals(namedIndividualList)) { - textToWrite += lodeParser.getNamedIndividuals(); + if (includesNamedIndividual) { + textToWrite += lodeParser.getNamedIndividuals(); } - // add legend - textToWrite += Constants.getLegend(lang) + "\n"; + + // Add legend (for ontology components actually used). + textToWrite += Constants.getLegend(lang, includesClass, includesProperty, + includesDatatypeProperty, includesAnnotation, includesNamedIndividual); if(!c.isIncludeAllSectionsInOneDocument()){ saveDocument(path + File.separator + "crossref-" + c.getCurrentLanguage() + ".html", textToWrite, c); }