PageRenderTime 92ms CodeModel.GetById 89ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/library/server/httpd/interface/support/http_file_system_utilities.e

http://github.com/jocelyn/EiffelWebReloaded
Specman e | 106 lines | 92 code | 9 blank | 5 comment | 6 complexity | 53ff55473affff8b87fa21be2c9f7beb MD5 | raw file
  1note
  2	description: "Summary description for {HTTP_FILE_SYSTEM_UTILITIES}."
  3	legal: "See notice at end of class."
  4	status: "See notice at end of class."
  5	date: "$Date$"
  6	revision: "$Revision$"
  7
  8class
  9	HTTP_FILE_SYSTEM_UTILITIES
 10
 11feature -- Access
 12
 13	filesize (fn: STRING): INTEGER
 14			-- Size of the file `fn'.
 15		local
 16			f: RAW_FILE
 17		do
 18			create f.make (fn)
 19			if f.exists then
 20				Result := f.count
 21			end
 22		end
 23
 24	file_extension (fn: STRING): STRING
 25			-- Extension of file `fn'.
 26		local
 27			p: INTEGER
 28		do
 29			p := fn.last_index_of ('.', fn.count)
 30			if p > 0 then
 31				Result := fn.substring (p + 1, fn.count)
 32			else
 33				Result := ""
 34			end
 35		end
 36
 37	basename (fn: STRING): STRING
 38			-- Basename of `fn'.
 39		local
 40			p: INTEGER
 41		do
 42			p := fn.last_index_of ((create {OPERATING_ENVIRONMENT}).Directory_separator, fn.count)
 43			if p > 0 then
 44				Result := fn.substring (p + 1, fn.count)
 45			else
 46				Result := fn
 47			end
 48		end
 49
 50	dirname (fn: STRING): STRING
 51			-- Dirname of `fn'.	
 52		local
 53			p: INTEGER
 54		do
 55			p := fn.last_index_of ((create {OPERATING_ENVIRONMENT}).Directory_separator, fn.count)
 56			if p > 0 then
 57				Result := fn.substring (1, p - 1)
 58			else
 59				Result := ""
 60			end
 61		end
 62
 63feature -- Content-type related
 64
 65	content_type_by_extension (ext: STRING): STRING
 66			-- Content type associated with extension `ext'.
 67		local
 68			e: STRING
 69		do
 70			e := ext.as_lower
 71			if e.same_string ("pdf") then
 72      			Result := "application/pdf"
 73      		elseif e.same_string ("exe") then
 74      			Result := "application/octet-stream"
 75      		elseif e.same_string ("exe") then
 76				Result := "application/octet-stream"
 77      		elseif e.same_string ("zip") then
 78				Result := "application/zip"
 79      		elseif e.same_string ("doc") then
 80				Result := "application/msword"
 81      		elseif e.same_string ("xls") then
 82				Result := "application/vnd.ms-excel"
 83      		elseif e.same_string ("ppt") then
 84				Result := "application/vnd.ms-powerpoint"
 85      		elseif e.same_string ("gif") then
 86				Result := "image/gif"
 87      		elseif e.same_string ("png") then
 88				Result := "image/png"
 89      		elseif e.same_string ("jpg") or e.same_string ("jpeg") then
 90				Result := "image/jpg"
 91      		else
 92				Result := "application/force-download"
 93			end
 94		end
 95
 96note
 97	copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
 98	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
 99	source: "[
100			Eiffel Software
101			5949 Hollister Ave., Goleta, CA 93117 USA
102			Telephone 805-685-1006, Fax 805-685-6869
103			Website http://www.eiffel.com
104			Customer support http://support.eiffel.com
105		]"
106end