Refactor rename error_500_cms_response to internal_server_error_cms_response

Added bad_request_error_cms_response
Updated code example to use the new internal_server_error_cms_response instead of error_500_cms_response class.
Removed class error_500_cms_response.

Updated cms setup and configuration design:
  Removed CMS_SETUP.configuration: CMS_CONFIGURATION
  Removed CMS_CONFIGURATION and replaced it by using the configuration library.
  Added CMS_DEFAULT_SETUP.configuration: CONFIG_READER
  Addec CMS_SETUP.text_item (name): detachable READABLE_STRING_32 ...
    in order to access option not publish by the CMS_SETUP interface.
Removed CMS_SERVICE.configuration: CMS_CONFIGURATION since it was not used.

Moved configuration library from eiffel-lang to cms libraries.
Fixed issue related to ini config when parsing from string content,
  and also issue related to section included in file via @include.
Updated cms setup and configuration design:
  Removed CMS_SETUP.configuration: CMS_CONFIGURATION
  Removed CMS_CONFIGURATION and replaced it by using the configuration library.
  Added CMS_DEFAULT_SETUP.configuration: CONFIG_READER
  Addec CMS_SETUP.text_item (name): detachable READABLE_STRING_32 ...
    in order to access option not publish by the CMS_SETUP interface.
Removed CMS_SERVICE.configuration: CMS_CONFIGURATION since it was not used.
Improved the email service and related.
This commit is contained in:
jvelilla
2014-12-19 18:03:52 -03:00
parent bd26deb6c1
commit e2f02953f4
22 changed files with 1117 additions and 363 deletions

View File

