From faabbe42bea9a2f75251720a20fc2742603a0881 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Thu, 8 Sep 2016 02:41:48 +0200 Subject: [PATCH] Refactor formatter. --- .settings/org.eclipse.jdt.core.prefs | 20 +- .settings/org.eclipse.jdt.ui.prefs | 112 +- demo/XidynDemo.java | 512 +++---- src/fr/devinsy/xidyn/XidynException.java | 62 +- src/fr/devinsy/xidyn/data/SimpleTagData.java | 222 +-- src/fr/devinsy/xidyn/data/TagAttributes.java | 100 +- src/fr/devinsy/xidyn/data/TagData.java | 2 +- .../devinsy/xidyn/data/TagDataListById.java | 40 +- .../xidyn/data/TagDataListByIndex.java | 14 +- src/fr/devinsy/xidyn/data/TagDataManager.java | 396 +++--- src/fr/devinsy/xidyn/pages/Page.java | 122 +- src/fr/devinsy/xidyn/pages/PageFactory.java | 342 ++--- .../xidyn/presenters/DomPresenter.java | 258 ++-- .../xidyn/presenters/DomPresenterCore.java | 1262 ++++++++--------- .../xidyn/presenters/FilePresenter.java | 380 ++--- .../xidyn/presenters/FilePresenters.java | 248 ++-- .../xidyn/presenters/FilePresentersProxy.java | 80 +- .../xidyn/presenters/GenericPresenter.java | 342 ++--- .../devinsy/xidyn/presenters/Presenter.java | 64 +- .../xidyn/presenters/PresenterFactory.java | 404 +++--- .../xidyn/presenters/PresenterUtils.java | 186 +-- .../xidyn/presenters/StringPresenter.java | 332 ++--- .../xidyn/presenters/TranslatorPresenter.java | 484 +++---- .../xidyn/presenters/URLPresenter.java | 544 +++---- .../xidyn/utils/ParserErrorHandler.java | 232 +-- src/fr/devinsy/xidyn/utils/XidynUtils.java | 1174 +++++++-------- src/fr/devinsy/xidyn/utils/cache/Cache.java | 224 +-- .../devinsy/xidyn/utils/cache/CacheItem.java | 160 +-- .../xidyn/utils/cache/CacheStrategy.java | 90 +- src/fr/devinsy/xidyn/views/CharterView.java | 18 +- src/fr/devinsy/xidyn/views/View.java | 6 +- test/Foo.java | 18 +- test/XidynTest.java | 423 +++--- test/fr/devinsy/xidyn/pages/PageTest.java | 137 ++ .../xidyn/presenters/DomPresenterTest.java | 101 +- .../xidyn/presenters/PresenterUtilsTest.java | 73 + .../xidyn/presenters/StringPresenterTest.java | 111 +- .../devinsy/xidyn/utils/XidynUtilsTest.java | 208 +-- 38 files changed, 4883 insertions(+), 4620 deletions(-) create mode 100644 test/fr/devinsy/xidyn/pages/PageTest.java create mode 100644 test/fr/devinsy/xidyn/presenters/PresenterUtilsTest.java diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 681d8fc..60464eb 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,14 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.codeComplete.argumentPrefixes= +org.eclipse.jdt.core.codeComplete.argumentSuffixes= +org.eclipse.jdt.core.codeComplete.fieldPrefixes= +org.eclipse.jdt.core.codeComplete.fieldSuffixes= +org.eclipse.jdt.core.codeComplete.localPrefixes= +org.eclipse.jdt.core.codeComplete.localSuffixes= +org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= +org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= +org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes= +org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes= org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 @@ -21,7 +31,7 @@ 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_enum_constants=49 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 @@ -60,7 +70,7 @@ 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=true +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 @@ -85,12 +95,12 @@ org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_de 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_breaks_compare_to_cases=false 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.indent_switchstatements_compare_to_switch=true 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 @@ -287,7 +297,7 @@ 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.char=space 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 diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs index 90b0130..1ddaa02 100644 --- a/.settings/org.eclipse.jdt.ui.prefs +++ b/.settings/org.eclipse.jdt.ui.prefs @@ -1,3 +1,113 @@ +cleanup.add_default_serial_version_id=false +cleanup.add_generated_serial_version_id=true +cleanup.add_missing_annotations=true +cleanup.add_missing_deprecated_annotations=true +cleanup.add_missing_methods=false +cleanup.add_missing_nls_tags=false +cleanup.add_missing_override_annotations=true +cleanup.add_missing_override_annotations_interface_methods=true +cleanup.add_serial_version_id=true +cleanup.always_use_blocks=true +cleanup.always_use_parentheses_in_expressions=false +cleanup.always_use_this_for_non_static_field_access=true +cleanup.always_use_this_for_non_static_method_access=false +cleanup.convert_to_enhanced_for_loop=false +cleanup.correct_indentation=false +cleanup.format_source_code=true +cleanup.format_source_code_changes_only=false +cleanup.make_local_variable_final=false +cleanup.make_parameters_final=true +cleanup.make_private_fields_final=false +cleanup.make_type_abstract_if_missing_method=false +cleanup.make_variable_declarations_final=true +cleanup.never_use_blocks=false +cleanup.never_use_parentheses_in_expressions=true +cleanup.organize_imports=false +cleanup.qualify_static_field_accesses_with_declaring_class=false +cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +cleanup.qualify_static_member_accesses_with_declaring_class=true +cleanup.qualify_static_method_accesses_with_declaring_class=false +cleanup.remove_private_constructors=true +cleanup.remove_trailing_whitespaces=true +cleanup.remove_trailing_whitespaces_all=true +cleanup.remove_trailing_whitespaces_ignore_empty=false +cleanup.remove_unnecessary_casts=true +cleanup.remove_unnecessary_nls_tags=true +cleanup.remove_unused_imports=true +cleanup.remove_unused_local_variables=false +cleanup.remove_unused_private_fields=true +cleanup.remove_unused_private_members=false +cleanup.remove_unused_private_methods=true +cleanup.remove_unused_private_types=true +cleanup.sort_members=true +cleanup.sort_members_all=false +cleanup.use_blocks=true +cleanup.use_blocks_only_for_return_and_throw=false +cleanup.use_parentheses_in_expressions=false +cleanup.use_this_for_non_static_field_access=true +cleanup.use_this_for_non_static_field_access_only_if_necessary=false +cleanup.use_this_for_non_static_method_access=false +cleanup.use_this_for_non_static_method_access_only_if_necessary=true +cleanup_profile=_Xidyn +cleanup_settings_version=2 eclipse.preferences.version=1 -formatter_profile=_Devinsy +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +formatter_profile=_Xidyn formatter_settings_version=12 +org.eclipse.jdt.ui.exception.name=exception +org.eclipse.jdt.ui.gettersetter.use.is=true +org.eclipse.jdt.ui.keywordthis=false +org.eclipse.jdt.ui.overrideannotation=true +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=true +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_missing_override_annotations_interface_methods=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=true +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=true +sp_cleanup.format_source_code=true +sp_cleanup.format_source_code_changes_only=false +sp_cleanup.make_local_variable_final=false +sp_cleanup.make_parameters_final=true +sp_cleanup.make_private_fields_final=false +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=true +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=false +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_trailing_whitespaces=false +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=true +sp_cleanup.remove_unnecessary_nls_tags=true +sp_cleanup.remove_unused_imports=true +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=true +sp_cleanup.sort_members_all=false +sp_cleanup.use_blocks=true +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=true +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=false +sp_cleanup.use_this_for_non_static_method_access=false +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/demo/XidynDemo.java b/demo/XidynDemo.java index edb4f5e..60676be 100644 --- a/demo/XidynDemo.java +++ b/demo/XidynDemo.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2006-2014 Christian Pierre MOMON + * Copyright (C) 2006-2016 Christian Pierre MOMON * * This file is part of Xidyn. * @@ -22,293 +22,293 @@ import org.slf4j.LoggerFactory; import fr.devinsy.xidyn.data.SimpleTagData; import fr.devinsy.xidyn.data.TagDataManager; -import fr.devinsy.xidyn.presenters.StringPresenter; +import fr.devinsy.xidyn.presenters.PresenterUtils; /** * */ class XidynDemo { - static private Logger logger = LoggerFactory.getLogger(XidynDemo.class); - static - { - // Initialize logger. - org.apache.log4j.BasicConfigurator.configure(); - org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO); - } + private static Logger logger = LoggerFactory.getLogger(XidynDemo.class); + static + { + // Initialize logger. + org.apache.log4j.BasicConfigurator.configure(); + org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO); + } - /** + /** * */ - public static void main(final String[] args) - { - System.out.println("Hello World!"); + public static void main(final String[] args) + { + System.out.println("Hello World!"); - // test (); + // test (); - // - TagDataManager data; + // + TagDataManager data; - // Step #01. - { - System.out.println("----------------------------"); + // Step #01. + { + System.out.println("----------------------------"); - // Populate attributes. - data = new TagDataManager(); - data.setContent("name", "Superman"); + // Populate attributes. + data = new TagDataManager(); + data.setContent("name", "Superman"); - String htmlSource = "
a name
"; - StringBuffer htmlTarget; - try - { - htmlTarget = StringPresenter.dynamize(htmlSource, data); - } - 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() + "]"); - } + String htmlSource = "
a name
"; + StringBuffer htmlTarget; + try + { + htmlTarget = PresenterUtils.dynamize(htmlSource, data); + } + 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. - data = new TagDataManager(); - data.setContent("lastname", "Spiderman"); - data.appendAttribute("lastname", "style", "background: blue;"); - data.appendAttribute("lastname", "style", "foreground: red;"); - data.setAttribute("lastname", "class", "nameClass"); + // Step #02. + { + System.out.println("----------------------------"); + // Populate attributes. + data = new TagDataManager(); + data.setContent("lastname", "Spiderman"); + data.appendAttribute("lastname", "style", "background: blue;"); + data.appendAttribute("lastname", "style", "foreground: red;"); + data.setAttribute("lastname", "class", "nameClass"); - String htmlSource = "
a last name
"; - StringBuffer htmlTarget; - try - { - htmlTarget = StringPresenter.dynamize(htmlSource, data); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - htmlTarget = null; - } + String htmlSource = "
a last name
"; + StringBuffer htmlTarget; + try + { + htmlTarget = PresenterUtils.dynamize(htmlSource, data); + } + 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() + "]"); - } + 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. - data = new TagDataManager(); - data.setContent("words", 0, "alpha"); - data.setContent("words", 1, "bravo"); - data.setContent("words", 2, "charlie"); - data.setContent("words", 3, "delta"); - data.setContent("words", 4, "echo"); - data.setContent("words", 5, "fox"); + // Step #03. + { + System.out.println("----------------------------"); + // Populate attributes. + data = new TagDataManager(); + data.setContent("words", 0, "alpha"); + data.setContent("words", 1, "bravo"); + data.setContent("words", 2, "charlie"); + data.setContent("words", 3, "delta"); + data.setContent("words", 4, "echo"); + data.setContent("words", 5, "fox"); - String htmlSource = ""; - StringBuffer htmlTarget; - try - { - htmlTarget = StringPresenter.dynamize(htmlSource, data); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - htmlTarget = null; - } + String htmlSource = ""; + StringBuffer htmlTarget; + try + { + htmlTarget = PresenterUtils.dynamize(htmlSource, data); + } + 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() + "]"); - } + 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. - data = new TagDataManager(); - data.setContent("identity", 0, "last_name", "Jemba"); - data.setContent("identity", 0, "first_name", "Epo"); - data.setContent("identity", 1, "last_name", "Momon"); - data.setContent("identity", 1, "first_name", "Christian"); - data.setContent("identity", 2, "last_name", "Tronche"); - data.setContent("identity", 2, "first_name", "Christophe"); + // Step #04. + { + System.out.println("----------------------------"); + // Populate attributes. + data = new TagDataManager(); + data.setContent("identity", 0, "last_name", "Jemba"); + data.setContent("identity", 0, "first_name", "Epo"); + data.setContent("identity", 1, "last_name", "Momon"); + data.setContent("identity", 1, "first_name", "Christian"); + data.setContent("identity", 2, "last_name", "Tronche"); + data.setContent("identity", 2, "first_name", "Christophe"); - StringBuffer source = new StringBuffer(); - source.append("\n"); - source.append(" \n"); - source.append("
noidJeanReve
"); + StringBuffer source = new StringBuffer(); + source.append("\n"); + source.append(" \n"); + source.append("
noidJeanReve
"); - String htmlSource = source.toString(); - StringBuffer htmlTarget; - try - { - htmlTarget = StringPresenter.dynamize(htmlSource, data); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - htmlTarget = null; - } + String htmlSource = source.toString(); + StringBuffer htmlTarget; + try + { + htmlTarget = PresenterUtils.dynamize(htmlSource, data); + } + 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("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() + "]"); - } + 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. - data = new TagDataManager(); - data.setContent("identity", 0, "last_name", "Jemba"); - data.setContent("identity", 0, "first_name", "Epo"); - data.setContent("identity", 1, "last_name", "Momon"); - data.setContent("identity", 1, "first_name", "Christian"); - data.setContent("identity", 2, "last_name", "Tronche"); - data.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); + // Step #05. + { + System.out.println("----------------------------"); + // Populate attributes. + data = new TagDataManager(); + data.setContent("identity", 0, "last_name", "Jemba"); + data.setContent("identity", 0, "first_name", "Epo"); + data.setContent("identity", 1, "last_name", "Momon"); + data.setContent("identity", 1, "first_name", "Christian"); + data.setContent("identity", 2, "last_name", "Tronche"); + data.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(); + // + 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("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("=>"); + System.out.println("+"); + System.out.println(htmlSource); + System.out.println("=>"); - // #05.1 - data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_FIRST_ROW); - System.out.println("ONLY_FIRST_ROW:"); - StringBuffer html; - try - { - html = StringPresenter.dynamize(htmlSource, data); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - html = null; - } - System.out.println(html); - System.out.println(""); + // #05.1 + data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_FIRST_ROW); + System.out.println("ONLY_FIRST_ROW:"); + StringBuffer html; + try + { + html = PresenterUtils.dynamize(htmlSource, data); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + html = null; + } + System.out.println(html); + System.out.println(""); - // #05.2 - data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_FIRST_TWO_ROWS); - System.out.println("ONLY_FIRST_TWO_ROWS:"); - try - { - html = StringPresenter.dynamize(htmlSource, data); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - html = null; - } - System.out.println(html); - System.out.println(""); + // #05.2 + data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_FIRST_TWO_ROWS); + System.out.println("ONLY_FIRST_TWO_ROWS:"); + try + { + html = PresenterUtils.dynamize(htmlSource, data); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + html = null; + } + System.out.println(html); + System.out.println(""); - // #05.3 - data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_ROWS_WITH_ID); - System.out.println("ONLY_ROWS_WITH_ID:"); - try - { - html = StringPresenter.dynamize(htmlSource, data); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - html = null; - } - System.out.println(html); - System.out.println(""); + // #05.3 + data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_ROWS_WITH_ID); + System.out.println("ONLY_ROWS_WITH_ID:"); + try + { + html = PresenterUtils.dynamize(htmlSource, data); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + html = null; + } + System.out.println(html); + System.out.println(""); - // #05.4 - data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_ROWS_WITHOUT_ID); - System.out.println("ONLY_ROWS_WITHOUT_ID:"); - try - { - html = StringPresenter.dynamize(htmlSource, data); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - html = null; - } - System.out.println(html); - System.out.println(""); + // #05.4 + data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_ROWS_WITHOUT_ID); + System.out.println("ONLY_ROWS_WITHOUT_ID:"); + try + { + html = PresenterUtils.dynamize(htmlSource, data); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + html = null; + } + System.out.println(html); + System.out.println(""); - // #05.5 - data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ALL_ROWS); - System.out.println("ALL_ROWS:"); - try - { - html = StringPresenter.dynamize(htmlSource, data); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - html = null; - } - System.out.println(html); - } - } + // #05.5 + data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ALL_ROWS); + System.out.println("ALL_ROWS:"); + try + { + html = PresenterUtils.dynamize(htmlSource, data); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + html = null; + } + System.out.println(html); + } + } } diff --git a/src/fr/devinsy/xidyn/XidynException.java b/src/fr/devinsy/xidyn/XidynException.java index e3a0be2..ed70d60 100644 --- a/src/fr/devinsy/xidyn/XidynException.java +++ b/src/fr/devinsy/xidyn/XidynException.java @@ -24,41 +24,41 @@ package fr.devinsy.xidyn; */ public class XidynException extends Exception { - private static final long serialVersionUID = 8498031594322380559L; + private static final long serialVersionUID = 8498031594322380559L; - /** + /** * */ - public XidynException() - { - super(); - } + public XidynException() + { + super(); + } - /** - * - * @param message - */ - public XidynException(final String message) - { - super(message); - } + /** + * + * @param message + */ + public XidynException(final String message) + { + super(message); + } - /** - * - * @param message - * @param cause - */ - public XidynException(final String message, final Throwable cause) - { - super(message, cause); - } + /** + * + * @param message + * @param cause + */ + public XidynException(final String message, final Throwable cause) + { + super(message, cause); + } - /** - * - * @param cause - */ - public XidynException(final Throwable cause) - { - super(cause); - } + /** + * + * @param cause + */ + public XidynException(final Throwable cause) + { + super(cause); + } } diff --git a/src/fr/devinsy/xidyn/data/SimpleTagData.java b/src/fr/devinsy/xidyn/data/SimpleTagData.java index 8719232..aa8566c 100644 --- a/src/fr/devinsy/xidyn/data/SimpleTagData.java +++ b/src/fr/devinsy/xidyn/data/SimpleTagData.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2006-2014 Christian Pierre MOMON + * Copyright (C) 2006-2016 Christian Pierre MOMON * * This file is part of Xidyn. * @@ -34,161 +34,167 @@ import java.io.Serializable; */ public class SimpleTagData implements Serializable, TagData { - public enum IterationStrategy - { - ONLY_FIRST_ROW, ONLY_FIRST_TWO_ROWS, ONLY_ROWS_WITH_ID, ONLY_ROWS_WITHOUT_ID, ALL_ROWS - } + 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 MODE + { + REPLACE, + APPEND, + IGNORE + } - private static final long serialVersionUID = 8976245034682639923L;; + private static final long serialVersionUID = 8976245034682639923L;; - private IterationStrategy iterationStrategy; - private TagAttributes attributes; - private boolean excludeSection; - private MODE displayMode = MODE.REPLACE; - private String content; + private IterationStrategy iterationStrategy; + private TagAttributes attributes; + private boolean excludeSection; + private MODE displayMode = MODE.REPLACE; + private String content; - /** + /** * */ - public SimpleTagData() - { - this.attributes = null; - this.excludeSection = false; - this.displayMode = MODE.REPLACE; - this.content = null; - this.iterationStrategy = IterationStrategy.ALL_ROWS; - } + public SimpleTagData() + { + this.attributes = null; + this.excludeSection = false; + this.displayMode = MODE.REPLACE; + this.content = null; + this.iterationStrategy = IterationStrategy.ALL_ROWS; + } - /** + /** * */ - public SimpleTagData(final String text) - { - this.attributes = null; - this.excludeSection = false; - this.displayMode = MODE.REPLACE; - this.content = text; - this.iterationStrategy = IterationStrategy.ALL_ROWS; - } + public SimpleTagData(final String text) + { + this.attributes = null; + this.excludeSection = false; + this.displayMode = MODE.REPLACE; + this.content = text; + this.iterationStrategy = IterationStrategy.ALL_ROWS; + } - /** + /** * */ - public void appendContent(final String text) - { - if (this.content == null) - { - this.content = text; - } - else - { - this.content += text; - } - } + public void appendContent(final String text) + { + if (this.content == null) + { + this.content = text; + } + else + { + this.content += text; + } + } - /** + /** * */ - public TagAttributes attributes() - { - TagAttributes result; + public TagAttributes attributes() + { + TagAttributes result; - if (this.attributes == null) - { - this.attributes = new TagAttributes(); - } + if (this.attributes == null) + { + this.attributes = new TagAttributes(); + } - result = this.attributes; + result = this.attributes; - // - return (result); - } + // + return (result); + } - /** + /** * */ - public String display() - { - String result; + public String display() + { + String result; - result = this.content; + result = this.content; - // - return (result); - } + // + return (result); + } - /** + /** * */ - public MODE displayMode() - { - MODE result; + public MODE displayMode() + { + MODE result; - result = this.displayMode; + result = this.displayMode; - return (result); - } + return (result); + } - /** + /** * */ - public boolean excludeSection() - { - boolean result; + public boolean excludeSection() + { + boolean result; - result = this.excludeSection; + result = this.excludeSection; - // - return (result); - } + // + return (result); + } - /** + /** * */ - public IterationStrategy iterationStrategy() - { - IterationStrategy result; + public IterationStrategy iterationStrategy() + { + IterationStrategy result; - result = this.iterationStrategy; + result = this.iterationStrategy; - // - return (result); - } + // + return (result); + } - /** + /** * */ - public void setContent(final String text) - { - this.content = text; - } + public void setContent(final String text) + { + this.content = text; + } - /** + /** * */ - public void setDisplayMode(final MODE displayMode) - { - this.displayMode = displayMode; - } + public void setDisplayMode(final MODE displayMode) + { + this.displayMode = displayMode; + } - /** + /** * */ - public void setExcludeSection(final boolean excludeSection) - { - this.excludeSection = excludeSection; - } + public void setExcludeSection(final boolean excludeSection) + { + this.excludeSection = excludeSection; + } - /** + /** * */ - public void setIterationStrategy(final IterationStrategy strategy) - { - this.iterationStrategy = strategy; - } + public void setIterationStrategy(final IterationStrategy strategy) + { + this.iterationStrategy = strategy; + } } diff --git a/src/fr/devinsy/xidyn/data/TagAttributes.java b/src/fr/devinsy/xidyn/data/TagAttributes.java index 765f2e5..554c208 100644 --- a/src/fr/devinsy/xidyn/data/TagAttributes.java +++ b/src/fr/devinsy/xidyn/data/TagAttributes.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2006-2014 Christian Pierre MOMON + * Copyright (C) 2006-2016 Christian Pierre MOMON * * This file is part of Xidyn. * @@ -27,67 +27,67 @@ import java.util.HashMap; */ public class TagAttributes extends HashMap { - private static final long serialVersionUID = 2802739066295665336L; + private static final long serialVersionUID = 2802739066295665336L; - /** + /** * */ - public TagAttributes() - { - super(); - } + public TagAttributes() + { + super(); + } - /** - * Useful for the merge attributes. - */ - public TagAttributes(final TagAttributes attributes) - { - super(attributes); - } + /** + * Useful for the merge attributes. + */ + public TagAttributes(final TagAttributes attributes) + { + super(attributes); + } - /** - * Add a value to an existing value. This is useful to the 'style' - * attribute. - * - */ - public void appendAttribute(final String label, final String value) - { - if (this.containsKey(label)) - { - this.put(label, this.get(label) + value); - } - else - { - this.put(label, value); - } - } + /** + * Add a value to an existing value. This is useful to the 'style' + * attribute. + * + */ + public void appendAttribute(final String label, final String value) + { + if (this.containsKey(label)) + { + this.put(label, this.get(label) + value); + } + else + { + this.put(label, value); + } + } - /** + /** * */ - public String getAttribute(final String label) - { - String result; + public String getAttribute(final String label) + { + String result; - if (this.containsKey(label)) - { - result = this.get(label); - } - else - { - result = null; - } + if (this.containsKey(label)) + { + result = this.get(label); + } + else + { + result = null; + } - // - return (result); - } + // + return (result); + } - /** + /** * */ - public void setAttribute(final String label, final String value) - { - this.put(label, value); - } + public void setAttribute(final String label, final String value) + { + this.put(label, value); + } } diff --git a/src/fr/devinsy/xidyn/data/TagData.java b/src/fr/devinsy/xidyn/data/TagData.java index 4c2f02f..1d5a257 100644 --- a/src/fr/devinsy/xidyn/data/TagData.java +++ b/src/fr/devinsy/xidyn/data/TagData.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2006-2014 Christian Pierre MOMON + * Copyright (C) 2006-2016 Christian Pierre MOMON * * This file is part of Xidyn. * diff --git a/src/fr/devinsy/xidyn/data/TagDataListById.java b/src/fr/devinsy/xidyn/data/TagDataListById.java index 7f11c3e..4a642e2 100644 --- a/src/fr/devinsy/xidyn/data/TagDataListById.java +++ b/src/fr/devinsy/xidyn/data/TagDataListById.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2006-2014 Christian Pierre MOMON + * Copyright (C) 2006-2016 Christian Pierre MOMON * * This file is part of Xidyn. * @@ -26,35 +26,35 @@ import java.util.HashMap; public class TagDataListById extends HashMap implements TagData { - private static final long serialVersionUID = -5787252043825503554L; + private static final long serialVersionUID = -5787252043825503554L; - /** + /** * */ - public TagDataListById() - { - super(); - } + public TagDataListById() + { + super(); + } - /** + /** * */ - public TagData getId(final String id) - { - TagData result; + public TagData getId(final String id) + { + TagData result; - result = this.get(id); + result = this.get(id); - // - return (result); - } + // + return (result); + } - /** + /** * */ - public void setId(final String id, final TagData data) - { - this.put(id, data); - } + public void setId(final String id, final TagData data) + { + this.put(id, data); + } } diff --git a/src/fr/devinsy/xidyn/data/TagDataListByIndex.java b/src/fr/devinsy/xidyn/data/TagDataListByIndex.java index 7519d9e..5e5f6e7 100644 --- a/src/fr/devinsy/xidyn/data/TagDataListByIndex.java +++ b/src/fr/devinsy/xidyn/data/TagDataListByIndex.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2006-2014 Christian Pierre MOMON + * Copyright (C) 2006-2016 Christian Pierre MOMON * * This file is part of Xidyn. * @@ -26,13 +26,13 @@ import java.util.Vector; public class TagDataListByIndex extends Vector implements TagData { - private static final long serialVersionUID = 215545720925753884L; + private static final long serialVersionUID = 215545720925753884L; - /** + /** * */ - public TagDataListByIndex() - { - super(); - } + public TagDataListByIndex() + { + super(); + } } diff --git a/src/fr/devinsy/xidyn/data/TagDataManager.java b/src/fr/devinsy/xidyn/data/TagDataManager.java index 3055366..3838c83 100644 --- a/src/fr/devinsy/xidyn/data/TagDataManager.java +++ b/src/fr/devinsy/xidyn/data/TagDataManager.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2006-2014 Christian Pierre MOMON + * Copyright (C) 2006-2016 Christian Pierre MOMON * * This file is part of Xidyn. * @@ -23,308 +23,308 @@ package fr.devinsy.xidyn.data; */ public class TagDataManager { - private TagDataListById idsDataById; + private TagDataListById idsDataById; - /** + /** * */ - public TagDataManager() - { - this.idsDataById = new TagDataListById(); - } + public TagDataManager() + { + this.idsDataById = new TagDataListById(); + } - /** + /** * */ - public void appendAttribute(final String id, final int line, final String column, final String label, final String value) - { - SimpleTagData tag = this.getIdData(id, line, column); + public void appendAttribute(final String id, final int line, final String column, final String label, final String value) + { + SimpleTagData tag = this.getIdData(id, line, column); - tag.attributes().appendAttribute(label, value); - } + tag.attributes().appendAttribute(label, value); + } - /** + /** * */ - public void appendAttribute(final String id, final String label, final long value) - { - appendAttribute(id, label, String.valueOf(value)); - } + public void appendAttribute(final String id, final String label, final long value) + { + appendAttribute(id, label, String.valueOf(value)); + } - /** + /** * */ - public void appendAttribute(final String id, final String label, final String value) - { - SimpleTagData tag = this.getIdData(id); + public void appendAttribute(final String id, final String label, final String value) + { + SimpleTagData tag = this.getIdData(id); - tag.attributes().appendAttribute(label, value); - } + tag.attributes().appendAttribute(label, value); + } - /** + /** * */ - public void appendContent(final String id, final int line, final long value) - { - appendContent(id, line, String.valueOf(value)); - } + public void appendContent(final String id, final int line, final long value) + { + appendContent(id, line, String.valueOf(value)); + } - /** + /** * */ - public void appendContent(final String id, final int line, final String value) - { - SimpleTagData tag = this.getIdData(id, line); + public void appendContent(final String id, final int line, final String value) + { + SimpleTagData tag = this.getIdData(id, line); - tag.appendContent(value); - } + tag.appendContent(value); + } - /** + /** * */ - public void appendContent(final String id, final int line, final String column, final long value) - { - appendContent(id, line, column, String.valueOf(value)); - } + public void appendContent(final String id, final int line, final String column, final long value) + { + appendContent(id, line, column, String.valueOf(value)); + } - /** + /** * */ - public void appendContent(final String id, final int line, final String column, final String value) - { - SimpleTagData tag = this.getIdData(id, line, column); + public void appendContent(final String id, final int line, final String column, final String value) + { + SimpleTagData tag = this.getIdData(id, line, column); - tag.appendContent(value); - } + tag.appendContent(value); + } - /** + /** * */ - public SimpleTagData getIdData(final String id) - { - SimpleTagData result; + public SimpleTagData getIdData(final String id) + { + SimpleTagData result; - // Be sure that IdData is existing and get item. - result = (SimpleTagData) this.idsDataById.getId(id); + // Be sure that IdData is existing and get item. + result = (SimpleTagData) this.idsDataById.getId(id); - if (result == null) - { - this.idsDataById.setId(id, new SimpleTagData()); + if (result == null) + { + this.idsDataById.setId(id, new SimpleTagData()); - result = (SimpleTagData) this.idsDataById.getId(id); - } + result = (SimpleTagData) this.idsDataById.getId(id); + } - // - return (result); - } + // + return (result); + } - /** + /** * */ - public SimpleTagData getIdData(final String id, final int line) - { - SimpleTagData result; + public SimpleTagData getIdData(final String id, final int line) + { + SimpleTagData result; - // Be sure that IdsData are existing. - TagDataListByIndex tags = (TagDataListByIndex) this.idsDataById.getId(id); - if (tags == null) - { - this.idsDataById.setId(id, new TagDataListByIndex()); + // Be sure that IdsData are existing. + TagDataListByIndex tags = (TagDataListByIndex) this.idsDataById.getId(id); + if (tags == null) + { + this.idsDataById.setId(id, new TagDataListByIndex()); - tags = (TagDataListByIndex) this.idsDataById.getId(id); - } + tags = (TagDataListByIndex) 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 SimpleTagData()); - } + // Be sure that lines are existing. + int nbLines = tags.size(); + for (int nLine = nbLines; nLine < line + 1; nLine++) + { + tags.add(nLine, new SimpleTagData()); + } - // Get item. - result = (SimpleTagData) tags.elementAt(line); + // Get item. + result = (SimpleTagData) tags.elementAt(line); - // - return (result); - } + // + return (result); + } - /** + /** * */ - public SimpleTagData getIdData(final String id, final int line, final String column) - { - SimpleTagData result; + public SimpleTagData getIdData(final String id, final int line, final String column) + { + SimpleTagData result; - // Be sure that IdsData are existing. - TagDataListByIndex tags = (TagDataListByIndex) this.idsDataById.getId(id); - if (tags == null) - { - this.idsDataById.setId(id, new TagDataListByIndex()); + // Be sure that IdsData are existing. + TagDataListByIndex tags = (TagDataListByIndex) this.idsDataById.getId(id); + if (tags == null) + { + this.idsDataById.setId(id, new TagDataListByIndex()); - tags = (TagDataListByIndex) this.idsDataById.getId(id); - } + tags = (TagDataListByIndex) 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 TagDataListById()); - } + // Be sure that lines are existing. + int nbLines = tags.size(); + for (int nLine = nbLines; nLine < line + 1; nLine++) + { + tags.add(nLine, new TagDataListById()); + } - // Get item. - TagDataListById lineData = (TagDataListById) tags.elementAt(line); + // Get item. + TagDataListById lineData = (TagDataListById) tags.elementAt(line); - result = (SimpleTagData) lineData.get(column); + result = (SimpleTagData) lineData.get(column); - if (result == null) - { - lineData.put(column, new SimpleTagData()); + if (result == null) + { + lineData.put(column, new SimpleTagData()); - result = (SimpleTagData) lineData.get(column); - } + result = (SimpleTagData) lineData.get(column); + } - // - return (result); - } + // + return (result); + } - /** + /** * */ - public TagDataListById getIdsDataById() - { - TagDataListById result; + public TagDataListById getIdsDataById() + { + TagDataListById result; - result = this.idsDataById; + result = this.idsDataById; - // - return (result); - } + // + return (result); + } - /** + /** * */ - public void setAttribute(final String id, final int line, final String label, final long value) - { - setAttribute(id, line, label, String.valueOf(value)); - } + public void setAttribute(final String id, final int line, final String label, final long value) + { + setAttribute(id, line, label, String.valueOf(value)); + } - /** + /** * */ - public void setAttribute(final String id, final int line, final String label, final String value) - { - SimpleTagData tag = this.getIdData(id, line); + public void setAttribute(final String id, final int line, final String label, final String value) + { + SimpleTagData tag = this.getIdData(id, line); - tag.attributes().setAttribute(label, value); - } + tag.attributes().setAttribute(label, value); + } - /** + /** * */ - public void setAttribute(final String id, final int line, final String column, final String label, final long value) - { - setAttribute(id, line, column, label, String.valueOf(value)); - } + public void setAttribute(final String id, final int line, final String column, final String label, final long value) + { + setAttribute(id, line, column, label, String.valueOf(value)); + } - /** + /** * */ - public void setAttribute(final String id, final int line, final String column, final String label, final String value) - { - SimpleTagData tag = this.getIdData(id, line, column); + public void setAttribute(final String id, final int line, final String column, final String label, final String value) + { + SimpleTagData tag = this.getIdData(id, line, column); - tag.attributes().setAttribute(label, value); - } + tag.attributes().setAttribute(label, value); + } - /** + /** * */ - public void setAttribute(final String id, final String label, final long value) - { - setAttribute(id, label, String.valueOf(value)); - } + public void setAttribute(final String id, final String label, final long value) + { + setAttribute(id, label, String.valueOf(value)); + } - /** + /** * */ - public void setAttribute(final String id, final String label, final String value) - { - SimpleTagData tag = this.getIdData(id); + public void setAttribute(final String id, final String label, final String value) + { + SimpleTagData tag = this.getIdData(id); - tag.attributes().setAttribute(label, value); - } + tag.attributes().setAttribute(label, value); + } - /** + /** * */ - public void setContent(final String id, final int line, final long value) - { - setContent(id, line, String.valueOf(value)); - } + public void setContent(final String id, final int line, final long value) + { + setContent(id, line, String.valueOf(value)); + } - /** + /** * */ - public void setContent(final String id, final int line, final String content) - { - SimpleTagData tag = this.getIdData(id, line); + public void setContent(final String id, final int line, final String content) + { + SimpleTagData tag = this.getIdData(id, line); - tag.setContent(content); - } + tag.setContent(content); + } - /** - * @TODO - */ - 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); + /** + * @TODO + */ + 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 setContent(final String id, final int line, final String column, final long value) - { - setContent(id, line, column, String.valueOf(value)); - } + public void setContent(final String id, final int line, final String column, final long value) + { + setContent(id, line, column, String.valueOf(value)); + } - /** + /** * */ - public void setContent(final String id, final int line, final String column, final String content) - { - SimpleTagData tag = this.getIdData(id, line, column); + public void setContent(final String id, final int line, final String column, final String content) + { + SimpleTagData tag = this.getIdData(id, line, column); - tag.setContent(content); - } + tag.setContent(content); + } - /** + /** * */ - public void setContent(final String id, final long value) - { - setContent(id, String.valueOf(value)); - } + public void setContent(final String id, final long value) + { + setContent(id, String.valueOf(value)); + } - /** + /** * */ - public void setContent(final String id, final String content) - { - SimpleTagData idData = this.getIdData(id); + public void setContent(final String id, final String content) + { + SimpleTagData idData = this.getIdData(id); - idData.setContent(content); - } + idData.setContent(content); + } - /** + /** * */ - public void setIterationStrategy(final String id, final SimpleTagData.IterationStrategy strategy) - { - SimpleTagData tag = this.getIdData(id); + public void setIterationStrategy(final String id, final SimpleTagData.IterationStrategy strategy) + { + SimpleTagData tag = this.getIdData(id); - tag.setIterationStrategy(strategy); - } + tag.setIterationStrategy(strategy); + } } diff --git a/src/fr/devinsy/xidyn/pages/Page.java b/src/fr/devinsy/xidyn/pages/Page.java index 655a343..d450879 100644 --- a/src/fr/devinsy/xidyn/pages/Page.java +++ b/src/fr/devinsy/xidyn/pages/Page.java @@ -26,82 +26,82 @@ import fr.devinsy.xidyn.presenters.Presenter; */ public class Page extends TagDataManager { - private Presenter presenter; - private StringBuffer lastDynamize; + private Presenter presenter; + private StringBuffer lastDynamize; - /** + /** * */ - public Page(final Presenter presenter) - { - super(); + public Page(final Presenter presenter) + { + super(); - if (presenter == null) - { - throw new IllegalArgumentException("Null parameter."); - } - else - { - this.presenter = presenter; - this.lastDynamize = null; - } - } + if (presenter == null) + { + throw new IllegalArgumentException("Null parameter."); + } + else + { + this.presenter = presenter; + this.lastDynamize = null; + } + } - /** - * - * @return - * @throws Exception - */ - public StringBuffer dynamize() throws Exception - { - StringBuffer result; + /** + * + * @return + * @throws Exception + */ + public StringBuffer dynamize() throws Exception + { + StringBuffer result; - this.lastDynamize = this.presenter.dynamize(this); + this.lastDynamize = this.presenter.dynamize(this); - result = this.lastDynamize; + result = this.lastDynamize; - // - return result; - } + // + return result; + } - /** - * - * @return - */ - public boolean isComplete() - { - boolean result; + /** + * + * @return + */ + public boolean isComplete() + { + boolean result; - if (this.lastDynamize == null) - { - result = false; - } - else - { - result = true; - } + if (this.lastDynamize == null) + { + result = false; + } + else + { + result = true; + } - // - return result; - } + // + return result; + } - /** - * @throws Exception - */ - public StringBuffer lastVersion() throws Exception - { - StringBuffer result; + /** + * @throws Exception + */ + public StringBuffer lastVersion() throws Exception + { + StringBuffer result; - if ((this.lastDynamize == null) || (this.presenter.isOutdated())) - { - dynamize(); - } + if ((this.lastDynamize == null) || (this.presenter.isOutdated())) + { + dynamize(); + } - result = this.lastDynamize; + result = this.lastDynamize; - // - return result; - } + // + return result; + } } // //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/fr/devinsy/xidyn/pages/PageFactory.java b/src/fr/devinsy/xidyn/pages/PageFactory.java index 8376893..19280d4 100644 --- a/src/fr/devinsy/xidyn/pages/PageFactory.java +++ b/src/fr/devinsy/xidyn/pages/PageFactory.java @@ -33,214 +33,214 @@ import fr.devinsy.xidyn.utils.cache.Cache; */ public class PageFactory { - /** - * http://thecodersbreakfast.net/index.php?post/2008/02/25/26-de-la-bonne- - * implementation-du-singleton-en-java + /** + * http://thecodersbreakfast.net/index.php?post/2008/02/25/26-de-la-bonne- + * implementation-du-singleton-en-java + * + */ + private static class SingletonHolder + { + private final static PageFactory INSTANCE = new PageFactory(); + } + + private Cache cache; + + /** * */ - private static class SingletonHolder - { - private final static PageFactory INSTANCE = new PageFactory(); - } + private PageFactory() + { + this.cache = new Cache(); + } - private Cache cache; - - /** + /** * */ - private PageFactory() - { - this.cache = new Cache(); - } + public void clear() + { + this.cache.clear(); + PresenterFactory.instance().clear(); + } - /** - * - * @param source - * @param parameters - * @return - */ - public Page get(final Document source) - { - Page result; + /** + * + * @param source + * @param parameters + * @return + */ + public Page get(final Document source) + { + Page result; - result = new Page(PresenterFactory.instance().get(source)); + result = new Page(PresenterFactory.instance().get(source)); - // - return result; - } + // + return result; + } - /** - * - * @param source - * @param parameters - * @return - * @throws Exception - */ - public Page get(final Document source, final String... keys) - { - Page result; + /** + * + * @param source + * @param parameters + * @return + * @throws Exception + */ + public Page get(final Document source, final String... keys) + { + Page result; - String key = StringListUtils.toStringSeparatedBy(keys, "-").toString(); + String key = StringListUtils.toStringSeparatedBy(keys, "-").toString(); - result = this.cache.get(key); - if (result == null) - { - result = get(source); - this.cache.put(key, result); - } + result = this.cache.get(key); + if (result == null) + { + result = get(source); + this.cache.put(key, result); + } - // - return result; - } + // + return result; + } - /** - * - * @param source - * @param parameters - * @return - */ - public Page get(final File source) - { - Page result; + /** + * + * @param source + * @param parameters + * @return + */ + public Page get(final File source) + { + Page result; - result = new Page(PresenterFactory.instance().get(source)); + result = new Page(PresenterFactory.instance().get(source)); - // - return result; - } + // + return result; + } - /** - * - * @param source - * @param parameters - * @return - */ - public Page get(final File source, final String... keys) - { - Page result; + /** + * + * @param source + * @param parameters + * @return + */ + public Page get(final File source, final String... keys) + { + Page result; - String key = StringListUtils.toStringSeparatedBy(keys, "-").toString(); + String key = StringListUtils.toStringSeparatedBy(keys, "-").toString(); - result = this.cache.get(key); - if (result == null) - { - result = get(source); - this.cache.put(key, result); - } + result = this.cache.get(key); + if (result == null) + { + result = get(source); + this.cache.put(key, result); + } - // - return result; - } + // + return result; + } - /** - * - * @param source - * @param parameters - * @return - */ - public Page get(final String source) - { - Page result; + /** + * + * @param source + * @param parameters + * @return + */ + public Page get(final String source) + { + Page result; - result = new Page(PresenterFactory.instance().get(source)); + result = new Page(PresenterFactory.instance().get(source)); - // - return result; - } + // + return result; + } - /** - * - * @param source - * @param parameters - * @return - */ - public Page get(final String source, final String... keys) - { - Page result; + /** + * + * @param source + * @param parameters + * @return + */ + public Page get(final String source, final String... keys) + { + Page result; - String key = StringListUtils.toStringSeparatedBy(keys, "-").toString(); + String key = StringListUtils.toStringSeparatedBy(keys, "-").toString(); - result = this.cache.get(key); - if (result == null) - { - result = get(source); - this.cache.put(key, result); - } + result = this.cache.get(key); + if (result == null) + { + result = get(source); + this.cache.put(key, result); + } - // - return result; - } + // + return result; + } - /** - * - * @param source - * @param parameters - * @return - */ - public Page get(final URL source) - { - Page result; + /** + * + * @param source + * @param parameters + * @return + */ + public Page get(final URL source) + { + Page result; - result = new Page(PresenterFactory.instance().get(source)); + result = new Page(PresenterFactory.instance().get(source)); - // - return result; - } + // + return result; + } - /** - * - * @param source - * @param parameters - * @return - */ - public Page get(final URL source, final String... keys) - { - Page result; + /** + * + * @param source + * @param parameters + * @return + */ + public Page get(final URL source, final String... keys) + { + Page result; - String key = StringListUtils.toStringSeparatedBy(keys, "-").toString(); + String key = StringListUtils.toStringSeparatedBy(keys, "-").toString(); - result = this.cache.get(key); - if (result == null) - { - result = get(source); - this.cache.put(key, result); - } + result = this.cache.get(key); + if (result == null) + { + result = get(source); + this.cache.put(key, result); + } - // - return result; - } + // + return result; + } - /** - * - */ - public void clear() - { - this.cache.clear(); - PresenterFactory.instance().clear(); - } + /** + * + * @return + */ + public int size() + { + int result; - /** - * - * @return - */ - public int size() - { - int result; + result = this.cache.size(); - result = this.cache.size(); + // + return result; + } - // - return result; - } - - /** - * - * @return - */ - public static PageFactory instance() - { - return SingletonHolder.INSTANCE; - } + /** + * + * @return + */ + public static PageFactory instance() + { + return SingletonHolder.INSTANCE; + } } // //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/fr/devinsy/xidyn/presenters/DomPresenter.java b/src/fr/devinsy/xidyn/presenters/DomPresenter.java index 6ef2e72..d7de736 100644 --- a/src/fr/devinsy/xidyn/presenters/DomPresenter.java +++ b/src/fr/devinsy/xidyn/presenters/DomPresenter.java @@ -32,168 +32,168 @@ import fr.devinsy.xidyn.utils.XidynUtils; */ public class DomPresenter implements Presenter { - private static Logger logger = LoggerFactory.getLogger(DomPresenter.class); - private Document dom; - private boolean isOutdated; - private StringBuffer defaultHtmlTarget; + private static Logger logger = LoggerFactory.getLogger(DomPresenter.class); + private Document dom; + private boolean isOutdated; + private StringBuffer defaultHtmlTarget; - /** + /** * */ - public DomPresenter() - { - this.dom = null; - this.isOutdated = false; - } + public DomPresenter() + { + this.dom = null; + this.isOutdated = false; + } - /** + /** * */ - public DomPresenter(final Document doc) - { - setSource(doc); - } + public DomPresenter(final Document doc) + { + setSource(doc); + } - /** - * {@inheritDoc} - */ - @Override - public StringBuffer dynamize() throws Exception - { - StringBuffer result; + /** + * {@inheritDoc} + */ + @Override + public StringBuffer dynamize() throws Exception + { + StringBuffer result; - if ((this.isOutdated) || (this.defaultHtmlTarget == null)) - { - this.defaultHtmlTarget = dynamize(null); - this.isOutdated = false; - } + if ((this.isOutdated) || (this.defaultHtmlTarget == null)) + { + this.defaultHtmlTarget = dynamize(null); + this.isOutdated = false; + } - result = this.defaultHtmlTarget; + result = this.defaultHtmlTarget; - // - return result; - } + // + return result; + } - /** - * {@inheritDoc} - */ - @Override - public StringBuffer dynamize(final TagDataManager data) throws Exception - { - StringBuffer result; + /** + * {@inheritDoc} + */ + @Override + public StringBuffer dynamize(final TagDataManager data) throws Exception + { + StringBuffer result; - if (data == null) - { - result = dynamize(new TagDataManager()); - } - else if (this.dom == null) - { - String errorMessage = "source not defined"; - logger.error(errorMessage); - result = null; - throw new Exception(errorMessage); - } - else - { - // Build the web page. - StringWriter writer = new StringWriter(20000); - DomPresenterCore.dynamize(writer, this.dom, data); - result = writer.getBuffer(); - this.isOutdated = false; - } + if (data == null) + { + result = dynamize(new TagDataManager()); + } + else if (this.dom == null) + { + String errorMessage = "source not defined"; + logger.error(errorMessage); + result = null; + throw new Exception(errorMessage); + } + else + { + // Build the web page. + StringWriter writer = new StringWriter(20000); + DomPresenterCore.dynamize(writer, this.dom, data); + result = writer.getBuffer(); + this.isOutdated = false; + } - // - return (result); - } + // + return (result); + } - /** + /** * */ - public Document getDOM() - { - Document result; + public Document getDOM() + { + Document result; - result = this.dom; + result = this.dom; - // - return (result); - } + // + return (result); + } - /** - * {@inheritDoc} - */ - @Override - public Object getSource() - { - Object result; + /** + * {@inheritDoc} + */ + @Override + public Object getSource() + { + Object result; - result = this.dom; + result = this.dom; - // - return (result); - } + // + return (result); + } - /** - * {@inheritDoc} - */ - @Override - public boolean isAvailable() - { - boolean result; + /** + * {@inheritDoc} + */ + @Override + public boolean isAvailable() + { + boolean result; - if (this.dom == null) - { - result = false; - } - else - { - result = true; - } + if (this.dom == null) + { + result = false; + } + else + { + result = true; + } - // - return result; - } + // + return result; + } - /** - * {@inheritDoc} - */ - @Override - public boolean isOutdated() throws Exception - { - boolean result; + /** + * {@inheritDoc} + */ + @Override + public boolean isOutdated() throws Exception + { + boolean result; - result = this.isOutdated; + result = this.isOutdated; - // - return result; - } + // + return result; + } - /** + /** * */ - public void setDOM(final Document doc) - { - this.dom = doc; - this.isOutdated = true; - } + public void setDOM(final Document doc) + { + this.dom = doc; + this.isOutdated = true; + } - /** + /** * */ - public void setSource(final Document doc) - { - this.dom = doc; - XidynUtils.addMetaTag(this.dom, "generator", "XIDYN"); - this.isOutdated = true; - } + public void setSource(final Document doc) + { + this.dom = doc; + XidynUtils.addMetaTag(this.dom, "generator", "XIDYN"); + this.isOutdated = true; + } - /** - * - * @throws Exception - */ - @Override - public void update() throws Exception - { + /** + * + * @throws Exception + */ + @Override + public void update() throws Exception + { - } + } } diff --git a/src/fr/devinsy/xidyn/presenters/DomPresenterCore.java b/src/fr/devinsy/xidyn/presenters/DomPresenterCore.java index fbcdd89..27b5122 100644 --- a/src/fr/devinsy/xidyn/presenters/DomPresenterCore.java +++ b/src/fr/devinsy/xidyn/presenters/DomPresenterCore.java @@ -46,765 +46,765 @@ import fr.devinsy.xidyn.utils.XidynUtils; */ public class DomPresenterCore { - private static Logger logger = LoggerFactory.getLogger(DomPresenterCore.class); + private static Logger logger = LoggerFactory.getLogger(DomPresenterCore.class); - public static final char INDEX_SEPARATOR = '_'; + public static final char INDEX_SEPARATOR = '_'; - /** - * Dynamize a doc with data. - */ - public static StringBuffer dynamize(final Document doc, final TagDataListById data) throws Exception - { - StringBuffer result; + /** + * Dynamize a doc with data. + */ + public static StringBuffer dynamize(final Document doc, final TagDataListById data) throws Exception + { + StringBuffer result; - StringWriter htmlCode = new StringWriter(); - dynamize(htmlCode, doc, data); - result = htmlCode.getBuffer(); + StringWriter htmlCode = new StringWriter(); + dynamize(htmlCode, doc, data); + result = htmlCode.getBuffer(); - // - return (result); - } + // + return (result); + } - /** - * Dynamize a doc with data. - */ - public static StringBuffer dynamize(final Document doc, final TagDataManager data) throws Exception - { - StringBuffer result; + /** + * Dynamize a doc with data. + */ + public static StringBuffer dynamize(final Document doc, final TagDataManager data) throws Exception + { + StringBuffer result; - result = dynamize(doc, data.getIdsDataById()); + result = dynamize(doc, data.getIdsDataById()); - // - return (result); - } + // + return (result); + } - /** - * Dynamize a doc with data. - */ - public static void dynamize(final Writer result, final Document doc, final TagDataListById data) throws Exception - { - process(result, doc, data); - } + /** + * Dynamize a doc with data. + */ + public static void dynamize(final Writer result, final Document doc, final TagDataListById data) throws Exception + { + process(result, doc, data); + } - /** - * Dynamize a doc with data. - */ - public static void dynamize(final Writer result, final Document doc, final TagDataManager data) throws Exception - { - dynamize(result, doc, data.getIdsDataById()); - } + /** + * Dynamize a doc with data. + */ + public static void dynamize(final Writer result, final Document doc, final TagDataManager data) throws Exception + { + dynamize(result, doc, data.getIdsDataById()); + } - /** + /** * */ - private static String getClassAttributeValue(final Node node) - { - String result; + private static String getClassAttributeValue(final Node node) + { + String result; - NamedNodeMap attributes = node.getAttributes(); - if (attributes == null) - { - result = null; - } - else - { - Node nameAttribute = attributes.getNamedItem("class"); + NamedNodeMap attributes = node.getAttributes(); + if (attributes == null) + { + result = null; + } + else + { + Node nameAttribute = attributes.getNamedItem("class"); - if (nameAttribute == null) - { - result = null; - } - else - { - result = nameAttribute.getNodeValue(); - } - } + if (nameAttribute == null) + { + result = null; + } + else + { + result = nameAttribute.getNodeValue(); + } + } - // - return (result); - } + // + return (result); + } - /** - * Get the text for an element. Converts new lines to spaces. - * - * @param node - */ - private static String getElementText(final Node node) - { - String result; + /** + * Get the text for an element. Converts new lines to spaces. + * + * @param node + */ + private static String getElementText(final Node node) + { + String result; - NodeList children = node.getChildNodes(); - if ((children == null) || (children.getLength() == 0)) - { - result = ""; - } - else - { - boolean ended = false; - result = ""; // Grrrr, Java ... - 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) - { - // STU (+=, newLines...) - result = newLinesToSpaces(child.getNodeValue()); - ended = true; - } - else - { - childCounter += 1; - } - } - } - } + NodeList children = node.getChildNodes(); + if ((children == null) || (children.getLength() == 0)) + { + result = ""; + } + else + { + boolean ended = false; + result = ""; // Grrrr, Java ... + 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) + { + // STU (+=, newLines...) + result = newLinesToSpaces(child.getNodeValue()); + ended = true; + } + else + { + childCounter += 1; + } + } + } + } - // - return (result); - } + // + return (result); + } - /** + /** * */ - private static TagAttributes mergeAttributes(final TagAttributes target, final TagAttributes source) - { - TagAttributes result; + private static TagAttributes mergeAttributes(final TagAttributes target, final TagAttributes source) + { + TagAttributes result; - // - if (target == null) - { - result = source; - } - else if (source == null) - { - result = target; - } - else - { - result = new TagAttributes(target); + // + if (target == null) + { + result = source; + } + else if (source == null) + { + result = target; + } + else + { + result = new TagAttributes(target); - Iterator> iterator = source.entrySet().iterator(); + Iterator> iterator = source.entrySet().iterator(); - while (iterator.hasNext()) - { - Map.Entry attribute = iterator.next(); + while (iterator.hasNext()) + { + Map.Entry attribute = iterator.next(); - String currentValue = target.get(attribute.getKey()); + 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()); - } - } - } + 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); - } + // + return (result); + } - /** - * Converts New Line characters to spaces. This is used when for example the - * text in a div tag goes over several lines. - * - * @param text - * String - * @return String - */ - private static String newLinesToSpaces(final String text) - { - StringBuffer result = new StringBuffer(text); + /** + * Converts New Line characters to spaces. This is used when for example the + * text in a div tag goes over several lines. + * + * @param text + * String + * @return String + */ + private static 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, ' '); - } - } + for (int i = 0; i < result.length(); i++) + { + if (result.charAt(i) == '\n') + { + result.setCharAt(i, ' '); + } + } - // - return (result.toString()); - } + // + return (result.toString()); + } - /** + /** * */ - private static void process(final Writer result, final Node node, final TagDataListById data) throws Exception - { - process(result, node, data, ""); - } + private static void process(final Writer result, final Node node, final TagDataListById data) throws Exception + { + process(result, node, data, ""); + } - /** - * Recursive method that processes a node and any child nodes. - * - */ - private static void process(final Writer result, final Node node, final TagDataListById datas, final String suffix) throws Exception - { - logger.debug("process - started"); - String TRANSITIONAL_DTD = "xhtml1-transitional.dtd"; - String TRANSITIONAL_DOCTYPE = "\n"; + /** + * Recursive method that processes a node and any child nodes. + * + */ + private static void process(final Writer result, final Node node, final TagDataListById 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); + // 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 ((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 (dt != null) + { + // String publicId = dt.getPublicId(); + String systemId = dt.getSystemId(); - if ((systemId != null) && (systemId.equals(TRANSITIONAL_DTD))) - { - result.append(TRANSITIONAL_DOCTYPE); - } + if ((systemId != null) && (systemId.equals(TRANSITIONAL_DTD))) + { + result.append(TRANSITIONAL_DOCTYPE); + } - // Log.write(Log.TRACE,"publicId = " + publicId); - // Log.write(Log.TRACE,"systemId = " + systemId); - } + // Log.write(Log.TRACE,"publicId = " + publicId); + // Log.write(Log.TRACE,"systemId = " + systemId); + } - process(result, ((Document) node).getDocumentElement(), datas, suffix); + process(result, ((Document) node).getDocumentElement(), datas, suffix); - break; - } + break; + } - case Node.ELEMENT_NODE: - { - logger.debug("case Node.ELEMENT_NODE [{}]", node.getNodeName()); + case Node.ELEMENT_NODE: + { + logger.debug("case Node.ELEMENT_NODE [{}]", node.getNodeName()); - NamedNodeMap attrs = node.getAttributes(); - Node idAttr = attrs.getNamedItem("id"); + NamedNodeMap attrs = node.getAttributes(); + Node idAttr = attrs.getNamedItem("id"); - if (idAttr != null) - { - processElementWithId(result, node, attrs, idAttr, datas, suffix); - } - else - { - processElementBasically(result, node, datas, suffix); - } + if (idAttr != null) + { + processElementWithId(result, node, attrs, idAttr, datas, suffix); + } + else + { + processElementBasically(result, node, datas, suffix); + } - break; - } + break; + } - // handle entity reference nodes - case Node.ENTITY_REFERENCE_NODE: - { - logger.debug("case Node.ENTITY_REFERENCE_NODE"); + // 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; - } + result.append('&'); + result.append(node.getNodeName()); + result.append(';'); + break; + } - // print cdata sections - case Node.CDATA_SECTION_NODE: - { - logger.debug("case Node.CDATA_SECTION_NODE"); + // print cdata sections + case Node.CDATA_SECTION_NODE: + { + logger.debug("case Node.CDATA_SECTION_NODE"); - result.append(""); + result.append(""); - break; - } + break; + } - // print text - case Node.TEXT_NODE: - { - logger.debug("case Node.TEXTE_NODE"); - result.append(XidynUtils.restoreEntities(new StringBuffer(node.getNodeValue()))); - break; - } + // print text + case Node.TEXT_NODE: + { + logger.debug("case Node.TEXTE_NODE"); + result.append(XidynUtils.restoreEntities(new StringBuffer(node.getNodeValue()))); + break; + } - // print processing instruction - case Node.PROCESSING_INSTRUCTION_NODE: - { - logger.debug("Node.PROCESSING_INSTRUCTION_NODE"); + // print processing instruction + case Node.PROCESSING_INSTRUCTION_NODE: + { + logger.debug("Node.PROCESSING_INSTRUCTION_NODE"); - result.append(" 0)) - { - result.append(' '); - result.append(value); - } - result.append("?>"); - break; - } - } - } - } + result.append(" 0)) + { + result.append(' '); + result.append(value); + } + result.append("?>"); + break; + } + } + } + } - // - // logger.info ("result=" + result); - logger.debug("process - ended"); - } + // + // logger.info ("result=" + result); + logger.debug("process - ended"); + } - /** + /** * */ - private static StringBuffer processAttributes(final NamedNodeMap attrs) - { - StringBuffer result; + private static StringBuffer processAttributes(final NamedNodeMap attrs) + { + StringBuffer result; - result = processAttributes(attrs, null, null, ""); + result = processAttributes(attrs, null, null, ""); - // - return (result); - } + // + return (result); + } - /** + /** * */ - private static StringBuffer processAttributes(final NamedNodeMap attrs, final TagAttributes dataAttributes) - { - StringBuffer result; + private static StringBuffer processAttributes(final NamedNodeMap attrs, final TagAttributes dataAttributes) + { + StringBuffer result; - result = processAttributes(attrs, dataAttributes, ""); + result = processAttributes(attrs, dataAttributes, ""); - // - return (result); - } + // + return (result); + } - /** + /** * */ - private static StringBuffer processAttributes(final NamedNodeMap attrs, final TagAttributes dataAttributes, final String suffix) - { - StringBuffer result; + private static StringBuffer processAttributes(final NamedNodeMap attrs, final TagAttributes dataAttributes, final String suffix) + { + StringBuffer result; - result = new StringBuffer(); + 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()); - } + // 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(); + // Put model attributes in the merged attributes list. + if (dataAttributes != null) + { + Iterator> iterator = dataAttributes.entrySet().iterator(); - while (iterator.hasNext()) - { - Map.Entry attribute = iterator.next(); + 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()); - } - } - } + 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(); + // 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() + INDEX_SEPARATOR + suffix + "\""); - } - else - { - result.append(" " + attribute.getKey() + "=\"" + attribute.getValue() + "\""); - } - } + if ((attribute.getKey().equals("id")) && (suffix.length() != 0)) + { + result.append(" " + attribute.getKey() + "=\"" + attribute.getValue() + INDEX_SEPARATOR + suffix + "\""); + } + else + { + result.append(" " + attribute.getKey() + "=\"" + attribute.getValue() + "\""); + } + } - // - return (result); - } + // + return (result); + } - /** + /** * */ - private static StringBuffer processAttributes(final NamedNodeMap attrs, final TagAttributes dataAttributes, final TagAttributes namedDataAttributes, final String suffix) - { - StringBuffer result; + private static StringBuffer processAttributes(final NamedNodeMap attrs, final TagAttributes dataAttributes, final TagAttributes namedDataAttributes, final String suffix) + { + StringBuffer result; - result = processAttributes(attrs, mergeAttributes(dataAttributes, namedDataAttributes), suffix); + result = processAttributes(attrs, mergeAttributes(dataAttributes, namedDataAttributes), suffix); - // - return (result); - } + // + return (result); + } - /** + /** * */ - private static void processChildren(final Writer result, final Node node, final TagDataListById datas) throws Exception - { - processChildren(result, node, datas, ""); - } + private static void processChildren(final Writer result, final Node node, final TagDataListById datas) throws Exception + { + processChildren(result, node, datas, ""); + } - /** + /** * */ - private static void processChildren(final Writer result, final Node node, final TagDataListById datas, final String suffix) throws Exception - { - // Get the iteration strategy. - SimpleTagData.IterationStrategy strategy; + private static void processChildren(final Writer result, final Node node, final TagDataListById datas, final String suffix) throws Exception + { + // Get the iteration strategy. + SimpleTagData.IterationStrategy strategy; - NamedNodeMap attributes = node.getAttributes(); - if (attributes == null) - { - strategy = SimpleTagData.IterationStrategy.ALL_ROWS; - } - else - { - Node id = attributes.getNamedItem("id"); + NamedNodeMap attributes = node.getAttributes(); + if (attributes == null) + { + strategy = SimpleTagData.IterationStrategy.ALL_ROWS; + } + else + { + Node id = attributes.getNamedItem("id"); - if (id == null) - { - strategy = SimpleTagData.IterationStrategy.ALL_ROWS; - } - else - { - TagData dataCore = datas.getId(id.getNodeValue()); - if (dataCore == null) - { - strategy = SimpleTagData.IterationStrategy.ALL_ROWS; - } - else if (dataCore instanceof SimpleTagData) - { - SimpleTagData data = (SimpleTagData) dataCore; - strategy = data.iterationStrategy(); - } - else - { - strategy = SimpleTagData.IterationStrategy.ALL_ROWS; - } - } - } + if (id == null) + { + strategy = SimpleTagData.IterationStrategy.ALL_ROWS; + } + else + { + TagData dataCore = datas.getId(id.getNodeValue()); + if (dataCore == null) + { + strategy = SimpleTagData.IterationStrategy.ALL_ROWS; + } + else if (dataCore instanceof SimpleTagData) + { + SimpleTagData data = (SimpleTagData) dataCore; + strategy = data.iterationStrategy(); + } + else + { + strategy = SimpleTagData.IterationStrategy.ALL_ROWS; + } + } + } - // Iterate. - NodeList children = node.getChildNodes(); - int childrenCount = children.getLength(); + // 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; + 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; + 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; + 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(); + 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; + 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 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; - } - } + case ALL_ROWS: + for (int childIndex = 0; childIndex < childrenCount; childIndex++) + { + process(result, children.item(childIndex), datas, suffix); + } + break; + } + } - /** - * TODO remove? - */ - private static void processElementBasically(final Writer result, final Node node, final TagDataListById datas) throws Exception - { - processElementBasically(result, node, datas, ""); - } + /** + * TODO remove? + */ + private static void processElementBasically(final Writer result, final Node node, final TagDataListById datas) throws Exception + { + processElementBasically(result, node, datas, ""); + } - /** + /** * */ - private static void processElementBasically(final Writer result, final Node node, final TagDataListById datas, final String suffix) throws Exception - { - logger.debug("processElementBasically - started [{}]", node.getNodeName()); + private static void processElementBasically(final Writer result, final Node node, final TagDataListById datas, final String suffix) throws Exception + { + logger.debug("processElementBasically - started [{}]", node.getNodeName()); - // Open the tag. - result.append('<'); - result.append(node.getNodeName()); + // Open the tag. + result.append('<'); + result.append(node.getNodeName()); - // Build the tag attributes. - // Attributes tagAttributes; + // Build the tag attributes. + // Attributes tagAttributes; - result.append(processAttributes(node.getAttributes(), null, suffix)); + result.append(processAttributes(node.getAttributes(), null, suffix)); - // - if ((node.getChildNodes() == null) || (node.getChildNodes().getLength() == 0)) - { - result.append(" />"); - } - else - { - result.append('>'); + // + if ((node.getChildNodes() == null) || (node.getChildNodes().getLength() == 0)) + { + result.append(" />"); + } + else + { + result.append('>'); - processChildren(result, node, datas, suffix); + processChildren(result, node, datas, suffix); - result.append("'); - } + result.append("'); + } - logger.debug("processElementBasically - ended"); - } + 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. - */ - private static void processElementWithId(final Writer result, final Node node, final NamedNodeMap attrs, final Node idAttr, final TagDataListById datas) throws Exception + /** + * 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. + */ + private static void processElementWithId(final Writer result, final Node node, final NamedNodeMap attrs, final Node idAttr, final TagDataListById datas) throws Exception - { - processElementWithId(result, node, attrs, idAttr, datas, ""); - } + { + 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. - */ - private static void processElementWithId(final Writer result, final Node node, final NamedNodeMap attrs, final Node idAttr, final TagDataListById datas, final String suffix) throws Exception - { - String tag = node.getNodeName(); + /** + * 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. + */ + private static void processElementWithId(final Writer result, final Node node, final NamedNodeMap attrs, final Node idAttr, final TagDataListById datas, final String suffix) throws Exception + { + String tag = node.getNodeName(); - // String idValue = idAttr.getNodeValue(); + // String idValue = idAttr.getNodeValue(); - logger.debug("tag=" + tag); + logger.debug("tag=" + tag); - // Get data of this id. - TagData dataCore = datas.get(idAttr.getNodeValue()); + // Get data of this id. + TagData dataCore = datas.get(idAttr.getNodeValue()); - if (dataCore == null) - { - processElementBasically(result, node, datas, suffix); - } - else if (dataCore instanceof SimpleTagData) - { - SimpleTagData data = (SimpleTagData) dataCore; + if (dataCore == null) + { + processElementBasically(result, node, datas, suffix); + } + else if (dataCore instanceof SimpleTagData) + { + SimpleTagData data = (SimpleTagData) dataCore; - String theClass = data.attributes().getAttribute("class"); + String theClass = data.attributes().getAttribute("class"); - if ((theClass == null) || (!theClass.equals("xid:nodisplay"))) - { - // Open the tag. - result.append("<"); - result.append(node.getNodeName()); + 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)); + // Build attributes. + result.append(processAttributes(attrs, data.attributes(), suffix)); - if (((node.getChildNodes() == null) || (node.getChildNodes().getLength() == 0)) && ((data == null) || (data.display() == null))) - { - // Close the tag. - result.append(" />"); - } - else - { - result.append('>'); + if (((node.getChildNodes() == null) || (node.getChildNodes().getLength() == 0)) && ((data == null) || (data.display() == null))) + { + // Close the tag. + result.append(" />"); + } + else + { + result.append('>'); - // CHANGED, cpm: + // CHANGED, cpm: - // Insert data. - if ((data == null) || (data.display() == null)) - { - processChildren(result, node, datas, suffix); - } - else - { - result.append(data.display()); - } + // 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 TagDataListByIndex) - { - TagDataListByIndex tags = (TagDataListByIndex) dataCore; + // Close the tag. + result.append("'); + } + } + } + else if (dataCore instanceof TagDataListByIndex) + { + TagDataListByIndex tags = (TagDataListByIndex) dataCore; - int nbLines = tags.size(); - for (int nLine = 0; nLine < nbLines; nLine++) - { - if (tags.elementAt(nLine) instanceof SimpleTagData) - { - SimpleTagData data = (SimpleTagData) tags.elementAt(nLine); + int nbLines = tags.size(); + for (int nLine = 0; nLine < nbLines; nLine++) + { + if (tags.elementAt(nLine) instanceof SimpleTagData) + { + SimpleTagData data = (SimpleTagData) tags.elementAt(nLine); - // Open the tag. - result.append("<"); - result.append(node.getNodeName()); + // Open the tag. + result.append("<"); + result.append(node.getNodeName()); - result.append(processAttributes(attrs, data.attributes(), Integer.toString(nLine))); + result.append(processAttributes(attrs, data.attributes(), Integer.toString(nLine))); - if (((node.getChildNodes() == null) || (node.getChildNodes().getLength() == 0)) && ((data == null) || (data.display() == null))) - { - // Close the tag. - result.append(" />\n"); - } - else - { - result.append('>'); + if (((node.getChildNodes() == null) || (node.getChildNodes().getLength() == 0)) && ((data == null) || (data.display() == null))) + { + // Close the tag. + result.append(" />\n"); + } + else + { + result.append('>'); - // CHANGED, cpm + // CHANGED, cpm - // Insert data. - if ((data == null) || (data.display() == null)) - { - processChildren(result, node, datas, suffix); - } - else - { - result.append(data.display()); - } + // 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. - TagDataListById data = (TagDataListById) tags.elementAt(nLine); + // Close the tag. + result.append("\n"); + } + } + else + { + // Manage a Hashmap. + TagDataListById data = (TagDataListById) tags.elementAt(nLine); - processElementWithId(result, node, attrs, idAttr, data, Integer.toString(nLine)); - result.append('\n'); - } - } - } - else - { - logger.warn("Unknow type of IdDataId"); - } + processElementWithId(result, node, attrs, idAttr, data, Integer.toString(nLine)); + result.append('\n'); + } + } + } + else + { + logger.warn("Unknow type of IdDataId"); + } - // - logger.debug("Exit"); - } + // + logger.debug("Exit"); + } } diff --git a/src/fr/devinsy/xidyn/presenters/FilePresenter.java b/src/fr/devinsy/xidyn/presenters/FilePresenter.java index 81a5fd8..7055428 100644 --- a/src/fr/devinsy/xidyn/presenters/FilePresenter.java +++ b/src/fr/devinsy/xidyn/presenters/FilePresenter.java @@ -33,233 +33,233 @@ import fr.devinsy.xidyn.utils.XidynUtils; */ public class FilePresenter extends StringPresenter { - private static Logger logger = LoggerFactory.getLogger(FilePresenter.class); + private static Logger logger = LoggerFactory.getLogger(FilePresenter.class); - private File source; - private String sourceFilePathname; - private long sourceTime; + private File source; + private String sourceFilePathname; + private long sourceTime; - /** + /** * */ - public FilePresenter() - { - setSource((String) null); - } + public FilePresenter() + { + setSource((String) null); + } - /** + /** * */ - public FilePresenter(final File source) - { - setSource(source); - } + public FilePresenter(final File source) + { + setSource(source); + } - /** + /** * */ - public FilePresenter(final String filePathname) - { - setSource(filePathname); - } + public FilePresenter(final String filePathname) + { + setSource(filePathname); + } - /** - * {@inheritDoc} - */ - @Override - public StringBuffer dynamize() throws Exception - { - StringBuffer result; + /** + * {@inheritDoc} + */ + @Override + public StringBuffer dynamize() throws Exception + { + StringBuffer result; - // - update(); + // + update(); - // - result = super.dynamize(); + // + result = super.dynamize(); - // - return result; - } + // + return result; + } - /** - * No need to be synchronized. - * - * {@inheritDoc} - */ - @Override - public StringBuffer dynamize(final TagDataManager data) throws Exception - { - StringBuffer result; + /** + * No need to be synchronized. + * + * {@inheritDoc} + */ + @Override + public StringBuffer dynamize(final TagDataManager data) throws Exception + { + StringBuffer result; - logger.info("dynamize file [" + this.sourceFilePathname + "]"); + logger.info("dynamize file [" + this.sourceFilePathname + "]"); - // - update(); + // + update(); - // Build the web page. - result = super.dynamize(data); + // Build the web page. + result = super.dynamize(data); - // - return (result); - } + // + return (result); + } - /** + /** * */ - public File getFile() - { - File result; + public File getFile() + { + File result; - result = this.source; + result = this.source; - // - return (result); - } + // + return (result); + } - /** - * {@inheritDoc} - */ - @Override - public String getSource() - { - String result; + /** + * {@inheritDoc} + */ + @Override + public String getSource() + { + String result; - result = this.sourceFilePathname; + result = this.sourceFilePathname; - // - return (result); - } + // + return (result); + } - /** - * {@inheritDoc} - */ - @Override - public boolean isAvailable() - { - boolean result; + /** + * {@inheritDoc} + */ + @Override + public boolean isAvailable() + { + boolean result; - if ((this.source == null) || (!this.source.exists())) - { - result = false; - } - else - { - result = true; - } + if ((this.source == null) || (!this.source.exists())) + { + result = false; + } + else + { + result = true; + } - // - return result; - } + // + return result; + } - /** - * {@inheritDoc} - */ - @Override - public boolean isOutdated() throws Exception - { - boolean result; + /** + * {@inheritDoc} + */ + @Override + public boolean isOutdated() throws Exception + { + boolean result; - // - if (super.isOutdated()) - { - result = true; - } - else if (this.sourceTime == this.source.lastModified()) - { - result = true; - } - else - { - result = false; - } + // + if (super.isOutdated()) + { + result = true; + } + else if (this.sourceTime == this.source.lastModified()) + { + result = true; + } + else + { + result = false; + } - // - return result; - } + // + return result; + } - /** + /** * */ - public void setSource(final File source) - { - if (source == null) - { - super.setSource(null); - this.source = null; - this.sourceFilePathname = null; - this.sourceTime = 0; - setSource((String) null); - } - else - { - this.source = source; - this.sourceFilePathname = source.getAbsolutePath(); - this.sourceTime = 0; - super.setSource(null); - } - } + public void setSource(final File source) + { + if (source == null) + { + super.setSource(null); + this.source = null; + this.sourceFilePathname = null; + this.sourceTime = 0; + setSource((String) null); + } + else + { + this.source = source; + this.sourceFilePathname = source.getAbsolutePath(); + this.sourceTime = 0; + super.setSource(null); + } + } - /** - * @throws Exception - * - */ - @Override - public void setSource(final String source) - { - // - File file; - if (source == null) - { - file = null; - } - else if (source.matches("file://.+")) - { - try - { - file = new File(new URI(source)); - } - catch (URISyntaxException exception) - { - exception.printStackTrace(); - throw new IllegalArgumentException("Bad URI argument.", exception); - } - } - else - { - file = new File(source); - } + /** + * @throws Exception + * + */ + @Override + public void setSource(final String source) + { + // + File file; + if (source == null) + { + file = null; + } + else if (source.matches("file://.+")) + { + try + { + file = new File(new URI(source)); + } + catch (URISyntaxException exception) + { + exception.printStackTrace(); + throw new IllegalArgumentException("Bad URI argument.", exception); + } + } + else + { + file = new File(source); + } - // - setSource(file); - } + // + setSource(file); + } - /** - * @throws Exception - */ - @Override - public void update() throws Exception - { - // - if (this.source == null) - { - String errorMessage = "source not defined"; - logger.error(errorMessage); - throw new NullPointerException(errorMessage); - } - else if (!this.source.exists()) - { - String errorMessage = "source file defined but not found (" + this.sourceFilePathname + ")"; - logger.error(errorMessage); - throw new Exception(errorMessage); - } - else - { - long currentTime = this.source.lastModified(); - if ((super.getSource() == null) || (this.sourceTime != currentTime)) - { - super.setSource(XidynUtils.load(this.source)); - this.sourceTime = currentTime; - } - } - } + /** + * @throws Exception + */ + @Override + public void update() throws Exception + { + // + if (this.source == null) + { + String errorMessage = "source not defined"; + logger.error(errorMessage); + throw new NullPointerException(errorMessage); + } + else if (!this.source.exists()) + { + String errorMessage = "source file defined but not found (" + this.sourceFilePathname + ")"; + logger.error(errorMessage); + throw new Exception(errorMessage); + } + else + { + long currentTime = this.source.lastModified(); + if ((super.getSource() == null) || (this.sourceTime != currentTime)) + { + super.setSource(XidynUtils.load(this.source)); + this.sourceTime = currentTime; + } + } + } } diff --git a/src/fr/devinsy/xidyn/presenters/FilePresenters.java b/src/fr/devinsy/xidyn/presenters/FilePresenters.java index b9ae775..37dc700 100644 --- a/src/fr/devinsy/xidyn/presenters/FilePresenters.java +++ b/src/fr/devinsy/xidyn/presenters/FilePresenters.java @@ -28,163 +28,163 @@ import org.slf4j.LoggerFactory; */ public class FilePresenters extends Vector { - private static final long serialVersionUID = 7058868685681354293L; - private static Logger logger = LoggerFactory.getLogger(FilePresenters.class); + private static final long serialVersionUID = 7058868685681354293L; + private static Logger logger = LoggerFactory.getLogger(FilePresenters.class); - /** + /** * */ - public FilePresenters() - { - super(); - } + public FilePresenters() + { + super(); + } - /** + /** * */ - public FilePresenters(final FilePresenters source) - { - super(); - for (FilePresenter presenter : source) - { - this.add(presenter); - } - } + public FilePresenters(final FilePresenters source) + { + super(); + for (FilePresenter presenter : source) + { + this.add(presenter); + } + } - /** + /** * */ - public boolean exists(final String source) - { - boolean result; + public boolean exists(final String source) + { + boolean result; - if (this.getBySource(source) == null) - { - result = false; - } - else - { - result = true; - } + if (this.getBySource(source) == null) + { + result = false; + } + else + { + result = true; + } - // - return (result); - } + // + return (result); + } - /** + /** * */ - public FilePresenter getByIndex(final int id) - { - FilePresenter result; + public FilePresenter getByIndex(final int id) + { + FilePresenter result; - result = this.get(id); + result = this.get(id); - // - return (result); - } + // + return (result); + } - /** + /** * */ - public FilePresenter getBySource(final String source) - { - FilePresenter result; + public FilePresenter getBySource(final String source) + { + FilePresenter result; - if (source == null) - { - result = null; - } - else - { - result = null; - boolean ended = false; - int presenterIndex = 0; - while (!ended) - { - if (presenterIndex < this.size()) - { - FilePresenter presenter = this.get(presenterIndex); + if (source == null) + { + result = null; + } + else + { + result = null; + boolean ended = false; + int presenterIndex = 0; + while (!ended) + { + if (presenterIndex < this.size()) + { + FilePresenter presenter = this.get(presenterIndex); - if (presenter.getSource().equals(source)) - { - result = presenter; - ended = true; - } - else - { - presenterIndex += 1; - } - } - else - { - ended = true; - result = null; - } - } - } + if (presenter.getSource().equals(source)) + { + result = presenter; + ended = true; + } + else + { + presenterIndex += 1; + } + } + else + { + ended = true; + result = null; + } + } + } - // - return (result); - } + // + return (result); + } - /** + /** * */ - public int getIndexOf(final String source) - { - int result; + public int getIndexOf(final String source) + { + int result; - if (source == null) - { - result = -1; - } - else - { - result = -1; - boolean ended = false; - int presenterIndex = 0; - while (!ended) - { - if (presenterIndex < this.size()) - { - FilePresenter presenter = this.get(presenterIndex); + if (source == null) + { + result = -1; + } + else + { + result = -1; + boolean ended = false; + int presenterIndex = 0; + while (!ended) + { + if (presenterIndex < this.size()) + { + FilePresenter presenter = this.get(presenterIndex); - if (presenter.getSource().equals(source)) - { - result = presenterIndex; - ended = true; - } - else - { - presenterIndex += 1; - } - } - else - { - ended = true; - result = -1; - } - } - } + if (presenter.getSource().equals(source)) + { + result = presenterIndex; + ended = true; + } + else + { + presenterIndex += 1; + } + } + else + { + ended = true; + result = -1; + } + } + } - // - return (result); - } + // + return (result); + } - /** + /** * */ - @Override - public String toString() - { - String result; + @Override + public String toString() + { + String result; - result = ""; + result = ""; - // - return (result); - } + // + return (result); + } } // //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/fr/devinsy/xidyn/presenters/FilePresentersProxy.java b/src/fr/devinsy/xidyn/presenters/FilePresentersProxy.java index 4cd7de6..d1c4ec1 100644 --- a/src/fr/devinsy/xidyn/presenters/FilePresentersProxy.java +++ b/src/fr/devinsy/xidyn/presenters/FilePresentersProxy.java @@ -26,61 +26,61 @@ import org.slf4j.LoggerFactory; */ public class FilePresentersProxy { - private static Logger logger = LoggerFactory.getLogger(FilePresentersProxy.class); + private static Logger logger = LoggerFactory.getLogger(FilePresentersProxy.class); - private static FilePresentersProxy instance = null; - private FilePresenters presenters = null; + private static FilePresentersProxy instance = null; + private FilePresenters presenters = null; - /** + /** * */ - protected FilePresentersProxy() throws Exception - { - this.presenters = new FilePresenters(); - } + protected FilePresentersProxy() throws Exception + { + this.presenters = new FilePresenters(); + } - /** + /** * */ - public FilePresenter getBySource(final String source) throws Exception - { - FilePresenter result; + public FilePresenter getBySource(final String source) throws Exception + { + FilePresenter result; - if (source == null) - { - result = null; - } - else - { - result = this.presenters.getBySource(source); - if (result == null) - { - result = new FilePresenter(source); - this.presenters.add(result); - } - } + if (source == null) + { + result = null; + } + else + { + result = this.presenters.getBySource(source); + if (result == null) + { + result = new FilePresenter(source); + this.presenters.add(result); + } + } - // - return (result); - } + // + return (result); + } - /** + /** * */ - public static FilePresentersProxy instance() throws Exception - { - FilePresentersProxy result; + public static FilePresentersProxy instance() throws Exception + { + FilePresentersProxy result; - if (FilePresentersProxy.instance == null) - { - instance = new FilePresentersProxy(); - } + if (FilePresentersProxy.instance == null) + { + instance = new FilePresentersProxy(); + } - result = instance; + result = instance; - // - return (result); - } + // + return (result); + } } // //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/fr/devinsy/xidyn/presenters/GenericPresenter.java b/src/fr/devinsy/xidyn/presenters/GenericPresenter.java index 248fb56..2bdcf9f 100644 --- a/src/fr/devinsy/xidyn/presenters/GenericPresenter.java +++ b/src/fr/devinsy/xidyn/presenters/GenericPresenter.java @@ -30,226 +30,226 @@ import fr.devinsy.xidyn.data.TagDataManager; */ public class GenericPresenter implements Presenter { - private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(GenericPresenter.class); + private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(GenericPresenter.class); - private Presenter presenter; + private Presenter presenter; - /** + /** * */ - public GenericPresenter(final Document source) - { - if (source == null) - { - throw new NullPointerException("source is null"); - } - else - { - this.presenter = PresenterFactory.create(source); - } - } + public GenericPresenter(final Document source) + { + if (source == null) + { + throw new NullPointerException("source is null"); + } + else + { + this.presenter = PresenterFactory.create(source); + } + } - /** + /** * */ - public GenericPresenter(final File source) - { - if (source == null) - { - throw new NullPointerException("source is null"); - } - else - { - this.presenter = PresenterFactory.create(source); - } - } + public GenericPresenter(final File source) + { + if (source == null) + { + throw new NullPointerException("source is null"); + } + else + { + this.presenter = PresenterFactory.create(source); + } + } - /** + /** * */ - public GenericPresenter(final String source) - { - if (source == null) - { - throw new NullPointerException("source is null"); - } - else - { - this.presenter = PresenterFactory.create(source); - } - } + public GenericPresenter(final String source) + { + if (source == null) + { + throw new NullPointerException("source is null"); + } + else + { + this.presenter = PresenterFactory.create(source); + } + } - /** + /** * */ - public GenericPresenter(final URL source) - { - if (source == null) - { - throw new NullPointerException("source is null"); - } - else - { - this.presenter = PresenterFactory.create(source); - } - } + public GenericPresenter(final URL source) + { + if (source == null) + { + throw new NullPointerException("source is null"); + } + else + { + this.presenter = PresenterFactory.create(source); + } + } - /** + /** * */ - @Override - public StringBuffer dynamize() throws Exception - { - StringBuffer result; + @Override + public StringBuffer dynamize() throws Exception + { + StringBuffer result; - result = this.presenter.dynamize(); + result = this.presenter.dynamize(); - // - return result; - } + // + return result; + } - /** + /** * */ - @Override - public StringBuffer dynamize(final TagDataManager datas) throws Exception - { - StringBuffer result; + @Override + public StringBuffer dynamize(final TagDataManager datas) throws Exception + { + StringBuffer result; - result = this.presenter.dynamize(datas); + result = this.presenter.dynamize(datas); - // - return result; - } + // + return result; + } - /** + /** * */ - @Override - public Object getSource() - { - Object result; + @Override + public Object getSource() + { + Object result; - result = this.presenter.getSource(); + result = this.presenter.getSource(); - // - return result; - } + // + return result; + } - /** - * {@inheritDoc} - */ - @Override - public boolean isAvailable() - { - boolean result; + /** + * {@inheritDoc} + */ + @Override + public boolean isAvailable() + { + boolean result; - result = this.presenter.isAvailable(); + result = this.presenter.isAvailable(); - // - return result; - } + // + return result; + } - /** + /** * */ - @Override - public boolean isOutdated() throws Exception - { - boolean result; + @Override + public boolean isOutdated() throws Exception + { + boolean result; - result = this.presenter.isOutdated(); + result = this.presenter.isOutdated(); - // - return result; - } + // + return result; + } - /** - * - * @param source - */ - public void setSource(final Document source) - { - if (source == null) - { - throw new NullPointerException("source is null"); - } - else - { - this.presenter = PresenterFactory.create(source); - } - } + /** + * + * @param source + */ + public void setSource(final Document source) + { + if (source == null) + { + throw new NullPointerException("source is null"); + } + else + { + this.presenter = PresenterFactory.create(source); + } + } - /** - * - * @param source - */ - public void setSource(final File source) - { - if (source == null) - { - throw new NullPointerException("source is null"); - } - else - { - this.presenter = PresenterFactory.create(source); - } - } + /** + * + * @param source + */ + public void setSource(final File source) + { + if (source == null) + { + throw new NullPointerException("source is null"); + } + else + { + this.presenter = PresenterFactory.create(source); + } + } - /** - * - * @param source - */ - public void setSource(final String source) - { - if (source == null) - { - throw new NullPointerException("source is null"); - } - else - { - this.presenter = PresenterFactory.create(source); - } - } + /** + * + * @param source + */ + public void setSource(final String source) + { + if (source == null) + { + throw new NullPointerException("source is null"); + } + else + { + this.presenter = PresenterFactory.create(source); + } + } - /** - * - * @param source - */ - public void setSource(final URL source) - { - if (source == null) - { - throw new NullPointerException("source is null"); - } - else - { - this.presenter = PresenterFactory.create(source); - } - } + /** + * + * @param source + */ + public void setSource(final URL source) + { + if (source == null) + { + throw new NullPointerException("source is null"); + } + else + { + this.presenter = PresenterFactory.create(source); + } + } - /** + /** * */ - public String toString(final String language) throws Exception - { - String result; + public String toString(final String language) throws Exception + { + String result; - result = this.presenter.toString(); + result = this.presenter.toString(); - // - return result; - } + // + return result; + } - /** + /** * */ - @Override - public void update() throws Exception - { - this.presenter.update(); + @Override + public void update() throws Exception + { + this.presenter.update(); - } + } } // //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/fr/devinsy/xidyn/presenters/Presenter.java b/src/fr/devinsy/xidyn/presenters/Presenter.java index 1e94dbc..529cf26 100644 --- a/src/fr/devinsy/xidyn/presenters/Presenter.java +++ b/src/fr/devinsy/xidyn/presenters/Presenter.java @@ -30,43 +30,43 @@ import fr.devinsy.xidyn.data.TagDataManager; */ public interface Presenter { - /** - * - * @param datas - * @return - * @throws Exception - */ - public StringBuffer dynamize() throws Exception; + /** + * + * @param datas + * @return + * @throws Exception + */ + public StringBuffer dynamize() throws Exception; - /** - * - * @param datas - * @return - * @throws Exception - */ - public StringBuffer dynamize(final TagDataManager datas) throws Exception; + /** + * + * @param datas + * @return + * @throws Exception + */ + public StringBuffer dynamize(final TagDataManager datas) throws Exception; - /** - * - * @return - */ - public Object getSource(); + /** + * + * @return + */ + public Object getSource(); - /** - * This method check if the source exists and it is readable. - * - * @return - */ - public boolean isAvailable(); + /** + * This method check if the source exists and it is readable. + * + * @return + */ + public boolean isAvailable(); - /** - * - * @return - */ - public boolean isOutdated() throws Exception; + /** + * + * @return + */ + public boolean isOutdated() throws Exception; - /** + /** * */ - public void update() throws Exception; + public void update() throws Exception; } diff --git a/src/fr/devinsy/xidyn/presenters/PresenterFactory.java b/src/fr/devinsy/xidyn/presenters/PresenterFactory.java index 7e532c1..64db319 100644 --- a/src/fr/devinsy/xidyn/presenters/PresenterFactory.java +++ b/src/fr/devinsy/xidyn/presenters/PresenterFactory.java @@ -32,246 +32,246 @@ import fr.devinsy.xidyn.utils.cache.Cache; */ public class PresenterFactory { - /** - * http://thecodersbreakfast.net/index.php?post/2008/02/25/26-de-la-bonne- - * implementation-du-singleton-en-java - */ - private static class SingletonHolder - { - private final static PresenterFactory INSTANCE = new PresenterFactory(); - } + /** + * http://thecodersbreakfast.net/index.php?post/2008/02/25/26-de-la-bonne- + * implementation-du-singleton-en-java + */ + private static class SingletonHolder + { + private final static PresenterFactory INSTANCE = new PresenterFactory(); + } - private static Logger logger = LoggerFactory.getLogger(PresenterFactory.class); + private static Logger logger = LoggerFactory.getLogger(PresenterFactory.class); - private Cache cache; + private Cache cache; - /** + /** * */ - private PresenterFactory() - { - this.cache = new Cache(); - } + private PresenterFactory() + { + this.cache = new Cache(); + } - /** + /** * */ - public void clear() - { - this.cache.clear(); - } + public void clear() + { + this.cache.clear(); + } - /** - * - * @param source - * @return - */ - public Presenter get(final Document source) - { - Presenter result; + /** + * + * @param source + * @return + */ + public Presenter get(final Document source) + { + Presenter result; - result = this.cache.get(source); + result = this.cache.get(source); - if (result == null) - { - result = create(source); - this.cache.put(source, result); - } + if (result == null) + { + result = create(source); + this.cache.put(source, result); + } - // - return result; - } + // + return result; + } - /** - * - * @param source - * @return - */ - public Presenter get(final File source) - { - Presenter result; + /** + * + * @param source + * @return + */ + public Presenter get(final File source) + { + Presenter result; - result = this.cache.get(source); + result = this.cache.get(source); - if (result == null) - { - result = create(source); - this.cache.put(source, result); - } + if (result == null) + { + result = create(source); + this.cache.put(source, result); + } - // - return result; - } + // + return result; + } - /** - * - * @param source - * @return - */ - public Presenter get(final String source) - { - Presenter result; + /** + * + * @param source + * @return + */ + public Presenter get(final String source) + { + Presenter result; - result = this.cache.get(source); + result = this.cache.get(source); - if (result == null) - { - result = create(source); - this.cache.put(source, result); - } + if (result == null) + { + result = create(source); + this.cache.put(source, result); + } - // - return result; - } + // + return result; + } - /** - * - * @param source - * @return - */ - public Presenter get(final URL source) - { - Presenter result; + /** + * + * @param source + * @return + */ + public Presenter get(final URL source) + { + Presenter result; - result = this.cache.get(source); + result = this.cache.get(source); - if (result == null) - { - result = create(source); - this.cache.put(source, result); - } + if (result == null) + { + result = create(source); + this.cache.put(source, result); + } - // - return result; - } + // + return result; + } - /** - * - * @return - */ - public int size() - { - int result; + /** + * + * @return + */ + public int size() + { + int result; - result = this.cache.size(); + result = this.cache.size(); - // - return result; - } + // + return result; + } - /** - * - * @param source - * @return - */ - public static Presenter create(final Document source) - { - Presenter result; + /** + * + * @param source + * @return + */ + public static Presenter create(final Document source) + { + Presenter result; - if (source == null) - { - result = null; - } - else - { - result = new DomPresenter(source); - } + if (source == null) + { + result = null; + } + else + { + result = new DomPresenter(source); + } - // - return result; - } + // + return result; + } - /** - * - * @param source - * @return - */ - public static Presenter create(final File source) - { - Presenter result; + /** + * + * @param source + * @return + */ + public static Presenter create(final File source) + { + Presenter result; - if (source == null) - { - result = null; - } - else - { - result = new FilePresenter(source); - } + if (source == null) + { + result = null; + } + else + { + result = new FilePresenter(source); + } - // - return result; - } + // + return result; + } - /** - * - * @param source - * @return - */ - public static Presenter create(final String source) - { - Presenter result; + /** + * + * @param source + * @return + */ + public static Presenter create(final String source) + { + Presenter result; - if (source == null) - { - result = null; - } - else if (source.startsWith("file://")) - { - result = new FilePresenter(source); - } - else if (source.matches(".+://.+")) - { - result = new URLPresenter(source); - } - else if (source.startsWith("/")) - { - if (new File(source).exists()) - { - result = new FilePresenter(source); - } - else - { - result = new URLPresenter(source); - } - } - else - { - result = new StringPresenter(source); - } + if (source == null) + { + result = null; + } + else if (source.startsWith("file://")) + { + result = new FilePresenter(source); + } + else if (source.matches(".+://.+")) + { + result = new URLPresenter(source); + } + else if (source.startsWith("/")) + { + if (new File(source).exists()) + { + result = new FilePresenter(source); + } + else + { + result = new URLPresenter(source); + } + } + else + { + result = new StringPresenter(source); + } - // - return result; - } + // + return result; + } - /** - * - * @param source - * @return - */ - public static Presenter create(final URL source) - { - Presenter result; + /** + * + * @param source + * @return + */ + public static Presenter create(final URL source) + { + Presenter result; - if (source == null) - { - result = null; - } - else - { - result = new URLPresenter(source); - } + if (source == null) + { + result = null; + } + else + { + result = new URLPresenter(source); + } - // - return result; - } + // + return result; + } - /** - * - * @return - */ - public static PresenterFactory instance() - { - return SingletonHolder.INSTANCE; - } + /** + * + * @return + */ + public static PresenterFactory instance() + { + return SingletonHolder.INSTANCE; + } } diff --git a/src/fr/devinsy/xidyn/presenters/PresenterUtils.java b/src/fr/devinsy/xidyn/presenters/PresenterUtils.java index 2be9362..445b08f 100644 --- a/src/fr/devinsy/xidyn/presenters/PresenterUtils.java +++ b/src/fr/devinsy/xidyn/presenters/PresenterUtils.java @@ -32,121 +32,121 @@ import fr.devinsy.xidyn.data.TagDataManager; */ public class PresenterUtils { - private static Logger logger = LoggerFactory.getLogger(PresenterUtils.class); + private static Logger logger = LoggerFactory.getLogger(PresenterUtils.class); - /** + /** * */ - private PresenterUtils() - { - } + private PresenterUtils() + { + } - /** - * - * @param doc - * @param data - * @return - * @throws Exception - */ - public static StringBuffer dynamize(final Document doc, final TagDataListById data) throws Exception - { - StringBuffer result; + /** + * + * @param doc + * @param data + * @return + * @throws Exception + */ + public static StringBuffer dynamize(final Document doc, final TagDataListById data) throws Exception + { + StringBuffer result; - result = DomPresenterCore.dynamize(doc, data); + result = DomPresenterCore.dynamize(doc, data); - // - return result; - } + // + return result; + } - /** - * - * @param doc - * @param data - * @return - * @throws Exception - */ - public static StringBuffer dynamize(final Document doc, final TagDataManager data) throws Exception - { - StringBuffer result; + /** + * + * @param doc + * @param data + * @return + * @throws Exception + */ + public static StringBuffer dynamize(final Document doc, final TagDataManager data) throws Exception + { + StringBuffer result; - result = DomPresenterCore.dynamize(doc, data); + result = DomPresenterCore.dynamize(doc, data); - // - return result; - } + // + return result; + } - /** - * Dynamize a file without data. - */ - public static StringBuffer dynamize(final File source) throws Exception - { - StringBuffer result; + /** + * Dynamize a file without data. + */ + public static StringBuffer dynamize(final File source) throws Exception + { + StringBuffer result; - FilePresenter presenter = new FilePresenter(source); + FilePresenter presenter = new FilePresenter(source); - result = presenter.dynamize((TagDataManager) null); + result = presenter.dynamize((TagDataManager) null); - // - return (result); - } + // + return (result); + } - /** - * Dynamize a file. - */ - public static StringBuffer dynamize(final File source, final TagDataManager datas) throws Exception - { - StringBuffer result; + /** + * Dynamize a file. + */ + public static StringBuffer dynamize(final File source, final TagDataManager datas) throws Exception + { + StringBuffer result; - FilePresenter presenter = new FilePresenter(source); + FilePresenter presenter = new FilePresenter(source); - result = presenter.dynamize(datas); + result = presenter.dynamize(datas); - // - return (result); - } + // + return (result); + } - /** - * Dynamize a string with HTML in, or with file path name in, or with URL - * in. - */ - public static StringBuffer dynamize(final String source, final TagDataManager datas) throws Exception - { - StringBuffer result; + /** + * Dynamize a string with HTML in, or with file path name in, or with URL + * in. + */ + public static StringBuffer dynamize(final String source, final TagDataManager datas) throws Exception + { + StringBuffer result; - Presenter presenter = PresenterFactory.create(source); + Presenter presenter = PresenterFactory.create(source); - result = presenter.dynamize(datas); + result = presenter.dynamize(datas); - // - return (result); - } + // + return (result); + } - /** - * - * @param source - * @return - */ - public static boolean hasHtmlTag(final String source) - { - boolean result; + /** + * + * @param source + * @return + */ + public static boolean hasHtmlTag(final String source) + { + boolean result; - if (source == null) - { - result = false; - } - else - { - if (source.matches("<[hH][tT][mM][lL]>")) - { - result = true; - } - else - { - result = false; - } - } + if (source == null) + { + result = false; + } + else + { + if (source.matches("<[hH][tT][mM][lL]>")) + { + result = true; + } + else + { + result = false; + } + } - // - return result; - } + // + return result; + } } diff --git a/src/fr/devinsy/xidyn/presenters/StringPresenter.java b/src/fr/devinsy/xidyn/presenters/StringPresenter.java index 1da1fe3..f7c435d 100644 --- a/src/fr/devinsy/xidyn/presenters/StringPresenter.java +++ b/src/fr/devinsy/xidyn/presenters/StringPresenter.java @@ -32,204 +32,204 @@ import fr.devinsy.xidyn.utils.XidynUtils; */ public class StringPresenter implements Presenter { - private static Logger logger = LoggerFactory.getLogger(StringPresenter.class); + private static Logger logger = LoggerFactory.getLogger(StringPresenter.class); - private String source; - private String doctype; - private Document dom; + private String source; + private String doctype; + private Document dom; - /** + /** * */ - public StringPresenter() - { - setSource(""); - } + public StringPresenter() + { + setSource(""); + } - /** + /** * */ - public StringPresenter(final String html) - { - setSource(html); - } + public StringPresenter(final String html) + { + setSource(html); + } - /** - * {@inheritDoc} - */ - @Override - public StringBuffer dynamize() throws Exception - { - StringBuffer result; + /** + * {@inheritDoc} + */ + @Override + public StringBuffer dynamize() throws Exception + { + StringBuffer result; - result = new StringBuffer(this.source); + result = new StringBuffer(this.source); - // - return result; - } + // + return result; + } - /** - * {@inheritDoc} - */ - @Override - public StringBuffer dynamize(final TagDataManager data) throws Exception - { - StringBuffer result; + /** + * {@inheritDoc} + */ + @Override + public StringBuffer dynamize(final TagDataManager data) throws Exception + { + StringBuffer result; - // Build the DOM. - if (this.dom == null) - { - // Build the source HTML. - String sourceHtml; - if (this.source == null) - { - String errorMessage = "source not defined"; - logger.error(errorMessage); - result = null; - throw new Exception(errorMessage); - } - else - { - this.doctype = XidynUtils.extractDoctype(this.source); + // Build the DOM. + if (this.dom == null) + { + // Build the source HTML. + String sourceHtml; + if (this.source == null) + { + String errorMessage = "source not defined"; + logger.error(errorMessage); + result = null; + throw new Exception(errorMessage); + } + else + { + this.doctype = XidynUtils.extractDoctype(this.source); - if (this.doctype == null) - { - StringBuffer buffer = new StringBuffer(this.source.length() + 100); - buffer.append("\n"); - buffer.append(this.source); - buffer.append(""); - sourceHtml = buffer.toString(); - } - else - { - sourceHtml = this.source; - } - } + if (this.doctype == null) + { + StringBuffer buffer = new StringBuffer(this.source.length() + 100); + buffer.append("\n"); + buffer.append(this.source); + buffer.append(""); + sourceHtml = buffer.toString(); + } + else + { + sourceHtml = this.source; + } + } - // StringBufferInputStream is deprecated so we use another solution. - // (see - // http://www.developpez.net/forums/archive/index.php/t-14101.html). - this.dom = XidynUtils.buildDom(sourceHtml); - XidynUtils.addMetaTag(this.dom, "generator", "XIDYN"); - } + // StringBufferInputStream is deprecated so we use another solution. + // (see + // http://www.developpez.net/forums/archive/index.php/t-14101.html). + this.dom = XidynUtils.buildDom(sourceHtml); + XidynUtils.addMetaTag(this.dom, "generator", "XIDYN"); + } - // - if (data == null) - { - result = dynamize(); - } - else - { - // - StringWriter htmlCode = new StringWriter(XidynUtils.estimatedTargetLength(this.source.length())); - if ((this.doctype != null)) - { - htmlCode.write(this.doctype); - } + // + if (data == null) + { + result = dynamize(); + } + else + { + // + StringWriter htmlCode = new StringWriter(XidynUtils.estimatedTargetLength(this.source.length())); + if ((this.doctype != null)) + { + htmlCode.write(this.doctype); + } - DomPresenterCore.dynamize(htmlCode, this.dom, data); - StringBuffer htmlTarget = htmlCode.getBuffer(); + DomPresenterCore.dynamize(htmlCode, this.dom, data); + StringBuffer htmlTarget = htmlCode.getBuffer(); - // - if (htmlTarget == null) - { - result = null; - } - else if (this.doctype != null) - { - result = htmlTarget; - } - else - { - String bodyContent = XidynUtils.extractBodyContent(htmlTarget); + // + if (htmlTarget == null) + { + result = null; + } + else if (this.doctype != null) + { + result = htmlTarget; + } + else + { + String bodyContent = XidynUtils.extractBodyContent(htmlTarget); - if (bodyContent == null) - { - result = null; - } - else - { - result = new StringBuffer(bodyContent); - } - } - } + if (bodyContent == null) + { + result = null; + } + else + { + result = new StringBuffer(bodyContent); + } + } + } - // - return (result); - } + // + return (result); + } - /** - * {@inheritDoc} - */ - @Override - public String getSource() - { - String result; + /** + * {@inheritDoc} + */ + @Override + public String getSource() + { + String result; - result = this.source; + result = this.source; - // - return (result); - } + // + return (result); + } - /** - * {@inheritDoc} - */ - @Override - public boolean isAvailable() - { - boolean result; + /** + * {@inheritDoc} + */ + @Override + public boolean isAvailable() + { + boolean result; - if (this.source == null) - { - result = false; - } - else - { - result = true; - } + if (this.source == null) + { + result = false; + } + else + { + result = true; + } - // - return result; - } + // + return result; + } - /** - * {@inheritDoc} - */ - @Override - public boolean isOutdated() throws Exception - { - boolean result; + /** + * {@inheritDoc} + */ + @Override + public boolean isOutdated() throws Exception + { + boolean result; - if (this.dom == null) - { - result = true; - } - else - { - result = false; - } + if (this.dom == null) + { + result = true; + } + else + { + result = false; + } - // - return result; - } + // + return result; + } - /** + /** * */ - public void setSource(final String html) - { - this.source = html; - this.doctype = null; - this.dom = null; - } + public void setSource(final String html) + { + this.source = html; + this.doctype = null; + this.dom = null; + } - /** + /** * */ - @Override - public void update() throws Exception - { - // Nothing to do. - } + @Override + public void update() throws Exception + { + // Nothing to do. + } } diff --git a/src/fr/devinsy/xidyn/presenters/TranslatorPresenter.java b/src/fr/devinsy/xidyn/presenters/TranslatorPresenter.java index e2d891e..9a0fc6f 100644 --- a/src/fr/devinsy/xidyn/presenters/TranslatorPresenter.java +++ b/src/fr/devinsy/xidyn/presenters/TranslatorPresenter.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2006-2014 Christian Pierre MOMON + * Copyright (C) 2006-2016 Christian Pierre MOMON * * This file is part of Xidyn. * @@ -29,323 +29,323 @@ import fr.devinsy.xidyn.data.TagDataManager; */ public class TranslatorPresenter implements Presenter { - private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TranslatorPresenter.class); - private String defaultSource; - private HashMap presenters; + private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TranslatorPresenter.class); + private String defaultSource; + private HashMap presenters; - /** + /** * */ - public TranslatorPresenter(final String defaultSource) - { + public TranslatorPresenter(final String defaultSource) + { - if (defaultSource == null) - { - throw new NullPointerException("defaultSource is null"); - } - else - { - this.defaultSource = defaultSource; - this.presenters = new HashMap(); - } - } + if (defaultSource == null) + { + throw new NullPointerException("defaultSource is null"); + } + else + { + this.defaultSource = defaultSource; + this.presenters = new HashMap(); + } + } - /** + /** * */ - @Override - public StringBuffer dynamize() throws Exception - { - StringBuffer result; + @Override + public StringBuffer dynamize() throws Exception + { + StringBuffer result; - Presenter presenter = getPresenter((String) null); - if (presenter == null) - { - result = null; - } - else - { - result = presenter.dynamize(); - } + Presenter presenter = getPresenter((String) null); + if (presenter == null) + { + result = null; + } + else + { + result = presenter.dynamize(); + } - // - return result; - } + // + return result; + } - /** + /** * */ - public StringBuffer dynamize(final Locale locale) throws Exception - { - StringBuffer result; + public StringBuffer dynamize(final Locale locale) throws Exception + { + StringBuffer result; - // - String language; - if (locale == null) - { - language = null; - } - else - { - language = locale.getLanguage(); - } + // + String language; + if (locale == null) + { + language = null; + } + else + { + language = locale.getLanguage(); + } - // - result = getPresenter(language).dynamize(); + // + result = getPresenter(language).dynamize(); - // - return result; - } + // + return result; + } - /** + /** * */ - public StringBuffer dynamize(final String language) throws Exception - { - StringBuffer result; + public StringBuffer dynamize(final String language) throws Exception + { + StringBuffer result; - result = getPresenter(language).dynamize(); + result = getPresenter(language).dynamize(); - // - return result; - } + // + return result; + } - /** + /** * */ - @Override - public StringBuffer dynamize(final TagDataManager datas) throws Exception - { - StringBuffer result; + @Override + public StringBuffer dynamize(final TagDataManager datas) throws Exception + { + StringBuffer result; - Presenter presenter = getPresenter((String) null); - if (presenter == null) - { - result = null; - } - else - { - result = presenter.dynamize(datas); - } + Presenter presenter = getPresenter((String) null); + if (presenter == null) + { + result = null; + } + else + { + result = presenter.dynamize(datas); + } - // - return result; - } + // + return result; + } - /** + /** * */ - public StringBuffer dynamize(final TagDataManager datas, final Locale locale) throws Exception - { - StringBuffer result; + public StringBuffer dynamize(final TagDataManager datas, final Locale locale) throws Exception + { + StringBuffer result; - // - String language; - if (locale == null) - { - language = null; - } - else - { - language = locale.getLanguage(); - } + // + String language; + if (locale == null) + { + language = null; + } + else + { + language = locale.getLanguage(); + } - // - result = getPresenter(language).dynamize(datas); + // + result = getPresenter(language).dynamize(datas); - // - return result; - } + // + return result; + } - /** + /** * */ - public StringBuffer dynamize(final TagDataManager datas, final String language) throws Exception - { - StringBuffer result; + public StringBuffer dynamize(final TagDataManager datas, final String language) throws Exception + { + StringBuffer result; - result = getPresenter(language).dynamize(datas); + result = getPresenter(language).dynamize(datas); - // - return result; - } + // + return result; + } - /** + /** * */ - public Presenter getPresenter(final Locale locale) throws Exception - { - Presenter result; + public Presenter getPresenter(final Locale locale) throws Exception + { + Presenter result; - // - String language; - if ((locale == null) || (locale.getLanguage().length() == 0)) - { - language = null; - } - else - { - language = locale.getLanguage(); - } + // + String language; + if ((locale == null) || (locale.getLanguage().length() == 0)) + { + language = null; + } + else + { + language = locale.getLanguage(); + } - // - result = getPresenter(language); + // + result = getPresenter(language); - // - return result; - } + // + return result; + } - /** + /** * */ - public Presenter getPresenter(final String language) throws Exception - { - Presenter result; + public Presenter getPresenter(final String language) throws Exception + { + Presenter result; - // - result = this.presenters.get(language); + // + result = this.presenters.get(language); - // - if (result == null) - { - // - if (language == null) - { - // - result = PresenterFactory.create(this.defaultSource); + // + if (result == null) + { + // + if (language == null) + { + // + result = PresenterFactory.create(this.defaultSource); - if (result.isAvailable()) - { - this.presenters.put(language, result); - } - else - { - throw new Exception("Undefined default language file."); - } - } - else - { - String adaptedSource = FileTools.addBeforeExtension(this.defaultSource, "-" + language); - result = PresenterFactory.create(adaptedSource); + if (result.isAvailable()) + { + this.presenters.put(language, result); + } + else + { + throw new Exception("Undefined default language file."); + } + } + else + { + String adaptedSource = FileTools.addBeforeExtension(this.defaultSource, "-" + language); + result = PresenterFactory.create(adaptedSource); - if (result.isAvailable()) - { - this.presenters.put(language, result); - } - else - { - adaptedSource = FileTools.addBeforeExtension(this.defaultSource, "_" + language); + if (result.isAvailable()) + { + this.presenters.put(language, result); + } + else + { + adaptedSource = FileTools.addBeforeExtension(this.defaultSource, "_" + language); - if (result.isAvailable()) - { - this.presenters.put(language, result); - } - else - { - result = getPresenter((String) null); - } - } - } - } + if (result.isAvailable()) + { + this.presenters.put(language, result); + } + else + { + result = getPresenter((String) null); + } + } + } + } - // - return result; - } + // + return result; + } - /** + /** * */ - @Override - public Object getSource() - { - String result; + @Override + public Object getSource() + { + String result; - result = this.defaultSource; + result = this.defaultSource; - // - return result; - } + // + return result; + } - /** + /** * */ - @Override - public boolean isAvailable() - { - boolean result; + @Override + public boolean isAvailable() + { + boolean result; - try - { - result = getPresenter((String) null).isAvailable(); - } - catch (Exception exception) - { - result = false; - } + try + { + result = getPresenter((String) null).isAvailable(); + } + catch (Exception exception) + { + result = false; + } - // - return result; - } + // + return result; + } - /** + /** * */ - @Override - public boolean isOutdated() throws Exception - { - return false; - } + @Override + public boolean isOutdated() throws Exception + { + return false; + } - /** + /** * */ - public String toString(final Locale locale) throws Exception - { - String result; + public String toString(final Locale locale) throws Exception + { + String result; - // - String language; - if (locale == null) - { - language = null; - } - else - { - language = locale.getLanguage(); - } + // + String language; + if (locale == null) + { + language = null; + } + else + { + language = locale.getLanguage(); + } - // - result = toString(language); + // + result = toString(language); - // - return result; - } + // + return result; + } - /** + /** * */ - public String toString(final String language) throws Exception - { - String result; + public String toString(final String language) throws Exception + { + String result; - Presenter presenter = getPresenter(language); - if (presenter == null) - { - result = null; - } - else - { - result = presenter.toString(); - } + Presenter presenter = getPresenter(language); + if (presenter == null) + { + result = null; + } + else + { + result = presenter.toString(); + } - // - return result; - } + // + return result; + } - @Override - public void update() throws Exception - { - } + @Override + public void update() throws Exception + { + } } // //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/fr/devinsy/xidyn/presenters/URLPresenter.java b/src/fr/devinsy/xidyn/presenters/URLPresenter.java index 091379f..b9f2405 100644 --- a/src/fr/devinsy/xidyn/presenters/URLPresenter.java +++ b/src/fr/devinsy/xidyn/presenters/URLPresenter.java @@ -33,321 +33,321 @@ import fr.devinsy.xidyn.utils.XidynUtils; */ public class URLPresenter extends StringPresenter { - private static Logger logger = LoggerFactory.getLogger(URLPresenter.class); + private static Logger logger = LoggerFactory.getLogger(URLPresenter.class); - private String sourcePathname; - private URL source; - private long sourceTime; + private String sourcePathname; + private URL source; + private long sourceTime; - /** + /** * */ - public URLPresenter() - { - super(); - setSource((URL) null); - } + public URLPresenter() + { + super(); + setSource((URL) null); + } - /** + /** * */ - public URLPresenter(final String source) - { - super(); - setSource(source); - } + public URLPresenter(final String source) + { + super(); + setSource(source); + } - /** + /** * */ - public URLPresenter(final URL source) - { - super(); - setSource(source); - } + public URLPresenter(final URL source) + { + super(); + setSource(source); + } - /** - * No need to be synchronized. - */ - @Override - public StringBuffer dynamize() throws Exception - { - StringBuffer result; + /** + * No need to be synchronized. + */ + @Override + public StringBuffer dynamize() throws Exception + { + StringBuffer result; - // - update(); + // + update(); - // - result = super.dynamize(); + // + result = super.dynamize(); - // - return result; - } + // + return result; + } - /** - * No need to be synchronized. - */ - @Override - public StringBuffer dynamize(final TagDataManager data) throws Exception - { - StringBuffer result; + /** + * No need to be synchronized. + */ + @Override + public StringBuffer dynamize(final TagDataManager data) throws Exception + { + StringBuffer result; - logger.info("dynamize URL [" + this.sourcePathname + "]"); + logger.info("dynamize URL [" + this.sourcePathname + "]"); - // - update(); + // + update(); - // Build the web page. - result = super.dynamize(data); + // Build the web page. + result = super.dynamize(data); - // - return (result); - } + // + return (result); + } - /** - * {@inheritDoc} - */ - @Override - public String getSource() - { - String result; + /** + * {@inheritDoc} + */ + @Override + public String getSource() + { + String result; - result = this.sourcePathname; + result = this.sourcePathname; - // - return (result); - } + // + return (result); + } - /** + /** * */ - public URL getURL() - { - URL result; + public URL getURL() + { + URL result; - result = this.source; + result = this.source; - // - return (result); - } + // + return (result); + } - /** - * {@inheritDoc} - */ - @Override - public boolean isAvailable() - { - boolean result; + /** + * {@inheritDoc} + */ + @Override + public boolean isAvailable() + { + boolean result; - if (this.source == null) - { - result = false; - } - else if (this.sourcePathname.startsWith("/")) - { - /* - * In case of Jar resources, if resource does not exist then - * this.source is null. So, if we are here in the code then - * this.source is not null and so resource is available. - */ - result = true; - } - else - { - /* - * The source is an URL with protocol. Open a stream is the only way to test if the resource is available. - */ - try - { - this.source.openStream(); - result = true; - } - catch (final IOException exception) - { - /* - * On URL.openStream: - *
    - *
  • If host does not exist then a java.net.UnknownHostException is throwed.
  • - *
  • If host exists but not the file does not exist then a java.io.FileNotFoundException is throwed.
  • - *
