Reviewed initialization and usage of various CMS_SERVICE urls

This commit is contained in:
Jocelyn Fiat
2013-02-04 22:04:55 +01:00
parent cffc02daee
commit 461cb4a4db
7 changed files with 104 additions and 103 deletions

View File

@@ -136,21 +136,32 @@ feature -- Access
end
end
site_base_url (dft: like site_base_url): detachable READABLE_STRING_8
site_url (dft: like site_url): READABLE_STRING_8
do
if attached options.item ("site.base_url") as s then
if attached options.item ("site.url") as s then
Result := s
else
Result := dft
end
if Result /= Void then
if Result.is_empty then
Result := Void
elseif not Result.starts_with ("/") then
Result := "/" + Result
if Result.ends_with ("/") then
Result := Result.substring (1, Result.count - 1)
end
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

View File

@@ -51,15 +51,6 @@ feature {CMS_SESSION_CONTROLER} -- Access: restricted
controller: CMS_SESSION_CONTROLER
base_url: detachable READABLE_STRING_8
do
if attached service.base_url as l_url then
Result := request.script_url (l_url)
else
Result := request.script_url ("")
end
end
pending_messages_session_item_name: STRING = "cms.pending_messages"
-- Session item name to get the pending messages.

View File

@@ -11,7 +11,7 @@ deferred class
feature -- Initialization
initialize_cms (a_cfg: detachable CMS_CONFIGURATION)
initialize_cms (a_base_url: like base_url; a_cfg: detachable CMS_CONFIGURATION)
local
cfg: detachable CMS_CONFIGURATION
do
@@ -20,7 +20,13 @@ feature -- Initialization
create cfg.make
end
site_url := "" -- Fixme
if a_base_url /= Void and then not a_base_url.is_empty then
base_url := a_base_url
else
base_url := Void
end
site_url := cfg.site_url ("")
site_name := cfg.site_name ("EWF::CMS")
site_email := cfg.site_email ("webmaster")
site_dir := cfg.root_location
@@ -29,6 +35,8 @@ feature -- Initialization
themes_location := cfg.themes_location
theme_name := cfg.theme_name ("default")
set_script_url (cfg.site_script_url (Void)) -- Temporary value
compute_theme_resource_location
@@ -266,31 +274,8 @@ feature -- Router
theme_name: READABLE_STRING_32
front_path: STRING
do
if attached base_url as l_base_url then
Result := l_base_url + "/"
else
Result := "/"
end
end
router: WSF_ROUTER
base_url: detachable READABLE_STRING_8
-- Base url (related to the script path).
deferred
ensure
valid_base_url: (Result /= Void and then Result.is_empty) implies (Result.starts_with ("/") and not Result.ends_with ("/"))
end
server_base_url: detachable READABLE_STRING_8
-- Base url (related to absolute path).
deferred
ensure
valid_base_url: (Result /= Void and then Result.is_empty) implies (Result.starts_with ("/") and not Result.ends_with ("/"))
end
map_uri_template (tpl: STRING; proc: PROCEDURE [ANY, TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]])
do
router.map (create {WSF_URI_TEMPLATE_MAPPING}.make_from_template (tpl, create {CMS_HANDLER}.make (proc)))
@@ -301,6 +286,67 @@ feature -- Router
router.map (create {WSF_URI_MAPPING}.make (a_uri, create {CMS_HANDLER}.make (proc)))
end
feature -- URL related
front_path: STRING
do
if attached base_url as l_base_url then
Result := l_base_url + "/"
else
Result := "/"
end
end
urls_set: BOOLEAN
initialize_urls (req: WSF_REQUEST)
do
if not urls_set then
urls_set := True
if site_url.is_empty then
site_url := req.absolute_script_url ("")
end
set_script_url (req.script_url (""))
end
end
base_url: detachable READABLE_STRING_8
-- Base url (related to the script path).
-- deferred
-- ensure
-- valid_base_url: (Result /= Void and then Result.is_empty) implies (Result.starts_with ("/") and not Result.ends_with ("/"))
-- end
-- server_base_url: detachable READABLE_STRING_8
-- -- Base url (related to absolute path).
-- deferred
-- ensure
-- valid_base_url: (Result /= Void and then Result.is_empty) implies (Result.starts_with ("/") and not Result.ends_with ("/"))
-- end
script_url: detachable READABLE_STRING_8
set_script_url (a_url: like script_url)
local
s: STRING_8
do
if a_url = Void then
script_url := Void
elseif not a_url.is_empty then
if a_url.ends_with ("/") then
create s.make_from_string (a_url)
else
create s.make (a_url.count + 1)
s.append (a_url)
s.append_character ('/')
end
script_url := s
end
ensure
attached script_url as l_url implies l_url.ends_with ("/")
end
feature -- Report
is_front_page (req: WSF_REQUEST): BOOLEAN
@@ -400,9 +446,7 @@ feature -- Core Execution
e: CMS_EXECUTION
-- not_found: WSF_NOT_FOUND_RESPONSE
do
if site_url.is_empty then
site_url := req.absolute_script_url ("")
end
initialize_urls (req)
if attached router.dispatch_and_return_handler (req, res) as p then
-- ok
else

