use of com.twinsoft.convertigo.beans.common.PanelBlockFactory in project convertigo by convertigo.
the class JavelinTransaction method searchPanelsAndApplyExtractionRules.
public void searchPanelsAndApplyExtractionRules(JavelinScreenClass screenClass, BlockFactory blockFactory, iJavelin javelin, boolean bNotFirstLoop) throws EngineException {
// if there are panel type blocks, apply extraction rules on the panel block children
Block tmpBlock = null;
try {
tmpBlock = blockFactory.getFirstBlock();
} catch (NoSuchElementException e) {
Engine.logContext.trace("(JavelinTransaction) Cannot apply extraction rules in panels : no block left in block factory.");
return;
}
PanelBlockFactory bf = null;
while (tmpBlock != null) {
if (tmpBlock.type.equals("panel") || tmpBlock.type.equals("container") || tmpBlock.type.equals("tabBox")) {
// creation of a BlockFactory containing the child blocks
try {
bf = PanelBlockFactory.cloneBlockFactory((DefaultBlockFactory) blockFactory);
} catch (CloneNotSupportedException e) {
throw new EngineException("(JavelinTransaction) Exception when cloning blockFactory", e);
}
bf.setName("Panel_block_factory");
bf.make(tmpBlock);
if (tmpBlock.type.equals("panel")) {
// if type = panel, apply extraction rules
Engine.logContext.trace("(JavelinTransaction) Applying extraction rules in a panel.");
applyExtractionRules(screenClass, bf, javelin, bNotFirstLoop);
Engine.logContext.trace("(JavelinTransaction) End applying extraction rules in a panel.");
// replace panel content with blockFactory blocks
tmpBlock.clearOptionalChildren();
for (Block block : bf.list) tmpBlock.addOptionalChildren(block);
} else if (tmpBlock.type.equals("container") || tmpBlock.type.equals("tabBox")) {
// if type = container or tabBox, recurse on this method to find inside panels
searchPanelsAndApplyExtractionRules(screenClass, bf, javelin, bNotFirstLoop);
}
}
// go on the next block
tmpBlock = blockFactory.getNextBlock(tmpBlock);
}
}
use of com.twinsoft.convertigo.beans.common.PanelBlockFactory in project convertigo by convertigo.
the class JavelinTransaction method applyExtractionRules.
public void applyExtractionRules(JavelinScreenClass screenClass, BlockFactory blockFactory, iJavelin javelin, boolean bNotFirstLoop) throws EngineException {
String t = context.statistics.start(EngineStatistics.APPLY_EXTRACTION_RULES);
try {
// We apply the extraction rules for this screen class to
// the words list.
Block block = null;
JavelinExtractionRuleResult extractionRuleResult;
int extractionRuleInitReason;
boolean panelExtractionRuleFound = false;
List<ExtractionRule> vExtractionRules = screenClass.getExtractionRules();
for (ExtractionRule extractionRule : vExtractionRules) {
JavelinExtractionRule javelinExtractionRule = (JavelinExtractionRule) extractionRule;
if (!runningThread.bContinue)
break;
/*
if ((Engine.objectsProvider == null) && !javelin.isConnected()) {
throw new ConnectionException("The emulator has been disconnected! See the emulator logs for more details...");
}
*/
blockFactory.moveToFirstBlock();
if (!extractionRule.isEnabled()) {
// if extraction rule is disabled
Engine.logContext.trace("(JavelinTransaction) Skipping the extraction rule \"" + extractionRule.getName() + "\" because it has been disabled.");
continue;
}
if (blockFactory instanceof PanelBlockFactory && !panelExtractionRuleFound) {
// if we apply the rules in a panel and the rule is before the rule which has created the panel
Engine.logContext.trace("(JavelinTransaction) Skipping the extraction rule \"" + extractionRule.getName() + "\" because it has been applied before the panel creation.");
if (extractionRule instanceof Nptui)
panelExtractionRuleFound = true;
continue;
}
if (blockFactory instanceof PanelBlockFactory && extractionRule instanceof TabBox) {
// if we try to apply tabbox rule in a panel
Block panel = ((PanelBlockFactory) blockFactory).getPanel();
XMLRectangle zone = ((TabBox) extractionRule).getSelectionScreenZone();
if (zone.contains(panel.column, panel.line, Integer.parseInt(panel.getOptionalAttribute("width")), Integer.parseInt(panel.getOptionalAttribute("height")))) {
// if the tabbox screen zone is larger than the panel
Engine.logContext.trace("(JavelinTransaction) Skipping the extraction rule \"" + extractionRule.getName() + "\" because the screen zone is larger than the panel.");
continue;
}
}
Engine.logContext.debug("(JavelinTransaction) Applying the extraction rule \"" + extractionRule.getName() + "\" on blocks");
String extractionRuleQName = extractionRule.getQName();
if (vExtractionRulesInited.contains(extractionRuleQName)) {
extractionRuleInitReason = ExtractionRule.ACCUMULATING;
} else {
extractionRuleInitReason = ExtractionRule.INITIALIZING;
vExtractionRulesInited.add(extractionRuleQName);
}
Engine.logContext.trace("(JavelinTransaction) Initializing extraction rule (reason = " + extractionRuleInitReason + ")...");
extractionRule.init(extractionRuleInitReason);
// We fire engine events only in studio mode.
if (Engine.isStudioMode()) {
Engine.theApp.fireObjectDetected(new EngineEvent(extractionRule));
}
// We try to apply the current extraction rule on each block.
while (runningThread.bContinue && ((block = blockFactory.getNextBlock(block)) != null)) {
Engine.logContext.trace("(JavelinTransaction) Analyzing block \"" + block.getText() + "\"");
// We skip final blocks.
if (block.bFinal) {
Engine.logContext.trace("(JavelinTransaction) The block has been marked as final; skipping it.");
continue;
}
extractionRuleResult = javelinExtractionRule.apply(javelin, block, blockFactory, context.outputDocument);
if (extractionRuleResult.hasMatched) {
// extraction rules on this block and pass on the next block.
if (javelinExtractionRule.isFinal()) {
block.bFinal = true;
Engine.logContext.trace("(JavelinTransaction) Applying extraction rule '" + extractionRule.getName() + "': matching and final");
} else {
Engine.logContext.trace("(JavelinTransaction) Applying extraction rule '" + extractionRule.getName() + "': matching");
}
// We need to update the current block only if the
// rule has matched.
block = extractionRuleResult.newCurrentBlock;
} else {
Engine.logContext.trace("(JavelinTransaction) Applying extraction rule '" + extractionRule.getName() + "': not matching");
}
}
// We fire engine events only in studio mode.
if (Engine.isStudioMode()) {
Engine.theApp.fireBlocksChanged(new EngineEvent(blockFactory));
Engine.logContext.debug("(JavelinTransaction) Step reached after having applied the extraction rule \"" + extractionRule.getName() + "\".");
Engine.theApp.fireStepReached(new EngineEvent(extractionRule));
}
}
vExtractionRules = null;
extractionRuleResult = null;
} finally {
context.statistics.stop(t, bNotFirstLoop);
}
}
Aggregations