Search in sources :

Example 1 with AbstractEvent

use of com.twinsoft.convertigo.engine.parsers.events.AbstractEvent in project convertigo by convertigo.

the class HtmlTransaction method applyUserEvents.

protected void applyUserEvents() throws EngineException {
    HtmlConnector connector = (HtmlConnector) parent;
    if (!runningThread.bContinue)
        return;
    try {
        Document dom = null;
        for (int i = 0; i < wcFields.size(); i++) {
            AbstractEvent event = (AbstractEvent) wcFields.get(i);
            connector.dispatchEvent(event, context, new WaitTimeTrigger(0, false));
        }
        String comment = (wcEvent instanceof AbstractEvent) ? ((AbstractEvent) wcEvent).getXPath() : "on browser";
        Engine.logBeans.trace("(HtmlTransaction) Dispatch Event: " + comment);
        boolean dispatch = connector.dispatchEvent(wcEvent, context, wcTrigger);
        dom = connector.getHtmlParser().getDom(context);
        Engine.logBeans.trace("(HtmlTransaction) Event: " + comment + (dispatch ? "" : " not") + " dispatched");
        setCurrentXmlDocument(dom);
        if (Engine.logBeans.isTraceEnabled())
            Engine.logBeans.trace("(HtmlTransaction) Parse result dom:\n" + XMLUtils.prettyPrintDOM(dom));
    } catch (Exception e) {
        throw new EngineException("An unexpected exception occured while trying to get the document via HTTP.", e);
    } finally {
        bDispatching = false;
    }
    if (!runningThread.bContinue)
        return;
}
Also used : WaitTimeTrigger(com.twinsoft.convertigo.engine.parsers.triggers.WaitTimeTrigger) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) EngineException(com.twinsoft.convertigo.engine.EngineException) AbstractEvent(com.twinsoft.convertigo.engine.parsers.events.AbstractEvent) Document(org.w3c.dom.Document) 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 2 with AbstractEvent

use of com.twinsoft.convertigo.engine.parsers.events.AbstractEvent in project convertigo by convertigo.

the class AbstractEventStatement method execute.

@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
    if (isEnabled()) {
        if (super.execute(javascriptContext, scope)) {
            evaluate(javascriptContext, scope, getXpath(), "xpath", false);
            String jsXpath = evaluated.toString();
            HtmlTransaction htmlTransaction = (HtmlTransaction) getParentTransaction();
            HtmlConnector htmlConnector = (HtmlConnector) htmlTransaction.getParent();
            Engine.logBeans.trace("Getting event...");
            AbstractEvent event = getEvent(javascriptContext, scope);
            event.setXPath(jsXpath);
            event.setDelay(getDelay());
            Engine.logBeans.trace("Dispatching event...");
            boolean dispatch = htmlConnector.dispatchEvent(event, htmlTransaction.context, trigger.getTrigger());
            Engine.logBeans.trace("Getting DOM...");
            htmlTransaction.setCurrentXmlDocument(htmlConnector.getHtmlParser().getDom(htmlTransaction.context));
            if (dispatch)
                Engine.logBeans.trace("For target '" + jsXpath + " " + event + " has been successfully dispatched on webViewer");
            else {
                Engine.logBeans.warn("For target '" + jsXpath + " " + event + " has not been well dispatched on webViewer");
                throw new EngineException("Error when dispatch Html event");
            }
            return true;
        }
    }
    return false;
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) EngineException(com.twinsoft.convertigo.engine.EngineException) AbstractEvent(com.twinsoft.convertigo.engine.parsers.events.AbstractEvent)

Example 3 with AbstractEvent

use of com.twinsoft.convertigo.engine.parsers.events.AbstractEvent in project convertigo by convertigo.

the class HtmlTransaction method parseInputDocument.

/* (non-Javadoc)
	 * @see com.twinsoft.convertigo.beans.transactions.HttpTransaction#parseInputDocument(com.twinsoft.convertigo.engine.Context)
	 */
