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

46 lines
1.1 KiB
Java

package org.gcube.informationsystem.utils.documentation.rst;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class Section {
public enum SectionType {
HEADING_1(true, "*"),
HEADING_2(false, "="),
HEADING_3(false, "-"),
HEADING_4(false, "^");
boolean both;
String separator;
private SectionType(boolean both, String separator) {
this.both = both;
this.separator = separator;
}
}
protected StringBuffer getSectionSeparation(String separator, int lenght) {
StringBuffer stringBuffer = new StringBuffer();
for(int i=0; i<lenght; i++) {
stringBuffer.append(separator);
}
return stringBuffer;
}
public StringBuffer generateSection(SectionType sectionType, String sectionTitle) {
StringBuffer stringBuffer = new StringBuffer();
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;
}
}