From 0c793e9c04c7c3ea63743eba94c8aea38f2f99a9 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sun, 23 Jun 2013 01:28:40 +0200 Subject: [PATCH] Normalize code in Devinsy style. Replace protected by private in declarations. --- .settings/org.eclipse.jdt.core.prefs | 280 +++ changelog.txt | 18 +- demo/XidDemo.java | 566 +++--- src/fr/devinsy/xid/Attributes.java | 69 +- src/fr/devinsy/xid/Data.java | 427 ++--- src/fr/devinsy/xid/DomPresenter.java | 130 +- src/fr/devinsy/xid/FilePresenter.java | 192 +- src/fr/devinsy/xid/FilePresenters.java | 63 +- src/fr/devinsy/xid/FilePresentersProxy.java | 52 +- src/fr/devinsy/xid/IdData.java | 193 +- src/fr/devinsy/xid/IdsDataById.java | 32 +- src/fr/devinsy/xid/IdsDataByIndex.java | 9 +- src/fr/devinsy/xid/ParserErrorHandler.java | 190 +- src/fr/devinsy/xid/Presenter.java | 1823 +++++++++---------- src/fr/devinsy/xid/StringPresenter.java | 118 +- test/XidTest.java | 25 +- 16 files changed, 2174 insertions(+), 2013 deletions(-) diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 8000cd6..c328801 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -9,3 +9,283 @@ org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.formatter.align_type_members_on_columns=false +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_assignment=0 +org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 +org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 +org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=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_resources_in_try=80 +org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 +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_type_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_union_type_in_multicatch=16 +org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_after_package=1 +org.eclipse.jdt.core.formatter.blank_lines_before_field=0 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 +org.eclipse.jdt.core.formatter.blank_lines_before_method=1 +org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 +org.eclipse.jdt.core.formatter.blank_lines_before_package=0 +org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 +org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 +org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=next_line +org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=next_line +org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block=next_line +org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=next_line +org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=next_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=next_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=next_line +org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=next_line +org.eclipse.jdt.core.formatter.brace_position_for_switch=next_line +org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=next_line +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false +org.eclipse.jdt.core.formatter.comment.format_block_comments=false +org.eclipse.jdt.core.formatter.comment.format_header=false +org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true +org.eclipse.jdt.core.formatter.comment.format_line_comments=true +org.eclipse.jdt.core.formatter.comment.format_source_code=true +org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true +org.eclipse.jdt.core.formatter.comment.indent_root_tags=true +org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert +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_javadoc_boundaries=true +org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false +org.eclipse.jdt.core.formatter.compact_else_if=true +org.eclipse.jdt.core.formatter.continuation_indentation=2 +org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 +org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off +org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on +org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false +org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true +org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_empty_lines=false +org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true +org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false +org.eclipse.jdt.core.formatter.indentation.size=4 +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=insert +org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=insert +org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=insert +org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=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_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert +org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=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_parameterized_type_reference=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_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert +org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.join_lines_in_comments=true +org.eclipse.jdt.core.formatter.join_wrapped_lines=true +org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false +org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false +org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false +org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false +org.eclipse.jdt.core.formatter.lineSplit=200 +org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false +org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 +org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true +org.eclipse.jdt.core.formatter.tabulation.char=tab +org.eclipse.jdt.core.formatter.tabulation.size=4 +org.eclipse.jdt.core.formatter.use_on_off_tags=false +org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false +org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true +org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true +org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true diff --git a/changelog.txt b/changelog.txt index d501773..7e2109b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,19 +1,25 @@ -v1.0.0: 01/10/2009 +== 2013-06 +Rename project. Clean files. Update build. + + +== v1.0.0: 01/10/2009 New version for: - Eclipse integration, - fr.devinsy.xid package rename. -V_006: 12/03/2007 +== V_006: 12/03/2007 Version used in DevinsyGes and maitress-admin. -V_003: 12/03/2006 +== 20061214, cpm, import dans svn sur https://www.ocmland.org/svn/Xid + +== V_004: 12/05/2006 + - + +== V_003: 12/03/2006 - add build.xml file - Vue class rename Presenter - debug of object tag - add webappPath capability -V_004: 12/05/2006 - - -20061214, cpm, import dans snv sur https://www.ocmland.org/svn/Xid diff --git a/demo/XidDemo.java b/demo/XidDemo.java index c514389..668b120 100644 --- a/demo/XidDemo.java +++ b/demo/XidDemo.java @@ -2,7 +2,9 @@ * XidDemo */ -import fr.devinsy.xid.*; +import fr.devinsy.xid.Data; +import fr.devinsy.xid.IdData; +import fr.devinsy.xid.StringPresenter; /** * @@ -10,297 +12,287 @@ import fr.devinsy.xid.*; class XidDemo { static - { - // Initialize logger. - org.apache.log4j.BasicConfigurator.configure (); + { + // Initialize logger. + org.apache.log4j.BasicConfigurator.configure(); - org.apache.log4j.Logger log = null; - log = org.apache.log4j.Logger.getRootLogger (); - log = org.apache.log4j.Logger.getLogger (XidDemo.class); - } + org.apache.log4j.Logger log = null; + log = org.apache.log4j.Logger.getRootLogger(); + log = org.apache.log4j.Logger.getLogger(XidDemo.class); + } - - /** + /** * */ - public static void main (String[] args) - { - System.out.println("Hello World!"); - - //test (); - - // - Data datas; - - - - // Step #01. + public static void main(final String[] args) { - System.out.println ("----------------------------"); - - // Populate attributes. - datas = new Data (); - datas.setContent ("name", "Superman"); - - String htmlSource = "
a name
"; - StringBuffer htmlTarget; - try - { - htmlTarget = StringPresenter.doXid (htmlSource, datas); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - htmlTarget = null; - } - System.out.println ("datas = new Data ();"); - System.out.println ("datas.setContent (\"name\", \"Superman\");"); - System.out.println ("+"); - System.out.println ("
a name
"); - System.out.println ("=>"); - System.out.println (htmlTarget); - System.out.println ("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]"); - } - - - // Step #02. - { - System.out.println ("----------------------------"); - // Populate attributes. - datas = new Data (); - datas.setContent ("lastname", "Spiderman"); - datas.appendAttribute ("lastname", "style", "background: blue;"); - datas.appendAttribute ("lastname", "style", "foreground: red;"); - datas.setAttribute ("lastname", "class", "nameClass"); - - String htmlSource = "
a last name
"; - StringBuffer htmlTarget; - try - { - htmlTarget = StringPresenter.doXid (htmlSource, datas); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - htmlTarget = null; - } - - System.out.println ("datas = new Data ();"); - System.out.println ("datas.setContent (\"lastname\", \"Spiderman\");"); - System.out.println ("datas.appendAttribute (\"lastname\", \"style\", \"background: blue;\");"); - System.out.println ("datas.appendAttribute (\"lastname\", \"style\", \"foreground: red;\");"); - System.out.println ("datas.setAttribute (\"lastname\", \"class\", \"nameClass\");"); - System.out.println ("+"); - System.out.println ("
a last name
"); - System.out.println ("=>"); - System.out.println (htmlTarget); - System.out.println ("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]"); - } - - - // Step #03. - { - System.out.println ("----------------------------"); - // Populate attributes. - datas = new Data (); - datas.setContent ("words", 0, "alpha"); - datas.setContent ("words", 1, "bravo"); - datas.setContent ("words", 2, "charlie"); - datas.setContent ("words", 3, "delta"); - datas.setContent ("words", 4, "echo"); - datas.setContent ("words", 5, "fox"); - - String htmlSource = ""; - StringBuffer htmlTarget; - try - { - htmlTarget = StringPresenter.doXid (htmlSource, datas); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - htmlTarget = null; - } - - System.out.println ("datas = new Data ();"); - System.out.println ("datas.setContent (\"words\", 0, \"alpha\");"); - System.out.println ("datas.setContent (\"words\", 1, \"bravo\");"); - System.out.println ("datas.setContent (\"words\", 2, \"charlie\");"); - System.out.println ("datas.setContent (\"words\", 3, \"delta\");"); - System.out.println ("datas.setContent (\"words\", 4, \"echo\");"); - System.out.println ("datas.setContent (\"words\", 5, \"fox\");"); - System.out.println ("+"); - System.out.println (""); - System.out.println ("=>"); - System.out.println (htmlTarget); - System.out.println ("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]"); - } - - - // Step #04. - { - System.out.println ("----------------------------"); - // Populate attributes. - datas = new Data (); - datas.setContent ("identity", 0, "last_name", "Jemba"); - datas.setContent ("identity", 0, "first_name", "Epo"); - datas.setContent ("identity", 1, "last_name", "Momon"); - datas.setContent ("identity", 1, "first_name", "Christian"); - datas.setContent ("identity", 2, "last_name", "Tronche"); - datas.setContent ("identity", 2, "first_name", "Christophe"); - - - StringBuffer source = new StringBuffer (); - source.append ("\n"); - source.append (" \n"); - source.append ("
noidJeanReve
"); - - String htmlSource = source.toString (); - StringBuffer htmlTarget; - try - { - htmlTarget = StringPresenter.doXid (htmlSource, datas); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - htmlTarget = null; - } - - System.out.println ("datas = new Data ();"); - System.out.println ("datas.setContent (\"identity\", 0, \"last_name\", \"Jemba\");"); - System.out.println ("datas.setContent (\"identity\", 0, \"first_name\", \"Epo\");"); - System.out.println ("datas.setContent (\"identity\", 1, \"last_name\", \"Momon\");"); - System.out.println ("datas.setContent (\"identity\", 1, \"first_name\", \"Christian\");"); - System.out.println ("datas.setContent (\"identity\", 2, \"last_name\", \"Tronche\");"); - System.out.println ("datas.setContent (\"identity\", 2, \"first_name\", \"Christophe\");"); - - System.out.println ("+"); - System.out.println (htmlSource); - System.out.println ("=>"); - System.out.println (htmlTarget); - System.out.println ("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]"); - } - - - // Step #05. - { - System.out.println ("----------------------------"); - // Populate attributes. - datas = new Data (); - datas.setContent ("identity", 0, "last_name", "Jemba"); - datas.setContent ("identity", 0, "first_name", "Epo"); - datas.setContent ("identity", 1, "last_name", "Momon"); - datas.setContent ("identity", 1, "first_name", "Christian"); - datas.setContent ("identity", 2, "last_name", "Tronche"); - datas.setContent ("identity", 2, "first_name", "Christophe"); - //datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID); - //datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID); - //datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ALL_ROWS); - - // - StringBuffer source = new StringBuffer (); - source.append ("\n"); - source.append (" \n"); - source.append (" \n"); - source.append (" \n"); - source.append (" \n"); - source.append ("
noidFirst NameLast Name
noidJeanReve
noida first namea last name
noida first name morea last name more
\n"); - String htmlSource = source.toString (); - - System.out.println ("datas = new Data ();"); - System.out.println ("datas.setContent (\"identity\", 0, \"first_name\", \"Epo\");"); - System.out.println ("datas.setContent (\"identity\", 0, \"last_name\", \"Jemba\");"); - System.out.println ("datas.setContent (\"identity\", 1, \"first_name\", \"Christian\");"); - System.out.println ("datas.setContent (\"identity\", 1, \"last_name\", \"Momon\");"); - System.out.println ("datas.setContent (\"identity\", 2, \"first_name\", \"Christophe\");"); - System.out.println ("datas.setContent (\"identity\", 2, \"last_name\", \"Tronche\");"); - - System.out.println ("+"); - System.out.println (htmlSource); - System.out.println ("=>"); - - - // #05.1 - datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_FIRST_ROW); - System.out.println ("ONLY_FIRST_ROW:"); - StringBuffer html; - try - { - html = StringPresenter.doXid (htmlSource, datas); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - html = null; - } - System.out.println (html); - System.out.println (""); - - - // #05.2 - datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_FIRST_TWO_ROWS); - System.out.println ("ONLY_FIRST_TWO_ROWS:"); - try - { - html = StringPresenter.doXid (htmlSource, datas); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - html = null; - } - System.out.println (html); - System.out.println (""); + System.out.println("Hello World!"); - - // #05.3 - datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_ROWS_WITH_ID); - System.out.println ("ONLY_ROWS_WITH_ID:"); - try - { - html = StringPresenter.doXid (htmlSource, datas); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - html = null; - } - System.out.println (html); - System.out.println (""); + // test (); - - // #05.4 - datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_ROWS_WITHOUT_ID); - System.out.println ("ONLY_ROWS_WITHOUT_ID:"); - try - { - html = StringPresenter.doXid (htmlSource, datas); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - html = null; - } - System.out.println (html); - System.out.println (""); - - - // #05.5 - datas.setIterationStrategy ("identities", IdData.IterationStrategy.ALL_ROWS); - System.out.println ("ALL_ROWS:"); - try - { - html = StringPresenter.doXid (htmlSource, datas); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - html = null; - } - System.out.println (html); - } - } + // + Data datas; + + // Step #01. + { + System.out.println("----------------------------"); + + // Populate attributes. + datas = new Data(); + datas.setContent("name", "Superman"); + + String htmlSource = "
a name
"; + StringBuffer htmlTarget; + try + { + htmlTarget = StringPresenter.doXid(htmlSource, datas); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + htmlTarget = null; + } + System.out.println("datas = new Data ();"); + System.out.println("datas.setContent (\"name\", \"Superman\");"); + System.out.println("+"); + System.out.println("
a name
"); + System.out.println("=>"); + System.out.println(htmlTarget); + System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]"); + } + + // Step #02. + { + System.out.println("----------------------------"); + // Populate attributes. + datas = new Data(); + datas.setContent("lastname", "Spiderman"); + datas.appendAttribute("lastname", "style", "background: blue;"); + datas.appendAttribute("lastname", "style", "foreground: red;"); + datas.setAttribute("lastname", "class", "nameClass"); + + String htmlSource = "
a last name
"; + StringBuffer htmlTarget; + try + { + htmlTarget = StringPresenter.doXid(htmlSource, datas); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + htmlTarget = null; + } + + System.out.println("datas = new Data ();"); + System.out.println("datas.setContent (\"lastname\", \"Spiderman\");"); + System.out.println("datas.appendAttribute (\"lastname\", \"style\", \"background: blue;\");"); + System.out.println("datas.appendAttribute (\"lastname\", \"style\", \"foreground: red;\");"); + System.out.println("datas.setAttribute (\"lastname\", \"class\", \"nameClass\");"); + System.out.println("+"); + System.out.println("
a last name
"); + System.out.println("=>"); + System.out.println(htmlTarget); + System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]"); + } + + // Step #03. + { + System.out.println("----------------------------"); + // Populate attributes. + datas = new Data(); + datas.setContent("words", 0, "alpha"); + datas.setContent("words", 1, "bravo"); + datas.setContent("words", 2, "charlie"); + datas.setContent("words", 3, "delta"); + datas.setContent("words", 4, "echo"); + datas.setContent("words", 5, "fox"); + + String htmlSource = ""; + StringBuffer htmlTarget; + try + { + htmlTarget = StringPresenter.doXid(htmlSource, datas); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + htmlTarget = null; + } + + System.out.println("datas = new Data ();"); + System.out.println("datas.setContent (\"words\", 0, \"alpha\");"); + System.out.println("datas.setContent (\"words\", 1, \"bravo\");"); + System.out.println("datas.setContent (\"words\", 2, \"charlie\");"); + System.out.println("datas.setContent (\"words\", 3, \"delta\");"); + System.out.println("datas.setContent (\"words\", 4, \"echo\");"); + System.out.println("datas.setContent (\"words\", 5, \"fox\");"); + System.out.println("+"); + System.out.println(""); + System.out.println("=>"); + System.out.println(htmlTarget); + System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]"); + } + + // Step #04. + { + System.out.println("----------------------------"); + // Populate attributes. + datas = new Data(); + datas.setContent("identity", 0, "last_name", "Jemba"); + datas.setContent("identity", 0, "first_name", "Epo"); + datas.setContent("identity", 1, "last_name", "Momon"); + datas.setContent("identity", 1, "first_name", "Christian"); + datas.setContent("identity", 2, "last_name", "Tronche"); + datas.setContent("identity", 2, "first_name", "Christophe"); + + StringBuffer source = new StringBuffer(); + source.append("\n"); + source.append(" \n"); + source.append("
noidJeanReve
"); + + String htmlSource = source.toString(); + StringBuffer htmlTarget; + try + { + htmlTarget = StringPresenter.doXid(htmlSource, datas); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + htmlTarget = null; + } + + System.out.println("datas = new Data ();"); + System.out.println("datas.setContent (\"identity\", 0, \"last_name\", \"Jemba\");"); + System.out.println("datas.setContent (\"identity\", 0, \"first_name\", \"Epo\");"); + System.out.println("datas.setContent (\"identity\", 1, \"last_name\", \"Momon\");"); + System.out.println("datas.setContent (\"identity\", 1, \"first_name\", \"Christian\");"); + System.out.println("datas.setContent (\"identity\", 2, \"last_name\", \"Tronche\");"); + System.out.println("datas.setContent (\"identity\", 2, \"first_name\", \"Christophe\");"); + + System.out.println("+"); + System.out.println(htmlSource); + System.out.println("=>"); + System.out.println(htmlTarget); + System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]"); + } + + // Step #05. + { + System.out.println("----------------------------"); + // Populate attributes. + datas = new Data(); + datas.setContent("identity", 0, "last_name", "Jemba"); + datas.setContent("identity", 0, "first_name", "Epo"); + datas.setContent("identity", 1, "last_name", "Momon"); + datas.setContent("identity", 1, "first_name", "Christian"); + datas.setContent("identity", 2, "last_name", "Tronche"); + datas.setContent("identity", 2, "first_name", "Christophe"); + // datas.setIterationStrategy ("identity", + // IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID); + // datas.setIterationStrategy ("identity", + // IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID); + // datas.setIterationStrategy ("identity", + // IdsDataByIndex.IterationStrategy.ALL_ROWS); + + // + StringBuffer source = new StringBuffer(); + source.append("\n"); + source.append(" \n"); + source.append(" \n"); + source.append(" \n"); + source.append(" \n"); + source.append("
noidFirst NameLast Name
noidJeanReve
noida first namea last name
noida first name morea last name more
\n"); + String htmlSource = source.toString(); + + System.out.println("datas = new Data ();"); + System.out.println("datas.setContent (\"identity\", 0, \"first_name\", \"Epo\");"); + System.out.println("datas.setContent (\"identity\", 0, \"last_name\", \"Jemba\");"); + System.out.println("datas.setContent (\"identity\", 1, \"first_name\", \"Christian\");"); + System.out.println("datas.setContent (\"identity\", 1, \"last_name\", \"Momon\");"); + System.out.println("datas.setContent (\"identity\", 2, \"first_name\", \"Christophe\");"); + System.out.println("datas.setContent (\"identity\", 2, \"last_name\", \"Tronche\");"); + + System.out.println("+"); + System.out.println(htmlSource); + System.out.println("=>"); + + // #05.1 + datas.setIterationStrategy("identities", IdData.IterationStrategy.ONLY_FIRST_ROW); + System.out.println("ONLY_FIRST_ROW:"); + StringBuffer html; + try + { + html = StringPresenter.doXid(htmlSource, datas); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + html = null; + } + System.out.println(html); + System.out.println(""); + + // #05.2 + datas.setIterationStrategy("identities", IdData.IterationStrategy.ONLY_FIRST_TWO_ROWS); + System.out.println("ONLY_FIRST_TWO_ROWS:"); + try + { + html = StringPresenter.doXid(htmlSource, datas); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + html = null; + } + System.out.println(html); + System.out.println(""); + + // #05.3 + datas.setIterationStrategy("identities", IdData.IterationStrategy.ONLY_ROWS_WITH_ID); + System.out.println("ONLY_ROWS_WITH_ID:"); + try + { + html = StringPresenter.doXid(htmlSource, datas); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + html = null; + } + System.out.println(html); + System.out.println(""); + + // #05.4 + datas.setIterationStrategy("identities", IdData.IterationStrategy.ONLY_ROWS_WITHOUT_ID); + System.out.println("ONLY_ROWS_WITHOUT_ID:"); + try + { + html = StringPresenter.doXid(htmlSource, datas); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + html = null; + } + System.out.println(html); + System.out.println(""); + + // #05.5 + datas.setIterationStrategy("identities", IdData.IterationStrategy.ALL_ROWS); + System.out.println("ALL_ROWS:"); + try + { + html = StringPresenter.doXid(htmlSource, datas); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + html = null; + } + System.out.println(html); + } + } } diff --git a/src/fr/devinsy/xid/Attributes.java b/src/fr/devinsy/xid/Attributes.java index 98b2caf..5259fe1 100644 --- a/src/fr/devinsy/xid/Attributes.java +++ b/src/fr/devinsy/xid/Attributes.java @@ -1,74 +1,59 @@ package fr.devinsy.xid; -import java.util.*; - - - +import java.util.HashMap; /** - * - * Note: no more AttrValue as in Brill, because the exception of style is managed - * in the attribute merging on the "style" string detection. + * + * Note: no more AttrValue as in Brill, because the exception of style is + * managed in the attribute merging on the "style" string detection. */ public class Attributes extends HashMap { private static final long serialVersionUID = 2802739066295665336L; - - /* - * + /** + * */ - public Attributes () + public Attributes() { - super (); + super(); } - - /* + /** * Useful for the merge attributes. */ - public Attributes (Attributes attributes) + public Attributes(final Attributes attributes) { - super (attributes); + super(attributes); } - - /* - * + /** + * Add a value to an existing value. This is useful to the 'style' + * attribute. + * */ - public void setAttribute (String label, String value) + public void appendAttribute(final String label, final String value) { - this.put (label, value); - } - - - /* - * Add a value to an existing value. This is useful to the 'style' attribute. - * - */ - public void appendAttribute (String label, String value) - { - if (this.containsKey (label)) + if (this.containsKey(label)) { - this.put (label, this.get (label) + value); + this.put(label, this.get(label) + value); } else { - this.put (label, value); + this.put(label, value); } } - - /* + /** * */ - public String getAttribute (String label) + public String getAttribute(final String label) { String result; - if (this.containsKey (label)) + if (this.containsKey(label)) { - result = this.get (label); + result = this.get(label); } else { @@ -79,4 +64,12 @@ public class Attributes extends HashMap return (result); } + /** + * + */ + public void setAttribute(final String label, final String value) + { + this.put(label, value); + } + } diff --git a/src/fr/devinsy/xid/Data.java b/src/fr/devinsy/xid/Data.java index 2c28212..893b36a 100644 --- a/src/fr/devinsy/xid/Data.java +++ b/src/fr/devinsy/xid/Data.java @@ -1,27 +1,178 @@ package fr.devinsy.xid; - /* * */ public class Data { - protected IdsDataById idsDataById; - + private IdsDataById idsDataById; /** * */ - public Data () + public Data() { - this.idsDataById = new IdsDataById (); + this.idsDataById = new IdsDataById(); } + /** + * + */ + public void appendAttribute(final String id, final int line, final String column, final String label, final String value) + { + IdData tag = this.getIdData(id, line, column); + + tag.attributes().appendAttribute(label, value); + } /** * */ - public IdsDataById getIdsDataById () + public void appendAttribute(final String id, final String label, final int value) + { + appendAttribute(id, label, (new Integer(value)).toString()); + } + + /** + * + */ + public void appendAttribute(final String id, final String label, final String value) + { + IdData tag = this.getIdData(id); + + tag.attributes().appendAttribute(label, value); + } + + /** + * + */ + public void appendContent(final String id, final int line, final int value) + { + appendContent(id, line, (new Integer(value)).toString()); + } + + /** + * + */ + public void appendContent(final String id, final int line, final String value) + { + IdData tag = this.getIdData(id, line); + + tag.appendContent(value); + } + + /** + * + */ + public void appendContent(final String id, final int line, final String column, final int value) + { + appendContent(id, line, column, (new Integer(value)).toString()); + } + + /** + * + */ + public void appendContent(final String id, final int line, final String column, final String value) + { + IdData tag = this.getIdData(id, line, column); + + tag.appendContent(value); + } + + /** + * + */ + public IdData getIdData(final String id) + { + IdData result; + + // Be sure that IdData is existing and get item. + result = (IdData) this.idsDataById.getId(id); + + if (result == null) + { + this.idsDataById.setId(id, new IdData()); + + result = (IdData) this.idsDataById.getId(id); + } + + // + return (result); + } + + /** + * + */ + public IdData getIdData(final String id, final int line) + { + IdData result; + + // Be sure that IdsData are existing. + IdsDataByIndex tags = (IdsDataByIndex) this.idsDataById.getId(id); + if (tags == null) + { + this.idsDataById.setId(id, new IdsDataByIndex()); + + tags = (IdsDataByIndex) this.idsDataById.getId(id); + } + + // Be sure that lines are existing. + int nbLines = tags.size(); + for (int nLine = nbLines; nLine < line + 1; nLine++) + { + tags.add(nLine, new IdData()); + } + + // Get item. + result = (IdData) tags.elementAt(line); + + // + return (result); + } + + /** + * + */ + public IdData getIdData(final String id, final int line, final String column) + { + IdData result; + + // Be sure that IdsData are existing. + IdsDataByIndex tags = (IdsDataByIndex) this.idsDataById.getId(id); + if (tags == null) + { + this.idsDataById.setId(id, new IdsDataByIndex()); + + tags = (IdsDataByIndex) this.idsDataById.getId(id); + } + + // Be sure that lines are existing. + int nbLines = tags.size(); + for (int nLine = nbLines; nLine < line + 1; nLine++) + { + tags.add(nLine, new IdsDataById()); + } + + // Get item. + IdsDataById lineData = (IdsDataById) tags.elementAt(line); + + result = (IdData) lineData.get(column); + + if (result == null) + { + lineData.put(column, new IdData()); + + result = (IdData) lineData.get(column); + } + + // + return (result); + } + + /** + * + */ + public IdsDataById getIdsDataById() { IdsDataById result; @@ -31,311 +182,131 @@ public class Data return (result); } + /** + * + */ + public void setAttribute(final String id, final int line, final String label, final int value) + { + setAttribute(id, line, label, (new Integer(value)).toString()); + } /** * */ - public IdData getIdData (String id) + public void setAttribute(final String id, final int line, final String label, final String value) { - IdData result; + IdData tag = this.getIdData(id, line); - // Be sure that IdData is existing and get item. - result = (IdData) this.idsDataById.getId (id); - - if (result == null) - { - this.idsDataById.setId (id, new IdData ()); - - result = (IdData) this.idsDataById.getId (id); - } - - - // - return (result); + tag.attributes().setAttribute(label, value); } - /** * */ - public IdData getIdData (String id, int line) + public void setAttribute(final String id, final int line, final String column, final String label, final int value) { - IdData result; - - // Be sure that IdsData are existing. - IdsDataByIndex tags = (IdsDataByIndex) this.idsDataById.getId (id); - if (tags == null) - { - this.idsDataById.setId (id, new IdsDataByIndex ()); - - tags = (IdsDataByIndex) this.idsDataById.getId (id); - } - - // Be sure that lines are existing. - int nbLines = tags.size (); - for (int nLine = nbLines; nLine < line + 1; nLine++) - { - tags.add (nLine, new IdData ()); - } - - // Get item. - result = (IdData) tags.elementAt (line); - - // - return (result); + setAttribute(id, line, column, label, (new Integer(value)).toString()); } - /** * */ - public IdData getIdData (String id, int line, String column) + public void setAttribute(final String id, final int line, final String column, final String label, final String value) { - IdData result; + IdData tag = this.getIdData(id, line, column); - // Be sure that IdsData are existing. - IdsDataByIndex tags = (IdsDataByIndex) this.idsDataById.getId (id); - if (tags == null) - { - this.idsDataById.setId (id, new IdsDataByIndex ()); - - tags = (IdsDataByIndex) this.idsDataById.getId (id); - } - - // Be sure that lines are existing. - int nbLines = tags.size (); - for (int nLine = nbLines; nLine < line + 1; nLine++) - { - tags.add (nLine, new IdsDataById ()); - } - - // Get item. - IdsDataById lineData = (IdsDataById) tags.elementAt (line); - - result = (IdData) lineData.get (column); - - if (result == null) - { - lineData.put (column, new IdData ()); - - result = (IdData) lineData.get (column); - } - - // - return (result); + tag.attributes().setAttribute(label, value); } - /** * */ - public void setIterationStrategy (String id, IdData.IterationStrategy strategy) + public void setAttribute(final String id, final String label, final int value) { - IdData tag = (IdData) this.getIdData (id); - - tag.setIterationStrategy (strategy); + setAttribute(id, label, (new Integer(value)).toString()); } - - /** * */ - public void setContent (String id, String content) + public void setAttribute(final String id, final String label, final String value) { - IdData idData = this.getIdData (id); + IdData tag = this.getIdData(id); - idData.setContent (content); + tag.attributes().setAttribute(label, value); } - /** * */ - public void setContent (String id, int content) + public void setContent(final String id, final int content) { - setContent (id, (new Integer (content)).toString ()); + setContent(id, (new Integer(content)).toString()); } - /** * */ - public void setContent (String id, int line, String content) + public void setContent(final String id, final int line, final int content) { - IdData tag = this.getIdData (id, line); - - tag.setContent (content); + setContent(id, line, (new Integer(content)).toString()); } - /** * */ - public void setContent (String id, int line, int content) + public void setContent(final String id, final int line, final String content) { - setContent (id, line, (new Integer (content)).toString ()); - } + IdData tag = this.getIdData(id, line); + tag.setContent(content); + } /** * */ - public void setContent (String id, int line, String column, String content) + public void setContent(final String id, final int line, final String column, final int content) { - IdData tag = this.getIdData (id, line, column); - - tag.setContent (content); + setContent(id, line, column, (new Integer(content)).toString()); } - - /** - * - */ - public void setContent (String id, int line, String column, int content) - { - setContent (id, line, column, (new Integer (content)).toString ()); - } - - /** * @TODO */ - public void setContent (String id, int line, String subId, int subLine, String column, String content) + public void setContent(final String id, final int line, final String subId, final int subLine, final String column, final String content) { // IdData tag = this.getIdData (id, line, subId, subLine, column); - //tag.setContent (content); + // tag.setContent (content); } - - /** - * - */ - public void setAttribute (String id, String label, String value) - { - IdData tag = this.getIdData (id); - - tag.attributes ().setAttribute (label, value); - } - - /** * */ - public void setAttribute (String id, String label, int value) + public void setContent(final String id, final int line, final String column, final String content) { - setAttribute (id, label, (new Integer (value)).toString ()); - } + IdData tag = this.getIdData(id, line, column); + tag.setContent(content); + } /** * */ - public void setAttribute (String id, int line, String label, String value) + public void setContent(final String id, final String content) { - IdData tag = this.getIdData (id, line); + IdData idData = this.getIdData(id); - tag.attributes ().setAttribute (label, value); + idData.setContent(content); } - /** * */ - public void setAttribute (String id, int line, String label, int value) + public void setIterationStrategy(final String id, final IdData.IterationStrategy strategy) { - setAttribute (id, line, label, (new Integer (value)).toString ()); - } + IdData tag = this.getIdData(id); - - /** - * - */ - public void setAttribute (String id, int line, String column, String label, String value) - { - IdData tag = this.getIdData (id, line, column); - - tag.attributes ().setAttribute (label, value); - } - - - /** - * - */ - public void setAttribute (String id, int line, String column, String label, int value) - { - setAttribute (id, line, column, label, (new Integer (value)).toString ()); - } - - - /** - * - */ - public void appendAttribute (String id, int line, String column, String label, String value) - { - IdData tag = this.getIdData (id, line, column); - - tag.attributes ().appendAttribute (label, value); - } - - - /** - * - */ - public void appendAttribute (String id, String label, String value) - { - IdData tag = this.getIdData (id); - - tag.attributes ().appendAttribute (label, value); - } - - - /** - * - */ - public void appendAttribute (String id, String label, int value) - { - appendAttribute (id, label, (new Integer (value)).toString ()); - } - - - /** - * - */ - public void appendContent (String id, int line, String value) - { - IdData tag = this.getIdData (id, line); - - tag.appendContent (value); - } - - - /** - * - */ - public void appendContent (String id, int line, int value) - { - appendContent (id, line, (new Integer (value)).toString ()); - } - - - /** - * - */ - public void appendContent (String id, int line, String column, String value) - { - IdData tag = this.getIdData (id, line, column); - - tag.appendContent (value); - } - - - /** - * - */ - public void appendContent (String id, int line, String column, int value) - { - appendContent (id, line, column, (new Integer (value)).toString ()); + tag.setIterationStrategy(strategy); } } diff --git a/src/fr/devinsy/xid/DomPresenter.java b/src/fr/devinsy/xid/DomPresenter.java index f3a2fb1..2cb2e8b 100644 --- a/src/fr/devinsy/xid/DomPresenter.java +++ b/src/fr/devinsy/xid/DomPresenter.java @@ -1,8 +1,8 @@ package fr.devinsy.xid; import java.io.StringWriter; -import org.w3c.dom.Document; +import org.w3c.dom.Document; /** * @@ -11,32 +11,29 @@ public class DomPresenter extends Presenter { static final public char INDEX_SEPARATOR = '_'; - static protected org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (DomPresenter.class); + static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(DomPresenter.class); protected Document doc; - /* - * - */ - public DomPresenter () - { - this.doc = null; - } - - - /* - * - */ - public DomPresenter (Document doc) - { - this.doc = doc; - DomPresenter.addMetaTag (this.doc, "generator", "XID 0.0"); - } - - /** * */ - public Document dom () + public DomPresenter() + { + this.doc = null; + } + + /** + * + */ + public DomPresenter(final Document doc) + { + setSource(doc); + } + + /** + * + */ + public Document dom() { Document result; @@ -46,31 +43,61 @@ public class DomPresenter extends Presenter return (result); } + /** + * + */ + public StringBuffer doXid(final Data datas) throws Exception + { + return (doXid(datas.getIdsDataById())); + } /** * */ - public void setDom (Document doc) + public StringBuffer doXid(final IdsDataById datas) throws Exception + { + StringBuffer result; + + if (this.doc == null) + { + String errorMessage = "source not defined"; + logger.error(errorMessage); + result = null; + throw new Exception(errorMessage); + } + else + { + // Build the web page. + StringWriter htmlCode = new StringWriter(); + Presenter.doXid(htmlCode, this.doc, datas); + result = new StringBuffer(htmlCode.toString()); + } + + // + return (result); + } + + /** + * + */ + public void setDom(final Document doc) { this.doc = doc; } - /* * */ - public void setSource (Document doc) + public void setSource(final Document doc) { this.doc = doc; - - Presenter.addMetaTag (this.doc, "generator", "XID 0.0"); + addMetaTag(this.doc, "generator", "XID 0.0"); } - - /* + /** * */ - public Object source () + public Object source() { Object result; @@ -80,52 +107,15 @@ public class DomPresenter extends Presenter return (result); } - - /* - * - */ - public StringBuffer doXid (Data datas) throws Exception - { - return (doXid (datas.getIdsDataById ())); - } - - - /* - * - */ - public StringBuffer doXid (IdsDataById datas) throws Exception - { - StringBuffer result; - - if (this.doc == null) - { - String errorMessage = "source not defined"; - logger.error (errorMessage); - result = null; - throw new Exception (errorMessage); - } - else - { - // Build the web page. - StringWriter htmlCode = new StringWriter(); - Presenter.doXid (htmlCode, this.doc, datas); - result = new StringBuffer (htmlCode.toString()); - } - - // - return (result); - } - - - /* + /** * Xid a file with data. */ - static public StringBuffer doXid (Document doc, IdsDataById datas) throws Exception + static public StringBuffer doXid(final Document doc, final IdsDataById datas) throws Exception { StringBuffer result; StringWriter htmlCode = new StringWriter(); - Presenter.process (htmlCode, doc, datas); + Presenter.process(htmlCode, doc, datas); result = htmlCode.getBuffer(); // diff --git a/src/fr/devinsy/xid/FilePresenter.java b/src/fr/devinsy/xid/FilePresenter.java index 1619bac..6226193 100644 --- a/src/fr/devinsy/xid/FilePresenter.java +++ b/src/fr/devinsy/xid/FilePresenter.java @@ -5,22 +5,21 @@ import java.io.File; import java.io.FileReader; import java.io.StringWriter; - /** * */ public class FilePresenter extends DomPresenter { - static protected org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (FilePresenter.class); + static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(FilePresenter.class); - protected String sourceFilePathname; - protected long sourceFileTime; - protected String doctype; + private String sourceFilePathname; + private long sourceFileTime; + private String doctype; - /* + /** * */ - public FilePresenter () + public FilePresenter() { this.sourceFilePathname = null; this.sourceFileTime = 0; @@ -28,11 +27,10 @@ public class FilePresenter extends DomPresenter this.doctype = ""; } - - /* + /** * */ - public FilePresenter (String filePathname) + public FilePresenter(final String filePathname) { this.sourceFilePathname = filePathname; this.sourceFileTime = 0; @@ -40,11 +38,62 @@ public class FilePresenter extends DomPresenter this.doctype = ""; } - - /* + /** * */ - public void setSource (String filePathname) + @Override + public StringBuffer doXid(final Data datas) throws Exception + { + return (doXid(datas.getIdsDataById())); + } + + /** + * No need to be synchronized. + */ + @Override + public StringBuffer doXid(final IdsDataById datas) throws Exception + { + StringBuffer result; + + logger.info("doXid for file [" + this.sourceFilePathname + "]"); + + // Get the good tree. + File source = new File(this.sourceFilePathname); + + if (!source.exists()) + { + String errorMessage = "source file defined but not found (" + this.sourceFilePathname + ")"; + logger.error(errorMessage); + result = null; + throw new Exception(errorMessage); + } + else if ((this.doc == null) || (this.sourceFileTime != source.lastModified())) + { + this.sourceFileTime = source.lastModified(); + this.doc = Presenter.fileToTree(this.sourceFilePathname); + this.doctype = getDoctype(this.sourceFilePathname); + if (this.doc != null) + { + Presenter.addMetaTag(doc, "generator", "XID 0.0"); + } + } + + // Build the web page. + StringWriter htmlCode = new StringWriter(Presenter.estimatedTargetLength(source.length())); + htmlCode.write(doctype); + htmlCode.write('\n'); + + Presenter.doXid(htmlCode, doc, datas); + result = htmlCode.getBuffer(); + + // + return (result); + } + + /** + * + */ + public void setSource(final String filePathname) { this.sourceFilePathname = filePathname; this.sourceFileTime = 0; @@ -52,11 +101,11 @@ public class FilePresenter extends DomPresenter this.doctype = ""; } - - /* + /** * */ - public String source () + @Override + public String source() { String result; @@ -66,74 +115,55 @@ public class FilePresenter extends DomPresenter return (result); } - - /* - * + /** + * Xid a file without data. */ - public StringBuffer doXid (Data datas) throws Exception - { - return (doXid (datas.getIdsDataById ())); - } - - - /* - * No need to be synchronized. - */ - public StringBuffer doXid (IdsDataById datas) throws Exception + static public StringBuffer doXid(final String filePathname) throws Exception { StringBuffer result; - logger.info("doXid for file [" + this.sourceFilePathname + "]"); - - // Get the good tree. - File source = new File (this.sourceFilePathname); + FilePresenter presenter = new FilePresenter(filePathname); - if (!source.exists ()) - { - String errorMessage = "source file defined but not found (" + this.sourceFilePathname + ")"; - logger.error (errorMessage); - result = null; - throw new Exception (errorMessage); - } - else if ((this.doc == null) || - (this.sourceFileTime != source.lastModified ())) - { - this.sourceFileTime = source.lastModified (); - this.doc = Presenter.fileToTree (this.sourceFilePathname); - this.doctype = getDoctype(this.sourceFilePathname); - if (this.doc != null) - { - Presenter.addMetaTag (doc, "generator", "XID 0.0"); - } - } - - // Build the web page. - StringWriter htmlCode = new StringWriter(Presenter.estimatedTargetLength(source.length())); - htmlCode.write(doctype); - htmlCode.write('\n'); - - Presenter.doXid (htmlCode, doc, datas); - result = htmlCode.getBuffer(); + result = presenter.doXid((Data) null); // return (result); } + /** + * Xid a file. + */ + static public StringBuffer doXid(final String filePathname, final Data datas) throws Exception + { + StringBuffer result; - static public String getDoctype (String filePathname) throws Exception + FilePresenter presenter = new FilePresenter(filePathname); + + result = presenter.doXid(datas); + + // + return (result); + } + + /** + * + * @param filePathname + * @return + * @throws Exception + */ + static public String getDoctype(final String filePathname) throws Exception { String result; // - BufferedReader in = new BufferedReader (new FileReader (filePathname)); + BufferedReader in = new BufferedReader(new FileReader(filePathname)); String doctype = in.readLine(); in.close(); - + logger.info("doctype=[" + doctype + "]"); - + // - if ((doctype.startsWith (" { private static final long serialVersionUID = 7058868685681354293L; - static protected org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (FilePresenters.class); - + static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(FilePresenters.class); /** * */ - public FilePresenters () + public FilePresenters() { - super (); + super(); } - /** * */ - public FilePresenters (FilePresenters source) + public FilePresenters(final FilePresenters source) { - super (); + super(); for (FilePresenter presenter : source) { this.add(presenter); } } - /** * */ - public boolean exists (String source) + public boolean exists(final String source) { boolean result; - - + if (this.getBySource(source) == null) { result = false; @@ -57,33 +51,31 @@ public class FilePresenters extends Vector { result = true; } - + // - return(result); + return (result); } - /** * */ - public FilePresenter getByIndex (int id) + public FilePresenter getByIndex(final int id) { FilePresenter result; result = this.get(id); - + // - return(result); + return (result); } - /** * */ - public FilePresenter getBySource (String source) + public FilePresenter getBySource(final String source) { FilePresenter result; - + if (source == null) { result = null; @@ -98,7 +90,7 @@ public class FilePresenters extends Vector if (presenterIndex < this.size()) { FilePresenter presenter = this.get(presenterIndex); - + if (presenter.source().equals(source)) { result = presenter; @@ -116,19 +108,18 @@ public class FilePresenters extends Vector } } } - + // - return(result); + return (result); } - /** * */ - public int getIndexOf (String source) + public int getIndexOf(final String source) { int result; - + if (source == null) { result = -1; @@ -143,7 +134,7 @@ public class FilePresenters extends Vector if (presenterIndex < this.size()) { FilePresenter presenter = this.get(presenterIndex); - + if (presenter.source().equals(source)) { result = presenterIndex; @@ -161,23 +152,23 @@ public class FilePresenters extends Vector } } } - - // - return(result); - } + // + return (result); + } /** * */ + @Override public String toString() { String result; - + result = ""; - + // - return(result); + return (result); } } diff --git a/src/fr/devinsy/xid/FilePresentersProxy.java b/src/fr/devinsy/xid/FilePresentersProxy.java index 275acb3..3c9d929 100644 --- a/src/fr/devinsy/xid/FilePresentersProxy.java +++ b/src/fr/devinsy/xid/FilePresentersProxy.java @@ -1,52 +1,30 @@ package fr.devinsy.xid; - /** * */ public class FilePresentersProxy { - static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger (FilePresentersProxy.class); - + static private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(FilePresentersProxy.class); private static FilePresentersProxy instance = null; - protected FilePresenters presenters = null; + private FilePresenters presenters = null; /** * */ - protected FilePresentersProxy () throws Exception + protected FilePresentersProxy() throws Exception { this.presenters = new FilePresenters(); } - /** * */ - public static FilePresentersProxy instance () throws Exception - { - FilePresentersProxy result; - - if (FilePresentersProxy.instance == null) - { - instance = new FilePresentersProxy (); - } - - result = instance; - - // - return (result); - } - - - /** - * - */ - public FilePresenter getBySource(String source) throws Exception + public FilePresenter getBySource(final String source) throws Exception { FilePresenter result; - + if (source == null) { result = null; @@ -60,7 +38,25 @@ public class FilePresentersProxy this.presenters.add(result); } } - + + // + return (result); + } + + /** + * + */ + public static FilePresentersProxy instance() throws Exception + { + FilePresentersProxy result; + + if (FilePresentersProxy.instance == null) + { + instance = new FilePresentersProxy(); + } + + result = instance; + // return (result); } diff --git a/src/fr/devinsy/xid/IdData.java b/src/fr/devinsy/xid/IdData.java index d7fbde8..51d4a91 100644 --- a/src/fr/devinsy/xid/IdData.java +++ b/src/fr/devinsy/xid/IdData.java @@ -2,38 +2,42 @@ package fr.devinsy.xid; import java.io.Serializable; - /** - * IdData class is used to hold application data and - * the business logic that operates on the data. - * - * The only requirement of a IdData class is that it must implement a - * display method. The display method must return a text representation - * of the data, suitable for display in a web page. - * - * XID provides a User Input IdData, Text IdData and ... - * application may also implement it's own IdData classes. - * + * IdData class is used to hold application data and the business logic that + * operates on the data. + * + * The only requirement of a IdData class is that it must implement a display + * method. The display method must return a text representation of the data, + * suitable for display in a web page. + * + * XID provides a User Input IdData, Text IdData and ... application may also + * implement it's own IdData classes. + * */ public class IdData implements Serializable, IdDataCore { - private static final long serialVersionUID = 8976245034682639923L; + public enum IterationStrategy + { + ONLY_FIRST_ROW, ONLY_FIRST_TWO_ROWS, ONLY_ROWS_WITH_ID, ONLY_ROWS_WITHOUT_ID, ALL_ROWS + } + public enum MODE + { + REPLACE, APPEND, IGNORE + } - public enum IterationStrategy {ONLY_FIRST_ROW, ONLY_FIRST_TWO_ROWS, ONLY_ROWS_WITH_ID, ONLY_ROWS_WITHOUT_ID, ALL_ROWS} + private static final long serialVersionUID = 8976245034682639923L;; - public enum MODE {REPLACE, APPEND, IGNORE}; + private IterationStrategy iterationStrategy; + private Attributes attributes; + private boolean excludeSection; + private MODE displayMode = MODE.REPLACE; + private String content; - protected IterationStrategy iterationStrategy; - protected Attributes attributes; - protected boolean excludeSection; - protected MODE displayMode = MODE.REPLACE; - protected String content; - - /* + /** * */ - public IdData () + public IdData() { this.attributes = null; this.excludeSection = false; @@ -42,11 +46,10 @@ public class IdData implements Serializable, IdDataCore this.iterationStrategy = IterationStrategy.ALL_ROWS; } - - /* + /** * */ - public IdData (String text) + public IdData(final String text) { this.attributes = null; this.excludeSection = false; @@ -55,34 +58,10 @@ public class IdData implements Serializable, IdDataCore this.iterationStrategy = IterationStrategy.ALL_ROWS; } - - /* + /** * */ - public String display () - { - String result; - - result = this.content; - - // - return (result); - } - - - /* - * - */ - public void setContent (String text) - { - this.content = text; - } - - - /* - * - */ - public void appendContent (String text) + public void appendContent(final String text) { if (this.content == null) { @@ -94,17 +73,38 @@ public class IdData implements Serializable, IdDataCore } } - - /* + /** * */ - public void setDisplayMode(MODE displayMode) + public Attributes attributes() { - this.displayMode = displayMode; + Attributes result; + + if (this.attributes == null) + { + this.attributes = new Attributes(); + } + + result = this.attributes; + + // + return (result); } + /** + * + */ + public String display() + { + String result; - /* + result = this.content; + + // + return (result); + } + + /** * */ public MODE displayMode() @@ -116,62 +116,23 @@ public class IdData implements Serializable, IdDataCore return (result); } - - /* - * - */ - public Attributes attributes () - { - Attributes result; - - if (this.attributes == null) - { - this.attributes = new Attributes (); - } - - result = this.attributes; - - // - return (result); - } - - - /* - * - */ - public void setExcludeSection(boolean excludeSection) - { - this.excludeSection = excludeSection; - } - - - /* + /** * */ public boolean excludeSection() { boolean result; - + result = excludeSection; - + // - return(result); + return (result); } - /** * */ - public void setIterationStrategy (IterationStrategy strategy) - { - this.iterationStrategy = strategy; - } - - - /** - * - */ - public IterationStrategy iterationStrategy () + public IterationStrategy iterationStrategy() { IterationStrategy result; @@ -180,4 +141,36 @@ public class IdData implements Serializable, IdDataCore // return (result); } + + /** + * + */ + public void setContent(final String text) + { + this.content = text; + } + + /** + * + */ + public void setDisplayMode(final MODE displayMode) + { + this.displayMode = displayMode; + } + + /** + * + */ + public void setExcludeSection(final boolean excludeSection) + { + this.excludeSection = excludeSection; + } + + /** + * + */ + public void setIterationStrategy(final IterationStrategy strategy) + { + this.iterationStrategy = strategy; + } } diff --git a/src/fr/devinsy/xid/IdsDataById.java b/src/fr/devinsy/xid/IdsDataById.java index e1ec7c4..c0d4193 100644 --- a/src/fr/devinsy/xid/IdsDataById.java +++ b/src/fr/devinsy/xid/IdsDataById.java @@ -1,8 +1,8 @@ package fr.devinsy.xid; -import java.util.*; +import java.util.HashMap; -/* +/** * */ public class IdsDataById extends HashMap implements IdDataCore @@ -10,33 +10,33 @@ public class IdsDataById extends HashMap implements IdDataCo private static final long serialVersionUID = -5787252043825503554L; - /* + /** * */ - public IdsDataById () + public IdsDataById() { - super (); + super(); } - /* + /** * */ - public void setId (String id, IdDataCore data) - { - this.put (id, data); - } - - /* - * - */ - public IdDataCore getId (String id) + public IdDataCore getId(final String id) { IdDataCore result; - result = this.get (id); + result = this.get(id); // return (result); } + /** + * + */ + public void setId(final String id, final IdDataCore data) + { + this.put(id, data); + } + } diff --git a/src/fr/devinsy/xid/IdsDataByIndex.java b/src/fr/devinsy/xid/IdsDataByIndex.java index c47e1b2..9b0aecf 100644 --- a/src/fr/devinsy/xid/IdsDataByIndex.java +++ b/src/fr/devinsy/xid/IdsDataByIndex.java @@ -1,9 +1,8 @@ package fr.devinsy.xid; -import java.util.*; +import java.util.Vector; - -/* +/** * */ public class IdsDataByIndex extends Vector implements IdDataCore @@ -14,8 +13,8 @@ public class IdsDataByIndex extends Vector implements IdDataCore /** * */ - public IdsDataByIndex () + public IdsDataByIndex() { - super (); + super(); } } diff --git a/src/fr/devinsy/xid/ParserErrorHandler.java b/src/fr/devinsy/xid/ParserErrorHandler.java index 675def3..70ee36a 100644 --- a/src/fr/devinsy/xid/ParserErrorHandler.java +++ b/src/fr/devinsy/xid/ParserErrorHandler.java @@ -1,36 +1,96 @@ package fr.devinsy.xid; -import org.xml.sax.*; -import java.util.*; +import java.util.Vector; + +import org.xml.sax.ErrorHandler; +import org.xml.sax.SAXParseException; /** - * Extract from org.xml.sax Interface ErrorHandler: - * "If a SAX application needs to implement customized error handling, - * it must implement this interface and then register an instance with - * the XML reader using the setErrorHandler method. The parser will - * then report all errors and warnings through this interface." - * + * Extract from org.xml.sax Interface ErrorHandler: "If a SAX application needs + * to implement customized error handling, it must implement this interface and + * then register an instance with the XML reader using the setErrorHandler + * method. The parser will then report all errors and warnings through this + * interface." + * */ public class ParserErrorHandler implements ErrorHandler { - Vector messages; - int fatalErrorsCount; - int errorsCount; - int warningCount; + private Vector messages; + private int fatalErrorsCount; + private int errorsCount; + private int warningCount; - public ParserErrorHandler () + public ParserErrorHandler() { fatalErrorsCount = 0; errorsCount = 0; warningCount = 0; - messages = new Vector (); + messages = new Vector(); } - /** * */ - public int fatalErrorsCount () + public int allErrorsCount() + { + int result; + + result = fatalErrorsCount() + errorsCount() + warningCount(); + + // + return (result); + } + + /** + * Called by the XML parser to handle fatal errors. + * + * @param ex + * Parse Excpetion. Contains the warning text and the line + * number. + */ + @Override + public void error(final SAXParseException exception) + { + String message = "Error at line " + exception.getLineNumber() + " : " + exception.getMessage(); + + this.errorsCount += 1; + this.messages.add(message); + } + + /** + * + */ + public int errorsCount() + { + int result; + + result = this.errorsCount; + + // + return (result); + } + + /** + * Called by the XML parser to handle fatal errors. + * + * @param ex + * Parse Excpetion. Contains the error text and the line number. + * When a fatal parse error occurs, the parse does not return a + * document. + */ + @Override + public void fatalError(final SAXParseException exception) + { + String message = "Fatal error at line " + exception.getLineNumber() + " : " + exception.getMessage(); + + this.fatalErrorsCount += 1; + this.messages.add(message); + } + + /** + * + */ + public int fatalErrorsCount() { int result; @@ -43,50 +103,11 @@ public class ParserErrorHandler implements ErrorHandler /** * */ - public int errorsCount () - { - int result; - - result = this.errorsCount; - - // - return (result); - } - - /** - * - */ - public int warningCount () - { - int result; - - result = this.warningCount; - - // - return (result); - } - - /** - * - */ - public int allErrorsCount () - { - int result; - - result = fatalErrorsCount () + errorsCount () + warningCount (); - - // - return (result); - } - - /** - * - */ - public boolean hasError () + public boolean hasError() { boolean result; - if (allErrorsCount () == 0) + if (allErrorsCount() == 0) { result = false; } @@ -99,61 +120,52 @@ public class ParserErrorHandler implements ErrorHandler return (result); } - /** - * Called by the XML parser to handle fatal errors. - * @param ex Parse Excpetion. Contains the warning text and the line number. + * */ - public void error (SAXParseException exception) + @Override + public String toString() { - String message = "Error at line " + exception.getLineNumber() + " : " + exception.getMessage(); + StringBuffer result; - this.errorsCount += 1; - this.messages.add (message); - } + result = new StringBuffer(); - /** - * Called by the XML parser to handle fatal errors. - * @param ex Parse Excpetion. Contains the error text and the line number. - * When a fatal parse error occurs, the parse does not return a document. - */ - public void fatalError (SAXParseException exception) - { - String message = "Fatal error at line " + exception.getLineNumber() + " : " + exception.getMessage(); + for (String message : messages) + { + result.append(message); + result.append('\n'); + } - this.fatalErrorsCount += 1; - this.messages.add (message); + // + return (result.toString()); } /** * Called by the XML parser to handle warnings. - * @param ex Parse Excpetion. Contains the warning text and the line number. + * + * @param ex + * Parse Excpetion. Contains the warning text and the line + * number. */ - public void warning(SAXParseException exception) + @Override + public void warning(final SAXParseException exception) { String message = "Warning at line " + exception.getLineNumber() + " : " + exception.getMessage(); this.warningCount += 1; - this.messages.add (message); + this.messages.add(message); } - /** * */ - public String toString () + public int warningCount() { - StringBuffer result; + int result; - result = new StringBuffer (); - - for (String message : messages) - { - result.append (message); - result.append ('\n'); - } + result = this.warningCount; // - return (result.toString ()); + return (result); } } diff --git a/src/fr/devinsy/xid/Presenter.java b/src/fr/devinsy/xid/Presenter.java index cf22d66..c0b3eec 100644 --- a/src/fr/devinsy/xid/Presenter.java +++ b/src/fr/devinsy/xid/Presenter.java @@ -1,6 +1,5 @@ package fr.devinsy.xid; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -9,10 +8,12 @@ import java.io.Writer; import java.util.HashMap; import java.util.Iterator; import java.util.Map; + import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.validation.Schema; + import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.DocumentType; @@ -21,7 +22,6 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; - /** * */ @@ -29,675 +29,22 @@ public class Presenter { static final public char INDEX_SEPARATOR = '_'; - static protected org.apache.log4j.Logger logger; + static private org.apache.log4j.Logger logger; static - { - logger = org.apache.log4j.Logger.getLogger (Presenter.class); - } - - - /* - * Xid a file with data. - */ - static public void doXid (Writer result, Document doc, IdsDataById datas) throws Exception { - Presenter.process (result, doc, datas); + logger = org.apache.log4j.Logger.getLogger(Presenter.class); } - - /* - * - */ - static public String getClassAttributeValue (Node node) - { - String result; - - NamedNodeMap attributes = node.getAttributes (); - if (attributes == null) - { - result = null; - } - else - { - Node nameAttribute = attributes.getNamedItem ("class"); - - if (nameAttribute == null) - { - result = null; - } - else - { - result = nameAttribute.getNodeValue (); - } - } - - // - return (result); - } - - /** * */ - static public Attributes mergeAttributes (Attributes target, Attributes source) - { - Attributes result; - - // - if (target == null) - { - result = source; - } - else if (source == null) - { - result = target; - } - else - { - result = new Attributes (target); - - Iterator> iterator = source.entrySet().iterator(); - - while (iterator.hasNext()) - { - Map.Entry attribute = iterator.next(); - - String currentValue = target.get (attribute.getKey ()); - - if (currentValue == null) - { - result.put (attribute.getKey (), attribute.getValue ()); - } - else if (attribute.getKey ().equals ("style")) - { - result.put (attribute.getKey (), currentValue + attribute.getValue ()); - } - else - { - result.put (attribute.getKey (), attribute.getValue ()); - } - } - } - - // - return (result); - } - - - /* - * - */ - static protected void processChildren (Writer result, Node node, IdsDataById datas) throws Exception - { - processChildren (result, node, datas, ""); - } - - - /* - * - */ - static protected void processChildren (Writer result, Node node, IdsDataById datas, String suffix) throws Exception - { - // Get the iteration strategy. - IdData.IterationStrategy strategy; - - NamedNodeMap attributes = node.getAttributes (); - if (attributes == null) - { - strategy = IdData.IterationStrategy.ALL_ROWS; - } - else - { - Node id = attributes.getNamedItem ("id"); - - if (id == null) - { - strategy = IdData.IterationStrategy.ALL_ROWS; - } - else - { - IdDataCore dataCore = datas.getId (id.getNodeValue ()); - if (dataCore == null) - { - strategy = IdData.IterationStrategy.ALL_ROWS; - } - else if (dataCore instanceof IdData) - { - IdData data = (IdData) dataCore; - strategy = data.iterationStrategy (); - } - else - { - strategy = IdData.IterationStrategy.ALL_ROWS; - } - } - } - - - // Iterate. - NodeList children = node.getChildNodes(); - int childrenCount = children.getLength (); - - switch (strategy) - { - case ONLY_FIRST_ROW: - int lineCounter = 0; - for (int childIndex = 0; childIndex < childrenCount; childIndex++) - { - if (children.item (childIndex).getNodeType () == Node.ELEMENT_NODE) - { - lineCounter += 1; - if (lineCounter == 1) - { - process (result, children.item (childIndex), datas, suffix); - } - } - else - { - process (result, children.item (childIndex), datas, suffix); - } - } - break; - - case ONLY_FIRST_TWO_ROWS: - lineCounter = 0; - for (int childIndex = 0; childIndex < childrenCount; childIndex++) - { - if (children.item (childIndex).getNodeType () == Node.ELEMENT_NODE) - { - lineCounter += 1; - - if ((lineCounter == 1) || (lineCounter == 2)) - { - process (result, children.item (childIndex), datas, suffix); - } - } - else - { - process (result, children.item (childIndex), datas, suffix); - } - } - break; - - case ONLY_ROWS_WITH_ID: - for (int childIndex = 0; childIndex < childrenCount; childIndex++) - { - if (children.item (childIndex).getNodeType () == Node.ELEMENT_NODE) - { - NamedNodeMap attrs2 = children.item (childIndex).getAttributes (); - - if ((attrs2 != null) && - (attrs2.getNamedItem ("id") != null)) - { - process (result, children.item (childIndex), datas, suffix); - } - } - else - { - process (result, children.item (childIndex), datas, suffix); - } - } - break; - - case ONLY_ROWS_WITHOUT_ID: - for (int childIndex = 0; childIndex < childrenCount; childIndex++) - { - if (children.item (childIndex).getNodeType () == Node.ELEMENT_NODE) - { - NamedNodeMap attrs2 = children.item (childIndex).getAttributes (); - if ((attrs2 == null) || - (attrs2.getNamedItem ("id") == null)) - { - process (result, children.item(childIndex), datas, suffix); - } - } - else - { - process (result, children.item (childIndex), datas, suffix); - } - } - break; - - case ALL_ROWS: - for (int childIndex = 0; childIndex < childrenCount; childIndex++) - { - process (result, children.item(childIndex), datas, suffix); - } - break; - } - } - - - /** - * Processes a node that has dynamic content. Calls the appropriate code - * generator method, depending on the tag. - * - * @param node - * Current node. - * @param attrs - * The tag attributes. - * @param idAttr - * The ID. - */ - static protected void processElementWithId (Writer result, Node node, NamedNodeMap attrs, Node idAttr, IdsDataById datas) throws Exception - - { - processElementWithId (result, node, attrs, idAttr, datas, ""); - } - - - /** - * Processes a node that has dynamic content. Calls the appropriate code - * generator method, depending on the tag. - * - * @param node - * Current node. - * @param attrs - * The tag attributes. - * @param idAttr - * The ID. - */ - static protected void processElementWithId (Writer result, Node node, NamedNodeMap attrs, Node idAttr, IdsDataById datas, String suffix) throws Exception - { - String tag = node.getNodeName(); - - // String idValue = idAttr.getNodeValue(); - - logger.debug ("tag=" + tag); - - // Get data of this id. - IdDataCore dataCore = datas.get (idAttr.getNodeValue ()); - - if (dataCore == null) - { - Presenter.processElementBasically (result, node, datas, suffix); - } - else if (dataCore instanceof IdData) - { - IdData data = (IdData) dataCore; - - String theClass = data.attributes ().getAttribute ("class"); - - if ((theClass == null) || - (!theClass.equals ("xid:nodisplay"))) - { - // Open the tag. - result.append ("<"); - result.append (node.getNodeName()); - - // Build attributes. - result.append (processAttributes (attrs, data.attributes (), suffix)); - - if ((node.getChildNodes () == null) && - ((data == null) || (data.display () == null))) - { - // Close the tag. - result.append (" />"); - } - else - { - result.append ('>'); - - // CHANGED, cpm: - - // Insert data. - if ((data == null) || - (data.display () == null)) - { - processChildren (result, node, datas, suffix); - } - else - { - result.append (data.display ()); - } - - // Close the tag. - result.append ("'); - } - } - } - else if (dataCore instanceof IdsDataByIndex) - { - IdsDataByIndex tags = (IdsDataByIndex) dataCore; - - int nbLines = tags.size (); - for (int nLine = 0; nLine < nbLines; nLine++) - { - if (tags.elementAt (nLine) instanceof IdData) - { - IdData data = (IdData) tags.elementAt (nLine); - - // Open the tag. - result.append ("<"); - result.append (node.getNodeName()); - - result.append (processAttributes (attrs, data.attributes (), Integer.toString (nLine))); - - if ((node.getChildNodes () == null) && - ((data == null) || (data.display () == null))) - { - // Close the tag. - result.append (" />\n"); - } - else - { - result.append ('>'); - - - // CHANGED, cpm - - // Insert data. - if ((data == null) || (data.display () == null)) - { - processChildren (result, node, datas, suffix); - } - else - { - result.append (data.display ()); - } - - // Close the tag. - result.append ("\n"); - } - } - else - { - // Manage a Hashmap. - IdsDataById data = (IdsDataById) tags.elementAt (nLine); - - Presenter.processElementWithId (result, node, attrs, idAttr, data, Integer.toString (nLine)); - result.append ('\n'); - } - } - } - else - { - logger.warn ("Unknow type of IdDataId"); - } - - // - logger.debug ("Exit"); - } - - - - /** - * - */ - static protected void process (Writer result, Node node, IdsDataById datas) throws Exception - { - Presenter.process (result, node, datas, ""); - } - - - /** - * Recursive method that processes a node and any child nodes. - * - */ - static protected void process (Writer result, Node node, IdsDataById datas, String suffix) throws Exception - { - logger.debug ("process - started"); - String TRANSITIONAL_DTD = "xhtml1-transitional.dtd"; - String TRANSITIONAL_DOCTYPE = "\n"; - - // Is there anything to do? - if (node != null) - { - logger.debug ("nodeName=" + node.getNodeName ()); - // Find the name attribute value. - String name; - name = getClassAttributeValue (node); - - if ((name == null) || - ((name != null) && - (!name.equals ("xid:nodisplay")))) - { - int type = node.getNodeType(); - switch (type) - { - case Node.DOCUMENT_NODE: - { - logger.debug ("case Node.DOCUMENT_NODE"); - DocumentType dt = ((Document) node).getDoctype(); - - if (dt != null) - { - // String publicId = dt.getPublicId(); - String systemId = dt.getSystemId(); - - if (systemId.equals(TRANSITIONAL_DTD)) - { - result.append(TRANSITIONAL_DOCTYPE); - } - - // Log.write(Log.TRACE,"publicId = " + publicId); - // Log.write(Log.TRACE,"systemId = " + systemId); - } - - Presenter.process (result, ((Document) node).getDocumentElement(), datas, suffix); - - break; - } - - case Node.ELEMENT_NODE: - { - logger.debug ("case Node.ELEMENT_NODE"); - - NamedNodeMap attrs = node.getAttributes (); - Node idAttr = attrs.getNamedItem ("id"); - - if (idAttr != null) - { - Presenter.processElementWithId (result, node, attrs, idAttr, datas, suffix); - } - else - { - Presenter.processElementBasically (result, node, datas, suffix); - } - - break; - } - - // handle entity reference nodes - case Node.ENTITY_REFERENCE_NODE: - { - logger.debug ("case Node.ENTITY_REFERENCE_NODE"); - - result.append ('&'); - result.append (node.getNodeName()); - result.append (';'); - break; - } - - // print cdata sections - case Node.CDATA_SECTION_NODE: - { - logger.debug ("case Node.CDATA_SECTION_NODE"); - - result.append (""); - - break; - } - - // print text - case Node.TEXT_NODE: - { - logger.debug ("case Node.TEXTE_NODE"); - result.append (restoreEntities (new StringBuffer(node.getNodeValue()))); - break; - } - - // print processing instruction - case Node.PROCESSING_INSTRUCTION_NODE: - { - logger.debug ("Node.PROCESSING_INSTRUCTION_NODE"); - - result.append (" 0)) - { - result.append (' '); - result.append (data); - } - result.append ("?>"); - break; - } - } - } - } - - // - //logger.info ("result=" + result); - logger.debug ("process - ended"); - } - - - /* - * - */ - static void processElementBasically (Writer result, Node node, IdsDataById datas) throws Exception - { - processElementBasically (result, node, datas, ""); - } - - - /* - * - */ - static void processElementBasically (Writer result, Node node, IdsDataById datas, String suffix) throws Exception - { - logger.debug("processElementBasically - started"); - - // Open the tag. - result.append ('<'); - result.append (node.getNodeName()); - - - // Build the tag attributes. - //Attributes tagAttributes; - - result.append (processAttributes (node.getAttributes (), - null, - suffix)); - - // - if (node.getChildNodes () == null) - { - result.append(" />"); - } - else - { - result.append('>'); - - processChildren (result, node, datas, suffix); - - result.append("'); - } - - logger.debug("processElementBasically - ended"); - } - - - - /* - * - */ - static protected Document buildTree (InputStream source) throws Exception - { - Document result; - - try - { - // Create a DocumentBuilderFactory and configure it. - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance (); - - // Set various configuration options. - dbf.setValidating (true); - dbf.setIgnoringComments (true); - dbf.setIgnoringElementContentWhitespace (false); - dbf.setCoalescing (false); - - // Keep entity references as they are. - dbf.setExpandEntityReferences(false); - - // Create a DocumentBuilder that satisfies the constraints - // specified by the DocumentBuilderFactory. - DocumentBuilder db = dbf.newDocumentBuilder (); - - ParserErrorHandler errorHandler; - errorHandler = new ParserErrorHandler(); - - // Set the error handler. - db.setErrorHandler (errorHandler); - - Schema schema = db.getSchema (); - - logger.debug ("schema=" + schema); - - // Parse the input file. - result = db.parse (source); - - if (errorHandler.hasError ()) - { - // Most time, error is (with StringPresenter): - // "Error at line 1 : Document root element "html", must match DOCTYPE root "null". - // Error at line 1 : Document is invalid: no grammar found. - // We ignore it. STU - logger.debug(errorHandler.toString ()); - } - else - { - DomPresenter.addMetaTag (result, "generator", "XID 0.0"); - } - } - catch (ParserConfigurationException exception) - { - String errorMessage = "Parser configuration exception: " + exception.getMessage (); - logger.error (errorMessage); - result = null; - throw new Exception (errorMessage, exception); - } - catch (SAXException exception) - { - String errorMessage = "Error during SAX parsing: " + exception.getMessage (); - logger.error (errorMessage); - result = null; - throw new Exception (errorMessage, exception); - } - catch (IOException exception) - { - String errorMessage = "IOError during parsing." + exception.getMessage (); - logger.error (errorMessage); - result = null; - throw new Exception (errorMessage, exception); - } - - // - return (result); - } - - - - /* - * - */ - static protected void addMetaTag (Document doc, String name, String content) + static protected void addMetaTag(final Document doc, final String name, final String content) { // Find head tag. - Node headNode = Presenter.findHeadNode (doc); + Node headNode = Presenter.findHeadNode(doc); - Node metaNode = doc.createElement ("meta"); + Node metaNode = doc.createElement("meta"); NamedNodeMap attrMap = metaNode.getAttributes(); Node attrNode = doc.createAttribute("name"); @@ -710,6 +57,169 @@ public class Presenter headNode.insertBefore(metaNode, headNode.getFirstChild()); } + /** + * + */ + static protected Document buildTree(final InputStream source) throws Exception + { + Document result; + + try + { + // Create a DocumentBuilderFactory and configure it. + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + + // Set various configuration options. + dbf.setValidating(true); + dbf.setIgnoringComments(true); + dbf.setIgnoringElementContentWhitespace(false); + dbf.setCoalescing(false); + + // Keep entity references as they are. + dbf.setExpandEntityReferences(false); + + // Create a DocumentBuilder that satisfies the constraints + // specified by the DocumentBuilderFactory. + DocumentBuilder db = dbf.newDocumentBuilder(); + + ParserErrorHandler errorHandler; + errorHandler = new ParserErrorHandler(); + + // Set the error handler. + db.setErrorHandler(errorHandler); + + Schema schema = db.getSchema(); + + logger.debug("schema=" + schema); + + // Parse the input file. + result = db.parse(source); + + if (errorHandler.hasError()) + { + // Most time, error is (with StringPresenter): + // "Error at line 1 : Document root element "html", must match DOCTYPE root "null". + // Error at line 1 : Document is invalid: no grammar found. + // We ignore it. STU + logger.debug(errorHandler.toString()); + } + else + { + DomPresenter.addMetaTag(result, "generator", "XID 0.0"); + } + } + catch (ParserConfigurationException exception) + { + String errorMessage = "Parser configuration exception: " + exception.getMessage(); + logger.error(errorMessage); + result = null; + throw new Exception(errorMessage, exception); + } + catch (SAXException exception) + { + String errorMessage = "Error during SAX parsing: " + exception.getMessage(); + logger.error(errorMessage); + result = null; + throw new Exception(errorMessage, exception); + } + catch (IOException exception) + { + String errorMessage = "IOError during parsing." + exception.getMessage(); + logger.error(errorMessage); + result = null; + throw new Exception(errorMessage, exception); + } + + // + return (result); + } + + /** + * Xid a file with data. + */ + static public void doXid(final Writer result, final Document doc, final IdsDataById datas) throws Exception + { + Presenter.process(result, doc, datas); + } + + /** + * Good estimation of the target length able to optimize performance. + */ + static int estimatedTargetLength(final long sourceLength) + { + int result; + + if (sourceLength < 1000) + { + result = (int) (sourceLength * 5); + } + else if (sourceLength < 50000) + { + result = (int) (sourceLength * 2); + } + else if (sourceLength < 800000) + { + result = (100000); + } + else + { + result = (int) (sourceLength + 30000); + } + + // + return (result); + } + + /** + * + */ + static public String extractBodyContent(final StringBuffer data) + { + String result = null; + + // Extract the body content. + String dataLowerCase = data.toString().toLowerCase(); + + int startBody = dataLowerCase.indexOf(""); + int endBody = dataLowerCase.indexOf(""); + + // Note: as failed search is improbable, no care about complexity + // in failed search case. + if ((startBody == -1) || (endBody == -1)) + { + result = null; + } + else + { + result = data.substring(startBody + 6, endBody).trim(); + } + + // + return (result); + } + + /** + * Define in Presenter cause needs this possibility. + */ + static protected Document fileToTree(final String fileName) throws Exception + { + Document result; + + try + { + result = buildTree(new FileInputStream(new File(fileName))); + } + catch (IOException exception) + { + String errorMessage = "IOError during parsing." + exception.getMessage(); + logger.error(errorMessage); + result = null; + throw new Exception(errorMessage, exception); + } + + // + return (result); + } /** * Finds the node containing the <head> tag. @@ -718,7 +228,7 @@ public class Presenter * Document node. * @return The head tag node */ - static protected Node findHeadNode (Node node) + static protected Node findHeadNode(final Node node) { Node headNode = null; @@ -746,13 +256,17 @@ public class Presenter int numChildren = 0; if (children != null) + { numChildren = children.getLength(); + } for (int i = 0; i < numChildren; i++) { headNode = findHeadNode(children.item(i)); if (headNode != null) + { break; + } } break; } @@ -760,15 +274,730 @@ public class Presenter return headNode; } + /** + * + */ + static public String getClassAttributeValue(final Node node) + { + String result; + + NamedNodeMap attributes = node.getAttributes(); + if (attributes == null) + { + result = null; + } + else + { + Node nameAttribute = attributes.getNamedItem("class"); + + if (nameAttribute == null) + { + result = null; + } + else + { + result = nameAttribute.getNodeValue(); + } + } + + // + return (result); + } + + /** + * Get the text for an element. Converts new lines to spaces. + * + * @param node + */ + static protected String getElementText(final Node node) + { + String result; + result = ""; // Grrrr, Java ... + + NodeList children = node.getChildNodes(); + if (children == null) + { + result = ""; + } + else + { + boolean ended = false; + int childCounter = 0; + int childCount = children.getLength(); + while (!ended) + { + if (childCounter >= childCount) + { + ended = true; + result = ""; + } + else + { + Node child = children.item(childCounter); + if (child.getNodeType() == Node.TEXT_NODE) + { + result = newLinesToSpaces(child.getNodeValue()); // STU + // (+=, + // newLines...) + ended = true; + } + else + { + childCounter += 1; + } + } + } + } + + // + return (result); + } + + /** + * + */ + static public Attributes mergeAttributes(final Attributes target, final Attributes source) + { + Attributes result; + + // + if (target == null) + { + result = source; + } + else if (source == null) + { + result = target; + } + else + { + result = new Attributes(target); + + Iterator> iterator = source.entrySet().iterator(); + + while (iterator.hasNext()) + { + Map.Entry attribute = iterator.next(); + + String currentValue = target.get(attribute.getKey()); + + if (currentValue == null) + { + result.put(attribute.getKey(), attribute.getValue()); + } + else if (attribute.getKey().equals("style")) + { + result.put(attribute.getKey(), currentValue + attribute.getValue()); + } + else + { + result.put(attribute.getKey(), attribute.getValue()); + } + } + } + + // + return (result); + } + + /** + * Converts New Line characters to spaces. This is used when for example the + * text in a div tag goes over serveral lines. + * + * @param text + * String + * @return String + */ + static protected String newLinesToSpaces(final String text) + { + StringBuffer result = new StringBuffer(text); + + for (int i = 0; i < result.length(); i++) + { + if (result.charAt(i) == '\n') + { + result.setCharAt(i, ' '); + } + } + + // + return (result.toString()); + } + + /** + * + */ + static protected void process(final Writer result, final Node node, final IdsDataById datas) throws Exception + { + Presenter.process(result, node, datas, ""); + } + + /** + * Recursive method that processes a node and any child nodes. + * + */ + static protected void process(final Writer result, final Node node, final IdsDataById datas, final String suffix) throws Exception + { + logger.debug("process - started"); + String TRANSITIONAL_DTD = "xhtml1-transitional.dtd"; + String TRANSITIONAL_DOCTYPE = "\n"; + + // Is there anything to do? + if (node != null) + { + logger.debug("nodeName=" + node.getNodeName()); + // Find the name attribute value. + String name; + name = getClassAttributeValue(node); + + if ((name == null) || ((name != null) && (!name.equals("xid:nodisplay")))) + { + int type = node.getNodeType(); + switch (type) + { + case Node.DOCUMENT_NODE: + { + logger.debug("case Node.DOCUMENT_NODE"); + DocumentType dt = ((Document) node).getDoctype(); + + if (dt != null) + { + // String publicId = dt.getPublicId(); + String systemId = dt.getSystemId(); + + if (systemId.equals(TRANSITIONAL_DTD)) + { + result.append(TRANSITIONAL_DOCTYPE); + } + + // Log.write(Log.TRACE,"publicId = " + publicId); + // Log.write(Log.TRACE,"systemId = " + systemId); + } + + Presenter.process(result, ((Document) node).getDocumentElement(), datas, suffix); + + break; + } + + case Node.ELEMENT_NODE: + { + logger.debug("case Node.ELEMENT_NODE"); + + NamedNodeMap attrs = node.getAttributes(); + Node idAttr = attrs.getNamedItem("id"); + + if (idAttr != null) + { + Presenter.processElementWithId(result, node, attrs, idAttr, datas, suffix); + } + else + { + Presenter.processElementBasically(result, node, datas, suffix); + } + + break; + } + + // handle entity reference nodes + case Node.ENTITY_REFERENCE_NODE: + { + logger.debug("case Node.ENTITY_REFERENCE_NODE"); + + result.append('&'); + result.append(node.getNodeName()); + result.append(';'); + break; + } + + // print cdata sections + case Node.CDATA_SECTION_NODE: + { + logger.debug("case Node.CDATA_SECTION_NODE"); + + result.append(""); + + break; + } + + // print text + case Node.TEXT_NODE: + { + logger.debug("case Node.TEXTE_NODE"); + result.append(restoreEntities(new StringBuffer(node.getNodeValue()))); + break; + } + + // print processing instruction + case Node.PROCESSING_INSTRUCTION_NODE: + { + logger.debug("Node.PROCESSING_INSTRUCTION_NODE"); + + result.append(" 0)) + { + result.append(' '); + result.append(data); + } + result.append("?>"); + break; + } + } + } + } + + // + // logger.info ("result=" + result); + logger.debug("process - ended"); + } + + /** + * + */ + static protected StringBuffer processAttributes(final NamedNodeMap attrs) + { + StringBuffer result; + + result = processAttributes(attrs, null, null, ""); + + // + return (result); + } + + /** + * + */ + static protected StringBuffer processAttributes(final NamedNodeMap attrs, final Attributes dataAttributes) + { + StringBuffer result; + + result = processAttributes(attrs, dataAttributes, ""); + + // + return (result); + } + + /** + * + */ + static protected StringBuffer processAttributes(final NamedNodeMap attrs, final Attributes dataAttributes, final Attributes namedDataAttributes, final String suffix) + { + StringBuffer result; + + result = processAttributes(attrs, mergeAttributes(dataAttributes, namedDataAttributes), suffix); + + // + return (result); + } + + /** + * + */ + static protected StringBuffer processAttributes(final NamedNodeMap attrs, final Attributes dataAttributes, final String suffix) + { + StringBuffer result; + + result = new StringBuffer(); + + // Build the original attributes list. + HashMap mergedAttributes; + mergedAttributes = new HashMap(); + for (int attributeCounter = 0; attributeCounter < attrs.getLength(); attributeCounter++) + { + Attr attr = (Attr) attrs.item(attributeCounter); + mergedAttributes.put(attr.getNodeName(), attr.getNodeValue()); + } + + // Put model attributes in the merged attributes list. + if (dataAttributes != null) + { + Iterator> iterator = dataAttributes.entrySet().iterator(); + + while (iterator.hasNext()) + { + Map.Entry attribute = iterator.next(); + + if (mergedAttributes.containsKey(attribute.getKey())) + { + if (attribute.getKey().equalsIgnoreCase("style")) + { + mergedAttributes.put(attribute.getKey(), mergedAttributes.get(attribute.getKey()) + attribute.getValue()); + } + else + { + mergedAttributes.put(attribute.getKey(), attribute.getValue()); + } + } + else + { + mergedAttributes.put(attribute.getKey(), attribute.getValue()); + } + } + } + + // Display the attributes + Iterator> iterator = mergedAttributes.entrySet().iterator(); + while (iterator.hasNext()) + { + Map.Entry attribute = iterator.next(); + + if ((attribute.getKey().equals("id")) && (suffix.length() != 0)) + { + result.append(" " + attribute.getKey() + "=\"" + attribute.getValue() + Presenter.INDEX_SEPARATOR + suffix + "\""); + } + else + { + result.append(" " + attribute.getKey() + "=\"" + attribute.getValue() + "\""); + } + } + + // + return (result); + } + + /** + * + */ + static protected void processChildren(final Writer result, final Node node, final IdsDataById datas) throws Exception + { + processChildren(result, node, datas, ""); + } + + /** + * + */ + static protected void processChildren(final Writer result, final Node node, final IdsDataById datas, final String suffix) throws Exception + { + // Get the iteration strategy. + IdData.IterationStrategy strategy; + + NamedNodeMap attributes = node.getAttributes(); + if (attributes == null) + { + strategy = IdData.IterationStrategy.ALL_ROWS; + } + else + { + Node id = attributes.getNamedItem("id"); + + if (id == null) + { + strategy = IdData.IterationStrategy.ALL_ROWS; + } + else + { + IdDataCore dataCore = datas.getId(id.getNodeValue()); + if (dataCore == null) + { + strategy = IdData.IterationStrategy.ALL_ROWS; + } + else if (dataCore instanceof IdData) + { + IdData data = (IdData) dataCore; + strategy = data.iterationStrategy(); + } + else + { + strategy = IdData.IterationStrategy.ALL_ROWS; + } + } + } + + // Iterate. + NodeList children = node.getChildNodes(); + int childrenCount = children.getLength(); + + switch (strategy) + { + case ONLY_FIRST_ROW: + int lineCounter = 0; + for (int childIndex = 0; childIndex < childrenCount; childIndex++) + { + if (children.item(childIndex).getNodeType() == Node.ELEMENT_NODE) + { + lineCounter += 1; + if (lineCounter == 1) + { + process(result, children.item(childIndex), datas, suffix); + } + } + else + { + process(result, children.item(childIndex), datas, suffix); + } + } + break; + + case ONLY_FIRST_TWO_ROWS: + lineCounter = 0; + for (int childIndex = 0; childIndex < childrenCount; childIndex++) + { + if (children.item(childIndex).getNodeType() == Node.ELEMENT_NODE) + { + lineCounter += 1; + + if ((lineCounter == 1) || (lineCounter == 2)) + { + process(result, children.item(childIndex), datas, suffix); + } + } + else + { + process(result, children.item(childIndex), datas, suffix); + } + } + break; + + case ONLY_ROWS_WITH_ID: + for (int childIndex = 0; childIndex < childrenCount; childIndex++) + { + if (children.item(childIndex).getNodeType() == Node.ELEMENT_NODE) + { + NamedNodeMap attrs2 = children.item(childIndex).getAttributes(); + + if ((attrs2 != null) && (attrs2.getNamedItem("id") != null)) + { + process(result, children.item(childIndex), datas, suffix); + } + } + else + { + process(result, children.item(childIndex), datas, suffix); + } + } + break; + + case ONLY_ROWS_WITHOUT_ID: + for (int childIndex = 0; childIndex < childrenCount; childIndex++) + { + if (children.item(childIndex).getNodeType() == Node.ELEMENT_NODE) + { + NamedNodeMap attrs2 = children.item(childIndex).getAttributes(); + if ((attrs2 == null) || (attrs2.getNamedItem("id") == null)) + { + process(result, children.item(childIndex), datas, suffix); + } + } + else + { + process(result, children.item(childIndex), datas, suffix); + } + } + break; + + case ALL_ROWS: + for (int childIndex = 0; childIndex < childrenCount; childIndex++) + { + process(result, children.item(childIndex), datas, suffix); + } + break; + } + } + + /** + * + */ + static void processElementBasically(final Writer result, final Node node, final IdsDataById datas) throws Exception + { + processElementBasically(result, node, datas, ""); + } + + /** + * + */ + static void processElementBasically(final Writer result, final Node node, final IdsDataById datas, final String suffix) throws Exception + { + logger.debug("processElementBasically - started"); + + // Open the tag. + result.append('<'); + result.append(node.getNodeName()); + + // Build the tag attributes. + // Attributes tagAttributes; + + result.append(processAttributes(node.getAttributes(), null, suffix)); + + // + if (node.getChildNodes() == null) + { + result.append(" />"); + } + else + { + result.append('>'); + + processChildren(result, node, datas, suffix); + + result.append("'); + } + + logger.debug("processElementBasically - ended"); + } + + /** + * Processes a node that has dynamic content. Calls the appropriate code + * generator method, depending on the tag. + * + * @param node + * Current node. + * @param attrs + * The tag attributes. + * @param idAttr + * The ID. + */ + static protected void processElementWithId(final Writer result, final Node node, final NamedNodeMap attrs, final Node idAttr, final IdsDataById datas) throws Exception + + { + processElementWithId(result, node, attrs, idAttr, datas, ""); + } + + /** + * Processes a node that has dynamic content. Calls the appropriate code + * generator method, depending on the tag. + * + * @param node + * Current node. + * @param attrs + * The tag attributes. + * @param idAttr + * The ID. + */ + static protected void processElementWithId(final Writer result, final Node node, final NamedNodeMap attrs, final Node idAttr, final IdsDataById datas, final String suffix) throws Exception + { + String tag = node.getNodeName(); + + // String idValue = idAttr.getNodeValue(); + + logger.debug("tag=" + tag); + + // Get data of this id. + IdDataCore dataCore = datas.get(idAttr.getNodeValue()); + + if (dataCore == null) + { + Presenter.processElementBasically(result, node, datas, suffix); + } + else if (dataCore instanceof IdData) + { + IdData data = (IdData) dataCore; + + String theClass = data.attributes().getAttribute("class"); + + if ((theClass == null) || (!theClass.equals("xid:nodisplay"))) + { + // Open the tag. + result.append("<"); + result.append(node.getNodeName()); + + // Build attributes. + result.append(processAttributes(attrs, data.attributes(), suffix)); + + if ((node.getChildNodes() == null) && ((data == null) || (data.display() == null))) + { + // Close the tag. + result.append(" />"); + } + else + { + result.append('>'); + + // CHANGED, cpm: + + // Insert data. + if ((data == null) || (data.display() == null)) + { + processChildren(result, node, datas, suffix); + } + else + { + result.append(data.display()); + } + + // Close the tag. + result.append("'); + } + } + } + else if (dataCore instanceof IdsDataByIndex) + { + IdsDataByIndex tags = (IdsDataByIndex) dataCore; + + int nbLines = tags.size(); + for (int nLine = 0; nLine < nbLines; nLine++) + { + if (tags.elementAt(nLine) instanceof IdData) + { + IdData data = (IdData) tags.elementAt(nLine); + + // Open the tag. + result.append("<"); + result.append(node.getNodeName()); + + result.append(processAttributes(attrs, data.attributes(), Integer.toString(nLine))); + + if ((node.getChildNodes() == null) && ((data == null) || (data.display() == null))) + { + // Close the tag. + result.append(" />\n"); + } + else + { + result.append('>'); + + // CHANGED, cpm + + // Insert data. + if ((data == null) || (data.display() == null)) + { + processChildren(result, node, datas, suffix); + } + else + { + result.append(data.display()); + } + + // Close the tag. + result.append("\n"); + } + } + else + { + // Manage a Hashmap. + IdsDataById data = (IdsDataById) tags.elementAt(nLine); + + Presenter.processElementWithId(result, node, attrs, idAttr, data, Integer.toString(nLine)); + result.append('\n'); + } + } + } + else + { + logger.warn("Unknow type of IdDataId"); + } + + // + logger.debug("Exit"); + } /** * Any ampersand lt;, ampersand gt; and ampersand amp; sequences in text * nodes get read in as symbols. This method converts them back to entities. * - * @param s String that is to have the entities restored.. + * @param s + * String that is to have the entities restored.. * @return The processed string. */ - static public String restoreEntities (StringBuffer s) + static public String restoreEntities(final StringBuffer s) { String result; @@ -810,274 +1039,10 @@ public class Presenter } } } - result = str.toString (); - } - - - // - return (result);//import javax.xml.parsers.*; - } - - - /** - * Get the text for an element. Converts new lines to spaces. - * - * @param node - */ - static protected String getElementText (Node node) - { - String result; - result = ""; // Grrrr, Java ... - - NodeList children = node.getChildNodes(); - if (children == null) - { - result = ""; - } - else - { - boolean ended = false; - int childCounter = 0; - int childCount = children.getLength (); - while (!ended) - { - if (childCounter >= childCount) - { - ended = true; - result = ""; - } - else - { - Node child = children.item (childCounter); - if (child.getNodeType () == Node.TEXT_NODE) - { - result = newLinesToSpaces (child.getNodeValue ()); // STU (+=, newLines...) - ended = true; - } - else - { - childCounter += 1; - } - } - } + result = str.toString(); } // - return (result); - } - - - /** - * Converts New Line characters to spaces. This is used when for example - * the text in a div tag goes over serveral lines. - * - * @param text String - * @return String - */ - static protected String newLinesToSpaces (String text) - { - StringBuffer result = new StringBuffer (text); - - for (int i = 0; i < result.length(); i++) - { - if (result.charAt (i) == '\n') - { - result.setCharAt (i,' '); - } - } - - // - return (result.toString()); - } - - - /* - * - */ - static protected StringBuffer processAttributes (NamedNodeMap attrs, Attributes dataAttributes, Attributes namedDataAttributes, String suffix) - { - StringBuffer result; - - result = processAttributes (attrs, mergeAttributes (dataAttributes, namedDataAttributes), suffix); - - // - return (result); - } - - - /* - * - */ - static protected StringBuffer processAttributes (NamedNodeMap attrs, Attributes dataAttributes) - { - StringBuffer result; - - result = processAttributes (attrs, dataAttributes, ""); - - // - return (result); - } - - - /* - * - */ - static protected StringBuffer processAttributes (NamedNodeMap attrs) - { - StringBuffer result; - - result = processAttributes (attrs, null, null, ""); - - // - return (result); - } - - - /* - * - */ - static protected StringBuffer processAttributes (NamedNodeMap attrs, Attributes dataAttributes, String suffix) - { - StringBuffer result; - - result = new StringBuffer (); - - // Build the original attributes list. - HashMap mergedAttributes; - mergedAttributes = new HashMap (); - for (int attributeCounter = 0; attributeCounter < attrs.getLength(); attributeCounter++) - { - Attr attr = (Attr) attrs.item (attributeCounter); - mergedAttributes.put (attr.getNodeName(), attr.getNodeValue ()); - } - - - // Put model attributes in the merged attributes list. - if (dataAttributes != null) - { - Iterator> iterator = dataAttributes.entrySet().iterator(); - - while (iterator.hasNext()) - { - Map.Entry attribute = iterator.next(); - - if (mergedAttributes.containsKey (attribute.getKey ())) - { - if (attribute.getKey ().equalsIgnoreCase ("style")) - { - mergedAttributes.put (attribute.getKey (), mergedAttributes.get (attribute.getKey ()) + attribute.getValue ()); - } - else - { - mergedAttributes.put (attribute.getKey (), attribute.getValue ()); - } - } - else - { - mergedAttributes.put (attribute.getKey (), attribute.getValue ()); - } - } - } - - // Display the attributes - Iterator> iterator = mergedAttributes.entrySet().iterator(); - while (iterator.hasNext ()) - { - Map.Entry attribute = iterator.next(); - - if ((attribute.getKey ().equals ("id")) && (suffix.length () != 0)) - { - result.append(" " + attribute.getKey () + "=\"" + attribute.getValue () + Presenter.INDEX_SEPARATOR + suffix + "\""); - } - else - { - result.append(" " + attribute.getKey () + "=\"" + attribute.getValue ()+ "\""); - } - } - - // - return (result); - } - - - /* - * - */ - static public String extractBodyContent (StringBuffer data) - { - String result = null; - - // Extract the body content. - String dataLowerCase = data.toString ().toLowerCase (); - - int startBody = dataLowerCase.indexOf (""); - int endBody = dataLowerCase.indexOf (""); - - // Note: as failed search is improbable, no care about complexity - // in failed search case. - if ((startBody == -1) || (endBody == -1)) - { - result = null; - } - else - { - result = data.substring (startBody + 6, endBody).trim (); - } - - // - return (result); - } - - - /* - * Define in Presenter cause needs this possibility. - */ - static protected Document fileToTree (String fileName) throws Exception - { - Document result; - - try - { - result = buildTree (new FileInputStream (new File (fileName))); - } - catch (IOException exception) - { - String errorMessage = "IOError during parsing." + exception.getMessage (); - logger.error (errorMessage); - result = null; - throw new Exception (errorMessage, exception); - } - - // - return (result); - } - - - /** - * Good estimation of the target length able to optimize performance. - */ - static int estimatedTargetLength(long sourceLength) - { - int result; - - if (sourceLength < 1000) - { - result = (int) (sourceLength*5); - } - else if (sourceLength < 50000) - { - result = (int) (sourceLength*2); - } - else if (sourceLength < 800000) - { - result = (int) (100000); - } - else - { - result = (int) (sourceLength + 30000); - } - - // - return(result); + return (result);// import javax.xml.parsers.*; } } diff --git a/src/fr/devinsy/xid/StringPresenter.java b/src/fr/devinsy/xid/StringPresenter.java index 8def531..5aca5b6 100644 --- a/src/fr/devinsy/xid/StringPresenter.java +++ b/src/fr/devinsy/xid/StringPresenter.java @@ -3,77 +3,52 @@ package fr.devinsy.xid; import java.io.ByteArrayInputStream; import java.io.StringWriter; - /** * */ public class StringPresenter extends DomPresenter { - static protected org.apache.log4j.Logger logger; + static private org.apache.log4j.Logger logger; static - { - logger = org.apache.log4j.Logger.getLogger (StringPresenter.class); + { + logger = org.apache.log4j.Logger.getLogger(StringPresenter.class); } - protected String html; + private String html; - /* + /** * */ - public StringPresenter () + public StringPresenter() { - super (); + super(); this.doc = null; this.html = null; } - - /* + /** * */ - public StringPresenter (String html) + public StringPresenter(final String html) { this.doc = null; this.html = html; } - - /* + /** * */ - public void setSource (String html) + @Override + public StringBuffer doXid(final Data datas) throws Exception { - this.html = html; - this.doc = null; + return (doXid(datas.getIdsDataById())); } - - /* + /** * */ - public String source () - { - String result; - - result = this.html; - - // - return (result); - } - - - /* - * - */ - public StringBuffer doXid (Data datas) throws Exception - { - return (doXid (datas.getIdsDataById ())); - } - - /* - * - */ - public StringBuffer doXid (IdsDataById datas) throws Exception + @Override + public StringBuffer doXid(final IdsDataById datas) throws Exception { StringBuffer result; @@ -81,10 +56,7 @@ public class StringPresenter extends DomPresenter { // Build doc from this.html. String htmlSource; - if ((this.html.startsWith ("")) || - (this.html.startsWith (""))) + if ((this.html.startsWith("")) || (this.html.startsWith(""))) { htmlSource = html; } @@ -94,33 +66,30 @@ public class StringPresenter extends DomPresenter } // StringBufferInputStream is deprecated so we use another solution. - // (see http://www.developpez.net/forums/archive/index.php/t-14101.html). - doc = buildTree (new ByteArrayInputStream (htmlSource.getBytes ())); + // (see + // http://www.developpez.net/forums/archive/index.php/t-14101.html). + doc = buildTree(new ByteArrayInputStream(htmlSource.getBytes())); } StringWriter htmlCode = new StringWriter(Presenter.estimatedTargetLength(this.html.length())); - if ((this.html.startsWith ("'))); } - Presenter.doXid (htmlCode, doc, datas); + Presenter.doXid(htmlCode, doc, datas); StringBuffer htmlTarget = htmlCode.getBuffer(); if (htmlTarget == null) { result = null; } - else if ((this.html.startsWith ("")) || - (this.html.startsWith (""))) + else if ((this.html.startsWith("")) || (this.html.startsWith(""))) { result = htmlTarget; } else { - String bodyContent = extractBodyContent (htmlTarget); + String bodyContent = extractBodyContent(htmlTarget); if (bodyContent == null) { @@ -128,7 +97,7 @@ public class StringPresenter extends DomPresenter } else { - result = new StringBuffer (bodyContent); + result = new StringBuffer(bodyContent); } } @@ -136,26 +105,47 @@ public class StringPresenter extends DomPresenter return (result); } - - /* + /** * */ - static public StringBuffer doXid (String html, Data datas) throws Exception + public void setSource(final String html) { - return (doXid (html, datas.getIdsDataById ())); + this.html = html; + this.doc = null; } + /** + * + */ + @Override + public String source() + { + String result; - /* + result = this.html; + + // + return (result); + } + + /** + * + */ + static public StringBuffer doXid(final String html, final Data datas) throws Exception + { + return (doXid(html, datas.getIdsDataById())); + } + + /** * Xid a string with html in. */ - static public StringBuffer doXid (String html, IdsDataById datas) throws Exception + static public StringBuffer doXid(final String html, final IdsDataById datas) throws Exception { StringBuffer result; - StringPresenter presenter = new StringPresenter (html); + StringPresenter presenter = new StringPresenter(html); - result = presenter.doXid (datas); + result = presenter.doXid(datas); // return (result); diff --git a/test/XidTest.java b/test/XidTest.java index ddfeb8f..bdd1a15 100644 --- a/test/XidTest.java +++ b/test/XidTest.java @@ -13,18 +13,7 @@ class XidTest { public enum MONTHS { - JANUARY, - FEBRUARY, - MARCH, - APRIL, - MAY, - JUNE, - JULY, - AUGUST, - SEPTEMBER, - OCTOBER, - NOVEMBRE, - DECEMBRE + JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBRE, DECEMBRE } static @@ -104,8 +93,7 @@ class XidTest System.out.println(exception.getMessage()); html = null; } - System.out.println(check("content and attributes", html, - "
Spiderman
")); + System.out.println(check("content and attributes", html, "
Spiderman
")); // Populate attributes of Test 03. System.out.println("----------------------------"); @@ -159,12 +147,9 @@ class XidTest html = null; } - System.out - .println(check("table 1 assertion 1", html, "noidJembaEpo")); - System.out.println(check("table 1 assertion 2", html, - "noidMomonChristian")); - System.out.println(check("table 1 assertion 3", html, - "noidTroncheChristophe")); + System.out.println(check("table 1 assertion 1", html, "noidJembaEpo")); + System.out.println(check("table 1 assertion 2", html, "noidMomonChristian")); + System.out.println(check("table 1 assertion 3", html, "noidTroncheChristophe")); /* * // Populate attributes of Test 03. System.out.println