Search in sources :

Example 1 with Block

use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.

the class JavelinTransaction method renderBlocksToXml.

private void renderBlocksToXml(List<Collection<Block>> vBlocks) throws EngineException {
    String t = context.statistics.start(EngineStatistics.GENERATE_DOM);
    try {
        Enumeration<Collection<Block>> enumBlocks = Collections.enumeration(vBlocks);
        Map<String, String> types = null;
        int nPage = 0;
        Element page = null;
        Element outputDocumentRootElement = context.outputDocument.getDocumentElement();
        outputDocumentRootElement.setAttribute("transaction", context.transactionName);
        outputDocumentRootElement.setAttribute("connector", context.connectorName);
        String prefix = getXsdTypePrefix();
        String transactionName = context.transactionName;
        boolean studioMode = Engine.isStudioMode();
        if (studioMode) {
            types = new HashMap<String, String>(5);
            xsdType = "";
            xsdType += "<xsd:complexType name=\"" + prefix + transactionName + "Response\">\n";
            xsdType += "\t<xsd:sequence>\n";
            xsdType += "\t\t<xsd:element name=\"error\" minOccurs=\"0\" maxOccurs=\"1\" type=\"p_ns:ConvertigoError\"/>\n";
        }
        if (!isRemoveBlocksNode()) {
            xsdType += "\t\t<xsd:element name=\"blocks\" minOccurs=\"1\" maxOccurs=\"unbounded\" type=\"p_ns:" + prefix + transactionName + "_blocksType\"/>\n";
            xsdType += "\t</xsd:sequence>\n";
            xsdType += "</xsd:complexType>\n";
            xsdType += "<xsd:complexType name=\"" + prefix + transactionName + "_blocksType\">\n";
            xsdType += "\t<xsd:sequence>\n";
        }
        if (onlyOnePage) {
            Engine.logContext.debug("(JavelinTransaction) Creating the unique page item into the XML document");
            page = context.outputDocument.createElement("blocks");
            outputDocumentRootElement.appendChild(page);
        }
        while (enumBlocks.hasMoreElements()) {
            if (!onlyOnePage) {
                Engine.logContext.debug("(JavelinTransaction) Creating a new page item into the XML document");
                page = context.outputDocument.createElement("blocks");
                page.setAttribute("page-number", Integer.toString(nPage));
                outputDocumentRootElement.appendChild(page);
            }
            Element xmlBlock, history, xmlValue;
            List<String> values;
            String value;
            for (Block block : enumBlocks.nextElement()) {
                Engine.logContext.trace("(JavelinTransaction) Block: " + block.toString());
                // Skip rendering if needed
                if (block.bRender) {
                    xmlBlock = block.toXML(context.outputDocument, getIncludedTagAttributes(), prefix + transactionName + "_blocks");
                    // Add history
                    String historyBlock = block.getOptionalAttribute("history");
                    if ((context.httpSession != null) && (block != null) && (block.type.equals("field")) && (historyBlock != null) && (historyBlock.equals("true"))) {
                        values = GenericUtils.cast(context.httpSession.getAttribute(block.tagName));
                        if (values != null) {
                            history = context.outputDocument.createElement("history");
                            int len = values.size();
                            for (int i = 0; i < len; i++) {
                                value = values.get(i);
                                xmlValue = context.outputDocument.createElement("value");
                                xmlValue.appendChild(context.outputDocument.createTextNode(value));
                                history.appendChild(xmlValue);
                            }
                            xmlBlock.appendChild(history);
                        }
                    }
                    page.appendChild(xmlBlock);
                    if (studioMode) {
                        if (types.get(block.tagName) == null) {
                            xsdType += "\t\t\t" + block.xsdType + "\n";
                            types.put(block.tagName, block.xsdTypes);
                        }
                    }
                }
            }
            nPage++;
        }
        if (studioMode) {
            if (!isRemoveBlocksNode()) {
                xsdType += "\t</xsd:sequence>\n";
                xsdType += "\t<xsd:attribute name=\"page-number\" use=\"optional\"/>\n";
                xsdType += "</xsd:complexType>\n";
            } else {
                xsdType += "\t</xsd:sequence>\n";
                xsdType += "</xsd:complexType>\n";
            }
            Enumeration<String> e = Collections.enumeration(types.values());
            while (e.hasMoreElements()) {
                xsdType += e.nextElement();
            }
        // System.out.println(xsdType);
        }
    } finally {
        context.statistics.stop(t);
    }
    Engine.logContext.debug("(JavelinTransaction) DOM generated");
}
Also used : Element(org.w3c.dom.Element) Collection(java.util.Collection) Block(com.twinsoft.convertigo.beans.core.Block)