@Override
public void parseInputDocument(com.twinsoft.convertigo.engine.Context context) throws EngineException {
    super.parseInputDocument(context);
    // TODO : voir si on garde cela
    // Overrides statefull mode using given __statefull request parameter
    NodeList stateNodes = context.inputDocument.getElementsByTagName("statefull");
    if (stateNodes.getLength() == 1) {
        Element node = (Element) stateNodes.item(0);
        String value = node.getAttribute("value");
        if (!value.equals("")) {
            setStateFull(value.equalsIgnoreCase("true"));
        }
    }
    stateNodes = context.inputDocument.getElementsByTagName("webviewer-action");
    if (stateNodes.getLength() == 1 && stateNodes.item(0).getChildNodes().getLength() > 0) {
        Element webviewerAction = (Element) stateNodes.item(0);
        IdToXpathManager idToXpathManager = context.getIdToXpathManager();
        NodeList fieldNodes = context.inputDocument.getElementsByTagName("field");
        wcEvent = null;
        wcTrigger = null;
        wcFields = new ArrayList<AbstractEvent>(fieldNodes.getLength());
        for (int i = 0; i < fieldNodes.getLength(); i++) {
            Element field = (Element) fieldNodes.item(i);
            String id = field.getAttribute("name");
            id = id.substring(id.lastIndexOf('_') + 1, id.length());
            String value = field.getAttribute("value");
            String xPath = idToXpathManager.getXPath(id);
            Node node = idToXpathManager.getNode(id);
            if (node != null && node instanceof Element) {
                Element el = (Element) node;
                String tagname = el.getTagName();
                AbstractEvent evt = null;
                if (tagname.equalsIgnoreCase("input")) {
                    String type = el.getAttribute("type");
                    if (type.equalsIgnoreCase("checkbox") || type.equalsIgnoreCase("radio")) {
                        evt = new InputCheckEvent(xPath, true, Boolean.valueOf(value).booleanValue());
                    } else {
                        evt = new InputValueEvent(xPath, true, value);
                    }
                } else if (tagname.equalsIgnoreCase("select")) {
                    evt = new InputSelectEvent(xPath, true, InputSelectEvent.MOD_INDEX, value.split(";"));
                } else if (tagname.equalsIgnoreCase("textarea")) {
                    evt = new InputValueEvent(xPath, true, value);
                }
                if (evt != null) {
                    wcFields.add(evt);
                    Engine.logBeans.trace("Xpath: " + xPath + " will be set to :" + value);
                }
            }
        }
        NodeList actionNodes = webviewerAction.getElementsByTagName("action");
        if (actionNodes.getLength() == 1) {
            String action = ((Element) actionNodes.item(0)).getAttribute("value");
            if (action.equals("click")) {
                int screenX, screenY, clientX, clientY;
                screenX = screenY = clientX = clientY = -1;
                boolean ctrlKey, altKey, shiftKey, metKey;
                ctrlKey = altKey = shiftKey = metKey = false;
                short button = 0;
                String xPath = null;
                NodeList eventNodes = webviewerAction.getElementsByTagName("event");
                for (int i = 0; i < eventNodes.getLength(); i++) {
                    String name = ((Element) eventNodes.item(i)).getAttribute("name");
                    String value = ((Element) eventNodes.item(i)).getAttribute("value");
                    if (name.equals("x") || name.equals("y") || name.startsWith("client")) {
                        int valueInt = Integer.parseInt(value);
                        if (name.equals("x"))
                            screenX = valueInt;
                        else if (name.equals("y"))
                            screenY = valueInt;
                        else if (name.equals("clientX"))
                            clientX = valueInt;
                        else if (name.equals("clientY"))
                            clientY = valueInt;
                    } else if (name.endsWith("Key")) {
                        boolean valueBool = Boolean.getBoolean(value);
                        if (name.equals("ctrlKey"))
                            ctrlKey = valueBool;
                        else if (name.equals("altKey"))
                            altKey = valueBool;
                        else if (name.equals("shiftKey"))
                            altKey = valueBool;
                        else if (name.equals("metKey"))
                            altKey = valueBool;
                    } else if (name.equals("srcid")) {
                        xPath = idToXpathManager.getXPath(value);
                    }
                }
                if (xPath != null) {
                    wcEvent = new MouseEvent(xPath, action, screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metKey, button);
                    Engine.logBeans.debug("Created an click event from webviewer-action on : " + xPath);
                }
            } else if (action.startsWith("navbar_")) {
                action = action.substring(7, action.length());
                wcEvent = new NavigationBarEvent(action);
            } else {
                String xPath = null;
                NodeList eventNodes = webviewerAction.getElementsByTagName("event");
                for (int i = 0; i < eventNodes.getLength(); i++) {
                    String name = ((Element) eventNodes.item(i)).getAttribute("name");
                    String value = ((Element) eventNodes.item(i)).getAttribute("value");
                    if (name.equals("srcid"))
                        xPath = idToXpathManager.getXPath(value);
                }
                if (xPath != null)
                    wcEvent = new SimpleEvent(xPath, action);
            }
            bDispatching = (wcEvent != null);
            if (bDispatching && wcTrigger == null)
                // wcTrigger = new  WaitTimeTrigger(2000);
                // wcTrigger = new  XpathTrigger("*", 10000);
                // wcTrigger = new  DocumentCompletedTrigger(1, 10000);
                wcTrigger = getTrigger().getTrigger();
        }
    }
}
Also used : InputValueEvent(com.twinsoft.convertigo.engine.parsers.events.InputValueEvent) SimpleEvent(com.twinsoft.convertigo.engine.parsers.events.SimpleEvent) MouseEvent(com.twinsoft.convertigo.engine.parsers.events.MouseEvent) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) InputSelectEvent(com.twinsoft.convertigo.engine.parsers.events.InputSelectEvent) AbstractEvent(com.twinsoft.convertigo.engine.parsers.events.AbstractEvent) IdToXpathManager(com.twinsoft.convertigo.engine.IdToXpathManager) NavigationBarEvent(com.twinsoft.convertigo.engine.parsers.events.NavigationBarEvent) InputCheckEvent(com.twinsoft.convertigo.engine.parsers.events.InputCheckEvent)

Aggregations

AbstractEvent (com.twinsoft.convertigo.engine.parsers.events.AbstractEvent)3 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)2 EngineException (com.twinsoft.convertigo.engine.EngineException)2 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)1 IdToXpathManager (com.twinsoft.convertigo.engine.IdToXpathManager)1 ObjectWithSameNameException (com.twinsoft.convertigo.engine.ObjectWithSameNameException)1 InputCheckEvent (com.twinsoft.convertigo.engine.parsers.events.InputCheckEvent)1 InputSelectEvent (com.twinsoft.convertigo.engine.parsers.events.InputSelectEvent)1 InputValueEvent (com.twinsoft.convertigo.engine.parsers.events.InputValueEvent)1 MouseEvent (com.twinsoft.convertigo.engine.parsers.events.MouseEvent)1 NavigationBarEvent (com.twinsoft.convertigo.engine.parsers.events.NavigationBarEvent)1 SimpleEvent (com.twinsoft.convertigo.engine.parsers.events.SimpleEvent)1 WaitTimeTrigger (com.twinsoft.convertigo.engine.parsers.triggers.WaitTimeTrigger)1 IOException (java.io.IOException)1 EvaluatorException (org.mozilla.javascript.EvaluatorException)1 JavaScriptException (org.mozilla.javascript.JavaScriptException)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1