use of com.twinsoft.convertigo.engine.IdToXpathManager 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