Search in sources :

Example 11 with JsonObject

use of net.jangaroo.exml.json.JsonObject in project jangaroo-tools by CoreMedia.

the class ExmlToModelParserTest method testParseActions.

@Test
public void testParseActions() throws Exception {
    setUp("exmlparser.config");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/exmlparser/TestActions.exml"));
    Assert.assertEquals("ext.Panel", model.getSuperClassName());
    JsonObject expectedJsonObject = new JsonObject("baseAction", JsonObject.code("net.jangaroo.ext.create(ext.config.action,{disabled: false})"));
    System.out.println(model.getJsonObject().toString(2));
    Assert.assertEquals(expectedJsonObject.toString(2), model.getJsonObject().toString(2));
}
Also used : ExmlModel(net.jangaroo.exml.model.ExmlModel) JsonObject(net.jangaroo.exml.json.JsonObject) ExmlToModelParser(net.jangaroo.exml.parser.ExmlToModelParser) Test(org.junit.Test)

Example 12 with JsonObject

use of net.jangaroo.exml.json.JsonObject in project jangaroo-tools by CoreMedia.

the class ExmlToModelParserTest method testParseTyped.

@Test
public void testParseTyped() throws Exception {
    setUp("exmlparser.config");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/exmlparser/TestTyped.exml"));
    Assert.assertEquals("ext.Panel", model.getSuperClassName());
    JsonObject expectedJsonObject = new JsonObject("items", new JsonArray(new JsonObject("xtype", "component", // not the number 5!
    "margins", // not the number 5!
    "5"), new JsonObject("xtype", "component", // not the boolean false!
    "id", // not the boolean false!
    "false")));
    System.out.println(model.getJsonObject().toString(2));
    Assert.assertEquals(expectedJsonObject.toString(2), model.getJsonObject().toString(2));
}
Also used : JsonArray(net.jangaroo.exml.json.JsonArray) ExmlModel(net.jangaroo.exml.model.ExmlModel) JsonObject(net.jangaroo.exml.json.JsonObject) ExmlToModelParser(net.jangaroo.exml.parser.ExmlToModelParser) Test(org.junit.Test)

Example 13 with JsonObject

use of net.jangaroo.exml.json.JsonObject in project jangaroo-tools by CoreMedia.

the class ExmlToModelParserTest method testParseTestNumber.

@Test
public void testParseTestNumber() throws Exception {
    setUp("exmlparser.config");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/exmlparser/TestNumber.exml"));
    Assert.assertEquals("ext.Panel", model.getSuperClassName());
    JsonObject expectedJsonObject = new JsonObject("items", new JsonArray(new JsonObject("xtype", "panel", "id", "foo", "x", 100.0), new JsonObject("xtype", "panel", "id", "foo", "x", 1.5), new JsonObject("xtype", "panel", "id", "foo", "x", 1.0), new JsonObject("xtype", "panel", "id", "foo", "x", -1.5), new JsonObject("xtype", "panel", "id", "foo", "x", 3.0)));
    System.out.println(model.getJsonObject().toString(2));
    Assert.assertEquals(expectedJsonObject.toString(2), model.getJsonObject().toString(2));
}
Also used : JsonArray(net.jangaroo.exml.json.JsonArray) ExmlModel(net.jangaroo.exml.model.ExmlModel) JsonObject(net.jangaroo.exml.json.JsonObject) ExmlToModelParser(net.jangaroo.exml.parser.ExmlToModelParser) Test(org.junit.Test)

Example 14 with JsonObject

use of net.jangaroo.exml.json.JsonObject in project jangaroo-tools by CoreMedia.

the class ExmlToModelParserTest method testConfigModes.

@Test
public void testConfigModes() throws Exception {
    setUp("testNamespace.config");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/testPackage/TestComponentWithConfigModes.exml"));
    Assert.assertEquals("testPackage.TestComponent", model.getSuperClassName());
    JsonObject expectedJsonObject = new JsonObject("items", new JsonArray(new JsonObject("propertyThree", "3").settingWrapperClass("testNamespace.config.testComponent2")), "items$at", JsonObject.code("net.jangaroo.ext.Exml.APPEND"), "propertyFive", new JsonArray(new JsonObject("xtype", "agridcolumn")), "propertyFive$at", JsonObject.code("net.jangaroo.ext.Exml.PREPEND"), "layoutConfig", new JsonObject("mode", "foo"));
    System.out.println(model.getJsonObject().toString(2));
    Assert.assertEquals(expectedJsonObject.toString(2), model.getJsonObject().toString(2));
}
Also used : JsonArray(net.jangaroo.exml.json.JsonArray) ExmlModel(net.jangaroo.exml.model.ExmlModel) JsonObject(net.jangaroo.exml.json.JsonObject) ExmlToModelParser(net.jangaroo.exml.parser.ExmlToModelParser) Test(org.junit.Test)

Example 15 with JsonObject

use of net.jangaroo.exml.json.JsonObject in project jangaroo-tools by CoreMedia.

the class ExmlToModelParser method parseExmlObjectNode.

private Object parseExmlObjectNode(Node exmlObjectNode) {
    String textContent = exmlObjectNode.getTextContent();
    if (textContent != null && textContent.length() > 0) {
        return JsonObject.code(textContent.trim());
    } else {
        if (!exmlObjectNode.hasAttributes()) {
            return null;
        }
        JsonObject object = new JsonObject();
        setUntypedAttributes(exmlObjectNode, object);
        return object;
    }
}
Also used : JsonObject(net.jangaroo.exml.json.JsonObject)

Aggregations

JsonObject (net.jangaroo.exml.json.JsonObject)17 ExmlModel (net.jangaroo.exml.model.ExmlModel)11 ExmlToModelParser (net.jangaroo.exml.parser.ExmlToModelParser)11 Test (org.junit.Test)11 JsonArray (net.jangaroo.exml.json.JsonArray)10 Element (org.w3c.dom.Element)3 ConfigAttribute (net.jangaroo.exml.model.ConfigAttribute)2 ConfigClass (net.jangaroo.exml.model.ConfigClass)2 ArrayList (java.util.ArrayList)1 ExmlcException (net.jangaroo.exml.api.ExmlcException)1 Code (net.jangaroo.exml.json.Code)1 Declaration (net.jangaroo.exml.model.Declaration)1