Updated CMS support for unicode.

This commit is contained in:
2013-06-12 18:22:56 +02:00
parent 110a95b786
commit f3f5384d9b
11 changed files with 142 additions and 161 deletions

View File

@@ -20,8 +20,8 @@ feature {NONE} -- Initialization
initialize
local
args: ARGUMENTS
cfg: detachable STRING
args: ARGUMENTS_32
cfg: detachable READABLE_STRING_32
i,n: INTEGER
do
--| Arguments
@@ -33,7 +33,7 @@ feature {NONE} -- Initialization
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 s.same_string_general ("--config") or s.same_string_general ("-c") then
if i < n then
cfg := args.argument (i + 1)
end
@@ -43,7 +43,7 @@ feature {NONE} -- Initialization
end
if cfg = Void then
if file_exists ("cms.ini") then
cfg := "cms.ini"
cfg := {STRING_32} "cms.ini"
end
end
@@ -55,7 +55,7 @@ feature {NONE} -- Initialization
launch_cms (cms_setup (cfg))
end
cms_setup (a_cfg_fn: detachable READABLE_STRING_8): CMS_CUSTOM_SETUP
cms_setup (a_cfg_fn: detachable READABLE_STRING_GENERAL): CMS_CUSTOM_SETUP
do
if a_cfg_fn /= Void then
create Result.make_from_file (a_cfg_fn)
@@ -124,11 +124,11 @@ feature -- Event
feature -- Helper
file_exists (fn: STRING): BOOLEAN
file_exists (fn: READABLE_STRING_GENERAL): BOOLEAN
local
f: RAW_FILE
do
create f.make (fn)
create f.make_with_name (fn)
Result := f.exists and then f.is_readable
end

View File

@@ -7,6 +7,14 @@ note
class
CMS_CONFIGURATION
inherit
ANY
SHARED_EXECUTION_ENVIRONMENT
export
{NONE} all
end
create
make,
make_from_file
@@ -15,16 +23,19 @@ feature {NONE} -- Initialization
make
do
create options.make (10)
create options.make_equal (10)
analyze
end
make_from_file (a_filename: READABLE_STRING_32)
make_from_file (a_filename: READABLE_STRING_GENERAL)
-- Initialize `Current'.
local
p: PATH
do
make
configuration_location := a_filename
import (a_filename)
create p.make_from_string (a_filename)
configuration_location := p
import_from_path (p)
analyze
end
@@ -38,52 +49,54 @@ feature {NONE} -- Initialization
feature -- Access
configuration_location: detachable READABLE_STRING_8
configuration_location: detachable PATH
option (a_name: READABLE_STRING_GENERAL): detachable ANY
do
Result := options.item (a_name.as_string_8.as_lower)
Result := options.item (a_name)
end
options: HASH_TABLE [STRING, STRING]
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)
s.append (c.key.to_string_8)
s.append_character ('=')
s.append (c.key)
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 + "%N")
s.append ("var_location=" + var_location + "%N")
s.append ("files_location=" + files_location + "%N")
s.append ("themes_location=" + themes_location + "%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)
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: READABLE_STRING_8
var_location: PATH
root_location: READABLE_STRING_8
root_location: PATH
files_location: STRING
files_location: PATH
themes_location: STRING
themes_location: PATH
theme_name (dft: detachable like theme_name): READABLE_STRING_8
do
@@ -158,67 +171,63 @@ feature -- Change
get_var_location
local
res: STRING_32
utf: UTF_CONVERTER
do
if attached options.item ("var-dir") as s then
res := s
create var_location.make_from_string (utf.utf_8_string_8_to_escaped_string_32 (s))
else
res := execution_environment.current_working_directory
var_location := execution_environment.current_working_path
end
if res.ends_with ("/") then
res.remove_tail (1)
end
var_location := res
end
get_root_location
local
res: STRING_32
utf: UTF_CONVERTER
do
if attached options.item ("root-dir") as s then
res := s
create root_location.make_from_string (utf.utf_8_string_8_to_escaped_string_32 (s))
else
res := execution_environment.current_working_directory
root_location := execution_environment.current_working_path
end
if res.ends_with ("/") then
res.remove_tail (1)
end
root_location := res
end
get_files_location
local
utf: UTF_CONVERTER
do
if attached options.item ("files-dir") as s then
files_location := s
create files_location.make_from_string (utf.utf_8_string_8_to_escaped_string_32 (s))
else
files_location := "files"
create files_location.make_from_string ("files")
end
end
get_themes_location
local
dn: DIRECTORY_NAME
utf: UTF_CONVERTER
do
if attached options.item ("themes-dir") as s then
themes_location := s
create themes_location.make_from_string (utf.utf_8_string_8_to_escaped_string_32 (s))
else
create dn.make_from_string (root_location)
dn.extend ("themes")
themes_location := dn.string
themes_location := root_location.extended ("themes")
end
end
feature {NONE} -- Implementation
import (a_filename: READABLE_STRING_32)
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
--FIXME: handle unicode filename here.
create f.make (a_filename)
create f.make_with_path (a_filename)
if f.exists and f.is_readable then
f.open_read
from
@@ -241,7 +250,7 @@ feature {NONE} -- Implementation
l.right_adjust
if l.is_case_insensitive_equal ("@include") then
import (resolved_string (v))
import_from_file (resolved_string (v))
else
set_option (l.as_lower, resolved_string (v))
end
@@ -256,12 +265,7 @@ feature {NONE} -- Implementation
feature {NONE} -- Environment
Execution_environment: EXECUTION_ENVIRONMENT
once
create Result
end
resolved_string (s: READABLE_STRING_8): STRING
resolved_string (s: READABLE_STRING_8): STRING_32
-- Resolved `s' using `options' or else environment variables.
local
i,n,b,e: INTEGER
@@ -280,9 +284,13 @@ feature {NONE} -- Environment
if e > 0 then
k := s.substring (b, e)
if attached option (k) as v then
Result.append (v.out)
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.get (k) as v then
elseif attached execution_environment.item (k) as v then
Result.append (v)
i := e + 1
else

