diff --git a/examples/demo/demo.ini b/examples/demo/demo.ini index e09f0dd..2498319 100644 --- a/examples/demo/demo.ini +++ b/examples/demo/demo.ini @@ -1,2 +1,3 @@ port=9090 +#port=12345 #verbose=true diff --git a/examples/demo/modules/file_upload/cms_file_upload.e b/examples/demo/modules/file_upload/cms_file_upload.e deleted file mode 100644 index 0edf440..0000000 --- a/examples/demo/modules/file_upload/cms_file_upload.e +++ /dev/null @@ -1,254 +0,0 @@ -note - description: "file_upload application root class" - date: "$Date$" - revision: "$Revision$" - -class - CMS_FILE_UPLOAD - -inherit - CMS_MODULE - redefine - install, - initialize, - setup_hooks - end - - CMS_HOOK_BLOCK - - CMS_HOOK_MENU_SYSTEM_ALTER - - -- WSF_ROUTED_URI_TEMPLATE_HELPER - - SHARED_EXECUTION_ENVIRONMENT - -create - make - -feature {NONE} -- Initialization - - make - do - name := "file_uploader" - version := "1.0" - description := "Service to upload some files" - package := "file upload" - end - -feature -- Access - - name: STRING - -feature {CMS_API} -- Module Initialization - - initialize (api: CMS_API) - -- - do - Precursor (api) - end - -feature {CMS_API }-- Module management - - install (api: CMS_API) - -- install the module - local - sql: STRING - do - -- create a database table - if attached {CMS_STORAGE_SQL_I} api.storage as l_sql_storage then - if not l_sql_storage.sql_table_exists ("file_upload_table") then - sql := "[ -CREATE TABLE file_upload_table( - `id` INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL CHECK("id">=0), - `name` VARCHAR(100) NOT NULL, - `uploaded_date` DATE, - `size` INTEGER -); - ]" - l_sql_storage.sql_execute_script (sql, Void) - if l_sql_storage.has_error then - api.logger.put_error ("Could not initialize database for file uploader module", generating_type) - end - end - Precursor {CMS_MODULE}(api) - end - end - -feature -- Access: router - - - setup_router (a_router: WSF_ROUTER; a_api: CMS_API) - -- - local - www: WSF_FILE_SYSTEM_HANDLER - do - - map_uri_template_agent (a_router, "/upload{?nb}", agent execute_upload_handler, void) - - create www.make_with_path (document_root) - www.set_directory_index (<<"index.html">>) - www.set_not_found_handler (agent execute_not_found_handler) - a_router.handle("", www, a_router.methods_get) - end - -feature -- Hooks - - setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER) - do - a_hooks.subscribe_to_menu_system_alter_hook (Current) - a_hooks.subscribe_to_block_hook (Current) - end - - block_list: ITERABLE [like {CMS_BLOCK}.name] - do - Result := <<"Uploader info TODO">> - end - - get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE) - do - - end - - menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE) - local - link: CMS_LOCAL_LINK - do - create link.make ("Upload", "/upload") - a_menu_system.primary_menu.extend (link) - end - -feature -- Configuration - - document_root: PATH - -- Document root to look for files or directories - once - Result := execution_environment.current_working_path.extended ("docs") - end - - files_root: PATH - -- Uploaded files will be stored in `files_root' folder - once - Result := document_root.extended ("files") - end - -feature -- Handler - - execute_not_found_handler (uri: READABLE_STRING_8; req: WSF_REQUEST; res: WSF_RESPONSE) - -- `uri' is not found, redirect to default page - do - res.redirect_now_with_content (req.script_url ("/"), uri + ": not found. %N Redirectioin to" + req.script_url ("/"), "text/html") - end - - execute_upload_handler(req: WSF_REQUEST; res: WSF_RESPONSE; a_api: CMS_API) - local - body: STRING_8 - safe_filename: STRING_8 - path: PATH - page: WSF_HTML_PAGE_RESPONSE - n: INTEGER - do - if req.is_request_method ("GET") or else not req.has_uploaded_file then - create page.make - page.set_title ("EWF: Upload file") - page.add_style (req.script_url ("style.css"), "all") - create body.make_empty - page.set_body (body) - - -- create the body - body.append ("

