Search in sources :

Example 16 with HtmlConnector

use of com.twinsoft.convertigo.beans.connectors.HtmlConnector 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 17 with HtmlConnector

use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.

the class XMLPrintScreen method apply.

@Override
public boolean apply(Document xmlDom, Context context) {
    try {
        HtmlConnector htmlConnector = (HtmlConnector) context.getConnector();
        PrintScreenResponse printScreenResponse = htmlConnector.getHtmlParser().makePrintScreen(context, new PrintScreenRequest(height, width, top, left, scale, getImageFormat(), true, minDelay));
        if (printScreenResponse != null) {
            Document doc = context.outputDocument;
            Element root = doc.getDocumentElement();
            Element elt = doc.createElement((tagName.equals("") ? getName() : tagName));
            elt.setAttribute("height", Integer.toString(printScreenResponse.height));
            elt.setAttribute("width", Integer.toString(printScreenResponse.width));
            elt.setAttribute("scale", Float.toString(printScreenResponse.scale));
            elt.setAttribute("imageFormat", printScreenResponse.imageFormat.name());
            if (includeDataUrl) {
                elt.setTextContent(printScreenResponse.dataUrlPrefix + printScreenResponse.dataBase64);
            } else {
                elt.setTextContent(printScreenResponse.dataBase64);
            }
            root.appendChild(elt);
        }
        return true;
    } catch (Exception ex) {
    }
    return false;
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) Element(org.w3c.dom.Element) PrintScreenRequest(com.twinsoft.convertigo.engine.parsers.PrintScreenRequest) Document(org.w3c.dom.Document) PrintScreenResponse(com.twinsoft.convertigo.engine.parsers.PrintScreenResponse)

Example 18 with HtmlConnector

use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.

the class IfXpathExistsStatement method execute.

@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
    if (isEnabled()) {
        if (super.execute(javascriptContext, scope)) {
            HtmlConnector htmlConnector = getConnector();
            Document xmlDocument = htmlConnector.getCurrentXmlDocument();
            TwsCachedXPathAPI xpathApi = htmlConnector.context.getXpathApi();
            if ((xmlDocument == null) || (xpathApi == null)) {
                Engine.logBeans.warn((xmlDocument == null) ? "(XPath) Current DOM of HtmlConnector is Null!" : "TwsCachedXPathAPI of HtmlConnector is Null!");
                return false;
            }
            evaluate(javascriptContext, scope, getCondition(), "xpath", false);
            String jsXpath = evaluated.toString();
            NodeList nodeList = null;
            try {
                nodeList = xpathApi.selectNodeList(xmlDocument, jsXpath);
            } catch (TransformerException e) {
                return false;
            } catch (ClassCastException e) {
                return false;
            }
            if (nodeList == null)
                return false;
            if (nodeList.getLength() == 0)
                return false;
            return executeNextStatement(javascriptContext, scope);
        }
    }
    return false;
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) TransformerException(javax.xml.transform.TransformerException) TwsCachedXPathAPI(com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI)

Example 19 with HtmlConnector

use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.

the class IfXpathExistsThenElseStatement method execute.

@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
    if (isEnabled()) {
        if (super.execute(javascriptContext, scope)) {
            HtmlConnector htmlConnector = getConnector();
            Document xmlDocument = htmlConnector.getCurrentXmlDocument();
            TwsCachedXPathAPI xpathApi = htmlConnector.context.getXpathApi();
            if ((xmlDocument == null) || (xpathApi == null)) {
                Engine.logBeans.warn((xmlDocument == null) ? "(XPath) Current DOM of HtmlConnector is Null!" : "TwsCachedXPathAPI of HtmlConnector is Null!");
                return false;
            }
            evaluate(javascriptContext, scope, getCondition(), "xpath", false);
            String jsXpath = evaluated.toString();
            NodeList nodeList = null;
            try {
                nodeList = xpathApi.selectNodeList(xmlDocument, jsXpath);
            } catch (TransformerException e) {
                return false;
            } catch (ClassCastException e) {
                return false;
            }
            if (nodeList == null) {
                return false;
            }
            if (nodeList.getLength() == 0) {
                elseStatement = getElseStatement();
                if (elseStatement != null) {
                    elseStatement.execute(javascriptContext, scope);
                }
                return false;
            }
            thenStatement = getThenStatement();
            if (thenStatement != null) {
                thenStatement.execute(javascriptContext, scope);
                return true;
            }
            return false;
        }
    }
    return false;
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) TransformerException(javax.xml.transform.TransformerException) TwsCachedXPathAPI(com.twinsoft.convertigo.engine.util.TwsCachedXPathAPI)

Example 20 with HtmlConnector

use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.

the class TabManagementStatement method execute.

@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
    if (isEnabled()) {
        if (super.execute(javascriptContext, scope)) {
            HtmlTransaction htmlTransaction = (HtmlTransaction) getParentTransaction();
            HtmlConnector htmlConnector = (HtmlConnector) htmlTransaction.getParent();
            TabManagementEvent evt;
            if (action.equalsIgnoreCase(TabManagementEvent.ACTION_SETINDEX)) {
                try {
                    evaluate(javascriptContext, scope, jsIndex, "jsIndex", false);
                    int index = (int) Double.parseDouble(evaluated.toString());
                    evt = new TabManagementEvent(action, index);
                } catch (Exception e) {
                    throw new EngineException("Tab index value isn't good.", e);
                }
            } else {
                evt = new TabManagementEvent(action);
            }
            HtmlParser htmlParser = htmlConnector.getHtmlParser();
            boolean success = htmlParser.dispatchEvent(evt, htmlTransaction.context, null);
            if (!success)
                Engine.logBeans.debug("NavigationBarStatement has failed");
            else {
                if (action.equalsIgnoreCase(TabManagementEvent.ACTION_GETINDEX)) {
                    String code = getIndexVarname + "=" + evt.getIndex();
                    evaluate(javascriptContext, scope, code, "ContextGet", true);
                } else if (action.equalsIgnoreCase(TabManagementEvent.ACTION_GETNBTAB)) {
                    String code = getIndexVarname + "=" + evt.getNbTab();
                    evaluate(javascriptContext, scope, code, "ContextGet", true);
                }
            }
            success = true;
            return success;
        }
    }
    return false;
}
Also used : HtmlParser(com.twinsoft.convertigo.engine.parsers.HtmlParser) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) TabManagementEvent(com.twinsoft.convertigo.engine.parsers.events.TabManagementEvent) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) EngineException(com.twinsoft.convertigo.engine.EngineException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Aggregations

HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)42 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)14 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)13 EngineException (com.twinsoft.convertigo.engine.EngineException)13 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)12 Connector (com.twinsoft.convertigo.beans.core.Connector)12 Transaction (com.twinsoft.convertigo.beans.core.Transaction)10 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)9 SqlConnector (com.twinsoft.convertigo.beans.connectors.SqlConnector)8 SiteClipperConnector (com.twinsoft.convertigo.beans.connectors.SiteClipperConnector)7 Statement (com.twinsoft.convertigo.beans.core.Statement)7 Document (org.w3c.dom.Document)7 CicsConnector (com.twinsoft.convertigo.beans.connectors.CicsConnector)6 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)6 HandlerStatement (com.twinsoft.convertigo.beans.statements.HandlerStatement)6 List (java.util.List)6 HtmlScreenClass (com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass)5 ScHandlerStatement (com.twinsoft.convertigo.beans.statements.ScHandlerStatement)5 IOException (java.io.IOException)5 TransformerException (javax.xml.transform.TransformerException)5