Compare commits

...

28 commits
0.11 ... 0.17

Author SHA1 Message Date
94b231f74b Upgrade log4j libs from 2.17.1 to 2.23.1. 2024-08-21 16:36:40 +02:00
474a13b7e2 Cleaned code and Javadoc. 2024-08-18 23:34:02 +02:00
08e6071876 Improved HtmlCache class. 2024-08-18 22:37:29 +02:00
5e807b5200 Added KissDispatcher Processor setting in Ant script. 2024-08-18 22:37:10 +02:00
dd682a6b0a Made a Javadoc review. 2024-08-18 22:36:23 +02:00
33252b83ab Added a first version of HtmlCache class. 2024-08-12 17:31:15 +02:00
f90a88521f Improved logs. 2024-08-12 17:30:53 +02:00
0017f5a84e Added clear caches features. 2024-08-12 14:23:22 +02:00
40fa91feb4 Added feature about annotation for KissDispatcher. 2024-08-12 03:35:46 +02:00
d872a7528b Fixed Java upgrade. 2024-08-12 03:34:22 +02:00
0f8d487c32 Removed not useful log. 2024-08-12 03:33:34 +02:00
4e95cbd8ec Set explicitly UTF-8 as the project encoding. 2024-08-12 03:32:59 +02:00
1996d2f719 Refactored hugely hooks, added hook cache and servlet cache. 2024-08-08 17:23:52 +02:00
74ee23a382 Added RewriteHook. 2024-07-26 19:34:07 +02:00
c1603461f0 Upgraded log4j libs. 2024-07-26 19:33:39 +02:00
78f16db8f0 Build 0.17.1 2023-12-01 05:27:08 +01:00
5b096f4d79 Fixed FolderHook. 2023-12-01 05:26:38 +01:00
3a79d8e214 Build 0.17.0 2023-11-29 16:26:06 +01:00
67a2993cf5 Migrated to Tomcat 10.1. Improved code, Javadoc, doc, process… 2023-11-29 16:25:42 +01:00
02a8c54cb6 Javadoc review. 2023-11-28 03:28:49 +01:00
590c99c19b Fixed Java 17 migration. 2023-11-28 02:22:43 +01:00
07d0eb52b2 Clean code. 2023-11-28 00:38:36 +01:00
bac5b466b3 Improved Hooks. 2023-11-27 23:34:07 +01:00
eeba80d4b2 Removed unuseful devinsy-xml lib. 2023-11-27 19:24:54 +01:00
1ed5d0d029 Upgraded xidyn lib to 1.17.0. 2023-11-27 19:23:32 +01:00
f1d20d7c75 Upgraded devinsy-strings lib to 0.17.0. 2023-11-27 19:15:14 +01:00
99595ca81b Configured new version 0.17, Java 17 and Tomcat 10.1. 2023-11-27 19:13:42 +01:00
3abef0d595 Upgraded commons-lang3 to 3.13.0. 2023-11-26 20:46:45 +01:00
110 changed files with 3017 additions and 1479 deletions

View file

@ -2,7 +2,7 @@
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/> <classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes> <attributes>
<attribute name="module" value="true"/> <attribute name="module" value="true"/>
<attribute name="owner.project.facets" value="java"/> <attribute name="owner.project.facets" value="java"/>
@ -11,21 +11,19 @@
<classpathentry kind="lib" path="lib/commons-codec-1.8.jar" sourcepath="lib/commons-codec-1.8-sources.jar"/> <classpathentry kind="lib" path="lib/commons-codec-1.8.jar" sourcepath="lib/commons-codec-1.8-sources.jar"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="lib" path="lib/commons-fileupload-1.3.jar" sourcepath="lib/commons-fileupload-1.3-sources.jar"/> <classpathentry kind="lib" path="lib/commons-fileupload-1.3.jar" sourcepath="lib/commons-fileupload-1.3-sources.jar"/>
<classpathentry kind="lib" path="lib/commons-lang3-3.1.jar" sourcepath="lib/commons-lang3-3.1-sources.jar"/>
<classpathentry kind="lib" path="lib/UnitTesting/hamcrest-core-1.3.jar" sourcepath="lib/UnitTesting/hamcrest-core-1.3-sources.jar"/> <classpathentry kind="lib" path="lib/UnitTesting/hamcrest-core-1.3.jar" sourcepath="lib/UnitTesting/hamcrest-core-1.3-sources.jar"/>
<classpathentry kind="lib" path="lib/UnitTesting/junit-4.12.jar" sourcepath="lib/UnitTesting/junit-4.12-sources.jar"/> <classpathentry kind="lib" path="lib/UnitTesting/junit-4.12.jar" sourcepath="lib/UnitTesting/junit-4.12-sources.jar"/>
<classpathentry kind="lib" path="lib/devinsy-strings-0.11.4.jar" sourcepath="lib/devinsy-strings-0.11.4-sources.zip"/> <classpathentry kind="lib" path="lib/commons-io-2.7.jar" sourcepath="lib/commons-io-2.7-sources.jar"/>
<classpathentry kind="lib" path="lib/tomcat9-servlet-api-9.0.31.jar" sourcepath="lib/tomcat9-servlet-api-9.0.31-sources.jar"/> <classpathentry kind="lib" path="lib/commons-lang3-3.13.0.jar" sourcepath="lib/commons-lang3-3.13.0-sources.jar"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0.46"> <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/apache-tomcat-10.1.12">
<attributes> <attributes>
<attribute name="owner.project.facets" value="jst.utility"/> <attribute name="owner.project.facets" value="jst.utility"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="lib" path="lib/xidyn-1.11.2.jar" sourcepath="lib/xidyn-1.11.2-sources.zip"/> <classpathentry kind="lib" path="lib/devinsy-strings-0.17.0.jar" sourcepath="lib/devinsy-strings-0.17.0-sources.zip"/>
<classpathentry kind="lib" path="lib/commons-io-2.7.jar" sourcepath="lib/commons-io-2.7-sources.jar"/> <classpathentry kind="lib" path="lib/Logs/log4j-api-2.23.1.jar" sourcepath="lib/Logs/log4j-api-2.23.1-sources.jar"/>
<classpathentry kind="lib" path="lib/Logs/log4j-api-2.17.0.jar" sourcepath="lib/Logs/log4j-api-2.17.0-sources.jar"/> <classpathentry kind="lib" path="lib/Logs/log4j-core-2.23.1.jar" sourcepath="lib/Logs/log4j-core-2.23.1-sources.jar"/>
<classpathentry kind="lib" path="lib/Logs/log4j-core-2.17.0.jar" sourcepath="lib/Logs/log4j-core-2.17.0-sources.jar"/> <classpathentry kind="lib" path="lib/Logs/log4j-slf4j2-impl-2.23.1.jar" sourcepath="lib/Logs/log4j-slf4j2-impl-2.32.1-sources.jar"/>
<classpathentry kind="lib" path="lib/Logs/log4j-slf4j-impl-2.17.0.jar" sourcepath="lib/Logs/log4j-slf4j-impl-2.17.0-sources.jar"/> <classpathentry kind="lib" path="lib/Logs/slf4j-api-2.0.16.jar" sourcepath="lib/Logs/slf4j-api-2.0.16-sources.jar"/>
<classpathentry kind="lib" path="lib/Logs/slf4j-api-1.7.32.jar" sourcepath="lib/Logs/slf4j-api-1.7.32-sources.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View file

@ -0,0 +1,4 @@
eclipse.preferences.version=1
filter_fields=false
project_specific_settings=true
replacements=<?xml version\="1.0" standalone\="yes"?>\n\n<replacements>\n<replacement key\="get" scope\="1" mode\="0">Gets the</replacement>\n<replacement key\="set" scope\="1" mode\="0">Sets the</replacement>\n<replacement key\="add" scope\="1" mode\="0">Adds the</replacement>\n<replacement key\="edit" scope\="1" mode\="0">Edits the</replacement>\n<replacement key\="remove" scope\="1" mode\="0">Removes the</replacement>\n<replacement key\="init" scope\="1" mode\="0">Inits the</replacement>\n<replacement key\="parse" scope\="1" mode\="0">Parses the</replacement>\n<replacement key\="create" scope\="1" mode\="0">Creates the</replacement>\n<replacement key\="build" scope\="1" mode\="0">Builds the</replacement>\n<replacement key\="is" scope\="1" mode\="0">Checks if is</replacement>\n<replacement key\="print" scope\="1" mode\="0">Prints the</replacement>\n<replacement key\="has" scope\="1" mode\="0">Checks for</replacement>\n</replacements>\n\n

View file

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -1,9 +1,9 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=11 org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@ -12,9 +12,10 @@ org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11 org.eclipse.jdt.core.compiler.source=17
org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647 org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
org.eclipse.jdt.core.formatter.align_selector_in_method_invocation_on_expression_first_line=false
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false
org.eclipse.jdt.core.formatter.align_with_spaces=false org.eclipse.jdt.core.formatter.align_with_spaces=false
@ -42,6 +43,8 @@ org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=49 org.eclipse.jdt.core.formatter.alignment_for_enum_constants=49
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_switch_case_with_arrow=0
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_switch_case_with_colon=0
org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16 org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_module_statements=16 org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
@ -50,6 +53,7 @@ org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0 org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_permitted_types_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_record_components=16 org.eclipse.jdt.core.formatter.alignment_for_record_components=16
org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0 org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80 org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
@ -60,6 +64,7 @@ org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_switch_case_with_arrow=0
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0 org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0
@ -111,6 +116,7 @@ org.eclipse.jdt.core.formatter.comment.indent_tag_description=false
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=do not insert org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=do not insert
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
org.eclipse.jdt.core.formatter.comment.javadoc_do_not_separate_block_tags=false
org.eclipse.jdt.core.formatter.comment.line_length=80 org.eclipse.jdt.core.formatter.comment.line_length=80
org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
@ -190,6 +196,7 @@ org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arg
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_permitted_types=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert
@ -281,6 +288,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_ar
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_permitted_types=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert
@ -364,6 +372,8 @@ org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false
org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false
org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false
org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false
org.eclipse.jdt.core.formatter.keep_switch_body_block_on_one_line=one_line_never
org.eclipse.jdt.core.formatter.keep_switch_case_with_arrow_on_one_line=one_line_never
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never
org.eclipse.jdt.core.formatter.lineSplit=150 org.eclipse.jdt.core.formatter.lineSplit=150
@ -404,5 +414,6 @@ org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true
org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true
org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
org.eclipse.jdt.core.formatter.wrap_before_switch_case_arrow_operator=false
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter

View file

@ -8,6 +8,7 @@ cleanup.add_missing_nls_tags=false
cleanup.add_missing_override_annotations=true cleanup.add_missing_override_annotations=true
cleanup.add_missing_override_annotations_interface_methods=true cleanup.add_missing_override_annotations_interface_methods=true
cleanup.add_serial_version_id=true cleanup.add_serial_version_id=true
cleanup.also_simplify_lambda=true
cleanup.always_use_blocks=true cleanup.always_use_blocks=true
cleanup.always_use_parentheses_in_expressions=false cleanup.always_use_parentheses_in_expressions=false
cleanup.always_use_this_for_non_static_field_access=true cleanup.always_use_this_for_non_static_field_access=true
@ -27,6 +28,7 @@ cleanup.convert_to_enhanced_for_loop=false
cleanup.convert_to_enhanced_for_loop_if_loop_var_used=true cleanup.convert_to_enhanced_for_loop_if_loop_var_used=true
cleanup.convert_to_switch_expressions=false cleanup.convert_to_switch_expressions=false
cleanup.correct_indentation=false cleanup.correct_indentation=false
cleanup.do_while_rather_than_while=true
cleanup.double_negation=false cleanup.double_negation=false
cleanup.else_if=false cleanup.else_if=false
cleanup.embedded_if=false cleanup.embedded_if=false
@ -60,6 +62,7 @@ cleanup.one_if_rather_than_duplicate_blocks_that_fall_through=true
cleanup.operand_factorization=false cleanup.operand_factorization=false
cleanup.organize_imports=false cleanup.organize_imports=false
cleanup.overridden_assignment=false cleanup.overridden_assignment=false
cleanup.overridden_assignment_move_decl=true
cleanup.plain_replacement=false cleanup.plain_replacement=false
cleanup.precompile_regex=false cleanup.precompile_regex=false
cleanup.primitive_comparison=false cleanup.primitive_comparison=false
@ -89,6 +92,7 @@ cleanup.remove_unnecessary_casts=true
cleanup.remove_unnecessary_nls_tags=true cleanup.remove_unnecessary_nls_tags=true
cleanup.remove_unused_imports=true cleanup.remove_unused_imports=true
cleanup.remove_unused_local_variables=false cleanup.remove_unused_local_variables=false
cleanup.remove_unused_method_parameters=false
cleanup.remove_unused_private_fields=true cleanup.remove_unused_private_fields=true
cleanup.remove_unused_private_members=false cleanup.remove_unused_private_members=false
cleanup.remove_unused_private_methods=true cleanup.remove_unused_private_methods=true
@ -101,7 +105,11 @@ cleanup.sort_members_all=false
cleanup.standard_comparison=false cleanup.standard_comparison=false
cleanup.static_inner_class=false cleanup.static_inner_class=false
cleanup.strictly_equal_or_different=false cleanup.strictly_equal_or_different=false
cleanup.stringbuffer_to_stringbuilder=false
cleanup.stringbuilder=false cleanup.stringbuilder=false
cleanup.stringbuilder_for_local_vars=true
cleanup.stringconcat_stringbuffer_stringbuilder=false
cleanup.stringconcat_to_textblock=false
cleanup.substring=false cleanup.substring=false
cleanup.switch=false cleanup.switch=false
cleanup.system_property=false cleanup.system_property=false
@ -136,10 +144,11 @@ cleanup_settings_version=2
eclipse.preferences.version=1 eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_Kiss4web formatter_profile=_Kiss4web
formatter_settings_version=21 formatter_settings_version=23
jautodoc.cleanup.add_header=false jautodoc.cleanup.add_header=false
jautodoc.cleanup.javadoc=false jautodoc.cleanup.javadoc=false
jautodoc.cleanup.replace_header=false jautodoc.cleanup.replace_header=false
org.eclipse.jdt.ui.text.custom_code_templates=
sp_cleanup.add_default_serial_version_id=true sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true sp_cleanup.add_missing_annotations=true

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<faceted-project> <faceted-project>
<runtime name="Apache Tomcat v9.0.46"/> <runtime name="apache-tomcat-10.1.12"/>
<fixed facet="java"/> <fixed facet="java"/>
<fixed facet="jst.utility"/> <fixed facet="jst.utility"/>
<installed facet="jst.utility" version="1.0"/> <installed facet="jst.utility" version="1.0"/>
<installed facet="java" version="11"/> <installed facet="java" version="17"/>
</faceted-project> </faceted-project>