Example 2 with Block

use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.

the class JavelinTransaction method applyUserRequest.

public void applyUserRequest(iJavelin javelin) throws EngineException {
    boolean fieldIsAutoEnter = false;
    String currentField = "null";
    sessionMustBeDestroyed = false;
    String t = context.statistics.start(EngineStatistics.APPLY_USER_REQUEST);
    try {
        Engine.logContext.debug("(JavelinTransaction) Applying user request");
        // We apply the XML command to the Javelin object.
        if (context.inputDocument == null) {
            // Nothing to do: the user request is not relevant for this screen.
            Engine.logContext.debug("(JavelinTransaction) Request handling aborted: no user request");
            return;
        }
        NodeList nodeList;
        Node node, nodeAttribute;
        NamedNodeMap nodeAttributes;
        long documentSignature = 0;
        nodeList = context.inputDocument.getElementsByTagName("document-signature");
        if (nodeList.getLength() > 0) {
            node = nodeList.item(0);
            String value = ((Element) node).getAttribute("value");
            try {
                documentSignature = Long.parseLong(value);
            } catch (NumberFormatException e) {
                Engine.logContext.debug("(JavelinTransaction) Wrong document signature: " + value);
            }
        }
        Engine.logContext.debug("(JavelinTransaction) Received document signature:      " + documentSignature);
        Engine.logContext.debug("(JavelinTransaction) Last received document signature: " + context.documentSignatureReceived);
        Engine.logContext.debug("(JavelinTransaction) Last sent document signature:     " + context.documentSignatureSent);
        if (documentSignature < context.documentSignatureReceived) {
            // The user is trying to replay a previous request (probably by using the back
            // functionality from the browser...): this is forbidden.
            Engine.logContext.warn("(JavelinTransaction) Request handling aborted: \"back\" protection");
            context.outputDocument.getDocumentElement().setAttribute("back-attempt", "true");
            return;
        }
        // Json string of modified fields
        String modifiedFields = "";
        nodeList = context.inputDocument.getElementsByTagName("modified-fields");
        if (nodeList.getLength() > 0) {
            node = nodeList.item(0);
            nodeAttributes = node.getAttributes();
            nodeAttribute = nodeAttributes.getNamedItem("value");
            modifiedFields = nodeAttribute.getNodeValue();
        }
        nodeList = context.inputDocument.getElementsByTagName("current-field");
        if (nodeList.getLength() > 0) {
            node = nodeList.item(0);
            nodeAttributes = node.getAttributes();
            nodeAttribute = nodeAttributes.getNamedItem("name");
            currentField = nodeAttribute.getNodeValue();
        }
        nodeList = context.inputDocument.getElementsByTagName("action");
        if (nodeList.getLength() == 1) {
            Block block;
            String action, blockName;
            node = nodeList.item(0);
            nodeAttributes = node.getAttributes();
            nodeAttribute = nodeAttributes.getNamedItem("name");
            action = nodeAttribute.getNodeValue();
            action = action.trim();
            // Refreshing current XML document
            if (action.equalsIgnoreCase("convertigo_refresh")) {
                Engine.logContext.debug("(JavelinTransaction) Refresh required");
            } else if (action.startsWith("convertigo_bench")) {
                long sleepTime = 1000;
                if (action.length() > "convertigo_bench".length()) {
                    String s = action.substring(16);
                    try {
                        sleepTime = Long.parseLong(s);
                    } catch (NumberFormatException e) {
                    // Ignore
                    }
                }
                Engine.logContext.debug("(JavelinTransaction) Bench option: sleep during " + sleepTime + " second(s)");
                try {
                    Thread.sleep(sleepTime);
                } catch (InterruptedException e) {
                }
            } else // Destroy the current session
            if (action.equalsIgnoreCase("convertigo_destroy_session")) {
                Engine.logContext.debug("(JavelinTransaction) Requiring destroy of the current session");
                sessionMustBeDestroyed = true;
            } else // Reconnecting
            if (action.equalsIgnoreCase("convertigo_reconnect")) {
                Engine.logContext.debug("(JavelinTransaction) Reconnection required");
                javelin.disconnect();
                if (javelin.isConnected()) {
                    throw new ConnectionException("Unable to disconnect the session! See the emulator logs for more details...");
                }
                javelin.connect(timeoutForConnect);
                if (!javelin.isConnected()) {
                    throw new ConnectionException("Unable to connect the session! See the emulator logs for more details...");
                }
                javelin.waitForDataStable(timeoutForDataStable, dataStableThreshold);
            } else {
                if (javelin.getTerminalClass().equals(iJavelin.SNA) || javelin.getTerminalClass().equals(iJavelin.AS400)) {
                    // Special case for IBM emulators: before applying an action,
                    // do a RESET action on the emulator to clear a possible
                    // previous X System Status.
                    javelin.doAction("KEY_RESET");
                    Engine.logContext.debug("(JavelinTransaction) Action performed on the Javelin object: 'KEY_RESET'");
                }
                // previously sent document signature
                if ((documentSignature == 0) || (documentSignature == context.documentSignatureSent)) {
                    // Searching for fields to push into the Javelin object.
                    nodeList = context.inputDocument.getElementsByTagName("field");
                    int len = nodeList.getLength();
                    String value;
                    // sort fields by line and column in the screen
                    Element elem;
                    ArrayList<ComparableFieldElement> liste = new ArrayList<ComparableFieldElement>();
                    for (int i = 0; i < len; i++) {
                        elem = (Element) nodeList.item(i);
                        liste.add(new ComparableFieldElement(elem));
                    }
                    Engine.logContext.debug("(JavelinTransaction) Fields from inputDocument set in a list.");
                    Collections.sort(liste);
                    Engine.logContext.debug("(JavelinTransaction) Fields from inputDocument sorted.");
                    Iterator<ComparableFieldElement> it = liste.iterator();
                    while (it.hasNext()) {
                        ComparableFieldElement cfElem = it.next();
                        elem = cfElem.getFieldElement();
                        value = elem.getAttribute("value");
                        if (javelin.getTerminalClass().equals(iJavelin.VDX)) {
                            javelin.send(value);
                            Engine.logContext.debug("(JavelinTransaction) Characters sent to the Javelin object: '" + value + "'");
                        } else if (javelin.getTerminalClass().equals(iJavelin.VT)) {
                            javelin.send(value);
                            Engine.logContext.debug("(JavelinTransaction) VT Characters sent to the Javelin object: '" + value + "'");
                        } else {
                            // Trying to find the requested block
                            blockName = elem.getAttribute("name");
                            Engine.logContext.debug("(JavelinTransaction) Analyzing field \"" + blockName + "\"");
                            block = context.previousFields.get(blockName);
                            int column = 0;
                            int line = 0;
                            try {
                                int index1 = blockName.indexOf("_c");
                                int index2 = blockName.indexOf("_l");
                                column = Integer.parseInt(blockName.substring(index1 + 2, index2));
                                line = Integer.parseInt(blockName.substring(index2 + 2));
                                Engine.logContext.debug("(JavelinTransaction) Cursor position retrieved from the field name \"" + blockName + "\"column: =" + column + " line=" + line);
                            } catch (Exception e) {
                                Engine.logContext.error("Unable to retrieve the cursor position from the field name \"" + blockName + "\"! Skipping it.", e);
                                continue;
                            }
                            if (isFieldValueDifferent(blockName, value, modifiedFields)) {
                                javelin.moveCursor(column, line);
                                Engine.logContext.debug("(JavelinTransaction) Cursor moved to column:" + column + ", line: " + line);
                                // Delete the previous field value
                                if (javelin.getTerminalClass().equals(iJavelin.SNA) || javelin.getTerminalClass().equals(iJavelin.AS400)) {
                                    javelin.doAction("KEY_ERASEEOF");
                                } else if (javelin.getTerminalClass().equals(iJavelin.DKU)) {
                                    javelin.doAction("ERAEOL");
                                }
                                if (value.length() != 0) {
                                    // Test if the field is numeric only
                                    if ((block != null) && (block.attribute & iJavelin.AT_FIELD_NUMERIC) > 0) {
                                        value = removeAllNonNumericChars(value);
                                        Engine.logContext.warn("(JavelinTransaction) Numeric field. Non numeric chars may have been discarded [" + value + "]");
                                    }
                                    // Test if the field is autoenter and that its size equals to the field size
                                    try {
                                        if ((block != null) && (block.attribute & iJavelin.AT_AUTO_ENTER) > 0) {
                                            if (value.length() == Integer.parseInt(block.getOptionalAttribute("size"))) {
                                                fieldIsAutoEnter = true;
                                                Engine.logContext.debug("(JavelinTransaction) Field is auto enter, doAction will not be executed [" + value + "]");
                                            }
                                        }
                                    } catch (Exception e) {
                                        Engine.logContext.warn("(JavelinTransaction) Field is auto enter, but no size attribute present! [" + value + "]");
                                    }
                                    javelin.send(value);
                                    Engine.logContext.debug("(JavelinTransaction) Characters sent to the emulator on (" + column + ", " + line + "): '" + value + "'");
                                }
                                // Update the block history if it is a non empty field
                                if ((block != null) && (value.length() != 0)) {
                                    String historyBlock = block.getOptionalAttribute("history");
                                    if ((block.type.equals("field")) && (historyBlock != null) && (historyBlock.equals("true")) && (value.length() > 0)) {
                                        // TODO: set the tagname list to remember
                                        List<String> values = GenericUtils.cast(context.httpSession.getAttribute(block.tagName));
                                        if (values == null) {
                                            values = new ArrayList<String>(10);
                                        }
                                        if (!values.contains(value)) {
                                            values.add(value);
                                            context.httpSession.setAttribute(block.tagName, values);
                                            Engine.logContext.debug("(JavelinTransaction) History: block '" + block.tagName + "' += '" + value + "'");
                                        }
                                    }
                                }
                                if (action.equalsIgnoreCase("KEY_FIELDPLUS")) {
                                    Engine.logContext.debug("(JavelinTransaction) Action is KEY_FIELDPLUS while sending " + blockName + " field");
                                    if (blockName.equalsIgnoreCase(currentField)) {
                                        // The field we are handling is the current field.
                                        // Do now the FIELD_PLUS action.
                                        Engine.logContext.debug("(JavelinTransaction) We just sent the current field, and action is KEY_FIELDPLUS");
                                        javelin.doAction("KEY_FIELDPLUS");
                                        return;
                                    }
                                }
                            }
                        }
                    }
                    if (currentField != null) {
                        block = (Block) context.previousFields.get(currentField);
                        // we did not find the field in the previous fields : assume the current field is set on a static position. This is
                        // legal as some applications rely on the cursor position event on static fields
                        int index1 = currentField.indexOf("_c");
                        int index2 = currentField.indexOf("_l");
                        if ((index1 != -1) && (index2 != -1)) {
                            int column = Integer.parseInt(currentField.substring(index1 + 2, index2));
                            int line = Integer.parseInt(currentField.substring(index2 + 2));
                            Engine.logContext.debug("(JavelinTransaction) Move cursor on Current field : Cursor position retrieved from the field name \"" + currentField + "\"column=" + column + " line=" + line);
                            boolean moveDone = false;
                            // if current field is numeric, put the cursor at the end of the field
                            // searching field index
                            int nbFields = javelin.getNumberOfFields();
                            int i = 0;
                            boolean found = false;
                            while (i < nbFields && !found) {
                                if (javelin.getFieldColumn(i) == column && javelin.getFieldLine(i) == line)
                                    found = true;
                                else
                                    i++;
                            }
                            if (found) {
                                // field index found
                                if ((javelin.getFieldAttribute(i) & iJavelin.AT_FIELD_NUMERIC) > 0) {
                                    // numeric field
                                    // put the cursor at the end of the field
                                    column = column + javelin.getFieldLength(i) - 1;
                                    Engine.logContext.debug("(JavelinTransaction) Cursor is in a numeric field '" + currentField + "' ; moving cursor to the end of the field '" + currentField + "' at (" + column + ", " + line + ")");
                                    javelin.moveCursor(column, line);
                                    Engine.logContext.debug("(JavelinTransaction) Moved cursor to (" + javelin.getCurrentColumn() + ", " + javelin.getCurrentLine() + ")");
                                    moveDone = true;
                                }
                            }
                            if (!moveDone) {
                                // and if the action is KEY_NPTUI or not
                                if (javelin.getCurrentColumn() == column && javelin.getCurrentLine() == line && !action.equals("KEY_NPTUI")) {
                                    Engine.logContext.debug("(JavelinTransaction) Cursor has not moved from field '" + currentField + "' at (" + column + ", " + line + ") and action is not \"KEY_NPTUI\" ; don't move cursor");
                                } else {
                                    Engine.logContext.debug("(JavelinTransaction) Cursor has moved from field '" + currentField + "' or action is \"KEY_NPTUI\" ; moving cursor to field '" + currentField + "' at (" + column + ", " + line + ")");
                                    javelin.moveCursor(column, line);
                                    Engine.logContext.debug("(JavelinTransaction) Moved cursor to (" + javelin.getCurrentColumn() + ", " + javelin.getCurrentLine() + ")");
                                }
                            }
                        }
                    }
                } else {
                    Engine.logContext.warn("(JavelinTransaction) Cancel applying fields because of document signature check");
                }
                // Storing last document signature received
                context.documentSignatureReceived = documentSignature;
                // Executing action
                if (!fieldIsAutoEnter) {
                    // Execute the action only if there were no AutoEnter fields...
                    if (action.equalsIgnoreCase("KEY_NPTUI")) {
                        // NPTUI action just wait as the moveCursor already triggered the HOST COMM. we only have
                        // to wait here
                        boolean bTimedOut = javelin.waitForDataStable(timeoutForDataStable, dataStableThreshold);
                        Engine.logContext.debug("(JavelinTransaction) Action performed on the Javelin object: '" + action + "'waitForDataStable returned :" + bTimedOut);
                    } else if (action.length() != 0) {
                        javelin.doAction(action);
                        Engine.logContext.debug("(JavelinTransaction) Action performed on the Javelin object: '" + action + "'");
                        if (!(action.equalsIgnoreCase("KEY_FIELDPLUS") || action.equalsIgnoreCase("KEY_FIELDMINUS"))) {
                            boolean bTimedOut = javelin.waitForDataStable(timeoutForDataStable, dataStableThreshold);
                            Engine.logContext.debug("(JavelinTransaction) WaitForDataStable() returned " + bTimedOut);
                        } else
                            Engine.logContext.debug("(JavelinTransaction) Action was KEY_FIELDPLUS or KEY_FIELDMINUS, do not perform waitForDataStable");
                    } else {
                        Engine.logContext.debug("(JavelinTransaction) Empty action string => action aborted");
                    }
                } else {
                    boolean bTimedOut = javelin.waitForDataStable(timeoutForDataStable, dataStableThreshold);
                    Engine.logContext.debug("(JavelinTransaction) WaitForDataStable() returned " + bTimedOut);
                }
            }
        }
    } catch (Exception e) {
        Engine.logContext.error("Request handling aborted because of internal error.", e);
    } finally {
        context.statistics.stop(t);
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NoSuchElementException(java.util.NoSuchElementException) ConnectionException(com.twinsoft.convertigo.beans.connectors.ConnectionException) EvaluatorException(org.mozilla.javascript.EvaluatorException) JavaScriptException(org.mozilla.javascript.JavaScriptException) EngineException(com.twinsoft.convertigo.engine.EngineException) Iterator(java.util.Iterator) Block(com.twinsoft.convertigo.beans.core.Block) ConnectionException(com.twinsoft.convertigo.beans.connectors.ConnectionException)

Example 3 with 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);
}
Also used : Block(com.twinsoft.convertigo.beans.core.Block)

