use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult 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;
}
use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.
the class Radio 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;
Block nextBlock;
XMLVector<XMLVector<Object>> foundOptions = new XMLVector<XMLVector<Object>>();
Collection<Block> blocksToDelete = new LinkedList<Block>();
String currentOption = "";
String direction = "horizontal";
boolean bLastBlock = false;
if (bFirstTime) {
if (radioDesc.x != -1 && radioDesc.y != -1) {
// defined radio button
if (radioDesc.width == -1)
radioDesc.width = 1;
if (radioDesc.height == -1)
radioDesc.height = 1;
} else if (!separatorChars.equals("")) {
// if no position is defined and separator is defined
// searching all radio buttons on the screen
bSearch = true;
bFirstTime = false;
} else if (!options.isEmpty()) {
// initialize the position of the radio button
if (radioDesc.x == -1)
radioDesc.x = 0;
if (radioDesc.y == -1)
radioDesc.y = 0;
if (radioDesc.width == -1)
radioDesc.width = 1;
if (radioDesc.height == -1)
radioDesc.height = 1;
} else {
// no position, no separator, no options defined
// use default check pattern
separatorChars = ". ";
// searching all radio buttons on the screen
bSearch = true;
bFirstTime = false;
}
}
if (bSearch) {
nextBlock = blockFactory.getNextBlock(block);
// if next block = null or is not on the same line : not matching
if (nextBlock == null || nextBlock.line != block.line) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
// if block is a field and next block is a matching option
if (block.type.equals("field") && nextBlock != null && canBlockBeSelected(nextBlock) && nextBlock.type.equals("static") && nextBlock.getText().indexOf(separatorChars) != -1) {
// first option found
foundOptions.add(createOption(nextBlock));
blocksToDelete.add(nextBlock);
currentOption = block.getText().trim();
// searching for the direction of options
if (blockFactory.getEastBlock(nextBlock) != null && canBlockBeSelected(blockFactory.getEastBlock(nextBlock)) && blockFactory.getEastBlock(nextBlock).type.equals("static") && blockFactory.getEastBlock(nextBlock).getText().indexOf(separatorChars) != -1) {
// options are on the same line
direction = "horizontal";
do {
nextBlock = blockFactory.getEastBlock(nextBlock);
foundOptions.add(createOption(nextBlock));
blocksToDelete.add(nextBlock);
} while (blockFactory.getEastBlock(nextBlock) != null && canBlockBeSelected(blockFactory.getEastBlock(nextBlock)) && blockFactory.getEastBlock(nextBlock).type.equals("static") && blockFactory.getEastBlock(nextBlock).getText().indexOf(separatorChars) != -1);
} else if (blockFactory.getSouthBlock(nextBlock) != null && canBlockBeSelected(blockFactory.getSouthBlock(nextBlock)) && blockFactory.getSouthBlock(nextBlock).type.equals("static") && blockFactory.getSouthBlock(nextBlock).getText().indexOf(separatorChars) != -1) {
// options are on the same column
direction = "vertical";
do {
nextBlock = blockFactory.getSouthBlock(nextBlock);
foundOptions.add(createOption(nextBlock));
blocksToDelete.add(nextBlock);
} while (blockFactory.getSouthBlock(nextBlock) != null && canBlockBeSelected(blockFactory.getSouthBlock(nextBlock)) && blockFactory.getSouthBlock(nextBlock).type.equals("static") && blockFactory.getSouthBlock(nextBlock).getText().indexOf(separatorChars) != -1);
} else // no other option
{
}
} else {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
} else if (bAdded) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
if (!bAdded || bSearch) {
bFirstTime = false;
if (!bSearch) {
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 checkbox just before
if (block.line < radioDesc.y) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
} else if (block.line == radioDesc.y) {
if (block.column < radioDesc.x) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
}
}
}
Block myRadio;
// build result block
if (bSearch) {
myRadio = block;
// add the options
for (List<Object> op : foundOptions) {
Element element = dom.createElement("item");
element.setAttribute("action", (String) op.get(0));
element.setAttribute("value", (String) op.get(1));
element.setAttribute("column", String.valueOf((Integer) op.get(2)));
element.setAttribute("line", String.valueOf((Integer) op.get(3)));
element.setAttribute("selected", currentOption.equalsIgnoreCase((String) op.get(0)) ? "true" : "false");
myRadio.addOptionalChildren(element);
}
} else {
myRadio = new Block();
myRadio.bRender = true;
myRadio.name = "untitled";
myRadio.line = radioDesc.y;
myRadio.column = radioDesc.x;
if (bLastBlock) {
blockFactory.insertBlock(myRadio, block);
} else {
blockFactory.insertBlock(myRadio, blockFactory.getPreviousBlock(block));
}
// add the options
int item = 0;
for (List<Object> op : options) {
Element element = dom.createElement("item");
element.setAttribute("action", (String) op.get(1));
element.setAttribute("value", (String) op.get(0));
element.setAttribute("column", String.valueOf(radioDesc.x));
element.setAttribute("line", String.valueOf(radioDesc.y + item));
item++;
element.setAttribute("selected", "false");
myRadio.addOptionalChildren(element);
}
}
myRadio.setText("");
myRadio.type = "radio";
myRadio.setOptionalAttribute("radio", "true");
myRadio.setOptionalAttribute("direction", direction);
// remove old blocks
blockFactory.removeBlocks(blocksToDelete);
bAdded = true;
xrs.newCurrentBlock = bSearch ? myRadio : block;
xrs.hasMatched = true;
}
return xrs;
}
use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.
the class MergeBlocks method execute.
/**
* Applies the extraction rule to the current iJavelin object.
*
* @param javelin the Javelin object.
* @param block the current block to analyze.
* @param blockFactory the block context of the current block.
* @param dom the XML DOM.
*
* @return an ExtractionRuleResult object containing the result of
* the query.
*/
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
Block curBlock;
Block tempBlock;
curBlock = block;
xrs.hasMatched = false;
if (canBlockBeSelected(curBlock)) {
tempBlock = blockFactory.getNextBlock(curBlock);
if ((tempBlock == null) || (tempBlock.line != curBlock.line && !bMultilineMerge) || (!canBlockBeSelected(tempBlock)) || (tempBlock.bFinal)) {
bAccumulating = false;
xrs.newCurrentBlock = curBlock;
return xrs;
} else {
if (tempBlock.line != curBlock.line) {
curBlock.setText(curBlock.getText() + multilineSeparatorChar);
}
if (separationPattern.equals("")) {
// Ignore separator
Engine.logBeans.trace("merging curBlock : line,col " + curBlock.line + "," + curBlock.column + " text [" + curBlock.getText() + "]");
Engine.logBeans.trace("and tempBlock : line,col " + tempBlock.line + "," + tempBlock.column + " text [" + tempBlock.getText() + "]");
blockFactory.mergeBlocks(curBlock, tempBlock);
bAccumulating = true;
xrs.hasMatched = true;
xrs.newCurrentBlock = blockFactory.getPreviousBlock(curBlock);
return xrs;
} else if (tempBlock.getText().equalsIgnoreCase(separationPattern)) {
// next block is a separator block so merge it in our block
Engine.logBeans.trace("merging curBlock : line,col " + curBlock.line + "," + curBlock.column + " text [" + curBlock.getText() + "]");
Engine.logBeans.trace("and tempBlock : line,col " + tempBlock.line + "," + tempBlock.column + " text [" + tempBlock.getText() + "]");
blockFactory.mergeBlocks(curBlock, tempBlock);
tempBlock = blockFactory.getNextBlock(curBlock);
if ((tempBlock != null) && ((tempBlock.line == curBlock.line) || (tempBlock.line != curBlock.line && bMultilineMerge)) && (canBlockBeSelected(tempBlock)) && (!tempBlock.bFinal) && (!tempBlock.getText().equalsIgnoreCase(separationPattern))) {
blockFactory.mergeBlocks(curBlock, tempBlock);
// the engine will fetch the nect block but this rule
// needs to restart with the same block !!
// so position the currentBlock on the prevous block
bAccumulating = true;
xrs.hasMatched = true;
xrs.newCurrentBlock = blockFactory.getPreviousBlock(curBlock);
return xrs;
}
}
}
}
bAccumulating = false;
xrs.newCurrentBlock = curBlock;
return xrs;
}
use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.
the class Panel method execute.
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
/*
* consider any form of text :
*
* UL t t t t t t t t t UR l R l R LL b b b b b b b b b LR
*
* to be a panel.
*
* UL : upperLeft UR : upperRight LL : lowerLeft LR : lowerRight l :
* left r : right t : top b : bottom
*
*/
boolean isSelected = isSelectedPanel();
if (initialize && isSelected) {
initialize = false;
Block myPanel = new Block();
myPanel.name = getName();
myPanel.type = "panel";
myPanel.setText("");
myPanel.bRender = true;
myPanel.line = getSelectionScreenZone().y;
myPanel.column = getSelectionScreenZone().x;
myPanel.setOptionalAttribute("width", "" + getSelectionScreenZone().width);
myPanel.setOptionalAttribute("height", "" + getSelectionScreenZone().height);
myPanel.setOptionalAttribute("topTitle", topTitle);
myPanel.setOptionalAttribute("bottomTitle", bottomTitle);
Block curBlock = blockFactory.getFirstBlock();
block = null;
while ((curBlock = blockFactory.getNextBlock(curBlock)) != null) {
if (isBlockInSelection(curBlock, getSelectionScreenZone())) {
myPanel.addOptionalChildren(curBlock);
// we mark the first block that goes inside the panel
if (block == null)
block = curBlock;
}
}
// we insert the panel to the blockfactory, before the first block
// inside the panel
blockFactory.insertBlock(myPanel, blockFactory.getPreviousBlock(block));
xrs.newCurrentBlock = blockFactory.getLastBlock();
return xrs;
}
// blockFactory
if (initialize) {
listCandidate = new LinkedList<PanelCandidate>();
lePanel = null;
screenHeight = javelin.getScreenHeight();
screenWidth = javelin.getScreenWidth();
int curLine = 0, curColumn = 0;
while (curLine < screenHeight) {
while (curColumn < screenWidth) {
// check if current character matches UL corner of a panel
if (charMatchesUpperLeft(javelin, javelin.getChar(curColumn, curLine), javelin.getCharAttribute(curColumn, curLine)) && !coordinateInExistantPanel((new Coordinates(curColumn, curLine)))) {
// Engine.logBeans.trace("PANEL TROUVE en " + curColumn + " " +curLine);
checkClosedContours(javelin, curColumn, curLine);
}
curColumn++;
}
curColumn = 0;
curLine++;
}
// do not execute the instructions above next time (on the other
// blocks)
initialize = false;
// print the found panel
for (PanelCandidate unPanel : listCandidate) {
if (unPanel.factor >= minSides) {
Engine.logBeans.trace("Found closed panel : l=" + unPanel.UL.line + ", c=" + unPanel.UL.column);
lePanel = unPanel;
xrs.hasMatched = true;
// panel
if (lePanel != null) {
XMLRectangle laScreenZone = new XMLRectangle(lePanel.UL.column, lePanel.UL.line, lePanel.UR.column - lePanel.UL.column, lePanel.LR.line - lePanel.UR.line);
Engine.logBeans.trace("Entry with " + block.getText());
Engine.logBeans.trace("Panel : " + "column=" + lePanel.UL.column + ", line=" + lePanel.UL.line + ", width=" + (lePanel.UR.column - lePanel.UL.column) + ", height=" + (lePanel.LR.line - lePanel.UR.line));
if (laScreenZone.width > 1 && laScreenZone.height > 1) {
Block myPanel = new Block();
myPanel.name = getName();
myPanel.type = "panel";
myPanel.setText("");
myPanel.bRender = true;
myPanel.line = laScreenZone.y;
myPanel.column = laScreenZone.x;
myPanel.setOptionalAttribute("width", "" + laScreenZone.width);
myPanel.setOptionalAttribute("height", "" + laScreenZone.height);
myPanel.setOptionalAttribute("topTitle", lePanel.topTitle);
myPanel.setOptionalAttribute("bottomTitle", lePanel.bottomTitle);
Block curBlock = blockFactory.getFirstBlock();
block = null;
do {
Engine.logBeans.trace("Testing " + curBlock);
if (isBlockInSelection(curBlock, laScreenZone)) {
// right + left + upperLeft))
if (isBlockInBorder(curBlock, laScreenZone) && removeBlocksInBorder) {
Block bToRemove = curBlock;
curBlock = blockFactory.getPreviousBlock(curBlock);
blockFactory.removeBlock(bToRemove);
Engine.logBeans.trace("Removing " + bToRemove);
} else {
myPanel.addOptionalChildren(curBlock);
// inside the panel
if (block == null)
block = curBlock;
}
}
} while ((curBlock = blockFactory.getNextBlock(curBlock)) != null);
// we insert the panel to the blockfactory, before
// the first block inside the panel
blockFactory.insertBlock(myPanel, blockFactory.getPreviousBlock(block));
xrs.newCurrentBlock = blockFactory.getLastBlock();
return xrs;
} else {
Engine.logBeans.debug("Invalid panel found (width = 0 or height = 0)");
continue;
}
} else
return xrs;
}
}
return xrs;
}
return xrs;
}
use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.
the class Field 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;
boolean bLastBlock = false;
if (bFirstTime) {
bFirstTime = false;
if (fieldDesc.x == -1)
fieldDesc.x = 0;
if (fieldDesc.y == -1)
fieldDesc.y = 0;
if (fieldDesc.width == -1)
fieldDesc.width = 6;
if (fieldDesc.height == -1)
fieldDesc.height = 1;
}
// if field has already been added to the blocks
if (bAdded) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
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 field just before
if (block.line < fieldDesc.y) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
} else if (block.line == fieldDesc.y) {
if (block.column < fieldDesc.x) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
}
}
// block matches : add the field block
Block myField = new Block();
myField.name = Name;
myField.type = Type;
myField.setText(Value);
myField.bRender = true;
myField.line = fieldDesc.y;
myField.column = fieldDesc.x;
myField.setOptionalAttribute("hasFocus", "false");
myField.setOptionalAttribute("size", Integer.toString(fieldDesc.width));
myField.attribute = fieldAttrb;
addMashupAttribute(myField);
if (bLastBlock) {
blockFactory.insertBlock(myField, block);
} else {
blockFactory.insertBlock(myField, blockFactory.getPreviousBlock(block));
}
bAdded = true;
xrs.newCurrentBlock = block;
xrs.hasMatched = true;
return xrs;
}
Aggregations