Search in sources :

Example 6 with EngineEvent

use of com.twinsoft.convertigo.engine.EngineEvent in project convertigo by convertigo.

the class HtmlConnectorDesignComposite method checkEventSource.

private boolean checkEventSource(EventObject event) {
    boolean isSourceFromConnector = false;
    Object source = event.getSource();
    if (event instanceof EngineEvent) {
        if (source instanceof DatabaseObject) {
            Connector connector = ((DatabaseObject) source).getConnector();
            if ((connector != null) && (connector.equals(htmlConnector)))
                isSourceFromConnector = true;
        }
    }
    return isSourceFromConnector;
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) EventObject(java.util.EventObject) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject)

Example 7 with EngineEvent

use of com.twinsoft.convertigo.engine.EngineEvent in project convertigo by convertigo.

the class HtmlConnectorDesignComposite method createScreenClassFromSelection.

public void createScreenClassFromSelection() throws EngineException {
    String className = "com.twinsoft.convertigo.beans.core.ScreenClass";
    // Retrieve selected criteria xpath
    String criteriaXpath = xpathEvaluator.getSelectionXpath();
    // Retrieve parent ScreenClass
    HtmlScreenClass parentObject = getParentHtmlScreenClass();
    NewObjectWizard newObjectWizard = new NewObjectWizard(parentObject, className);
    WizardDialog wzdlg = new WizardDialog(Display.getCurrent().getActiveShell(), newObjectWizard);
    wzdlg.setPageSize(850, 650);
    wzdlg.open();
    if (wzdlg.getReturnCode() != Window.CANCEL) {
        HtmlScreenClass htmlScreenClass = (HtmlScreenClass) newObjectWizard.newBean;
        if (htmlScreenClass != null) {
            String screenClassName = htmlScreenClass.getName();
            // Add criteria to screen class
            createCriteria(htmlScreenClass, criteriaXpath);
            // Set detected ScreenClass to newly created one
            if (htmlConnector.isLearning()) {
                detectedScreenClass = htmlScreenClass;
                ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) Detected screen class is set to newly created one named '" + screenClassName + "'");
            } else {
                ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) New screen class named '" + screenClassName + "' has been added");
            }
            // Reload parent ScreenClass in Tree
            fireObjectChanged(new CompositeEvent(parentObject));
            // Set selection on newly created screenclass
            fireObjectSelected(new CompositeEvent(htmlScreenClass));
            // Highlight new detected ScreenClass in Tree
            if (htmlConnector.isLearning())
                Engine.theApp.fireObjectDetected(new EngineEvent(htmlScreenClass));
        // TODO:toolScreenclass.setEnabled(false);
        }
    }
}
Also used : EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) HtmlScreenClass(com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass) NewObjectWizard(com.twinsoft.convertigo.eclipse.wizards.new_object.NewObjectWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent)

Example 8 with EngineEvent

use of com.twinsoft.convertigo.engine.EngineEvent in project convertigo by convertigo.

the class ConnectorEditorPart method checkEventSource.

private boolean checkEventSource(EventObject event) {
    boolean isSourceFromConnector = false;
    if (event instanceof RequestableEngineEvent) {
        RequestableEngineEvent requestableEvent = (RequestableEngineEvent) event;
        String connectorName = requestableEvent.getConnectorName();
        if (connectorName != null) {
            if (connectorName.equals(connector.getName()) && requestableEvent.getProjectName().equals(connector.getProject().getName())) {
                isSourceFromConnector = true;
            }
        }
    } else if (event instanceof EngineEvent) {
        Object ob = ((EngineEvent) event).getSource();
        if (ob instanceof DatabaseObject) {
            try {
                String projectName = ((DatabaseObject) ob).getProject().getName();
                String connectorName = ((DatabaseObject) ob).getConnector().getName();
                if (connectorName.equals(connector.getName()) && projectName.equals(connector.getProject().getName())) {
                    isSourceFromConnector = true;
                }
            } catch (Exception e) {
            }
        }
    }
    return isSourceFromConnector;
}
Also used : RequestableEngineEvent(com.twinsoft.convertigo.engine.RequestableEngineEvent) RequestableEngineEvent(com.twinsoft.convertigo.engine.RequestableEngineEvent) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) EventObject(java.util.EventObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) KeyExpiredException(com.twinsoft.convertigo.engine.KeyExpiredException) MaxCvsExceededException(com.twinsoft.convertigo.engine.MaxCvsExceededException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException)