@@ -1,317 +0,0 @@
note
description: "[
Configure the basic settings for a CMS application,
i.e: where to look for themes, name of the application, etc...
The settings can be configured by default:
- using the current working directory,
- using the commands provided by the class
- or by an external configuration file.
]"
class
CMS_CONFIGURATION
inherit
ANY
SHARED_EXECUTION_ENVIRONMENT
export
{NONE} all
end
create
make
feature {NONE} -- Initialization
make (a_layout: CMS_LAYOUT)
-- Initialize `Current' with layout `a_layout'.
do
layout := a_layout
create options.make_equal (10)
configuration_location := layout.cms_config_ini_path
import_from_path (layout.cms_config_ini_path)
analyze
end
analyze
do
get_root_location
get_var_location
get_themes_location
get_files_location
get_smtp
end
feature -- Access
configuration_location: detachable PATH
-- Path to configuration location.
option (a_name: READABLE_STRING_GENERAL): detachable ANY
do
Result := options.item (a_name)
end
options: STRING_TABLE [STRING_32]
feature -- Conversion
append_to_string (s: STRING)
local
utf: UTF_CONVERTER
do
s.append ("Options:%N")
across
options as c
loop
s.append (c.key.to_string_8)
s.append_character ('=')
utf.string_32_into_utf_8_string_8 (c.item, s)
s.append_character ('%N')
end
s.append ("Specific:%N")
s.append ("root_location=" + root_location.utf_8_name + "%N")
s.append ("var_location=" + var_location.utf_8_name + "%N")
s.append ("files_location=" + files_location.utf_8_name + "%N")
s.append ("themes_location=" + themes_location.utf_8_name + "%N")
end
feature -- Element change
set_option (a_name: READABLE_STRING_GENERAL; a_value: STRING_32)
do
options.force (a_value, a_name.as_string_8)
end
feature -- Access
var_location: PATH
root_location: PATH
files_location: PATH
themes_location: PATH
theme_name (dft: detachable like theme_name): READABLE_STRING_8
do
if attached options.item ("theme") as s then
Result := s
elseif dft /= Void then
Result := dft
else
Result := "default"
end
end
site_id: READABLE_STRING_8
do
if attached options.item ("site.id") as s then
Result := s
else
Result := "_EWF_CMS_NO_ID_"
end
end
site_name (dft: like site_name): READABLE_STRING_8
do
if attached options.item ("site.name") as s then
Result := s
else
Result := dft
end
end
site_url (dft: like site_url): detachable READABLE_STRING_8
do
if attached options.item ("site.url") as s then
Result := s
else
Result := dft
end
if Result /= Void then
if Result.is_empty then
-- ok
elseif not Result.ends_with ("/") then
Result := Result + "/"
end
end
end
site_script_url (dft: like site_script_url): detachable READABLE_STRING_8
do
if attached options.item ("site.script_url") as s then
Result := s
else
Result := dft
end
if Result /= Void then
if Result.is_empty then
elseif not Result.ends_with ("/") then
Result := Result + "/"
end
end
end
site_email (dft: like site_email): READABLE_STRING_8
do
if attached options.item ("site.email") as s then
Result := s
else
Result := dft
end
end
smtp: detachable READABLE_STRING_8
feature -- Change
get_var_location
local
utf: UTF_CONVERTER
do
if attached options.item ("var-dir") as s then
create var_location.make_from_string (utf.utf_8_string_8_to_escaped_string_32 (s))
else
var_location := execution_environment.current_working_path
end
end
get_root_location
do
root_location := layout.www_path
end
get_files_location
local
utf: UTF_CONVERTER
do
if attached options.item ("files-dir") as s then
create files_location.make_from_string (utf.utf_8_string_8_to_escaped_string_32 (s))
else
create files_location.make_from_string ("files")
end
end
get_themes_location
local
utf: UTF_CONVERTER
do
if attached options.item ("themes-dir") as s then
create themes_location.make_from_string (utf.utf_8_string_8_to_escaped_string_32 (s))
else
themes_location := root_location.extended ("themes")
end
end
get_smtp
do
if attached options.item ("smtp") as s then
smtp := s
end
end
feature {NONE} -- Implementation
import_from_file (fn: READABLE_STRING_GENERAL)
do
import_from_path (create {PATH}.make_from_string (fn))
end
import_from_path (a_filename: PATH)
-- Import ini file content
local
f: PLAIN_TEXT_FILE
l,v: STRING_8
p: INTEGER
do
create f.make_with_path (a_filename)
if f.exists and f.is_readable then
f.open_read
from
f.read_line
until
f.exhausted
loop
l := f.last_string
l.left_adjust
if not l.is_empty then
if l[1] = '#' then
-- commented line
else
p := l.index_of ('=', 1)
if p > 1 then
v := l.substring (p + 1, l.count)
l.keep_head (p - 1)
v.left_adjust
v.right_adjust
l.right_adjust
if l.is_case_insensitive_equal ("@include") then
import_from_file (resolved_string (v))
else
set_option (l.as_lower, resolved_string (v))
end
end
end
end
f.read_line
end
f.close
end
end
feature {NONE} -- Environment
resolved_string (s: READABLE_STRING_8): STRING_32
-- Resolved `s' using `options' or else environment variables.
local
i,n,b,e: INTEGER
k: detachable READABLE_STRING_8
do
from
i := 1
n := s.count
create Result.make (s.count)
until
i > n
loop
if i + 1 < n and then s[i] = '$' and then s[i+1] = '{' then
b := i + 2
e := s.index_of ('}', b) - 1
if e > 0 then
k := s.substring (b, e)
if attached option (k) as v then
if attached {READABLE_STRING_32} v as s32 then
Result.append (s32)
else
Result.append (v.out)
end
i := e + 1
elseif attached execution_environment.item (k) as v then
Result.append (v)
i := e + 1
else
Result.extend (s[i])
end
else
Result.extend (s[i])
end
else
Result.extend (s[i])
end
i := i + 1
end
end
feature -- Implementation
layout: CMS_LAYOUT
-- Cms layout
end

View File

