Search in sources :

Example 26 with XMLElement

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

the class MapDefinition method parseDef.

public static MapDefinition parseDef(XMLElement e) throws ClassNotFoundException, KeywordException {
    MapDefinition md = new MapDefinition(MapMetaData.getInstance());
    XMLElement c = e.getElementByTagName("tagname");
    if (c != null) {
        md.tagName = c.getContent();
    }
    XMLElement o = e.getElementByTagName("object");
    if (o != null) {
        md.objectName = o.getContent();
    }
    XMLElement d = e.getElementByTagName("description");
    if (d != null) {
        md.description = d.getContent();
    }
    XMLElement a = e.getElementByTagName("abstract");
    if (a != null) {
        md.abstractMap = a.getContent().equals("true");
    }
    XMLElement valuesTag = e.getElementByTagName("values");
    if (valuesTag != null) {
        Vector<XMLElement> ch = valuesTag.getChildren();
        for (int i = 0; i < ch.size(); i++) {
            XMLElement v = ch.get(i);
            ValueDefinition vd = ValueDefinition.parseDef(v);
            md.values.put(vd.getName(), vd);
        }
    }
    XMLElement methodsTag = e.getElementByTagName("methods");
    if (methodsTag != null) {
        Vector<XMLElement> ch = methodsTag.getChildren();
        for (int i = 0; i < ch.size(); i++) {
            XMLElement v = ch.get(i);
            MethodDefinition mdef = MethodDefinition.parseDef(v);
            md.methods.put(mdef.getName(), mdef);
        }
    }
    return md;
}
Also used : XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Example 27 with XMLElement

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

the class MapDefinition method generateFieldCode.

private void generateFieldCode(XMLElement child, XMLElement mout, String filename, boolean isMethod) throws MetaCompileException {
    // First process children...
    if (child.getChildren().size() > 0 && !child.getFirstChild().getName().equals("value")) {
        Vector<XMLElement> vc = child.getChildren();
        for (int vci = 0; vci < vc.size(); vci++) {
            if (child.getName().indexOf(".") != -1) {
                String name = vc.get(vci).getName();
                if (name.indexOf(".") == -1) {
                    // Construct dummy prefix if prefix not present..
                    vc.get(vci).setName("dummy." + name);
                }
                generateFieldCode(vc.get(vci), mout, filename, getMethodDefinition(stripDot(vc.get(vci))) != null);
            } else {
                throw new MetaCompileException(filename, child, "Illegal children tags defined for tag <" + child.getName() + "/>");
            }
        }
    }
    if (isMethod) {
        String method = stripDot(child);
        MethodDefinition md = getMethodDefinition(method);
        md.generateCode(child, mout, filename);
    } else {
        String field = stripDot(child);
        String condition = (String) child.getAttribute("condition");
        // Check for <map.xyz><value condition=""></value>...<value></value></map.xyz> construction.
        if (child.getChildren().size() > 0 && child.getFirstChild().getName().equals("value")) {
            XMLElement fieldElt = new TSLElement(child, "field");
            fieldElt.setAttribute("name", field);
            if (condition != null && !condition.equals("")) {
                fieldElt.setAttribute("condition", condition);
            }
            Vector<XMLElement> values = child.getChildren();
            for (int val = 0; val < values.size(); val++) {
                XMLElement xec = values.get(val);
                XMLElement expressionElt = new TSLElement(child, "expression");
                String valueCondition = (String) xec.getAttribute("condition");
                XMLElement valueElt = new TSLElement(child, "value");
                if (valueCondition != null) {
                    expressionElt.setAttribute("condition", valueCondition);
                }
                valueElt.setContent(xec.getContent().trim());
                expressionElt.addChild(valueElt);
                fieldElt.addChild(expressionElt);
            }
            mout.addChild(fieldElt);
        } else {
            // <map.xyz value=""> or <map.xyz>value</map.xyz> construction.
            String setterValue = (child.getAttribute("value") != null ? (String) child.getAttribute("value") : (String) child.getAttribute("ref"));
            // Maybe value is given as tag content?
            boolean isTextNode = false;
            if (setterValue == null) {
                setterValue = child.getContent();
                if (setterValue == null || "".equals(setterValue)) {
                    throw new MetaCompileException(filename, child, "Did not find any value that could be set for setter <" + child.getName() + "/>" + " in " + this.objectName);
                }
                setterValue = setterValue.trim();
                isTextNode = true;
            }
            ValueDefinition vd = getValueDefinition(field);
            if (vd == null) {
                throw new MetaCompileException(filename, child, "Could not find definition for setter: " + field + " in " + this.objectName);
            }
            vd.generateCode(child, setterValue, isTextNode, condition, mout, true, filename);
        }
    }
}
Also used : XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Example 28 with XMLElement

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

the class MapMetaData method parse.

public void parse(XMLElement in, String scriptName, Writer sw) throws MetaCompileException, IOException, ClassNotFoundException {
    // Remember tsl attributes.
    Map<String, String> tslAttributes = new HashMap<>();
    Iterator<String> all = in.enumerateAttributeNames();
    while (all.hasNext()) {
        String name = all.next();
        String value = in.getAttribute(name) + "";
        tslAttributes.put(name, value);
    }
    XMLElement result = new CaseSensitiveXMLElement();
    result.setName("tsl");
    generateCode(in, result, scriptName);
    // Reinsert tsl attributes.
    all = tslAttributes.keySet().iterator();
    while (all.hasNext()) {
        String name = all.next().toString();
        String value = tslAttributes.get(name);
        result.setAttribute(name, value);
    }
    result.write(sw);
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) HashMap(java.util.HashMap) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Example 29 with XMLElement

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

the class MapMetaData method readExtentionDefinition.

public void readExtentionDefinition(ExtensionDefinition ed) throws IOException, ClassNotFoundException, KeywordException {
    // System.err.println("In MapMetaData. ExtensionDefinition: " + ed);
    BufferedReader br = new BufferedReader(new InputStreamReader(ed.getDefinitionAsStream(), StandardCharsets.UTF_8));
    XMLElement config = new CaseSensitiveXMLElement();
    config.parseFromReader(br);
    br.close();
    if (config.getName().equals("adapterdef")) {
        Vector<XMLElement> allmaps = config.getElementsByTagName("map");
        for (int i = 0; i < allmaps.size(); i++) {
            XMLElement map = allmaps.get(i);
            addMapDefinition(map);
        }
    }
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Example 30 with XMLElement

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

the class MapMetaData method isMetaScript.

public static boolean isMetaScript(String fullScriptPath) {
    try (InputStreamReader isr = new InputStreamReader(new FileInputStream(fullScriptPath), StandardCharsets.UTF_8)) {
        XMLElement x = new CaseSensitiveXMLElement();
        x.parseFromReader(isr);
        return (x.getName().equals("navascript"));
    } catch (Exception e) {
        AuditLog.log("", "Something went wrong while in determination of metascript status of script: " + fullScriptPath + "(" + e.getMessage() + ")", Level.WARNING);
        return false;
    }
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) InputStreamReader(java.io.InputStreamReader) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

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