information-system-model-do.../src/main/java/org/gcube/informationsystem/utils/documentation/rst/Section.java

66 lines
1.5 KiB
Java
Raw Normal View History

2022-12-13 10:29:52 +01:00
package org.gcube.informationsystem.utils.documentation.rst;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class Section {
public enum SectionType {
2023-01-22 19:44:32 +01:00
HEADING_1(true, "#"),
HEADING_2(true, "*"),
HEADING_3(false, "="),
HEADING_4(false, "-"),
HEADING_5(false, "^"),
HEADING_6(false, "\"");
2022-12-13 10:29:52 +01:00
2023-01-22 19:44:32 +01:00
boolean overline;
2022-12-13 10:29:52 +01:00
String separator;
2023-01-22 19:44:32 +01:00
private SectionType(boolean overline, String separator) {
this.overline = overline;
2022-12-13 10:29:52 +01:00
this.separator = separator;
}
}
2023-01-24 16:54:00 +01:00
protected SectionType sectionType;
public Section() {
this.sectionType = SectionType.HEADING_1;
}
public Section(SectionType sectionType) {
this.sectionType = sectionType;
}
public SectionType getSectionType() {
return sectionType;
}
public void setSectionType(SectionType sectionType) {
this.sectionType = sectionType;
}
2022-12-13 10:29:52 +01:00
protected StringBuffer getSectionSeparation(String separator, int lenght) {
StringBuffer stringBuffer = new StringBuffer();
for(int i=0; i<lenght; i++) {
stringBuffer.append(separator);
}
return stringBuffer;
}
2023-01-24 16:54:00 +01:00
public StringBuffer generate(String sectionTitle) {
2022-12-13 10:29:52 +01:00
StringBuffer stringBuffer = new StringBuffer();
int lenght = sectionTitle.length();
2023-01-22 19:44:32 +01:00
if(sectionType.overline) {
2022-12-13 10:29:52 +01:00
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;
}
}