Search in sources :

Example 16 with JavelinExtractionRuleResult

use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.

the class FieldsVT method execute.

public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
    JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
    // the block is a field
    xrs.hasMatched = true;
    xrs.newCurrentBlock = block;
    // setting type attribute
    block.type = "field";
    // setting name attribute
    block.name = "field_c" + block.column + "_l" + block.line;
    // setting size attribute
    block.setOptionalAttribute("size", Integer.toString(block.length));
    return (xrs);
}
Also used : JavelinExtractionRuleResult(com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult)

Example 17 with JavelinExtractionRuleResult

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

Example 18 with JavelinExtractionRuleResult

use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.

the class TrimBlock method execute.

public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
    JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
    String temp = block.getText();
    int len = temp.length();
    int firstNonSpace = 0;
    for (firstNonSpace = 0; firstNonSpace < len; firstNonSpace++) {
        if (temp.charAt(firstNonSpace) != ' ')
            break;
    }
    if (bTrimRight && bTrimLeft) {
        block.setText(temp.trim());
        // block.length = block.getText().length();
        // ==> block.setText already changes the length
        block.column += firstNonSpace;
        xrs.hasMatched = true;
        xrs.newCurrentBlock = block;
        return xrs;
    }
    if (bTrimRight) {
        block.setText(rtrim(temp));
        xrs.hasMatched = true;
        xrs.newCurrentBlock = block;
        return xrs;
    }
    if (bTrimLeft) {
        block.setText(ltrim(temp));
        block.column += firstNonSpace;
        xrs.hasMatched = true;
        xrs.newCurrentBlock = block;
        return xrs;
    }
    xrs.hasMatched = false;
    xrs.newCurrentBlock = block;
    return xrs;
}
Also used : JavelinExtractionRuleResult(com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult)

Example 19 with JavelinExtractionRuleResult

use of com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult in project convertigo by convertigo.

the class Separator method execute.

public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
    JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
    xrs.newCurrentBlock = block;
    xrs.hasMatched = false;
    String blockText = block.getText();
    int len = blockText.length();
    if (len <= nbOccurrences)
        return xrs;
    boolean found;
    int separatorCharactersLength = separatorCharacters.length();
    char c1, c2;
    int nbOcc = 0;
    for (int i = 0; i < separatorCharactersLength; i++) {
        found = true;
        c1 = separatorCharacters.charAt(i);
        for (int j = 0; j < len; j++) {
            c2 = blockText.charAt(j);
            if (c1 != c2) {
                found = false;
                if (j != 0)
                    return xrs;
                else
                    break;
            } else {
                nbOcc++;
            }
        }
        if (found && nbOcc >= nbOccurrences) {
            if (this.tagName.length() != 0)
                block.tagName = this.tagName;
            block.type = "separator";
            block.setOptionalAttribute("width", String.valueOf(nbOcc));
            block.setText("");
            xrs.hasMatched = true;
            xrs.newCurrentBlock = block;
            return xrs;
        }
    }
    return xrs;
}
Also used : JavelinExtractionRuleResult(com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult)

Example 20 with JavelinExtractionRuleResult

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

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