Enhancements for response buffer handling
hide
ContentsWhat I propose here started out while thinking about ways to de-uglify res.debug(). My goals were:
After trying some superficial plastic surgery, it became clear to me that this is a model case for what Tobi proposed here and was implemented as res.pushBuffer() and res.popBuffer() in Helma 1.6. (This wasn't immediately obvious because I didn't think "skin rendering" when thinking about res.debug().) res.pushBuffer() and res.popBuffer() in Helma 1.6These new response methods allow to slip an existing java.lang.StringBuffer on top of the resoponse buffer stack (as opposed to res.push(), which always creates a new one), and get the StringBuffer out of the response buffer stack without converting it to a String (versus res.pop(), which does just that). In other words, the new methods allow you to get a StringBuffer in and out of the response object multiple times without the penalty of StringBuffer to String conversion. Unfortunately, res.pushBuffer() and res.popBuffer() is not quite as powerful as it should be. The problem is that the managing of StringBuffers is left to the application, which makes it quite difficult to implement a generic res.debug(). Proposed enhancement: manage buffers in res.buffersIn my eyes, we should enhance res.pushBuffer() to allow putting response buffers in a well-known, accessible location, and/or get them from there. Let's assume this location is called res.buffers. res.pushBuffer() would then optionally take a String argument:
A third variant may or may not make sense:
Auto-Expanding res.buffersFor programmatic access to res.buffers, it might be useful to auto-expand by automatically creating buffers that do not yet exist:
The nice thing here would be that for programmatic access we didn't even have to push/pop the buffer in question. What it would mean for res.debug()res.debug() could then be implemented as a method that writes to a buffer called "debug" (or "helma_debug"). Applications could simply provide their own version of res.debug(), and it would be easy to render skins to the response buffer, in addition to using res.write(). Other usesAnother area where this feature might prove useful is handling of javascript or style sheet resources included in a page. Sometimes individual modules of a web application need to add a script or style sheet to a page. Therefore, creating the Pages linking to this page: Core API Comments |
navigation
Download
Community
Weblog
Mailing Lists
IRC Channel
Documentation
Introductions
Tools
Reference
Project
Roadmap
Bug Reporting
Source
Helma NG Wiki
Wiki
Tags
Updates
Related Projects
Sites using Helma
Shop
search
tags for this page
all tags
Tagsapps (1) bugs (2) class (1) community (2) compatibility (1) concurrency (1) continuations (2) Documentation (6) dogfood (1) formatting (1) functions (1) gobi (1) helma (7) helma 1.6 (17) helma 1.7 (8) helma 1.x (4) Helma 1x (0) helma 2 (11) helma ng (20) hopobject (1) howto sample code xml-rpc (1) html (1) inheritance (5) introspection (1) java (3) javascript (5) jetty (4) JSDoc (1) lazy (1) marius person (1) metaprogramming (3) modules (5) oop (1) organization (2) ORM (2) parsing (1) plugins (1) project (2) projects (1) prototype (2) prototype scope rhino functions this (0) Rabbit (2) Reference (1) REPL (1) rhino (5) roadmap (3) scope (1) shell (1) shop (0) Skin Rendering (5) Snippets (1) source svn (1) sugar (3) templates (13) testing (5) this (1) Tobi (10) web.xml (2) xml (1) Pages linking to this page: Wiki Overview Text Draft, wiki pages linking here
|
Comments
#1 by midnightmonster at 2008/07/21 23:03 One of the benefits of using E4X for my "templating" is that I don't need any particular control over the buffers. Since my whole page lives as a tree in memory until I res.write it at the end of the request, I can modify any part at any time--e.g., add another script include to , add a message in , or add a debug message to(which it had never occurred to me to try since I always just debug to the console).
I know it's not usual to build the page as I do, but the only time I might use any more buffer power than exists would be if I were outputting to non-HTML.
The way the buffers currently are actually gives about the same functionality as PHP's output buffering--since I came from there, I'm pretty used to it.