116
README.md
View file

@ -13,9 +13,17 @@ Kiss4web builds on:
- KissDispatcher: call the good Java Servlet for each HTTP request, - KissDispatcher: call the good Java Servlet for each HTTP request,
- Xidyn: a template solution to dynamize HTML sources. - Xidyn: a template solution to dynamize HTML sources.
## Author
Lead developer: Christian Pierre MOMON <christian.momon@devinsy.fr>
## License
Kiss4web is released under the GNU LGPL license.
## Developing environment ## Developing environment
Kiss4web-demo project uses strictly Eclipse Kepler, Java 6, GIT. Kiss4web project uses strictly Eclipse 4.29, Java 17, tomcat 10.1 and Git.
## Build ## Build
@ -26,7 +34,109 @@ Kiss4web uses Ant and generates a kiss4web-x.y.z folder which contains:
- x-core.jar : only compiled class without any library. - x-core.jar : only compiled class without any library.
- x-core-source.jar : sources. - x-core-source.jar : sources.
## Dependencies
# License The kiss4web jar requires:
- commons-io
- commons-lang3
- devinsy-strings
Kiss4web is released under the GNU LGPL license. ## Usages
```
B --> FooAppLauncher -------------------------> FooApp
[ServletContextListener] [Singleton]
|
| setMode(Mode.OPEN)
\ /
A --> Kiss4webLauncher ----setMode(Mode.OPEN)---> Kiss4web <Mode.APP_INIT>
[ServletContextListener] [Singleton]
```
KissDispatcher is initialized with Mode.APP_INIT.
### Usage A: default
The easier way, in case you have no application initialization step. The Kiss4webLauncher set a default log4j2 configuration and set the KissDispatcher to Mode.OPEN state with a default set of hooks.
Edit `…/WebContent/WEB-INF/web.xml` :
```
<listener>
<listener-class>fr.devinsy.kiss4web.Kiss4webLauncher</listener-class>
</listener>
<servlet>
<servlet-name>Application dispatcher</servlet-name>
<servlet-class>fr.devinsy.kiss4web.dispatcher.KissDispatcher</servlet-class>
<init-param>
<param-name>webClassesRootPackage</param-name>
<param-value>website</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Application dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
```
You can create …/WebContent/WEB-INF/log4j2.properties:
```
# Log configuration
# #################
# priority setting: DEBUG < INFO < WARN < ERROR
name = Log4j2 Properties Config
status = ERROR
dest = err
# Logger settings.
rootLogger.level = INFO
rootLogger.appenderRefs = a, b
rootLogger.appenderRef.a.ref = CONSOLE
rootLogger.appenderRef.b.ref = LOGFILE
logger.statoolinfos.name = fr.devinsy.statoolinfos
logger.statoolinfos.level = INFO
logger.xidyn.name = fr.devinsy.xidyn
logger.xidyn.level = WARN
# Appenders settings.
appenders = CONSOLE, LOGFILE
appender.CONSOLE.type = Console
appender.CONSOLE.name = CONSOLE
appender.CONSOLE.layout.type = PatternLayout
appender.CONSOLE.layout.pattern = %d{ISO8601} - FooApp [%-5p] %34.34c.%25M - %m%n
appender.LOGFILE.type = File
appender.LOGFILE.name = LOGFILE
appender.LOGFILE.filename = /srv/fooapp/rslisi.log
appender.LOGFILE.layout.type = PatternLayout
appender.LOGFILE.layout.pattern = %d{ISO8601} - FooApp [%-5p] %34.34c.%25M - %m%n
```
### Usage B: custom init
If you want manage an application initialization step, do not use the Kiss4webLauncher as class listener. Create your own FooAppLauncher and make it calls `Kiss4web.instance().setMode(Mode.OPEN)` when the init step is over.
Edit `…/WebContent/WEB-INF/web.xml` :
```
<listener>
<listener-class>org.foo.app.FooAppLauncher</listener-class>
</listener>
<servlet>
<servlet-name>Application dispatcher</servlet-name>
<servlet-class>fr.devinsy.kiss4web.dispatcher.KissDispatcher</servlet-class>
<init-param>
<param-name>webClassesRootPackage</param-name>
<param-value>website</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Application dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
```

View file

@ -110,6 +110,7 @@
<attribute name="Built-By" value="${user.name} using ant" /> <attribute name="Built-By" value="${user.name} using ant" />
<attribute name="Built-Date" value="${dist.time}" /> <attribute name="Built-Date" value="${dist.time}" />
</manifest> </manifest>
<service type="javax.annotation.processing.Processor" provider="fr.devinsy.kiss4web.dispatcher.annotation.KissServletProcessor" />
<fileset dir="${build.classes}" /> <fileset dir="${build.classes}" />
</jar> </jar>

View file

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Wed Sep 21 14:25:05 CEST 2016 #Fri Dec 01 05:27:08 CET 2023
build.number=1 build.number=2

View file

@ -1,3 +1,3 @@
product.name=kiss4web product.name=kiss4web
product.revision.major=0 product.revision.major=0
product.revision.minor=3 product.revision.minor=17

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2013-2021 Christian Pierre MOMON * Copyright (C) 2013-2023 Christian Pierre MOMON
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -74,43 +74,80 @@ public class BuildInformation
} }
} }
/**
* Author.
*
* @return the string
*/
public String author() public String author()
{ {
return this.author; return this.author;
} }
/**
* Builds the date.
*
* @return the string
*/
public String buildDate() public String buildDate()
{ {
return this.buildDate; return this.buildDate;
} }
/**
* Builds the number.
*
* @return the string
*/
public String buildNumber() public String buildNumber()
{ {
return this.buildNumber; return this.buildNumber;
} }
/**
* Generator.
*
* @return the string
*/
public String generator() public String generator()
{ {
return this.generator; return this.generator;
} }
/**
* Major revision.
*
* @return the string
*/
public String majorRevision() public String majorRevision()
{ {
return this.majorRevision; return this.majorRevision;
} }
/**
* Minor revision.
*
* @return the string
*/
public String minorRevision() public String minorRevision()
{ {
return this.minorRevision; return this.minorRevision;
} }
/**
* Product name.
*
* @return the string
*/
public String productName() public String productName()
{ {
return this.productName; return this.productName;
} }
/** /**
* To string.
* *
* @return the string
*/ */
@Override @Override
public String toString() public String toString()
@ -125,8 +162,9 @@ public class BuildInformation
} }
/** /**
* Version.
* *
* @return * @return the string
*/ */
public String version() public String version()
{ {

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -20,13 +20,13 @@ package fr.devinsy.kiss4web;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/** /**
* The Class CookieHelper. * The Class CookieHelper.
*/ */

View file

@ -80,11 +80,11 @@ public class EnvironmentInformation
try try
{ {
result = (String) this.environment.lookup("kiss4web.log4j.path"); result = (String) this.environment.lookup("kiss4web.log4j2.path");
} }
catch (NamingException exception) catch (NamingException exception)
{ {
throw new ConfigurationException("Context configuration error on log4j path."); throw new ConfigurationException("Context configuration error on log4j2 path.");
} }
// //

View file

@ -0,0 +1,200 @@
/*
* Copyright (C) 2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web;
import java.util.HashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.strings.StringList;
import jakarta.servlet.http.HttpServletRequest;
/**
* The Class HtmlCache.
*/
public class HtmlCache extends HashMap<String, String>
{
private static final long serialVersionUID = -310354977854681838L;
private static Logger logger = LoggerFactory.getLogger(HtmlCache.class);
/**
* Instantiates a new html cache.
*/
public HtmlCache()
{
super();
}
/**
* Builds the key.
*
* @param object
* the object
* @param strings
* the strings
* @return the string
*/
public String buildKey(final Object object, final String... strings)
{
String result;
if (object == null)
{
result = null;
}
else
{
result = buildKey(object.getClass().getCanonicalName(), strings);
}
//
return result;
}
/**
* Builds the key.
*
* @param main
* the main
* @param strings
* the strings
* @return the string
*/
public String buildKey(final String main, final String... strings)
{
String result;
if (main == null)
{
result = null;
}
else
{
int capacity = strings.length * 2 + 1;
StringList buffer = new StringList(capacity);
buffer.add(main);
for (int index = 0; index < strings.length; index++)
{
buffer.append('#');
buffer.append(index);
buffer.append(strings[index]);
}
result = buffer.toString();
}
//
return result;
}
/**
* Gets the HTML code using a GET request.
*
* @param request
* the request
* @return the string
*/
public String get(final HttpServletRequest request)
{
String result;
if (request == null)
{
result = null;
}
else
{
String key = request.getPathInfo();
if (request.getQueryString() != null)
{
key = key + "?" + request.getQueryString();
}
result = super.get(key);
if (result != null)
{
logger.info("HTML CACHE MATCHED: [{}]", key);
}
}
//
return result;
}
/**
* Gets the.
*
* @param key
* the key
* @return the string
*/
public String get(final String key)
{
String result;
if (key == null)
{
result = null;
}
else
{
result = super.get(key);
if (result != null)
{
logger.info("HTML Cache matched: [{}]", key);
}
}
//
return result;
}
/**
* Put HTML code using a GET request.
*
* @param html
* the html
* @param request
* the request
* @return the string
*/
public String put(final HttpServletRequest request, final String html)
{
String result;
if ((request == null) || (html == null))
{
result = null;
}
else
{
String key = request.getPathInfo();
if (request.getQueryString() != null)
{
key = key + "?" + request.getQueryString();
}
result = super.put(key, html);
}
//
return result;
}
}

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2013-2021 Christian Pierre MOMON * Copyright (C) 2013-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -23,7 +23,6 @@ import java.util.Date;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import fr.devinsy.kiss4web.dispatcher.KissDispatcher; import fr.devinsy.kiss4web.dispatcher.KissDispatcher;
import fr.devinsy.kiss4web.dispatcher.KissDispatcherFactory;
import fr.devinsy.kiss4web.dispatcher.hooks.ApplicationInitFailedHook; import fr.devinsy.kiss4web.dispatcher.hooks.ApplicationInitFailedHook;
import fr.devinsy.kiss4web.dispatcher.hooks.ApplicationInitHook; import fr.devinsy.kiss4web.dispatcher.hooks.ApplicationInitHook;
import fr.devinsy.kiss4web.dispatcher.hooks.BlankHook; import fr.devinsy.kiss4web.dispatcher.hooks.BlankHook;
@ -53,8 +52,8 @@ public class Kiss4web
{ {
INIT, INIT,
INIT_FAILED, INIT_FAILED,
APPLICATION_INIT, APP_INIT,
APPLICATION_INIT_FAILED, APP_INIT_FAILED,
OPEN, OPEN,
MAINTENANCE, MAINTENANCE,
FATAL, FATAL,
@ -79,7 +78,7 @@ public class Kiss4web
try try
{ {
// //
this.mode = Mode.INIT; setMode(Mode.INIT);
// //
currentLog = "Kiss4web"; currentLog = "Kiss4web";
@ -97,8 +96,8 @@ public class Kiss4web
// //
// //
setMode(Mode.APPLICATION_INIT); setMode(Mode.APP_INIT);
logInit("set APPLICATION INIT mode", "PASSED"); logInit("set APP INIT mode", "PASSED");
// //
currentLog = "Kiss4web"; currentLog = "Kiss4web";
@ -146,6 +145,12 @@ public class Kiss4web
switch (mode) switch (mode)
{ {
case INIT: case INIT:
{
if (this.mode == null)
{
this.mode = Mode.INIT;
}
}
break; break;
case INIT_FAILED: case INIT_FAILED:
@ -155,50 +160,53 @@ public class Kiss4web
this.mode = mode; this.mode = mode;
HookRegister hooks = new HookRegister("Init failed"); HookRegister hooks = new HookRegister("Init failed");
hooks.register(new InitFailedHook()); hooks.register(new InitFailedHook());
KissDispatcher.setHookRegister(hooks); KissDispatcher.instance().setHookRegister(hooks);
} }
} }
break; break;
case APPLICATION_INIT: case APP_INIT:
{ {
if (this.mode == Mode.INIT) if (this.mode == Mode.INIT)
{ {
this.mode = mode; this.mode = mode;
HookRegister hooks = new HookRegister("Application Init"); HookRegister hooks = new HookRegister("Application Init");
hooks.register(new ApplicationInitHook()); hooks.register(new ApplicationInitHook());
KissDispatcher.setHookRegister(hooks); KissDispatcher.instance().setHookRegister(hooks);
} }
} }
break; break;
case APPLICATION_INIT_FAILED: case APP_INIT_FAILED:
{ {
if (this.mode == Mode.APPLICATION_INIT_FAILED) if (this.mode == Mode.APP_INIT)
{ {
this.mode = mode; this.mode = mode;
HookRegister hooks = new HookRegister("Application Init failed"); HookRegister hooks = new HookRegister("Application Init failed");
hooks.register(new ApplicationInitFailedHook()); hooks.register(new ApplicationInitFailedHook());
KissDispatcher.setHookRegister(hooks); KissDispatcher.instance().setHookRegister(hooks);
} }
} }
break; break;
case OPEN: case OPEN:
{ {
this.mode = mode; if ((this.mode == Mode.APP_INIT) || (this.mode == Mode.MAINTENANCE))
{
this.mode = mode;
HookRegister hooks = new HookRegister("Open"); HookRegister hooks = new HookRegister("Open");
hooks.register(new BlankHook()); hooks.register(new BlankHook());
hooks.register(new RootHook()); hooks.register(new RootHook());
hooks.register(new LongURLHook()); hooks.register(new LongURLHook());
hooks.register(new FolderHook()); hooks.register(new FolderHook());
hooks.register(new ShortURLHook()); hooks.register(new ShortURLHook());
hooks.register(new XHTMLHook()); hooks.register(new XHTMLHook());
hooks.register(new WebContentHook()); hooks.register(new WebContentHook());
hooks.register(new WebInfHook()); hooks.register(new WebInfHook());
KissDispatcher.setHookRegister(hooks); KissDispatcher.instance().setHookRegister(hooks);
}
} }
break; break;
@ -209,7 +217,7 @@ public class Kiss4web
HookRegister hooks = new HookRegister("Maintenance"); HookRegister hooks = new HookRegister("Maintenance");
hooks.register(new MaintenanceHook()); hooks.register(new MaintenanceHook());
KissDispatcher.setHookRegister(hooks); KissDispatcher.instance().setHookRegister(hooks);
} }
break; break;
@ -220,19 +228,25 @@ public class Kiss4web
HookRegister hooks = new HookRegister("Fatal"); HookRegister hooks = new HookRegister("Fatal");
hooks.register(new FatalHook()); hooks.register(new FatalHook());
KissDispatcher.setHookRegister(hooks); KissDispatcher.instance().setHookRegister(hooks);
} }
break; break;
case CUSTOM: case CUSTOM:
if ((this.mode == Mode.APP_INIT) || (this.mode == Mode.MAINTENANCE) || (this.mode == Mode.OPEN))
{
this.mode = mode;
}
break; break;
default:
} }
} }
/** /**
* Sets the mode custom. * Sets the mode custom.
* *
* @param register * @param hooks
* the new mode custom * the new mode custom
*/ */
public void setModeCustom(final HookRegister hooks) public void setModeCustom(final HookRegister hooks)
@ -240,7 +254,7 @@ public class Kiss4web
if (hooks != null) if (hooks != null)
{ {
this.mode = Mode.CUSTOM; this.mode = Mode.CUSTOM;
KissDispatcher.setHookRegister(hooks); KissDispatcher.instance().setHookRegister(hooks);
} }
} }

