use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class Table method writeColumns.
private void writeColumns(Block row) {
if (!isEmpty() && columns.size() <= colonDispatch.size()) {
Block item;
int i = 0;
for (TableColumn tc : columns) {
Block blk = colonDispatch.get(i);
if (blk == null) {
item = new Block();
item.name = "";
item.type = "static";
item.setText("");
} else
item = blk;
String columnTagName = "undefined";
if (tc.title.length() > 0) {
columnTagName = StringUtils.normalize(tc.title, false);
if (columnTagName.equals(""))
columnTagName = "col" + i;
}
item.tagName = columnTagName;
if (columnSelection == i)
item.setOptionalAttribute("columnSelection", "true");
row.addOptionalChildren(item);
++i;
}
}
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class Table method dispatchBlockInColumn.
private void dispatchBlockInColumn(Block block) {
Block blockTmp;
int overlapFactor, bestOverlapFactor = 0, indexRightColumn = 0;
int relLineInTable;
GenericUtils.setListSize(colonDispatch, columns.size());
max_index = getMax_index();
int nbLineForARecord = max_index + 1;
int i = 0;
for (TableColumn tc : columns) {
Engine.logBeans.trace("");
overlapFactor = getOverlapFactor(block, tc);
relLineInTable = block.line - firstLine;
Engine.logBeans.trace("OverlapFactor: " + overlapFactor + " for this block " + block.getText() + " and the column " + tc.title);
Engine.logBeans.trace("BLOCK = " + block.getText() + ", relLineInTable=" + relLineInTable + ", nbLineForARecord=" + nbLineForARecord + ", (relLineInTable % nbLineForARecord)=" + (relLineInTable % nbLineForARecord) + ", tc.lineIndex=" + tc.lineIndex);
if ((tc.lineIndex == (relLineInTable % nbLineForARecord)) && (overlapFactor > bestOverlapFactor)) {
bestOverlapFactor = overlapFactor;
indexRightColumn = i;
}
++i;
}
if (bestOverlapFactor != 0) {
if (colonDispatch.get(indexRightColumn) != null) {
// there is already a block dispatched in this column, append the text of the new block to the existing one
blockTmp = colonDispatch.get(indexRightColumn);
colonDispatch.remove(indexRightColumn);
block.setText(blockTmp.getText() + " " + block.getText());
// update the block column to the initial column
block.column = blockTmp.column;
}
Engine.logBeans.trace("insert block " + block.getText() + " in column " + columns.get(indexRightColumn).title);
colonDispatch.add(indexRightColumn, block);
} else
Engine.logBeans.trace("block " + block.getText() + " inserted nowhere (bestOvelapFactor = 0)");
}
use of com.twinsoft.convertigo.beans.core.Block 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.core.Block 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.core.Block 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;
}
Aggregations