use of com.twinsoft.convertigo.beans.core.ExtractionRule in project convertigo by convertigo.
the class SiteClipperScreenClass method getRequestRules.
public List<IRequestRule> getRequestRules() {
List<ExtractionRule> rules = getExtractionRules();
List<IRequestRule> requestRules = new ArrayList<IRequestRule>(rules.size());
for (ExtractionRule rule : rules) {
if (rule instanceof IRequestRule) {
requestRules.add((IRequestRule) rule);
}
}
return requestRules;
}
use of com.twinsoft.convertigo.beans.core.ExtractionRule 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");
}
use of com.twinsoft.convertigo.beans.core.ExtractionRule in project convertigo by convertigo.
the class HtmlTransaction method addExtractionRuleShemas.
private void addExtractionRuleShemas(Map<String, String> names, Map<String, String> types, List<String> schemas, HtmlScreenClass screenClass) throws Exception {
HtmlExtractionRule htmlExtractionRule = null;
String typeSchema, typeName;
String erSchema, erSchemaEltName, erSchemaEltNSType;
Map<String, String> type;
if (screenClass != null) {
for (ExtractionRule extractionRule : screenClass.getExtractionRules()) {
htmlExtractionRule = (HtmlExtractionRule) extractionRule;
if (htmlExtractionRule.isEnabled()) {
erSchemaEltName = htmlExtractionRule.getSchemaElementName();
erSchemaEltNSType = htmlExtractionRule.getSchemaElementNSType("p_ns");
if (!names.containsKey(erSchemaEltName)) {
names.put(erSchemaEltName, erSchemaEltNSType);
} else {
typeSchema = (String) names.get(erSchemaEltName);
if (!typeSchema.equals(erSchemaEltNSType)) {
throw new Exception("Transaction may generate at least two extraction rules named '" + erSchemaEltName + "' with different type : '" + typeSchema + "' and '" + erSchemaEltNSType + "'.\nPlease correct by changing tagname or name if tagname is empty");
}
}
erSchema = htmlExtractionRule.getSchema("p_ns");
if (!schemas.contains(erSchema)) {
schemas.add(erSchema);
}
type = htmlExtractionRule.getSchemaTypes();
for (Entry<String, String> entry : type.entrySet()) {
typeName = entry.getKey();
typeSchema = entry.getValue();
types.put(typeName, typeSchema);
}
}
}
List<ScreenClass> visc = screenClass.getInheritedScreenClasses();
for (ScreenClass inheritedScreenClass : visc) {
addExtractionRuleShemas(names, types, schemas, (HtmlScreenClass) inheritedScreenClass);
}
}
}
use of com.twinsoft.convertigo.beans.core.ExtractionRule in project convertigo by convertigo.
the class SiteClipperScreenClass method getResponseRules.
public List<IResponseRule> getResponseRules() {
List<ExtractionRule> rules = getExtractionRules();
List<IResponseRule> responseRules = new ArrayList<IResponseRule>(rules.size());
for (ExtractionRule rule : rules) {
if (rule instanceof IResponseRule) {
responseRules.add((IResponseRule) rule);
}
}
return responseRules;
}
use of com.twinsoft.convertigo.beans.core.ExtractionRule in project convertigo by convertigo.
the class HtmlTransaction method applyExtractionRules.
public void applyExtractionRules(HtmlScreenClass screenClass, boolean bNotFirstLoop) throws EngineException {
String t = context.statistics.start(EngineStatistics.APPLY_EXTRACTION_RULES);
try {
// We apply the extraction rules for this screen class
int extractionRuleInitReason;
List<ExtractionRule> vExtractionRules = screenClass.getExtractionRules();
for (ExtractionRule extractionRule : vExtractionRules) {
HtmlExtractionRule htmlExtractionRule = (HtmlExtractionRule) extractionRule;
if (!runningThread.bContinue)
break;
if (!extractionRule.isEnabled()) {
Engine.logBeans.trace("(HtmlTransaction) Skipping the extraction rule \"" + extractionRule.getName() + "\" because it has been disabled.");
continue;
}
Engine.logBeans.debug("(HtmlTransaction) Applying the extraction rule \"" + extractionRule.getName() + "\"");
extractionRule.checkSymbols();
String extractionRuleQName = extractionRule.getQName();
if (vExtractionRulesInited.contains(extractionRuleQName)) {
extractionRuleInitReason = ExtractionRule.ACCUMULATING;
} else {
extractionRuleInitReason = ExtractionRule.INITIALIZING;
vExtractionRulesInited.add(extractionRuleQName);
}
Engine.logBeans.trace("(HtmlTransaction) Initializing extraction rule (reason = " + extractionRuleInitReason + ")...");
extractionRule.init(extractionRuleInitReason);
// We fire engine events only in studio mode.
if (Engine.isStudioMode()) {
Engine.theApp.fireObjectDetected(new EngineEvent(extractionRule));
}
boolean hasMatched = htmlExtractionRule.apply(currentXmlDocument, context);
if (hasMatched) {
htmlExtractionRule.addToScope(scope);
Engine.logBeans.trace("(HtmlTransaction) Applying extraction rule '" + extractionRule.getName() + "': matching");
} else
Engine.logBeans.trace("(HtmlTransaction) Applying extraction rule '" + extractionRule.getName() + "': not matching");
// We fire engine events only in studio mode.
if (Engine.isStudioMode()) {
Engine.logBeans.debug("(HtmlTransaction) Step reached after having applied the extraction rule \"" + extractionRule.getName() + "\".");
Engine.theApp.fireStepReached(new EngineEvent(extractionRule));
}
extractionRule = null;
}
vExtractionRules = null;
} finally {
context.statistics.stop(t, bNotFirstLoop);
}
}
Aggregations