Author: max
Date: 2007-06-18 14:58:11 -0700 (Mon, 18 Jun 2007)
New Revision: 5461

Added:
   openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/LzLibrary.js
Modified:
   openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/Library.lzs
   
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java
   
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/DHTMLWriter.java
   
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/ImportCompiler.java
   
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/ObjectWriter.java
   
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/SWFWriter.java
   openlaszlo/branches/legals/lps/includes/source/embednew.js
Log:
Change 20070618-maxcarlson-L by [EMAIL PROTECTED] on 2007-06-18 14:06:31 PDT
    in /Users/maxcarlson/openlaszlo/legals-clean
    for http://svn.openlaszlo.org/openlaszlo/branches/legals

Summary: UPDATED: add DHTML loadable library support to server

New Features:

Bugs Fixed:

Technical Reviewer: hminsky
QA Reviewer: ptw
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details: compiles a .js library file in the usual place 
(build/appname/libname.js) .  Henry: note that this fails to recompile if the 
library if compiled in debug mode, it fails on load for a non-debug mode run of 
the app.  Libraries should probably always be compiled as non-debug.

This change implements all the required client code.

Tests: 
http://localhost:8080/legals-clean/test/snippets/import-view.lzx?lzr=dhtml&lzt=html
 now runs.  
http://localhost:8080/legals-clean/test/snippets/import-view.lzx?lzr=dhtml&debug=true
 followed by 
http://localhost:8080/legals-clean/test/snippets/import-view.lzx?lzr=dhtml&lzt=html
 fails.



Modified: openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/Library.lzs
===================================================================
--- openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/Library.lzs 
2007-06-18 21:51:17 UTC (rev 5460)
+++ openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/Library.lzs 
2007-06-18 21:58:11 UTC (rev 5461)
@@ -12,6 +12,7 @@
 #include "kernel/dhtml/LzKeyboardKernel.js"
 #include "kernel/dhtml/LzMouseKernel.js"
 #include "kernel/dhtml/LzSprite.js"
+#include "kernel/dhtml/LzLibrary.js"
 #include "kernel/dhtml/LzTextSprite.js"
 #include "kernel/dhtml/LzInputTextSprite.js"
 #include "kernel/dhtml/LzXMLParser.js"

Added: openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/LzLibrary.js


Property changes on: 
openlaszlo/branches/legals/WEB-INF/lps/lfc/kernel/dhtml/LzLibrary.js
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Modified: 
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java
===================================================================
--- 
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java
     2007-06-18 21:51:17 UTC (rev 5460)
+++ 
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java
     2007-06-18 21:58:11 UTC (rev 5461)
@@ -135,7 +135,7 @@
         return compile(sourceFile, objectFile, props);
     }
 
