/usr/share/tcltk/xotcl1.6.7-actiweb/WebDocument.xotcl is in xotcl 1.6.7-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | # $Id: WebDocument.xotcl,v 1.9 2007/08/14 16:38:26 neumann Exp $
package provide xotcl::actiweb::webDocument 0.8
package require xotcl::actiweb::webObject
package require xotcl::comm::httpAccess
package require xotcl::mixinStrategy
package require xotcl::actiweb::sendStrategy
package require XOTcl
namespace eval ::xotcl::actiweb::webDocument {
namespace import ::xotcl::*
Class WebDocument -superclass WebObject \
-parameter {
{content ""}
filename
}
WebDocument instproc init args {
my exportProcs content contentType
next
my mixinStrategy ::Send=TypedString
}
WebDocument instproc attachFile filename {
my filename $filename
my set oldSendStrategy [my mixinStrategy ::Send=File]
my contentType [Mime guessContentType $filename]
}
WebDocument instproc detachFile {} {
my mixinStrategy [my set oldSendStrategy]
my unset contentType
my unset filename
}
WebDocument instproc default args {
if {[my exists content]} {
return [my content]
}
return ""
}
#WebDocument instproc contentLength {} {
# my showCall
# return [expr {[string length [my content]] + 1}]
#}
Class TextDocument -superclass WebDocument
TextDocument instproc init args {
next
my contentType text/plain
}
Class HtmlDocument -superclass TextDocument
HtmlDocument instproc init args {
next
my contentType text/html
}
Class FileDocument -superclass WebDocument
#
# class factory creates classes on the fly if they do not exist
# already, otherwise return exisiting class
#
# auch flyweigth
Class DocumentClassFactory
DocumentClassFactory abstract instproc getClass contentType
Class FileDocumentClassFactory -superclass DocumentClassFactory
FileDocumentClassFactory instproc getClass contentType {
if {[FileDocument info classchildren $contentType] eq ""} {
Class ::FileDocument::${contentType} -superclass FileDocument
}
return ::FileDocument::${contentType}
}
Class DocumentFactory
DocumentFactory abstract instproc create {name args}
Class FileDocumentFactory -superclass DocumentFactory
FileDocumentFactory instproc create {name class filename} {
$class $name
#$name contentType [$class set contentType]
$name attachFile $filename
return $name
}
Class FileObjectifier
FileObjectifier instproc init args {
next
FileDocumentClassFactory [self]::clFactory
FileDocumentFactory [self]::objFactory
}
#
# filename must be given with full path ->
# create objects with filename's tail (prefix can be used to
# give object name a preceding dir)
#
FileObjectifier instproc objectifyFile {place filename {prefix ""}} {
set obj ""
if {[file isfile $filename]} {
set type [Mime guessContentType $filename]
#if {$type ne "unknown/unknown"} {
set fn [string trimleft $prefix/[file tail $filename] /]
set class [[self]::clFactory getClass $type]
set obj [[self]::objFactory create $fn $class $filename]
$place exportObjs $obj
#puts stderr "...objectified: $obj of class $class"
#}
}
return $obj
}
#
# objectify a whole directory tree
#
FileObjectifier instproc objectifyTree {place dir {prefix ""}} {
if {[file isdirectory $dir]} {
foreach f [glob -nocomplain $dir/*] {
if {[file isfile $f]} {
my objectifyFile $place $f $prefix
} elseif {[file isdirectory $f]} {
my objectifyTree $place $f $prefix/[file tail $f]
}
}
}
}
Class GraphicDirectoryObjectifier -superclass FileObjectifier \
-parameter {{thumbnaildir [::xotcl::tmpdir]}}
GraphicDirectoryObjectifier instproc objectifyTree {place dir {prefix ""}} {
if {[file isdirectory $dir]} {
set indexpage ""
set title ""
set date ""
foreach f [lsort [glob -nocomplain $dir/* $dir/{.date,.title}]] {
set exportedfn [string trimleft $prefix/[file tail $f] /]
if {[file isfile $f]} {
set type [Mime guessContentType $f]
if {[string match "image/*" $type]} {
set class [[self]::clFactory getClass $type]
$class $exportedfn -init -attachFile $f
$place exportObjs $exportedfn
#puts stderr "...objectified: FN=$exportedfn cl=$class d=$dir o=$exportedfn"
######
set expThumbnaildir [file dirname $exportedfn]/.thumbnail
set thumbnaildir [file dirname $f]/.thumbnail
if {![file isdirectory $thumbnaildir]} {
file mkdir $thumbnaildir
}
set thumbnail $thumbnaildir/[file tail $f]
set expThumbnail $expThumbnaildir/[file tail $f]
if {![file exists $thumbnail]} {
catch {exec djpeg -pnm $f | \
pnmscale -xscale .2 -yscale .2 | ppmquant 256 | \
ppmtogif > $thumbnail}
}
$class $expThumbnail -init -attachFile $thumbnail
$place exportObjs $expThumbnail
####
append indexpage "<A href='/$exportedfn'>" \
"<IMG SRC='/$expThumbnail'>$exportedfn</A><br>\n"
} elseif {[string match *.title $exportedfn]} {
set title [my fileContent $f]
} elseif {[string match *.date $exportedfn]} {
set date <H4>[my fileContent $f]</H4>
}
} elseif {[file isdirectory $f]} {
if {[file exists $f/.title]} {
set desc ": [my fileContent $f/.title]"
} else {
set desc ""
}
append indexpage "<A href='/$exportedfn/gindex.html'>" \
"$exportedfn</A>$desc<br>\n"
my objectifyTree $place $f $exportedfn
}
set gindex [string trimleft $prefix/gindex.html /]
HtmlDocument $gindex -content \
"<HTML><TITLE>$title</TITLE><H1>$title</H1>\
<BODY>$date$indexpage</BODY></HTML>"
#puts stderr "mixins of HtmlDocument=<[$gindex info mixins]>"
$gindex mixinStrategy ::Send=TypedString
#$gindex showVars
receiver exportObjs $gindex
}
}
}
GraphicDirectoryObjectifier instproc fileContent {f} {
set FILE [open $f r]
set content [read $FILE]
close $FILE
return $content
}
Class HtmlProxy -superclass HtmlDocument -parameter realSubject
HtmlProxy instproc init args {
next
[Place getInstance] exportObjs [self]
}
HtmlProxy instproc unknown {m args} {
my instvar realSubject
::eval $realSubject $m $args
return [my default]
}
namespace export \
WebDocument TextDocument HtmlDocument FileDocument \
DocumentClassFactory FileDocumentClassFactory \
DocumentFactory FileDocumentFactory \
FileObjectifier GraphicDirectoryObjectifier \
HtmlProxy
}
namespace import ::xotcl::actiweb::webDocument::*
|