From b77c5cd93c1a67dee8086998958f042524e9e9ef Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Fri, 22 May 2015 23:04:09 +0200 Subject: [PATCH] Added abstraction of cms storage on file system. (mostly helpers features). --- src/persistence/sql/cms_storage_fs_i.e | 107 +++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/persistence/sql/cms_storage_fs_i.e diff --git a/src/persistence/sql/cms_storage_fs_i.e b/src/persistence/sql/cms_storage_fs_i.e new file mode 100644 index 0000000..2cb025f --- /dev/null +++ b/src/persistence/sql/cms_storage_fs_i.e @@ -0,0 +1,107 @@ +note + description: "Interface used to implement CMS Storage based on File system." + date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $" + revision: "$Revision: 96616 $" + +deferred class + CMS_STORAGE_FS_I + +inherit + SHARED_LOGGER + +feature {NONE} -- Initialization + + make (a_location: PATH; a_api: CMS_API) + do + location := a_location + api := a_api + create error_handler.make + end + +feature -- Access + + api: CMS_API + -- Associated CMS api. + + location: PATH + -- File system location. + +feature -- Error handler + + error_handler: ERROR_HANDLER + -- Error handler. + + has_error: BOOLEAN + -- Last operation reported error. + do + Result := error_handler.has_error + end + + reset_error + -- Reset errors. + do + error_handler.reset + end + +feature -- Helpers + + save_to_file (a_text: STRING; opt_name: detachable READABLE_STRING_GENERAL) + local + s: READABLE_STRING_GENERAL + now: DATE_TIME + fut: WSF_FILE_UTILITIES [RAW_FILE] + do + create fut + if opt_name /= Void then + s := opt_name + else + create now.make_now_utc + s := date_to_yyyymmdd_hhmmss_string (now) + end + if attached fut.new_file (location.extended (s)) as f then + f.put_string (a_text) + f.close + else + error_handler.add_custom_error (0, "saving failure", Void) + end + end + + date_to_yyyymmdd_hhmmss_string (d: DATE_TIME): STRING + local + i: INTEGER + do + create Result.make_empty + Result.append_integer (d.year) + Result.append_character ('-') + i := d.month + if i < 10 then + Result.append_integer (0) + end + Result.append_integer (i) + Result.append_character ('-') + i := d.day + if i < 10 then + Result.append_integer (0) + end + Result.append_integer (i) + Result.append_character ('_') + i := d.hour + if i < 10 then + Result.append_integer (0) + end + Result.append_integer (i) + Result.append_character ('-') + i := d.minute + if i < 10 then + Result.append_integer (0) + end + Result.append_integer (i) + Result.append_character ('-') + i := d.second + if i < 10 then + Result.append_integer (0) + end + Result.append_integer (i) + end + +end