use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class Container method execute.
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
if (!bFirstTime) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
if (containerDesc.x == -1)
containerDesc.x = 0;
if (containerDesc.y == -1)
containerDesc.y = 0;
bFirstTime = false;
// create the container
Block container = new Block();
if (tagName.length() != 0)
container.tagName = this.tagName;
else
container.tagName = "container";
container.bRender = true;
container.type = "container";
container.setText("");
container.column = containerDesc.x;
container.line = containerDesc.y;
container.setOptionalAttribute("width", "" + containerDesc.width);
container.setOptionalAttribute("height", "" + containerDesc.height);
addMashupAttribute(container);
// block to go through the block factory
Block tmpBlock = blockFactory.getFirstBlock();
Block saveBlock = null;
// block to memorize container's place in block factory
Block blockBeforeContainer = null;
while (tmpBlock != null) {
// } else {
if (// if tmpBlock is on a line inferior to container's
tmpBlock.line < containerDesc.y || (tmpBlock.line == containerDesc.y && tmpBlock.column < containerDesc.x)) {
// or tmpBlock is on the good line but on a column inferior to container's
// the container must be set after this block
blockBeforeContainer = tmpBlock;
}
// skip final blocks
if (tmpBlock.bFinal) {
tmpBlock = blockFactory.getNextBlock(tmpBlock);
continue;
}
// test if the block is matching selection and attributes criterias
if (canBlockBeSelected(tmpBlock)) {
// add the block to the container
container.addOptionalChildren(tmpBlock);
// container.addOptionalChildren(tmpBlock.toXML(dom, attributes));
// go on to the next block
saveBlock = tmpBlock;
tmpBlock = blockFactory.getNextBlock(tmpBlock);
// remove the old block from the block factory
blockFactory.removeBlock(saveBlock);
} else {
// go on to the next block
tmpBlock = blockFactory.getNextBlock(tmpBlock);
}
}
// add the container to the block factory
blockFactory.insertBlock(container, blockBeforeContainer);
xrs.hasMatched = true;
xrs.newCurrentBlock = blockFactory.getNextBlock(container);
return xrs;
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class Button method execute.
@Override
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
Block startBlock = null;
Block blockTmp = null;
Collection<Block> blocksToDelete = new LinkedList<Block>();
boolean bEndBlockFound = false;
XMLRectangle position = new XMLRectangle(-1, -1, -1, -1);
String label = "";
boolean bPenSelectable = false;
boolean bLastBlock = false;
if (bFirstTime) {
if (buttonDesc.x != -1 && buttonDesc.y != -1) {
// defined button
if (buttonDesc.width == -1) {
if (!Label.equals("")) {
buttonDesc.width = Label.length();
} else {
buttonDesc.width = 6;
}
}
if (buttonDesc.height == -1)
buttonDesc.height = 1;
} else if (!startPattern.equals("") && !endPattern.equals("")) {
// no position is defined and start and end patterns are defined
// searching all buttons on the screen thanks to a start pattern and an end pattern
bSearchPos = true;
bFirstTime = false;
} else if (!Label.equals("")) {
// initialize the position of the button
if (buttonDesc.x == -1)
buttonDesc.x = 0;
if (buttonDesc.y == -1)
buttonDesc.y = 0;
if (buttonDesc.width == -1)
buttonDesc.width = 6;
if (buttonDesc.height == -1)
buttonDesc.height = 1;
} else {
// use default start and end pattern
startPattern = "<";
endPattern = ">";
// searching all buttons on the screen
bSearchPos = true;
bFirstTime = false;
}
}
if (bSearchPos) {
// search of the start block of a button
if (block.getText().trim().indexOf(startPattern) == 0) {
startBlock = block;
if (startBlock.getOptionalAttribute("penselectable") != null && startBlock.getOptionalAttribute("penselectable").equals("true"))
bPenSelectable = true;
blocksToDelete.add(startBlock);
position.x = startBlock.column;
position.y = startBlock.line;
// search of the end pattern of the button in the same block
if (// block contains endPattern
startBlock.getText().trim().indexOf(endPattern) != -1 && // and endPattern is at the end of the block
startBlock.getText().trim().indexOf(endPattern) == startBlock.getText().trim().length() - endPattern.length()) {
label = startBlock.getText().trim().substring(startPattern.length(), startBlock.getText().trim().indexOf(endPattern));
position.width = startBlock.length;
position.height = 1;
} else {
label = startBlock.getText().trim().substring(startPattern.length());
// search of the end pattern in the next blocks
blockTmp = block;
while (blockFactory.getNextBlock(blockTmp) != null && !bEndBlockFound) {
blockTmp = blockFactory.getNextBlock(blockTmp);
if (blockTmp.getText().trim().indexOf(startPattern) != 0) {
if (blockTmp.getOptionalAttribute("penselectable") != null && blockTmp.getOptionalAttribute("penselectable").equals("true"))
bPenSelectable = true;
blocksToDelete.add(blockTmp);
if (// block contains endPattern
blockTmp.getText().trim().indexOf(endPattern) != -1 && // and endPattern is at the end of the block
blockTmp.getText().trim().indexOf(endPattern) == blockTmp.getText().trim().length() - endPattern.length()) {
label += " " + blockTmp.getText().trim().substring(0, blockTmp.getText().trim().indexOf(endPattern));
bEndBlockFound = true;
position.width = blockTmp.column - startBlock.column + 1;
position.height = blockTmp.line - startBlock.line + 1;
} else {
label += " " + blockTmp.getText().trim();
}
} else {
xrs.hasMatched = false;
xrs.newCurrentBlock = blockTmp;
return xrs;
}
}
if (!bEndBlockFound) {
xrs.hasMatched = false;
xrs.newCurrentBlock = blockTmp;
return xrs;
}
}
} else {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
} else if (bAdded) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
if (!bAdded || bSearchPos) {
bFirstTime = false;
if (!bSearchPos) {
if (blockFactory.getNextBlock(block) == null) {
// case block is the last one : insert block after !
bLastBlock = true;
} else {
// test if the block matches to add the block button just before
if (block.line < buttonDesc.y) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
} else if (block.line == buttonDesc.y) {
if (block.column < buttonDesc.x) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
}
}
}
Block myButton;
if (bSearchPos) {
myButton = createButton(label, position, false);
if (bPenSelectable)
myButton.setOptionalAttribute("penselectable", "true");
else
myButton.setOptionalAttribute("penselectable", "false");
} else {
myButton = createButton(Label, buttonDesc, DoTransaction);
}
addMashupAttribute(myButton);
if (bLastBlock) {
blockFactory.insertBlock(myButton, block);
} else {
blockFactory.insertBlock(myButton, blockFactory.getPreviousBlock(block));
}
blockFactory.removeBlocks(blocksToDelete);
bAdded = true;
if (bSearchPos) {
xrs.newCurrentBlock = myButton;
} else {
xrs.newCurrentBlock = block;
}
xrs.hasMatched = true;
}
return xrs;
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class JavelinTransaction method renderBlocksToXml.
private void renderBlocksToXml(List<Collection<Block>> vBlocks) throws EngineException {
String t = context.statistics.start(EngineStatistics.GENERATE_DOM);
try {
Enumeration<Collection<Block>> enumBlocks = Collections.enumeration(vBlocks);
Map<String, String> types = null;
int nPage = 0;
Element page = null;
Element outputDocumentRootElement = context.outputDocument.getDocumentElement();
outputDocumentRootElement.setAttribute("transaction", context.transactionName);
outputDocumentRootElement.setAttribute("connector", context.connectorName);
String prefix = getXsdTypePrefix();
String transactionName = context.transactionName;
boolean studioMode = Engine.isStudioMode();
if (studioMode) {
types = new HashMap<String, String>(5);
xsdType = "";
xsdType += "<xsd:complexType name=\"" + prefix + transactionName + "Response\">\n";
xsdType += "\t<xsd:sequence>\n";
xsdType += "\t\t<xsd:element name=\"error\" minOccurs=\"0\" maxOccurs=\"1\" type=\"p_ns:ConvertigoError\"/>\n";
}
if (!isRemoveBlocksNode()) {
xsdType += "\t\t<xsd:element name=\"blocks\" minOccurs=\"1\" maxOccurs=\"unbounded\" type=\"p_ns:" + prefix + transactionName + "_blocksType\"/>\n";
xsdType += "\t</xsd:sequence>\n";
xsdType += "</xsd:complexType>\n";
xsdType += "<xsd:complexType name=\"" + prefix + transactionName + "_blocksType\">\n";
xsdType += "\t<xsd:sequence>\n";
}
if (onlyOnePage) {
Engine.logContext.debug("(JavelinTransaction) Creating the unique page item into the XML document");
page = context.outputDocument.createElement("blocks");
outputDocumentRootElement.appendChild(page);
}
while (enumBlocks.hasMoreElements()) {
if (!onlyOnePage) {
Engine.logContext.debug("(JavelinTransaction) Creating a new page item into the XML document");
page = context.outputDocument.createElement("blocks");
page.setAttribute("page-number", Integer.toString(nPage));
outputDocumentRootElement.appendChild(page);
}
Element xmlBlock, history, xmlValue;
List<String> values;
String value;
for (Block block : enumBlocks.nextElement()) {
Engine.logContext.trace("(JavelinTransaction) Block: " + block.toString());
// Skip rendering if needed
if (block.bRender) {
xmlBlock = block.toXML(context.outputDocument, getIncludedTagAttributes(), prefix + transactionName + "_blocks");
// Add history
String historyBlock = block.getOptionalAttribute("history");
if ((context.httpSession != null) && (block != null) && (block.type.equals("field")) && (historyBlock != null) && (historyBlock.equals("true"))) {
values = GenericUtils.cast(context.httpSession.getAttribute(block.tagName));
if (values != null) {
history = context.outputDocument.createElement("history");
int len = values.size();
for (int i = 0; i < len; i++) {
value = values.get(i);
xmlValue = context.outputDocument.createElement("value");
xmlValue.appendChild(context.outputDocument.createTextNode(value));
history.appendChild(xmlValue);
}
xmlBlock.appendChild(history);
}
}
page.appendChild(xmlBlock);
if (studioMode) {
if (types.get(block.tagName) == null) {
xsdType += "\t\t\t" + block.xsdType + "\n";
types.put(block.tagName, block.xsdTypes);
}
}
}
}
nPage++;
}
if (studioMode) {
if (!isRemoveBlocksNode()) {
xsdType += "\t</xsd:sequence>\n";
xsdType += "\t<xsd:attribute name=\"page-number\" use=\"optional\"/>\n";
xsdType += "</xsd:complexType>\n";
} else {
xsdType += "\t</xsd:sequence>\n";
xsdType += "</xsd:complexType>\n";
}
Enumeration<String> e = Collections.enumeration(types.values());
while (e.hasMoreElements()) {
xsdType += e.nextElement();
}
// System.out.println(xsdType);
}
} finally {
context.statistics.stop(t);
}
Engine.logContext.debug("(JavelinTransaction) DOM generated");
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class JavelinTransaction method applyUserRequest.
public void applyUserRequest(iJavelin javelin) throws EngineException {
boolean fieldIsAutoEnter = false;
String currentField = "null";
sessionMustBeDestroyed = false;
String t = context.statistics.start(EngineStatistics.APPLY_USER_REQUEST);
try {
Engine.logContext.debug("(JavelinTransaction) Applying user request");
// We apply the XML command to the Javelin object.
if (context.inputDocument == null) {
// Nothing to do: the user request is not relevant for this screen.
Engine.logContext.debug("(JavelinTransaction) Request handling aborted: no user request");
return;
}
NodeList nodeList;
Node node, nodeAttribute;
NamedNodeMap nodeAttributes;
long documentSignature = 0;
nodeList = context.inputDocument.getElementsByTagName("document-signature");
if (nodeList.getLength() > 0) {
node = nodeList.item(0);
String value = ((Element) node).getAttribute("value");
try {
documentSignature = Long.parseLong(value);
} catch (NumberFormatException e) {
Engine.logContext.debug("(JavelinTransaction) Wrong document signature: " + value);
}
}
Engine.logContext.debug("(JavelinTransaction) Received document signature: " + documentSignature);
Engine.logContext.debug("(JavelinTransaction) Last received document signature: " + context.documentSignatureReceived);
Engine.logContext.debug("(JavelinTransaction) Last sent document signature: " + context.documentSignatureSent);
if (documentSignature < context.documentSignatureReceived) {
// The user is trying to replay a previous request (probably by using the back
// functionality from the browser...): this is forbidden.
Engine.logContext.warn("(JavelinTransaction) Request handling aborted: \"back\" protection");
context.outputDocument.getDocumentElement().setAttribute("back-attempt", "true");
return;
}
// Json string of modified fields
String modifiedFields = "";
nodeList = context.inputDocument.getElementsByTagName("modified-fields");
if (nodeList.getLength() > 0) {
node = nodeList.item(0);
nodeAttributes = node.getAttributes();
nodeAttribute = nodeAttributes.getNamedItem("value");
modifiedFields = nodeAttribute.getNodeValue();
}
nodeList = context.inputDocument.getElementsByTagName("current-field");
if (nodeList.getLength() > 0) {
node = nodeList.item(0);
nodeAttributes = node.getAttributes();
nodeAttribute = nodeAttributes.getNamedItem("name");
currentField = nodeAttribute.getNodeValue();
}
nodeList = context.inputDocument.getElementsByTagName("action");
if (nodeList.getLength() == 1) {
Block block;
String action, blockName;
node = nodeList.item(0);
nodeAttributes = node.getAttributes();
nodeAttribute = nodeAttributes.getNamedItem("name");
action = nodeAttribute.getNodeValue();
action = action.trim();
// Refreshing current XML document
if (action.equalsIgnoreCase("convertigo_refresh")) {
Engine.logContext.debug("(JavelinTransaction) Refresh required");
} else if (action.startsWith("convertigo_bench")) {
long sleepTime = 1000;
if (action.length() > "convertigo_bench".length()) {
String s = action.substring(16);
try {
sleepTime = Long.parseLong(s);
} catch (NumberFormatException e) {
// Ignore
}
}
Engine.logContext.debug("(JavelinTransaction) Bench option: sleep during " + sleepTime + " second(s)");
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
}
} else // Destroy the current session
if (action.equalsIgnoreCase("convertigo_destroy_session")) {
Engine.logContext.debug("(JavelinTransaction) Requiring destroy of the current session");
sessionMustBeDestroyed = true;
} else // Reconnecting
if (action.equalsIgnoreCase("convertigo_reconnect")) {
Engine.logContext.debug("(JavelinTransaction) Reconnection required");
javelin.disconnect();
if (javelin.isConnected()) {
throw new ConnectionException("Unable to disconnect the session! See the emulator logs for more details...");
}
javelin.connect(timeoutForConnect);
if (!javelin.isConnected()) {
throw new ConnectionException("Unable to connect the session! See the emulator logs for more details...");
}
javelin.waitForDataStable(timeoutForDataStable, dataStableThreshold);
} else {
if (javelin.getTerminalClass().equals(iJavelin.SNA) || javelin.getTerminalClass().equals(iJavelin.AS400)) {
// Special case for IBM emulators: before applying an action,
// do a RESET action on the emulator to clear a possible
// previous X System Status.
javelin.doAction("KEY_RESET");
Engine.logContext.debug("(JavelinTransaction) Action performed on the Javelin object: 'KEY_RESET'");
}
// previously sent document signature
if ((documentSignature == 0) || (documentSignature == context.documentSignatureSent)) {
// Searching for fields to push into the Javelin object.
nodeList = context.inputDocument.getElementsByTagName("field");
int len = nodeList.getLength();
String value;
// sort fields by line and column in the screen
Element elem;
ArrayList<ComparableFieldElement> liste = new ArrayList<ComparableFieldElement>();
for (int i = 0; i < len; i++) {
elem = (Element) nodeList.item(i);
liste.add(new ComparableFieldElement(elem));
}
Engine.logContext.debug("(JavelinTransaction) Fields from inputDocument set in a list.");
Collections.sort(liste);
Engine.logContext.debug("(JavelinTransaction) Fields from inputDocument sorted.");
Iterator<ComparableFieldElement> it = liste.iterator();
while (it.hasNext()) {
ComparableFieldElement cfElem = it.next();
elem = cfElem.getFieldElement();
value = elem.getAttribute("value");
if (javelin.getTerminalClass().equals(iJavelin.VDX)) {
javelin.send(value);
Engine.logContext.debug("(JavelinTransaction) Characters sent to the Javelin object: '" + value + "'");
} else if (javelin.getTerminalClass().equals(iJavelin.VT)) {
javelin.send(value);
Engine.logContext.debug("(JavelinTransaction) VT Characters sent to the Javelin object: '" + value + "'");
} else {
// Trying to find the requested block
blockName = elem.getAttribute("name");
Engine.logContext.debug("(JavelinTransaction) Analyzing field \"" + blockName + "\"");
block = context.previousFields.get(blockName);
int column = 0;
int line = 0;
try {
int index1 = blockName.indexOf("_c");
int index2 = blockName.indexOf("_l");
column = Integer.parseInt(blockName.substring(index1 + 2, index2));
line = Integer.parseInt(blockName.substring(index2 + 2));
Engine.logContext.debug("(JavelinTransaction) Cursor position retrieved from the field name \"" + blockName + "\"column: =" + column + " line=" + line);
} catch (Exception e) {
Engine.logContext.error("Unable to retrieve the cursor position from the field name \"" + blockName + "\"! Skipping it.", e);
continue;
}
if (isFieldValueDifferent(blockName, value, modifiedFields)) {
javelin.moveCursor(column, line);
Engine.logContext.debug("(JavelinTransaction) Cursor moved to column:" + column + ", line: " + line);
// Delete the previous field value
if (javelin.getTerminalClass().equals(iJavelin.SNA) || javelin.getTerminalClass().equals(iJavelin.AS400)) {
javelin.doAction("KEY_ERASEEOF");
} else if (javelin.getTerminalClass().equals(iJavelin.DKU)) {
javelin.doAction("ERAEOL");
}
if (value.length() != 0) {
// Test if the field is numeric only
if ((block != null) && (block.attribute & iJavelin.AT_FIELD_NUMERIC) > 0) {
value = removeAllNonNumericChars(value);
Engine.logContext.warn("(JavelinTransaction) Numeric field. Non numeric chars may have been discarded [" + value + "]");
}
// Test if the field is autoenter and that its size equals to the field size
try {
if ((block != null) && (block.attribute & iJavelin.AT_AUTO_ENTER) > 0) {
if (value.length() == Integer.parseInt(block.getOptionalAttribute("size"))) {
fieldIsAutoEnter = true;
Engine.logContext.debug("(JavelinTransaction) Field is auto enter, doAction will not be executed [" + value + "]");
}
}
} catch (Exception e) {
Engine.logContext.warn("(JavelinTransaction) Field is auto enter, but no size attribute present! [" + value + "]");
}
javelin.send(value);
Engine.logContext.debug("(JavelinTransaction) Characters sent to the emulator on (" + column + ", " + line + "): '" + value + "'");
}
// Update the block history if it is a non empty field
if ((block != null) && (value.length() != 0)) {
String historyBlock = block.getOptionalAttribute("history");
if ((block.type.equals("field")) && (historyBlock != null) && (historyBlock.equals("true")) && (value.length() > 0)) {
// TODO: set the tagname list to remember
List<String> values = GenericUtils.cast(context.httpSession.getAttribute(block.tagName));
if (values == null) {
values = new ArrayList<String>(10);
}
if (!values.contains(value)) {
values.add(value);
context.httpSession.setAttribute(block.tagName, values);
Engine.logContext.debug("(JavelinTransaction) History: block '" + block.tagName + "' += '" + value + "'");
}
}
}
if (action.equalsIgnoreCase("KEY_FIELDPLUS")) {
Engine.logContext.debug("(JavelinTransaction) Action is KEY_FIELDPLUS while sending " + blockName + " field");
if (blockName.equalsIgnoreCase(currentField)) {
// The field we are handling is the current field.
// Do now the FIELD_PLUS action.
Engine.logContext.debug("(JavelinTransaction) We just sent the current field, and action is KEY_FIELDPLUS");
javelin.doAction("KEY_FIELDPLUS");
return;
}
}
}
}
}
if (currentField != null) {
block = (Block) context.previousFields.get(currentField);
// we did not find the field in the previous fields : assume the current field is set on a static position. This is
// legal as some applications rely on the cursor position event on static fields
int index1 = currentField.indexOf("_c");
int index2 = currentField.indexOf("_l");
if ((index1 != -1) && (index2 != -1)) {
int column = Integer.parseInt(currentField.substring(index1 + 2, index2));
int line = Integer.parseInt(currentField.substring(index2 + 2));
Engine.logContext.debug("(JavelinTransaction) Move cursor on Current field : Cursor position retrieved from the field name \"" + currentField + "\"column=" + column + " line=" + line);
boolean moveDone = false;
// if current field is numeric, put the cursor at the end of the field
// searching field index
int nbFields = javelin.getNumberOfFields();
int i = 0;
boolean found = false;
while (i < nbFields && !found) {
if (javelin.getFieldColumn(i) == column && javelin.getFieldLine(i) == line)
found = true;
else
i++;
}
if (found) {
// field index found
if ((javelin.getFieldAttribute(i) & iJavelin.AT_FIELD_NUMERIC) > 0) {
// numeric field
// put the cursor at the end of the field
column = column + javelin.getFieldLength(i) - 1;
Engine.logContext.debug("(JavelinTransaction) Cursor is in a numeric field '" + currentField + "' ; moving cursor to the end of the field '" + currentField + "' at (" + column + ", " + line + ")");
javelin.moveCursor(column, line);
Engine.logContext.debug("(JavelinTransaction) Moved cursor to (" + javelin.getCurrentColumn() + ", " + javelin.getCurrentLine() + ")");
moveDone = true;
}
}
if (!moveDone) {
// and if the action is KEY_NPTUI or not
if (javelin.getCurrentColumn() == column && javelin.getCurrentLine() == line && !action.equals("KEY_NPTUI")) {
Engine.logContext.debug("(JavelinTransaction) Cursor has not moved from field '" + currentField + "' at (" + column + ", " + line + ") and action is not \"KEY_NPTUI\" ; don't move cursor");
} else {
Engine.logContext.debug("(JavelinTransaction) Cursor has moved from field '" + currentField + "' or action is \"KEY_NPTUI\" ; moving cursor to field '" + currentField + "' at (" + column + ", " + line + ")");
javelin.moveCursor(column, line);
Engine.logContext.debug("(JavelinTransaction) Moved cursor to (" + javelin.getCurrentColumn() + ", " + javelin.getCurrentLine() + ")");
}
}
}
}
} else {
Engine.logContext.warn("(JavelinTransaction) Cancel applying fields because of document signature check");
}
// Storing last document signature received
context.documentSignatureReceived = documentSignature;
// Executing action
if (!fieldIsAutoEnter) {
// Execute the action only if there were no AutoEnter fields...
if (action.equalsIgnoreCase("KEY_NPTUI")) {
// NPTUI action just wait as the moveCursor already triggered the HOST COMM. we only have
// to wait here
boolean bTimedOut = javelin.waitForDataStable(timeoutForDataStable, dataStableThreshold);
Engine.logContext.debug("(JavelinTransaction) Action performed on the Javelin object: '" + action + "'waitForDataStable returned :" + bTimedOut);
} else if (action.length() != 0) {
javelin.doAction(action);
Engine.logContext.debug("(JavelinTransaction) Action performed on the Javelin object: '" + action + "'");
if (!(action.equalsIgnoreCase("KEY_FIELDPLUS") || action.equalsIgnoreCase("KEY_FIELDMINUS"))) {
boolean bTimedOut = javelin.waitForDataStable(timeoutForDataStable, dataStableThreshold);
Engine.logContext.debug("(JavelinTransaction) WaitForDataStable() returned " + bTimedOut);
} else
Engine.logContext.debug("(JavelinTransaction) Action was KEY_FIELDPLUS or KEY_FIELDMINUS, do not perform waitForDataStable");
} else {
Engine.logContext.debug("(JavelinTransaction) Empty action string => action aborted");
}
} else {
boolean bTimedOut = javelin.waitForDataStable(timeoutForDataStable, dataStableThreshold);
Engine.logContext.debug("(JavelinTransaction) WaitForDataStable() returned " + bTimedOut);
}
}
}
} catch (Exception e) {
Engine.logContext.error("Request handling aborted because of internal error.", e);
} finally {
context.statistics.stop(t);
}
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class TabBox method execute.
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
int activeTab = 0;
Block blockTmp, dataBlock = null;
Collection<Block> tabBlocks = new LinkedList<Block>();
org.w3c.dom.Element tabBox;
org.w3c.dom.Element item;
xrs.hasMatched = false;
if (!extendedMode) {
if (!block.type.equals("keyword") || block.getOptionalAttribute("penselectable") == null) {
// block not matching first button
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
// seams first button found
blockTmp = block;
tabBlocks.add(blockTmp);
if (blockTmp.getOptionalAttribute("penselectable").equals("false"))
activeTab++;
// look for other buttons
while (blockFactory.getEastBlock(blockTmp) != null && canBlockBeSelected(blockFactory.getEastBlock(blockTmp)) && blockFactory.getEastBlock(blockTmp).type.equals("keyword") && blockFactory.getEastBlock(blockTmp).getOptionalAttribute("penselectable") != null && activeTab <= 1) {
tabBlocks.add(blockFactory.getEastBlock(blockTmp));
if (blockFactory.getEastBlock(blockTmp).getOptionalAttribute("penselectable").equals("false"))
activeTab++;
blockTmp = blockFactory.getEastBlock(blockTmp);
}
if (activeTab != 1) {
// more than one button not penselectable => not a tabBox
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
// creates the tab box element
tabBox = dom.createElement("tabBox");
// creates the tab box items
for (Block itemBlock : tabBlocks) {
// create item element
item = dom.createElement("block");
item.appendChild(dom.createTextNode(itemBlock.getText()));
item.setAttribute("line", "" + itemBlock.line);
item.setAttribute("column", "" + itemBlock.column);
item.setAttribute("width", "" + itemBlock.getOptionalAttribute("width"));
item.setAttribute("height", "" + itemBlock.getOptionalAttribute("height"));
item.setAttribute("type", "tabBoxItem");
item.setAttribute("selected", itemBlock.getOptionalAttribute("penselectable").equals("false") ? "true" : "false");
// add the item to the tabBox element
tabBox.appendChild(item);
}
} else {
// extended mode : we look for buttonsPanel type block
if (!block.type.equals("buttonsPanel")) {
// block not matching buttons panel
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
// buttonsPanel found
// change tagname
block.tagName = "tabBox";
// save tabBox
tabBox = block.toXML(dom, attributes);
// and remove all attributes to match tabBoxes'set
tabBox.removeAttribute("background");
tabBox.removeAttribute("choicesCols");
tabBox.removeAttribute("choicesRows");
tabBox.removeAttribute("choicesTextSize");
tabBox.removeAttribute("column");
tabBox.removeAttribute("foreground");
tabBox.removeAttribute("line");
tabBox.removeAttribute("name");
tabBox.removeAttribute("reverse");
tabBox.removeAttribute("type");
// modify every child node to match tabBoxes'items
NodeList items = tabBox.getChildNodes();
for (int i = 0; i < items.getLength(); i++) {
Node node = items.item(i);
if (node instanceof Element) {
Element elem = (Element) node;
elem.setAttribute("type", "tabBoxItem");
elem.removeAttribute("action");
if (elem.getAttribute("available").equals("true"))
elem.setAttribute("selected", "false");
else
elem.setAttribute("selected", "true");
elem.removeAttribute("available");
elem.removeAttribute("background");
elem.removeAttribute("dotransaction");
elem.removeAttribute("foreground");
elem.removeAttribute("name");
elem.removeAttribute("reverse");
}
}
// set dataBlock to the first next block
blockTmp = blockFactory.getNextBlock(block);
// put the block in the vector to be removed
tabBlocks.add(block);
}
// look for the first data block : the first selectable block of the next line
while (blockFactory.getNextBlock(blockTmp) != null && dataBlock == null) {
if (canBlockBeSelected(blockFactory.getNextBlock(blockTmp)) && blockFactory.getNextBlock(blockTmp).line > blockTmp.line) {
dataBlock = blockFactory.getNextBlock(blockTmp);
} else {
blockTmp = blockFactory.getNextBlock(blockTmp);
}
}
// create the tab box block
Block tabBoxBlock = new Block();
tabBoxBlock.type = "tabBox";
tabBoxBlock.setText("");
tabBoxBlock.bRender = true;
tabBoxBlock.column = block.column;
tabBoxBlock.line = block.line;
tabBoxBlock.name = "untitled";
tabBoxBlock.setOptionalAttribute("width", "" + getSelectionScreenZone().width);
tabBoxBlock.setOptionalAttribute("height", "" + getSelectionScreenZone().height);
// attach the tabBox element
tabBoxBlock.addOptionalChildren(tabBox);
// add the block to the block factory
blockFactory.insertBlock(tabBoxBlock, block);
// remove other blocks from the block factory
blockFactory.removeBlocks(tabBlocks);
// now attach all data blocks to the tabBoxBlock
// and remove them from the blockFactory
Block dataNextBlock = dataBlock;
do {
if (canBlockBeSelected(dataBlock)) {
tabBoxBlock.addOptionalChildren(dataBlock);
dataNextBlock = blockFactory.getNextBlock(dataBlock);
blockFactory.removeBlock(dataBlock);
dataBlock = dataNextBlock;
} else {
dataBlock = blockFactory.getNextBlock(dataBlock);
}
} while (dataBlock != null);
xrs.hasMatched = true;
xrs.newCurrentBlock = block;
return xrs;
}
Aggregations