View File

@@ -26,7 +26,7 @@ feature {NONE} -- Initialization
default_create
end
make_from_file (fn: READABLE_STRING_8)
make_from_file (fn: READABLE_STRING_GENERAL)
local
cfg: CMS_CONFIGURATION
do
@@ -83,29 +83,27 @@ feature {NONE} -- Initialization
build_storage
local
dn: DIRECTORY_NAME
dn: PATH
do
if attached configuration as cfg and then attached cfg.var_location as l_site_var_dir then
create dn.make_from_string (l_site_var_dir)
dn := l_site_var_dir
else
create dn.make
create dn.make_current
end
dn.extend ("_storage_")
create {CMS_SED_STORAGE} storage.make (dn.string)
create {CMS_SED_STORAGE} storage.make (dn.extended ("_storage_").name)
end
build_session_manager
local
dn: DIRECTORY_NAME
dn: PATH
do
if attached configuration as cfg and then attached cfg.var_location as l_site_var_dir then
create dn.make_from_string (l_site_var_dir)
dn := l_site_var_dir
else
create dn.make
create dn.make_empty
end
dn.extend ("_storage_")
dn.extend ("_sessions_")
create {WSF_FS_SESSION_MANAGER} session_manager.make_with_folder (dn.string)
dn := dn.extended ("_storage_").extended ("_sessions_")
create {WSF_FS_SESSION_MANAGER} session_manager.make_with_folder (dn.name)
end
build_auth_engine

View File

@@ -110,7 +110,6 @@ feature {NONE} -- Initialization
local
-- h: CMS_HANDLER
file_hdl: CMS_FILE_SYSTEM_HANDLER
dn: DIRECTORY_NAME
do
create router.make (10)
router.set_base_url (base_url)
@@ -118,13 +117,12 @@ feature {NONE} -- Initialization
router.map (create {WSF_URI_MAPPING}.make ("/", create {CMS_HANDLER}.make (agent handle_home)))
router.map (create {WSF_URI_MAPPING}.make ("/favicon.ico", create {CMS_HANDLER}.make (agent handle_favicon)))
create file_hdl.make (files_location)
create file_hdl.make_with_path (files_location)
file_hdl.disable_index
file_hdl.set_max_age (8*60*60)
router.map (create {WSF_STARTS_WITH_MAPPING}.make ("/files/", file_hdl))
create dn.make_from_string (theme_resource_location)
create file_hdl.make (theme_resource_location)
create file_hdl.make_with_path (theme_resource_location)
file_hdl.set_max_age (8*60*60)
router.map (create {WSF_STARTS_WITH_MAPPING}.make ("/theme/", file_hdl))
end
@@ -257,25 +255,20 @@ feature -- Router
site_url: READABLE_STRING_8
site_dir: READABLE_STRING_8
site_dir: PATH
site_var_dir: READABLE_STRING_8
site_var_dir: PATH
files_location: READABLE_STRING_8
files_location: PATH
themes_location: READABLE_STRING_8
themes_location: PATH
compute_theme_resource_location
local
dn: DIRECTORY_NAME
do
create dn.make_from_string (themes_location)
dn.extend (theme_name)
dn.extend ("res")
theme_resource_location := dn.string
theme_resource_location := themes_location.extended (theme_name).extended ("res")
end
theme_resource_location: READABLE_STRING_8
theme_resource_location: PATH
theme_name: READABLE_STRING_32
@@ -420,11 +413,8 @@ feature -- Core Execution
handle_favicon (req: WSF_REQUEST; res: WSF_RESPONSE)
local
fres: WSF_FILE_RESPONSE
fn: FILE_NAME
do
create fn.make_from_string (theme_resource_location)
fn.set_file_name ("favicon.ico")
create fres.make (fn.string)
create fres.make_with_path (theme_resource_location.extended ("favicon.ico"))
fres.set_expires_in_seconds (7 * 24 * 60 * 60) -- 7 jours
res.send (fres)
end

View File

@@ -11,6 +11,7 @@ inherit
WSF_FILE_SYSTEM_HANDLER
create
make
make,
make_with_path
end

View File

@@ -45,7 +45,6 @@ feature -- Conversion
i: INTEGER
n: INTEGER
in_tag: BOOLEAN
t: READABLE_STRING_8
p1, p2: INTEGER
do
create l_new.make (a_text.count)

View File

@@ -13,6 +13,11 @@ inherit
CMS_HOOK_AUTO_REGISTER
SHARED_EXECUTION_ENVIRONMENT
export
{NONE} all
end
create
make
@@ -68,22 +73,22 @@ feature -- Handler
if attached cms.configuration as cfg and then attached cfg.configuration_location as l_loc then
s.append ("<hr/>")
append_info_to ("Configuration file", l_loc, e, s)
append_info_to ("Configuration file", l_loc.name, e, s)
end
s.append ("<hr/>")
append_info_to ("Current dir", (create {EXECUTION_ENVIRONMENT}).current_working_directory, e, s)
append_info_to ("Current dir", execution_environment.current_working_path.utf_8_name, e, s)
append_info_to ("Base url", cms.base_url, e, s)
append_info_to ("Script url", cms.script_url, e, s)
s.append ("<hr/>")
append_info_to ("Dir", cms.site_dir, e, s)
append_info_to ("Var dir", cms.site_var_dir, e, s)
append_info_to ("Dir", cms.site_dir.utf_8_name, e, s)
append_info_to ("Var dir", cms.site_var_dir.utf_8_name, e, s)
s.append ("<hr/>")
append_info_to ("Theme", cms.theme_name, e, s)
append_info_to ("Theme location", cms.theme_resource_location, e, s)
append_info_to ("Theme location", cms.theme_resource_location.utf_8_name, e, s)
s.append ("<hr/>")
append_info_to ("Files location", cms.files_location, e, s)
append_info_to ("Files location", cms.files_location.utf_8_name, e, s)
s.append ("<hr/>")
append_info_to ("Url", e.url ("/", Void), e, s)

View File

@@ -75,7 +75,7 @@ feature -- Execution
password_form_submit (fd: WSF_FORM_DATA; b: STRING)
local
e: detachable NOTIFICATION_EMAIL
e: detachable CMS_EMAIL
l_uuid: UUID
do
debug
@@ -144,7 +144,7 @@ feature -- Execution
Result := f
end
new_password_email (u: CMS_USER; a_mail_address: STRING; a_extra: READABLE_STRING_8): NOTIFICATION_EMAIL
new_password_email (u: CMS_USER; a_mail_address: STRING; a_extra: READABLE_STRING_8): CMS_EMAIL
local
b: STRING
opts: CMS_URL_API_OPTIONS

View File

@@ -73,7 +73,7 @@ feature -- Execution
b: STRING
u: detachable CMS_USER
up: detachable CMS_USER_PROFILE
e: detachable NOTIFICATION_EMAIL
e: detachable CMS_EMAIL
l_pass: detachable READABLE_STRING_32
l_uuid: UUID
do
@@ -174,7 +174,7 @@ feature -- Execution
Result := f
end
new_registration_email (a_mail_address: STRING; u: CMS_USER; a_password: detachable like {CMS_USER}.password; a_extra: READABLE_STRING_8): NOTIFICATION_EMAIL
new_registration_email (a_mail_address: STRING; u: CMS_USER; a_password: detachable like {CMS_USER}.password; a_extra: READABLE_STRING_8): CMS_EMAIL
require
has_clear_password: u.password /= Void or else a_password /= Void
local
@@ -202,7 +202,7 @@ feature -- Execution
create Result.make (service.site_email, a_mail_address, "Account details for " + u.name + " at " + service.site_name, b)
end
new_user_account_email (a_mail_address: STRING; u: CMS_USER): NOTIFICATION_EMAIL
new_user_account_email (a_mail_address: STRING; u: CMS_USER): CMS_EMAIL
local
b: STRING
opts: CMS_URL_API_OPTIONS

View File

@@ -1,6 +1,6 @@
note
description : "[
Component representing an email for the CMS
Component representing an email
]"
author : "$Author$"
date : "$Date$"

View File

@@ -16,16 +16,16 @@ create
feature {NONE} -- Initialization
make (dn: STRING)
make (dn: READABLE_STRING_GENERAL)
-- Initialize `Current'.
do
directory_name := dn
ensure_directory_exists (dn)
create directory_name.make_from_string (dn)
ensure_directory_exists (directory_name)
create sed
initialize
end
directory_name: STRING
directory_name: PATH
sed: SED_STORABLE_FACILITIES
@@ -49,18 +49,14 @@ feature {NONE} -- Initialization
save_object_with_id (obj: ANY; a_id: INTEGER; a_type: STRING)
local
dn: STRING
fn: FILE_NAME
fn: PATH
f: RAW_FILE
do
create fn.make_from_string (directory_name)
fn.extend (a_type)
dn := fn.string
ensure_directory_exists (dn)
create fn.make_from_string (dn)
fn.set_file_name (a_id.out)
-- fn.add_extension ("txt")
create f.make (fn.string)
fn := directory_name.extended (a_type)
ensure_directory_exists (fn)
fn := fn.extended (a_id.out)
-- .appended_with_extension ("txt")
create f.make_with_path (fn)
-- check not f.exists end
f.create_read_write
sed_file_store (obj, f)
@@ -69,18 +65,14 @@ feature {NONE} -- Initialization
object_with_id (a_id: INTEGER; a_type: STRING): detachable ANY
local
dn: STRING
fn: FILE_NAME
fn: PATH
f: RAW_FILE
do
create fn.make_from_string (directory_name)
fn.extend (a_type)
dn := fn.string
ensure_directory_exists (dn)
create fn.make_from_string (dn)
fn.set_file_name (a_id.out)
-- fn.add_extension ("txt")
create f.make (fn.string)
fn := directory_name.extended (a_type)
ensure_directory_exists (fn)
fn := fn.extended (a_id.out)
-- .append_with_extension ("txt")
create f.make_with_path (fn)
if f.exists and f.is_readable then
f.open_read
Result := sed_file_retrieved (f)
@@ -261,30 +253,24 @@ feature -- Email
save_email (a_email: NOTIFICATION_EMAIL)
local
dn: STRING
fn: FILE_NAME
dn: PATH
fn: PATH
f: RAW_FILE
ts: INTEGER_64
i: INTEGER
do
create fn.make_from_string (directory_name)
fn.extend ("emails")
dn := fn.string
dn := directory_name.extended ("emails")
ensure_directory_exists (dn)
ts := (create {HTTP_DATE_TIME_UTILITIES}).unix_time_stamp (a_email.date)
from
create fn.make_from_string (dn)
fn.set_file_name (ts.out)
fn.add_extension ("txt")
create f.make (fn.string)
fn := dn.extended (ts.out).appended_with_extension ("txt")
create f.make_with_path (fn)
until
not f.exists
loop
i := i + 1
create fn.make_from_string (dn)
fn.set_file_name (ts.out + "-" + i.out)
fn.add_extension ("txt")
f.make (fn.string)
fn := dn.extended (ts.out + "-" + i.out).appended_with_extension ("txt")
f.make_with_path (fn)
end
f.create_read_write
f.put_string (a_email.message)
@@ -388,13 +374,11 @@ feature {NONE} -- Implementation
last_sequence (a_type: STRING): INTEGER
local
fn: FILE_NAME
fn: PATH
f: RAW_FILE
do
create fn.make_from_string (directory_name)
fn.set_file_name (a_type)
fn.add_extension ("last_id")
create f.make (fn.string)
fn := directory_name.extended (a_type).appended_with_extension ("last_id")
create f.make_with_path (fn)
if f.exists and then f.is_readable then
f.open_read
f.read_line
@@ -409,13 +393,11 @@ feature {NONE} -- Implementation
next_sequence (a_type: STRING): INTEGER
local
fn: FILE_NAME
fn: PATH
f: RAW_FILE
do
create fn.make_from_string (directory_name)
fn.set_file_name (a_type)
fn.add_extension ("last_id")
create f.make (fn.string)
fn := directory_name.extended (a_type).appended_with_extension ("last_id")
create f.make_with_path (fn)
if f.exists and then f.is_readable then
f.open_read
f.read_line
@@ -439,13 +421,12 @@ feature {NONE} -- Implementation
]
local
f: RAW_FILE
fn: FILE_NAME
fn: PATH
res: detachable like users_index
retried: INTEGER
do
create fn.make_from_string (directory_name)
fn.set_file_name ("users.db")
create f.make (fn.string)
fn := directory_name.extended ("users.db")
create f.make_with_path (fn)
if retried = 0 then
if f.exists and then f.is_readable then
f.open_read
@@ -469,11 +450,10 @@ feature {NONE} -- Implementation
store_users_index (a_users_index: like users_index)
local
f: RAW_FILE
fn: FILE_NAME
fn: PATH
do
create fn.make_from_string (directory_name)
fn.set_file_name ("users.db")
create f.make (fn.string)
fn := directory_name.extended ("users.db")
create f.make_with_path (fn)
if not f.exists or else f.is_writable then
f.open_write
sed_file_store (a_users_index, f)
@@ -612,12 +592,12 @@ feature -- Misc
feature {NONE} -- Implementation
ensure_directory_exists (dn: STRING)
ensure_directory_exists (dn: PATH)
local
d: DIRECTORY
do
d := tmp_dir
d.make (dn)
d.make_with_path (dn)
if not d.exists then
d.recursive_create_dir
end
@@ -627,7 +607,7 @@ feature {NONE} -- Implementation
tmp_dir: DIRECTORY
once
create Result.make (directory_name)
create Result.make_with_path (directory_name)
end
invariant