View file

@ -0,0 +1,71 @@
/*
* Copyright (C) 2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web;
/**
* The Class Kiss4webException.
*/
public class Kiss4webException extends Exception
{
private static final long serialVersionUID = -6018571288000296858L;
/**
* Instantiates a new kiss 4 web exception.
*/
public Kiss4webException()
{
super();
}
/**
* Instantiates a new kiss 4 web exception.
*
* @param message
* the message
*/
public Kiss4webException(final String message)
{
super(message);
}
/**
* Instantiates a new kiss 4 web exception.
*
* @param message
* the message
* @param cause
* the cause
*/
public Kiss4webException(final String message, final Throwable cause)
{
super(message, cause);
}
/**
* Instantiates a new kiss 4 web exception.
*
* @param cause
* the cause
*/
public Kiss4webException(final Throwable cause)
{
super(cause);
}
}

View file

@ -1,28 +1,26 @@
/* /*
* Copyright (C) 2021 Christian Pierre MOMON <christian.momon@devinsy.fr> * Copyright (C) 2013-2024 Christian Pierre MOMON <christian.momon@devinsy.fr>
* *
* This file is part of Juga, simple key value database. * This file is part of Kiss4web.
* *
* Juga is free software: you can redistribute it and/or modify * Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Lesser General Public License as published by
* published by the Free Software Foundation, either version 3 of the * the Free Software Foundation, either version 3 of the License, or
* License, or (at your option) any later version. * (at your option) any later version.
* *
* Juga is distributed in the hope that it will be useful, * Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Juga. If not, see <http://www.gnu.org/licenses/>. * along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/ */
package fr.devinsy.kiss4web; package fr.devinsy.kiss4web;
import java.io.File; import java.io.File;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.core.config.Configurator; import org.apache.logging.log4j.core.config.Configurator;
@ -30,24 +28,48 @@ import org.apache.logging.log4j.core.config.DefaultConfiguration;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.Kiss4web.Mode;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
/** /**
* The Class JugaWebLauncher. * The Class Kiss4WebLauncher.
*
* The Context element represents a web application. If you have implemented a
* Java object that needs to know when this Context is started or stopped, you
* can declare it by nesting a Listener element inside this element.
*/ */
public class Kiss4webLauncher implements javax.servlet.ServletContextListener public class Kiss4webLauncher implements ServletContextListener
{ {
private static Logger logger = LoggerFactory.getLogger(Kiss4webLauncher.class); private static Logger logger = LoggerFactory.getLogger(Kiss4webLauncher.class);
/* (non-Javadoc) /**
* @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) * {@inheritDoc}
*/
@Override
public void contextDestroyed(final ServletContextEvent sce)
{
}
/**
* {@inheritDoc}
*/ */
@Override @Override
public void contextInitialized(final ServletContextEvent event) public void contextInitialized(final ServletContextEvent event)
{ {
launch(event.getServletContext()); System.out.println("========= KISS4WEB WEBAPP LAUNCHING… ==========");
ServletContext context = event.getServletContext();
initLogger(context.getRealPath("/"));
Kiss4web.instance().setMode(Mode.OPEN);
System.out.println("========= KISS4WEB WEBAPP LAUNCHED ==========");
} }
/** /**
* Inits the logger. * Inits the logger.
*
* @param webappRoot
* the webapp root
*/ */
public void initLogger(final String webappRoot) public void initLogger(final String webappRoot)
{ {
@ -93,19 +115,4 @@ public class Kiss4webLauncher implements javax.servlet.ServletContextListener
logger.info("Log initialization done."); logger.info("Log initialization done.");
} }
} }
/**
* Launch.
*
* @param context
* the context
*/
public void launch(final ServletContext context)
{
System.out.println("========= KISS4WEB WEBAPP LAUNCHING… ==========");
initLogger(context.getRealPath("/"));
Kiss4web.instance();
System.out.println("========= KISS4WEB WEBAPP LAUNCHED ==========");
}
} }

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *

View file

