Search in sources :

Example 16 with ExmlModel

use of net.jangaroo.exml.model.ExmlModel 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 17 with ExmlModel

use of net.jangaroo.exml.model.ExmlModel 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 18 with ExmlModel

use of net.jangaroo.exml.model.ExmlModel in project jangaroo-tools by CoreMedia.

the class ExmlToModelParser method parse.

/**
 * Parses the exml file into an ExmlModel
 * @param file the file to parse
 * @return the parsed model
 * @throws IOException if the input stream could not be read
 * @throws SAXException if the XML was not well-formed
 */
public ExmlModel parse(File file) throws IOException, SAXException {
    ExmlModel model = new ExmlModel();
    String qName = CompilerUtils.qNameFromFile(registry.getConfig().findSourceDir(file), file);
    String className = CompilerUtils.className(qName);
    model.setClassName(ExmlUtils.createComponentClassName(className));
    ConfigClass configClassByName = registry.getConfigClassByName(registry.getConfig().getConfigClassPackage() + "." + ConfigClass.createConfigClassName(className));
    model.setConfigClass(configClassByName);
    model.setPackageName(CompilerUtils.packageName(qName));
    BufferedInputStream inputStream = null;
    try {
        inputStream = new BufferedInputStream(new FileInputStream(file));
        parse(inputStream, model);
    } finally {
        if (inputStream != null) {
            inputStream.close();
        }
    }
    return model;
}
Also used : ConfigClass(net.jangaroo.exml.model.ConfigClass) ExmlModel(net.jangaroo.exml.model.ExmlModel) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream)

Aggregations

ExmlModel (net.jangaroo.exml.model.ExmlModel)18 ExmlToModelParser (net.jangaroo.exml.parser.ExmlToModelParser)17 Test (org.junit.Test)16 JsonObject (net.jangaroo.exml.json.JsonObject)11 JsonArray (net.jangaroo.exml.json.JsonArray)10 File (java.io.File)4 ExmlSourceFile (net.jangaroo.exml.model.ExmlSourceFile)4 Declaration (net.jangaroo.exml.model.Declaration)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 StringWriter (java.io.StringWriter)1 ExmlComponentClassGenerator (net.jangaroo.exml.generator.ExmlComponentClassGenerator)1 ConfigAttribute (net.jangaroo.exml.model.ConfigAttribute)1 ConfigClass (net.jangaroo.exml.model.ConfigClass)1