diff --git a/src/main/java/org/gcube/informationsystem/utils/documentation/DocumentationGenerator.java b/src/main/java/org/gcube/informationsystem/utils/documentation/DocumentationGenerator.java index 74d0db4..1f506e3 100644 --- a/src/main/java/org/gcube/informationsystem/utils/documentation/DocumentationGenerator.java +++ b/src/main/java/org/gcube/informationsystem/utils/documentation/DocumentationGenerator.java @@ -6,21 +6,92 @@ import java.util.Set; import org.gcube.informationsystem.types.reference.Type; import org.gcube.informationsystem.utils.discovery.Discovery; +import org.gcube.informationsystem.utils.documentation.rst.Section; +import org.gcube.informationsystem.utils.documentation.rst.Section.SectionType; +import org.gcube.informationsystem.utils.documentation.rst.table.Cell; +import org.gcube.informationsystem.utils.documentation.rst.table.Row; +import org.gcube.informationsystem.utils.documentation.rst.table.RowType; +import org.gcube.informationsystem.utils.documentation.rst.table.Table; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) */ public class DocumentationGenerator { + private static final Logger logger = LoggerFactory.getLogger(DocumentationGenerator.class); + protected File baseDirectory; public DocumentationGenerator(File baseDirectory) { this.baseDirectory = baseDirectory; } - public void generatePropertySection(Type type) { + /* + * E.g. GCubeProperty extends Property + */ + protected Row getTypeDeclaration(Type type) { + Row row = new Row(RowType.NORMAL); + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append("**"); + stringBuffer.append(type.getName()); + stringBuffer.append("**"); + stringBuffer.append(" *extends* "); + boolean first = true; + for(String superClass : type.getSuperClasses()) { + if(!first) { + stringBuffer.append(", "); + }else { + first = false; + } + stringBuffer.append("**"); + stringBuffer.append(superClass); + stringBuffer.append("**"); + } + Cell cell = new Cell(); + cell.setText(stringBuffer.toString()); + row.appendCell(cell); + row.appendCell(cell); + row.appendCell(cell); + row.appendCell(cell); + return row; + } + + public Row getPropertyHeadingRow() { + Row row = new Row(RowType.HEADING); + Cell name = new Cell(); + name.setText("Name"); + row.appendCell(name); + Cell type = new Cell(); + type.setText("Type"); + row.appendCell(type); + Cell attributes = new Cell(); + attributes.setText("Attributes"); + row.appendCell(attributes); + Cell description = new Cell(); + description.setText("Description"); + row.appendCell(description); + return row; + } + + public StringBuffer generatePropertySection(Type type) { + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append("\n"); + String name = type.getName(); + Section section = new Section(); + stringBuffer.append(section.generateSection(SectionType.HEADING_3, name)); + stringBuffer.append(type.getDescription()); + stringBuffer.append("\n"); + + Table table = new Table(); + table.appendRow(getTypeDeclaration(type)); + table.appendRow(getPropertyHeadingRow()); + stringBuffer.append(table.generateTable()); + logger.info(stringBuffer.toString()); + return stringBuffer; } public void generate() throws Exception { diff --git a/src/main/java/org/gcube/informationsystem/utils/documentation/rst/Section.java b/src/main/java/org/gcube/informationsystem/utils/documentation/rst/Section.java index 3b77623..3adf5bd 100644 --- a/src/main/java/org/gcube/informationsystem/utils/documentation/rst/Section.java +++ b/src/main/java/org/gcube/informationsystem/utils/documentation/rst/Section.java @@ -8,7 +8,7 @@ public class Section { public enum SectionType { HEADING_1(true, "*"), HEADING_2(false, "="), - HEADING_3(false, "_"), + HEADING_3(false, "-"), HEADING_4(false, "^"); boolean both; @@ -33,9 +33,12 @@ public class Section { int lenght = sectionTitle.length(); if(sectionType.both) { stringBuffer.append(getSectionSeparation(sectionType.separator, lenght)); + stringBuffer.append("\n"); } stringBuffer.append(sectionTitle); + stringBuffer.append("\n"); stringBuffer.append(getSectionSeparation(sectionType.separator, lenght)); + stringBuffer.append("\n\n"); return stringBuffer; }