Search in sources :

Example 1 with EngineEvent

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

the class HtmlTransaction method runCore.

@Override
public void runCore() throws EngineException {
    try {
        HtmlConnector connector = (HtmlConnector) parent;
        vExtractionRulesInited = new LinkedList<String>();
        if (!runningThread.bContinue) {
            return;
        }
        if (isStateFull() || connector.getHtmlParser().isConnected()) {
            alreadyConnected = true;
        }
        if (!alreadyConnected) {
            connector.setCurrentXmlDocument(null);
            applyUserRequest(connector);
        } else {
            setCurrentXmlDocument(connector.getHtmlParser().getDom(context));
        }
        if (bDispatching) {
            applyUserEvents();
        }
        bNotFirstLoop1 = false;
        bNotFirstLoop2 = false;
        if (!runningThread.bContinue) {
            return;
        }
        if (isContentTypeHTML()) {
            latestCalledHandler = null;
            do {
                do {
                    String t = context.statistics.start(EngineStatistics.GET_CURRENT_SCREEN_CLASS);
                    try {
                        screenClass = ((HtmlConnector) connector).getCurrentScreenClass();
                        normalizedScreenClassName = StringUtils.normalize(screenClass.getName());
                        context.lastDetectedObject = screenClass;
                        score += 1;
                        Engine.logBeans.info("Detected screen class: '" + screenClass.getName() + "'");
                        // We fire engine events only in studio mode.
                        if (Engine.isStudioMode()) {
                            Engine.theApp.fireObjectDetected(new EngineEvent(screenClass));
                        }
                    } finally {
                        context.statistics.stop(t, bNotFirstLoop1);
                    }
                    // We execute the entry handler for the detected screen class
                    executeHandler(EVENT_ENTRY_HANDLER, ((RequestableThread) Thread.currentThread()).javascriptContext);
                    bNotFirstLoop1 = true;
                    // while re detecting, a new page could be loaded by async client javascript, if this happens,
                    // we refresh our current dom. Normally this is done by each statement, refreshing the dom here seems to be useless
                    // except in the case explained above. We rely on the the DOM cache to speed up things as the
                    // isDirty flag would not be set in most of the cases
                    setCurrentXmlDocument(connector.getHtmlParser().getDom(context));
                } while (runningThread.bContinue && (handlerResult.equalsIgnoreCase(RETURN_REDETECT)));
                if (!handlerResult.equalsIgnoreCase(RETURN_SKIP)) {
                    // We fire engine events only in studio mode.
                    if (Engine.isStudioMode()) {
                    // Engine.theApp.fireObjectDetected(new EngineEvent(blockFactory));
                    }
                    if (!runningThread.bContinue) {
                        return;
                    }
                    if (currentXmlDocument == null) {
                        throw new EngineException(alreadyConnected ? "Connector did not reconnect, please verify transaction statefull mode." : "" + " Current document is null. Cannot apply extraction rules.");
                    }
                    applyExtractionRules(screenClass, bNotFirstLoop2);
                    Engine.logBeans.debug("(HtmlTransaction) Extraction rules executed ...");
                }
                if (!runningThread.bContinue) {
                    return;
                }
                // We execute the exit handler for the current screen class
                executeHandler(EVENT_EXIT_HANDLER, ((RequestableThread) Thread.currentThread()).javascriptContext);
                bNotFirstLoop2 = true;
            } while (runningThread.bContinue && (handlerResult.equalsIgnoreCase(RETURN_ACCUMULATE)));
            if (!runningThread.bContinue) {
                return;
            }
        } else if (currentXmlDocument != null) {
            XMLUtils.copyDocument(currentXmlDocument, context.outputDocument);
        } else {
            throw new EngineException("Connector doesn't retrieve xmlizable content. Verify your url.");
        }
    } finally {
        alreadyConnected = false;
        // restoreVariablesDefinition();
        restoreVariables();
        if ((runningThread == null) || (!runningThread.bContinue)) {
            Engine.logBeans.warn("(HtmlTransaction) The transaction \"" + getName() + "\" has been successfully interrupted.");
        } else {
            Engine.logBeans.debug("(HtmlTransaction) The transaction \"" + getName() + "\" has successfully finished.");
        }
    }
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) EngineException(com.twinsoft.convertigo.engine.EngineException) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent)

