Search in sources :

Example 46 with XMLVector

use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.

the class Copybook method main.

public static void main(String[] args) {
    try {
        String strFilePath = null;
        if (args != null) {
            if (args.length > 0) {
                strFilePath = args[0];
            }
        }
        // strFilePath = "C:/Projects/Canon/CO242702.txt";
        if (strFilePath != null) {
            // System.out.println("Parsing copybook '"+ strFilePath +"'");
            FileReader reader = new FileReader(strFilePath);
            Copybook cpbk = new Copybook();
            // XMLVector v = cpbk.importFromFile(reader);
            XMLVector<XMLVector<Object>> v2 = cpbk.importFromFile2(reader);
            Element elt = cpbk.addLeveledXMLVector(null, null, v2);
            if (elt != null) {
                Document doc = elt.getOwnerDocument();
                String s = XMLUtils.prettyPrintDOM(doc);
                System.out.println(s);
            }
        }
    } catch (Exception e) {
        Engine.logEngine.error("Unexpected exception", e);
    } finally {
        System.exit(0);
    }
}
Also used : XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) Element(org.w3c.dom.Element) FileReader(java.io.FileReader) Document(org.w3c.dom.Document) IOException(java.io.IOException)

Example 47 with XMLVector

use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.

the class Copybook method addLeveledXMLVector.

public Element addLeveledXMLVector(Document doc, Element root, XMLVector<XMLVector<Object>> v) {
    Element parent = null, node = null, last = null;
    if (doc == null) {
        try {
            doc = XMLUtils.getDefaultDocumentBuilder().newDocument();
        } catch (Exception e) {
            Engine.logEngine.error("Unexpected exception", e);
        }
    }
    if (doc != null) {
        int curlevel = 0;
        if (root == null) {
            root = doc.getDocumentElement();
            if (root == null) {
                root = doc.createElement("cics");
                doc.appendChild(root);
            }
        }
        if (v != null) {
            Enumeration<XMLVector<Object>> rows = v.elements();
            while (rows.hasMoreElements()) {
                XMLVector<Object> row = rows.nextElement();
                String sLevel = (String) row.get(0);
                String sName = (String) row.get(1);
                String sOccurs = (String) row.get(2);
                String sBytes = ((Integer) row.get(3)).toString();
                String sFormat = (String) row.get(4);
                String sPicture = (String) row.get(5);
                String sValue = (String) row.get(6);
                int level = Integer.parseInt(sLevel, 10);
                if (level > 0) {
                    node = doc.createElement(sName);
                    node.setAttribute("level", sLevel);
                    if (!sOccurs.equalsIgnoreCase(""))
                        node.setAttribute("occurs", sOccurs);
                    if (!sPicture.equalsIgnoreCase(""))
                        node.setAttribute("picture", sPicture);
                    if (!sBytes.equalsIgnoreCase(""))
                        node.setAttribute("bytes", sBytes);
                    if (!sFormat.equalsIgnoreCase(""))
                        node.setAttribute("format", sFormat);
                    node.appendChild(doc.createTextNode(sValue));
                    if (curlevel == 0)
                        parent = root;
                    else if (level < curlevel) {
                        curlevel = level;
                        do {
                            parent = (Element) last.getParentNode();
                            try {
                                level = Integer.parseInt((parent.getAttribute("level")), 10);
                            } catch (NumberFormatException e) {
                                level = 0;
                            }
                            last = parent;
                        } while (level >= curlevel);
                        level = curlevel;
                    } else if (level == curlevel) {
                        parent = (Element) last.getParentNode();
                    } else {
                        parent = last;
                    }
                    if (parent != null) {
                        parent.appendChild(node);
                        last = node;
                        curlevel = level;
                    }
                }
            }
        }
    }
    root = extendXMLMap(root);
    return root;
}
Also used : XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) Element(org.w3c.dom.Element) IOException(java.io.IOException)

Example 48 with XMLVector

use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.

the class DefaultInternalTranslator method buildInputDocument.

public void buildInputDocument(Context context, Object inputData) throws Exception {
    Engine.logContext.debug("Making input document");
    Map<String, Object> request = GenericUtils.cast(inputData);
    InputDocumentBuilder inputDocumentBuilder = new InputDocumentBuilder(context);
    // Indicates whether variable values were generated using strict mode or nor(text/childs only)
    inputDocumentBuilder.transactionVariablesElement.setAttribute("strictMode", Boolean.toString(bStrictMode));
    for (Entry<String, Object> entry : request.entrySet()) {
        String parameterName = entry.getKey();
        Object parameterObject = entry.getValue();
        if (!inputDocumentBuilder.handleSpecialParameter(parameterName, parameterObject)) {
            if (parameterObject instanceof String[]) {
                inputDocumentBuilder.addVariable(parameterName, (String[]) parameterObject);
            } else {
                addParameterObject(context.inputDocument, inputDocumentBuilder.transactionVariablesElement, parameterName, parameterObject);
            }
        }
    }
    TestCase tc = TestCase.getTestCase(request, context.projectName);
    if (tc != null) {
        for (TestCaseVariable var : tc.getVariables()) {
            String parameterName = var.getName();
            Object parameterObject = var.getValueOrNull();
            if (parameterObject == null) {
                // ignore variables set to <null>
                continue;
            }
            if (!request.containsKey(parameterName) && !inputDocumentBuilder.handleSpecialParameter(parameterName, parameterObject)) {
                if (parameterObject instanceof XMLVector) {
                    String[] strings = ((XMLVector<?>) parameterObject).toArray(new String[0]);
                    inputDocumentBuilder.addVariable(parameterName, strings);
                } else {
                    addParameterObject(context.inputDocument, inputDocumentBuilder.transactionVariablesElement, parameterName, parameterObject);
                }
            }
        }
    }
    Engine.logContext.info("Input document created");
}
Also used : XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) TestCase(com.twinsoft.convertigo.beans.core.TestCase) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) TestCaseVariable(com.twinsoft.convertigo.beans.variables.TestCaseVariable)