EWF: Upload files

%N") - body.append ("
%N") - - -- tetermine how many files to upload by a query parameter ?nb=number_of_files - if attached {WSF_STRING} req.query_parameter ("nb") as p_nb and then p_nb.is_integer then - n := p_nb.integer_value - else - n := 1 - end - - -- llist for the number of wanted files a upload button - from - until - n = 0 - loop - body.append ("
%N") - n := n-1 - end - - -- set the submit button - body.append ("%N") - - res.send (page) - else - create body.make_empty - body.append ("

EWF: Uploaded files

%N") - body.append ("
    %N") - - n := 0 - - across - req.uploaded_files as u_file - loop - body.append ("
  • %N") - body.append ("
    " + u_file.item.name + "=" + html_encode (u_file.item.filename) + " size=" + u_file.item.size.out + " type" + u_file.item.content_type + "
    %N") - safe_filename := u_file.item.safe_filename - path := files_root.extended (safe_filename) - - -- TODO: list dhe uploaded items - - body.append ("
  • %N") - end - - body.append ("
%N") - - -- create page - create page.make - page.add_style ("../style.css", "all") - page.set_body (body) - res.send (page) - end - end - -feature {NONE} -- Encoder - - url_encode (s: READABLE_STRING_32): STRING_8 - -- URL Encode `s' as Result - do - Result := url_encoder.encoded_string (s) - end - - url_encoder: URL_ENCODER - once - create Result - end - - html_encode (s: READABLE_STRING_32): STRING_8 - -- HTML Encode `s' as Result - do - Result := html_encoder.encoded_string (s) - end - - html_encoder: HTML_ENCODER - once - create Result - end - -feature -- Mapping helper: uri template agent - - map_uri_template (a_router: WSF_ROUTER; a_tpl: STRING; h: WSF_URI_TEMPLATE_HANDLER; rqst_methods: detachable WSF_REQUEST_METHODS) - -- Map `h' as handler for `a_tpl', according to `rqst_methods'. - require - a_tpl_attached: a_tpl /= Void - h_attached: h /= Void - do - a_router.map (create {WSF_URI_TEMPLATE_MAPPING}.make (a_tpl, h), rqst_methods) - end - - map_uri_template_agent (a_router: WSF_ROUTER; a_tpl: READABLE_STRING_8; proc: PROCEDURE [TUPLE [req: WSF_REQUEST; res: WSF_RESPONSE]]; rqst_methods: detachable WSF_REQUEST_METHODS) - -- Map `proc' as handler for `a_tpl', according to `rqst_methods'. - require - a_tpl_attached: a_tpl /= Void - proc_attached: proc /= Void - do - map_uri_template (a_router, a_tpl, create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (proc), rqst_methods) - end -end diff --git a/examples/demo/modules/file_upload/file_uploader.ecf b/examples/demo/modules/file_upload/file_uploader.ecf deleted file mode 100644 index ab71576..0000000 --- a/examples/demo/modules/file_upload/file_uploader.ecf +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - /.svn$ - /CVS$ - /EIFGENs$ - - - - diff --git a/examples/demo/site/database.sqlite3 b/examples/demo/site/database.sqlite3 index 687d1fe..2c2fdf0 100644 Binary files a/examples/demo/site/database.sqlite3 and b/examples/demo/site/database.sqlite3 differ diff --git a/examples/demo/site/files/.cache/feed_aggregator/feed__forum__5_True b/examples/demo/site/files/.cache/feed_aggregator/feed__forum__5_True index 011edfd..2d301af 100644 --- a/examples/demo/site/files/.cache/feed_aggregator/feed__forum__5_True +++ b/examples/demo/site/files/.cache/feed_aggregator/feed__forum__5_True @@ -1,64 +1,29 @@ -
+
  • -
    Jan 07
    -RE: [eiffel-users] Book suggestion -
    I agree with each of the three you’ve mentioned: 1. Thick-client GUI 2. Browser/Webserver/Web-services 3. Mobile applications (phones/tablets) I will add: RaspberryPi! The RaspberryPi is relatively young and needs Eiffel. I have seen folks ganging these little $5 PC’s together to produce
    +
    Jan 11
    +SCOOP & Contracts +
    Recently, I was reading a research paper from a Canadian university talking about applying something like SCOOP to Java. Because Java does not have Design-by-Contract, they wanted to build in a new keyword (like "require") called "await". From the writers point of view, the require contract was
  • -
    Jan 07
    -Book suggestion -
    What the world needs, besides peace, is a new edition of the excellent book *Windows Programming Made Easy* by Maughan and Simon, rewritten for Vision2. I've looked in vain for an equally thorough reference for Vision2. The Vision2 section at docs.eiffel.com is good as far as it goes, but nowhere
    +
    Jan 11
    +General Question: Object Persistence Mechanism +
    NEED: An innate, compiler-known, object persistence mechanism, whereby objects are tracked for version (at design-time), version-updating (at run-time comparative between memory object and persisted object), and attribute change auto-persist. What would be nice is something akin to the Design-by
  • -
    Jan 06
    -Re: [eiffel-users] Easiest way to do type comparisons? -
    I've been looking at the code. There are around 1,500 lines of code affected, and in fact, a pretty high dependence on using type ids rather than testing types of objects. Fixing this is going to be major surgery, but I have to do something because it's broken every project we have in Eiffel,
    +
    Jan 11
    +RE: [eiffel-users] Solving OOSC 2/E E7.3 +
    In addition to Colin's reply, "is" is no longer used, as it is unnecessary. The functions sqrt and atan are in classes SINGLE_MATH or DOUBLE_MATH which are interfaces to the C library functions defined in math.h. Peter Horan -----Original Message----- From: eiffel...@googlegroups.com
  • -
    Jan 06
    -Creating dynamic objects (Eiffel) -

    I have to find a way to create objects dynamically, that means the user can decide how many objects to create once the program starts. What I tried to do is:

    - -
                    if count = 6 then
    -                create player1.player
    -                create player2.player 
    -                create player3.player
    -                create player4.player
    -                create player5.player
    -                create player6.player
    -                  elseif count > 4 then
    -                    create player1.player
    -                    create player2.player 
    -                    create player3.player
    -                    create player4.player
    -                    create player5.player
    -                      elseif count > 3 then
    -                        create player1.player
    -                        create player2.player 
    -                        create player3.player
    -                        create player4.player
    -                          elseif count > 2 then
    -                            create player1.player
    -                            create player2.player 
    -                            create player3.player
    -                           else
    -                             create player1.player
    -                             create player2.player 
    -               end
    -
    - -

    Once the user has choosen the number of players, the variable count gets updated and the feature that creates the objects gets called.

    - -

    I used this kind of brute force method, instead of a loop, because I need the "names" of the objects, I have to called them again in the program.

    - -

    Anyways the compiler gives me a VEVI error, variable is not properly set. -Some help?

    +
    Jan 11
    +Re: [eiffel-users] Solving OOSC 2/E E7.3 +
    The indexing clause has been replaced by the note clause (just a change of keyword). You might try changing the configuration to use transitional syntax instead of standard syntax. On 11 January 2016 at 09:46, wrote: > Hi, everyone. > > I'm reading the japanese version of
  • -
    Jan 05
    -RE: [eiffel-users] Easiest way to do type comparisons? -
    In the old way, you will get the detachable type ID. In the new way (only available in experimental mode), you will always get an attached type ID. This is why, even if you are increasing the size of your table which should have a minimal impact on performance, it will work now and then. >
    +
    Jan 11
    +Solving OOSC 2/E E7.3 +
    Hi, everyone. I'm reading the japanese version of Object-Oriented Software Construction 2/E. I tried to build the code of "7.5.4 class" in EiffelStudio 15.11 and it raises some build errors. My question is: 1) Is the "indexing description:" description disposed? 2) Is the "function: syntax
  • See more ...
