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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations