Index: openacs-4/packages/acs-content-repository/tcl/revision-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/revision-procs.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/acs-content-repository/tcl/revision-procs.tcl 9 May 2001 05:15:58 -0000 1.4 +++ openacs-4/packages/acs-content-repository/tcl/revision-procs.tcl 31 Oct 2001 20:42:07 -0000 1.5 @@ -18,3 +18,69 @@ return $revision_id } + +ad_proc -public cr_write_content { + -item_id + -revision_id +} { + + @param item_id the item to write + @param revision_id revision to write + @author Don Baccus (dhogaza@pacifier.com) + + Write out the specified content to the current HTML connection. Only one of + item_id and revision_id should be passed to this procedure. If item_id is + provided the item's live revision will be written, otherwise the specified + revision. + + This routine was was written to centralize the downloading of data from + the content repository. Previously, similar code was scattered among + various packages, not all of which were written to handle both in-database + and in-filesystem storage of content items. + + Though this routine is written to be fully general in terms of a content + item's storage type, typically those stored as text aren't simply dumped + to the user in raw form, but rather ran through the templating system + in order to surround the content with decorative HTML. + +} { + + if { [info exists revision_id] && [info exists item_id] } { + return -code error "Both revision_id and item_id were specfied" + } + + if { [info exists item_id] } { + if { ![db_0or1row get_item_info ""] } { + return -code error "There is no content that matches item_id '$item_id'" + } + } elseif { [info exists revision_id] } { + if { ![db_0or1row get_revision_info ""] } { + return -code error "There is no content that matches revision_id '$revision_id'" + } + } else { + return -code error "Either revision_id or item_id must be specified" + } + + if { ![string equal $storage_type "file"] && \ + ![string equal $storage_type "text"] && \ + ![string equal $storage_type "lob"] } { + return -code error "Storage type '$storage_type' is invalid." + } + + ReturnHeaders $mime_type + + switch $storage_type { + text { + ns_write [db_string write_text_content] + } + file { + set path [cr_fs_path $storage_area_key] + db_write_blob write_file_content "" + } + lob { + db_write_blob write_lob_content "" + } + } + + return +}