Example 49 with XMLVector

use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.

the class DefaultServletTranslator method buildInputDocument.

public void buildInputDocument(Context context, Object inputData) throws Exception {
    Engine.logContext.debug("Making input document");
    HttpServletRequest request = (HttpServletRequest) inputData;
    InputDocumentBuilder inputDocumentBuilder = new InputDocumentBuilder(context);
    // We transform the HTTP post data into XML data.
    Enumeration<?> parameterNames = request.getParameterNames();
    // Sometimes, because of a bug about bad recycling of request facade objects in Tomcat,
    // the HTTP parameters parsing is not realized, and then parameterNames is empty. In
    // such a case, a (bad) workaround is to decode by ourselves the query string in GET
    // or the HTTP body in POST...
    // Map<String, String[]> reparsedParameters = (Map<String, String[]>) request.getAttribute(ServletRequester.REPARSED_PARAMETERS_ATTRIBUTE);
    // boolean bReparsedParameters = (reparsedParameters != null);
    // if (bReparsedParameters) {
    // parameterNames = reparsedParameters.keys();
    // }
    boolean isHandleComplex = "true".equals(request.getParameter("__handleComplex"));
    while (parameterNames.hasMoreElements()) {
        String parameterName = (String) parameterNames.nextElement();
        String[] parameterValues = request.getParameterValues(parameterName);
        if (!inputDocumentBuilder.handleSpecialParameter(parameterName, parameterValues)) {
            inputDocumentBuilder.addVariable(parameterName, parameterValues, isHandleComplex);
        }
    }
    TestCase tc = TestCase.getTestCase(request, context.projectName);
    if (tc != null) {
        for (TestCaseVariable var : tc.getVariables()) {
            String parameterName = var.getName();
            if (request.getParameter(parameterName) == null) {
                Object parameterObject = var.getValueOrNull();
                String[] parameterValues = (parameterObject instanceof XMLVector<?>) ? ((XMLVector<?>) parameterObject).toArray(new String[0]) : new String[] { (String) parameterObject };
                if (!inputDocumentBuilder.handleSpecialParameter(parameterName, parameterValues)) {
                    inputDocumentBuilder.addVariable(parameterName, parameterValues, isHandleComplex);
                }
            }
        }
    }
    Engine.logContext.debug("Input document created");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) TestCase(com.twinsoft.convertigo.beans.core.TestCase) TestCaseVariable(com.twinsoft.convertigo.beans.variables.TestCaseVariable)

Example 50 with XMLVector

use of com.twinsoft.convertigo.beans.common.XMLVector in project convertigo by convertigo.

the class XMLConcatStep method getActionValue.

@Override
protected String getActionValue() throws EngineException {
    String nodeValue = super.getActionValue();
    XMLVector<XMLVector<Object>> sourcesDefinition = getSourcesDefinition();
    if (sourcesDefinition.size() > 0) {
        StepSource source = null;
        NodeList list = null;
        for (int i = 0; i < sourcesDefinition.size(); i++) {
            nodeValue += nodeValue.equals("") ? "" : separator;
            source = getDefinitionsSource(i);
            if (source != null) {
                list = source.getContextValues();
                if (list != null) {
                    int len = list.getLength();
                    for (int j = 0; j < len; j++) {
                        String text = getNodeValue(list.item(j));
                        nodeValue += ((text == null) ? getDefinitionsDefaultValue(i) : text);
                        nodeValue += ((j < len - 1) ? separator : "");
                    }
                } else {
                    nodeValue += getDefinitionsDefaultValue(i);
                }
            } else {
                nodeValue += getDefinitionsDefaultValue(i);
            }
        }
    }
    return nodeValue;
}
Also used : StepSource(com.twinsoft.convertigo.beans.core.StepSource) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) NodeList(org.w3c.dom.NodeList)

Aggregations

XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)51 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)19 EngineException (com.twinsoft.convertigo.engine.EngineException)15 Element (org.w3c.dom.Element)15 IOException (java.io.IOException)10 NodeList (org.w3c.dom.NodeList)8 RequestableHttpVariable (com.twinsoft.convertigo.beans.variables.RequestableHttpVariable)7 RequestableVariable (com.twinsoft.convertigo.beans.variables.RequestableVariable)7 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)7 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)6 Shell (org.eclipse.swt.widgets.Shell)6 Step (com.twinsoft.convertigo.beans.core.Step)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 ArrayList (java.util.ArrayList)5 Document (org.w3c.dom.Document)5 Block (com.twinsoft.convertigo.beans.core.Block)4 Sequence (com.twinsoft.convertigo.beans.core.Sequence)4 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)4 TestCase (com.twinsoft.convertigo.beans.core.TestCase)4 Variable (com.twinsoft.convertigo.beans.core.Variable)4