-    public String getObjectFileExtensionForRuntime (String runtime) {
+    public static String getObjectFileExtensionForRuntime (String runtime) {
         String ext = SCRIPT_RUNTIMES.contains(runtime) ? ".js" : ".lzr=" + 
runtime + ".swf";
         return ext;
     }

Modified: 
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/DHTMLWriter.java
===================================================================
--- 
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/DHTMLWriter.java
  2007-06-18 21:51:17 UTC (rev 5460)
+++ 
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/DHTMLWriter.java
  2007-06-18 21:58:11 UTC (rev 5461)
@@ -44,6 +44,9 @@
     protected PrintWriter scriptWriter = null;
     protected StringWriter scriptBuffer = null;
 
+    /** Logger */
+    protected static Logger mLogger = 
org.apache.log4j.Logger.getLogger(DHTMLWriter.class);
+
     DHTMLWriter(Properties props, OutputStream stream,
                 CompilerMediaCache cache,
                 boolean importLibrary,
@@ -328,6 +331,7 @@
 
         try { 
             Properties props = (Properties)mProperties.clone();
+            scriptWriter.close();
             byte[] objcode = 
ScriptCompiler.compileToByteArray(scriptBuffer.toString(), props);
             InputStream input = new ByteArrayInputStream(objcode);
             mLogger.debug("compiled DHTML code is "+new String(objcode));
@@ -341,15 +345,42 @@
         mCloseCalled = true;
     }
 
-    public void openSnippet(String url) throws IOException { }
-    public void closeSnippet() throws IOException { }
+    public void openSnippet(String url) throws IOException {
+        this.liburl = url;
+    }
 
+    public void closeSnippet() throws IOException {
+        // Callback to let library know we're done loading
+        // TODO [hqm 2007 06] figure out where to get pointer to Library 
object so
+        // we can call back to it. Key by URL? 
+        addScript("LzLibrary.__LZsnippetLoaded('"+this.liburl+"')");
+
+        if (mCloseCalled) {
+            throw new IllegalStateException("DHTMLWriter.close() called 
twice");
+        }
+
+        try { 
+            Properties props = (Properties)mProperties.clone();
+            scriptWriter.close();
+            byte[] objcode = 
ScriptCompiler.compileToByteArray(scriptBuffer.toString(), props);
+            InputStream input = new ByteArrayInputStream(objcode);
+            mLogger.debug("compiled DHTML code is "+new String(objcode));
+            FileUtils.send(input, mStream);
+        } catch (org.openlaszlo.sc.CompilerException e) {
+            throw new CompilationError(e);
+        } catch (Exception e) {
+            throw new ChainedException(e);
+        }
+
+        mCloseCalled = true;
+    }
+
     /* [todo 2006-02-09 hqm] These methods are to be compatible with
        SWF font machinery -- this should get factored away someday so that the 
FontCompiler
        doesn't try to do anything with <font> tags in DHTML, (except maybe 
make aliases for them?)
     */
     FontManager getFontManager() {
-        mEnv.warn("DHTML runtime doesn't support FontManager API");
+        //        mEnv.warn("DHTML runtime doesn't support FontManager API");
         return null;
     }
 

Modified: 
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/ImportCompiler.java
===================================================================
--- 
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/ImportCompiler.java
       2007-06-18 21:51:17 UTC (rev 5460)
+++ 
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/ImportCompiler.java
       2007-06-18 21:58:11 UTC (rev 5461)
@@ -91,8 +91,10 @@
             // directly for now.
             String libfile = libsrcfile.getName();
             String libprefix = mEnv.getLibPrefix();
-            String objfilename = libprefix + "/" + libfile + ".swf";
-            String objpath = mEnv.getLibPrefixRelative() + "/" + libfile + 
".swf";
+            String runtime = mEnv.getProperty(mEnv.RUNTIME_PROPERTY);
+            String extension = Compiler.SCRIPT_RUNTIMES.contains(runtime) ? 
".js" : ".swf";
+            String objfilename = libprefix + "/" + libfile + extension;
+            String objpath = mEnv.getLibPrefixRelative() + "/" + libfile + 
extension;
 
             mLogger.info(
 /* (non-Javadoc)
@@ -143,8 +145,19 @@
 
             OutputStream ostream = new FileOutputStream(outfile);
             try {
-                ObjectWriter writer = new SWFWriter(env.getProperties(), 
ostream,
-                                                 env.getMediaCache(), false, 
env);
+                ObjectWriter writer;
+
+                String runtime = env.getProperty(env.RUNTIME_PROPERTY);
+                if (Compiler.SCRIPT_RUNTIMES.contains(runtime)) {
+                    writer = new DHTMLWriter(env.getProperties(), ostream,
+                                             env.getMediaCache(), false, env);
+                } else if (Compiler.SWF_RUNTIMES.contains(runtime)) {
+                    writer = new SWFWriter(env.getProperties(), ostream,
+                                           env.getMediaCache(), false, env);
+                } else {
+                    throw new CompilationError("runtime "+runtime+" not 
supported for generating an import library", element);
+                }
+                    
                 env.setObjectWriter(writer);
                 // Set the main SWFWriter so we can output resources
                 // to the main app
@@ -159,15 +172,14 @@
                 // copy the fontmanager from old env to new one.
                 writer.setFontManager(mEnv.getGenerator().getFontManager());
                 writer.setCanvasDefaults(mEnv.getCanvas(), 
mEnv.getMediaCache());
-
                 
-                String objpath = mEnv.getLibPrefixRelative() + "/" + outfile + 
".swf";
-
                 writer.openSnippet(liburl);
 
                 // allows snippet code to call out to LzInstantiateView in the 
main app:
                 // var LzInstantiateView = _level0.LzInstantiateView;
-                env.compileScript("var "+VIEW_INSTANTIATION_FNAME+" = 
_level0."+VIEW_INSTANTIATION_FNAME, element);
+                if (Compiler.SWF_RUNTIMES.contains(runtime)) {
+                    env.compileScript("var "+VIEW_INSTANTIATION_FNAME+" = 
_level0."+VIEW_INSTANTIATION_FNAME, element);
+                }
 
                 // Note: canvas.initDone() resets the _lzinitialsubviews list, 
so
                 // that has to be called when the library finishes loading. 
This is currently

Modified: 
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/ObjectWriter.java
===================================================================
--- 
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/ObjectWriter.java
 2007-06-18 21:51:17 UTC (rev 5460)
+++ 
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/ObjectWriter.java
 2007-06-18 21:58:11 UTC (rev 5461)
@@ -74,6 +74,8 @@
     /** Properties */
     protected Properties mProperties;
 
+    protected String liburl = "";
+
     /** media cache for transcoding */
     protected CompilerMediaCache mCache = null;
 

Modified: 
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/SWFWriter.java
===================================================================
--- 
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/SWFWriter.java
    2007-06-18 21:51:17 UTC (rev 5460)
+++ 
openlaszlo/branches/legals/WEB-INF/lps/server/src/org/openlaszlo/compiler/SWFWriter.java
    2007-06-18 21:58:11 UTC (rev 5461)
@@ -909,7 +909,6 @@
         mCloseCalled = true;
     }
 
-    protected String liburl = "";
     public void openSnippet(String liburl) throws IOException {
         // How do we make sure an initial frame exists?  Does this do it? 
         Frame frame = mFlashFile.getMainScript().getFrameAt(mLastFrame);

Modified: openlaszlo/branches/legals/lps/includes/source/embednew.js
===================================================================
--- openlaszlo/branches/legals/lps/includes/source/embednew.js  2007-06-18 
21:51:17 UTC (rev 5460)
+++ openlaszlo/branches/legals/lps/includes/source/embednew.js  2007-06-18 
21:58:11 UTC (rev 5461)
@@ -203,12 +203,20 @@
     ,/** @access private */
     __dhtmlLoadScript: function (url) {
         var o = '<script type="text/javascript" language="JavaScript1.5" 
src="' + url +'"></script>';
-        
-        document.write(o);
         //alert(o);
+        document.writeln(o);
         return o;
     }
 
+    ,__dhtmlLoadLibrary: function (url) {
+        var o = document.createElement('script');
+        o.setAttribute('type', 'text/javascript');
+        o.setAttribute('src', url);
+        document.getElementsByTagName("head")[0].appendChild(o);
+        //alert(o);
+        return o;
+    }
+
     ,/** @access private */
     __getqueryurl: function (url, setglobals) {
         // strip query string to only args required by the compiler


_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins

Reply via email to