@ -1,43 +1,28 @@
/** /**
* Copyright 2021 Christian Pierre MOMON, DEVINSY, UMR 7186 LESC. * Copyright (C) 2021-2023 Christian Pierre MOMON
* *
* christian.momon@devinsy.fr * This file is part of Kiss4web.
* *
* This file is part of Kiwa. This software (Kiwa) is a computer program whose * Kiss4web is free software: you can redistribute it and/or modify
* purpose is to be the Kinsources Web Application, an open interactive platform * it under the terms of the GNU Lesser General Public License as published by
* for archiving, sharing, analyzing and comparing kinship data used in * the Free Software Foundation, either version 3 of the License, or
* scientific inquiry. * (at your option) any later version.
* *
* This software is governed by the CeCILL license under French law and abiding * Kiss4web is distributed in the hope that it will be useful,
* by the rules of distribution of free software. You can use, modify and/ or * but WITHOUT ANY WARRANTY; without even the implied warranty of
* redistribute the software under the terms of the CeCILL license as circulated * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". * GNU Lesser General Public License for more details.
* *
* As a counterpart to the access to the source code and rights to copy, modify * You should have received a copy of the GNU Lesser General Public License
* and redistribute granted by the license, users are provided only with a * along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
* limited warranty and the software's author, the holder of the economic
* rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated with
* loading, using, modifying and/or developing or reproducing the software by
* the user in light of its specific status of free software, that may mean that
* it is complicated to manipulate, and that also therefore means that it is
* reserved for developers and experienced professionals having in-depth
* computer knowledge. Users are therefore encouraged to load and test the
* software's suitability as regards their requirements in conditions enabling
* the security of their systems and/or data to be ensured and, more generally,
* to use and operate it in the same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/ */
package fr.devinsy.kiss4web; package fr.devinsy.kiss4web;
import java.io.IOException; import java.io.IOException;
import javax.servlet.ServletException; import jakarta.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
/** /**
* The Class Page. * The Class Page.
@ -50,22 +35,46 @@ public abstract class Page
private HttpServletRequest request; private HttpServletRequest request;
private HttpServletResponse response; private HttpServletResponse response;
/**
* Instantiates a new page.
*
* @param request
* the request
* @param response
* the response
* @throws ServletException
* the servlet exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public Page(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException public Page(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException
{ {
this.request = request; this.request = request;
this.response = response; this.response = response;
} }
/**
* Do get.
*/
public void doGet() public void doGet()
{ {
} }
/**
* Do post.
*/
public void doPost() public void doPost()
{ {
} }
/**
* Redirect.
*
* @param urlPath
* the url path
*/
public void redirect(final String urlPath) public void redirect(final String urlPath)
{ {
Redirector.redirect(this.response, urlPath); Redirector.redirect(this.response, urlPath);

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/> * along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/ */
package fr.devinsy.kiss4web.dispatcher; package fr.devinsy.kiss4web;
import java.util.HashMap; import java.util.HashMap;
@ -24,17 +24,17 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class KissClassCache. * The Class PageCache.
*/ */
public class KissDispatcherCache2 extends HashMap<String, String> public class PageCache extends HashMap<String, String>
{ {
private static final long serialVersionUID = 2058060444094070931L; private static final long serialVersionUID = 6600633944028794039L;
private static Logger logger = LoggerFactory.getLogger(KissDispatcherCache2.class); private static Logger logger = LoggerFactory.getLogger(PageCache.class);
/** /**
* Instantiates a new kiss class cache. * Instantiates a new kiss page cache.
*/ */
public KissDispatcherCache2() public PageCache()
{ {
super(); super();
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,11 +18,11 @@
*/ */
package fr.devinsy.kiss4web; package fr.devinsy.kiss4web;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.servlet.http.HttpServletResponse;
/** /**
* The Class Redirector. * The Class Redirector.
*/ */
@ -42,6 +42,11 @@ public class Redirector
this.statusCode = value; this.statusCode = value;
} }
/**
* Status code.
*
* @return the int
*/
public int statusCode() public int statusCode()
{ {
int result; int result;
@ -63,8 +68,6 @@ public class Redirector
*/ */
public static void redirect(final HttpServletResponse response, final String destination) public static void redirect(final HttpServletResponse response, final String destination)
{ {
logger.info("Redirect to <" + destination + ">");
redirect(response, destination, Type.MOVED_TEMPORARILY); redirect(response, destination, Type.MOVED_TEMPORARILY);
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2023 Christian Pierre MOMON
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,14 +18,13 @@
*/ */
package fr.devinsy.kiss4web; package fr.devinsy.kiss4web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringList;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/** /**
* The Class SimpleSecurityAgent. * The Class SimpleSecurityAgent.

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,186 +18,120 @@
*/ */
package fr.devinsy.kiss4web.dispatcher; package fr.devinsy.kiss4web.dispatcher;
import java.io.IOException;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.dispatcher.annotation.AnnotationHooks;
import fr.devinsy.kiss4web.dispatcher.annotation.AnnotationUtils;
import fr.devinsy.kiss4web.dispatcher.hooks.ErrorServlet;
import fr.devinsy.kiss4web.dispatcher.hooks.Hook; import fr.devinsy.kiss4web.dispatcher.hooks.Hook;
import fr.devinsy.kiss4web.dispatcher.hooks.HookRegister; import fr.devinsy.kiss4web.dispatcher.hooks.HookRegister;
import fr.devinsy.kiss4web.dispatcher.hooks.InitHook; import fr.devinsy.kiss4web.dispatcher.hooks.InitHook;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
/** /**
* The Class KissDispatcher. * The Class KissDispatcher.
* *
* According that URL is under UTF-8 format. Set Tomcat connector if needs * According that URL is under UTF-8 format. Set Tomcat connector if needs
* (<connector URIEncoding="UTF-8" />).
* *
* <pre>
* <connector URIEncoding="UTF-8" />.
* </pre>
*/ */
public class KissDispatcher extends HttpServlet public class KissDispatcher
{ {
private static final long serialVersionUID = -3471226305721330069L;
private static final Logger logger = LoggerFactory.getLogger(KissDispatcher.class); private static final Logger logger = LoggerFactory.getLogger(KissDispatcher.class);
public static final int DEFAULT_CACHE_AGE = 2 * 60 * 60; public static final int DEFAULT_CACHE_AGE = 2 * 60 * 60;
private static HookRegister hookRegister = new HookRegister("Init").register(new InitHook()); private static KissDispatcher instance = new KissDispatcher();
private HookRegister hookRegister;
// Pathinfo -> Servlet.
private ServletCache cache;
private AnnotationHooks annotationHooks;
/** /**
* Instantiates a new kiss dispatcher. * Instantiates a new kiss dispatcher.
*/ */
public KissDispatcher() private KissDispatcher()
{ {
this.cache = new ServletCache();
this.hookRegister = new HookRegister("Init").register(new InitHook());
this.annotationHooks = AnnotationUtils.getAnnotationHooks();
} }
/** /**
* <pre> * Clear.
* "/" => "Index_xhtml" */
* "/good/" => "good.Good_xhtml" public void clear()
* "/good/morning.xhtml" => "good.Morning_xhtml" {
* "/good/morning_girl.xhtml" => "good.Morning_girl_xhtml" this.cache.clear();
* "/good/morning-123.xhtml" => "good.Morning_xhtml" ('123' is detected as a parameter, it will be logger.info("KissDispatcher PATHINFO Cache: CLEARED");
* decoded in the class called later). KissDispatcherFactory.instance().clearCache();
* "/good/morning-/12/toto.jpg" => "good.Morning" ('12' and 'toto.jpg" are detected as a parameter, they }
* will be decoded in the class called later).
* </pre> /**
* Gets the annotation hooks.
* *
* @return the annotation hooks
*/ */
public void dispatch(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException public AnnotationHooks getAnnotationHooks()
{ {
long startTime = new Date().getTime(); return this.annotationHooks;
}
request.setCharacterEncoding("UTF-8"); /**
* Provide servlet.
*
* @param config
* the config
* @param request
* the request
* @return the http servlet
*/
public HttpServlet provideServlet(final ServletConfig config, final HttpServletRequest request)
{
HttpServlet result;
logger.info("=================================================="); try
logger.info("getContextPath=[" + request.getContextPath() + "]");
logger.info("getPathInfo=[" + request.getPathInfo() + "]");
logger.info("getPathTranslated=[" + request.getPathTranslated() + "]");
logger.info("getQueryString=[" + request.getQueryString() + "]");
logger.info("getRequestURI=[" + request.getRequestURI() + "]");
logger.info("getRequestURL=[" + request.getRequestURL() + "]");
logger.info("getServletPath=[" + request.getServletPath() + "]");
//
/*
* In past, possibility to use the servlet path was enable. It is too
* complexe, not kiss mind.
*
* String path;
* if (request.getPathInfo() == null)
* {
* // web.xml url-pattern= *.xhtml
* path = request.getServletPath();
* }
* else
* {
* // web.xml url-pattern =
* path = request.getPathInfo();
* }
*
* https://issues.apache.org/bugzilla/show_bug.cgi?id=11318
* A number of features have been introduced in later versions of Tomcat
* that relate to URI encoding. This includes a URIEncoding attribute
* on the Coyote HTTP/1.1 connector which defaults to ISO-8859-1.
*
* According to the servlet specification:
* HttpServletRequest.getPathInfo() should be decoded by the web container;
* HttpServletRequest.getRequestURI() should not be decoded by the web container.
*
*
* http://stackoverflow.com/questions/15278512/safe-html-form-accept-charset/15587140#15587140
* The standard URL encoding must use UTF-8 yet servlets not only default to ISO-8859-1 but don't offer
* any way to change that with code.
* Sure you can req.setRequestEncoding("UTF-8") before you read anything, but for some ungodly reason this only affects request body,
* not query string parameters. There is nothing in the servlet request interface to specify the encoding used for query string parameters.
* Using ISO-8859-1 in your form is a hack. Using this ancient encoding will cause more problems than solve for sure.
* Especially since browsers do not support ISO-8859-1 and always treat it as Windows-1252. Whereas servlets treat ISO-8859-1 as ISO-8859-1,
* so you will be screwed beyond belief if you go with this.
* To change this in Tomcat for example, you can use the URIEncoding attribute in your <connector> element:
* <connector ... URIEncoding="UTF-8" ... />
*
* If you don't use a container that has these settings, can't change its settings or some other issue,
* you can still make it work because ISO-8859-1 decoding retains full information from the original binary.
* String correct = new String(request.getParameter("test").getBytes("ISO-8859-1"), "UTF-8")
*
*
* http://tomcat.apache.org/tomcat-5.5-doc/config/http.html
* URIEncoding
* This specifies the character encoding used to decode the URI bytes, after %xx decoding the URL.
* If not specified, ISO-8859-1 will be used.
*
*/
// String urlPath = request.getPathInfo();
// Search a matching catcher.
Hook hook = hookRegister.getMatching(this.getServletContext(), request);
if (hook == null)
{ {
logger.info("Request not satisfied [" + request.getPathInfo() + "]"); result = this.cache.get(request.getPathInfo());
response.sendError(HttpServletResponse.SC_NOT_FOUND); if (result == null)
{
logger.debug("PathInfo is NOT matching servlet cache.");
Hook hook = this.hookRegister.getMatching(config.getServletContext(), request);
if (hook == null)
{
result = new ErrorServlet("Hook not found.");
}
else
{
logger.debug("Hook matching: {}", hook.getClass().getCanonicalName());
String servletClassName = hook.getServletClassName(config, request);
Class<HttpServlet> servletClass = KissDispatcherUtils.pickServletClass(servletClassName);
result = KissDispatcherFactory.instance().provideServlet(config, servletClass);
this.cache.put(request.getPathInfo(), result);
}
}
else
{
logger.debug("PathInfo is matching servlet cache [{}]", result.getClass().getCanonicalName());
}
} }
else catch (IllegalArgumentException | SecurityException | ServletException exception)
{ {
logger.info("Catch found for {}", hook.getClass().getSimpleName()); result = new ErrorServlet("Error instanciating servlet.", exception);
hook.process(this.getServletConfig(), this.getServletContext(), request, response);
} }
// //
long endTime = new Date().getTime(); return result;
logger.debug("TIME: {}ms {}", endTime - startTime, request.getPathInfo());
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doDelete(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void doDelete(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
dispatch(request, response);
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
dispatch(request, response);
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void doPost(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
dispatch(request, response);
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doPut(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void doPut(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
dispatch(request, response);
}
/* (non-Javadoc)
* @see javax.servlet.GenericServlet#init()
*/
@Override
public void init() throws ServletException
{
super.init();
System.out.println("KissDispatcher INIT.");
} }
/** /**
@ -206,14 +140,24 @@ public class KissDispatcher extends HttpServlet
* @param register * @param register
* the new hook register * the new hook register
*/ */
public static void setHookRegister(final HookRegister register) public void setHookRegister(final HookRegister register)
{ {
if ((register != null) && (!register.isEmpty())) if ((register != null) && (!register.isEmpty()))
{ {
HookRegister target = new HookRegister(register.getName()); HookRegister target = new HookRegister(register.getName());
target.registerAll(register); target.registerAll(register);
hookRegister = target; this.hookRegister = target;
KissDispatcherFactory.instance().clearCache(); KissDispatcherFactory.instance().clearCache();
} }
} }
/**
* Instance.
*
* @return the kiss dispatcher
*/
public static KissDispatcher instance()
{
return instance;
}
} }

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,169 +18,77 @@
*/ */
package fr.devinsy.kiss4web.dispatcher; package fr.devinsy.kiss4web.dispatcher;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
/** /**
* A factory for creating KissDispatcher objects. * A factory for creating KissDispatcher objects.
* *
*/ */
public class KissDispatcherFactory public class KissDispatcherFactory
{ {
private static Logger logger = LoggerFactory.getLogger(KissDispatcherFactory.class); static Logger logger = LoggerFactory.getLogger(KissDispatcherFactory.class);
private static class SingletonHolder private static class SingletonHolder
{ {
private static final KissDispatcherFactory instance = new KissDispatcherFactory(); private static final KissDispatcherFactory instance = new KissDispatcherFactory();
} }
private KissDispatcherCache cache; /*
* Need to avoid servlet duplication when more than pathinfo is matching a servlet.
* ClassPath -> Servlet.
*/
private ServletCache cache;
/** /**
* Instantiates a new kiss dispatcher factory. * Instantiates a new kiss dispatcher factory.
*/ */
private KissDispatcherFactory() private KissDispatcherFactory()
{ {
this.cache = new KissDispatcherCache(); this.cache = new ServletCache();
} }
/**
* Clear cache.
*/
public void clearCache() public void clearCache()
{ {
this.cache.clear(); this.cache.clear();
logger.info("KissDispatcherFactory Servlet Cache: CLEARED");
} }
/** /**
* Dispatch to servlet. * Provide servlet.
* *
* @param servletConfig * @param config
* the servlet config * the config
* @param request * @param servletClass
* the request * the servlet class
* @param response * @return the http servlet
* the response
* @param urlPath
* the url path
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws ServletException * @throws ServletException
* the servlet exception * the servlet exception
*/ */
public void dispatchPathToServlet(final ServletConfig servletConfig, final HttpServletRequest request, final HttpServletResponse response, public HttpServlet provideServlet(final ServletConfig config, final Class<HttpServlet> servletClass) throws ServletException
final String urlPath) throws IOException, ServletException
{ {
// Get the servlet. HttpServlet result;
HttpServlet servlet = this.cache.get(urlPath);
if (servlet == null) if ((config == null) || (servletClass == null))
{ {
String className = translateToClassName(urlPath); throw new ServletException("Null parameter detected calling KDF.provideServlet method.");
logger.info("className=[" + className + "]");
servlet = KissDispatcherUtils.instanciateServlet("website." + className);
if (servlet == null)
{
logger.info("Trying with Page suffix.");
servlet = KissDispatcherUtils.instanciateServlet("website." + className.replaceAll("Xhtml$", "Page"));
}
if (servlet != null)
{
servlet.init(servletConfig);
this.cache.put(urlPath, servlet);
}
} }
else else
{ {
logger.info("Class cache MATCHED."); String className = servletClass.getCanonicalName();
} result = this.cache.get(className);
if (result == null)
// Serve the servlet.
if (servlet == null)
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head></head><body>");
out.println("Unknown page.");
out.println("</body></html>");
out.close();
}
else
{
servlet.service(request, response);
}
}
/**
* Checks if is available class.
*
* @param className
* the class name
* @return true, if is available class
*/
private boolean isAvailableClass(final String className)
{
boolean result;
try
{
Class<HttpServlet> servletClass = (Class<HttpServlet>) Class.forName(className);
result = true;
}
catch (java.lang.ClassNotFoundException exception)
{
result = false;
}
//
return result;
}
/**
* Checks if is availableget path.
*
* @param servletConfig
* the servlet config
* @param request
* the request
* @param response
* the response
* @param urlPath
* the url path
* @return true, if is availableget path
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws ServletException
* the servlet exception
*/
public boolean isAvailablePath(final String urlPath)
{
boolean result;
if (this.cache.containsKey(urlPath))
{
result = true;
}
else
{
String className = "website." + translateToClassName(urlPath);
if (isAvailableClass(className) || isAvailableClass(className.replaceAll("Xhtml$", "Page")))
{ {
result = true; result = KissDispatcherUtils.instanciateServlet(className);
} result.init(config);
else this.cache.put(className, result);
{
result = false;
} }
} }
@ -197,105 +105,4 @@ public class KissDispatcherFactory
{ {
return SingletonHolder.instance; return SingletonHolder.instance;
} }
/**
* Translate to class name.
*
* <pre>
* "/" => "IndexXhtml"
* "/good/" => "good.IndexXhtml"
* "/good/morning.xhtml" => "good.MorningXhtml"
* "/good/morning_girl.xhtml" => "good.MorningGirlXhtml"
* "/good/morning-girl.xhtml" => "good.MorningGirlXhtml"
* </pre>
*
* @param urlPath
* the url path
* @return the string
*/
public static String translateToClassName(final String urlPath)
{
String result;
if (urlPath == null)
{
result = null;
}
else
{
if (urlPath.length() == 1)
{
result = "IndexXhtml";
}
else if (urlPath.endsWith("/"))
{
StringBuffer buffer = new StringBuffer(urlPath.length() + 50);
for (int index = 1; index < urlPath.length(); index++)
{
char letter = urlPath.charAt(index);
if (letter == '/')
{
buffer.append('.');
}
else
{
buffer.append(letter);
}
}
buffer.append(".IndexXhtml");
result = buffer.toString();
}
else
{
int lastToken = urlPath.lastIndexOf('/');
StringBuffer buffer = new StringBuffer(urlPath.length());
for (int index = 1; index <= lastToken; index++)
{
char letter = urlPath.charAt(index);
if (letter == '/')
{
buffer.append('.');
}
else
{
buffer.append(letter);
}
}
boolean capitalizedNext = true;
for (int index = lastToken + 1; index < urlPath.length(); index++)
{
char letter = urlPath.charAt(index);
if ((letter == '_') || (letter == '-') || (letter == '.'))
{
capitalizedNext = true;
}
else
{
if (capitalizedNext)
{
buffer.append(Character.toUpperCase(letter));
capitalizedNext = false;
}
else
{
buffer.append(letter);
}
}
}
result = buffer.toString();
}
}
logger.info(urlPath + " -> " + result);
//
return result;
}
} }

View file

@ -0,0 +1,135 @@
/**
* Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher;
import java.io.IOException;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
* The Class KissDispatcher.
*
*/
public class KissDispatcherServlet extends HttpServlet
{
private static final long serialVersionUID = -7278690604864844533L;
private static final Logger logger = LoggerFactory.getLogger(KissDispatcherServlet.class);
/**
* Instantiates a new kiss dispatcher.
*/
public KissDispatcherServlet()
{
}
/**
* {@inheritDoc}
*/
@Override
public void init() throws ServletException
{
super.init();
System.out.println("KissDispatcher INIT.");
}
/**
* {@inheritDoc}
*/
@Override
public void service(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
long startTime = new Date().getTime();
request.setCharacterEncoding("UTF-8");
logger.info("==================================================");
logger.info("getContextPath=[" + request.getContextPath() + "]");
logger.info("getPathInfo=[" + request.getPathInfo() + "]");
logger.info("getPathTranslated=[" + request.getPathTranslated() + "]");
logger.info("getQueryString=[" + request.getQueryString() + "]");
logger.info("getRequestURI=[" + request.getRequestURI() + "]");
logger.info("getRequestURL=[" + request.getRequestURL() + "]");
logger.info("getServletPath=[" + request.getServletPath() + "]");
/*
* In past, possibility to use the servlet path was enable. It is too
* complexe, not kiss mind.
*
* String path;
* if (request.getPathInfo() == null)
* {
* // web.xml url-pattern= *.xhtml
* path = request.getServletPath();
* }
* else
* {
* // web.xml url-pattern =
* path = request.getPathInfo();
* }
*
* https://issues.apache.org/bugzilla/show_bug.cgi?id=11318
* A number of features have been introduced in later versions of Tomcat
* that relate to URI encoding. This includes a URIEncoding attribute
* on the Coyote HTTP/1.1 connector which defaults to ISO-8859-1.
*
* According to the servlet specification:
* HttpServletRequest.getPathInfo() should be decoded by the web container;
* HttpServletRequest.getRequestURI() should not be decoded by the web container.
*
*
* http://stackoverflow.com/questions/15278512/safe-html-form-accept-charset/15587140#15587140
* The standard URL encoding must use UTF-8 yet servlets not only default to ISO-8859-1 but don't offer
* any way to change that with code.
* Sure you can req.setRequestEncoding("UTF-8") before you read anything, but for some ungodly reason this only affects request body,
* not query string parameters. There is nothing in the servlet request interface to specify the encoding used for query string parameters.
* Using ISO-8859-1 in your form is a hack. Using this ancient encoding will cause more problems than solve for sure.
* Especially since browsers do not support ISO-8859-1 and always treat it as Windows-1252. Whereas servlets treat ISO-8859-1 as ISO-8859-1,
* so you will be screwed beyond belief if you go with this.
* To change this in Tomcat for example, you can use the URIEncoding attribute in your <connector> element:
* <connector ... URIEncoding="UTF-8" ... />
*
* If you don't use a container that has these settings, can't change its settings or some other issue,
* you can still make it work because ISO-8859-1 decoding retains full information from the original binary.
* String correct = new String(request.getParameter("test").getBytes("ISO-8859-1"), "UTF-8")
*
*
* http://tomcat.apache.org/tomcat-5.5-doc/config/http.html
* URIEncoding
* This specifies the character encoding used to decode the URI bytes, after %xx decoding the URL.
* If not specified, ISO-8859-1 will be used.
*
*/
// String urlPath = request.getPathInfo();
HttpServlet servlet = KissDispatcher.instance().provideServlet(this.getServletConfig(), request);
servlet.service(request, response);
//
long endTime = new Date().getTime();
logger.debug("TIME: {}ms {}", endTime - startTime, request.getPathInfo());
}
}

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -25,26 +25,26 @@ import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.Date; import java.util.Date;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Objects;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.dispatcher.hooks.ShortURLRewriter; import fr.devinsy.kiss4web.dispatcher.hooks.ShortURLRewriter;
import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringList;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/** /**
* The Class KissDispatcherUtils. * The Class KissDispatcherUtils.
*/ */
public class KissDispatcherUtils public class KissDispatcherUtils
{ {
private static Logger logger = LoggerFactory.getLogger(KissDispatcherUtils.class); static Logger logger = LoggerFactory.getLogger(KissDispatcherUtils.class);
public enum ContentDispositionType public enum ContentDispositionType
{ {
@ -142,6 +142,7 @@ public class KissDispatcherUtils
* @throws ServletException * @throws ServletException
* the servlet exception * the servlet exception
*/ */
@Deprecated
public static void dispatchToServlet(final ServletConfig servletConfig, final HttpServletRequest request, final HttpServletResponse response, public static void dispatchToServlet(final ServletConfig servletConfig, final HttpServletRequest request, final HttpServletResponse response,
final String className) throws IOException, ServletException final String className) throws IOException, ServletException
{ {
@ -205,17 +206,17 @@ public class KissDispatcherUtils
* Instanciate servlet. * Instanciate servlet.
* *
* @param className * @param className
* the class name * the class pathname
* @return the http servlet or null if no one found. * @return the http servlet
*/ */
public static HttpServlet instanciateServlet(final String classPathname) public static HttpServlet instanciateServlet(final String className)
{ {
HttpServlet result; HttpServlet result;
Class<HttpServlet> servletClass = null; Class<HttpServlet> servletClass = null;
try try
{ {
servletClass = (Class<HttpServlet>) Class.forName(classPathname); servletClass = (Class<HttpServlet>) Class.forName(className);
} }
catch (java.lang.ClassNotFoundException exception) catch (java.lang.ClassNotFoundException exception)
{ {
@ -225,7 +226,7 @@ public class KissDispatcherUtils
if (servletClass == null) if (servletClass == null)
{ {
result = null; result = null;
logger.warn("unknown page: [{}]", classPathname); logger.warn("unknown page: [{}]", className);
} }
else else
{ {
@ -236,17 +237,17 @@ public class KissDispatcherUtils
} }
catch (java.lang.InstantiationException exception) catch (java.lang.InstantiationException exception)
{ {
logger.error("Can't instanciate servlet (" + classPathname + ")", exception); logger.error("Can't instanciate servlet (" + className + ")", exception);
result = null; result = null;
} }
catch (java.lang.IllegalAccessException exception) catch (java.lang.IllegalAccessException exception)
{ {
logger.error("(2) Can't instanciate servlet (" + classPathname + ")", exception); logger.error("(2) Can't instanciate servlet (" + className + ")", exception);
result = null; result = null;
} }
catch (IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException exception) catch (IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException exception)
{ {
logger.error("(3) Can't instanciate servlet (" + classPathname + ")", exception); logger.error("(3) Can't instanciate servlet (" + className + ")", exception);
result = null; result = null;
} }
} }
@ -255,6 +256,54 @@ public class KissDispatcherUtils
return result; return result;
} }
/**
* Checks if is available path.
*
* @param path
* the path
* @return true, if is available path
*/
public static boolean isAvailablePath(final String path)
{
boolean result;
if (pickServletClass(path) == null)
{
result = false;
}
else
{
result = true;
}
//
return result;
}
/**
* Path to class.
*
* @param className
* the class pathname
* @return the class
*/
public static Class nameToClass(final String className)
{
Class result;
try
{
result = Class.forName(className);
}
catch (java.lang.ClassNotFoundException exception)
{
result = null;
}
//
return result;
}
/** /**
* Convert a path in a class name, using kiss conventions. * Convert a path in a class name, using kiss conventions.
* *
@ -383,6 +432,39 @@ public class KissDispatcherUtils
return result; return result;
} }
/**
* Path to servlet class.
*
* @param className
* the class pathname
* @return the class
*/
public static Class<HttpServlet> pickServletClass(final String className)
{
Class<HttpServlet> result;
// String className = KissDispatcherUtils.translateToClassName(path);
logger.info("className=[{}]", className);
result = nameToClass(className);
if (result == null)
{
logger.info("Trying with Page suffix.");
result = nameToClass(className.replaceAll("Xhtml$", "Page"));
}
if (result == null)
{
logger.info("Trying with Do suffix.");
result = nameToClass(className.replaceAll("Xhtml$", "Do"));
}
logger.debug("servletClass={}", result);
//
return result;
}
/** /**
* Return attachment file. * Return attachment file.
* *
@ -417,6 +499,29 @@ public class KissDispatcherUtils
public static void returnFile(final HttpServletResponse response, final File file, final String mimeType, public static void returnFile(final HttpServletResponse response, final File file, final String mimeType,
final ContentDispositionType contentDisposition) throws IOException final ContentDispositionType contentDisposition) throws IOException
{ {
returnFile(response, file, null, mimeType, contentDisposition);
}
/**
* Return file.
*
* @param response
* the response
* @param file
* the file
* @param targetFilename
* the target filename, in case the name of file is not the one
* intended, if null then the file name is used
* @param mimeType
* the mime type
* @param contentDisposition
* the content disposition
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void returnFile(final HttpServletResponse response, final File file, final String targetFilename, final String mimeType,
final ContentDispositionType contentDisposition) throws IOException
{
if ((file == null) || (!file.exists())) if ((file == null) || (!file.exists()))
{ {
@ -444,7 +549,9 @@ public class KissDispatcherUtils
{ {
contentDispositionToken = "inline"; contentDispositionToken = "inline";
} }
response.setHeader("Content-Disposition", contentDispositionToken + "; filename=\"" + file.getName() + "\"");
response.setHeader("Content-Disposition",
contentDispositionToken + "; filename=\"" + Objects.toString(targetFilename, file.getName()) + "\"");
response.setDateHeader("Expires", new Date().getTime() + KissDispatcher.DEFAULT_CACHE_AGE * 1000); response.setDateHeader("Expires", new Date().getTime() + KissDispatcher.DEFAULT_CACHE_AGE * 1000);
response.setHeader("Cache-Control", "max-age=" + KissDispatcher.DEFAULT_CACHE_AGE); response.setHeader("Cache-Control", "max-age=" + KissDispatcher.DEFAULT_CACHE_AGE);
@ -479,6 +586,10 @@ public class KissDispatcherUtils
} }
catch (IOException exception) catch (IOException exception)
{ {
System.out.println("/!\\/!\\/!\\/!\\/!\\/!\\/!\\/!\\/!\\/!\\/!\\/!\\/!\\/!\\/!\\");
exception.printStackTrace();
// TODO As sendError cannot be send because partial content has
// been send, we have to replace this with a better way.
response.sendError(HttpServletResponse.SC_PARTIAL_CONTENT); response.sendError(HttpServletResponse.SC_PARTIAL_CONTENT);
} }
finally finally
@ -586,6 +697,26 @@ public class KissDispatcherUtils
returnFile(response, file, mimeType, ContentDispositionType.INLINE); returnFile(response, file, mimeType, ContentDispositionType.INLINE);
} }
/**
* Return inline file.
*
* @param response
* the response
* @param file
* the file
* @param targetFilename
* the target filename
* @param mimeType
* the mime type
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void returnInlineFile(final HttpServletResponse response, final File file, final String targetFilename, final String mimeType)
throws IOException
{
returnFile(response, file, targetFilename, mimeType, ContentDispositionType.INLINE);
}
/** /**
* Show parameters. * Show parameters.
* *
@ -623,4 +754,202 @@ public class KissDispatcherUtils
// //
return result; return result;
} }
/**
* Translate to class name.
*
* <pre>
* "/" => "IndexXhtml"
* "/good/" => "good.IndexXhtml"
* "/good/morning.xhtml" => "good.MorningXhtml"
* "/good/morning_girl.xhtml" => "good.MorningGirlXhtml"
* "/good/morning-girl.xhtml" => "good.MorningGirlXhtml"
* </pre>
*
* @param urlPath
* the url path
* @return the string
*/
public static String translateToClassName(final String urlPath)
{
String result;
if (urlPath == null)
{
result = null;
}
else
{
if (urlPath.length() == 1)
{
result = "IndexXhtml";
}
else if (urlPath.endsWith("/"))
{
StringBuffer buffer = new StringBuffer(urlPath.length() + 50);
for (int index = 1; index < urlPath.length(); index++)
{
char letter = urlPath.charAt(index);
if (letter == '/')
{
buffer.append('.');
}
else
{
buffer.append(letter);
}
}
buffer.append("IndexXhtml");
result = buffer.toString();
}
else
{
int lastToken = urlPath.lastIndexOf('/');
StringBuffer buffer = new StringBuffer(urlPath.length());
for (int index = 1; index <= lastToken; index++)
{
char letter = urlPath.charAt(index);
if (letter == '/')
{
buffer.append('.');
}
else
{
buffer.append(letter);
}
}
boolean capitalizedNext = true;
for (int index = lastToken + 1; index < urlPath.length(); index++)
{
char letter = urlPath.charAt(index);
if ((letter == '_') || (letter == '-') || (letter == '.'))
{
capitalizedNext = true;
}
else
{
if (capitalizedNext)
{
buffer.append(Character.toUpperCase(letter));
capitalizedNext = false;
}
else
{
buffer.append(letter);
}
}
}
result = buffer.toString();
}
}
KissDispatcherFactory.logger.info(urlPath + " -> " + result);
//
return result;
}
/**
* Translate to class name.
*
* <pre>
* "/" => "Index_xhtml"
* "/good/" => "good.Index_xhtml"
* "/good/morning.xhtml" => "good.MorningXhtml"
* "/good/morning_girl.xhtml" => "good.Morning-Girl_xhtml"
* "/good/morning-girl.xhtml" => "good.Morning_Girl_xhtml"
* </pre>
*
* @param urlPath
* the url path
* @return the string
*/
public static String translateToClassNameAlternative(final String urlPath)
{
String result;
if (urlPath == null)
{
result = null;
}
else
{
if (urlPath.length() == 1)
{
result = "IndexXhtml";
}
else if (urlPath.endsWith("/"))
{
StringBuffer buffer = new StringBuffer(urlPath.length() + 50);
for (int index = 1; index < urlPath.length(); index++)
{
char letter = urlPath.charAt(index);
if (letter == '/')
{
buffer.append('.');
}
else
{
buffer.append(letter);
}
}
buffer.append(".Index_xhtml");
result = buffer.toString();
}
else
{
int lastToken = urlPath.lastIndexOf('/');
StringBuffer buffer = new StringBuffer(urlPath.length());
for (int index = 1; index <= lastToken; index++)
{
char letter = urlPath.charAt(index);
if (letter == '/')
{
buffer.append('.');
}
else
{
buffer.append(letter);
}
}
if (lastToken + 1 < urlPath.length())
{
buffer.append(Character.toUpperCase(urlPath.charAt(lastToken + 1)));
}
for (int index = lastToken + 2; index < urlPath.length(); index++)
{
char letter = urlPath.charAt(index);
if (letter == '.')
{
buffer.append('_');
}
else
{
buffer.append(letter);
}
}
result = buffer.toString();
}
}
KissDispatcherFactory.logger.info(urlPath + " -> " + result);
//
return result;
}
} }

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -20,23 +20,23 @@ package fr.devinsy.kiss4web.dispatcher;
import java.util.HashMap; import java.util.HashMap;
import javax.servlet.http.HttpServlet;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.servlet.http.HttpServlet;
/** /**
* The Class KissDispatcherCache. * The Class ServletCache.
*/ */
public class KissDispatcherCache extends HashMap<String, HttpServlet> public class ServletCache extends HashMap<String, HttpServlet>
{ {
private static final long serialVersionUID = -7727974577347443504L; private static final long serialVersionUID = -7727974577347443504L;
private static Logger logger = LoggerFactory.getLogger(KissDispatcherCache.class); private static Logger logger = LoggerFactory.getLogger(ServletCache.class);
/** /**
* Instantiates a new kiss dispatcher cache. * Instantiates a new kiss dispatcher cache.
*/ */
public KissDispatcherCache() public ServletCache()
{ {
super(); super();
} }
@ -53,13 +53,14 @@ public class KissDispatcherCache extends HashMap<String, HttpServlet>
HttpServlet result; HttpServlet result;
boolean ended = false; boolean ended = false;
int index = 0; int index = 0;
result = null; result = null;
while (!ended) while (!ended)
{ {
if (index < path.length) if (index < path.length)
{ {
result = get(path); result = super.get(path[index]);
if (result == null) if (result == null)
{ {
index += 1; index += 1;

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2021 Christian Pierre MOMON * Copyright (C) 2021-2023 Christian Pierre MOMON
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -20,13 +20,12 @@ package fr.devinsy.kiss4web.dispatcher;
import java.util.Iterator; import java.util.Iterator;
import javax.servlet.http.HttpServlet;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringList;
import jakarta.servlet.http.HttpServlet;
/** /**
* The Class WebsiteClasspaths. * The Class WebsiteClasspaths.
@ -45,8 +44,8 @@ public class WebsiteClasspaths extends StringList
super(); super();
} }
/* (non-Javadoc) /**
* @see java.util.ArrayList#add(java.lang.Object) * {@inheritDoc}
*/ */
@Override @Override
public boolean add(final String classpath) public boolean add(final String classpath)
@ -76,8 +75,8 @@ public class WebsiteClasspaths extends StringList
/** /**
* Instanciate servlet. * Instanciate servlet.
* *
* @param subClasspath * @param className
* the sub classpath * the class name
* @return the http servlet * @return the http servlet
*/ */
public HttpServlet instanciateServlet(final String className) public HttpServlet instanciateServlet(final String className)

View file

@ -0,0 +1,45 @@
/*
* Copyright (C) 2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.annotation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.dispatcher.hooks.RewriteHook;
/**
* The Class AnnotationHook.
*/
public class AnnotationHook extends RewriteHook
{
private static Logger logger = LoggerFactory.getLogger(AnnotationHook.class);
/**
* Instantiates a new annotation hook.
*
* @param regex
* the regex
* @param targetClassName
* the target class name
*/
public AnnotationHook(final String regex, final String targetClassName)
{
super(regex, targetClassName);
}
}

View file

@ -0,0 +1,37 @@
/**
* Copyright (C) 2024 Christian Pierre MOMON
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.annotation;
import java.util.ArrayList;
/**
* The Class AnnotationHooks.
*/
public class AnnotationHooks extends ArrayList<AnnotationHook>
{
private static final long serialVersionUID = 1979896054785066359L;
/**
* Instantiates a new hook list.
*/
public AnnotationHooks()
{
super();
}
}

View file

@ -0,0 +1,152 @@
/*
* Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.annotation;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.servlet.http.HttpServlet;
/**
* The Class AnnotationUtils.
*/
public class AnnotationUtils
{
private static final Logger logger = LoggerFactory.getLogger(AnnotationUtils.class);
/**
* Recursive method used to find all classes in a given directory and
* subdirs.
*
* @param directory
* The base directory
* @param packageName
* The package name for classes found inside the base directory
* @return The classes
* @throws ClassNotFoundException
*/
private static List<Class> findClasses(final File directory, final String packageName) throws ClassNotFoundException
{
List<Class> result;
result = new ArrayList<Class>();
if (directory.exists())
{
File[] files = directory.listFiles();
for (File file : files)
{
if (file.isDirectory())
{
assert !file.getName().contains(".");
result.addAll(findClasses(file, packageName + "." + file.getName()));
}
else if (file.getName().endsWith(".class"))
{
result.add(Class.forName(packageName + '.' + file.getName().substring(0, file.getName().length() - 6)));
}
}
}
//
return result;
}
/**
* Gets the annotation hooks.
*
* @return the annotation hooks
*/
public static AnnotationHooks getAnnotationHooks()
{
AnnotationHooks result;
try
{
result = new AnnotationHooks();
Class[] classes = getClasses("website");
for (Class clazz : classes)
{
if (clazz.isAnnotationPresent(KissServlet.class))
{
// System.out.println("==> " + clazz.getName() + " " +
// clazz.getCanonicalName());
// System.out.println("==> " + ((Class<HttpServlet>)
// clazz).getAnnotation(KissServlet.class).value());
String className = clazz.getCanonicalName();
String regexPathInfo = ((Class<HttpServlet>) clazz).getAnnotation(KissServlet.class).value();
AnnotationHook hook = new AnnotationHook(regexPathInfo, className);
result.add(hook);
}
}
}
catch (ClassNotFoundException | IOException exception)
{
logger.error("Package website undefined, KissServlet annotations ignored.", exception);
result = new AnnotationHooks();
}
//
return result;
}
/**
* Gets the classes.
*
* @param packageName
* the package name
* @return the classes
* @throws ClassNotFoundException
* the class not found exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static Class[] getClasses(final String packageName) throws ClassNotFoundException, IOException
{
Class[] result;
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
assert classLoader != null;
String path = packageName.replace('.', '/');
Enumeration<URL> resources = classLoader.getResources(path);
List<File> dirs = new ArrayList<File>();
while (resources.hasMoreElements())
{
URL resource = resources.nextElement();
dirs.add(new File(resource.getFile()));
}
ArrayList<Class> classes = new ArrayList<Class>();
for (File directory : dirs)
{
classes.addAll(findClasses(directory, packageName));
}
result = classes.toArray(new Class[classes.size()]);
//
return result;
}
}

View file

@ -0,0 +1,39 @@
/*
* Copyright (C) 2024 Christian Pierre MOMON
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* The Interface KissServlet.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface KissServlet
{
/**
* Value of the pathInfo regex to map on the annoted class..
*
* @return the string
*/
String value();
}

View file

@ -0,0 +1,70 @@
/*
* Copyright (C) 2024 Christian Pierre MOMON
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.annotation;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
/**
* The Class KissServletProcessor.
*/
@javax.annotation.processing.SupportedAnnotationTypes("fr.devinsy.kiss4web.dispatcher.annotation.KissServlet")
@javax.annotation.processing.SupportedSourceVersion(javax.lang.model.SourceVersion.RELEASE_17)
public class KissServletProcessor extends AbstractProcessor
{
/**
* {@inheritDoc}
*/
@Override
public synchronized void init(final ProcessingEnvironment processingEnv)
{
super.init(processingEnv);
// Initialization code, if needed
// System.out.println("=============== @INIT");
}
/**
* {@inheritDoc}
*/
@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv)
{
for (TypeElement annotation : annotations)
{
// Find elements annotated with MyCustomAnnotation
for (Element element : roundEnv.getElementsAnnotatedWith(annotation))
{
// Process each element
this.processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Processing: " + element.getSimpleName());
// Your processing logic here
System.out.println("=============== YOOOOOOOOOOP");
}
}
//
return true; // No further processing of this annotation type
}
}

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2018-2021 Christian Pierre MOMON * Copyright (C) 2018-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,75 +18,21 @@
*/ */
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.presenters.URLPresenter;
/** /**
* The Class InitHook. * The Class ApplicationInitFailedHook.
*/ */
public class ApplicationInitFailedHook extends HookCore public class ApplicationInitFailedHook extends DirectHook
{ {
private static Logger logger = LoggerFactory.getLogger(ApplicationInitFailedHook.class); private static Logger logger = LoggerFactory.getLogger(ApplicationInitFailedHook.class);
/** /**
* Instantiates a new inits the hook. * Instantiates a new application init failed hook.
*/ */
public ApplicationInitFailedHook() public ApplicationInitFailedHook()
{ {
super(); super("/fr/devinsy/kiss4web/dispatcher/hooks/ApplicationInitFailedServlet");
}
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.kernel.dispatcher.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest)
*/
@Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
{
boolean result;
result = true;
//
return result;
}
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.dispatcher.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException
{
try
{
logger.debug("Doing catch {}.", this.getClass().getName());
String path = servletContext.getRealPath("/") + request.getPathInfo();
logger.info("path=[{}]", path);
StringBuffer html = new URLPresenter("/fr/devinsy/kiss4web/dispatcher/hooks/applicationInitFailed.xhtml").dynamize();
// Display page.
response.setContentType("application/xhtml+xml; charset=UTF-8");
response.getWriter().println(html);
logger.info("Application Init Failed page returned.");
}
catch (XidynException exception)
{
exception.printStackTrace();
new FatalHook().process(servletConfig, servletContext, request, response);
}
} }
} }

View file

@ -0,0 +1,39 @@
/*
* Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.hooks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class ApplicationInitFailedServlet.
*/
public class ApplicationInitFailedServlet extends DirectServlet
{
private static final long serialVersionUID = 3354542049753884236L;
private static final Logger logger = LoggerFactory.getLogger(ApplicationInitFailedServlet.class);
/**
* Instantiates a new application init failed servlet.
*/
public ApplicationInitFailedServlet()
{
super("/fr/devinsy/kiss4web/dispatcher/hooks/applicationInitFailed.xhtml");
}
}

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2018-2021 Christian Pierre MOMON * Copyright (C) 2018-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,24 +18,13 @@
*/ */
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.presenters.URLPresenter;
/** /**
* The Class InitHook. * The Class InitHook.
*/ */
public class ApplicationInitHook extends HookCore public class ApplicationInitHook extends DirectHook
{ {
private static Logger logger = LoggerFactory.getLogger(ApplicationInitHook.class); private static Logger logger = LoggerFactory.getLogger(ApplicationInitHook.class);
@ -44,49 +33,6 @@ public class ApplicationInitHook extends HookCore
*/ */
public ApplicationInitHook() public ApplicationInitHook()
{ {
super(); super("/fr/devinsy/kiss4web/dispatcher/hooks/ApplicationInitServlet");
}
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.kernel.dispatcher.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest)
*/
@Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
{
boolean result;
result = true;
//
return result;
}
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.dispatcher.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException
{
try
{
logger.debug("Doing catch {}.", this.getClass().getName());
String path = servletContext.getRealPath("/") + request.getPathInfo();
logger.info("path=[{}]", path);
StringBuffer html = new URLPresenter("/fr/devinsy/kiss4web/dispatcher/hooks/applicationInit.xhtml").dynamize();
// Display page.
response.setContentType("application/xhtml+xml; charset=UTF-8");
response.getWriter().println(html);
logger.info("Application Init page returned.");
}
catch (XidynException exception)
{
exception.printStackTrace();
new FatalHook().process(servletConfig, servletContext, request, response);
}
} }
} }

View file

@ -0,0 +1,39 @@
/*
* Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.hooks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class ApplicationInitServlet.
*/
public class ApplicationInitServlet extends DirectServlet
{
private static final long serialVersionUID = 6515114898805106148L;
private static final Logger logger = LoggerFactory.getLogger(ApplicationInitServlet.class);
/**
* Instantiates a new application init servlet.
*/
public ApplicationInitServlet()
{
super("/fr/devinsy/kiss4web/dispatcher/hooks/applicationInitServlet.xhtml");
}
}

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,17 +18,13 @@
*/ */
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
/** /**
* The Class BlankHook. * The Class BlankHook.
*/ */
@ -44,8 +40,22 @@ public class BlankHook extends HookCore
super(); super();
} }
/* (non-Javadoc) /**
* @see fr.devinsy.kiss4web.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) * {@inheritDoc}
*/
@Override
public String getServletClassName(final ServletConfig config, final HttpServletRequest request)
{
String result;
result = "/fr/devinsy/kiss4web/dispatcher/hooks/BlankServlet";
//
return result;
}
/**
* {@inheritDoc}
*/ */
@Override @Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request) public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
@ -66,23 +76,4 @@ public class BlankHook extends HookCore
// //
return result; return result;
} }
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException
{
logger.debug("Doing catch.");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head></head><body>");
out.println("Null path.");
out.println("</body></html>");
out.close();
}
} }

View file

@ -0,0 +1,39 @@
/*
* Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.hooks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class BlankSerlvet.
*/
public class BlankSerlvet extends DirectServlet
{
private static final long serialVersionUID = -3751754076316971589L;
private static final Logger logger = LoggerFactory.getLogger(BlankSerlvet.class);
/**
* Instantiates a new blank serlvet.
*/
public BlankSerlvet()
{
super("/fr/devinsy/kiss4web/dispatcher/hooks/blank.xhtml");
}
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (C) 2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.hooks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
/**
* The Class DirectHook.
*/
public class DirectHook extends HookCore
{
private static Logger logger = LoggerFactory.getLogger(DirectHook.class);
private String targetClassName;
/**
* Instantiates a new direct hook.
*
* @param targetClassName
* the target class name
*/
public DirectHook(final String targetClassName)
{
super();
this.targetClassName = targetClassName;
}
/**
* {@inheritDoc}
*/
@Override
public String getServletClassName(final ServletConfig config, final HttpServletRequest request)
{
String result;
result = this.targetClassName;
//
return result;
}
/**
* {@inheritDoc}
*/
@Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
{
boolean result;
result = true;
//
return result;
}
}

View file

@ -0,0 +1,96 @@
/*
* Copyright (C) 2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
* The Class DirectServlet.
*/
public class DirectServlet extends HttpServlet
{
private static final long serialVersionUID = 3433035754728880755L;
private static final Logger logger = LoggerFactory.getLogger(DirectServlet.class);
private String path;
/**
* Instantiates a new direct servlet.
*
* @param path
* the path
*/
public DirectServlet(final String path)
{
super();
this.path = path;
}
/**
* Dispatch.
*
* @param request
* the request
* @param response
* the response
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws ServletException
* the servlet exception
*/
public void dispatch(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
// Get page.
URL url = Hook.class.getResource(this.path);
String xhtml = IOUtils.toString(url, StandardCharsets.UTF_8);
// Display page.
response.setContentType("application/xhtml+xml; charset=UTF-8");
response.getWriter().println(xhtml);
}
/**
* {@inheritDoc}
*/
@Override
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
dispatch(request, response);
}
/**
* {@inheritDoc}
*/
@Override
public void doPost(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
dispatch(request, response);
}
}

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2018-2021 Christian Pierre MOMON * Copyright (C) 2018-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,25 +18,13 @@
*/ */
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.File;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.presenters.URLPresenter;
/** /**
* The Class ErrorHook. * The Class ErrorHook.
*/ */
public class ErrorHook extends HookCore public class ErrorHook extends RewriteHook
{ {
private static Logger logger = LoggerFactory.getLogger(ErrorHook.class); private static Logger logger = LoggerFactory.getLogger(ErrorHook.class);
@ -45,55 +33,6 @@ public class ErrorHook extends HookCore
*/ */
public ErrorHook() public ErrorHook()
{ {
super(); super(".*", "/fr/devinsy/kiss4web/dispatcher/hooks/ErrorServlet");
}
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.kernel.dispatcher.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest)
*/
@Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
{
boolean result;
if (new File(servletContext.getRealPath("/") + request.getPathInfo()).exists())
{
result = true;
}
else
{
result = false;
}
//
return result;
}
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.dispatcher.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException
{
logger.debug("Doing catch.");
try
{
String path = servletContext.getRealPath("/") + request.getPathInfo();
logger.info("path=[{}]", path);
StringBuffer html = new URLPresenter("/fr/devinsy/kiss4web/dispatcher/hooks/error.xhtml").dynamize();
// Display page.
response.setContentType("application/xhtml+xml; charset=UTF-8");
response.getWriter().println(html);
logger.info("Error page returned for [{}].", path);
}
catch (XidynException exception)
{
exception.printStackTrace();
new FatalHook().process(servletConfig, servletContext, request, response);
}
} }
} }

View file

@ -0,0 +1,117 @@
/*
* Copyright (C) 2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
* The Class ErrorServlet.
*/
public class ErrorServlet extends HttpServlet
{
private static final long serialVersionUID = -4906221802965761187L;
private static final Logger logger = LoggerFactory.getLogger(ErrorServlet.class);
private String message;
private Exception exception;
/**
* Instantiates a new error servlet.
*
* @param message
* the message
*/
public ErrorServlet(final String message)
{
this(message, null);
}
/**
* Instantiates a new error servlet.
*
* @param message
* the message
* @param exception
* the exception
*/
public ErrorServlet(final String message, final Exception exception)
{
this.message = message;
this.exception = exception;
}
/**
* Dispatch.
*
* @param request
* the request
* @param response
* the response
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws ServletException
* the servlet exception
*/
public void dispatch(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
ServletContext context = this.getServletContext();
// Get page.
// TODO dynamize!!!
URL url = Hook.class.getResource("/fr/devinsy/kiss4web/dispatcher/hooks/error.xhtml");
String xhtml = IOUtils.toString(url, StandardCharsets.UTF_8);
// Display page.
response.setContentType("application/xhtml+xml; charset=UTF-8");
response.getWriter().println(xhtml);
}
/**
* {@inheritDoc}
*/
@Override
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
dispatch(request, response);
}
/**
* {@inheritDoc}
*/
@Override
public void doPost(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
dispatch(request, response);
}
}

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2018-2021 Christian Pierre MOMON * Copyright (C) 2018-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,23 +18,13 @@
*/ */
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class FatalHook. * The Class FatalHook.
*/ */
public class FatalHook extends HookCore public class FatalHook extends DirectHook
{ {
private static Logger logger = LoggerFactory.getLogger(FatalHook.class); private static Logger logger = LoggerFactory.getLogger(FatalHook.class);
@ -43,61 +33,6 @@ public class FatalHook extends HookCore
*/ */
public FatalHook() public FatalHook()
{ {
super(); super("/fr/devinsy/kiss4web/dispatcher/hooks/FatalServlet");
}
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.kernel.dispatcher.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest)
*/
@Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
{
boolean result;
if (new File(servletContext.getRealPath("/") + request.getPathInfo()).exists())
{
result = true;
}
else
{
result = false;
}
//
return result;
}
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.dispatcher.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException
{
logger.debug("Doing catch.");
String path = servletContext.getRealPath("/") + request.getPathInfo();
logger.info("path=[{}]", path);
// Display fatal error page.
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
out.println("<!DOCTYPE html >");
out.println("<html><header></header><body>");
out.println("A fatal error occured:<br/>");
out.println("<pre>");
// out.println(source.getMessage());
out.println("</pre>");
out.println("<hr />");
// if (source.getMessage() != null)
// {
// out.println("<pre>" + XidynUtils.restoreEntities(new
// StringBuffer(source.getMessage())) + "</pre>");
// }
out.println("<hr />");
out.println("</body></html>");
logger.info("File returned directly [{}] with mimetype [{}].", path, servletContext.getMimeType(path));
} }
} }

View file

@ -0,0 +1,39 @@
/*
* Copyright (C) 2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.hooks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class FatalServlet.
*/
public class FatalServlet extends DirectServlet
{
private static final long serialVersionUID = 634762859496474527L;
private static final Logger logger = LoggerFactory.getLogger(FatalServlet.class);
/**
* Instantiates a new fatal servlet.
*/
public FatalServlet()
{
super("/fr/devinsy/kiss4web/dispatcher/hooks/fatal.xhtml");
}
}

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,18 +18,13 @@
*/ */
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils; import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
/** /**
* The Class FolderHook. * The Class FolderHook.
@ -46,8 +41,22 @@ public class FolderHook extends HookCore
super(); super();
} }
/* (non-Javadoc) /**
* @see fr.devinsy.kiss4web.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) * {@inheritDoc}
*/
@Override
public String getServletClassName(final ServletConfig config, final HttpServletRequest request)
{
String result;
result = "website." + KissDispatcherUtils.translateToClassName(request.getPathInfo());
//
return result;
}
/**
* {@inheritDoc}
*/ */
@Override @Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request) public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
@ -68,17 +77,4 @@ public class FolderHook extends HookCore
// //
return result; return result;
} }
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException
{
logger.debug("Doing catch.");
String urlPath = request.getPathInfo();
KissDispatcherUtils.dispatchToServlet(servletConfig, request, response, urlPath);
}
} }

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,13 +18,9 @@
*/ */
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.IOException; import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import javax.servlet.ServletConfig; import jakarta.servlet.http.HttpServletRequest;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/** /**
* The Interface Hook. * The Interface Hook.
@ -32,11 +28,15 @@ import javax.servlet.http.HttpServletResponse;
public interface Hook public interface Hook
{ {
/** /**
* Checks if is terminal. * Gets the servlet.
* *
* @return true if it is a final hook, false otherwise. * @param config
* the config
* @param request
* the request
* @return the servlet
*/ */
boolean isTerminal(); String getServletClassName(ServletConfig config, HttpServletRequest request);
/** /**
* Matches. * Matches.
@ -48,23 +48,4 @@ public interface Hook
* @return true, if successful * @return true, if successful
*/ */
boolean matches(final ServletContext servletContext, final HttpServletRequest request); boolean matches(final ServletContext servletContext, final HttpServletRequest request);
/**
* Process.
*
* @param servletConfig
* the servlet config
* @param servletContext
* the servlet context
* @param request
* the request
* @param response
* the response
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws ServletException
* the servlet exception
*/
void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException;
} }

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -23,35 +23,11 @@ package fr.devinsy.kiss4web.dispatcher.hooks;
*/ */
public abstract class HookCore implements Hook public abstract class HookCore implements Hook
{ {
private boolean terminal;
/** /**
* Instantiates a new hook core. * Instantiates a new hook core.
*/ */
public HookCore() public HookCore()
{ {
super(); super();
this.terminal = true;
}
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.hooks.Hook#isTerminal()
*/
@Override
public boolean isTerminal()
{
return this.terminal;
}
/**
* Sets the terminal.
*
* @param terminal
* the new terminal
*/
public void setTerminal(final boolean terminal)
{
this.terminal = terminal;
} }
} }

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,10 +18,11 @@
*/ */
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import javax.servlet.ServletContext; import jakarta.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
/** /**
* The Class HookRegister. * The Class HookRegister.
@ -33,6 +34,9 @@ public class HookRegister
/** /**
* Instantiates a new hook register. * Instantiates a new hook register.
*
* @param name
* the name
*/ */
public HookRegister(final String name) public HookRegister(final String name)
{ {
@ -91,6 +95,11 @@ public class HookRegister
return result; return result;
} }
/**
* Gets the name.
*
* @return the name
*/
public String getName() public String getName()
{ {
return this.name; return this.name;
@ -111,11 +120,31 @@ public class HookRegister
return result; return result;
} }
/**
* Register.
*
* @param hooks
* the hooks
* @return the hook register
*/
public HookRegister register(final Collection<? extends Hook> hooks)
{
HookRegister result;
this.hooks.addAll(hooks);
result = this;
//
return result;
}
/** /**
* Register. * Register.
* *
* @param hook * @param hook
* the hook * the hook
* @return the hook register
*/ */
public HookRegister register(final Hook hook) public HookRegister register(final Hook hook)
{ {
@ -129,6 +158,12 @@ public class HookRegister
return result; return result;
} }
/**
* Register all.
*
* @param register
* the register
*/
public void registerAll(final HookRegister register) public void registerAll(final HookRegister register)
{ {
this.hooks.addAll(register.getHooks()); this.hooks.addAll(register.getHooks());

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2018-2021 Christian Pierre MOMON * Copyright (C) 2018-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,71 +18,21 @@
*/ */
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.File;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils;
/** /**
* The Class InitFailedHook. * The Class InitFailedHook.
*/ */
public class InitFailedHook extends HookCore public class InitFailedHook extends DirectHook
{ {
private static Logger logger = LoggerFactory.getLogger(InitFailedHook.class); private static Logger logger = LoggerFactory.getLogger(InitFailedHook.class);
/** /**
* Instantiates a new inits the failed hook. * Instantiates a new init failed hook.
*/ */
public InitFailedHook() public InitFailedHook()
{ {
super(); super("/fr/devinsy/kiss4web/dispatcher/hooks/initFailedServlet.xhtml");
}
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.kernel.dispatcher.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest)
*/
@Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
{
boolean result;
if (new File(servletContext.getRealPath("/") + request.getPathInfo()).exists())
{
result = true;
}
else
{
result = false;
}
//
return result;
}
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.dispatcher.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException
{
logger.debug("Doing catch.");
String path = servletContext.getRealPath("/") + request.getPathInfo();
logger.info("path=[{}]", path);
String mimeType = servletContext.getMimeType(path);
KissDispatcherUtils.returnInlineFile(response, new File(path), mimeType);
logger.info("File returned directly [{}] with mimetype [{}].", path, servletContext.getMimeType(path));
} }
} }

View file

@ -0,0 +1,39 @@
/*
* Copyright (C) 2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.hooks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class InitFailedServlet.
*/
public class InitFailedServlet extends DirectServlet
{
private static final long serialVersionUID = -8117673535638021417L;
private static final Logger logger = LoggerFactory.getLogger(InitFailedServlet.class);
/**
* Instantiates a new inits the failed servlet.
*/
public InitFailedServlet()
{
super("/fr/devinsy/kiss4web/dispatcher/hooks/maintenance.xhtml");
}
}

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2018-2021 Christian Pierre MOMON * Copyright (C) 2018-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,75 +18,21 @@
*/ */
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.presenters.URLPresenter;
/** /**
* The Class InitHook. * The Class InitHook.
*/ */
public class InitHook extends HookCore public class InitHook extends DirectHook
{ {
private static Logger logger = LoggerFactory.getLogger(InitHook.class); private static Logger logger = LoggerFactory.getLogger(InitHook.class);
/** /**
* Instantiates a new inits the hook. * Instantiates a new init the hook.
*/ */
public InitHook() public InitHook()
{ {
super(); super("/fr/devinsy/kiss4web/dispatcher/hooks/InitServlet");
}
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.kernel.dispatcher.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest)
*/
@Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
{
boolean result;
result = true;
//
return result;
}
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.dispatcher.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException
{
try
{
logger.debug("Doing catch {}.", this.getClass().getName());
String path = servletContext.getRealPath("/") + request.getPathInfo();
logger.info("path=[{}]", path);
StringBuffer html = new URLPresenter("/fr/devinsy/kiss4web/dispatcher/hooks/init.xhtml").dynamize();
// Display page.
response.setContentType("application/xhtml+xml; charset=UTF-8");
response.getWriter().println(html);
logger.info("Init page returned.");
}
catch (XidynException exception)
{
exception.printStackTrace();
new FatalHook().process(servletConfig, servletContext, request, response);
}
} }
} }

View file

@ -0,0 +1,39 @@
/*
* Copyright (C) 2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.hooks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class InitServlet.
*/
public class InitServlet extends DirectServlet
{
private static final long serialVersionUID = -6057469263221296444L;
private static final Logger logger = LoggerFactory.getLogger(InitServlet.class);
/**
* Instantiates a new inits the servlet.
*/
public InitServlet()
{
super("/fr/devinsy/kiss4web/dispatcher/hooks/maintenance.xhtml");
}
}

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,18 +18,13 @@
*/ */
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.dispatcher.KissDispatcherFactory; import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
/** /**
* The Class LongURLHook. * The Class LongURLHook.
@ -46,8 +41,23 @@ public class LongURLHook extends HookCore
super(); super();
} }
/* (non-Javadoc) /**
* @see fr.devinsy.kiss4web.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) * {@inheritDoc}
*/
@Override
public String getServletClassName(final ServletConfig config, final HttpServletRequest request)
{
String result;
String urlPath = request.getPathInfo();
result = "website." + KissDispatcherUtils.translateToClassName(LongURLRewriter.unrewrite(urlPath));
//
return result;
}
/**
* {@inheritDoc}
*/ */
@Override @Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request) public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
@ -56,25 +66,17 @@ public class LongURLHook extends HookCore
String urlPath = request.getPathInfo(); String urlPath = request.getPathInfo();
result = LongURLRewriter.matches(urlPath); if (LongURLRewriter.matches(urlPath))
{
urlPath = ShortURLRewriter.unrewrite(urlPath);
result = KissDispatcherUtils.isAvailablePath(urlPath);
}
else
{
result = false;
}
// //
return result; return result;
} }
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException
{
logger.debug("Doing catch.");
String urlPath = request.getPathInfo();
String rewritedURLPath = LongURLRewriter.unrewrite(urlPath);
KissDispatcherFactory.instance().dispatchPathToServlet(servletConfig, request, response, rewritedURLPath);
}
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -21,12 +21,11 @@ package fr.devinsy.kiss4web.dispatcher.hooks;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringList;
import jakarta.servlet.http.HttpServletRequest;
/** /**
* The Class LongURLRewriter. * The Class LongURLRewriter.
@ -75,6 +74,11 @@ public class LongURLRewriter
* *
* Note: "-/" is used to indicate the beginning of parameters. * Note: "-/" is used to indicate the beginning of parameters.
* *
* @param path
* the path
* @param parameters
* the parameters
* @return the string
*/ */
public static String rewrite(final String path, final String... parameters) public static String rewrite(final String path, final String... parameters)
{ {
@ -102,6 +106,8 @@ public class LongURLRewriter
} }
/** /**
* This methods unrewrite a pathinfo.
*
* /catalog/article-/123/2016/12/14/resume.xhtml -> /catalog/article.xhtml * /catalog/article-/123/2016/12/14/resume.xhtml -> /catalog/article.xhtml
* *
* @param source * @param source

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2018-2021 Christian Pierre MOMON * Copyright (C) 2018-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -19,19 +19,13 @@
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.File; import java.io.File;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.xidyn.XidynException; import jakarta.servlet.ServletConfig;
import fr.devinsy.xidyn.presenters.URLPresenter; import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
/** /**
* The Class MaintenanceHook. * The Class MaintenanceHook.
@ -48,8 +42,22 @@ public class MaintenanceHook extends HookCore
super(); super();
} }
/* (non-Javadoc) /**
* @see fr.devinsy.kiss4web.kernel.dispatcher.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) * {@inheritDoc}
*/
@Override
public String getServletClassName(final ServletConfig config, final HttpServletRequest request)
{
String result;
result = "/fr/devinsy/kiss4web/dispatcher/hooks/MaintenanceServlet";
//
return result;
}
/**
* {@inheritDoc}
*/ */
@Override @Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request) public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
@ -68,33 +76,4 @@ public class MaintenanceHook extends HookCore
// //
return result; return result;
} }
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.dispatcher.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException
{
try
{
logger.debug("Doing catch {}.", this.getClass().getName());
String path = servletContext.getRealPath("/") + request.getPathInfo();
logger.info("path=[{}]", path);
StringBuffer html = new URLPresenter("/fr/devinsy/kiss4web/dispatcher/hooks/maintenance.xhtml").dynamize();
// Display page.
response.setContentType("application/xhtml+xml; charset=UTF-8");
response.getWriter().println(html);
logger.info("Application Init page returned.");
}
catch (XidynException exception)
{
exception.printStackTrace();
new FatalHook().process(servletConfig, servletContext, request, response);
}
}
} }

View file

@ -0,0 +1,39 @@
/*
* Copyright (C) 2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.hooks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class MaintenanceServlet.
*/
public class MaintenanceServlet extends DirectServlet
{
private static final long serialVersionUID = 1116048013331691997L;
private static final Logger logger = LoggerFactory.getLogger(MaintenanceServlet.class);
/**
* Instantiates a new maintenance servlet.
*/
public MaintenanceServlet()
{
super("/fr/devinsy/kiss4web/dispatcher/hooks/maintenance.xhtml");
}
}

View file

@ -0,0 +1,114 @@
/*
* Copyright (C) 2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.hooks;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
/**
* The Class RewriteHook.
*/
public class RewriteHook extends HookCore
{
private static Logger logger = LoggerFactory.getLogger(RewriteHook.class);
private Pattern pattern;
private String targetClassName;
/**
* Instantiates a new rewrite hook.
*
* @param regex
* the regex
* @param targetClassName
* the target class name
*/
public RewriteHook(final String regex, final String targetClassName)
{
super();
this.pattern = Pattern.compile(regex);
this.targetClassName = targetClassName;
}
/**
* Gets the servlet class path.
*
* @param config
* the config
* @param request
* the request
* @return the servlet class path
*/
@Override
public String getServletClassName(final ServletConfig config, final HttpServletRequest request)
{
String result;
result = this.targetClassName;
//
return result;
}
/**
* {@inheritDoc}
*/
@Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
{
boolean result;
String urlPath = request.getPathInfo();
if (this.pattern.matcher(urlPath).matches())
{
result = KissDispatcherUtils.isAvailablePath(this.targetClassName);
}
else
{
result = false;
}
//
return result;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString()
{
String result;
result = this.pattern.toString() + " -> " + this.targetClassName;
//
return result;
}
}

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,18 +18,13 @@
*/ */
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.dispatcher.KissDispatcherFactory; import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
/** /**
* The Class RootHook. * The Class RootHook.
@ -46,8 +41,28 @@ public class RootHook extends HookCore
super(); super();
} }
/* (non-Javadoc) /**
* @see fr.devinsy.kiss4web.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) * Gets the servlet class path.
*
* @param config
* the config
* @param request
* the request
* @return the servlet class path
*/
@Override
public String getServletClassName(final ServletConfig config, final HttpServletRequest request)
{
String result;
result = "website." + KissDispatcherUtils.translateToClassName("/index.xhtml");
//
return result;
}
/**
* {@inheritDoc}
*/ */
@Override @Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request) public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
@ -68,18 +83,4 @@ public class RootHook extends HookCore
// //
return result; return result;
} }
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException
{
logger.debug("Doing catch.");
String classPath = "index.xhtml";
KissDispatcherFactory.instance().dispatchPathToServlet(servletConfig, request, response, classPath);
}
} }

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,18 +18,13 @@
*/ */
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.dispatcher.KissDispatcherFactory; import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
/** /**
* The Class ShortURLHook. * The Class ShortURLHook.
@ -46,8 +41,27 @@ public class ShortURLHook extends HookCore
super(); super();
} }
/* (non-Javadoc) /**
* @see fr.devinsy.kiss4web.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) * {@inheritDoc}
*/
@Override
public String getServletClassName(final ServletConfig config, final HttpServletRequest request)
{
String result;
logger.debug("Doing catch.");
String urlPath = request.getPathInfo();
result = "website." + KissDispatcherUtils.translateToClassName(ShortURLRewriter.unrewrite(urlPath));
logger.info("rewritedURLPath={}", result);
//
return result;
}
/**
* {@inheritDoc}
*/ */
@Override @Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request) public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
@ -56,9 +70,10 @@ public class ShortURLHook extends HookCore
String urlPath = request.getPathInfo(); String urlPath = request.getPathInfo();
if ((ShortURLRewriter.matches(urlPath)) && (!KissDispatcherFactory.instance().isAvailablePath(urlPath))) if (ShortURLRewriter.matches(urlPath))
{ {
result = true; urlPath = ShortURLRewriter.unrewrite(urlPath);
result = KissDispatcherUtils.isAvailablePath(urlPath);
} }
else else
{ {
@ -68,21 +83,4 @@ public class ShortURLHook extends HookCore
// //
return result; return result;
} }
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException
{
logger.debug("Doing catch.");
String urlPath = request.getPathInfo();
String rewritedURLPath = ShortURLRewriter.unrewrite(urlPath);
logger.info("rewritedURLPath={}", rewritedURLPath);
KissDispatcherFactory.instance().dispatchPathToServlet(servletConfig, request, response, rewritedURLPath);
}
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -21,12 +21,11 @@ package fr.devinsy.kiss4web.dispatcher.hooks;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringList;
import jakarta.servlet.http.HttpServletRequest;
/** /**
* The Class ShortURLRewriter. * The Class ShortURLRewriter.
@ -184,6 +183,8 @@ public class ShortURLRewriter
} }
/** /**
* This method unrewrite a pathInfo.
*
* article.xhtm?id=123 -> article.xhtml * article.xhtm?id=123 -> article.xhtml
* *
* @param source * @param source

View file

@ -1,73 +0,0 @@
/**
* Copyright (C) 2006-2021 Christian Pierre MOMON
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class StatisticsHook.
*/
public class StatisticsHook extends HookCore
{
private static Logger logger = LoggerFactory.getLogger(StatisticsHook.class);
/**
* Instantiates a new statistics hook.
*/
public StatisticsHook()
{
super();
setTerminal(false);
}
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest)
*/
@Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
{
boolean result;
result = true;
//
return result;
}
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException
{
logger.debug("Doing catch.");
// TODO store statistics.
}
}

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -19,18 +19,13 @@
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.File; import java.io.File;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils; import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
/** /**
* The Class WebContentHook. * The Class WebContentHook.
@ -47,8 +42,22 @@ public class WebContentHook extends HookCore
super(); super();
} }
/* (non-Javadoc) /**
* @see fr.devinsy.kiss4web.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) * {@inheritDoc}
*/
@Override
public String getServletClassName(final ServletConfig servletConfig, final HttpServletRequest request)
{
String result;
result = WebContentServlet.class.getCanonicalName();
//
return result;
}
/**
* {@inheritDoc}
*/ */
@Override @Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request) public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
@ -68,22 +77,4 @@ public class WebContentHook extends HookCore
// //
return result; return result;
} }
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException
{
logger.debug("Doing catch.");
String path = servletContext.getRealPath("/") + request.getPathInfo();
logger.info("path=[{}]", path);
String mimeType = servletContext.getMimeType(path);
KissDispatcherUtils.returnInlineFile(response, new File(path), mimeType);
logger.info("File returned directly [{}] with mimetype [{}].", path, servletContext.getMimeType(path));
}
} }

View file

@ -0,0 +1,91 @@
/**
* Copyright (C) 2006-2024 Christian Pierre MOMON
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.File;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
* The Class WebContentServlet.
*/
public class WebContentServlet extends HttpServlet
{
private static final long serialVersionUID = 3203080393289058696L;
private static final Logger logger = LoggerFactory.getLogger(WebContentServlet.class);
/**
* Instantiates a new web content servlet.
*/
public WebContentServlet()
{
}
/**
* Dispatch.
*
* @param request
* the request
* @param response
* the response
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws ServletException
* the servlet exception
*/
public void dispatch(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
ServletContext context = this.getServletContext();
String path = context.getRealPath("/") + request.getPathInfo();
logger.info("path=[{}]", path);
String mimeType = context.getMimeType(path);
KissDispatcherUtils.returnInlineFile(response, new File(path), mimeType);
logger.info("File returned directly [{}] with mimetype [{}].", path, mimeType);
}
/**
* {@inheritDoc}
*/
@Override
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
dispatch(request, response);
}
/**
* {@inheritDoc}
*/
@Override
public void doPost(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
dispatch(request, response);
}
}

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -19,18 +19,13 @@
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.File; import java.io.File;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils; import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
/** /**
* The Class WebInfHook. * The Class WebInfHook.
@ -47,8 +42,21 @@ public class WebInfHook extends HookCore
super(); super();
} }
/* (non-Javadoc) /**
* @see fr.devinsy.kiss4web.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) * {@inheritDoc}
*/
@Override
public String getServletClassName(final ServletConfig servletConfig, final HttpServletRequest request)
{
String result;
result = WebInfServlet.class.getCanonicalName();
//
return result;
}
/**
* {@inheritDoc}
*/ */
@Override @Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request) public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
@ -69,22 +77,4 @@ public class WebInfHook extends HookCore
return result; return result;
} }
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException
{
logger.debug("Doing catch.");
String path = servletContext.getRealPath("/") + "WEB-INF/classes/website" + request.getPathInfo();
logger.info("path=[{}]", path);
String mimeType = servletContext.getMimeType(path);
KissDispatcherUtils.returnInlineFile(response, new File(path), mimeType);
logger.info("File returned directly [{}] with mimetype [{}].", path, servletContext.getMimeType(path));
}
} }