Example 4 with Block

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

Example 5 with Block

use of com.twinsoft.convertigo.beans.core.Block in project convertigo by convertigo.

the class DefaultBlockFactory method splitProtectedField.

private void splitProtectedField(int i, boolean penSelectable) {
    StringBuffer sb = null;
    char c;
    String s;
    boolean spaceBlock = false;
    int state = STATE_NEW_BLOCK;
    int x0 = javelin.getFieldColumn(i);
    int y0 = javelin.getFieldLine(i);
    int x = x0;
    int y = y0;
    int initialFieldLen = javelin.getFieldLength(i);
    int fieldLen = initialFieldLen;
    int attribute = javelin.getCharAttribute(x0, y0);
    Block block = null;
    while (fieldLen > 0) {
        switch(state) {
            case STATE_NEW_BLOCK:
                if (block != null) {
                    s = sb.toString();
                    block.setText(s);
                    list.add(block);
                }
                sb = new StringBuffer(initialFieldLen);
                block = new Block();
                block.column = x;
                block.line = y;
                block.attribute = attribute;
                block.type = "static";
                block.length = 1;
                if (penSelectable)
                    block.setOptionalAttribute("penselectable", "true");
                c = formatChar(javelin.getChar(x, y));
                sb.append(c);
                if (c == ' ')
                    spaceBlock = true;
                else
                    spaceBlock = false;
                state = STATE_SAME_ATTRIBUTE;
                x++;
                fieldLen--;
                break;
            case STATE_SAME_ATTRIBUTE:
                if (x >= nbColumns) {
                    y++;
                    if (y == javelin.getScreenHeight())
                        y = 0;
                    x = 0;
                    attribute = javelin.getCharAttribute(x, y);
                    state = STATE_NEW_BLOCK;
                    break;
                }
                int newAttribute = javelin.getCharAttribute(x, y);
                if (attribute != newAttribute) {
                    attribute = newAttribute;
                    state = STATE_NEW_BLOCK;
                    break;
                }
                c = formatChar(javelin.getChar(x, y));
                if (spaceBlock) {
                    if (c != ' ') {
                        state = STATE_NEW_BLOCK;
                        spaceBlock = false;
                        break;
                    }
                } else {
                    if (c == ' ') {
                        state = STATE_GOT_SPACE;
                        break;
                    }
                }
                sb.append(c);
                x++;
                fieldLen--;
                break;
            case STATE_GOT_SPACE:
                // System.out.println("STATE_GOT_SPACE");
                // is the next char a space ?
                // yes two spaces so do a new block
                state = STATE_NEW_BLOCK;
                spaceBlock = true;
                break;
        }
    }
    if (sb != null) {
        s = sb.toString();
        block.setText(s);
        list.add(block);
    }
}
Also used : Block(com.twinsoft.convertigo.beans.core.Block)

