Class ::xowiki::File (public)
::xo::db::CrClass ::xowiki::File
Defined in
- Testcases:
-
No testcase defined.
Source code:
namespace eval ::xowiki {}
::nsf::object::alloc ::xo::db::CrClass ::xowiki::File {set :__default_metaclass ::xotcl::Class
set :__default_superclass ::xotcl::Object
set :abstract_p f
set :auto_save false
array set :db_constraints {}
array set :db_slot {page_order ::xowiki::Page::slot::page_order creator ::xowiki::Page::slot::creator page_id ::xowiki::Page::slot::page_id creation_date ::xo::db::Object::slot::creation_date creation_user ::xo::db::Object::slot::creation_user object_id ::xo::db::Object::slot::object_id file_id ::xowiki::File::slot::file_id description ::xowiki::Page::slot::description text ::xowiki::Page::slot::text creation_ip ::xo::db::Object::slot::creation_ip object_title ::xo::db::Object::slot::object_title nls_language ::xo::db::CrItem::slot::nls_language package_id ::xo::db::Object::slot::package_id name ::xo::db::CrItem::slot::name mime_type ::xo::db::CrItem::slot::mime_type context_id ::xo::db::Object::slot::context_id security_inherit_p ::xo::db::Object::slot::security_inherit_p title ::xowiki::Page::slot::title revision_id ::xo::db::CrItem::slot::revision_id item_id ::xo::db::CrItem::slot::item_id last_modified ::xo::db::Object::slot::last_modified modifying_user ::xo::db::Object::slot::modifying_user publish_date ::xowiki::Page::slot::publish_date modifying_ip ::xo::db::Object::slot::modifying_ip}
set :folder_id -100
set :form ::xowiki::FileForm
set :id_column file_id
set :mime_type text/plain
set :name_method {}
set :non_cached_instance_var_patterns {import_file do_substitutions}
set :object_type ::xowiki::File
set :object_type_key 00000000000011110001100100000011
set :pretty_name #xowiki.File_pretty_name#
set :pretty_plural #xowiki.File_pretty_plural#
set :security_inherit_p t
set :sql_package_name ::xowiki::File
set :storage_type file
set :supertype content_revision
set :table_name xowiki_file
set :with_table true}
::xowiki::File instproc build_name {name {fn {}}} {
if {$name ne ""} {
set stripped_name $name
regexp {^(.*):(.*)$} $name _ _t stripped_name
} else {
set stripped_name $fn
regexp {[/\\]([^/\\]+)$} $stripped_name _ stripped_name
}
return file:[::${:package_id} normalize_name $stripped_name]
}
::xowiki::File instproc render_icon {} {
return {text "<a title='file' class='file-icon'> </a>" is_richtext true}
}
::xowiki::File instproc full_file_name {} {
if {![info exists :full_file_name]} {
if {[info exists :revision_id]} {
set :full_file_name [::xowiki::cache eval -partition_key ${:revision_id} ffn-${:revision_id} {
return [content::revision::get_cr_file_path -revision_id ${:revision_id}]
}]
}
}
return ${:full_file_name}
}
::xowiki::File instproc render_content {} {
set parent_id ${:parent_id}
set package_id ${:package_id}
set ctx [::$package_id context]
set revision_id [$ctx query_parameter revision_id:integer]
set query [expr {$revision_id ne "" ? "revision_id=$revision_id" : ""}]
set page_link [:pretty_link -download true -query $query]
if {[$ctx query_parameter html-content] ne ""} {
return [:html_content]
}
set t [TableWidget new -volatile -columns {
AnchorField name -label [_ xowiki.Page-name]
Field mime_type -label "#xowiki.content_type#"
Field last_modified -label "#xowiki.Page-last_modified#"
Field mod_user -label "#xowiki.By_user#"
Field size -label "#xowiki.Size# (Bytes)"
}]
regsub {[.][0-9]+([^0-9])} ${:last_modified} {\1} last_modified
::$package_id get_lang_and_name -name ${:name} lang stripped_name
set label $stripped_name
$t add -name $stripped_name -mime_type ${:mime_type} -name.href $page_link -last_modified $last_modified -mod_user [::xo::get_user_name ${:creation_user}] -size [file size [:full_file_name]]
switch -glob ${:mime_type} {
image/* {
set l [Link new -page [self] -query $query -type image -name ${:name} -lang "" -stripped_name $stripped_name -label $label -parent_id $parent_id -item_id ${:item_id} -package_id $package_id]
set preview "<div >[$l render]</div>"
$l destroy
}
text/plain {
set text [::xo::read_file [:full_file_name]]
set preview "<pre class='code'>[::xowiki::Includelet html_encode $text]</pre>"
}
default {set preview ""}
}
return "$preview[$t asHTML]\n<p>${:description}</p>"
}
::xowiki::File instproc demarshall args {
next
if {[info exists :__file_content]} {
::xo::write_tmp_file :import_file [::base64::decode ${:__file_content}]
unset :__file_content
} elseif {[info exists :__file_name]} {
set :import_file ${:__file_name}
unset :__file_name
} else {
error "either __file_content or __file_name must be set"
}
}
::xowiki::File instproc search_render {} {
if {${:mime_type} eq "text/plain"} {
set f [open [:full_file_name] r]; set data [read $f]; close $f
set result [list text $data mime text/plain]
} elseif {[::namespace which ::search::convert::binary_to_text] ne ""} {
set txt [search::convert::binary_to_text -filename [:full_file_name] -mime_type ${:mime_type}]
set result [list text $txt mime text/plain]
} else {
set result [list text "" mime text/plain]
}
return $result
}
::xowiki::File instproc html_content {{-add_sections_to_folder_tree 0} -owner} {
set parent_id ${:parent_id}
set fileName [:full_file_name]
set f [open $fileName r]; set data [read $f]; close $f
regsub -all -- "/span> " $data "/span>\\ " data
regsub -all -- " <span " $data "\\ <span " data
regsub -all -- "/span>\n<span " $data "/span><br><span " data
regsub -all -- "/span>\n\n<span " $data "/span><br><br><span " data
dom parse -simple -- $data doc
$doc documentElement root
set prefix [::$parent_id pretty_link -absolute true -download true]
foreach n [$root selectNodes //img] {
set src [$n getAttribute src]
if {[regexp {^[^/]} $src]} {
$n setAttribute src $prefix/$src
}
}
if {$add_sections_to_folder_tree && [nsf::is object ::__xowiki__MenuBar]} {
$owner set book_mode 1
set pages [::xo::OrderedComposite new -destroy_on_cleanup]
if {$add_sections_to_folder_tree == 1} {
set selector //h2
} else {
set selector {//h2 | //h3}
}
set order 0
foreach n [$root selectNodes $selector] {
if {[$n hasAttribute id]} {
set name [$n getAttribute id]
} else {
set name "section $n"
}
set o [::xotcl::Object new]
$o set page_order [incr $order]
$o set title [$n asText]
set e [$doc createElement a]
$e setAttribute name $name
[$n parentNode] insertBefore $e $n
$o set name $name
$pages add $o
}
::__xowiki__MenuBar additional_sub_menu -kind folder -pages $pages -owner $owner
}
set content ""
foreach n [$root selectNodes //body/*] { append content [$n asHTML] \n }
return $content
}
::xowiki::File instproc pretty_name {} {
set name ${:name}
regsub {^file:} $name "" name
return $name
}
::xowiki::File instproc www-download {} {
set package_id [::xo::cc package_id]
if {[:exists_query_parameter filename]} {
set fn [::xo::backslash_escape \" [:query_parameter filename]]
ns_set put [ns_conn outputheaders] Content-Disposition "attachment;filename=\"$fn\""
}
set full_file_name [:full_file_name]
if {![ad_file exists $full_file_name]} {
ad_log error "The file '$full_file_name' does not exist." "Maybe the content repository is (partially) missing?"
return [::${:package_id} error_msg -status_code 500 [subst {
No file for link <b>'[ns_quotehtml [ns_conn url]]'</b> available.<br>
Please report this to the web master of this site.
}]]
}
::$package_id set mime_type ${:mime_type}
::$package_id set delivery ad_returnfile_background
set geometry [::xo::cc query_parameter geometry ""]
if {[string match "image/*" ${:mime_type}]
&& $geometry ne ""
} {
if {![regexp {^\d*x?\d*$} $geometry]} {
error "invalid geometry $geometry"
}
set tmpdir [ad_tmpdir]
if {![ad_file isdirectory $tmpdir/$geometry]} {
file mkdir $tmpdir/$geometry
}
set scaled_image $tmpdir/$geometry/${:revision_id}
if {![ad_file readable $scaled_image]} {
set cmd [::util::which convert]
if {$cmd ne ""} {
if {![catch {exec $cmd -geometry $geometry -interlace None -sharpen 1x2 $full_file_name $scaled_image}]} {
return $scaled_image
}
}
} else {
return $scaled_image
}
}
set modtime [ad_file mtime $full_file_name]
set cmptime [ns_set iget [ns_conn headers] If-Modified-Since]
if {$cmptime ne ""} {
if {[clock scan $cmptime] >= $modtime} {
::xo::cc set status_code 304
::$package_id set delivery ns_return
return ""
}
}
ns_set put [ns_conn outputheaders] Last-Modified [ns_httptime $modtime]
return $full_file_name
}
::xowiki::File instproc marshall {{-mode export}} {
set fn [:full_file_name]
if {$mode eq "export"} {
set :__file_content [::base64::encode [::xo::read_file $fn]]
} else {
set :__file_name $fn
}
next
}
::xowiki::File instparametercmd render_adp
::xowiki::File instparametercmd file_id
::xowiki::File instparametercmd storage_type
::xowiki::File instparametercmd mime_type
::nsf::relation::set ::xowiki::File superclass ::xowiki::Page
::nx::slotObj -container slot ::xowiki::File
::xowiki::File::slot eval {set :__parameter {
{render_adp 0}
}}
::nsf::object::alloc ::xo::db::Attribute ::xowiki::File::slot::file_id {set :accessor public
set :column_name file_id
set :configurable true
set :convert false
set :create_acs_attribute false
set :create_table_attribute true
set :datatype integer
set :defaultmethods {}
set :disposition alias
set :domain ::xowiki::File
set :incremental false
set :manager ::xowiki::File::slot::file_id
set :max_n_values 1
set :methodname file_id
set :min_n_values 1
set :multiplicity 1..1
set :name file_id
set :parameterSpec -file_id
set :per-object false
set :position 0
set :pretty_name ID
set :pretty_plural {}
set :references {}
set :required false
set :sqltype integer
set :trace none
: init}
::nsf::object::alloc ::xotcl::Attribute ::xowiki::File::slot::render_adp {set :accessor public
set :configurable true
set :convert false
set :default 0
set :defaultmethods {}
set :disposition alias
set :domain ::xowiki::File
set :incremental 0
set :manager ::xowiki::File::slot::render_adp
set :methodname render_adp
set :multiplicity 1..1
set :name render_adp
set :parameterSpec {-render_adp:substdefault 0}
set :per-object false
set :position 0
set :required false
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xotcl::Attribute ::xowiki::File::slot::mime_type {set :accessor public
set :configurable true
set :convert false
set :default text/plain
set :defaultmethods {}
set :disposition alias
set :domain ::xowiki::File
set :incremental false
set :manager ::xowiki::File::slot::mime_type
set :methodname mime_type
set :multiplicity 1..1
set :name mime_type
set :parameterSpec {-mime_type:substdefault text/plain}
set :per-object false
set :position 0
set :required false
set :substdefault 0b111
set :trace none
: init}
::nsf::object::alloc ::xotcl::Attribute ::xowiki::File::slot::storage_type {set :accessor public
set :configurable true
set :convert false
set :default file
set :defaultmethods {}
set :disposition alias
set :domain ::xowiki::File
set :incremental 0
set :manager ::xowiki::File::slot::storage_type
set :methodname storage_type
set :multiplicity 1..1
set :name storage_type
set :parameterSpec {-storage_type:substdefault file}
set :per-object false
set :position 0
set :required false
set :substdefault 0b111
set :trace none
: init}
namespace eval ::xowiki {::namespace export Menu YUIMenuBar YUIMenuBarItem YUIMenu YUIMenuItem YUIMenuItemList YUIContextMenu YUIContextMenuItem}
XQL Not present:Generic, PostgreSQL, Oracle
[
hide source ]
| [
make this the default ]