125 lines
3.6 KiB
Java
125 lines
3.6 KiB
Java
package org.gcube.informationsystem.utils.documentation;
|
|
|
|
import java.io.File;
|
|
import java.util.Map;
|
|
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;
|
|
}
|
|
|
|
/*
|
|
* 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 {
|
|
|
|
DocumentationSchemaAction schemaAction = new DocumentationSchemaAction();
|
|
Discovery.discover(schemaAction);
|
|
|
|
Map<String, Type> propertyElements = schemaAction.getPropertyElement();
|
|
Set<String> propertyNames = propertyElements.keySet();
|
|
for(String name : propertyNames) {
|
|
Type type = propertyElements.get(name);
|
|
|
|
}
|
|
|
|
Map<String, Type> relationElements = schemaAction.getRelationElements();
|
|
Set<String> relationNames = relationElements.keySet();
|
|
for(String name : relationNames) {
|
|
Type type = propertyElements.get(name);
|
|
|
|
}
|
|
|
|
Map<String, Type> entityElements = schemaAction.getEntityElement();
|
|
Set<String> entityNames = entityElements.keySet();
|
|
for(String name : entityNames) {
|
|
Type type = propertyElements.get(name);
|
|
|
|
}
|
|
|
|
}
|
|
}
|