Example 9 with EngineEvent

use of com.twinsoft.convertigo.engine.EngineEvent in project convertigo by convertigo.

the class HtmlConnectorDesignComposite method modelChanged.

public void modelChanged(HttpProxyEvent event) {
    if (!checkProxySource(event)) {
        return;
    }
    String requestString = event.getRequest();
    String responseString = event.getResponse();
    boolean https = event.isHttps();
    int status = Integer.parseInt(event.getStatus());
    // do not record client redirection
    if ((status == HttpStatus.SC_MOVED_TEMPORARILY) || (status == HttpStatus.SC_MOVED_PERMANENTLY) || (status == HttpStatus.SC_SEE_OTHER) || (status == HttpStatus.SC_TEMPORARY_REDIRECT)) {
        return;
    }
    /*if (requestString.indexOf(getServer()) == -1) {
			return;
		}*/
    Map<String, String> headers = parseResponseString(responseString);
    String contentType = headers.get(HeaderName.ContentType.value().toLowerCase());
    // record only text/html or null Content-Type ...
    if (contentType == null) {
        return;
    }
    if (MimeType.Html.is(contentType) && MimeType.Plain.is(contentType)) {
        return;
    }
    ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) Learning statement...");
    try {
        String url, method, handlerName, transactionName, statementName, scHandlerName;
        String normalizedScreenClassName, screenClassName;
        HtmlTransaction htmlTransaction = null;
        HTTPStatement httpStatement = null;
        HtmlScreenClass htmlScreenClass = null;
        HandlerStatement handlerStatement = null;
        ScHandlerStatement scHandlerStatement = null;
        // Document dom = null;
        // Log log = null;
        int size, index1;
        boolean bContinue;
        index1 = 0;
        bContinue = true;
        normalizedScreenClassName = "Unknown";
        htmlTransaction = (HtmlTransaction) htmlConnector.getLearningTransaction();
        synchronized (htmlConnector) {
            // dom = htmlConnector.getCurrentXmlDocument();
            htmlScreenClass = htmlConnector.getCurrentScreenClass();
        }
        screenClassName = htmlScreenClass.getName();
        normalizedScreenClassName = StringUtils.normalize(htmlScreenClass.getName());
        ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) current screen class is '" + screenClassName + "'");
        if (htmlTransaction != null) {
            transactionName = htmlTransaction.getName();
            ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) creating new HTTPStatement");
            ConvertigoPlugin.logDebug2(requestString);
            httpStatement = parseRequestString(requestString);
            httpStatement.setHttps(https);
            httpStatement.setPort(https ? 443 : 80);
            method = httpStatement.getMethod().toLowerCase();
            // size = httpStatement.getVariablesDefinitionSize();
            size = httpStatement.numberOfVariables();
            url = httpStatement.getUrl(htmlConnector.isHttps(), htmlConnector.getServer(), htmlConnector.getPort());
            while (bContinue) {
                statementName = method + ((index1 == 0) ? " " : " " + index1) + " (" + url + " - " + size + ")";
                statementName = StringUtils.normalize(statementName);
                httpStatement.setName(statementName);
                httpStatement.hasChanged = true;
                httpStatement.bNew = true;
                if (htmlScreenClass == null) {
                    try {
                        httpStatement.priority = 0;
                        htmlTransaction.addStatement(httpStatement);
                        ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new HTTPStatement to default transaction '" + transactionName + "'");
                        fireObjectChanged(new CompositeEvent(htmlTransaction));
                        Engine.theApp.fireObjectDetected(new EngineEvent(httpStatement));
                        bContinue = false;
                    } catch (ObjectWithSameNameException owsne) {
                        index1++;
                    }
                } else {
                    if (htmlConnector.isAccumulating())
                        handlerName = "on" + normalizedScreenClassName + "Exit";
                    else
                        handlerName = "on" + normalizedScreenClassName + "Entry";
                    handlerStatement = htmlTransaction.getHandlerStatement(handlerName);
                    if (handlerStatement != null) {
                        try {
                            handlerStatement.addStatement(httpStatement);
                            ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new HTTPStatement to handler '" + handlerName + "' of transaction '" + transactionName + "'");
                            fireObjectChanged(new CompositeEvent(handlerStatement));
                            Engine.theApp.fireObjectDetected(new EngineEvent(httpStatement));
                            bContinue = false;
                        } catch (ObjectWithSameNameException owsne) {
                            index1++;
                        }
                    } else {
                        try {
                            if (htmlConnector.isAccumulating())
                                scHandlerStatement = new ScExitHandlerStatement(normalizedScreenClassName);
                            else
                                scHandlerStatement = new ScEntryHandlerStatement(normalizedScreenClassName);
                            scHandlerName = scHandlerStatement.getName();
                            scHandlerStatement.setName(scHandlerName);
                            scHandlerStatement.hasChanged = true;
                            scHandlerStatement.bNew = true;
                            scHandlerStatement.priority = 0;
                            htmlTransaction.addStatement(scHandlerStatement);
                            ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new ScExitHandlerStatement '" + handlerName + "' of transaction '" + transactionName + "'");
                            try {
                                scHandlerStatement.addStatement(httpStatement);
                                ConvertigoPlugin.logDebug2("(HtmlConnectorDesignComposite) added new HTTPStatement '" + statementName + "' to ScExitHandlerStatement '" + handlerName + "'");
                                fireObjectChanged(new CompositeEvent(htmlTransaction));
                                Engine.theApp.fireObjectDetected(new EngineEvent(httpStatement));
                                bContinue = false;
                            } catch (ObjectWithSameNameException owsne) {
                                index1++;
                            }
                        }// Should not append
                         catch (ObjectWithSameNameException owsne) {
                            throw new EngineException(owsne.getMessage());
                        }
                    }
                }
            }
        } else {
            throw new EngineException("Found none learning transaction");
        }
    } catch (EngineException e) {
        ConvertigoPlugin.logException(e, "An exception occured while learning");
    }
}
Also used : HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) EngineException(com.twinsoft.convertigo.engine.EngineException) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) HtmlScreenClass(com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement)