diff --git a/examples/demo/site/files/.cache/feed_aggregator/feed__news__0_True b/examples/demo/site/files/.cache/feed_aggregator/feed__news__0_True index 15b8439..c2e1ee7 100644 --- a/examples/demo/site/files/.cache/feed_aggregator/feed__news__0_True +++ b/examples/demo/site/files/.cache/feed_aggregator/feed__news__0_True @@ -1,4 +1,4 @@ -
+
  • 2015, Nov 17
    diff --git a/examples/demo/site/files/uploaded_files/Readme.md b/examples/demo/site/files/uploaded_files/Readme.md new file mode 100644 index 0000000..e69de29 diff --git a/examples/demo/site/files/uploaded_files/demo-safe.ecf b/examples/demo/site/files/uploaded_files/demo-safe.ecf new file mode 100644 index 0000000..482e63e --- /dev/null +++ b/examples/demo/site/files/uploaded_files/demo-safe.ecf @@ -0,0 +1,82 @@ + + + Example/demo for Eiffel ROC CMS library + + + + /.svn$ + /CVS$ + /EIFGENs$ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/demo/site/files/uploaded_files/demo.ini b/examples/demo/site/files/uploaded_files/demo.ini new file mode 100644 index 0000000..2498319 --- /dev/null +++ b/examples/demo/site/files/uploaded_files/demo.ini @@ -0,0 +1,3 @@ +port=9090 +#port=12345 +#verbose=true diff --git a/examples/demo/site/files/uploaded_files/install_modules.bat b/examples/demo/site/files/uploaded_files/install_modules.bat new file mode 100644 index 0000000..98de61d --- /dev/null +++ b/examples/demo/site/files/uploaded_files/install_modules.bat @@ -0,0 +1,15 @@ +setlocal +set ROC_CMD=call %~dp0..\..\tools\roc.bat +set ROC_CMS_DIR=%~dp0 + +%ROC_CMD% install --module ..\..\modules\admin --dir %ROC_CMS_DIR% +%ROC_CMD% install --module ..\..\modules\auth --dir %ROC_CMS_DIR% +%ROC_CMD% install --module ..\..\modules\basic_auth --dir %ROC_CMS_DIR% +%ROC_CMD% install --module ..\..\modules\blog --dir %ROC_CMS_DIR% +%ROC_CMD% install --module ..\..\modules\node --dir %ROC_CMS_DIR% +%ROC_CMD% install --module ..\..\modules\oauth20 --dir %ROC_CMS_DIR% +%ROC_CMD% install --module ..\..\modules\openid --dir %ROC_CMS_DIR% +%ROC_CMD% install --module ..\..\modules\recent_changes --dir %ROC_CMS_DIR% +%ROC_CMD% install --module ..\..\modules\feed_aggregator --dir %ROC_CMS_DIR% +%ROC_CMD% install --module ..\..\modules\google_search --dir %ROC_CMS_DIR% +%ROC_CMD% install --module ..\..\modules\taxonomy --dir %ROC_CMS_DIR% diff --git a/modules/file_upload/cms_file_upload.e b/modules/file_upload/cms_file_upload.e index 0edf440..e32c716 100644 --- a/modules/file_upload/cms_file_upload.e +++ b/modules/file_upload/cms_file_upload.e @@ -18,8 +18,6 @@ inherit CMS_HOOK_MENU_SYSTEM_ALTER - -- WSF_ROUTED_URI_TEMPLATE_HELPER - SHARED_EXECUTION_ENVIRONMENT create @@ -47,7 +45,7 @@ feature {CMS_API} -- Module Initialization Precursor (api) end -feature {CMS_API }-- Module management +feature {CMS_API}-- Module management install (api: CMS_API) -- install the module @@ -83,7 +81,7 @@ feature -- Access: router www: WSF_FILE_SYSTEM_HANDLER do - map_uri_template_agent (a_router, "/upload{?nb}", agent execute_upload_handler, void) + map_uri_template_agent (a_router, "/upload{?nb}", agent execute_upload, void) create www.make_with_path (document_root) www.set_directory_index (<<"index.html">>) @@ -113,7 +111,7 @@ feature -- Hooks local link: CMS_LOCAL_LINK do - create link.make ("Upload", "/upload") + create link.make ("Upload", "upload/") a_menu_system.primary_menu.extend (link) end @@ -122,13 +120,16 @@ feature -- Configuration document_root: PATH -- Document root to look for files or directories once - Result := execution_environment.current_working_path.extended ("docs") + Result := execution_environment.current_working_path.extended ("site") end files_root: PATH -- Uploaded files will be stored in `files_root' folder + local + tmp: PATH once - Result := document_root.extended ("files") + tmp := document_root.extended ("files") + Result := tmp.extended ("uploaded_files") end feature -- Handler @@ -139,7 +140,89 @@ feature -- Handler res.redirect_now_with_content (req.script_url ("/"), uri + ": not found. %N Redirectioin to" + req.script_url ("/"), "text/html") end - execute_upload_handler(req: WSF_REQUEST; res: WSF_RESPONSE; a_api: CMS_API) + execute_upload (req: WSF_REQUEST; res: WSF_RESPONSE) + local + body: STRING_8 + answer: STRING_8 + file_name: STRING_8 + file_path: PATH + page: WSF_HTML_PAGE_RESPONSE + tmp: BOOLEAN + do + if req.is_request_method ("GET") or else not req.has_uploaded_file then + -- create page + create page.make + page.set_title ("EWF: Upload file") + page.add_style (req.script_url ("style.css"), "all") + -- page.set_status_code ({HTTP_STATUS_CODE}.ok) + + -- create body + create body.make_empty + body.append ("

    EWF: Upload files

    %N") + body.append (" Upload files %N") + body.append ("
    %N") + body.append ("
    %N") + body.append ("
  • %N") + + -- connect the body with the page + page.set_body (body) + + -- set response + -- res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-type", "text/html"], ["Content-length", body.count.out]>>) + res.send (page) + else + -- create page + create page.make + page.set_title ("Uploaded files") + page.add_style (req.script_url ("style.css"), "all") + + -- create answer + create answer.make_empty + answer.append ("

    Uploaded Files

    %N") + answer.append (" %N") + answer.append ("") + across + req.uploaded_files as uf + loop + file_name := uf.item.safe_filename + + -- add file to table + answer.append ("") + answer.append ("") + answer.append ("%N") + answer.append ("%N") + answer.append ("") + + -- check if file is already in folder + if not files_root.has_extension (file_name) then + file_path := files_root.extended (file_name) + + -- move file to path + tmp := uf.item.move_to(file_path.name) + end + + end + answer.append ("
    FilenameTypeSize
    %N") + answer.append ("" + uf.item.filename + " ") + answer.append ("") + answer.append (uf.item.content_type) + answer.append ("") + answer.append (uf.item.size.out + " Bytes") + answer.append ("
    %N") + + -- connect the body with the page + page.set_body (answer) + + -- set response + -- res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-type", "text/html"], ["Content-length", answer.count.out]>>) + res.send (page) + end + end + + execute_upload_handler(req: WSF_REQUEST; res: WSF_RESPONSE) local body: STRING_8 safe_filename: STRING_8 @@ -148,13 +231,13 @@ feature -- Handler n: INTEGER do if req.is_request_method ("GET") or else not req.has_uploaded_file then + -- create page create page.make page.set_title ("EWF: Upload file") page.add_style (req.script_url ("style.css"), "all") - create body.make_empty - page.set_body (body) -- create the body + create body.make_empty body.append ("

    EWF: Upload files

    %N") body.append ("
    %N") @@ -176,7 +259,7 @@ feature -- Handler -- set the submit button body.append ("%N") - + res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-type", "text/html"], ["Content-length", body.count.out]>>) res.send (page) else create body.make_empty @@ -204,6 +287,7 @@ feature -- Handler create page.make page.add_style ("../style.css", "all") page.set_body (body) + res.put_header ({HTTP_STATUS_CODE}.ok, <<["Content-type", "text/html"], ["Content-length", body.count.out]>>) res.send (page) end end diff --git a/modules/file_upload/file_uploader.ecf b/modules/file_upload/file_uploader.ecf index 83a246c..ff9add6 100644 --- a/modules/file_upload/file_uploader.ecf +++ b/modules/file_upload/file_uploader.ecf @@ -1,9 +1,12 @@ - -