View File

@@ -55,52 +55,6 @@ feature -- Access
Result := tpl
end
-- css: STRING
-- do
-- Result := "[
-- body { margin: 0; }
-- div#header { background-color: #00a; color: #fff; border: solid 1px #00a; padding: 10px;}
-- div#header img#logo { float: left; margin: 3px; }
-- div#header div#title {font-size: 180%; font-weight: bold; }
-- ul.horizontal {
-- list-style-type: none;
-- }
-- ul.horizontal li {
-- display: inline;
-- padding: 5px;
-- }
-- div#first-menu { padding: 5px; color: #ccf; background-color: #006; }
-- div#first-menu a { color: #ccf; }
-- div#second-menu { color: #99f; background-color: #333; }
-- div#second-menu a { color: #99f; }
--
-- div#left_sidebar {
-- width: 150px;
-- border: solid 1px #009;
-- margin: 5px;
-- padding: 5px;
-- width: 150px;
-- display: inline;
-- float: left;
-- position: relative;
-- }
-- div#main-wrapper {
-- clear: both;
-- display: block;
-- height: 0;
-- }
-- div#main { margin: 0; padding: 10px; clear: both; height:0; display: block; }
-- div#content { padding: 10px; border: solid 1px #00f;
-- width: 700px;
-- display: inline;
-- float: left;
-- position: relative;
-- }
-- div#footer { margin: 10px 0 10px 0; clear: both; display: block; text-align: center; padding: 10px; border-top: solid 1px #00f; color: #fff; background-color: #333;}
-- div#footer a { color: #ff0; }
-- ]"
-- end
feature -- Conversion
prepare (page: CMS_HTML_PAGE)

View File

@@ -41,9 +41,9 @@ feature -- Execution
elseif attached text as t then
create b.make_empty
s := request.path_info
if attached service.base_url as l_base_url then
if s.starts_with (l_base_url) then
s.remove_head (l_base_url.count)
if attached service.script_url as l_script_url then
if s.starts_with (l_script_url) then
s.remove_head (l_script_url.count)
if s.starts_with ("/") then
s.remove_head (1)
end

View File

@@ -15,7 +15,8 @@ feature {NONE} -- Access
base_url: detachable READABLE_STRING_8
-- Base url if any.
deferred
do
Result := service.script_url
end
based_path (p: STRING): STRING
@@ -23,7 +24,14 @@ feature {NONE} -- Access
do
if attached base_url as l_base_url then
create Result.make_from_string (l_base_url)
Result.append (p)
if p.is_empty then
else
if p[1] = '/' then
Result.append (p.substring (2, p.count))
else
Result.append (p)
end
end
else
Result := p
end

View File

@@ -10,19 +10,12 @@ deferred class
inherit
CMS_COMMON_API
feature {NONE} -- Access
service: CMS_SERVICE
deferred
end
base_url: detachable READABLE_STRING_8
-- Base url if any.
do
Result := service.server_base_url
end
feature -- Access
name: STRING