Search in sources :

Example 6 with MapTag

use of com.dexels.navajo.document.navascript.tags.MapTag in project navajo by Dexels.

the class NS3ToNSXML method parseProperty.

private NS3Compatible parseProperty(NS3Compatible parent, XMLElement currentXML) throws Exception {
    currentXML.setAttribute("PROCESSED", "true");
    PropertyTag pt = new PropertyTag(myNavascript);
    pt.addParent(parent);
    Vector<XMLElement> children = currentXML.getChildren();
    for (XMLElement child : children) {
        String name = child.getName();
        String content = (child.getContent() != null && !"".equals(child.getContent()) ? child.getContent() : null);
        if (name.equals("TOKEN")) {
            if (content.equals("value")) {
                pt.setName("value");
            }
            if (content.equals("name")) {
                pt.setName("name");
            }
            if (content.equals("selected")) {
                pt.setName("selected");
            }
        }
        if (name.equals("Conditional")) {
            ConditionFragment currentFragment = new ConditionFragment();
            consumeContent(currentFragment, child);
            pt.setCondition(currentFragment.consumedFragment());
        }
        if (name.equals("PropertyName")) {
            pt.setName(content);
        }
        if (name.equals("PropertyArguments")) {
            parsePropertyArguments(pt, child);
        }
        if (name.equals("ConditionalExpressions")) {
            List<ExpressionTag> expressions = parseConditionalExpressions(pt, child);
            for (ExpressionTag et : expressions) {
                pt.addExpression(et);
            }
        }
        if (name.equals("StringConstant")) {
            String c = content.replaceAll("\"", "");
            ExpressionTag et = new ExpressionTag(myNavascript);
            et.setConstant(c);
            pt.addExpression(et);
        }
        if (name.equals("MappedArrayFieldSelection")) {
            MapTag maf = parseMappedArrayField(parent, child);
            pt.addMap(maf);
        }
        if (name.equals("MappedArrayMessageSelection")) {
            MapTag maf = parsedMappedArrayMessage(parent, child);
            pt.addMap(maf);
        }
        // Use SelectionMap in combination with a param array message to support this construction in navascript XML.
        if (name.equals("SelectionArray")) {
            // Create param array
            ParamTag paramtag = new ParamTag(myNavascript);
            paramtag.setType(Message.MSG_TYPE_ARRAY);
            paramtag.setName(randomParamName(pt.getName() + "_selections"));
            myNavascript.addParam(paramtag);
            // Create com.dexels.navajo.adapter.SelectionMap
            MapTag mt = new MapTag(myNavascript);
            mt.setObject("com.dexels.navajo.adapter.SelectionMap");
            mt.setOldStyleMap(true);
            FieldTag fieldOptions = new FieldTag(mt);
            fieldOptions.setFieldName("options");
            fieldOptions.setOldSkool(true);
            MapTag mappedOptions = new MapTag(myNavascript);
            fieldOptions.addMap(mappedOptions);
            mappedOptions.setOldStyleMap(true);
            mappedOptions.setRefAttribute("[/@" + paramtag.getName() + "]");
            // Add name, value, selected
            FieldTag nameField = new FieldTag(mappedOptions);
            nameField.setOldSkool(true);
            nameField.setFieldName("optionName");
            mappedOptions.addField(nameField);
            nameField.addExpression(null, "[name]");
            FieldTag valueField = new FieldTag(mappedOptions);
            valueField.setOldSkool(true);
            valueField.setFieldName("optionValue");
            mappedOptions.addField(valueField);
            valueField.addExpression(null, "[value]");
            FieldTag selectedField = new FieldTag(mappedOptions);
            selectedField.setOldSkool(true);
            selectedField.setFieldName("optionSelected");
            mappedOptions.addField(selectedField);
            selectedField.addExpression(null, "[selected]");
            // add options field to map
            mt.addField(fieldOptions);
            // add property to selectionmap
            mt.addProperty(pt);
            MapTag refOptions = new MapTag(myNavascript);
            refOptions.setOldStyleMap(true);
            refOptions.setRefAttribute("options");
            pt.addMap(refOptions);
            PropertyTag nameProp = new PropertyTag(myNavascript);
            nameProp.setName("name");
            nameProp.addExpression(null, "$optionName");
            refOptions.addProperty(nameProp);
            PropertyTag valueProp = new PropertyTag(myNavascript);
            valueProp.setName("value");
            valueProp.addExpression(null, "$optionValue");
            refOptions.addProperty(valueProp);
            PropertyTag selectedProp = new PropertyTag(myNavascript);
            selectedProp.setName("selected");
            selectedProp.addExpression(null, "$optionSelected");
            refOptions.addProperty(selectedProp);
            // Fetch the array elements to construct a param array message to store them.
            parseSelectionArrayElements(paramtag, mt, child);
            // Return the map instead of the property.
            return mt;
        }
    }
    return pt;
}
Also used : PropertyTag(com.dexels.navajo.document.navascript.tags.PropertyTag) ParamTag(com.dexels.navajo.document.navascript.tags.ParamTag) ExpressionTag(com.dexels.navajo.document.navascript.tags.ExpressionTag) FieldTag(com.dexels.navajo.document.navascript.tags.FieldTag) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) MapTag(com.dexels.navajo.document.navascript.tags.MapTag)

