use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.
the class RemoveBlocks 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.
*/
protected JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
Block curBlock;
Block tempBlock;
int blockLen;
xrs.hasMatched = false;
// recreate the regular expression object.
if (regexp == null) {
try {
Engine.logBeans.debug("Setting regular expression to : " + regularExpression);
setRegularExpression(regularExpression);
} catch (RESyntaxException e) {
Engine.logBeans.error("Unable to create the regular expression object", e);
}
}
curBlock = block;
do {
tempBlock = blockFactory.getNextBlock(curBlock);
if (canBlockBeSelected(curBlock)) {
if ((blockTag.length() == 0) || blockTag.equalsIgnoreCase(curBlock.tagName)) {
blockLen = curBlock.getText().trim().length();
if ((length == -1) || (blockLen == length)) {
// Avoid to try to match on empty strings
if (blockLen != 0) {
if (regexp.match(curBlock.getText())) {
blockFactory.removeBlock(curBlock);
xrs.hasMatched = true;
}
} else {
blockFactory.removeBlock(curBlock);
xrs.hasMatched = true;
}
}
}
}
if (tempBlock == null)
break;
curBlock = tempBlock;
} while (true);
xrs.newCurrentBlock = curBlock;
return xrs;
}
use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.
the class ReplaceText 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();
// save the original len of the block
int len = block.length;
if (!regExp) {
StringEx strEx;
strEx = new StringEx(block.getText());
strEx.replaceAll(searchedText, replacedText);
block.setText(strEx.toString());
} else {
block.setText(block.getText().replaceAll(searchedText, replacedText));
}
// restore the len
block.length = len;
xrs.hasMatched = true;
xrs.newCurrentBlock = block;
return xrs;
}
use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.
the class Slider 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 startBlock = null;
Block blockTmp = null;
Collection<Block> blocksToDelete = new LinkedList<Block>();
boolean bEndBlockFound = false;
int ratio = 0;
int beginLine = -1;
// search of the start block
if (block.getText().trim().indexOf(startPattern) == 0 && block.length == 1) {
startBlock = block;
blocksToDelete.add(startBlock);
blockTmp = block;
// search of endPattern
while (blockFactory.getSouthBlock(blockTmp) != null && canBlockBeSelected(blockFactory.getSouthBlock(blockTmp)) && blockFactory.getSouthBlock(blockTmp).length == 1 && !bEndBlockFound) {
blockTmp = blockFactory.getSouthBlock(blockTmp);
// check if the block correspond to screenHiddenPattern or screenShowedPattern
if (blockTmp.getText().trim().indexOf(screenShowedPattern) == 0) {
ratio++;
if (beginLine == -1)
beginLine = blockTmp.line;
blocksToDelete.add(blockTmp);
} else if (blockTmp.getText().trim().indexOf(screenHiddenPattern) == 0) {
blocksToDelete.add(blockTmp);
} else if (blockTmp.getText().trim().indexOf(endPattern) == 0) {
blocksToDelete.add(blockTmp);
bEndBlockFound = true;
} else {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
}
if (!bEndBlockFound) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
} else {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return xrs;
}
Block mySlider = new Block();
mySlider.name = "untitled";
mySlider.type = "slider";
mySlider.setText("");
mySlider.bRender = true;
mySlider.line = startBlock.line;
mySlider.column = startBlock.column;
mySlider.setOptionalAttribute("width", "1");
mySlider.setOptionalAttribute("height", "" + (blockTmp.line - startBlock.line + 1));
mySlider.setOptionalAttribute("ratio", "" + ratio);
mySlider.setOptionalAttribute("begin", "" + beginLine);
blockFactory.insertBlock(mySlider, blockFactory.getPreviousBlock(block));
blockFactory.removeBlocks(blocksToDelete);
xrs.newCurrentBlock = mySlider;
xrs.hasMatched = true;
return xrs;
}
use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.
the class SplitBlock method execute.
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
Engine.logBeans.trace("Entering SplitBlock : " + block.getText() + " line :" + block.line + " col :" + block.column);
// create the tokenizer
StringTokenizer st = new StringTokenizer(block.getText(), delimiters, true);
if (st.countTokens() > 0) {
Block curBlock = blockFactory.getPreviousBlock(block);
Block tempBlock;
// variable lastIndex is used to adjust the column attribute of the created blocks
int lastIndex = 0;
if (keepDelimiters) {
while (st.hasMoreTokens()) {
// clones the original blocks in order to get the same attributes
try {
tempBlock = (Block) block.clone();
} catch (CloneNotSupportedException e) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return (xrs);
}
tempBlock.setText(st.nextToken());
// adjust the colum attribute
tempBlock.column = block.column + lastIndex;
// set lastIndex juste before the next token or delimiter
lastIndex += tempBlock.getText().length();
// insert the new sub block
blockFactory.insertBlock(tempBlock, curBlock);
Engine.logBeans.trace("SplitBlock new block: " + tempBlock.getText() + " line :" + tempBlock.line + " col :" + tempBlock.column);
// update the current block
curBlock = tempBlock;
}
} else {
String pattern;
while (st.hasMoreTokens()) {
pattern = st.nextToken();
if (delimiters.indexOf(pattern.charAt(0)) == -1) {
// clones the original blocks in order to get the same attributes
try {
tempBlock = (Block) block.clone();
} catch (CloneNotSupportedException e) {
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return (xrs);
}
tempBlock.setText(pattern);
// adjust the colum attribute
tempBlock.column = block.column + lastIndex;
// insert the new sub block
blockFactory.insertBlock(tempBlock, curBlock);
Engine.logBeans.trace("SplitBlock new block: " + tempBlock.getText() + " line :" + tempBlock.line + " col :" + tempBlock.column);
// update the current block
curBlock = tempBlock;
}
// set lastIndex juste before the next token or delimiter
lastIndex += pattern.length();
}
}
// once all tokens have been inserted, remove the original block
Engine.logBeans.trace("Exiting SplitBlock : " + block.getText());
if (curBlock != null)
Engine.logBeans.trace("currentBlock : " + curBlock.getText() + " line :" + curBlock.line + " col :" + curBlock.column);
blockFactory.removeBlock(block);
xrs.hasMatched = true;
xrs.newCurrentBlock = curBlock;
return (xrs);
}
Engine.logBeans.trace("Exiting SplitBlock without change : " + block.getText());
xrs.hasMatched = false;
xrs.newCurrentBlock = block;
return (xrs);
}
use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.
the class MoveBlocks method execute.
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
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;
}
// block's move
if (isRelative()) {
// search the move to apply
int x = (getSelectionScreenZone().x != -1 ? getSelectionScreenZone().x : 0);
int y = (getSelectionScreenZone().y != -1 ? getSelectionScreenZone().y : 0);
// moves the block itself
block.column = block.column + fieldDesc.x - x;
block.line = block.line + fieldDesc.y - y;
// // moves the sub-elements
// disabled because extended mode panels children are treated by selecting the apply extraction rules in panels property
// and old fashioned panels children are treated because they are still referenced into the block factory
// Iterator ite = block.optionalChildren.iterator();
// Element elem;
// Block blk;
// Object obj;
// while (ite.hasNext()) {
// obj = ite.next();
// if (obj instanceof Element) {
// elem = (Element)obj;
// // moves element's line
// if (elem.hasAttribute("line"))
// elem.setAttribute("line", "" + (Integer.parseInt(elem.getAttribute("line")) + fieldDesc.y - y));
// // moves element's column
// if (elem.hasAttribute("column"))
// elem.setAttribute("column", "" + (Integer.parseInt(elem.getAttribute("column")) + fieldDesc.x - x));
// } else if (obj instanceof Block) {
// blk = (Block)obj;
// // moves element's line
// blk.line = blk.line + fieldDesc.y - y;
// // moves element's column
// blk.column = blk.column + fieldDesc.x - x;
// }
// }
} else {
// moves the block itself
block.column = fieldDesc.x;
block.line = fieldDesc.y;
// // moves the sub-elements
// disabled because extended mode panels children are treated by selecting the apply extraction rules in panels property
// and old fashioned panels children are treated because they are still referenced into the block factory
// Iterator ite = block.optionalChildren.iterator();
// Element elem;
// Block blk;
// Object obj;
// while (ite.hasNext()) {
// obj = ite.next();
// if (obj instanceof Element) {
// elem = (Element)obj;
// // moves element's line
// if (elem.hasAttribute("line")) {
// elem.removeAttribute("line");
// elem.setAttribute("line", "" + fieldDesc.x);
// }
// // moves element's column
// if (elem.hasAttribute("column")) {
// elem.removeAttribute("column");
// elem.setAttribute("column", "" + fieldDesc.y);
// }
// } else if (obj instanceof Block) {
// blk = (Block)obj;
// // moves element's line
// blk.line = blk.line + fieldDesc.y;
// // moves element's column
// blk.column = blk.column + fieldDesc.x;
// }
// }
}
xrs.hasMatched = true;
xrs.newCurrentBlock = block;
return xrs;
}
Aggregations