/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

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