diff --git a/src/service/handler/cms_handler.e b/src/service/handler/cms_handler.e index 56517e4..ae2f3b9 100644 --- a/src/service/handler/cms_handler.e +++ b/src/service/handler/cms_handler.e @@ -36,6 +36,18 @@ feature -- Response helpers -- res.send (create {CMS_REDIRECTION_RESPONSE_MESSAGE}.make (a_location)) end + send_bad_request_message (res: WSF_RESPONSE) + -- Send via `res' a bad request response. + do + res.send (create {CMS_CUSTOM_RESPONSE_MESSAGE}.make ({HTTP_STATUS_CODE}.bad_request)) + end + + send_not_found_message (res: WSF_RESPONSE) + -- Send via `res' a bad request response. + do + res.send (create {CMS_CUSTOM_RESPONSE_MESSAGE}.make ({HTTP_STATUS_CODE}.not_found)) + end + send_access_denied_message (res: WSF_RESPONSE) -- Send via `res' an access denied response. do diff --git a/src/service/response/cms_response.e b/src/service/response/cms_response.e index b0dc598..0df5bf1 100644 --- a/src/service/response/cms_response.e +++ b/src/service/response/cms_response.e @@ -3,8 +3,8 @@ note Generic CMS Response. It builds the content to get process to render the output. ]" - date: "$Date: 2015-02-16 20:14:19 +0100 (lun., 16 févr. 2015) $" - revision: "$Revision: 96643 $" + date: "$Date: 2015-05-20 11:48:26 +0200 (mer., 20 mai 2015) $" + revision: "$Revision: 97327 $" deferred class CMS_RESPONSE @@ -40,14 +40,19 @@ feature {NONE} -- Initialization initialize_site_url -- Initialize site and base url. local - l_url: detachable READABLE_STRING_8 + l_url: detachable STRING_8 i,j: INTEGER do --| WARNING: do not use `absolute_url' and `url', since it relies on site_url and base_url. - l_url := setup.site_url - if l_url = Void then + if attached setup.site_url as l_site_url and then not l_site_url.is_empty then + create l_url.make_from_string (l_site_url) + else l_url := request.absolute_script_url ("/") end + check is_not_empty: not l_url.is_empty end + if l_url [l_url.count] /= '/' then + l_url.append_character ('/') + end site_url := l_url i := l_url.substring_index ("://", 1) if i > 0 then @@ -56,6 +61,9 @@ feature {NONE} -- Initialization base_url := l_url.substring (j, l_url.count) end end + ensure + site_url_set: site_url /= Void + site_url_ends_with_slash: site_url.ends_with_general ("/") end register_hooks @@ -98,6 +106,15 @@ feature -- Access redirection: detachable READABLE_STRING_8 -- Location for eventual redirection. + location: STRING_8 + -- Associated cms local location. + do + create Result.make_from_string (request.percent_encoded_path_info) + if not Result.is_empty and then Result[1] = '/' then + Result.remove_head (1) + end + end + feature -- Internationalization (i18n) translation (a_text: READABLE_STRING_GENERAL; opts: detachable CMS_API_OPTIONS): STRING_32 @@ -185,10 +202,10 @@ feature -- URL utilities end end - site_url: READABLE_STRING_8 + site_url: IMMUTABLE_STRING_8 -- Absolute site url. - base_url: detachable READABLE_STRING_8 + base_url: detachable IMMUTABLE_STRING_8 -- Base url if any. --| Usually it is Void, but it could be --| /project/demo/ diff --git a/src/service/response/message/cms_custom_response_message.e b/src/service/response/message/cms_custom_response_message.e new file mode 100644 index 0000000..7c2f435 --- /dev/null +++ b/src/service/response/message/cms_custom_response_message.e @@ -0,0 +1,64 @@ +note + description: "Custom cms response message." + date: "$Date$" + revision: "$Revision$" + +class + CMS_CUSTOM_RESPONSE_MESSAGE + +inherit + CMS_RESPONSE_MESSAGE + redefine + send_payload_to + end + +create + make + +feature {NONE} -- Initialization + + make (a_code: INTEGER) + -- Set `status_code' to `a_code'. + require + a_code_valid: a_code > 0 + do + initialize + status_code := a_code + end + +feature -- Access + + payload: detachable READABLE_STRING_8 + -- Optional payload. + +feature -- Element change + + set_status_code (a_code: INTEGER) + -- Set `status_code' to `a_code'. + require + a_code_valid: a_code > 0 + do + status_code := a_code + end + + set_payload (s: detachable READABLE_STRING_8) + -- Set `payload' to `s'. + do + if s /= Void then + payload := s + header.put_content_length (s.count) + else + end + end + +feature {WSF_RESPONSE} -- Output + + send_payload_to (res: WSF_RESPONSE) + -- Send payload data to response `res'. + do + if attached payload as s then + res.put_string (s) + end + end + +end diff --git a/src/theme/cms_theme.e b/src/theme/cms_theme.e index f88f7e9..0bc2b69 100644 --- a/src/theme/cms_theme.e +++ b/src/theme/cms_theme.e @@ -1,7 +1,7 @@ note description: "Abstract class describing a generic theme" - date: "$Date: 2015-02-16 12:52:35 +0100 (lun., 16 févr. 2015) $" - revision: "$Revision: 96630 $" + date: "$Date: 2015-05-20 11:48:26 +0200 (mer., 20 mai 2015) $" + revision: "$Revision: 97327 $" deferred class CMS_THEME @@ -18,10 +18,10 @@ feature {NONE} -- Access setup: CMS_SETUP - site_url: READABLE_STRING_8 assign set_site_url + site_url: IMMUTABLE_STRING_8 -- Absolute URL for Current CMS site. - base_url: detachable READABLE_STRING_8 + base_url: detachable IMMUTABLE_STRING_8 -- Optional base url of current CMS site. feature -- Access @@ -59,16 +59,17 @@ feature -- Element change i,j: INTEGER do base_url := Void - if a_url[a_url.count] = '/' then - site_url := a_url + if a_url [a_url.count] = '/' then + create site_url.make_from_string (a_url) else - site_url := a_url + "/" + create site_url.make_from_string (a_url + "/") end + i := a_url.substring_index ("://", 1) if i > 0 then j := a_url.index_of ('/', i + 3) if j > 0 then - base_url := a_url.substring (j, a_url.count) + create base_url.make_from_string (a_url.substring (j, a_url.count)) end end end