Example 7 with MapTag

use of com.dexels.navajo.document.navascript.tags.MapTag in project navajo by Dexels.

the class NS3ToNSXML method parseVar.

private ParamTag parseVar(NS3Compatible parent, XMLElement currentXML) throws Exception {
    // Conditional -> VarName -> "=" OR ":" -> ConditionalExpressions
    Vector<XMLElement> children = currentXML.getChildren();
    ParamTag paramTag = new ParamTag(myNavascript);
    paramTag.addParent(parent);
    currentXML.setAttribute("PROCESSED", "true");
    for (XMLElement child : children) {
        String name = child.getName();
        String content = (child.getContent() != null && !"".equals(child.getContent()) ? child.getContent() : null);
        if (name.equals("VarName")) {
            paramTag.setName(content);
        }
        if (name.equals("VarArguments")) {
            parseVarArguments(paramTag, child);
        }
        if (name.equals("Conditional")) {
            ConditionFragment currentFragment = new ConditionFragment();
            consumeContent(currentFragment, child);
            paramTag.setCondition(currentFragment.consumedFragment());
        }
        if (name.equals("ConditionalExpressions")) {
            List<ExpressionTag> expressions = parseConditionalExpressions(paramTag, child);
            for (ExpressionTag et : expressions) {
                paramTag.addExpression(et);
            }
        }
        if (name.equals("MappedArrayField")) {
            // <map ref="$"
            MapTag maf = parseMappedArrayField(findClosestMapTag(parent, ""), child);
            paramTag.addMap(maf);
        }
        if (name.equals("MappedArrayMessage")) {
            MapTag mt = parsedMappedArrayMessage(parent, child);
            paramTag.addMap(mt);
        }
        if (name.equals("VarArray")) {
            paramTag.setType(Message.MSG_TYPE_ARRAY);
            Vector<XMLElement> paramChildren = child.getChildren();
            for (XMLElement paramChild : paramChildren) {
                if (paramChild.getName().equals("VarArrayElement")) {
                    ParamTag paramElt = parseVarArrayElement(paramTag, paramChild);
                    paramElt.setName(paramTag.getName());
                    paramTag.addParam(paramElt);
                }
            }
        }
    }
    return paramTag;
}
Also used : ParamTag(com.dexels.navajo.document.navascript.tags.ParamTag) ExpressionTag(com.dexels.navajo.document.navascript.tags.ExpressionTag) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) MapTag(com.dexels.navajo.document.navascript.tags.MapTag)

Example 8 with MapTag

use of com.dexels.navajo.document.navascript.tags.MapTag in project navajo by Dexels.

the class NavascriptSaxHandler method startElement.

