Stream-based Compilation
From OpenLaszlo
Notes on re-architecting the Laszlo compiler to compile streams.
Contents |
Rationale
This enables/simplifies these uses:
- Cocoon integration
- Zope integration
- Netkernel integration
- Tag library
Document Status
This is unfinished. The overview needs editing, and the design is unfinished.
Overview
[Notes from one message:]
The right solution would be to replace File by an subclass of org.xml.sax.InputSource in the compiler, and com.laszlosystems.FileResolver by an implementation of org.xml.sax.EntityResolver, that returns an instance of this subclass.
The reason it's necessary to subclass InputSource is that the compiler uses a set of caches to avoid re-transcoding media (images, audio files, and fonts), and recompiling unmodified sources. It currently uses the File length and modification time as a checksum for this. In the case where the interface is a stream, it could continue to use these properties when the stream is backed by a file, and note that the media entity *always* has to be re-transcoded, and the application *always* has to be recompiled, when they aren't available. As an optimization, when the InputSource is backed by a URL and the Content-Length and Date are available, these could be used, or maybe only if Content-Location is also available since in this use case it seems more likely than in the local filesystem case that multiple resources could have the same date and size and be served from the same url at different times.
[Notes from another message:]
The source code needs to be rearchitected to take an InputSource instead of a File, which involves touching a lot of files. And it would need to be a ??? in order to work with the dependency-tracking mechanism that works for file compilation. (The system caches both partial and total compilations when the files haven't changed, so it needs an API for retrieving a size, modtime, or other checksum for an input source.)
Work Items
Compiling Streamed Source
I'm not set on any of the class or method names here; I don't particularly like them.
Classes are in org.openlaszo.compiler where there's no package.
- FileResolver:
- Remove assertion that protocol == "file"
- Use URI method for resolution?
- Rename to Resolver or something else that doesn't include "File" (cosmetic; this isn't necessary for functionality)
- Parser
- getUserPathname: remove last URI component instead of File.parent()
- more TBD
- read: getCanonicalFile -> ???
- getUserPathname: remove last URI component instead of File.parent()
- Many classes:
- Replace File -> org.xml.sax.InputSource
On entry to media transcoders (ResourceCompiler, SplashCompiler, ViewCompiler), need to verify that protocol is "file:" (for now; task below removes this restriction).
Caching
This is optional. It allows the use of the compilation cache for URLs.
Classes are in org.openlaszo.compiler where there's no package; org.openlaszlo where there's just the tail of a package qualifier (e.g. cm/DependencyTracker)
- utils/TimestampedInputSource extends org.xml.sax.InputSource. (There has got to be a better name for this.)
- Adds
long getModificationTime() - Adds
long getSize() - Adds
boolean hasMetadata() - new TimestampedFileInputSource(File) creates an instance which returns true/File.lastModified()/File.length()
- new TimestampedFileInputSource(anything else) creates an instances which returns false/error/error
- Adds
- new TimestampedFileInputSource(URL) uses the last-modified and size from the URL request.
- In cm/DependencyTracker:
- FileInfo -> InputSourceInfo
- File -> TimestampedFileInputSource
Compiling Streamed Media
TBD.
Workaround
Copy the stream to a temp file, and use the Compiler_API to compile this. This doesn't lose any compilation speed, but it can be difficult to clean up the file.