Example 2 with EngineEvent

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

the class JavelinTransaction method runCore.

public void runCore() throws EngineException {
    try {
        JavelinConnector connector = (JavelinConnector) parent;
        Javelin javelin = ((JavelinConnector) connector).javelin;
        vExtractionRulesInited = new ArrayList<String>(32);
        boolean bDocumentLogScreenDumps = (EnginePropertiesManager.getProperty(PropertyName.DOCUMENT_LOG_SCREEN_DUMPS).equals("true") ? true : false);
        if (handlerResult.equalsIgnoreCase(RETURN_CANCEL)) {
            // must detect screen class before exit
            String t = context.statistics.start(EngineStatistics.GET_CURRENT_SCREEN_CLASS);
            try {
                /*
					if ((Engine.objectsProvider == null) && !javelin.isConnected()) {
						throw new ConnectionException("The emulator has been disconnected! See the emulator logs for more details...");
					}
					*/
                screenClass = ((JavelinConnector) connector).getCurrentScreenClass();
                normalizedScreenClassName = StringUtils.normalize(screenClass.getName());
                context.lastDetectedObject = screenClass;
                score += 1;
                // for compatibility with older javelin projects, set the legacy lastDetectedScreenClass context property
                context.lastDetectedScreenClass = screenClass;
                Engine.logContext.info("Detected screen class: '" + screenClass.getName() + "'");
                if (bDocumentLogScreenDumps) {
                    StringBuffer screenDump = new StringBuffer("");
                    int sw = javelin.getScreenWidth();
                    int sh = javelin.getScreenHeight();
                    for (int i = 0; i < sh; i++) {
                        screenDump.append(javelin.getString(0, i, sw) + "\n");
                    }
                    Engine.logContext.info("Screen dump for screen class '" + screenClass.getName() + "':\n" + screenDump.toString());
                }
                // We fire engine events only in studio mode.
                if (Engine.isStudioMode()) {
                    Engine.theApp.fireObjectDetected(new EngineEvent(screenClass));
                }
                return;
            } finally {
                context.statistics.stop(t, bNotFirstLoop1);
            }
        }
        if (!handlerResult.equalsIgnoreCase(RETURN_BYPASS)) {
            applyUserRequest(javelin);
        }
        blocks = new ArrayList<Collection<Block>>(16);
        bNotFirstLoop1 = false;
        bNotFirstLoop2 = false;
        if (!runningThread.bContinue) {
            return;
        }
        do {
            do {
                String t = context.statistics.start(EngineStatistics.GET_CURRENT_SCREEN_CLASS);
                try {
                    /*
    					if ((Engine.objectsProvider == null) && !javelin.isConnected()) {
    						throw new ConnectionException("The emulator has been disconnected! See the emulator logs for more details...");
    					}
    					*/
                    screenClass = (JavelinScreenClass) ((JavelinConnector) connector).getCurrentScreenClass();
                    if (screenClass == null) {
                        throw new EngineException("(JavelinTransaction) The currentScreenClass is null, is the emulator connected ?");
                    }
                    normalizedScreenClassName = StringUtils.normalize(screenClass.getName());
                    context.lastDetectedObject = screenClass;
                    score += 1;
                    // for compatibility with older javelin projects, set the legacy lastDetectedScreenClass context property
                    context.lastDetectedScreenClass = screenClass;
                    Engine.logContext.info("Detected screen class: '" + screenClass.getName() + "'");
                    if (bDocumentLogScreenDumps) {
                        StringBuffer screenDump = new StringBuffer("");
                        int sw = javelin.getScreenWidth();
                        int sh = javelin.getScreenHeight();
                        for (int i = 0; i < sh; i++) {
                            screenDump.append(javelin.getString(0, i, sw) + "\n");
                        }
                        Engine.logContext.info("Screen dump for screen class '" + screenClass.getName() + "':\n" + screenDump.toString());
                    }
                    // We fire engine events only in studio mode.
                    if (Engine.isStudioMode()) {
                        Engine.theApp.fireObjectDetected(new EngineEvent(screenClass));
                    }
                } finally {
                    context.statistics.stop(t, bNotFirstLoop1);
                }
                // We execute the entry handler for the detected screen class
                executeHandler(EVENT_ENTRY_HANDLER, ((RequestableThread) Thread.currentThread()).javascriptContext);
                bNotFirstLoop1 = true;
            } while (runningThread.bContinue && (handlerResult.equalsIgnoreCase(RETURN_REDETECT)));
            if (!handlerResult.equalsIgnoreCase(RETURN_SKIP)) {
                BlockFactory blockFactory = screenClass.getBlockFactory();
                // We fire engine events only in studio mode.
                if (Engine.isStudioMode()) {
                    Engine.theApp.fireObjectDetected(new EngineEvent(blockFactory));
                }
                if (!runningThread.bContinue) {
                    return;
                }
                applyBlockFactory(screenClass, blockFactory, javelin, bNotFirstLoop2);
                Engine.logContext.debug("(JavelinTransaction) Block factory executed...");
                if (!runningThread.bContinue) {
                    return;
                }
                // first extraction rules execution on the block factory
                applyExtractionRules(screenClass, blockFactory, javelin, bNotFirstLoop2);
                if (executeExtractionRulesInPanels) {
                    // search panels and apply extraction rules on their content blocks
                    searchPanelsAndApplyExtractionRules(screenClass, blockFactory, javelin, bNotFirstLoop2);
                }
                Engine.logContext.debug("(JavelinTransaction) Extraction rules executed ...");
                blocks.add(blockFactory.getAllBlocks());
                Engine.logContext.debug("(JavelinTransaction) Blocks added to output");
            }
            if (!runningThread.bContinue) {
                return;
            }
            // We execute the exit handler for the current screen class
            executeHandler(EVENT_EXIT_HANDLER, ((RequestableThread) Thread.currentThread()).javascriptContext);
            bNotFirstLoop2 = true;
        } while (runningThread.bContinue && (handlerResult.equalsIgnoreCase(RETURN_ACCUMULATE)));
        if (!runningThread.bContinue) {
            return;
        }
        // Adding screen resolution information and cursor position information to the XML document
        Element documentElement = context.outputDocument.getDocumentElement();
        documentElement.setAttribute("screenWidth", Integer.toString(javelin.getScreenWidth()));
        documentElement.setAttribute("screenHeight", Integer.toString(javelin.getScreenHeight()));
        documentElement.setAttribute("cursorLine", Integer.toString(javelin.getCurrentLine()));
        documentElement.setAttribute("cursorColumn", Integer.toString(javelin.getCurrentColumn()));
        // Generating the blocks XML tags
        renderBlocksToXml(blocks);
        // and move all sub blocks node to the root element.
        if (isRemoveBlocksNode()) {
            NodeList childNodes = documentElement.getChildNodes();
            int len = childNodes.getLength();
            for (int i = 0; i < len; i++) {
                // Use index 0 because blocks node is removed at each loop round!
                Node node = childNodes.item(0);
                if (node.getNodeName().equalsIgnoreCase("blocks")) {
                    NodeList subNodesBlocks = node.getChildNodes();
                    int len2 = subNodesBlocks.getLength();
                    while (len2 > 0) {
                        documentElement.appendChild(subNodesBlocks.item(0));
                        subNodesBlocks = node.getChildNodes();
                        len2 = subNodesBlocks.getLength();
                    }
                    documentElement.removeChild(node);
                }
            }
        }
    } finally {
        if (sessionMustBeDestroyed) {
            Engine.logContext.debug("(JavelinTransaction) Destroying the current session");
            Engine.theApp.sessionManager.removeSession(context.contextID);
        }
        if ((runningThread == null) || (!runningThread.bContinue)) {
            Engine.logContext.warn("(JavelinTransaction) The transaction \"" + getName() + "\" has been successfully interrupted.");
        } else {
            Engine.logContext.debug("(JavelinTransaction) The transaction \"" + getName() + "\" has successfully finished.");
        }
    }
}
Also used : DefaultBlockFactory(com.twinsoft.convertigo.beans.common.DefaultBlockFactory) BlockFactory(com.twinsoft.convertigo.beans.core.BlockFactory) PanelBlockFactory(com.twinsoft.convertigo.beans.common.PanelBlockFactory) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) EngineException(com.twinsoft.convertigo.engine.EngineException) Javelin(com.twinsoft.twinj.Javelin) com.twinsoft.twinj.iJavelin(com.twinsoft.twinj.iJavelin) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) Collection(java.util.Collection)

