Search in sources :

Example 6 with JsonObject

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

the class ExmlToModelParserTest method testParseTestTrueFalse.

@Test
public void testParseTestTrueFalse() throws Exception {
    setUp("exmlparser.config");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/exmlparser/TestTrueFalse.exml"));
    Assert.assertEquals("ext.Panel", model.getSuperClassName());
    JsonObject expectedJsonObject = new JsonObject("items", new JsonArray(new JsonObject("xtype", "panel", "id", "foo", "visible", true), new JsonObject("xtype", "panel", "id", "foo", "visible", false), new JsonObject("xtype", "panel", "id", "foo", "visible", true), new JsonObject("xtype", "panel", "id", "foo", "visible", 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 7 with JsonObject

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

the class ExmlToModelParserTest method testParseArrayAttribute.

@Test
public void testParseArrayAttribute() throws Exception {
    setUp("exmlparser.config");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/exmlparser/TestArrayAttribute.exml"));
    Assert.assertEquals("ext.Panel", model.getSuperClassName());
    JsonObject expectedJsonObject = new JsonObject("items", JsonObject.code("config.myItems"), "tools", new JsonArray("tools"));
    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 8 with JsonObject

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

the class ExmlToModelParserTest method testConfigDefaultValues.

@Test
public void testConfigDefaultValues() throws Exception {
    setUp("testNamespace.config");
    ExmlToModelParser exmlToModelParser = new ExmlToModelParser(getConfigClassRegistry());
    ExmlModel model = exmlToModelParser.parse(getFile("/testPackage/TestComponentWithCfgDefaults.exml"));
    List<ConfigAttribute> cfgs = model.getConfigClass().getDirectCfgs();
    Assert.assertEquals(9, cfgs.size());
    JsonObject expectedJsonObject = new JsonObject("propertyWithLiteralDefault", "foobar", "propertyWithExpressionDefault", JsonObject.code("'foo' + 'bar'"), "propertyWithDefaultElement", new JsonObject("xtype", "button", "text", "click me!"), "propertyWithDefaultElementUsingConfig", new JsonObject("xtype", "button", "text", JsonObject.code("config.title + '!'")), "arrayPropertyWithDefaultElement", new JsonArray(new JsonObject("xtype", "button", "text", "button1"), new JsonObject("xtype", "button", "text", "button2")), "propertyWithInterfaceAndDefault", JsonObject.code(" new TestImpl() "), "propertyFromOtherPackage", JsonObject.code(" new SomeOtherClass('lala') "));
    System.out.println(model.getJsonObject().toString(2));
    Assert.assertEquals(expectedJsonObject.toString(2), model.getCfgDefaults().toString(2));
}
Also used : JsonArray(net.jangaroo.exml.json.JsonArray) ExmlModel(net.jangaroo.exml.model.ExmlModel) ConfigAttribute(net.jangaroo.exml.model.ConfigAttribute) JsonObject(net.jangaroo.exml.json.JsonObject) ExmlToModelParser(net.jangaroo.exml.parser.ExmlToModelParser) Test(org.junit.Test)

Example 9 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)

Example 10 with JsonObject

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

the class ExmlToModelParser method ifContainerDefaultsThenExtractXtype.

private void ifContainerDefaultsThenExtractXtype(JsonObject jsonObject, ConfigClass configClass, String elementName) {
    // special case: extract xtype from <defaults> as <defaultType>!
    if (EXT_CONTAINER_DEFAULTS_PROPERTY.equals(elementName) && isContainerConfig(configClass)) {
        Object value = jsonObject.get(elementName);
        if (value instanceof JsonObject) {
            JsonObject jsonObjectValue = (JsonObject) value;
            // there are two ways an xtype can be specified:
            // a) as an EXML config class wrapping the JSON object:
            String xtype = jsonObjectValue.getWrapperClass();
            if (xtype != null) {
                jsonObjectValue.settingWrapperClass(null);
            } else {
                // b) as an "xtype" attribute:
                xtype = (String) jsonObjectValue.remove(ConfigClassType.COMPONENT.getType());
            }
            if (xtype != null) {
                jsonObject.set(EXT_CONTAINER_DEFAULT_TYPE_PROPERTY, xtype);
            }
        }
    }
}
Also used : JsonObject(net.jangaroo.exml.json.JsonObject) 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