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