Example 3 with EngineEvent

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

the class JavelinTransaction method applyBlockFactory.

public void applyBlockFactory(JavelinScreenClass screenClass, BlockFactory blockFactory, iJavelin javelin, boolean bNotFirstLoop) {
    String t = context.statistics.start(EngineStatistics.APPLY_BLOCK_FACTORY);
    try {
        blockFactory.make(javelin);
        context.previousFields = blockFactory.fields;
        // We fire engine events only in studio mode.
        if (Engine.isStudioMode()) {
            Engine.theApp.fireBlocksChanged(new EngineEvent(blockFactory));
            Engine.logContext.debug("(JavelinTransaction) Step reached after having applied the block factory.");
            Engine.theApp.fireStepReached(new EngineEvent(blockFactory));
        }
    } finally {
        context.statistics.stop(t, bNotFirstLoop);
    }
}
Also used : EngineEvent(com.twinsoft.convertigo.engine.EngineEvent)

Example 4 with EngineEvent

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

the class SequenceEditorPartWrap method checkEventSource.

private boolean checkEventSource(EventObject event) {
    boolean isSourceFromSequence = false;
    if (event instanceof RequestableEngineEvent) {
        RequestableEngineEvent requestableEvent = (RequestableEngineEvent) event;
        String sequenceName = requestableEvent.getSequenceName();
        if (sequenceName != null) {
            if (sequenceName.equals(sequence.getName()) && requestableEvent.getProjectName().equals(sequence.getProject().getName())) {
                isSourceFromSequence = true;
            }
        }
    } else if (event instanceof EngineEvent) {
        Object ob = ((EngineEvent) event).getSource();
        if (ob instanceof Step) {
            try {
                String projectName = ((Step) ob).getProject().getName();
                String sequenceName = ((Step) ob).getSequence().getName();
                if (sequenceName.equals(sequence.getName()) && projectName.equals(sequence.getProject().getName())) {
                    isSourceFromSequence = true;
                }
            } catch (Exception e) {
            }
        }
    }
    return isSourceFromSequence;
}
Also used : RequestableEngineEvent(com.twinsoft.convertigo.engine.RequestableEngineEvent) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) RequestableEngineEvent(com.twinsoft.convertigo.engine.RequestableEngineEvent) EventObject(java.util.EventObject) Step(com.twinsoft.convertigo.beans.core.Step)

