use of com.twinsoft.convertigo.beans.core.Block 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;
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class Image 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) {
if (imageDesc.x == -1)
imageDesc.x = 0;
if (imageDesc.y == -1)
imageDesc.y = 0;
if (!keepSize) {
if (imageDesc.width == -1)
imageDesc.width = -1;
if (imageDesc.height == -1)
imageDesc.height = -1;
}
bFirstTime = false;
}
// if image 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 block matches to add the block image just before
if (block.line < imageDesc.y) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
} else if (block.line == imageDesc.y) {
if (block.column < imageDesc.x) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
}
}
// block matches : create image block
Block myImage = new Block();
myImage.name = "untitled";
myImage.type = "image";
myImage.setText("");
myImage.bRender = true;
myImage.column = imageDesc.x;
myImage.line = imageDesc.y;
myImage.setOptionalAttribute("url", url);
myImage.setOptionalAttribute("alt", label);
if (!keepSize) {
myImage.setOptionalAttribute("width", "" + imageDesc.width);
myImage.setOptionalAttribute("height", "" + imageDesc.height);
}
if (!action.equals(""))
myImage.setOptionalAttribute("action", action);
if (doTransaction)
myImage.setOptionalAttribute("dotransaction", "true");
if (!zOrder.equals(""))
myImage.setOptionalAttribute("z-order", zOrder);
addMashupAttribute(myImage);
if (bLastBlock) {
blockFactory.insertBlock(myImage, block);
} else {
blockFactory.insertBlock(myImage, blockFactory.getPreviousBlock(block));
}
bAdded = true;
xrs.hasMatched = true;
xrs.newCurrentBlock = block;
return xrs;
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class SplitFields 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) {
if (tab == null) {
tab = getBestSplitWith(separatorTableStart, separatorTableEnd);
}
if (row == null) {
row = getBestSplitWith(separatorRowStart, separatorRowEnd);
}
if (cel == null) {
cel = getBestSplitWith(separatorCelStart, separatorCelEnd);
}
if (cols == null) {
setColumns(columns);
}
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
Block curBlock = block;
StringBuffer strbuf = new StringBuffer();
while (!canBlockBeSelected(curBlock) && curBlock != null) {
curBlock = blockFactory.getNextBlock(curBlock);
}
if (curBlock == null) {
Engine.logBeans.trace("SplitFields extraction have no block");
xrs.hasMatched = false;
xrs.newCurrentBlock = curBlock;
return xrs;
}
Block tmpBlock = new Block();
tmpBlock.setText("");
blockFactory.insertBlock(tmpBlock, blockFactory.getPreviousBlock(block));
while (curBlock != null) {
if (canBlockBeSelected(curBlock)) {
strbuf.append(curBlock.getText());
curBlock = blockFactory.getNextBlock(curBlock);
// blockFactory.removeBlock(exBlock);
} else {
curBlock = blockFactory.getNextBlock(curBlock);
}
}
Block lastBlock = tmpBlock;
int tab_count = 1;
for (String ltab : tab.splitWith(strbuf.toString())) {
Block tableBlock;
if (accumulatedData == null || doNotAccumulate) {
tableBlock = new Block();
accumulatedData = tableBlock;
blockFactory.insertBlock(tableBlock, lastBlock);
// OPIC : Changed name to name of the rule instead of tagName. This is to avoid
// A CPU loop in getNextBlock. As block equality is done by comparing blocks by
// tagName and attributes. If all attibutes are the same, the routine goes in CPU loop.
tableBlock.name = this.getName() + "_" + (tab_count++);
tableBlock.type = "table";
tableBlock.tagName = tagTable;
tableBlock.setText("");
} else {
tableBlock = accumulatedData;
}
lastBlock = tableBlock;
for (String lrow : row.splitWith(ltab)) {
Block rowBlock = new Block();
rowBlock.name = "";
rowBlock.type = "row";
rowBlock.tagName = "row";
rowBlock.setText("");
tableBlock.addOptionalChildren(rowBlock);
int i = 0;
for (String lcel : cel.splitWith(lrow)) {
Block celBlock = new Block();
celBlock.name = "";
celBlock.type = "static";
celBlock.tagName = (cols.length > i++) ? cols[i - 1] : "block";
celBlock.setText(lcel);
rowBlock.addOptionalChildren(celBlock);
}
}
}
xrs.hasMatched = (lastBlock != tmpBlock) ? true : false;
// xrs.hasMatched = true;
// blockFactory.getNextBlock(lastBlock);
xrs.newCurrentBlock = blockFactory.getLastBlock();
blockFactory.removeBlock(tmpBlock);
return xrs;
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class DefaultBlockFactory method convertUnformattedScreen.
private void convertUnformattedScreen() {
int lastAttribute, currentAttribute;
int startx;
String text;
for (int y = 0; y < nbLines; y++) {
startx = 0;
lastAttribute = javelin.getCharAttribute(0, y);
for (int x = 1; x < nbColumns; x++) {
currentAttribute = javelin.getCharAttribute(x, y);
if (currentAttribute != lastAttribute) {
// Inserting a new block
Block block = new Block();
block.line = y;
block.column = x;
block.length = x - startx;
block.attribute = lastAttribute;
text = formatString(javelin.getString(startx, y, block.length));
if (((javelin.getTerminalClass().equals(iJavelin.VDX)) || (javelin.getTerminalClass().equals(iJavelin.VT)) || (block.attribute & iJavelin.AT_FIELD_PROTECTED) > 0)) {
block.type = "static";
block.setText(text);
} else {
block.type = "field";
block.setText(rightTrim(text));
setBlockName(block);
setupFieldBlock(block, lastAttribute);
}
block.line = y;
block.column = startx;
list.add(block);
// Updating temporary variables
lastAttribute = currentAttribute;
startx = x;
}
}
// Inserting the last block
Block block = new Block();
block.line = y;
block.column = startx;
block.attribute = lastAttribute;
block.length = nbColumns - startx;
block.setText(javelin.getString(startx, y, block.length));
if (((javelin.getTerminalClass().equals(iJavelin.VDX)) || (javelin.getTerminalClass().equals(iJavelin.VT)) || (block.attribute & iJavelin.AT_FIELD_PROTECTED) > 0)) {
block.type = "static";
block.setText(javelin.getString(startx, y, block.length));
} else {
block.type = "field";
setBlockName(block);
block.setOptionalAttribute("size", "" + block.length);
}
list.add(block);
}
}
use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.
the class DefaultBlockFactory method createFiller.
void createFiller(int index) {
int line = javelin.getFieldLine(index);
int column = javelin.getFieldColumn(index);
Block block = new Block();
block.setText(" ");
if (column == 0) {
block.line = line - 1;
if (block.line == -1)
block.line = javelin.getScreenHeight() - 1;
block.column = javelin.getScreenWidth() - 1;
} else {
block.line = line;
block.column = column - 1;
}
block.attribute = javelin.getCharAttribute(block.column, block.line);
block.type = "filler";
block.length = 1;
setBlockName(block);
list.add(block);
}
Aggregations