Search in sources :

Example 26 with JavelinExtractionRuleResult

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;
}
Also used : JavelinExtractionRuleResult(com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult) Block(com.twinsoft.convertigo.beans.core.Block) RESyntaxException(org.apache.regexp.RESyntaxException)

Example 27 with JavelinExtractionRuleResult

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;
}
Also used : JavelinExtractionRuleResult(com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult) StringEx(com.twinsoft.util.StringEx)

Example 28 with JavelinExtractionRuleResult

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;
}
Also used : JavelinExtractionRuleResult(com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult) Block(com.twinsoft.convertigo.beans.core.Block) LinkedList(java.util.LinkedList)

Example 29 with JavelinExtractionRuleResult

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);
}
Also used : StringTokenizer(java.util.StringTokenizer) JavelinExtractionRuleResult(com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult) Block(com.twinsoft.convertigo.beans.core.Block)

Example 30 with JavelinExtractionRuleResult

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;
}
Also used : JavelinExtractionRuleResult(com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult)

Aggregations

JavelinExtractionRuleResult (com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult)39 Block (com.twinsoft.convertigo.beans.core.Block)24 LinkedList (java.util.LinkedList)5 StringTokenizer (java.util.StringTokenizer)5 Element (org.w3c.dom.Element)4 XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)3 XMLRectangle (com.twinsoft.convertigo.beans.common.XMLRectangle)2 EngineException (com.twinsoft.convertigo.engine.EngineException)2 RESyntaxException (org.apache.regexp.RESyntaxException)2 ACLNptuiComponent (com.eicon.iConnect.acl.ACLNptuiComponent)1 ACLNptuiScreen (com.eicon.iConnect.acl.ACLNptuiScreen)1 ACLNptuiWindow (com.eicon.iConnect.acl.ACLNptuiWindow)1 PanelBlockFactory (com.twinsoft.convertigo.beans.common.PanelBlockFactory)1 TabBox (com.twinsoft.convertigo.beans.common.TabBox)1 ExtractionRule (com.twinsoft.convertigo.beans.core.ExtractionRule)1 JavelinExtractionRule (com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRule)1 Nptui (com.twinsoft.convertigo.beans.sna.Nptui)1 EngineEvent (com.twinsoft.convertigo.engine.EngineEvent)1 StringEx (com.twinsoft.util.StringEx)1 File (java.io.File)1