@@ -1,16 +1,13 @@
note
description: "Class that enable to set basic configuration, application layout, core modules and themes."
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2014-12-18 12:47:20 -0300 (ju. 18 de dic. de 2014) $"
revision: "$Revision: 96384 $"
deferred class
CMS_SETUP
feature -- Access
configuration: CMS_CONFIGURATION
-- cms configuration.
layout: CMS_LAYOUT
-- CMS layout.
@@ -59,7 +56,8 @@ feature -- Access: Site
-- Name of the site.
site_email: READABLE_STRING_8
-- Email for the site.
-- Admin email address for the site.
-- Mainly used for internal notification.
site_url: detachable READABLE_STRING_8
-- Optional base url of the site.
@@ -69,8 +67,31 @@ feature -- Access: Site
-- By default "" or "/".
smtp: detachable READABLE_STRING_8
-- Smtp server
-- Smtp server
feature -- Query
text_item (a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_32
-- Configuration value associated with `a_name', if any.
deferred
end
text_item_or_default (a_name: READABLE_STRING_GENERAL; a_default_value: READABLE_STRING_GENERAL): READABLE_STRING_32
-- `text_item' associated with `a_name' or if none, `a_default_value'.
do
if attached text_item (a_name) as v then
Result := v
else
Result := a_default_value.as_string_32
end
end
string_8_item (a_name: READABLE_STRING_GENERAL): detachable READABLE_STRING_8
-- Configuration value associated with `a_name', if any.
deferred
end
feature -- Access: Theme
themes_location: PATH

View File

@@ -1,7 +1,7 @@
note
description: "Summary description for {CMS_DEBUG_MODULE}."
date: "$Date: 2014-08-28 13:21:49 +0200 (jeu., 28 août 2014) $"
revision: "$Revision: 95708 $"
date: "$Date: 2014-12-18 12:47:20 -0300 (ju. 18 de dic. de 2014) $"
revision: "$Revision: 96384 $"
class
CMS_DEBUG_MODULE
@@ -82,7 +82,7 @@ feature -- Handler
append_info_to ("Name", api.setup.site_name, r, s)
append_info_to ("Url", api.setup.site_url, r, s)
if attached api.setup.configuration.configuration_location as l_loc then
if attached api.setup.layout.cms_config_ini_path as l_loc then
s.append ("<hr/>")
append_info_to ("Configuration file", l_loc.name, r, s)
end

View File

@@ -1,7 +1,7 @@
note
description: "Summary description for {NEW_CONTENT_HANDLER}."
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2014-12-19 10:17:32 -0300 (vi., 19 dic. 2014) $"
revision: "$Revision: 96402 $"
class
NODE_CONTENT_HANDLER
@@ -78,7 +78,7 @@ feature -- HTTP Methods
do_error (req, res, l_id)
end
else
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
@@ -96,14 +96,14 @@ feature -- HTTP Methods
if l_method.is_case_insensitive_equal ("PUT") then
do_put (req, res)
else
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
end
end
else
do_error (req, res, l_id)
end
else
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
@@ -127,7 +127,7 @@ feature -- HTTP Methods
do_error (req, res, l_id)
end
else
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)

View File

@@ -1,7 +1,7 @@
note
description: "Summary description for {NODE_HANDLER}."
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2014-12-19 10:17:32 -0300 (vi., 19 dic. 2014) $"
revision: "$Revision: 96402 $"
class
NODE_HANDLER
@@ -96,7 +96,7 @@ feature -- HTTP Methods
elseif l_method.is_case_insensitive_equal ("PUT") then
do_put (req, res)
else
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
end
end
else
@@ -131,7 +131,7 @@ feature -- HTTP Methods
do_error (req, res, l_id)
end
else
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
@@ -151,7 +151,7 @@ feature -- HTTP Methods
do_error (req, res, l_id)
end
else
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)

View File

