1 4 5 9 10 package org.openlaszlo.compiler; 11 import org.openlaszlo.iv.flash.api.action.*; 12 import java.io.*; 13 import org.jdom.Element; 14 import org.jdom.JDOMException; 15 import org.openlaszlo.xml.internal.XMLUtils; 16 17 22 class DataCompiler extends ElementCompiler { 23 static final String LOCAL_DATA_FNAME = "lzAddLocalData"; 24 25 DataCompiler(CompilationEnvironment env) { 26 super(env); 27 } 28 29 static boolean isElement(Element element) { 30 if (element.getName().equals("dataset")) { 31 String src = element.getAttributeValue("src"); 33 String type = element.getAttributeValue("type"); 34 if (type != null && (type.equals("soap") || type.equals("http"))) { 35 return false; 36 } 37 if (src != null && src.indexOf("http:") == 0) { 38 return false; 39 } 40 return src == null || !XMLUtils.isURL(src); 41 } 42 return false; 43 } 44 45 public void compile(Element element) { 46 Element data = element; 47 if (element.getAttribute("src") != null) { 48 File file = resolveSrcReference(element); 49 try { 50 Element newdata = new org.jdom.input.SAXBuilder(false) 51 .build(file) 52 .getRootElement(); 53 54 data.addContent(newdata); 55 } catch (org.jdom.JDOMException e) { 56 throw new CompilationError(e); 57 } catch (java.lang.OutOfMemoryError e) { 58 throw new CompilationError("out of memory", element); 62 } 63 } 64 65 boolean trimwhitespace = true; 66 String trimAttr = element.getAttributeValue("trimwhitespace"); 67 if (trimAttr != null && trimAttr.equals("false")) { 68 trimwhitespace = false; 69 } 70 71 int flashVersion = mEnv.getSWFVersionInt(); 72 73 Program program = org.openlaszlo.xml.internal.DataCompiler.makeProgram(data, flashVersion, trimwhitespace, true); 74 76 program.push(LOCAL_DATA_FNAME); 77 program.push("_level0"); 78 program.getVar(); 79 program.push(LOCAL_DATA_FNAME); 80 program.getMember(); 81 program.setVar(); 82 83 program.push("__lzdataroot"); 84 program.getVar(); 85 program.push(XMLUtils.requireAttributeValue(element, "name")); 86 program.push(2); 87 program.push(LOCAL_DATA_FNAME); 88 program.callFunction(); 89 program.pop(); 90 mEnv.getGenerator().addProgram(program); 91 } 92 } 93 | Popular Tags |