Aggregations

Block (com.twinsoft.convertigo.beans.core.Block)48 JavelinExtractionRuleResult (com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult)24 Element (org.w3c.dom.Element)8 StringTokenizer (java.util.StringTokenizer)7 LinkedList (java.util.LinkedList)5 XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)4 EngineException (com.twinsoft.convertigo.engine.EngineException)4 NoSuchElementException (java.util.NoSuchElementException)4 XMLRectangle (com.twinsoft.convertigo.beans.common.XMLRectangle)3 ArrayList (java.util.ArrayList)3 PanelBlockFactory (com.twinsoft.convertigo.beans.common.PanelBlockFactory)2 RESyntaxException (org.apache.regexp.RESyntaxException)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 ACLNptuiChoice (com.eicon.iConnect.acl.ACLNptuiChoice)1 ACLNptuiComponent (com.eicon.iConnect.acl.ACLNptuiComponent)1 ACLNptuiScrollBar (com.eicon.iConnect.acl.ACLNptuiScrollBar)1 ACLNptuiSelectionField (com.eicon.iConnect.acl.ACLNptuiSelectionField)1 ACLNptuiWindow (com.eicon.iConnect.acl.ACLNptuiWindow)1 DefaultBlockFactory (com.twinsoft.convertigo.beans.common.DefaultBlockFactory)1