- * These exceptions are IOException. - */ - result = false; - } - } + if (this.source == null) + { + result = false; + } + else if (this.sourcePathname.startsWith("/")) + { + /* + * In case of Jar resources, if resource does not exist then + * this.source is null. So, if we are here in the code then + * this.source is not null and so resource is available. + */ + result = true; + } + else + { + /* + * The source is an URL with protocol. Open a stream is the only way to test if the resource is available. + */ + try + { + this.source.openStream(); + result = true; + } + catch (final IOException exception) + { + /* + * On URL.openStream: + *
    + *
  • If host does not exist then a java.net.UnknownHostException is throwed.
  • + *
  • If host exists but not the file does not exist then a java.io.FileNotFoundException is throwed.
  • + *
+ * These exceptions are IOException. + */ + result = false; + } + } - // - return result; - } + // + return result; + } - /** - * {@inheritDoc} - * - * @throws IOException - */ - @Override - public boolean isOutdated() throws Exception - { - boolean result; + /** + * {@inheritDoc} + * + * @throws IOException + */ + @Override + public boolean isOutdated() throws Exception + { + boolean result; - // - if (super.isOutdated()) - { - result = true; - } - else if (this.sourceTime == this.source.openConnection().getLastModified()) - { - result = true; - } - else - { - result = false; - } + // + if (super.isOutdated()) + { + result = true; + } + else if (this.sourceTime == this.source.openConnection().getLastModified()) + { + result = true; + } + else + { + result = false; + } - // - return result; - } + // + return result; + } - /** + /** * */ - @Override - public void setSource(final String source) - { - // - if (source == null) - { - this.source = null; - this.sourcePathname = null; - this.sourceTime = 0; - super.setSource(null); - } - else - { - // - URL url; - if (source.matches(".+://.+")) - { - try - { - url = new URL(source); - } - catch (final MalformedURLException exception) - { - // TODO - logger.warn("UNKNOWN PROTOCOL [" + source + "]"); - url = null; - } - } - else - { - url = URLPresenter.class.getResource(source); - } + @Override + public void setSource(final String source) + { + // + if (source == null) + { + this.source = null; + this.sourcePathname = null; + this.sourceTime = 0; + super.setSource(null); + } + else + { + // + URL url; + if (source.matches(".+://.+")) + { + try + { + url = new URL(source); + } + catch (final MalformedURLException exception) + { + // TODO + logger.warn("UNKNOWN PROTOCOL [" + source + "]"); + url = null; + } + } + else + { + url = URLPresenter.class.getResource(source); + } - // - if (url == null) - { - this.source = null; - this.sourcePathname = source; - this.sourceTime = 0; - super.setSource(null); - } - else - { - this.source = url; - this.sourcePathname = source; - this.sourceTime = 0; - super.setSource(null); - } - } - } + // + if (url == null) + { + this.source = null; + this.sourcePathname = source; + this.sourceTime = 0; + super.setSource(null); + } + else + { + this.source = url; + this.sourcePathname = source; + this.sourceTime = 0; + super.setSource(null); + } + } + } - /** - * - * @param source - */ - public void setSource(final URL source) - { - if (source == null) - { - this.source = null; - this.sourcePathname = null; - this.sourceTime = 0; - super.setSource(null); - } - else - { - this.source = source; - this.sourcePathname = source.toString(); - this.sourceTime = 0; - super.setSource(null); - } - } + /** + * + * @param source + */ + public void setSource(final URL source) + { + if (source == null) + { + this.source = null; + this.sourcePathname = null; + this.sourceTime = 0; + super.setSource(null); + } + else + { + this.source = source; + this.sourcePathname = source.toString(); + this.sourceTime = 0; + super.setSource(null); + } + } - /** + /** * */ - @Override - public String toString() - { - String result; + @Override + public String toString() + { + String result; - try - { - // - update(); + try + { + // + update(); - // - result = super.getSource(); - } - catch (final Exception exception) - { - result = null; - } + // + result = super.getSource(); + } + catch (final Exception exception) + { + result = null; + } - // - return result; - } + // + return result; + } - /** - * No need to be synchronized. - * - * @throws Exception - */ - @Override - public void update() throws Exception - { - // - if (this.source == null) - { - String errorMessage = "source not defined (" + this.sourcePathname + ")"; - logger.error(errorMessage); - throw new NullPointerException(errorMessage); - } - else - { - try - { - long currentSourceTime = this.source.openConnection().getLastModified(); - if ((super.getSource() == null) || (this.sourceTime != currentSourceTime)) - { - super.setSource(XidynUtils.load(this.source)); - this.sourceTime = currentSourceTime; - } - } - catch (final IOException exception) - { - /* On URL.openStream: - *
    - *
  • If host does not exist then a java.net.UnknownHostException is throwed.
  • - *
  • If host exists but not the file does not exist then a java.io.FileNotFoundException is throwed.
  • - *
