cr_check_mime_type (public)

 cr_check_mime_type [ -mime_type mime_type ] [ -filename filename ] \
    [ -file file ]

Defined in packages/acs-content-repository/tcl/revision-procs.tcl

Check whether the mimetype is registered. If not, check whether it can be guessed from the filename. If guessed mimetype is not registered optionally insert it.

Switches:
-mime_type
(optional)
param The mime type
-filename
(optional)
the filename
-file
(optional)
the actual file being saved. This option currently doesn't have any effect, but in the future would be better to inspect the actual file content instead of trusting the user.
Returns:
the mapped mimetype

Partial Call Graph (max 5 caller/called nodes):
%3 test_test_cr_items test_cr_items (test xotcl-core) cr_check_mime_type cr_check_mime_type test_test_cr_items->cr_check_mime_type test_xotcl_core_tutorial_4 xotcl_core_tutorial_4 (test xotcl-core) test_xotcl_core_tutorial_4->cr_check_mime_type cr_filename_to_mime_type cr_filename_to_mime_type (public) cr_check_mime_type->cr_filename_to_mime_type db_0or1row db_0or1row (public) cr_check_mime_type->db_0or1row parameter::get parameter::get (public) cr_check_mime_type->parameter::get content::item::new content::item::new (public) content::item::new->cr_check_mime_type content::revision::new content::revision::new (public) content::revision::new->cr_check_mime_type fs::add_file fs::add_file (public) fs::add_file->cr_check_mime_type fs::add_version fs::add_version (public) fs::add_version->cr_check_mime_type xo::db::CrItem instproc save xo::db::CrItem instproc save (public) xo::db::CrItem instproc save->cr_check_mime_type

Testcases:
xotcl_core_tutorial_4, test_cr_items
Source code:
    #
    # Check if the provided mime_type is already in our cr_mime_types
    # table. If so, accept it.
    #
    if {$mime_type ne "*/*" && [db_0or1row check_given_mime_type {
        select 1 from cr_mime_types where mime_type = :mime_type
    }]} {
        return $mime_type
    }

    # TODO: we use only the extension to get the mimetype. Something
    # better should be done, like inspecting the actual content of the
    # file and never trust the user on this regard, but as this
    # involves changes also in the data model, we leave this for the
    # future. Usages of this proc in the systems are already set to
    # give us the path to the file here.
    set extension [string tolower [string trimleft [file extension $filename"."]]
    if {[db_0or1row lookup_mimetype {
      select mime_type
        from cr_extension_mime_type_map
       where extension = :extension
    }]} {
        return $mime_type
    }
    set mime_type [string tolower [ns_guesstype $filename]]
    if {[db_0or1row lookup_mimetype {
      select mime_type
        from cr_extension_mime_type_map
       where extension = :extension
    }]} {
        return $mime_type
    }
    set allow_mimetype_creation_p  [parameter::get  -parameter AllowMimeTypeCreationP -default 0]
    return [cr_filename_to_mime_type -create=$allow_mimetype_creation_p  $filename]
XQL Not present:
Generic
PostgreSQL XQL file:
packages/acs-content-repository/tcl/revision-procs-postgresql.xql

Oracle XQL file:
packages/acs-content-repository/tcl/revision-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: