# # # # matching_files_util.cfv # # # include "templates.util.encoding"; # # # # get_the_files_dat() # # # subroutine(get_the_files_dat( node the_files, int index_from, int index_to), ( node item; string file_name; string files_dat = "["; for (int i = index_from; i <= index_to; i++) ( item = subnode_by_number(the_files, i); file_name = @item; file_name = convert_local_code_page_to_utf8(file_name); files_dat .= '"' . encode_json(file_name) . '",'; ); files_dat = replace_last(files_dat, ",", "]"); # Return files_dat; )); # # # # get_matching_files_dat() # # # subroutine(get_matching_files_dat( string session_id, node the_log_source), ( # the_log_source is a node with one log source, it can be from the New Profile Wizard # or from Config/Log Source. debug_message("##### get_matching_files_dat() \n"); debug_message("##### the_log_source:\n" . node_as_string(the_log_source) . "\n"); # # # Update the_log_source (in particular when from new profile wizard) # # node log_source_item; string log_source_type; string pathname; foreach log_source_item the_log_source ( log_source_type = @log_source_item{"type"}; if (log_source_type eq "local") then ( # Convert pathname from UTF-8 to local code page pathname = @log_source_item{"pathname"}; @log_source_item{"pathname"} = convert_utf8_to_local_code_page(pathname); ) else if (log_source_type eq "ftp") then ( # Add username and password node if it doesn't yet exist if (!log_source_item?{"username"}) then ( @log_source_item{"username"} = ""; ); if (!log_source_item?{"password"}) then ( @log_source_item{"password"} = ""; ); ); ); # # # Get matching files # # # Note, we don't sort the matching files! delete_node("v.temp_matching_files"); v.temp_matching_files = ""; get_files_matching_log_source(the_log_source, "v.temp_matching_files"); # We need to convert all pathnames from UTF8 to local code page! # debug_message("\nmatching files:\n" . node_as_string("v.temp_matching_files") . "\n"); string cached_matching_files_node_name = ""; int number_of_matched_files = num_subnodes("v.temp_matching_files"); string label; string files_dat; if (number_of_matched_files > 0) then ( int number_of_files_to_load; int max_files_to_load = 200; bool safe_matched_files_to_cache = false; if ((number_of_matched_files - max_files_to_load) > (max_files_to_load / 2)) then ( # Load max_files_to_load only and save matched files in cache number_of_files_to_load = max_files_to_load; safe_matched_files_to_cache = true; ) else ( # Load all files now number_of_files_to_load = number_of_matched_files; ); files_dat = get_the_files_dat("v.temp_matching_files", 0, number_of_files_to_load - 1); label = expand(lang_admin.log_source_matching_files.matched_multiple_label); if (safe_matched_files_to_cache) then ( cached_matching_files_node_name = get_token(); string matching_files_sessions_path = "sessions_cache." . session_id . ".matching_files"; clone_node("v.temp_matching_files", matching_files_sessions_path . "." . cached_matching_files_node_name); save_node(matching_files_sessions_path . "." . cached_matching_files_node_name); ); ) else ( files_dat = "[]"; label = lang_admin.log_source_matching_files.no_match_label; ); # # Return dat # string dat = "{"; dat .= add_json("cachedMatchingFilesNodeName", cached_matching_files_node_name, "string"); dat .= add_json("numberOfMatchedFiles", number_of_matched_files, "int"); dat .= add_json("label", label, "string"); dat .= add_json("files", files_dat, "obj"); dat = close_json(dat); dat; ));