- * These exceptions are IOException. - */ - String errorMessage = "source file defined but not readable (" + this.source.toString() + ")"; - logger.error(errorMessage); - throw new Exception(errorMessage); - } - } - } + /** + * No need to be synchronized. + * + * @throws Exception + */ + @Override + public void update() throws Exception + { + // + if (this.source == null) + { + String errorMessage = "source not defined (" + this.sourcePathname + ")"; + logger.error(errorMessage); + throw new NullPointerException(errorMessage); + } + else + { + try + { + long currentSourceTime = this.source.openConnection().getLastModified(); + if ((super.getSource() == null) || (this.sourceTime != currentSourceTime)) + { + super.setSource(XidynUtils.load(this.source)); + this.sourceTime = currentSourceTime; + } + } + catch (final IOException exception) + { + /* On URL.openStream: + *
    + *
  • If host does not exist then a java.net.UnknownHostException is throwed.
  • + *
  • If host exists but not the file does not exist then a java.io.FileNotFoundException is throwed.
  • + *
+ * These exceptions are IOException. + */ + String errorMessage = "source file defined but not readable (" + this.source.toString() + ")"; + logger.error(errorMessage); + throw new Exception(errorMessage); + } + } + } } diff --git a/src/fr/devinsy/xidyn/utils/ParserErrorHandler.java b/src/fr/devinsy/xidyn/utils/ParserErrorHandler.java index a6c45dc..45ea7d5 100644 --- a/src/fr/devinsy/xidyn/utils/ParserErrorHandler.java +++ b/src/fr/devinsy/xidyn/utils/ParserErrorHandler.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2006-2014 Christian Pierre MOMON + * Copyright (C) 2006-2016 Christian Pierre MOMON * * This file is part of Xidyn. * @@ -33,157 +33,157 @@ import org.xml.sax.SAXParseException; */ public class ParserErrorHandler implements ErrorHandler { - private Vector messages; - private int fatalErrorsCount; - private int errorsCount; - private int warningCount; + private Vector messages; + private int fatalErrorsCount; + private int errorsCount; + private int warningCount; - public ParserErrorHandler() - { - this.fatalErrorsCount = 0; - this.errorsCount = 0; - this.warningCount = 0; - this.messages = new Vector(); - } + public ParserErrorHandler() + { + this.fatalErrorsCount = 0; + this.errorsCount = 0; + this.warningCount = 0; + this.messages = new Vector(); + } - /** + /** * */ - public int allErrorsCount() - { - int result; + public int allErrorsCount() + { + int result; - result = fatalErrorsCount() + errorsCount() + warningCount(); + result = fatalErrorsCount() + errorsCount() + warningCount(); - // - return (result); - } + // + 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(); + /** + * 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); - } + this.errorsCount += 1; + this.messages.add(message); + } - /** + /** * */ - public int errorsCount() - { - int result; + public int errorsCount() + { + int result; - result = this.errorsCount; + result = this.errorsCount; - // - return (result); - } + // + 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(); + /** + * 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); - } + this.fatalErrorsCount += 1; + this.messages.add(message); + } - /** + /** * */ - public int fatalErrorsCount() - { - int result; + public int fatalErrorsCount() + { + int result; - result = this.fatalErrorsCount; + result = this.fatalErrorsCount; - // - return (result); - } + // + return (result); + } - /** + /** * */ - public boolean hasError() - { - boolean result; + public boolean hasError() + { + boolean result; - if (allErrorsCount() == 0) - { - result = false; - } - else - { - result = true; - } + if (allErrorsCount() == 0) + { + result = false; + } + else + { + result = true; + } - // - return (result); - } + // + return (result); + } - /** + /** * */ - @Override - public String toString() - { - StringBuffer result; + @Override + public String toString() + { + StringBuffer result; - result = new StringBuffer(); + result = new StringBuffer(); - for (String message : this.messages) - { - result.append(message); - result.append('\n'); - } + for (String message : this.messages) + { + result.append(message); + result.append('\n'); + } - // - return (result.toString()); - } + // + return (result.toString()); + } - /** - * Called by the XML parser to handle warnings. - * - * @param ex - * Parse Excpetion. Contains the warning text and the line - * number. - */ - @Override - public void warning(final SAXParseException exception) - { - String message = "Warning at line " + exception.getLineNumber() + " : " + exception.getMessage(); + /** + * Called by the XML parser to handle warnings. + * + * @param ex + * Parse Excpetion. Contains the warning text and the line + * number. + */ + @Override + public void warning(final SAXParseException exception) + { + String message = "Warning at line " + exception.getLineNumber() + " : " + exception.getMessage(); - this.warningCount += 1; - this.messages.add(message); - } + this.warningCount += 1; + this.messages.add(message); + } - /** + /** * */ - public int warningCount() - { - int result; + public int warningCount() + { + int result; - result = this.warningCount; + result = this.warningCount; - // - return (result); - } + // + return (result); + } } diff --git a/src/fr/devinsy/xidyn/utils/XidynUtils.java b/src/fr/devinsy/xidyn/utils/XidynUtils.java index 441a5df..355aa7a 100644 --- a/src/fr/devinsy/xidyn/utils/XidynUtils.java +++ b/src/fr/devinsy/xidyn/utils/XidynUtils.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2006-2014 Christian Pierre MOMON + * Copyright (C) 2006-2016 Christian Pierre MOMON * * This file is part of Xidyn. * @@ -48,678 +48,678 @@ import org.xml.sax.SAXException; */ public class XidynUtils { - private static final Logger logger = LoggerFactory.getLogger(XidynUtils.class); - private static final Pattern BODY_PATTERN = Pattern.compile("(?s)^.*<[bB][oO][dD][yY]>\\s*(\\S.*\\S)\\s*.*$"); + private static final Logger logger = LoggerFactory.getLogger(XidynUtils.class); + private static final Pattern BODY_PATTERN = Pattern.compile("(?s)^.*<[bB][oO][dD][yY]>\\s*(\\S.*\\S)\\s*.*$"); - /** - * This method adds a tag to a DOM object. - */ - public static void addMetaTag(final Document doc, final String name, final String content) - { - // Find head tag. - Node headNode = findHeadNode(doc); - logger.debug("headNode = [" + headNode + "]"); + /** + * This method adds a tag to a DOM object. + */ + public static void addMetaTag(final Document doc, final String name, final String content) + { + // Find head tag. + Node headNode = findHeadNode(doc); + logger.debug("headNode = [" + headNode + "]"); - if (headNode != null) - { - Node metaNode = doc.createElement("meta"); + if (headNode != null) + { + Node metaNode = doc.createElement("meta"); - NamedNodeMap attrMap = metaNode.getAttributes(); - Node attrNode = doc.createAttribute("name"); - attrMap.setNamedItem(attrNode); - attrNode.setNodeValue(name); + NamedNodeMap attrMap = metaNode.getAttributes(); + Node attrNode = doc.createAttribute("name"); + attrMap.setNamedItem(attrNode); + attrNode.setNodeValue(name); - attrNode = doc.createAttribute("content"); - attrMap.setNamedItem(attrNode); - attrNode.setNodeValue(content); - headNode.insertBefore(metaNode, headNode.getFirstChild()); - } - } + attrNode = doc.createAttribute("content"); + attrMap.setNamedItem(attrNode); + attrNode.setNodeValue(content); + headNode.insertBefore(metaNode, headNode.getFirstChild()); + } + } - /** - * This method builds a DOM object from a source. - */ - public static Document buildDom(final InputStream source) throws Exception - { - Document result; + /** + * This method builds a DOM object from a source. + */ + public static Document buildDom(final InputStream source) throws Exception + { + Document result; - try - { - // Create a DocumentBuilderFactory and configure it. - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + try + { + // Create a DocumentBuilderFactory and configure it. + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - // Set various configuration options. - dbf.setValidating(false); - dbf.setIgnoringComments(true); - dbf.setIgnoringElementContentWhitespace(false); - dbf.setCoalescing(false); + // Set various configuration options. + dbf.setValidating(false); + dbf.setIgnoringComments(true); + dbf.setIgnoringElementContentWhitespace(false); + dbf.setCoalescing(false); - // Keep entity references as they are. - dbf.setExpandEntityReferences(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(); + // Create a DocumentBuilder that satisfies the constraints + // specified by the DocumentBuilderFactory. + DocumentBuilder db = dbf.newDocumentBuilder(); - ParserErrorHandler errorHandler; - errorHandler = new ParserErrorHandler(); + ParserErrorHandler errorHandler; + errorHandler = new ParserErrorHandler(); - // Set the error handler. - db.setErrorHandler(errorHandler); + // Set the error handler. + db.setErrorHandler(errorHandler); - Schema schema = db.getSchema(); - logger.debug("schema=" + schema); + Schema schema = db.getSchema(); + logger.debug("schema=" + schema); - // Parse the input file. - result = db.parse(source); + // 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()); - } - } - 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); - } + 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()); + } + } + 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); - } + // + return (result); + } - /** - * This method builds a DOM object from a source. - */ - public static Document buildDom(final String source) throws Exception - { - Document result; + /** + * This method builds a DOM object from a source. + */ + public static Document buildDom(final String source) throws Exception + { + Document result; - try - { - // Create a DocumentBuilderFactory and configure it. - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + try + { + // Create a DocumentBuilderFactory and configure it. + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - // Set various configuration options. - dbf.setValidating(false); - dbf.setIgnoringComments(true); - dbf.setIgnoringElementContentWhitespace(false); - dbf.setCoalescing(false); + // Set various configuration options. + dbf.setValidating(false); + dbf.setIgnoringComments(true); + dbf.setIgnoringElementContentWhitespace(false); + dbf.setCoalescing(false); - // Keep entity references as they are. - dbf.setExpandEntityReferences(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(); + // Create a DocumentBuilder that satisfies the constraints + // specified by the DocumentBuilderFactory. + DocumentBuilder db = dbf.newDocumentBuilder(); - ParserErrorHandler errorHandler; - errorHandler = new ParserErrorHandler(); + ParserErrorHandler errorHandler; + errorHandler = new ParserErrorHandler(); - // Set the error handler. - db.setErrorHandler(errorHandler); + // Set the error handler. + db.setErrorHandler(errorHandler); - Schema schema = db.getSchema(); - logger.debug("schema=" + schema); + Schema schema = db.getSchema(); + logger.debug("schema=" + schema); - // Parse the input file. - result = db.parse(new InputSource(new StringReader(source))); + // Parse the input file. + result = db.parse(new InputSource(new StringReader(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()); - } - } - 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); - } + 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()); + } + } + 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); - } + // + return (result); + } - /** - * Good estimation of the target length able to optimize performance. - */ - public static int estimatedTargetLength(final long sourceLength) - { - int result; + /** + * Good estimation of the target length able to optimize performance. + */ + public 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 = (1000000); - } - else - { - result = (int) (sourceLength + 30000); - } + if (sourceLength < 1000) + { + result = (int) (sourceLength * 5); + } + else if (sourceLength < 50000) + { + result = (int) (sourceLength * 2); + } + else if (sourceLength < 800000) + { + result = (1000000); + } + else + { + result = (int) (sourceLength + 30000); + } - // - return (result); - } + // + return (result); + } - /** + /** * */ - public static String extractBodyContent(final CharSequence source) - { - String result; + public static String extractBodyContent(final CharSequence source) + { + String result; - if (source == null) - { - result = ""; - } - else - { - Matcher matcher = BODY_PATTERN.matcher(source); - if ((matcher.find()) && (matcher.groupCount() == 1)) - { - // for (int i = 0; i <= matcher.groupCount(); i++) - // { - // System.out.println(i + " " + matcher.group(i)); - // } + if (source == null) + { + result = ""; + } + else + { + Matcher matcher = BODY_PATTERN.matcher(source); + if ((matcher.find()) && (matcher.groupCount() == 1)) + { + // for (int i = 0; i <= matcher.groupCount(); i++) + // { + // System.out.println(i + " " + matcher.group(i)); + // } - result = matcher.group(1); - } - else - { - result = ""; - } - } + result = matcher.group(1); + } + else + { + result = ""; + } + } - // - return (result); - } + // + return (result); + } - /** - * This method extracts the string before the html tag. - * - * A possible way is to use pattern searching for - * $(.*)<html>.*^. But if there is no html tag, all the - * source is read for nothing. - * - * A best way is to analyze each < while it is a XML tag or a DOCTYPE tag - * or the <HTML> tag. - * - * Uses cases: - * - * - * ... - * - * - * @param source - * @return the string before the html tag or null if no html - * tag found. So, "" if there is a html tag without doctype. - */ - public static String extractDoctype(final String source) - { - String result; + /** + * This method extracts the string before the html tag. + * + * A possible way is to use pattern searching for + * $(.*)<html>.*^. But if there is no html tag, all the + * source is read for nothing. + * + * A best way is to analyze each < while it is a XML tag or a DOCTYPE tag + * or the <HTML> tag. + * + * Uses cases: + * + * + * ... + * + * + * @param source + * @return the string before the html tag or null if no html + * tag found. So, "" if there is a html tag without doctype. + */ + public static String extractDoctype(final String source) + { + String result; - if (source == null) - { - result = null; - } - else - { - boolean ended = false; - result = null; - int currentPosition = 0; - while (!ended) - { - currentPosition = source.indexOf('<', currentPosition); + if (source == null) + { + result = null; + } + else + { + boolean ended = false; + result = null; + int currentPosition = 0; + while (!ended) + { + currentPosition = source.indexOf('<', currentPosition); - if (currentPosition == -1) - { - ended = true; - result = null; - } - else - { - if (currentPosition + 1 < source.length()) - { - if (Character.toLowerCase(source.charAt(currentPosition + 1)) == 'h') - { - if (source.substring(currentPosition + 1, currentPosition + 5).matches("^[hH][tT][mM][lL]$")) - { - ended = true; - result = source.substring(0, currentPosition); - } - } - else - { - char letter = source.charAt(currentPosition + 1); - if ((letter != '?') && (letter != '!')) - { - ended = true; - result = null; - } - else - { - currentPosition += 1; - } - } - } - else - { - ended = true; - result = null; - } - } - } - } + if (currentPosition == -1) + { + ended = true; + result = null; + } + else + { + if (currentPosition + 1 < source.length()) + { + if (Character.toLowerCase(source.charAt(currentPosition + 1)) == 'h') + { + if (source.substring(currentPosition + 1, currentPosition + 5).matches("^[hH][tT][mM][lL]$")) + { + ended = true; + result = source.substring(0, currentPosition); + } + } + else + { + char letter = source.charAt(currentPosition + 1); + if ((letter != '?') && (letter != '!')) + { + ended = true; + result = null; + } + else + { + currentPosition += 1; + } + } + } + else + { + ended = true; + result = null; + } + } + } + } - // - return result; - } + // + return result; + } - /** + /** * */ - public static Document fileToDom(final File source) throws Exception - { - Document result; + public static Document fileToDom(final File source) throws Exception + { + Document result; - try - { - result = buildDom(new FileInputStream(source)); - } - catch (IOException exception) - { - String errorMessage = "IOError during parsing." + exception.getMessage(); - logger.error(errorMessage); - result = null; - throw new Exception(errorMessage, exception); - } + try + { + result = buildDom(new FileInputStream(source)); + } + catch (IOException exception) + { + String errorMessage = "IOError during parsing." + exception.getMessage(); + logger.error(errorMessage); + result = null; + throw new Exception(errorMessage, exception); + } - // - return (result); - } + // + return (result); + } - /** - * Finds the node containing the <head> tag. - * - * @param node - * Document node. - * @return The head tag node - */ - public static Node findHeadNode(final Node node) - { - Node result; + /** + * Finds the node containing the <head> tag. + * + * @param node + * Document node. + * @return The head tag node + */ + public static Node findHeadNode(final Node node) + { + Node result; - result = findNodeByName(node, "head"); + result = findNodeByName(node, "head"); - // - return result; - } + // + return result; + } - /** - * Finds the node containing the <head> tag. - * - * @param node - * Document node. - * @return The head tag node - */ - public static Node findNodeByName(final Node node, final String name) - { - Node result; + /** + * Finds the node containing the <head> tag. + * + * @param node + * Document node. + * @return The head tag node + */ + public static Node findNodeByName(final Node node, final String name) + { + Node result; - switch (node.getNodeType()) - { - case Node.DOCUMENT_NODE: - { - result = findNodeByName(((Document) node).getDocumentElement(), name); - } - break; + switch (node.getNodeType()) + { + case Node.DOCUMENT_NODE: + { + result = findNodeByName(((Document) node).getDocumentElement(), name); + } + break; - case Node.ELEMENT_NODE: - { - String tag = node.getNodeName(); + case Node.ELEMENT_NODE: + { + String tag = node.getNodeName(); - if ((tag != null) && tag.equals(name)) - { - result = node; - } - else - { - NodeList children = node.getChildNodes(); - int childrenCount; - if (children == null) - { - childrenCount = 0; - } - else - { - childrenCount = children.getLength(); - } + if ((tag != null) && tag.equals(name)) + { + result = node; + } + else + { + NodeList children = node.getChildNodes(); + int childrenCount; + if (children == null) + { + childrenCount = 0; + } + else + { + childrenCount = children.getLength(); + } - boolean ended = false; - int childrenIndex = 0; - result = null; - while (!ended) - { - if (childrenIndex < childrenCount) - { - Node subResult = findNodeByName(children.item(childrenIndex), name); - if (subResult == null) - { - childrenIndex += 1; - } - else - { - ended = true; - result = subResult; - } - } - else - { - ended = true; - result = null; - } - } - } - } - break; + boolean ended = false; + int childrenIndex = 0; + result = null; + while (!ended) + { + if (childrenIndex < childrenCount) + { + Node subResult = findNodeByName(children.item(childrenIndex), name); + if (subResult == null) + { + childrenIndex += 1; + } + else + { + ended = true; + result = subResult; + } + } + else + { + ended = true; + result = null; + } + } + } + } + break; - default: - result = null; - } + default: + result = null; + } - // - return result; - } + // + return result; + } - /** - * - * @param file - * @return - * @throws IOException - */ - public static String load(final File source) throws IOException - { - String result; + /** + * + * @param file + * @return + * @throws IOException + */ + public static String load(final File source) throws IOException + { + String result; - final String DEFAULT_CHARSET_NAME = "UTF-8"; - result = load(source, DEFAULT_CHARSET_NAME); + final String DEFAULT_CHARSET_NAME = "UTF-8"; + result = load(source, DEFAULT_CHARSET_NAME); - // - return result; - } + // + return result; + } - /** - * - * @param file - * @throws IOException - */ - public static String load(final File source, final String charsetName) throws IOException - { - String result; + /** + * + * @param file + * @throws IOException + */ + public static String load(final File source, final String charsetName) throws IOException + { + String result; - result = loadToStringBuffer(source, charsetName).toString(); + result = loadToStringBuffer(source, charsetName).toString(); - // - return result; - } + // + return result; + } - /** - * - * @param file - * @return - * @throws IOException - */ - public static String load(final URL source) throws IOException - { - String result; + /** + * + * @param file + * @return + * @throws IOException + */ + public static String load(final URL source) throws IOException + { + String result; - final String DEFAULT_CHARSET_NAME = "UTF-8"; - result = load(source, DEFAULT_CHARSET_NAME); + final String DEFAULT_CHARSET_NAME = "UTF-8"; + result = load(source, DEFAULT_CHARSET_NAME); - // - return result; - } + // + return result; + } - /** - * - * @param file - * @throws IOException - */ - public static String load(final URL source, final String charsetName) throws IOException - { - String result; + /** + * + * @param file + * @throws IOException + */ + public static String load(final URL source, final String charsetName) throws IOException + { + String result; - // - StringBuffer buffer = new StringBuffer(source.openConnection().getContentLength() + 1); - read(buffer, source.openStream(), charsetName); + // + StringBuffer buffer = new StringBuffer(source.openConnection().getContentLength() + 1); + read(buffer, source.openStream(), charsetName); - // - result = buffer.toString(); + // + result = buffer.toString(); - // - return result; - } + // + return result; + } - /** - * - * @param file - * @throws IOException - */ - public static StringBuffer loadToStringBuffer(final File file, final String charsetName) throws IOException - { - StringBuffer result; + /** + * + * @param file + * @throws IOException + */ + public static StringBuffer loadToStringBuffer(final File file, final String charsetName) throws IOException + { + StringBuffer result; - BufferedReader in = null; - try - { - in = new BufferedReader(new InputStreamReader(new FileInputStream(file), charsetName)); + BufferedReader in = null; + try + { + in = new BufferedReader(new InputStreamReader(new FileInputStream(file), charsetName)); - boolean ended = false; - final String LINE_SEPARATOR = System.getProperty("line.separator"); - result = new StringBuffer((int) file.length() + 1); - while (!ended) - { - String line = in.readLine(); + boolean ended = false; + final String LINE_SEPARATOR = System.getProperty("line.separator"); + result = new StringBuffer((int) file.length() + 1); + while (!ended) + { + String line = in.readLine(); - if (line == null) - { - ended = true; - } - else - { - result.append(line).append(LINE_SEPARATOR); - } - } - } - finally - { - try - { - if (in != null) - { - in.close(); - } - } - catch (IOException exception) - { - exception.printStackTrace(); - } - } + if (line == null) + { + ended = true; + } + else + { + result.append(line).append(LINE_SEPARATOR); + } + } + } + finally + { + try + { + if (in != null) + { + in.close(); + } + } + catch (IOException exception) + { + exception.printStackTrace(); + } + } - // - return result; - } + // + return result; + } - /** - * - * @param file - * @throws IOException - */ - public static void read(final StringBuffer out, final InputStream is, final String charsetName) throws IOException - { - BufferedReader in = null; - try - { - in = new BufferedReader(new InputStreamReader(is, charsetName)); + /** + * + * @param file + * @throws IOException + */ + public static void read(final StringBuffer out, final InputStream is, final String charsetName) throws IOException + { + BufferedReader in = null; + try + { + in = new BufferedReader(new InputStreamReader(is, charsetName)); - boolean ended = false; - final String LINE_SEPARATOR = System.getProperty("line.separator"); + boolean ended = false; + final String LINE_SEPARATOR = System.getProperty("line.separator"); - while (!ended) - { - String line = in.readLine(); + while (!ended) + { + String line = in.readLine(); - if (line == null) - { - ended = true; - } - else - { - out.append(line).append(LINE_SEPARATOR); - } - } - } - finally - { - try - { - if (in != null) - { - in.close(); - } - } - catch (IOException exception) - { - exception.printStackTrace(); - } - } - } + if (line == null) + { + ended = true; + } + else + { + out.append(line).append(LINE_SEPARATOR); + } + } + } + finally + { + try + { + if (in != null) + { + in.close(); + } + } + catch (IOException exception) + { + exception.printStackTrace(); + } + } + } - /** - * 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 source - * String that is to have the entities restored.. - * @return The processed string. - */ - public static String restoreEntities(final StringBuffer source) - { - String result; + /** + * 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 source + * String that is to have the entities restored.. + * @return The processed string. + */ + public static String restoreEntities(final StringBuffer source) + { + String result; - if (source == null) - { - result = null; - } - else - { - StringBuffer buffer = new StringBuffer(source.length() * 2); + if (source == null) + { + result = null; + } + else + { + StringBuffer buffer = new StringBuffer(source.length() * 2); - int len = (source != null) ? source.length() : 0; - for (int index = 0; index < len; index++) - { - char letter = source.charAt(index); - switch (letter) - { - case '<': - { - buffer.append("<"); - break; - } + int len = (source != null) ? source.length() : 0; + for (int index = 0; index < len; index++) + { + char letter = source.charAt(index); + switch (letter) + { + case '<': + { + buffer.append("<"); + break; + } - case '>': - { - buffer.append(">"); - break; - } + case '>': + { + buffer.append(">"); + break; + } - case '&': - { - buffer.append("&"); - break; - } + case '&': + { + buffer.append("&"); + break; + } - default: - { - buffer.append(letter); - } - } - } - result = buffer.toString(); - } + default: + { + buffer.append(letter); + } + } + } + result = buffer.toString(); + } - // - return (result); - } + // + return (result); + } - /** + /** * */ - public static Document urlToDom(final URL source) throws Exception - { - Document result; + public static Document urlToDom(final URL source) throws Exception + { + Document result; - try - { - result = buildDom(source.openStream()); - } - catch (IOException exception) - { - String errorMessage = "IOError during parsing." + exception.getMessage(); - logger.error(errorMessage); - result = null; - throw new Exception(errorMessage, exception); - } + try + { + result = buildDom(source.openStream()); + } + catch (IOException exception) + { + String errorMessage = "IOError during parsing." + exception.getMessage(); + logger.error(errorMessage); + result = null; + throw new Exception(errorMessage, exception); + } - // - return (result); - } + // + return (result); + } } diff --git a/src/fr/devinsy/xidyn/utils/cache/Cache.java b/src/fr/devinsy/xidyn/utils/cache/Cache.java index 4405fda..978a329 100644 --- a/src/fr/devinsy/xidyn/utils/cache/Cache.java +++ b/src/fr/devinsy/xidyn/utils/cache/Cache.java @@ -28,147 +28,147 @@ import fr.devinsy.xidyn.utils.cache.CacheStrategy.Strategy; */ public class Cache { - private CacheStrategy strategy; - private Map> map; + private CacheStrategy strategy; + private Map> map; - /** + /** * */ - public Cache() - { - this.strategy = new CacheStrategy(Strategy.NONE, 0); - this.map = new HashMap>(); - } + public Cache() + { + this.strategy = new CacheStrategy(Strategy.NONE, 0); + this.map = new HashMap>(); + } - /** + /** * */ - public Cache(final int initialCapacity) - { - this.strategy = new CacheStrategy(Strategy.NONE, 0); - this.map = new HashMap>(initialCapacity); - } + public Cache(final int initialCapacity) + { + this.strategy = new CacheStrategy(Strategy.NONE, 0); + this.map = new HashMap>(initialCapacity); + } - /** + /** * */ - public void clear() - { - this.map.clear(); - } + public void clear() + { + this.map.clear(); + } - /** - * - * @param key - * @return - * @throws Exception - */ - public T get(final Object key) - { - T result; + /** + * + * @param key + * @return + * @throws Exception + */ + public T get(final Object key) + { + T result; - CacheItem item = this.map.get(key); + CacheItem item = this.map.get(key); - if (item == null) - { - result = null; - } - else - { - result = item.getValue(); - } + if (item == null) + { + result = null; + } + else + { + result = item.getValue(); + } - // - return result; - } + // + return result; + } - /** - * - * @return - */ - public boolean isEmpty() - { - boolean result; + /** + * + * @return + */ + public boolean isEmpty() + { + boolean result; - result = this.map.isEmpty(); + result = this.map.isEmpty(); - // - return result; - } + // + return result; + } - /** + /** * */ - public void purge() - { - switch (this.strategy.getStrategy()) - { - case NONE: - { - } - break; + public void purge() + { + switch (this.strategy.getStrategy()) + { + case NONE: + { + } + break; - case SIZE: - { - if (this.map.size() > this.strategy.getParameter()) - { - // TODO - } - } - break; + case SIZE: + { + if (this.map.size() > this.strategy.getParameter()) + { + // TODO + } + } + break; - case TIME: - { - // TODO - } - break; - } - } + case TIME: + { + // TODO + } + break; + } + } - /** - * - * @param source - * @return - */ - public T put(final Object key, final T source) - { - T result; + /** + * + * @param source + * @return + */ + public T put(final Object key, final T source) + { + T result; - if (source != null) - { - CacheItem item = this.map.get(key); + if (source != null) + { + CacheItem item = this.map.get(key); - if (item == null) - { - purge(); - item = new CacheItem(source); - this.map.put(key, item); - } - else - { - item.setValue(source); - } - } + if (item == null) + { + purge(); + item = new CacheItem(source); + this.map.put(key, item); + } + else + { + item.setValue(source); + } + } - result = source; + result = source; - // - return result; - } + // + return result; + } - /** - * - * @return - */ - public int size() - { - int result; + /** + * + * @return + */ + public int size() + { + int result; - result = this.map.size(); + result = this.map.size(); - // - return result; - } + // + return result; + } } // //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/fr/devinsy/xidyn/utils/cache/CacheItem.java b/src/fr/devinsy/xidyn/utils/cache/CacheItem.java index 727d8af..1bb54d9 100644 --- a/src/fr/devinsy/xidyn/utils/cache/CacheItem.java +++ b/src/fr/devinsy/xidyn/utils/cache/CacheItem.java @@ -25,103 +25,103 @@ import java.util.Date; */ public class CacheItem { - private T value; - private long creationDate; - private long editionDate; - private long accessDate; + private T value; + private long creationDate; + private long editionDate; + private long accessDate; - /** - * - * @param source - */ - public CacheItem(final T source) - { - this.value = source; - this.creationDate = time(); - this.editionDate = this.creationDate; - this.accessDate = this.creationDate; - } + /** + * + * @param source + */ + public CacheItem(final T source) + { + this.value = source; + this.creationDate = time(); + this.editionDate = this.creationDate; + this.accessDate = this.creationDate; + } - /** - * - * @return - */ - public long accessDate() - { - long result; + /** + * + * @return + */ + public long accessDate() + { + long result; - result = this.accessDate; + result = this.accessDate; - // - return result; - } + // + return result; + } - /** - * - * @return - */ - public long creationDate() - { - long result; + /** + * + * @return + */ + public long creationDate() + { + long result; - result = this.creationDate; + result = this.creationDate; - // - return result; - } + // + return result; + } - /** - * - * @return - */ - public long editionDate() - { - long result; + /** + * + * @return + */ + public long editionDate() + { + long result; - result = this.editionDate; + result = this.editionDate; - // - return result; - } + // + return result; + } - /** - * - * @return - */ - public T getValue() - { - T result; + /** + * + * @return + */ + public T getValue() + { + T result; - result = this.value; - this.accessDate = time(); + result = this.value; + this.accessDate = time(); - // - return result; - } + // + return result; + } - /** - * - * @param source - */ - public void setValue(final T source) - { - this.value = source; - this.editionDate = time(); - } + /** + * + * @param source + */ + public void setValue(final T source) + { + this.value = source; + this.editionDate = time(); + } - /** - * - * @return - */ - private static long time() - { - long result; + /** + * + * @return + */ + private static long time() + { + long result; - result = new Date().getTime(); + result = new Date().getTime(); - // - return result; - } + // + return result; + } } // //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/fr/devinsy/xidyn/utils/cache/CacheStrategy.java b/src/fr/devinsy/xidyn/utils/cache/CacheStrategy.java index 1e8d9f3..92d28ac 100644 --- a/src/fr/devinsy/xidyn/utils/cache/CacheStrategy.java +++ b/src/fr/devinsy/xidyn/utils/cache/CacheStrategy.java @@ -23,57 +23,57 @@ package fr.devinsy.xidyn.utils.cache; */ public class CacheStrategy { - public enum Strategy - { - NONE, - SIZE, - TIME - } + public enum Strategy + { + NONE, + SIZE, + TIME + } - private Strategy strategy; - private long parameter; + private Strategy strategy; + private long parameter; - /** - * - * @param strategy - * @param parameter - */ - public CacheStrategy(final Strategy strategy, final long parameter) - { - if (strategy == null) - { - throw new IllegalArgumentException("Null strategy."); - } - else if (parameter < 0) - { - throw new IllegalArgumentException("Negative parameter."); - } - else - { - this.strategy = strategy; - this.parameter = parameter; - } - } + /** + * + * @param strategy + * @param parameter + */ + public CacheStrategy(final Strategy strategy, final long parameter) + { + if (strategy == null) + { + throw new IllegalArgumentException("Null strategy."); + } + else if (parameter < 0) + { + throw new IllegalArgumentException("Negative parameter."); + } + else + { + this.strategy = strategy; + this.parameter = parameter; + } + } - public long getParameter() - { - return this.parameter; - } + public long getParameter() + { + return this.parameter; + } - public Strategy getStrategy() - { - return this.strategy; - } + public Strategy getStrategy() + { + return this.strategy; + } - public void setParameter(final long parameter) - { - this.parameter = parameter; - } + public void setParameter(final long parameter) + { + this.parameter = parameter; + } - public void setStrategy(final Strategy strategy) - { - this.strategy = strategy; - } + public void setStrategy(final Strategy strategy) + { + this.strategy = strategy; + } } // //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/fr/devinsy/xidyn/views/CharterView.java b/src/fr/devinsy/xidyn/views/CharterView.java index 61630f0..4902c61 100644 --- a/src/fr/devinsy/xidyn/views/CharterView.java +++ b/src/fr/devinsy/xidyn/views/CharterView.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2006-2014 Christian Pierre MOMON + * Copyright (C) 2006-2016 Christian Pierre MOMON * * This file is part of Xidyn. * @@ -25,14 +25,14 @@ import java.util.Locale; */ public interface CharterView extends View { - /** - * - * @param userId - * @param lang - * @param content - * @return - */ - public StringBuffer getHtml(final Long userId, final Locale language, final CharSequence content) throws Exception; + /** + * + * @param userId + * @param lang + * @param content + * @return + */ + public StringBuffer getHtml(final Long userId, final Locale language, final CharSequence content) throws Exception; } // //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/fr/devinsy/xidyn/views/View.java b/src/fr/devinsy/xidyn/views/View.java index 6715f97..f17558c 100644 --- a/src/fr/devinsy/xidyn/views/View.java +++ b/src/fr/devinsy/xidyn/views/View.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2006-2014 Christian Pierre MOMON + * Copyright (C) 2006-2016 Christian Pierre MOMON * * This file is part of Xidyn. * @@ -23,10 +23,10 @@ package fr.devinsy.xidyn.views; */ public interface View { - /** + /** * */ - public StringBuffer getHtml() throws Exception; + public StringBuffer getHtml() throws Exception; } diff --git a/test/Foo.java b/test/Foo.java index 36b80c9..d18d085 100644 --- a/test/Foo.java +++ b/test/Foo.java @@ -25,14 +25,14 @@ import fr.devinsy.xidyn.utils.XidynUtils; */ class Foo { - /** - * @throws Exception - * - */ - public static void main(final String[] args) throws Exception - { - String source = "

toto

blank
"; + /** + * @throws Exception + * + */ + public static void main(final String[] args) throws Exception + { + String source = "

toto

blank
"; - Document dom = XidynUtils.buildDom(source); - } + Document dom = XidynUtils.buildDom(source); + } } diff --git a/test/XidynTest.java b/test/XidynTest.java index c22bf08..e553bd5 100644 --- a/test/XidynTest.java +++ b/test/XidynTest.java @@ -29,233 +29,244 @@ import fr.devinsy.xidyn.presenters.StringPresenter; */ class XidynTest { - public enum MONTHS - { - JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBRE, DECEMBRE - } + public enum MONTHS + { + JANUARY, + FEBRUARY, + MARCH, + APRIL, + MAY, + JUNE, + JULY, + AUGUST, + SEPTEMBER, + OCTOBER, + NOVEMBRE, + DECEMBRE + } - static private Logger logger = LoggerFactory.getLogger(XidynTest.class); - static - { - // Initialize logger. - org.apache.log4j.BasicConfigurator.configure(); - org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO); - } + static private Logger logger = LoggerFactory.getLogger(XidynTest.class); + static + { + // Initialize logger. + org.apache.log4j.BasicConfigurator.configure(); + org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO); + } - /** + /** * */ - public static String check(final String title, final StringBuffer source, final String model) - { - String result; + public static String check(final String title, final StringBuffer source, final String model) + { + String result; - if (source.indexOf(model) == -1) - { - result = String.format("%-40s -> KO <-", title) + "\nGet:\n" + source + "\nWaiting:\n" + model; + if (source.indexOf(model) == -1) + { + result = String.format("%-40s -> KO <-", title) + "\nGet:\n" + source + "\nWaiting:\n" + model; - } - else - { - result = String.format("%-40s [ OK ] ", title); - } + } + else + { + result = String.format("%-40s [ OK ] ", title); + } - // - return (result); - }; + // + return (result); + }; - /** + /** * */ - public static void main(final String[] args) - { - System.out.println("Automatic test action for Xid!"); + public static void main(final String[] args) + { + System.out.println("Automatic test action for Xid!"); - TagDataManager datas; - SimpleTagData tag; + TagDataManager datas; + SimpleTagData tag; - String htmlSource; - StringBuffer html; + String htmlSource; + StringBuffer html; - // Populate attributes of Test 03. - System.out.println("----------------------------"); - datas = new TagDataManager(); - datas.setContent("name", "Superman"); - try - { - html = StringPresenter.dynamize("
a name
", datas); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - html = null; - } + // Populate attributes of Test 03. + System.out.println("----------------------------"); + datas = new TagDataManager(); + datas.setContent("name", "Superman"); + try + { + html = StringPresenter.dynamize("
a name
", datas); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + html = null; + } - System.out.println(check("only content change", html, "
Superman
")); + System.out.println(check("only content change", html, "
Superman
")); - // Populate attributes of Test 03. - System.out.println("----------------------------"); - datas = new TagDataManager(); - datas.setContent("lastname", "Spiderman"); - datas.appendAttribute("lastname", "style", "background: blue;"); - datas.appendAttribute("lastname", "style", "foreground: red;"); - datas.setAttribute("lastname", "class", "nameClass"); + // Populate attributes of Test 03. + System.out.println("----------------------------"); + datas = new TagDataManager(); + datas.setContent("lastname", "Spiderman"); + datas.appendAttribute("lastname", "style", "background: blue;"); + datas.appendAttribute("lastname", "style", "foreground: red;"); + datas.setAttribute("lastname", "class", "nameClass"); - try - { - html = StringPresenter.dynamize("
a last name
", datas); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - html = null; - } - System.out.println(check("content and attributes", html, "
Spiderman
")); + try + { + html = StringPresenter.dynamize("
a last name
", datas); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + html = null; + } + System.out.println(check("content and attributes", html, "
Spiderman
")); - // Populate attributes of Test 03. - System.out.println("----------------------------"); - datas = new TagDataManager(); - 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"); + // Populate attributes of Test 03. + System.out.println("----------------------------"); + datas = new TagDataManager(); + 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"); - try - { - html = StringPresenter.dynamize("
    \n
  • a word
  • \n
", datas); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - html = null; - } + try + { + html = StringPresenter.dynamize("
    \n
  • a word
  • \n
", datas); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + html = null; + } - System.out.println(check("list assertion 1", html, "
  • alpha
  • ")); - System.out.println(check("list assertion 2", html, "
  • bravo
  • ")); - System.out.println(check("list assertion 3", html, "
  • charlie
  • ")); - System.out.println(check("list assertion 4", html, "
  • delta
  • ")); - System.out.println(check("list assertion 5", html, "
  • echo
  • ")); - System.out.println(check("list assertion 6", html, "
  • fox
  • ")); + System.out.println(check("list assertion 1", html, "
  • alpha
  • ")); + System.out.println(check("list assertion 2", html, "
  • bravo
  • ")); + System.out.println(check("list assertion 3", html, "
  • charlie
  • ")); + System.out.println(check("list assertion 4", html, "
  • delta
  • ")); + System.out.println(check("list assertion 5", html, "
  • echo
  • ")); + System.out.println(check("list assertion 6", html, "
  • fox
  • ")); - // Populate attributes of Test 03. - System.out.println("----------------------------"); - datas = new TagDataManager(); - datas.setContent("identity", 0, "nom", "Jemba"); - datas.setContent("identity", 0, "prenom", "Epo"); - datas.setContent("identity", 1, "nom", "Momon"); - datas.setContent("identity", 1, "prenom", "Christian"); - datas.setContent("identity", 2, "nom", "Tronche"); - datas.setContent("identity", 2, "prenom", "Christophe"); + // Populate attributes of Test 03. + System.out.println("----------------------------"); + datas = new TagDataManager(); + datas.setContent("identity", 0, "nom", "Jemba"); + datas.setContent("identity", 0, "prenom", "Epo"); + datas.setContent("identity", 1, "nom", "Momon"); + datas.setContent("identity", 1, "prenom", "Christian"); + datas.setContent("identity", 2, "nom", "Tronche"); + datas.setContent("identity", 2, "prenom", "Christophe"); - StringBuffer source = new StringBuffer(); - source.append("\n"); - source.append(" \n"); - source.append("
    noidun nomun prenom
    "); - htmlSource = source.toString(); - try - { - html = StringPresenter.dynamize(htmlSource, datas); - } - catch (Exception exception) - { - System.out.println(exception.getMessage()); - html = null; - } + StringBuffer source = new StringBuffer(); + source.append("\n"); + source.append(" \n"); + source.append("
    noidun nomun prenom
    "); + htmlSource = source.toString(); + try + { + html = StringPresenter.dynamize(htmlSource, datas); + } + catch (Exception exception) + { + System.out.println(exception.getMessage()); + 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 - * ("----------------------------"); datas = new Data (); - * datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent - * ("identity", 0, "prenom", "Epo"); datas.setContent ("identity", 1, - * "nom", "Momon"); datas.setContent ("identity", 1, "prenom", - * "Christian"); datas.setContent ("identity", 2, "nom", "Tronche"); - * datas.setContent ("identity", 2, "prenom", "Christophe"); - * datas.setIterationStrategy ("identity", - * IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); - * //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); - * - * - * errorMessage = new StringBuffer (); source = new StringBuffer (); - * source.append ("\n"); source.append ( - * " \n" - * ); source.append ( - * " \n" - * ); source.append ( - * " \n" - * ); source.append ("
    noidun nomun prenom
    noidun nomun prenom
    noidun nomun prenom
    "); htmlSource = source.toString (); - * - * System.out.println ("datas = new Data ();"); System.out.println - * ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");"); - * System.out.println - * ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");"); - * System.out.println - * ("datas.setContent (\"identity\", 1, \"nom\", \"Momon\");"); - * System.out.println - * ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");"); - * System.out.println - * ("datas.setContent (\"identity\", 2, \"nom\", \"Tronche\");"); - * System.out.println - * ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");"); - * - * System.out.println ("+"); System.out.println (htmlSource); - * System.out.println ("=>"); - * - * - * datas.setIterationStrategy ("identity", - * IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); System.out.println - * ("ONLY_FIRST_ROW:"); html = Presenter.dynamize (htmlSource, datas, "", - * errorMessage); System.out.println (html); - * - * datas.setIterationStrategy ("identity", - * IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID); - * System.out.println ("ONLY_ROWS_WITH_ID:"); html = Presenter.dynamize - * (htmlSource, datas, "", errorMessage); System.out.println (html); - * - * datas.setIterationStrategy ("identity", - * IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID); - * System.out.println ("ONLY_ROWS_WITHOUT_ID:"); html = Presenter.dynamize - * (htmlSource, datas, "", errorMessage); System.out.println (html); - * - * datas.setIterationStrategy ("identity", - * IdsDataByIndex.IterationStrategy.ALL_ROWS); System.out.println - * ("ALL_ROWS:"); html = Presenter.dynamize (htmlSource, datas, "", - * errorMessage); System.out.println (html); - * - * - * - * // Populate attributes of Test 03. System.out.println - * ("----------------------------"); datas = new Data (); - * datas.setAttribute ("
    ", "class", "aDivClass"); - * datas.setAttribute ("
    ", "style", "background-color: #000000;"); - * datas.setAttribute ("number", "style", "background-color: #0000FF;"); - * - * errorMessage = new StringBuffer (); source = new StringBuffer (); - * source.append ("
    \n"); source.append ("

    one

    \n"); - * source.append ("
    \n"); source.append ("
    \n"); - * source.append ("

    three

    \n"); source.append ("
    "); - * htmlSource = source.toString (); html = Presenter.dynamize (htmlSource, - * datas, "", errorMessage); - * - * System.out.println (htmlSource); System.out.println ("+"); - * System.out.println ("datas = new Data ();"); System.out.println - * ("datas.setAttribute (\"
    \", \"class\", \"aDivClass\");"); - * System.out.println ( - * "datas.setAttribute (\"
    \", \"style\", \"background-color: #000000;\");" - * ); System.out.println ( - * "datas.setAttribute (\"number\", \"style\", \"background-color: #0000FF;\");" - * ); - * - * System.out.println ("=>"); System.out.println (html); - */ - } + /* + * // Populate attributes of Test 03. System.out.println + * ("----------------------------"); datas = new Data (); + * datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent + * ("identity", 0, "prenom", "Epo"); datas.setContent ("identity", 1, + * "nom", "Momon"); datas.setContent ("identity", 1, "prenom", + * "Christian"); datas.setContent ("identity", 2, "nom", "Tronche"); + * datas.setContent ("identity", 2, "prenom", "Christophe"); + * datas.setIterationStrategy ("identity", + * IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); + * //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); + * + * + * errorMessage = new StringBuffer (); source = new StringBuffer (); + * source.append ("\n"); source.append ( + * " \n" + * ); source.append ( + * " \n" + * ); source.append ( + * " \n" + * ); source.append ("
    noidun nomun prenom
    noidun nomun prenom
    noidun nomun prenom
    "); htmlSource = source.toString (); + * + * System.out.println ("datas = new Data ();"); System.out.println + * ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");"); + * System.out.println + * ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");"); + * System.out.println + * ("datas.setContent (\"identity\", 1, \"nom\", \"Momon\");"); + * System.out.println + * ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");"); + * System.out.println + * ("datas.setContent (\"identity\", 2, \"nom\", \"Tronche\");"); + * System.out.println + * ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");"); + * + * System.out.println ("+"); System.out.println (htmlSource); + * System.out.println ("=>"); + * + * + * datas.setIterationStrategy ("identity", + * IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); System.out.println + * ("ONLY_FIRST_ROW:"); html = Presenter.dynamize (htmlSource, datas, "", + * errorMessage); System.out.println (html); + * + * datas.setIterationStrategy ("identity", + * IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID); + * System.out.println ("ONLY_ROWS_WITH_ID:"); html = Presenter.dynamize + * (htmlSource, datas, "", errorMessage); System.out.println (html); + * + * datas.setIterationStrategy ("identity", + * IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID); + * System.out.println ("ONLY_ROWS_WITHOUT_ID:"); html = Presenter.dynamize + * (htmlSource, datas, "", errorMessage); System.out.println (html); + * + * datas.setIterationStrategy ("identity", + * IdsDataByIndex.IterationStrategy.ALL_ROWS); System.out.println + * ("ALL_ROWS:"); html = Presenter.dynamize (htmlSource, datas, "", + * errorMessage); System.out.println (html); + * + * + * + * // Populate attributes of Test 03. System.out.println + * ("----------------------------"); datas = new Data (); + * datas.setAttribute ("
    ", "class", "aDivClass"); + * datas.setAttribute ("
    ", "style", "background-color: #000000;"); + * datas.setAttribute ("number", "style", "background-color: #0000FF;"); + * + * errorMessage = new StringBuffer (); source = new StringBuffer (); + * source.append ("
    \n"); source.append ("

    one

    \n"); + * source.append ("
    \n"); source.append ("
    \n"); + * source.append ("

    three

    \n"); source.append ("
    "); + * htmlSource = source.toString (); html = Presenter.dynamize (htmlSource, + * datas, "", errorMessage); + * + * System.out.println (htmlSource); System.out.println ("+"); + * System.out.println ("datas = new Data ();"); System.out.println + * ("datas.setAttribute (\"
    \", \"class\", \"aDivClass\");"); + * System.out.println ( + * "datas.setAttribute (\"
    \", \"style\", \"background-color: #000000;\");" + * ); System.out.println ( + * "datas.setAttribute (\"number\", \"style\", \"background-color: #0000FF;\");" + * ); + * + * System.out.println ("=>"); System.out.println (html); + */ + } } diff --git a/test/fr/devinsy/xidyn/pages/PageTest.java b/test/fr/devinsy/xidyn/pages/PageTest.java new file mode 100644 index 0000000..183d441 --- /dev/null +++ b/test/fr/devinsy/xidyn/pages/PageTest.java @@ -0,0 +1,137 @@ +/** + * Copyright (C) 2016 Christian Pierre MOMON + * + * This file is part of Xidyn. + * + * Xidyn is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Xidyn is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Xidyn. If not, see + */ +package fr.devinsy.xidyn.pages; + +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.fest.assertions.Assertions; +import org.junit.Before; +import org.junit.Test; + +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; +import fr.devinsy.xidyn.presenters.StringPresenter; + +/** + * + */ +public class PageTest +{ + /** + * + */ + @Before + public void before() + { + BasicConfigurator.configure(); + Logger.getRootLogger().setLevel(Level.ERROR); + } + + /** + * @throws Exception + * + */ + @Test + public void testDynamize01() throws Exception + { + String source = "aaaaahellozzzzz"; + + String target = new Page(new StringPresenter(source)).dynamize().toString(); + + Assertions.assertThat(target).isEqualTo(source); + + target = new Page(new StringPresenter(source)).lastVersion().toString(); + + Assertions.assertThat(target).isEqualTo(source); + } + + /** + * @throws Exception + * + */ + @Test + public void testDynamize02() throws Exception + { + String source = "aaaaahellozzzzz"; + + String target = new StringPresenter(source).dynamize(null).toString(); + + Assertions.assertThat(target).isEqualTo(source); + } + + /** + * @throws Exception + * + */ + @Test + public void testDynamize03() throws Exception + { + String source = "aaaaa
    hello
    zzzzz"; + + String target = new StringPresenter(source).dynamize(new TagDataManager()).toString(); + + Assertions.assertThat(target).isEqualTo(source); + } + + /** + * @throws Exception + * + */ + @Test + public void testPage02() throws Exception + { + String source = "aaaaa
    hello
    zzzzz"; + + Page page = PageFactory.instance().get(source); + + String target = page.dynamize().toString(); + + Assertions.assertThat(target).isEqualTo(source); + } + + /** + * @throws Exception + * + */ + @Test + public void testStaticDynamize01() throws Exception + { + String source = "aaaaa
    hello
    zzzzz"; + + String target = PresenterUtils.dynamize(source, null).toString(); + + Assertions.assertThat(target).isEqualTo(source); + } + + /** + * @throws Exception + * + */ + @Test + public void testStaticDynamize02() throws Exception + { + String source = "aaaaa
    hello
    zzzzz"; + + String target = PresenterUtils.dynamize(source, new TagDataManager()).toString(); + + Assertions.assertThat(target).isEqualTo(source); + } + +} diff --git a/test/fr/devinsy/xidyn/presenters/DomPresenterTest.java b/test/fr/devinsy/xidyn/presenters/DomPresenterTest.java index 5131301..85304a4 100644 --- a/test/fr/devinsy/xidyn/presenters/DomPresenterTest.java +++ b/test/fr/devinsy/xidyn/presenters/DomPresenterTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2006-2014 Christian Pierre MOMON + * Copyright (C) 2006-2016 Christian Pierre MOMON * * This file is part of Xidyn. * @@ -18,11 +18,7 @@ */ package fr.devinsy.xidyn.presenters; -import org.apache.log4j.BasicConfigurator; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; import org.fest.assertions.Assertions; -import org.junit.Before; import org.junit.Test; import fr.devinsy.xidyn.data.TagDataManager; @@ -32,84 +28,33 @@ import fr.devinsy.xidyn.data.TagDataManager; */ public class DomPresenterTest { - /** - * - */ - @Before - public void before() - { - BasicConfigurator.configure(); - Logger.getRootLogger().setLevel(Level.ERROR); - } - /** - * @throws Exception - * - */ - @Test - public void testDynamize01() throws Exception - { - String source = "aaaaa
    hello
    zzzzz"; + /** + * @throws Exception + * + */ + @Test + public void testStaticDynamize01() throws Exception + { + String source = "aaaaa
    hello
    zzzzz"; - String target = new StringPresenter(source).dynamize().toString(); + String target = PresenterUtils.dynamize(source, null).toString(); - Assertions.assertThat(target).isEqualTo(source); - } + Assertions.assertThat(target).isEqualTo(source); + } - /** - * @throws Exception - * - */ - @Test - public void testDynamize02() throws Exception - { - String source = "aaaaa
    hello
    zzzzz"; + /** + * @throws Exception + * + */ + @Test + public void testStaticDynamize02() throws Exception + { + String source = "aaaaa
    hello
    zzzzz"; - String target = new StringPresenter(source).dynamize(null).toString(); + String target = PresenterUtils.dynamize(source, new TagDataManager()).toString(); - Assertions.assertThat(target).isEqualTo(source); - } - - /** - * @throws Exception - * - */ - @Test - public void testDynamize03() throws Exception - { - String source = "aaaaa
    hello
    zzzzz"; - - String target = new StringPresenter(source).dynamize(new TagDataManager()).toString(); - - Assertions.assertThat(target).isEqualTo(source); - } - - /** - * @throws Exception - * - */ - @Test - public void testStaticDynamize01() throws Exception - { - String source = "aaaaa
    hello
    zzzzz"; - - String target = StringPresenter.dynamize(source, null).toString(); - - Assertions.assertThat(target).isEqualTo(source); - } - - /** - * @throws Exception - * - */ - @Test - public void testStaticDynamize02() throws Exception - { - String source = "aaaaa
    hello
    zzzzz"; - - String target = StringPresenter.dynamize(source, new TagDataManager()).toString(); - - Assertions.assertThat(target).isEqualTo(source); - } + Assertions.assertThat(target).isEqualTo(source); + } } diff --git a/test/fr/devinsy/xidyn/presenters/PresenterUtilsTest.java b/test/fr/devinsy/xidyn/presenters/PresenterUtilsTest.java new file mode 100644 index 0000000..8dc87c0 --- /dev/null +++ b/test/fr/devinsy/xidyn/presenters/PresenterUtilsTest.java @@ -0,0 +1,73 @@ +/** + * Copyright (C) 2006-2016 Christian Pierre MOMON + * + * This file is part of Xidyn. + * + * Xidyn is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Xidyn is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Xidyn. If not, see + */ +package fr.devinsy.xidyn.presenters; + +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.fest.assertions.Assertions; +import org.junit.Before; +import org.junit.Test; + +import fr.devinsy.xidyn.data.TagDataManager; + +/** + * + */ +public class PresenterUtilsTest +{ + /** + * + */ + @Before + public void before() + { + BasicConfigurator.configure(); + Logger.getRootLogger().setLevel(Level.ERROR); + } + + /** + * @throws Exception + * + */ + @Test + public void testStaticDynamize01() throws Exception + { + String source = "aaaaa
    hello
    zzzzz"; + + String target = PresenterUtils.dynamize(source, null).toString(); + + Assertions.assertThat(target).isEqualTo(source); + } + + /** + * @throws Exception + * + */ + @Test + public void testStaticDynamize02() throws Exception + { + String source = "aaaaa
    hello
    zzzzz"; + + String target = PresenterUtils.dynamize(source, new TagDataManager()).toString(); + + Assertions.assertThat(target).isEqualTo(source); + } + +} diff --git a/test/fr/devinsy/xidyn/presenters/StringPresenterTest.java b/test/fr/devinsy/xidyn/presenters/StringPresenterTest.java index b7de4b1..cde3b97 100644 --- a/test/fr/devinsy/xidyn/presenters/StringPresenterTest.java +++ b/test/fr/devinsy/xidyn/presenters/StringPresenterTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2006-2014 Christian Pierre MOMON + * Copyright (C) 2006-2016 Christian Pierre MOMON * * This file is part of Xidyn. * @@ -32,84 +32,55 @@ import fr.devinsy.xidyn.data.TagDataManager; */ public class StringPresenterTest { - /** + /** * */ - @Before - public void before() - { - BasicConfigurator.configure(); - Logger.getRootLogger().setLevel(Level.ERROR); - } + @Before + public void before() + { + BasicConfigurator.configure(); + Logger.getRootLogger().setLevel(Level.ERROR); + } - /** - * @throws Exception - * - */ - @Test - public void testDynamize01() throws Exception - { - String source = "aaaaahellozzzzz"; + /** + * @throws Exception + * + */ + @Test + public void testDynamize01() throws Exception + { + String source = "aaaaahellozzzzz"; - String target = new StringPresenter(source).dynamize().toString(); + String target = new StringPresenter(source).dynamize().toString(); - Assertions.assertThat(target).isEqualTo(source); - } + Assertions.assertThat(target).isEqualTo(source); + } - /** - * @throws Exception - * - */ - @Test - public void testDynamize02() throws Exception - { - String source = "aaaaahellozzzzz"; + /** + * @throws Exception + * + */ + @Test + public void testDynamize02() throws Exception + { + String source = "aaaaahellozzzzz"; - String target = new StringPresenter(source).dynamize(null).toString(); + String target = new StringPresenter(source).dynamize(null).toString(); - Assertions.assertThat(target).isEqualTo(source); - } + Assertions.assertThat(target).isEqualTo(source); + } - /** - * @throws Exception - * - */ - @Test - public void testDynamize03() throws Exception - { - String source = "aaaaa
    hello
    zzzzz"; + /** + * @throws Exception + * + */ + @Test + public void testDynamize03() throws Exception + { + String source = "aaaaa
    hello
    zzzzz"; - String target = new StringPresenter(source).dynamize(new TagDataManager()).toString(); - - Assertions.assertThat(target).isEqualTo(source); - } - - /** - * @throws Exception - * - */ - @Test - public void testStaticDynamize01() throws Exception - { - String source = "aaaaa
    hello
    zzzzz"; - - String target = StringPresenter.dynamize(source, null).toString(); - - Assertions.assertThat(target).isEqualTo(source); - } - - /** - * @throws Exception - * - */ - @Test - public void testStaticDynamize02() throws Exception - { - String source = "aaaaa
    hello
    zzzzz"; - - String target = StringPresenter.dynamize(source, new TagDataManager()).toString(); - - Assertions.assertThat(target).isEqualTo(source); - } + String target = new StringPresenter(source).dynamize(new TagDataManager()).toString(); + Assertions.assertThat(target).isEqualTo(source); + } } diff --git a/test/fr/devinsy/xidyn/utils/XidynUtilsTest.java b/test/fr/devinsy/xidyn/utils/XidynUtilsTest.java index 88e5a0a..54340ce 100644 --- a/test/fr/devinsy/xidyn/utils/XidynUtilsTest.java +++ b/test/fr/devinsy/xidyn/utils/XidynUtilsTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2006-2014 Christian Pierre MOMON + * Copyright (C) 2006-2016 Christian Pierre MOMON * * This file is part of Xidyn. * @@ -30,151 +30,151 @@ import org.junit.Test; */ public class XidynUtilsTest { - /** + /** * */ - @Before - public void before() - { - BasicConfigurator.configure(); - Logger.getRootLogger().setLevel(Level.ERROR); - } + @Before + public void before() + { + BasicConfigurator.configure(); + Logger.getRootLogger().setLevel(Level.ERROR); + } - /** + /** * */ - @Test - public void testExtractBodyContent01() - { - String source = "aaaaahellozzzzz"; + @Test + public void testExtractBodyContent01() + { + String source = "aaaaahellozzzzz"; - String target = XidynUtils.extractBodyContent(source); - Assertions.assertThat(target).isEqualTo("hello"); - } + String target = XidynUtils.extractBodyContent(source); + Assertions.assertThat(target).isEqualTo("hello"); + } - /** + /** * */ - @Test - public void testExtractBodyContent02() - { - String source = "aaaaaaahellozzzzz"; + @Test + public void testExtractBodyContent02() + { + String source = "aaaaaaahellozzzzz"; - String target = XidynUtils.extractBodyContent(source); - Assertions.assertThat(target).isEqualTo(""); - } + String target = XidynUtils.extractBodyContent(source); + Assertions.assertThat(target).isEqualTo(""); + } - /** + /** * */ - @Test - public void testExtractBodyContent03() - { - String source = "aaaaazzzzz"; + @Test + public void testExtractBodyContent03() + { + String source = "aaaaazzzzz"; - String target = XidynUtils.extractBodyContent(source); - Assertions.assertThat(target).isEqualTo(""); - } + String target = XidynUtils.extractBodyContent(source); + Assertions.assertThat(target).isEqualTo(""); + } - /** + /** * */ - @Test - public void testExtractBodyContent04() - { - String source = "aaaaa hello zzzzz"; + @Test + public void testExtractBodyContent04() + { + String source = "aaaaa hello zzzzz"; - String target = XidynUtils.extractBodyContent(source); - Assertions.assertThat(target).isEqualTo("hello"); - } + String target = XidynUtils.extractBodyContent(source); + Assertions.assertThat(target).isEqualTo("hello"); + } - /** + /** * */ - @Test - public void testExtractBodyContent05() - { - StringBuffer buffer = new StringBuffer(1000); - buffer.append("").append("\n"); - buffer.append("").append("\n"); - buffer.append("").append("\n"); - buffer.append("").append("\n"); - buffer.append("Kinsources").append("\n"); - buffer.append("").append("\n"); - buffer.append("").append("\n"); - buffer.append(" ").append("\n"); - buffer.append("").append("\n"); - buffer.append("").append("\n"); - buffer.append(""); - buffer.append("WELCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOME"); - buffer.append("").append("\n"); - buffer.append("").append("\n"); + @Test + public void testExtractBodyContent05() + { + StringBuffer buffer = new StringBuffer(1000); + buffer.append("").append("\n"); + buffer.append("").append("\n"); + buffer.append("").append("\n"); + buffer.append("").append("\n"); + buffer.append("Kinsources").append("\n"); + buffer.append("").append("\n"); + buffer.append("").append("\n"); + buffer.append(" ").append("\n"); + buffer.append("").append("\n"); + buffer.append("").append("\n"); + buffer.append(""); + buffer.append("WELCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOME"); + buffer.append("").append("\n"); + buffer.append("").append("\n"); - String source = buffer.toString(); + String source = buffer.toString(); - // System.out.println("[" + source + "]"); - String target = XidynUtils.extractBodyContent(source); - Assertions.assertThat(target).isEqualTo("WELCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOME"); - } + // System.out.println("[" + source + "]"); + String target = XidynUtils.extractBodyContent(source); + Assertions.assertThat(target).isEqualTo("WELCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOME"); + } - /** + /** * */ - @Test - public void testExtractDoctype01() - { - String source = "aaaaahellozzzzz"; + @Test + public void testExtractDoctype01() + { + String source = "aaaaahellozzzzz"; - String target = XidynUtils.extractDoctype(source); - Assertions.assertThat(target).isNull(); - } + String target = XidynUtils.extractDoctype(source); + Assertions.assertThat(target).isNull(); + } - /** + /** * */ - @Test - public void testExtractDoctype02() - { - String source = "aaaaahellozzzzz"; + @Test + public void testExtractDoctype02() + { + String source = "aaaaahellozzzzz"; - String target = XidynUtils.extractDoctype(source); - Assertions.assertThat(target).isEqualTo(""); - } + String target = XidynUtils.extractDoctype(source); + Assertions.assertThat(target).isEqualTo(""); + } - /** + /** * */ - @Test - public void testExtractDoctype03() - { - String source = "aaaaahellozzzzz"; + @Test + public void testExtractDoctype03() + { + String source = "aaaaahellozzzzz"; - String target = XidynUtils.extractDoctype(source); - Assertions.assertThat(target).isEqualTo(""); - } + String target = XidynUtils.extractDoctype(source); + Assertions.assertThat(target).isEqualTo(""); + } - /** + /** * */ - @Test - public void testExtractDoctype04() - { - String source = "aaaaahellozzzzz"; + @Test + public void testExtractDoctype04() + { + String source = "aaaaahellozzzzz"; - String target = XidynUtils.extractDoctype(source); - Assertions.assertThat(target).isEqualTo(""); - } + String target = XidynUtils.extractDoctype(source); + Assertions.assertThat(target).isEqualTo(""); + } - /** + /** * */ - @Test - public void testExtractDoctype05() - { - String source = "aaaaahellozzzzz"; + @Test + public void testExtractDoctype05() + { + String source = "aaaaahellozzzzz"; - String target = XidynUtils.extractDoctype(source); - Assertions.assertThat(target).isEqualTo(""); - } + String target = XidynUtils.extractDoctype(source); + Assertions.assertThat(target).isEqualTo(""); + } }