Example 10 with EngineEvent

use of com.twinsoft.convertigo.engine.EngineEvent in project convertigo by convertigo.

the class Statement method execute.

public boolean execute(org.mozilla.javascript.Context javascriptContext, org.mozilla.javascript.Scriptable scope) throws EngineException {
    reset();
    HtmlTransaction htmlTransaction = (HtmlTransaction) getParentTransaction();
    if (isEnabled && htmlTransaction.runningThread.bContinue) {
        htmlTransaction.currentStatement = this;
        Engine.logBeans.debug("Executing statement named '" + this.getName() + "' (" + this.getClass().getName() + ")");
        // We fire engine events only in studio mode.
        if (Engine.isStudioMode()) {
            Engine.theApp.fireObjectDetected(new EngineEvent(this));
        }
        return true;
    }
    return false;
}
Also used : HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent)

Aggregations

EngineEvent (com.twinsoft.convertigo.engine.EngineEvent)19 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)5 EngineException (com.twinsoft.convertigo.engine.EngineException)5 EventObject (java.util.EventObject)5 RequestableEngineEvent (com.twinsoft.convertigo.engine.RequestableEngineEvent)4 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)3 Step (com.twinsoft.convertigo.beans.core.Step)3 ConnectorEditor (com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor)3 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)3 Javelin (com.twinsoft.twinj.Javelin)3 IOException (java.io.IOException)3 JSONException (org.codehaus.jettison.json.JSONException)3 Cursor (org.eclipse.swt.graphics.Cursor)3 Display (org.eclipse.swt.widgets.Display)3 Shell (org.eclipse.swt.widgets.Shell)3 PanelBlockFactory (com.twinsoft.convertigo.beans.common.PanelBlockFactory)2 XMLRectangle (com.twinsoft.convertigo.beans.common.XMLRectangle)2 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)2 Connector (com.twinsoft.convertigo.beans.core.Connector)2 ExtractionRule (com.twinsoft.convertigo.beans.core.ExtractionRule)2