View file

@ -0,0 +1,92 @@
/*
* Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of Kiss4web.
*
* Kiss4web is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kiss4web is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Kiss4web. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.File;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
* The Class WebInfServlet.
*/
public class WebInfServlet extends HttpServlet
{
private static final long serialVersionUID = -6085589095239389710L;
private static final Logger logger = LoggerFactory.getLogger(WebInfServlet.class);
/**
* Instantiates a new web inf servlet.
*/
public WebInfServlet()
{
}
/**
* Dispatch.
*
* @param request
* the request
* @param response
* the response
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws ServletException
* the servlet exception
*/
public void dispatch(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
ServletContext context = this.getServletContext();
String path = context.getRealPath("/") + "WEB-INF/classes/website" + request.getPathInfo();
logger.info("path=[{}]", path);
String mimeType = context.getMimeType(path);
KissDispatcherUtils.returnInlineFile(response, new File(path), mimeType);
logger.info("File returned directly [{}] with mimetype [{}].", path, mimeType);
}
/**
* {@inheritDoc}
*/
@Override
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
dispatch(request, response);
}
/**
* {@inheritDoc}
*/
@Override
public void doPost(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
dispatch(request, response);
}
}

View file

@ -1,5 +1,5 @@
/** /*
* Copyright (C) 2006-2021 Christian Pierre MOMON * Copyright (C) 2006-2024 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of Kiss4web. * This file is part of Kiss4web.
* *
@ -18,18 +18,13 @@
*/ */
package fr.devinsy.kiss4web.dispatcher.hooks; package fr.devinsy.kiss4web.dispatcher.hooks;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.kiss4web.dispatcher.KissDispatcherFactory; import fr.devinsy.kiss4web.dispatcher.KissDispatcherUtils;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
/** /**
* The Class XHTMLHook. * The Class XHTMLHook.
@ -46,8 +41,22 @@ public class XHTMLHook extends HookCore
super(); super();
} }
/* (non-Javadoc) /**
* @see fr.devinsy.kiss4web.hooks.Hook#matches(javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest) * {@inheritDoc}
*/
@Override
public String getServletClassName(final ServletConfig servletConfig, final HttpServletRequest request)
{
String result;
result = "website." + KissDispatcherUtils.translateToClassName(request.getPathInfo());
//
return result;
}
/**
* {@inheritDoc}
*/ */
@Override @Override
public boolean matches(final ServletContext servletContext, final HttpServletRequest request) public boolean matches(final ServletContext servletContext, final HttpServletRequest request)
@ -68,18 +77,4 @@ public class XHTMLHook extends HookCore
// //
return result; return result;
} }
/* (non-Javadoc)
* @see fr.devinsy.kiss4web.hooks.Hook#process(javax.servlet.ServletConfig, javax.servlet.ServletContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void process(final ServletConfig servletConfig, final ServletContext servletContext, final HttpServletRequest request,
final HttpServletResponse response) throws IOException, ServletException
{
logger.debug("Doing catch.");
String urlPath = request.getPathInfo();
KissDispatcherFactory.instance().dispatchPathToServlet(servletConfig, request, response, urlPath);
}
} }

Some files were not shown because too many files have changed in this diff Show more