@Override
public final void startElement(String tag, Map<String, String> h) throws Exception {
    if (tag.equals(Tags.NAVASCRIPT) || tag.equals("tsl")) {
        currentDocument = new NavascriptTag();
        currentDocument.setAuthor(h.get("author"));
        currentDocument.setNotes(h.get("notes"));
        currentDocument.setId(h.get("id"));
        currentNode.push(currentDocument);
        return;
    }
    BaseNode currentParent = currentNode.lastElement();
    if (tag.equals(Tags.FINALLY)) {
        FinallyTag ft = new FinallyTag(currentDocument);
        currentDocument.addFinally(ft);
        currentNode.push(ft);
    }
    if (tag.equals(Tags.METHODS)) {
        MethodsTag mt = new MethodsTag(currentDocument);
        currentDocument.addMethods(mt);
        currentNode.push(mt);
        currentMethods = mt;
    }
    if (tag.equals(Tags.METHOD)) {
        MethodTag m = new MethodTag(currentDocument);
        m.setScriptName(h.get("name"));
        if (currentMethods == null) {
            logger.error("Missing methods tag for this method " + h.get("name"));
            return;
        }
        currentNode.push(m);
        currentMethods.addMethod(m);
    }
    if (tag.equals(Tags.DEFINES)) {
        DefinesTag dt = new DefinesTag(currentDocument);
        currentDocument.addDefines(dt);
        currentNode.push(dt);
        currentDefines = dt;
    }
    if (tag.equals(Tags.DEFINE)) {
        DefineTag dt = new DefineTag(currentDocument);
        String name = h.get("name");
        dt.setName(name);
        if (currentDefines != null) {
            currentDefines.addDefine(dt);
        }
        currentNode.push(dt);
    }
    if (tag.equals(Tags.DEBUG)) {
        DebugTag dt = new DebugTag(currentDocument, h.get("value"));
        dt.setCondition(h.get("condition"));
        if (currentParent instanceof MapTag && currentMap.size() > 0) {
            currentMap.lastElement().addDebug(dt);
        } else if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
            currentMessage.lastElement().addDebug(dt);
        } else if (currentParent instanceof BlockTag) {
            ((BlockTag) currentParent).add(dt);
        } else if (currentParent instanceof FinallyTag) {
            ((FinallyTag) currentParent).add(dt);
        } else if (currentParent instanceof SynchronizedTag) {
            ((SynchronizedTag) currentParent).add(dt);
        } else if (currentParent instanceof BlockTag) {
            ((BlockTag) currentParent).addDebug(dt);
        } else if (currentParent instanceof NavascriptTag) {
            currentDocument.addDebug(dt);
        } else {
            throw new Exception("Did not expect debug tag under this parent: " + currentParent.getTagName());
        }
        currentNode.push(dt);
        return;
    }
    if (tag.equals(Tags.LOG)) {
        LogTag dt = new LogTag(currentDocument, h.get("value"));
        dt.setCondition(h.get("condition"));
        if (currentParent instanceof MapTag && currentMap.size() > 0) {
            currentMap.lastElement().addDebug(dt);
        } else if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
            currentMessage.lastElement().addDebug(dt);
        } else if (currentParent instanceof BlockTag) {
            ((BlockTag) currentParent).add(dt);
        } else if (currentParent instanceof FinallyTag) {
            ((FinallyTag) currentParent).add(dt);
        } else if (currentParent instanceof SynchronizedTag) {
            ((SynchronizedTag) currentParent).add(dt);
        } else if (currentParent instanceof BlockTag) {
            ((BlockTag) currentParent).addDebug(dt);
        } else if (currentParent instanceof NavascriptTag) {
            currentDocument.addDebug(dt);
        } else {
            throw new Exception("Did not expect log tag under this parent: " + currentParent.getTagName());
        }
        currentNode.push(dt);
        return;
    }
    if (tag.equals(Tags.INCLUDE)) {
        IncludeTag it = new IncludeTag(currentDocument, (h.get("script")));
        it.setCondition(h.get("condition"));
        if (currentParent instanceof MapTag && currentMap.size() > 0) {
            currentMap.lastElement().addInclude(it);
        } else if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
            currentMessage.lastElement().addInclude(it);
        } else if (currentParent instanceof BlockTag) {
            ((BlockTag) currentParent).add(it);
        } else if (currentParent instanceof FinallyTag) {
            ((FinallyTag) currentParent).add(it);
        } else if (currentParent instanceof SynchronizedTag) {
            ((SynchronizedTag) currentParent).add(it);
        } else if (currentParent instanceof NavascriptTag) {
            currentDocument.addInclude(it);
        } else {
        }
        currentNode.push(it);
        return;
    }
    if (tag.equals(Tags.VALIDATIONS)) {
        if (!(currentParent instanceof NavascriptTag)) {
            throw new Exception("Validation tags can only be specified as top level tags");
        }
        validationsBlock = currentDocument.addValidations();
        currentNode.push(validationsBlock);
        return;
    }
    if (tag.equals(Tags.OPTION)) {
        String name = h.get(Attributes.NAME);
        String value = h.get(Attributes.VALUE);
        String selected = h.get(Attributes.SELECTED);
        boolean bSel = (selected != null ? selected.equals("1") : false);
        if (currentParent instanceof PropertyTag) {
            SelectionTag st = ((PropertyTag) currentParent).addSelection(name, value, bSel);
            currentNode.push(st);
        } else {
            throw new Exception("Option tags are only allowed after a property tag.");
        }
        return;
    }
    if (tag.equals(Tags.CHECK)) {
        String code = h.get("code");
        String desc = h.get(Attributes.DESCRIPTION);
        String condition = h.get(Attributes.CONDITION);
        if (validationsBlock != null) {
            CheckTag ct = validationsBlock.addCheck(code, desc, condition);
            currentNode.push(ct);
        } else {
            throw new Exception("Check tags can only be found under validations tag.");
        }
        return;
    }
    if (tag.equals(Tags.BREAK)) {
        BreakTag bt = new BreakTag(currentDocument, h.get(Attributes.CONDITION), h.get("conditionId"), h.get("conditionDescription"));
        if (currentParent instanceof MapTag && currentMap.size() > 0) {
            currentMap.lastElement().addBreak(bt);
        } else if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
            currentMessage.lastElement().addBreak(bt);
        } else if (currentParent instanceof BlockTag) {
            ((BlockTag) currentParent).add(bt);
        } else if (currentParent instanceof FinallyTag) {
            ((FinallyTag) currentParent).add(bt);
        } else if (currentParent instanceof SynchronizedTag) {
            ((SynchronizedTag) currentParent).add(bt);
        } else if (currentParent instanceof NavascriptTag) {
            currentDocument.addBreak(bt);
        } else {
            throw new Exception("Did not expect break tag under this parent: " + currentParent.getTagName());
        }
        currentNode.push(bt);
        return;
    }
    if (tag.equals(Tags.SYNCHRONIZED)) {
        SynchronizedTag st = new SynchronizedTag(currentDocument);
        st.setContext(h.get(Attributes.CONTEXT));
        st.setKey(h.get(Attributes.KEY));
        st.setTimeout(h.get(Attributes.TIMEOUT));
        st.setBreakOnNoLock(h.get(Attributes.BREAKON_NOLOCK));
        if (currentParent instanceof MapTag && currentMap.size() > 0) {
            currentMap.lastElement().addSynchronized(st);
        } else if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
            currentMessage.lastElement().addSynchronized(st);
        } else if (currentParent instanceof BlockTag) {
            ((BlockTag) currentParent).addSynchronized(st);
        } else if (currentParent instanceof FinallyTag) {
            ((FinallyTag) currentParent).add(st);
        } else if (currentParent instanceof NavascriptTag) {
            ((NavascriptTag) currentParent).addSynchronized(st);
        } else {
            throw new Exception("Did not excpect synchronized tag under this parent: " + currentParent.getTagName());
        }
        currentNode.push(st);
    }
    if (tag.equals(Tags.BLOCK)) {
        BlockTag bt = new BlockTag(currentDocument);
        bt.setCondition(h.get(Attributes.CONDITION));
        if (currentParent instanceof MapTag && currentMap.size() > 0) {
            currentMap.lastElement().addBlock(bt);
        } else if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
            currentMessage.lastElement().addBlock(bt);
        } else if (currentParent instanceof BlockTag) {
            ((BlockTag) currentParent).addBlock(bt);
        } else if (currentParent instanceof FinallyTag) {
            ((FinallyTag) currentParent).add(bt);
        } else if (currentParent instanceof NavascriptTag) {
            ((NavascriptTag) currentParent).addBlock(bt);
        } else if (currentParent instanceof SynchronizedTag) {
            ((SynchronizedTag) currentParent).add(bt);
        } else {
            throw new Exception("Did not expect block tag under this parent: " + currentParent.getTagName());
        }
        currentNode.push(bt);
        return;
    }
    if (tag.equals(Tags.MESSAGE) || tag.equals(Tags.ANTIMESSAGE)) {
        MessageTag mt = new MessageTag(currentDocument, h.get(Attributes.NAME), h.get(Attributes.TYPE));
        mt.setCondition(h.get(Attributes.CONDITION));
        mt.setOrderBy(h.get(Attributes.ORDERBY));
        boolean isAntiMsg = tag.equals(Tags.ANTIMESSAGE);
        mt.setAntiMessage(isAntiMsg);
        if (h.get("mode") != null) {
            // postfix mode to prevent ignore message. Strip character later
            mt.setMode(h.get("mode") + "_");
        }
        if (currentParent instanceof MapTag && currentMap.size() > 0) {
            currentMap.lastElement().addMessage(mt);
        } else if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
            currentMessage.lastElement().addMessage(mt);
        } else if (currentParent instanceof BlockTag) {
            ((BlockTag) currentParent).add(mt);
        } else if (currentParent instanceof FinallyTag) {
            ((FinallyTag) currentParent).add(mt);
        } else if (currentParent instanceof SynchronizedTag) {
            ((SynchronizedTag) currentParent).add(mt);
        } else if (currentParent instanceof NavascriptTag) {
            currentDocument.addMessage(mt);
        } else {
            throw new Exception("Did not expect message tag under this parent: " + currentParent.getTagName());
        }
        currentMessage.push(mt);
        currentNode.push(mt);
        return;
    }
    if (tag.equals(Tags.MAP)) {
        String object = h.get(Attributes.OBJECT);
        String ref = h.get(Attributes.REF);
        String condition = h.get(Attributes.CONDITION);
        MapTag mt = null;
        if (object != null) {
            mt = new MapTag(currentDocument, object, h.get(Attributes.CONDITION), true);
        } else {
            // map ref on message
            mt = new MapTag(currentDocument, ref, h.get(Attributes.FILTER), (currentMap.size() > 0 ? currentMap.lastElement() : null), true);
            if (ref.startsWith("[")) {
                mt.setMappedMessage(true);
            }
        }
        mt.setCondition(condition);
        if (currentParent instanceof PropertyTag) {
            // selection property.
            ((PropertyTag) currentParent).addMap(mt);
        } else if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
            currentMessage.lastElement().addMap(mt);
        } else if (currentParent instanceof MapTag && currentMap.size() > 0) {
            currentMap.lastElement().addMap(mt);
        } else if (currentParent instanceof FieldTag && currentField.size() > 0) {
            currentField.lastElement().addMap(mt);
        } else if (currentParent instanceof ParamTag) {
            ((ParamTag) currentParent).addMap(mt);
            ((ParamTag) currentParent).setType("array");
        } else if (currentParent instanceof BlockTag) {
            ((BlockTag) currentParent).add(mt);
        } else if (currentParent instanceof FinallyTag) {
            ((FinallyTag) currentParent).add(mt);
        } else if (currentParent instanceof SynchronizedTag) {
            ((SynchronizedTag) currentParent).add(mt);
        } else if (currentParent instanceof NavascriptTag) {
            currentDocument.addMap(mt);
        } else {
            throw new Exception("Did not expect map tag under this parent: " + currentParent.getTagName());
        }
        currentMap.push(mt);
        currentNode.push(mt);
        return;
    }
    if (tag.equals(Tags.FIELD)) {
        String name = h.get(Attributes.NAME);
        FieldTag ft = new FieldTag(currentMap.lastElement(), null, name, true);
        // FIELD CAN ALSO BE UNDER MESSAGE!!!
        if (currentParent instanceof MessageTag) {
            currentMessage.lastElement().addField(ft);
        } else if (currentParent instanceof MapTag) {
            currentMap.lastElement().addField(ft);
        } else if (currentParent instanceof BlockTag) {
            ((BlockTag) currentParent).add(ft);
        } else {
            throw new Exception("Field tags can only be found under message or map tags.");
        }
        currentField.push(ft);
        currentNode.push(ft);
    }
    if (tag.startsWith(Tags.MAP + ".")) {
        // map.navajo
        String name = tag.split("\\.")[1].trim();
        MapTag mt = new MapTag(currentDocument, name, h.get(Attributes.CONDITION));
        Map<String, String> attributeMap = new HashMap<>();
        for (String key : h.keySet()) {
            attributeMap.put(key, h.get(key));
        }
        mt.addAttributes(attributeMap);
        if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
            currentMessage.lastElement().addMap(mt);
        } else if (currentParent instanceof MapTag && currentMap != null) {
            currentMap.lastElement().addMap(mt);
        } else if (currentParent instanceof BlockTag) {
            ((BlockTag) currentParent).add(mt);
        } else if (currentParent instanceof FinallyTag) {
            ((FinallyTag) currentParent).add(mt);
        } else if (currentParent instanceof SynchronizedTag) {
            ((SynchronizedTag) currentParent).add(mt);
        } else if (currentParent instanceof NavascriptTag) {
            currentDocument.addMap(mt);
        } else {
            StringBuffer sb = new StringBuffer();
            sb.append("Did not expect map[" + name + "] tag under this parent: " + currentParent.getTagName() + ", currentMessage: " + currentMessage.size());
            if (currentParent instanceof MessageTag) {
                sb.append("\nParent is a message with name: " + ((MessageTag) currentParent).getName());
            }
            throw new Exception(sb.toString());
        }
        currentMap.push(mt);
        currentNode.push(mt);
        return;
    }
    if (tag.equals(Tags.VALUE)) {
        String condition = h.get(Attributes.CONDITION);
        ValueTag vt = new ValueTag(currentDocument);
        vt.setCondition(condition);
        if (currentParent instanceof FieldTag) {
            // This FieldTag will be a normal "setter" field.
            ExpressionTag et = new ExpressionTag(currentDocument);
            et.addValueTag(vt);
            ((FieldTag) currentParent).setOldSkool(true);
            ((FieldTag) currentParent).setSetter(true);
            ((FieldTag) currentParent).addExpression(et);
        } else {
            ((ExpressionTag) currentParent).addValueTag(vt);
        }
        currentNode.push(vt);
    }
    if (tag.equals(Tags.EXPRESSION)) {
        String condition = h.get(Attributes.CONDITION);
        String value = h.get(Attributes.VALUE);
        ExpressionTag et = new ExpressionTag(currentDocument, condition, value);
        if (currentParent instanceof PropertyTag) {
            ((PropertyTag) currentParent).addExpression(et);
        } else if (currentParent instanceof FieldTag) {
            ((FieldTag) currentParent).addExpression(et);
        } else if (currentParent instanceof ParamTag) {
            ((ParamTag) currentParent).addExpression(et);
        } else if (currentParent instanceof MapTag) {
            // Oops. this cannot happen. Should have been a FieldTag. Fix this.
            MapTag fixThis = currentMap.pop();
            currentNode.pop();
            FieldTag ft = new FieldTag(currentMap.lastElement(), null, fixThis.getRefAttribute());
            currentNode.push(ft);
            currentField.push(ft);
            currentMessage.lastElement().removeMap(fixThis);
            currentMessage.lastElement().addField(ft);
            ft.addExpression(et);
        } else {
            throw new Exception("Expression tags can only be found under following tags: property, field, param");
        }
        currentNode.push(et);
        return;
    }
    if (tag.equals(Tags.PARAM)) {
        ParamTag pt = new ParamTag(currentDocument, h.get(Attributes.CONDITION), h.get(Attributes.NAME));
        String mode = h.get(Attributes.MODE);
        String value = h.get(Attributes.VALUE);
        pt.setType(h.get(Attributes.TYPE));
        if (value != null && !"".equals(value)) {
            // String Constant as value.
            ExpressionTag et = new ExpressionTag(currentDocument);
            et.setConstant(value);
            pt.addExpression(et);
        }
        pt.setMode(mode);
        if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
            currentMessage.lastElement().addParam(pt);
        } else if (currentParent instanceof MapTag && currentMap != null) {
            currentMap.lastElement().addParam(pt);
        } else if (currentParent instanceof BlockTag) {
            ((BlockTag) currentParent).add(pt);
        } else if (currentParent instanceof FinallyTag) {
            ((FinallyTag) currentParent).add(pt);
        } else if (currentParent instanceof SynchronizedTag) {
            ((SynchronizedTag) currentParent).add(pt);
        } else if (currentParent instanceof NavascriptTag) {
            currentDocument.addParam(pt);
        } else if (currentParent instanceof ParamTag) {
            ((ParamTag) currentParent).addParam(pt);
        } else {
            throw new Exception("Did not expect param tag under this parent: " + currentParent.getTagName());
        }
        currentNode.push(pt);
    }
    if (tag.equals(Tags.PROPERTY)) {
        String name = h.get(Attributes.NAME);
        String val = h.get(Attributes.VALUE);
        String type = h.get(Attributes.TYPE);
        String direction = h.get(Attributes.DIRECTION);
        String description = h.get(Attributes.DESCRIPTION);
        String length = h.get(Attributes.LENGTH);
        String cardinality = h.get(Attributes.CARDINALITY);
        String condition = h.get(Attributes.CONDITION);
        int iLen = (length != null ? Integer.parseInt(length) : 0);
        PropertyTag pt = new PropertyTag(currentDocument, name, type, val, iLen, description, direction);
        pt.setCondition(condition);
        if (cardinality != null) {
            pt.setCardinality(cardinality);
        }
        if (val != null) {
            // Dit kan NOG strakker. Niet alle types hoeven geunescaped worder
            Hashtable<String, String> h2 = new Hashtable<String, String>(h);
            val = BaseNode.XMLUnescape(val);
            h2.put(Attributes.VALUE, val);
        }
        if (currentParent instanceof MessageTag && currentMessage.size() > 0) {
            currentMessage.lastElement().addProperty(pt);
        } else if (currentParent instanceof MapTag && currentMap != null) {
            currentMap.lastElement().addProperty(pt);
        } else if (currentParent instanceof BlockTag) {
            ((BlockTag) currentParent).add(pt);
        } else {
            throw new Exception("Property tags can only be found under a message, map or block tag.");
        }
        currentNode.push(pt);
        return;
    }
    if (currentMap.size() > 0 && tag.startsWith(currentMap.lastElement().getAdapterName() + ".")) {
        // navajomap.callwebservice
        String fieldName = tag.split("\\.")[1];
        String adapterName = tag.split("\\.")[0];
        boolean isField = mapChecker.isField(adapterName, fieldName);
        if (currentParent instanceof MessageTag && isField && h.get(Attributes.VALUE) == null) {
            // Mapped field if it is a getter (no value field specified and no expression under the tag)
            // map ref on message
            MapTag mt = new MapTag(currentDocument, fieldName, h.get(Attributes.FILTER), currentMap.lastElement(), false);
            Map<String, String> attributeMap = new HashMap<>();
            for (String key : h.keySet()) {
                attributeMap.put(key, h.get(key));
            }
            mt.addAttributes(attributeMap);
            currentMessage.lastElement().addMap(mt);
            currentMap.push(mt);
            currentNode.push(mt);
        } else if (currentParent instanceof PropertyTag) {
            // selection property
            MapTag mt = new MapTag(currentDocument, fieldName, h.get(Attributes.FILTER), currentMap.lastElement(), false);
            Map<String, String> attributeMap = new HashMap<>();
            for (String key : h.keySet()) {
                attributeMap.put(key, h.get(key));
            }
            mt.addAttributes(attributeMap);
            ((PropertyTag) currentParent).addMap(mt);
            currentMap.push(mt);
            currentNode.push(mt);
        } else if (currentParent instanceof ParamTag) {
            // mapped param
            MapTag mt = new MapTag(currentDocument, fieldName, h.get(Attributes.FILTER), currentMap.lastElement(), false);
            Map<String, String> attributeMap = new HashMap<>();
            for (String key : h.keySet()) {
                attributeMap.put(key, h.get(key));
            }
            mt.addAttributes(attributeMap);
            ((ParamTag) currentParent).addMap(mt);
            ((ParamTag) currentParent).setType("array");
            currentMap.push(mt);
            currentNode.push(mt);
        } else {
            // Normal field
            FieldTag ft = new FieldTag(currentMap.lastElement(), null, fieldName);
            Map<String, String> attributeMap = new HashMap<>();
            for (String key : h.keySet()) {
                attributeMap.put(key, h.get(key));
            }
            ft.setAddAttributes(attributeMap);
            // TODO: Get all attributes of this tag and set them in field (navascript field can have any attribute value!
            if (h.get(Attributes.VALUE) != null) {
                ExpressionTag et = new ExpressionTag(currentDocument, h.get(Attributes.CONDITION), h.get(Attributes.VALUE));
                ft.addExpression(et);
            }
            if (currentParent instanceof MessageTag) {
                ((MessageTag) currentParent).addField(ft);
            } else if (currentParent instanceof BlockTag) {
                ((BlockTag) currentParent).add(ft);
            } else if (currentParent instanceof FinallyTag) {
                ((FinallyTag) currentParent).add(ft);
            } else if (currentParent instanceof MapTag) {
                ((MapTag) currentParent).addField(ft);
            } else {
                throw new Exception("Cannot place tag " + tag + " (setter/operation) under this tag: " + currentParent);
            }
            currentField.push(ft);
            currentNode.push(ft);
        }
    }
}
Also used : ParamTag(com.dexels.navajo.document.navascript.tags.ParamTag) HashMap(java.util.HashMap) ValueTag(com.dexels.navajo.document.navascript.tags.ValueTag) BreakTag(com.dexels.navajo.document.navascript.tags.BreakTag) NavascriptTag(com.dexels.navajo.document.navascript.tags.NavascriptTag) MapTag(com.dexels.navajo.document.navascript.tags.MapTag) BlockTag(com.dexels.navajo.document.navascript.tags.BlockTag) DefineTag(com.dexels.navajo.document.navascript.tags.DefineTag) IncludeTag(com.dexels.navajo.document.navascript.tags.IncludeTag) MethodTag(com.dexels.navajo.document.navascript.tags.MethodTag) FieldTag(com.dexels.navajo.document.navascript.tags.FieldTag) SynchronizedTag(com.dexels.navajo.document.navascript.tags.SynchronizedTag) DefinesTag(com.dexels.navajo.document.navascript.tags.DefinesTag) DebugTag(com.dexels.navajo.document.navascript.tags.DebugTag) Hashtable(java.util.Hashtable) CheckTag(com.dexels.navajo.document.navascript.tags.CheckTag) BaseNode(com.dexels.navajo.document.base.BaseNode) LogTag(com.dexels.navajo.document.navascript.tags.LogTag) ExpressionTag(com.dexels.navajo.document.navascript.tags.ExpressionTag) FinallyTag(com.dexels.navajo.document.navascript.tags.FinallyTag) IOException(java.io.IOException) MethodsTag(com.dexels.navajo.document.navascript.tags.MethodsTag) PropertyTag(com.dexels.navajo.document.navascript.tags.PropertyTag) MessageTag(com.dexels.navajo.document.navascript.tags.MessageTag) SelectionTag(com.dexels.navajo.document.navascript.tags.SelectionTag) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with MapTag

use of com.dexels.navajo.document.navascript.tags.MapTag in project navajo by Dexels.

the class NavascriptSaxHandler method text.

@Override
public void text(Reader r) throws Exception {
    StringWriter sw = new StringWriter();
    copyTextBuffer(sw, (PushbackReader) r);
    String text = sw.toString();
    BaseNode n = currentNode.lastElement();
    if (n instanceof BaseCheckTagImpl) {
        ((BaseCheckTagImpl) n).setRule(text);
    } else if (n instanceof BaseExpressionTagImpl) {
        ((BaseExpressionTagImpl) n).setConstant(text);
    } else if (n instanceof BaseFieldTagImpl) {
        ((BaseFieldTagImpl) n).setConstant(text);
    } else if (n instanceof ValueTag) {
        ((ValueTag) n).setValue(text);
    } else if (n instanceof DefineTag) {
        ((DefineTag) n).setExpression(text);
    } else {
        logger.info("Cannot place text under node, it must be a field tag. Correct.");
        if (currentNode.lastElement() instanceof MapTag) {
            currentMap.pop();
        } else {
            throw new Exception("Expected a MapTag to be corrected for a FieldTag not a " + currentNode.lastElement() + " tag.");
        }
        currentNode.pop();
        FieldTag ft = new FieldTag(currentMap.lastElement(), null, ((MapTag) n).getRefAttribute());
        ft.setConstant(text);
        BaseNode p = currentNode.lastElement();
        if (p instanceof MessageTag) {
            MessageTag mt = (MessageTag) p;
            mt.removeLastChild();
            mt.addField(ft);
        }
        currentNode.push(ft);
        currentField.push(ft);
    }
}
Also used : StringWriter(java.io.StringWriter) BaseCheckTagImpl(com.dexels.navajo.document.base.BaseCheckTagImpl) ValueTag(com.dexels.navajo.document.navascript.tags.ValueTag) DefineTag(com.dexels.navajo.document.navascript.tags.DefineTag) BaseNode(com.dexels.navajo.document.base.BaseNode) MessageTag(com.dexels.navajo.document.navascript.tags.MessageTag) FieldTag(com.dexels.navajo.document.navascript.tags.FieldTag) BaseExpressionTagImpl(com.dexels.navajo.document.base.BaseExpressionTagImpl) BaseFieldTagImpl(com.dexels.navajo.document.base.BaseFieldTagImpl) MapTag(com.dexels.navajo.document.navascript.tags.MapTag) IOException(java.io.IOException)

Example 10 with MapTag

use of com.dexels.navajo.document.navascript.tags.MapTag in project navajo by Dexels.

the class NavascriptGenerator method main.

public static void main(String[] args) {
    NavascriptTag navascript = new NavascriptTag();
    navascript.addParam(null, "MyParam").addExpression("1 == 2", "60").addExpression(null, "78");
    MapTag map = navascript.addMap(null, "sqlquery");
    navascript.addMap(null, "sqlquery");
    map.addParam(null, "AnotherParam").addExpression("1 == 2", "'AAP'").addExpression("IsEmpty([/Fluit/Ketel]", "'MIES'").addExpression(null, "'NOOT'");
    map.addField(null, "transactionContext").addExpression("?[/Transaction/TransactionContext]", "[/Transaction/TransactionContext]").addExpression(null, "23124343");
    navascript.addMessage("SomeMessage", null).addProperty(null, "LastName", "string").addExpression(null, "'Bergman'");
    map.addMessage("ResultSet", null).addMap(null, "resultSet", map, false).addProperty(null, "FirstName", "string").addExpression(null, "$columnValue('firstname')");
    navascript.write(System.out);
}
Also used : NavascriptTag(com.dexels.navajo.document.navascript.tags.NavascriptTag) MapTag(com.dexels.navajo.document.navascript.tags.MapTag)

