Updated CMS code.
Separated code to have a lib and an example. Improved design, fixed a few issues related to folder location. This is still experimental and require more work to be really friendly to use.
This commit is contained in:
60
draft/application/cms/example/src/module/demo/demo_module.e
Normal file
60
draft/application/cms/example/src/module/demo/demo_module.e
Normal file
@@ -0,0 +1,60 @@
|
||||
note
|
||||
description: "Summary description for {CMS_MODULE}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
DEMO_MODULE
|
||||
|
||||
inherit
|
||||
CMS_MODULE
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_service: like service)
|
||||
do
|
||||
service := a_service
|
||||
name := "demo"
|
||||
version := "1.0"
|
||||
description := "demo"
|
||||
package := "misc"
|
||||
end
|
||||
|
||||
feature {CMS_SERVICE} -- Registration
|
||||
|
||||
service: CMS_SERVICE
|
||||
|
||||
register (a_service: CMS_SERVICE)
|
||||
do
|
||||
a_service.map_uri_template ("/demo/date/{arg}", agent handle_date_time_demo)
|
||||
a_service.map_uri_template ("/demo/format/{arg}", agent handle_format_demo)
|
||||
end
|
||||
|
||||
feature -- Hooks
|
||||
|
||||
links: HASH_TABLE [CMS_MODULE_LINK, STRING]
|
||||
-- Link indexed by path
|
||||
local
|
||||
-- lnk: CMS_MODULE_LINK
|
||||
do
|
||||
create Result.make (3)
|
||||
-- create lnk.make ("Date/time demo")
|
||||
-- lnk.set_callback (agent process_date_time_demo, <<"arg">>)
|
||||
-- Result["/demo/date/{arg}"] := lnk
|
||||
end
|
||||
|
||||
handle_date_time_demo (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
(create {ANY_CMS_EXECUTION}.make_with_text (req, res, service, "<h1>Demo::date/time</h1>")).execute
|
||||
end
|
||||
|
||||
handle_format_demo (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
(create {ANY_CMS_EXECUTION}.make_with_text (req, res, service, "<h1>Demo::format</h1>")).execute
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,33 @@
|
||||
note
|
||||
description: "Summary description for {SHUTDOWN_CMS_EXECUTION}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
SHUTDOWN_CMS_EXECUTION
|
||||
|
||||
inherit
|
||||
CMS_EXECUTION
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Execution
|
||||
|
||||
process
|
||||
local
|
||||
b: STRING
|
||||
do
|
||||
create b.make_empty
|
||||
set_title ("Shutting down the service ...")
|
||||
if has_permission ("admin shutdown") then
|
||||
if attached {WGI_NINO_CONNECTOR} request.wgi_connector as nino then
|
||||
nino.server.shutdown_server
|
||||
end
|
||||
else
|
||||
b.append ("Access denied")
|
||||
end
|
||||
set_main_content (b)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,72 @@
|
||||
note
|
||||
description: "Summary description for {SHUTDOWN_MODULE}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
SHUTDOWN_MODULE
|
||||
|
||||
inherit
|
||||
CMS_MODULE
|
||||
|
||||
CMS_HOOK_MENU_ALTER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
do
|
||||
name := "shutdown"
|
||||
version := "1.0"
|
||||
description := "Shutdown the service if this is EWF Nino or FCGI"
|
||||
package := "server"
|
||||
end
|
||||
|
||||
feature {CMS_SERVICE} -- Registration
|
||||
|
||||
service: detachable CMS_SERVICE
|
||||
|
||||
register (a_service: CMS_SERVICE)
|
||||
do
|
||||
a_service.map_uri ("/admin/shutdown/", agent handle_shutdown)
|
||||
|
||||
a_service.add_menu_alter_hook (Current)
|
||||
service := a_service
|
||||
end
|
||||
|
||||
feature -- Hooks
|
||||
|
||||
menu_alter (a_menu_system: CMS_MENU_SYSTEM; a_execution: CMS_EXECUTION)
|
||||
local
|
||||
lnk: CMS_LOCAL_LINK
|
||||
do
|
||||
create lnk.make ("Shutdown", "/admin/shutdown/")
|
||||
lnk.set_permission_arguments (<<"admin shutdown">>)
|
||||
a_menu_system.management_menu.extend (lnk)
|
||||
|
||||
end
|
||||
|
||||
links: HASH_TABLE [CMS_MODULE_LINK, STRING]
|
||||
-- Link indexed by path
|
||||
local
|
||||
-- lnk: CMS_MODULE_LINK
|
||||
do
|
||||
create Result.make (3)
|
||||
-- create lnk.make ("Date/time demo")
|
||||
-- lnk.set_callback (agent process_date_time_demo, <<"arg">>)
|
||||
-- Result["/demo/date/{arg}"] := lnk
|
||||
end
|
||||
|
||||
handle_shutdown (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
do
|
||||
if attached service as l_service then
|
||||
(create {SHUTDOWN_CMS_EXECUTION}.make (req, res, l_service)).execute ;
|
||||
else
|
||||
res.set_status_code ({HTTP_STATUS_CODE}.expectation_failed)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
123
draft/application/cms/example/src/web_cms.e
Normal file
123
draft/application/cms/example/src/web_cms.e
Normal file
@@ -0,0 +1,123 @@
|
||||
note
|
||||
description: "[
|
||||
This class implements the Demo of WEB CMS service
|
||||
|
||||
]"
|
||||
|
||||
class
|
||||
WEB_CMS
|
||||
|
||||
inherit
|
||||
CMS_SERVICE
|
||||
redefine
|
||||
modules
|
||||
end
|
||||
|
||||
WSF_DEFAULT_SERVICE
|
||||
redefine
|
||||
initialize
|
||||
end
|
||||
|
||||
create
|
||||
make_and_launch
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
base_url: detachable READABLE_STRING_8
|
||||
|
||||
server_base_url: detachable READABLE_STRING_8
|
||||
-- Base url (related to absolute path).
|
||||
--| Mainly pertinent when run from a standalone server.
|
||||
do
|
||||
Result := base_url
|
||||
end
|
||||
|
||||
modules: ARRAYED_LIST [CMS_MODULE]
|
||||
local
|
||||
m: CMS_MODULE
|
||||
once
|
||||
Result := Precursor
|
||||
|
||||
-- Others
|
||||
create {DEMO_MODULE} m.make (Current)
|
||||
m.enable
|
||||
Result.extend (m)
|
||||
|
||||
create {SHUTDOWN_MODULE} m.make
|
||||
m.enable
|
||||
Result.extend (m)
|
||||
|
||||
-- create {EIFFEL_LOGIN_MODULE} m.make
|
||||
-- m.enable
|
||||
-- Result.extend (m)
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
initialize
|
||||
local
|
||||
args: ARGUMENTS
|
||||
cfg: detachable STRING
|
||||
i,n: INTEGER
|
||||
cms_config: CMS_CONFIGURATION
|
||||
opts: WSF_SERVICE_LAUNCHER_OPTIONS_FROM_INI
|
||||
do
|
||||
create args
|
||||
from
|
||||
i := 1
|
||||
n := args.argument_count
|
||||
until
|
||||
i > n or cfg /= Void
|
||||
loop
|
||||
if attached args.argument (i) as s then
|
||||
if s.same_string ("--config") or s.same_string ("-c") then
|
||||
if i < n then
|
||||
cfg := args.argument (i + 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
i := i + 1
|
||||
end
|
||||
if cfg = Void then
|
||||
if file_exists ("cms.ini") then
|
||||
cfg := "cms.ini"
|
||||
end
|
||||
end
|
||||
if cfg /= Void then
|
||||
create cms_config.make_from_file (cfg)
|
||||
-- (create {EXECUTION_ENVIRONMENT}).change_working_directory (dir)
|
||||
else
|
||||
create cms_config.make
|
||||
end
|
||||
|
||||
--| EWF settings
|
||||
create opts.make_from_file ("ewf.ini")
|
||||
service_options := opts
|
||||
Precursor
|
||||
|
||||
--| CMS settings
|
||||
base_url := cms_config.site_base_url (base_url)
|
||||
initialize_cms (cms_config)
|
||||
site_email := cms_config.site_email (site_email)
|
||||
site_name := cms_config.site_name (site_name)
|
||||
|
||||
on_launched
|
||||
end
|
||||
|
||||
on_launched
|
||||
local
|
||||
e: CMS_EMAIL
|
||||
do
|
||||
create e.make (site_email, site_email, "[" + site_name + "] launched...", "The site [" + site_name + "] was launched at " + (create {DATE_TIME}.make_now_utc).out + " UTC.")
|
||||
mailer.safe_process_email (e)
|
||||
end
|
||||
|
||||
file_exists (fn: STRING): BOOLEAN
|
||||
local
|
||||
f: RAW_FILE
|
||||
do
|
||||
create f.make (fn)
|
||||
Result := f.exists and then f.is_readable
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user