Search in sources :

Example 11 with XMLElement

use of com.dexels.navajo.document.nanoimpl.XMLElement 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 12 with XMLElement

use of com.dexels.navajo.document.nanoimpl.XMLElement 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 13 with XMLElement

use of com.dexels.navajo.document.nanoimpl.XMLElement in project navajo by Dexels.

the class NS3ToNSXML method parseExpression.

private String parseExpression(XMLElement currentXML) {
    ExpressionFragment ef = new ExpressionFragment();
    currentXML.setAttribute("PROCESSED", "true");
    Vector<XMLElement> children = currentXML.getChildren();
    for (XMLElement child : children) {
        String name = child.getName();
        if (name.equals("Expression")) {
            consumeContent(ef, child);
        }
    }
    return ef.consumedFragment();
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Example 14 with XMLElement

use of com.dexels.navajo.document.nanoimpl.XMLElement in project navajo by Dexels.

the class NS3ToNSXML method parseFinally.

private FinallyTag parseFinally(NS3Compatible parent, XMLElement xe) throws Exception {
    FinallyTag ft = new FinallyTag(myNavascript);
    ft.addParent(parent);
    Vector<XMLElement> children = xe.getChildren();
    for (XMLElement child : children) {
        String name = child.getName();
        if (name.equals("TopLevelStatement")) {
            List<NS3Compatible> innerBodyElements = parseInnerBody(ft, child);
            for (NS3Compatible ib : innerBodyElements) {
                addChildTag(ft, ib);
            }
        }
    }
    return ft;
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) FinallyTag(com.dexels.navajo.document.navascript.tags.FinallyTag) NS3Compatible(com.dexels.navajo.document.navascript.tags.NS3Compatible)

Example 15 with XMLElement

use of com.dexels.navajo.document.nanoimpl.XMLElement in project navajo by Dexels.

the class NS3ToNSXML method parseOptionElement.

private void parseOptionElement(ParamTag ft, XMLElement currentXML) {
    Vector<XMLElement> children = currentXML.getChildren();
    ParamTag pt = null;
    for (XMLElement child : children) {
        String name = child.getName();
        String content = (child.getContent() != null && !"".equals(child.getContent()) ? child.getContent() : null);
        if (name.equals("TOKEN") && (content.equals("name") || content.equals("value") || content.equals("selected"))) {
            pt = new ParamTag(myNavascript);
            pt.setName(content);
            ft.addParam(pt);
        }
        if (name.equals("ConditionalExpressions")) {
            List<ExpressionTag> expressions = parseConditionalExpressions(pt, child);
            for (ExpressionTag et : expressions) {
                pt.addExpression(et);
            }
        }
    }
}
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)

Aggregations

XMLElement (com.dexels.navajo.document.nanoimpl.XMLElement)120 CaseSensitiveXMLElement (com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement)109 MapTag (com.dexels.navajo.document.navascript.tags.MapTag)12 IOException (java.io.IOException)12 NS3Compatible (com.dexels.navajo.document.navascript.tags.NS3Compatible)10 ArrayList (java.util.ArrayList)8 ParamTag (com.dexels.navajo.document.navascript.tags.ParamTag)7 InputStreamReader (java.io.InputStreamReader)7 HashMap (java.util.HashMap)7 APIException (com.dexels.navajo.article.APIException)6 ExpressionTag (com.dexels.navajo.document.navascript.tags.ExpressionTag)5 FieldTag (com.dexels.navajo.document.navascript.tags.FieldTag)5 FileInputStream (java.io.FileInputStream)5 FileReader (java.io.FileReader)5 Property (com.dexels.navajo.document.Property)4 IncludeTag (com.dexels.navajo.document.navascript.tags.IncludeTag)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 File (java.io.File)4 Message (com.dexels.navajo.document.Message)3 BlockTag (com.dexels.navajo.document.navascript.tags.BlockTag)3