Aggregations

MapTag (com.dexels.navajo.document.navascript.tags.MapTag)15 CaseSensitiveXMLElement (com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement)12 XMLElement (com.dexels.navajo.document.nanoimpl.XMLElement)12 NS3Compatible (com.dexels.navajo.document.navascript.tags.NS3Compatible)7 FieldTag (com.dexels.navajo.document.navascript.tags.FieldTag)6 MessageTag (com.dexels.navajo.document.navascript.tags.MessageTag)5 ParamTag (com.dexels.navajo.document.navascript.tags.ParamTag)5 ExpressionTag (com.dexels.navajo.document.navascript.tags.ExpressionTag)4 IncludeTag (com.dexels.navajo.document.navascript.tags.IncludeTag)4 BlockTag (com.dexels.navajo.document.navascript.tags.BlockTag)3 BreakTag (com.dexels.navajo.document.navascript.tags.BreakTag)3 DebugTag (com.dexels.navajo.document.navascript.tags.DebugTag)3 DefineTag (com.dexels.navajo.document.navascript.tags.DefineTag)3 LogTag (com.dexels.navajo.document.navascript.tags.LogTag)3 LoopTag (com.dexels.navajo.document.navascript.tags.LoopTag)3 SynchronizedTag (com.dexels.navajo.document.navascript.tags.SynchronizedTag)3 BaseNode (com.dexels.navajo.document.base.BaseNode)2 FinallyTag (com.dexels.navajo.document.navascript.tags.FinallyTag)2 MethodsTag (com.dexels.navajo.document.navascript.tags.MethodsTag)2 NavascriptTag (com.dexels.navajo.document.navascript.tags.NavascriptTag)2