com.gitee.easyopen.doc.ParamHtmlBuilder Maven / Gradle / Ivy
package com.gitee.easyopen.doc;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
/**
* @author tanghc
*/
public class ParamHtmlBuilder {
private static final String START_TD = "";
private static final String END_TD = " ";
private static final String START_TR = "";
private static final String END_TR = " ";
private static final String TRUE = "true";
public String buildHtml(ApiDocFieldDefinition definition, String nameVersion) {
StringBuilder html = new StringBuilder();
html.append(START_TR)
.append(wrapTD(definition.getName()))
.append(""+definition.getDataType() + END_TD)
.append(wrapTD(this.getRequireHtml(definition)))
.append(wrapTD(buildExample(definition, nameVersion, null)))
.append(wrapTD(definition.getDescription()));
html.append(END_TR);
return html.toString();
}
private String wrapTD(String content) {
return START_TD + content + END_TD;
}
protected String buildExample(ApiDocFieldDefinition definition, String nameVersion, ApiDocFieldDefinition parentDefinition) {
StringBuilder html = new StringBuilder();
if(CollectionUtils.isNotEmpty(definition.getElements())) {
html.append("")
.append(START_TR)
.append("名称 ")
.append("类型 ")
.append("是否必须 ")
.append("示例值 ")
.append("描述 ")
.append(END_TR);
List els = definition.getElements();
for (ApiDocFieldDefinition apiDocFieldDefinition : els) {
html.append(START_TR)
.append(wrapTD(apiDocFieldDefinition.getName()))
.append(""+apiDocFieldDefinition.getDataType() + END_TD)
.append(wrapTD(getRequireHtml(apiDocFieldDefinition)))
.append(wrapTD(buildExample(apiDocFieldDefinition, nameVersion, definition)))
.append(wrapTD(apiDocFieldDefinition.getDescription()))
.append(END_TR);
}
html.append("
");
}else{
html.append(buildExampleValue(definition, nameVersion, parentDefinition));
}
return html.toString();
}
private String getRequireHtml(ApiDocFieldDefinition definition) {
if(TRUE.equals(definition.getRequired())) {
return "是";
}else{
return "否";
}
}
protected String buildExampleValue(ApiDocFieldDefinition definition, String nameVersion, ApiDocFieldDefinition parentDefinition) {
String parentname = (parentDefinition == null ? "" : parentDefinition.getName());
String type = "text";
if(definition.getDataType().equals(DataType.FILE.getValue())
|| definition.getElementClass() == MultipartFile.class) {
type = "file";
}
String id = nameVersion + "_" + definition.getName();
StringBuilder sb = new StringBuilder();
sb.append("")
.append(this.getAddBtn(definition))
;
return sb.toString();
}
protected String getArrAttr(ApiDocFieldDefinition definition) {
if(definition.getDataType().equals(DataType.ARRAY.getValue())) {
return " arrinput=\"true\" ";
} else {
return "";
}
}
protected String getDateEvent(ApiDocFieldDefinition definition) {
if(definition.getDataType().equals(DataType.DATE.getValue())) {
return " onClick=\"WdatePicker({el:this,dateFmt:'yyyy-MM-dd'})\"";
} else if(definition.getDataType().equals(DataType.DATETIME.getValue())) {
return " onClick=\"WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})\"";
}else {
return "";
}
}
protected String getAddBtn(ApiDocFieldDefinition definition) {
if(definition.getDataType().equals(DataType.ARRAY.getValue())) {
return " "
+ " ";
} else {
return "";
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy