use of com.twinsoft.convertigo.engine.dbo_explorer.DboParent in project convertigo by convertigo.
the class BeansDoc method createBeanElement.
private void createBeanElement(DboBean bean, boolean bEnable) throws Exception {
String databaseObjectClassName = bean.getClassName();
Class<?> databaseObjectClass = Class.forName(databaseObjectClassName);
DatabaseObject databaseObject = (DatabaseObject) databaseObjectClass.getConstructor().newInstance();
BeanInfo beanInfo = Introspector.getBeanInfo(databaseObjectClass);
BeanDescriptor databaseObjectBeanDescriptor = beanInfo.getBeanDescriptor();
String displayName = databaseObjectBeanDescriptor.getDisplayName();
String normalizedGroupName = normalize(groupName);
String normalizedCategoryName = normalize(categoryName);
String normalizedBeansCategoryName = normalize(beansCategoryName);
String normalizedName = normalize(displayName);
String path = (normalizedGroupName + "/" + normalizedCategoryName + "/" + normalizedBeansCategoryName + "/" + normalizedName).replaceAll("/+", "/");
String iconName = MySimpleBeanInfo.getIconName(beanInfo, BeanInfo.ICON_COLOR_32x32);
String iconPath = iconName.replaceFirst(".*/beans/", "");
try {
try (InputStream is = getClass().getResourceAsStream(iconName)) {
FileUtils.copyInputStreamToFile(is, new File(imageDirectory, iconPath));
}
} catch (Exception e) {
iconName = "/com/twinsoft/convertigo/beans/core/images/default_color_16x16.png";
iconPath = iconName.replaceFirst(".*/beans/", "");
try (InputStream is = getClass().getResourceAsStream(iconName)) {
FileUtils.copyInputStreamToFile(is, new File(imageDirectory, iconPath));
}
}
StringBuilder sb = new StringBuilder();
String permalink = "reference-manual/convertigo-objects/" + path + "/";
String metadesc = databaseObjectBeanDescriptor.getShortDescription();
metadesc = metadesc.replaceAll("<[a-zA-Z]*>|<\\/[a-zA-Z]*>|<br\\/>", " ");
metadesc = metadesc.replaceAll(":", " ");
metadesc = metadesc.replaceAll("\\|", " ");
if (metadesc.length() >= 150)
metadesc = metadesc.substring(0, 150);
sb.append("---\n" + "layout: page\n" + "title: " + displayName + "\n" + "sidebar: c8o_sidebar\n" + "permalink: " + permalink + "\n" + "metadesc: " + metadesc + "\n" + "ObjGroup: " + groupName + "\n" + "ObjCatName: " + normalizedBeansCategoryName + "\n" + "ObjName: " + displayName + "\n" + "ObjClass: " + databaseObjectClassName + "\n" + "ObjIcon: /images/beans/" + iconPath + "\n" + "topnav: topnavobj" + "\n" + "---\n");
if (bEnable) {
String description = databaseObjectBeanDescriptor.getShortDescription();
String shortDescription = description;
String longDescription = "";
Matcher mDescription = pDescription.matcher(description);
if (mDescription.matches()) {
shortDescription = mDescription.group(1);
if (mDescription.group(2) != null) {
longDescription = mDescription.group(2);
longDescription.replaceAll("\\n", "\n\n");
}
}
sb.append("##### " + shortDescription + "\n\n" + longDescription + "\n");
SortedMap<String, String> properties = new TreeMap<>();
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor databaseObjectPropertyDescriptor : propertyDescriptors) {
boolean skip = false;
longDescription = "";
// Don't display hidden property descriptors
if (databaseObjectPropertyDescriptor.isHidden()) {
skip = true;
}
Method getter = databaseObjectPropertyDescriptor.getReadMethod();
Method setter = databaseObjectPropertyDescriptor.getWriteMethod();
// Only display read/write property descriptors
if (getter == null || setter == null) {
skip = true;
}
String blackListedForParentClass = (String) databaseObjectPropertyDescriptor.getValue("blackListedForParentClass");
if (blackListedForParentClass != null) {
// check
for (DboParent parent : bean.getParents()) {
String parentName = parent.getClassName();
if (blackListedForParentClass.equals(parentName)) {
skip = true;
break;
}
}
}
if (skip) {
continue;
}
String category = "standard";
if (databaseObject instanceof ExtractionRule) {
category = "configuration";
if (databaseObjectPropertyDescriptor.isExpert()) {
category = "selection";
}
} else if (databaseObjectPropertyDescriptor.isExpert()) {
category = "expert";
}
description = databaseObjectPropertyDescriptor.getShortDescription();
mDescription = pDescription.matcher(description);
if (mDescription.matches()) {
description = mDescription.group(1).trim();
if (mDescription.group(2) != null) {
description += "<br/>" + mDescription.group(2).trim();
}
}
String type = databaseObjectPropertyDescriptor.getPropertyType().getSimpleName();
if ("true".equals("" + databaseObjectPropertyDescriptor.getValue("scriptable"))) {
type = "JS expression";
}
String propDisplayName = databaseObjectPropertyDescriptor.getDisplayName();
description = description.replace("|", "|");
String line = propDisplayName + " | " + type + " | " + category + " | " + description + "\n";
if (category.equals("standard")) {
category = "0";
}
properties.put(category + "_" + propDisplayName, line);
}
if (!properties.isEmpty()) {
sb.append("\nProperty | Type | Category | Description\n--- | --- | --- | ---\n");
for (String line : properties.values()) {
sb.append(line);
}
}
} else {
sb.append("##### Not yet documented.\nFor more information, do not hesitate to contact us in the forum in our Developer Network website: http://www.convertigo.com/itcenter.html\n");
}
String toWrite = sb.toString();
if (!"\n".equals(System.lineSeparator())) {
toWrite = toWrite.replace("\n", System.lineSeparator());
}
FileUtils.write(new File(outputDirectory, path + ".md"), toWrite, "UTF-8");
}
Aggregations