Example 5 with EngineEvent

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

the class SequenceEditorPart method checkEventSource.

private boolean checkEventSource(EventObject event) {
    boolean isSourceFromSequence = false;
    if (event instanceof RequestableEngineEvent) {
        RequestableEngineEvent requestableEvent = (RequestableEngineEvent) event;
        String sequenceName = requestableEvent.getSequenceName();
        if (sequenceName != null) {
            if (sequenceName.equals(sequence.getName()) && requestableEvent.getProjectName().equals(sequence.getProject().getName())) {
                isSourceFromSequence = true;
            }
        }
    } else if (event instanceof EngineEvent) {
        Object ob = ((EngineEvent) event).getSource();
        if (ob instanceof Step) {
            try {
                String projectName = ((Step) ob).getProject().getName();
                String sequenceName = ((Step) ob).getSequence().getName();
                if (sequenceName.equals(sequence.getName()) && projectName.equals(sequence.getProject().getName())) {
                    isSourceFromSequence = true;
                }
            } catch (Exception e) {
            }
        }
    }
    return isSourceFromSequence;
}
Also used : RequestableEngineEvent(com.twinsoft.convertigo.engine.RequestableEngineEvent) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) RequestableEngineEvent(com.twinsoft.convertigo.engine.RequestableEngineEvent) EventObject(java.util.EventObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Step(com.twinsoft.convertigo.beans.core.Step) IOException(java.io.IOException)

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 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 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)2