@@ -1,7 +1,7 @@
note
description: "Summary description for {NODE_SUMMARY_HANDLER}."
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2014-12-19 10:17:32 -0300 (vi., 19 dic. 2014) $"
revision: "$Revision: 96402 $"
class
NODE_SUMMARY_HANDLER
@@ -77,7 +77,7 @@ feature -- HTTP Methods
do_error (req, res, l_id)
end
else
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
@@ -95,14 +95,14 @@ feature -- HTTP Methods
if l_method.is_case_insensitive_equal ("PUT") then
do_put (req, res)
else
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
end
end
else
do_error (req, res, l_id)
end
else
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
@@ -125,7 +125,7 @@ feature -- HTTP Methods
do_error (req, res, l_id)
end
else
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)

View File

@@ -1,7 +1,7 @@
note
description: "Summary description for {NODE_TITLE_HANDLER}."
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2014-12-19 10:17:32 -0300 (vi., 19 dic. 2014) $"
revision: "$Revision: 96402 $"
class
NODE_TITLE_HANDLER
@@ -77,7 +77,7 @@ feature -- HTTP Methods
do_error (req, res, l_id)
end
else
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
@@ -94,14 +94,14 @@ feature -- HTTP Methods
if l_method.is_case_insensitive_equal ("PUT") then
do_put (req, res)
else
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
end
end
else
do_error (req, res, l_id)
end
else
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
@@ -125,7 +125,7 @@ feature -- HTTP Methods
do_error (req, res, l_id)
end
else
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
end
else
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)

View File

@@ -45,7 +45,6 @@ feature {NONE} -- Initialization
-- Build a CMS service with `a_api'
do
api := a_api
configuration := a_api.setup.configuration
initialize
ensure
api_set: api = a_api
@@ -230,10 +229,6 @@ feature -- Access
Result := api.setup
end
configuration: CMS_CONFIGURATION
-- CMS configuration.
--| Maybe we can compute it (using `setup') instead of using memory.
modules: CMS_MODULE_COLLECTION
-- Configurator of possible modules.

View File

@@ -1,7 +1,7 @@
note
description: "Summary description for {CMS_ERROR_FILTER}."
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2014-12-19 10:17:32 -0300 (vi., 19 dic. 2014) $"
revision: "$Revision: 96402 $"
class
CMS_ERROR_FILTER
@@ -32,7 +32,7 @@ feature -- Basic operations
execute_next (req, res)
else
log.write_critical (generator + ".execute" + api.as_string_representation )
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
api.reset
end
end

View File

@@ -0,0 +1,38 @@
note
description: "Summary description for {BAD_REQUEST_ERROR_CMS_RESPONSE}."
date: "$Date: 2014-12-19 10:17:32 -0300 (vi., 19 dic. 2014) $"
revision: "$Revision: 96402 $"
class
BAD_REQUEST_ERROR_CMS_RESPONSE
inherit
CMS_RESPONSE
redefine
custom_prepare
end
create
make
feature -- Generation
custom_prepare (page: CMS_HTML_PAGE)
do
page.register_variable (request.absolute_script_url (request.path_info), "request")
page.set_status_code ({HTTP_STATUS_CODE}.bad_request)
page.register_variable (page.status_code.out, "code")
end
feature -- Execution
process
-- Computed response message.
do
set_title ("Bad request")
set_page_title ("Bad request")
set_main_content ("<em>Bad request.</em>")
end
end

View File

@@ -1,10 +1,10 @@
note
description: "Summary description for {ERROR_500_CMS_RESPONSE}."
date: "$Date$"
revision: "$Revision$"
description: "Summary description for {INTERNAL_SERVER_ERROR_CMS_RESPONSE}."
date: "$Date: 2014-12-19 10:17:32 -0300 (vi., 19 dic. 2014) $"
revision: "$Revision: 96402 $"
class
ERROR_500_CMS_RESPONSE
INTERNAL_SERVER_ERROR_CMS_RESPONSE
inherit
@@ -32,6 +32,7 @@ feature -- Execution
do
set_title ("Internal Server Error")
set_page_title (Void)
set_main_content ("<em>Internal Server Error</em>")
end
end