Search in sources :

Example 6 with ExtractionRule

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;
}
Also used : ArrayList(java.util.ArrayList) ExtractionRule(com.twinsoft.convertigo.beans.core.ExtractionRule) IRequestRule(com.twinsoft.convertigo.beans.extractionrules.siteclipper.IRequestRule)

Example 7 with ExtractionRule

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("|", "&#124;");
            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");
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) Matcher(java.util.regex.Matcher) InputStream(java.io.InputStream) BeanInfo(java.beans.BeanInfo) MySimpleBeanInfo(com.twinsoft.convertigo.beans.core.MySimpleBeanInfo) ExtractionRule(com.twinsoft.convertigo.beans.core.ExtractionRule) Method(java.lang.reflect.Method) TreeMap(java.util.TreeMap) IOException(java.io.IOException) BeanDescriptor(java.beans.BeanDescriptor) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) File(java.io.File) DboParent(com.twinsoft.convertigo.engine.dbo_explorer.DboParent)

Example 8 with ExtractionRule

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);
        }
    }
}
Also used : ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) HtmlScreenClass(com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass) ExtractionRule(com.twinsoft.convertigo.beans.core.ExtractionRule) HtmlExtractionRule(com.twinsoft.convertigo.beans.extractionrules.HtmlExtractionRule) HtmlExtractionRule(com.twinsoft.convertigo.beans.extractionrules.HtmlExtractionRule) EngineException(com.twinsoft.convertigo.engine.EngineException) EvaluatorException(org.mozilla.javascript.EvaluatorException) JavaScriptException(org.mozilla.javascript.JavaScriptException) IOException(java.io.IOException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException)

Example 9 with ExtractionRule

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;
}
Also used : IResponseRule(com.twinsoft.convertigo.beans.extractionrules.siteclipper.IResponseRule) ArrayList(java.util.ArrayList) ExtractionRule(com.twinsoft.convertigo.beans.core.ExtractionRule)

Example 10 with ExtractionRule

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);
    }
}
Also used : EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) ExtractionRule(com.twinsoft.convertigo.beans.core.ExtractionRule) HtmlExtractionRule(com.twinsoft.convertigo.beans.extractionrules.HtmlExtractionRule) HtmlExtractionRule(com.twinsoft.convertigo.beans.extractionrules.HtmlExtractionRule)

Aggregations

ExtractionRule (com.twinsoft.convertigo.beans.core.ExtractionRule)15 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)6 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)5 BlockFactory (com.twinsoft.convertigo.beans.core.BlockFactory)4 Criteria (com.twinsoft.convertigo.beans.core.Criteria)4 Sheet (com.twinsoft.convertigo.beans.core.Sheet)4 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)4 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)4 IOException (java.io.IOException)4 Connector (com.twinsoft.convertigo.beans.core.Connector)3 Pool (com.twinsoft.convertigo.beans.core.Pool)3 Sequence (com.twinsoft.convertigo.beans.core.Sequence)3 Statement (com.twinsoft.convertigo.beans.core.Statement)3 Step (com.twinsoft.convertigo.beans.core.Step)3 TestCase (com.twinsoft.convertigo.beans.core.TestCase)3 Transaction (com.twinsoft.convertigo.beans.core.Transaction)3 Variable (com.twinsoft.convertigo.beans.core.Variable)3 JavelinScreenClass (com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass)3 EngineException (com.twinsoft.convertigo.engine.EngineException)3 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)2