Refactor formatter.

This commit is contained in:
Christian P. MOMON 2016-09-08 02:41:48 +02:00
parent 3b2de97563
commit faabbe42be
38 changed files with 4883 additions and 4620 deletions

View file

@ -1,4 +1,14 @@
eclipse.preferences.version=1 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.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 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_binary_expression=16
org.eclipse.jdt.core.formatter.alignment_for_compact_if=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_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_expressions_in_array_initializer=16
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 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.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_block_comment=false
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_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_header=false
org.eclipse.jdt.core.formatter.comment.format_html=true org.eclipse.jdt.core.formatter.comment.format_html=true
org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true org.eclipse.jdt.core.formatter.comment.format_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_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_enum_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_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_empty_lines=false
org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true 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_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_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.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_field=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_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_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.number_of_empty_lines_to_preserve=1
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true 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.tabulation.size=4
org.eclipse.jdt.core.formatter.use_on_off_tags=false org.eclipse.jdt.core.formatter.use_on_off_tags=false
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false

View file

@ -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 eclipse.preferences.version=1
formatter_profile=_Devinsy editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_Xidyn
formatter_settings_version=12 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

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2014 Christian Pierre MOMON * Copyright (C) 2006-2016 Christian Pierre MOMON
* *
* This file is part of Xidyn. * 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.SimpleTagData;
import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.StringPresenter; import fr.devinsy.xidyn.presenters.PresenterUtils;
/** /**
* *
*/ */
class XidynDemo class XidynDemo
{ {
static private Logger logger = LoggerFactory.getLogger(XidynDemo.class); private static Logger logger = LoggerFactory.getLogger(XidynDemo.class);
static static
{ {
// Initialize logger. // Initialize logger.
org.apache.log4j.BasicConfigurator.configure(); org.apache.log4j.BasicConfigurator.configure();
org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO); org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO);
} }
/** /**
* *
*/ */
public static void main(final String[] args) public static void main(final String[] args)
{ {
System.out.println("Hello World!"); System.out.println("Hello World!");
// test (); // test ();
// //
TagDataManager data; TagDataManager data;
// Step #01. // Step #01.
{ {
System.out.println("----------------------------"); System.out.println("----------------------------");
// Populate attributes. // Populate attributes.
data = new TagDataManager(); data = new TagDataManager();
data.setContent("name", "Superman"); data.setContent("name", "Superman");
String htmlSource = "<div id='name'>a name</div >"; String htmlSource = "<div id='name'>a name</div >";
StringBuffer htmlTarget; StringBuffer htmlTarget;
try try
{ {
htmlTarget = StringPresenter.dynamize(htmlSource, data); htmlTarget = PresenterUtils.dynamize(htmlSource, data);
} }
catch (Exception exception) catch (Exception exception)
{ {
System.out.println(exception.getMessage()); System.out.println(exception.getMessage());
htmlTarget = null; htmlTarget = null;
} }
System.out.println("datas = new Data ();"); System.out.println("datas = new Data ();");
System.out.println("datas.setContent (\"name\", \"Superman\");"); System.out.println("datas.setContent (\"name\", \"Superman\");");
System.out.println("+"); System.out.println("+");
System.out.println("<div id='name'>a name</div >"); System.out.println("<div id='name'>a name</div >");
System.out.println("=>"); System.out.println("=>");
System.out.println(htmlTarget); System.out.println(htmlTarget);
System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]"); System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]");
} }
// Step #02. // Step #02.
{ {
System.out.println("----------------------------"); System.out.println("----------------------------");
// Populate attributes. // Populate attributes.
data = new TagDataManager(); data = new TagDataManager();
data.setContent("lastname", "Spiderman"); data.setContent("lastname", "Spiderman");
data.appendAttribute("lastname", "style", "background: blue;"); data.appendAttribute("lastname", "style", "background: blue;");
data.appendAttribute("lastname", "style", "foreground: red;"); data.appendAttribute("lastname", "style", "foreground: red;");
data.setAttribute("lastname", "class", "nameClass"); data.setAttribute("lastname", "class", "nameClass");
String htmlSource = "<div id='lastname'>a last name</div >"; String htmlSource = "<div id='lastname'>a last name</div >";
StringBuffer htmlTarget; StringBuffer htmlTarget;
try try
{ {
htmlTarget = StringPresenter.dynamize(htmlSource, data); htmlTarget = PresenterUtils.dynamize(htmlSource, data);
} }
catch (Exception exception) catch (Exception exception)
{ {
System.out.println(exception.getMessage()); System.out.println(exception.getMessage());
htmlTarget = null; htmlTarget = null;
} }
System.out.println("datas = new Data ();"); System.out.println("datas = new Data ();");
System.out.println("datas.setContent (\"lastname\", \"Spiderman\");"); System.out.println("datas.setContent (\"lastname\", \"Spiderman\");");
System.out.println("datas.appendAttribute (\"lastname\", \"style\", \"background: blue;\");"); System.out.println("datas.appendAttribute (\"lastname\", \"style\", \"background: blue;\");");
System.out.println("datas.appendAttribute (\"lastname\", \"style\", \"foreground: red;\");"); System.out.println("datas.appendAttribute (\"lastname\", \"style\", \"foreground: red;\");");
System.out.println("datas.setAttribute (\"lastname\", \"class\", \"nameClass\");"); System.out.println("datas.setAttribute (\"lastname\", \"class\", \"nameClass\");");
System.out.println("+"); System.out.println("+");
System.out.println("<div id='lastname'>a last name</div>"); System.out.println("<div id='lastname'>a last name</div>");
System.out.println("=>"); System.out.println("=>");
System.out.println(htmlTarget); System.out.println(htmlTarget);
System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]"); System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]");
} }
// Step #03. // Step #03.
{ {
System.out.println("----------------------------"); System.out.println("----------------------------");
// Populate attributes. // Populate attributes.
data = new TagDataManager(); data = new TagDataManager();
data.setContent("words", 0, "alpha"); data.setContent("words", 0, "alpha");
data.setContent("words", 1, "bravo"); data.setContent("words", 1, "bravo");
data.setContent("words", 2, "charlie"); data.setContent("words", 2, "charlie");
data.setContent("words", 3, "delta"); data.setContent("words", 3, "delta");
data.setContent("words", 4, "echo"); data.setContent("words", 4, "echo");
data.setContent("words", 5, "fox"); data.setContent("words", 5, "fox");
String htmlSource = "<ul>\n <li id='words'>a word</li>\n</ul>"; String htmlSource = "<ul>\n <li id='words'>a word</li>\n</ul>";
StringBuffer htmlTarget; StringBuffer htmlTarget;
try try
{ {
htmlTarget = StringPresenter.dynamize(htmlSource, data); htmlTarget = PresenterUtils.dynamize(htmlSource, data);
} }
catch (Exception exception) catch (Exception exception)
{ {
System.out.println(exception.getMessage()); System.out.println(exception.getMessage());
htmlTarget = null; htmlTarget = null;
} }
System.out.println("datas = new Data ();"); System.out.println("datas = new Data ();");
System.out.println("datas.setContent (\"words\", 0, \"alpha\");"); System.out.println("datas.setContent (\"words\", 0, \"alpha\");");
System.out.println("datas.setContent (\"words\", 1, \"bravo\");"); System.out.println("datas.setContent (\"words\", 1, \"bravo\");");
System.out.println("datas.setContent (\"words\", 2, \"charlie\");"); System.out.println("datas.setContent (\"words\", 2, \"charlie\");");
System.out.println("datas.setContent (\"words\", 3, \"delta\");"); System.out.println("datas.setContent (\"words\", 3, \"delta\");");
System.out.println("datas.setContent (\"words\", 4, \"echo\");"); System.out.println("datas.setContent (\"words\", 4, \"echo\");");
System.out.println("datas.setContent (\"words\", 5, \"fox\");"); System.out.println("datas.setContent (\"words\", 5, \"fox\");");
System.out.println("+"); System.out.println("+");
System.out.println("<ul>"); System.out.println("<ul>");
System.out.println(" <li id='words'>a word</li>"); System.out.println(" <li id='words'>a word</li>");
System.out.println("</ul>"); System.out.println("</ul>");
System.out.println("=>"); System.out.println("=>");
System.out.println(htmlTarget); System.out.println(htmlTarget);
System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]"); System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]");
} }
// Step #04. // Step #04.
{ {
System.out.println("----------------------------"); System.out.println("----------------------------");
// Populate attributes. // Populate attributes.
data = new TagDataManager(); data = new TagDataManager();
data.setContent("identity", 0, "last_name", "Jemba"); data.setContent("identity", 0, "last_name", "Jemba");
data.setContent("identity", 0, "first_name", "Epo"); data.setContent("identity", 0, "first_name", "Epo");
data.setContent("identity", 1, "last_name", "Momon"); data.setContent("identity", 1, "last_name", "Momon");
data.setContent("identity", 1, "first_name", "Christian"); data.setContent("identity", 1, "first_name", "Christian");
data.setContent("identity", 2, "last_name", "Tronche"); data.setContent("identity", 2, "last_name", "Tronche");
data.setContent("identity", 2, "first_name", "Christophe"); data.setContent("identity", 2, "first_name", "Christophe");
StringBuffer source = new StringBuffer(); StringBuffer source = new StringBuffer();
source.append("<table>\n"); source.append("<table>\n");
source.append(" <tr id='identity'><td>noid</td><td id='first_name'>Jean</td><td id='last_name'>Reve</td></tr>\n"); source.append(" <tr id='identity'><td>noid</td><td id='first_name'>Jean</td><td id='last_name'>Reve</td></tr>\n");
source.append("</table>"); source.append("</table>");
String htmlSource = source.toString(); String htmlSource = source.toString();
StringBuffer htmlTarget; StringBuffer htmlTarget;
try try
{ {
htmlTarget = StringPresenter.dynamize(htmlSource, data); htmlTarget = PresenterUtils.dynamize(htmlSource, data);
} }
catch (Exception exception) catch (Exception exception)
{ {
System.out.println(exception.getMessage()); System.out.println(exception.getMessage());
htmlTarget = null; htmlTarget = null;
} }
System.out.println("datas = new Data ();"); System.out.println("datas = new Data ();");
System.out.println("datas.setContent (\"identity\", 0, \"last_name\", \"Jemba\");"); 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\", 0, \"first_name\", \"Epo\");");
System.out.println("datas.setContent (\"identity\", 1, \"last_name\", \"Momon\");"); 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\", 1, \"first_name\", \"Christian\");");
System.out.println("datas.setContent (\"identity\", 2, \"last_name\", \"Tronche\");"); System.out.println("datas.setContent (\"identity\", 2, \"last_name\", \"Tronche\");");
System.out.println("datas.setContent (\"identity\", 2, \"first_name\", \"Christophe\");"); System.out.println("datas.setContent (\"identity\", 2, \"first_name\", \"Christophe\");");
System.out.println("+"); System.out.println("+");
System.out.println(htmlSource); System.out.println(htmlSource);
System.out.println("=>"); System.out.println("=>");
System.out.println(htmlTarget); System.out.println(htmlTarget);
System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]"); System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]");
} }
// Step #05. // Step #05.
{ {
System.out.println("----------------------------"); System.out.println("----------------------------");
// Populate attributes. // Populate attributes.
data = new TagDataManager(); data = new TagDataManager();
data.setContent("identity", 0, "last_name", "Jemba"); data.setContent("identity", 0, "last_name", "Jemba");
data.setContent("identity", 0, "first_name", "Epo"); data.setContent("identity", 0, "first_name", "Epo");
data.setContent("identity", 1, "last_name", "Momon"); data.setContent("identity", 1, "last_name", "Momon");
data.setContent("identity", 1, "first_name", "Christian"); data.setContent("identity", 1, "first_name", "Christian");
data.setContent("identity", 2, "last_name", "Tronche"); data.setContent("identity", 2, "last_name", "Tronche");
data.setContent("identity", 2, "first_name", "Christophe"); data.setContent("identity", 2, "first_name", "Christophe");
// datas.setIterationStrategy ("identity", // datas.setIterationStrategy ("identity",
// IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID); // IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID);
// datas.setIterationStrategy ("identity", // datas.setIterationStrategy ("identity",
// IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID); // IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
// datas.setIterationStrategy ("identity", // datas.setIterationStrategy ("identity",
// IdsDataByIndex.IterationStrategy.ALL_ROWS); // IdsDataByIndex.IterationStrategy.ALL_ROWS);
// //
StringBuffer source = new StringBuffer(); StringBuffer source = new StringBuffer();
source.append("<table id=\"identities\">\n"); source.append("<table id=\"identities\">\n");
source.append(" <tr id='the_head'><th>noid</th><th>First Name</th><th>Last Name</th></tr>\n"); source.append(" <tr id='the_head'><th>noid</th><th>First Name</th><th>Last Name</th></tr>\n");
source.append(" <tr id='identity'><td>noid</td><td id='first_name'>Jean</td><td id='last_name'>Reve</td></tr>\n"); source.append(" <tr id='identity'><td>noid</td><td id='first_name'>Jean</td><td id='last_name'>Reve</td></tr>\n");
source.append(" <tr id='identity_bis'><td>noid</td><td id='first_name_bis'>a first name</td><td id='last_name_bis'>a last name</td></tr>\n"); source.append(" <tr id='identity_bis'><td>noid</td><td id='first_name_bis'>a first name</td><td id='last_name_bis'>a last name</td></tr>\n");
source.append(" <tr><td>noid</td><td id='first_name_ter'>a first name more</td><td id='last_name_ter'>a last name more</td></tr>\n"); source.append(" <tr><td>noid</td><td id='first_name_ter'>a first name more</td><td id='last_name_ter'>a last name more</td></tr>\n");
source.append("</table>\n"); source.append("</table>\n");
String htmlSource = source.toString(); String htmlSource = source.toString();
System.out.println("datas = new Data ();"); System.out.println("datas = new Data ();");
System.out.println("datas.setContent (\"identity\", 0, \"first_name\", \"Epo\");"); 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\", 0, \"last_name\", \"Jemba\");");
System.out.println("datas.setContent (\"identity\", 1, \"first_name\", \"Christian\");"); 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\", 1, \"last_name\", \"Momon\");");
System.out.println("datas.setContent (\"identity\", 2, \"first_name\", \"Christophe\");"); System.out.println("datas.setContent (\"identity\", 2, \"first_name\", \"Christophe\");");
System.out.println("datas.setContent (\"identity\", 2, \"last_name\", \"Tronche\");"); System.out.println("datas.setContent (\"identity\", 2, \"last_name\", \"Tronche\");");
System.out.println("+"); System.out.println("+");
System.out.println(htmlSource); System.out.println(htmlSource);
System.out.println("=>"); System.out.println("=>");
// #05.1 // #05.1
data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_FIRST_ROW); data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_FIRST_ROW);
System.out.println("ONLY_FIRST_ROW:"); System.out.println("ONLY_FIRST_ROW:");
StringBuffer html; StringBuffer html;
try try
{ {
html = StringPresenter.dynamize(htmlSource, data); html = PresenterUtils.dynamize(htmlSource, data);
} }
catch (Exception exception) catch (Exception exception)
{ {
System.out.println(exception.getMessage()); System.out.println(exception.getMessage());
html = null; html = null;
} }
System.out.println(html); System.out.println(html);
System.out.println(""); System.out.println("");
// #05.2 // #05.2
data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_FIRST_TWO_ROWS); data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_FIRST_TWO_ROWS);
System.out.println("ONLY_FIRST_TWO_ROWS:"); System.out.println("ONLY_FIRST_TWO_ROWS:");
try try
{ {
html = StringPresenter.dynamize(htmlSource, data); html = PresenterUtils.dynamize(htmlSource, data);
} }
catch (Exception exception) catch (Exception exception)
{ {
System.out.println(exception.getMessage()); System.out.println(exception.getMessage());
html = null; html = null;
} }
System.out.println(html); System.out.println(html);
System.out.println(""); System.out.println("");
// #05.3 // #05.3
data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_ROWS_WITH_ID); data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_ROWS_WITH_ID);
System.out.println("ONLY_ROWS_WITH_ID:"); System.out.println("ONLY_ROWS_WITH_ID:");
try try
{ {
html = StringPresenter.dynamize(htmlSource, data); html = PresenterUtils.dynamize(htmlSource, data);
} }
catch (Exception exception) catch (Exception exception)
{ {
System.out.println(exception.getMessage()); System.out.println(exception.getMessage());
html = null; html = null;
} }
System.out.println(html); System.out.println(html);
System.out.println(""); System.out.println("");
// #05.4 // #05.4
data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_ROWS_WITHOUT_ID); data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
System.out.println("ONLY_ROWS_WITHOUT_ID:"); System.out.println("ONLY_ROWS_WITHOUT_ID:");
try try
{ {
html = StringPresenter.dynamize(htmlSource, data); html = PresenterUtils.dynamize(htmlSource, data);
} }
catch (Exception exception) catch (Exception exception)
{ {
System.out.println(exception.getMessage()); System.out.println(exception.getMessage());
html = null; html = null;
} }
System.out.println(html); System.out.println(html);
System.out.println(""); System.out.println("");
// #05.5 // #05.5
data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ALL_ROWS); data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ALL_ROWS);
System.out.println("ALL_ROWS:"); System.out.println("ALL_ROWS:");
try try
{ {
html = StringPresenter.dynamize(htmlSource, data); html = PresenterUtils.dynamize(htmlSource, data);
} }
catch (Exception exception) catch (Exception exception)
{ {
System.out.println(exception.getMessage()); System.out.println(exception.getMessage());
html = null; html = null;
} }
System.out.println(html); System.out.println(html);
} }
} }
} }

View file

@ -24,41 +24,41 @@ package fr.devinsy.xidyn;
*/ */
public class XidynException extends Exception public class XidynException extends Exception
{ {
private static final long serialVersionUID = 8498031594322380559L; private static final long serialVersionUID = 8498031594322380559L;
/** /**
* *
*/ */
public XidynException() public XidynException()
{ {
super(); super();
} }
/** /**
* *
* @param message * @param message
*/ */
public XidynException(final String message) public XidynException(final String message)
{ {
super(message); super(message);
} }
/** /**
* *
* @param message * @param message
* @param cause * @param cause
*/ */
public XidynException(final String message, final Throwable cause) public XidynException(final String message, final Throwable cause)
{ {
super(message, cause); super(message, cause);
} }
/** /**
* *
* @param cause * @param cause
*/ */
public XidynException(final Throwable cause) public XidynException(final Throwable cause)
{ {
super(cause); super(cause);
} }
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2014 Christian Pierre MOMON * Copyright (C) 2006-2016 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -34,161 +34,167 @@ import java.io.Serializable;
*/ */
public class SimpleTagData implements Serializable, TagData public class SimpleTagData implements Serializable, TagData
{ {
public enum IterationStrategy public enum IterationStrategy
{ {
ONLY_FIRST_ROW, ONLY_FIRST_TWO_ROWS, ONLY_ROWS_WITH_ID, ONLY_ROWS_WITHOUT_ID, ALL_ROWS ONLY_FIRST_ROW,
} ONLY_FIRST_TWO_ROWS,
ONLY_ROWS_WITH_ID,
ONLY_ROWS_WITHOUT_ID,
ALL_ROWS
}
public enum MODE public enum MODE
{ {
REPLACE, APPEND, IGNORE REPLACE,
} APPEND,
IGNORE
}
private static final long serialVersionUID = 8976245034682639923L;; private static final long serialVersionUID = 8976245034682639923L;;
private IterationStrategy iterationStrategy; private IterationStrategy iterationStrategy;
private TagAttributes attributes; private TagAttributes attributes;
private boolean excludeSection; private boolean excludeSection;
private MODE displayMode = MODE.REPLACE; private MODE displayMode = MODE.REPLACE;
private String content; private String content;
/** /**
* *
*/ */
public SimpleTagData() public SimpleTagData()
{ {
this.attributes = null; this.attributes = null;
this.excludeSection = false; this.excludeSection = false;
this.displayMode = MODE.REPLACE; this.displayMode = MODE.REPLACE;
this.content = null; this.content = null;
this.iterationStrategy = IterationStrategy.ALL_ROWS; this.iterationStrategy = IterationStrategy.ALL_ROWS;
} }
/** /**
* *
*/ */
public SimpleTagData(final String text) public SimpleTagData(final String text)
{ {
this.attributes = null; this.attributes = null;
this.excludeSection = false; this.excludeSection = false;
this.displayMode = MODE.REPLACE; this.displayMode = MODE.REPLACE;
this.content = text; this.content = text;
this.iterationStrategy = IterationStrategy.ALL_ROWS; this.iterationStrategy = IterationStrategy.ALL_ROWS;
} }
/** /**
* *
*/ */
public void appendContent(final String text) public void appendContent(final String text)
{ {
if (this.content == null) if (this.content == null)
{ {
this.content = text; this.content = text;
} }
else else
{ {
this.content += text; this.content += text;
} }
} }
/** /**
* *
*/ */
public TagAttributes attributes() public TagAttributes attributes()
{ {
TagAttributes result; TagAttributes result;
if (this.attributes == null) if (this.attributes == null)
{ {
this.attributes = new TagAttributes(); this.attributes = new TagAttributes();
} }
result = this.attributes; result = this.attributes;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public String display() public String display()
{ {
String result; String result;
result = this.content; result = this.content;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public MODE displayMode() public MODE displayMode()
{ {
MODE result; MODE result;
result = this.displayMode; result = this.displayMode;
return (result); return (result);
} }
/** /**
* *
*/ */
public boolean excludeSection() public boolean excludeSection()
{ {
boolean result; boolean result;
result = this.excludeSection; result = this.excludeSection;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public IterationStrategy iterationStrategy() public IterationStrategy iterationStrategy()
{ {
IterationStrategy result; IterationStrategy result;
result = this.iterationStrategy; result = this.iterationStrategy;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public void setContent(final String text) public void setContent(final String text)
{ {
this.content = text; this.content = text;
} }
/** /**
* *
*/ */
public void setDisplayMode(final MODE displayMode) public void setDisplayMode(final MODE displayMode)
{ {
this.displayMode = displayMode; this.displayMode = displayMode;
} }
/** /**
* *
*/ */
public void setExcludeSection(final boolean excludeSection) public void setExcludeSection(final boolean excludeSection)
{ {
this.excludeSection = excludeSection; this.excludeSection = excludeSection;
} }
/** /**
* *
*/ */
public void setIterationStrategy(final IterationStrategy strategy) public void setIterationStrategy(final IterationStrategy strategy)
{ {
this.iterationStrategy = strategy; this.iterationStrategy = strategy;
} }
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2014 Christian Pierre MOMON * Copyright (C) 2006-2016 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -27,67 +27,67 @@ import java.util.HashMap;
*/ */
public class TagAttributes extends HashMap<String, String> public class TagAttributes extends HashMap<String, String>
{ {
private static final long serialVersionUID = 2802739066295665336L; private static final long serialVersionUID = 2802739066295665336L;
/** /**
* *
*/ */
public TagAttributes() public TagAttributes()
{ {
super(); super();
} }
/** /**
* Useful for the merge attributes. * Useful for the merge attributes.
*/ */
public TagAttributes(final TagAttributes attributes) public TagAttributes(final TagAttributes attributes)
{ {
super(attributes); super(attributes);
} }
/** /**
* Add a value to an existing value. This is useful to the 'style' * Add a value to an existing value. This is useful to the 'style'
* attribute. * 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 void appendAttribute(final String label, final String value) public String getAttribute(final String label)
{ {
if (this.containsKey(label)) String result;
{
this.put(label, this.get(label) + value);
}
else
{
this.put(label, value);
}
}
/** if (this.containsKey(label))
{
result = this.get(label);
}
else
{
result = null;
}
//
return (result);
}
/**
* *
*/ */
public String getAttribute(final String label) public void setAttribute(final String label, final String value)
{ {
String result; this.put(label, value);
}
if (this.containsKey(label))
{
result = this.get(label);
}
else
{
result = null;
}
//
return (result);
}
/**
*
*/
public void setAttribute(final String label, final String value)
{
this.put(label, value);
}
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2014 Christian Pierre MOMON * Copyright (C) 2006-2016 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2014 Christian Pierre MOMON * Copyright (C) 2006-2016 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -26,35 +26,35 @@ import java.util.HashMap;
public class TagDataListById extends HashMap<String, TagData> implements TagData public class TagDataListById extends HashMap<String, TagData> implements TagData
{ {
private static final long serialVersionUID = -5787252043825503554L; private static final long serialVersionUID = -5787252043825503554L;
/** /**
* *
*/ */
public TagDataListById() public TagDataListById()
{ {
super(); super();
} }
/** /**
* *
*/ */
public TagData getId(final String id) public TagData getId(final String id)
{ {
TagData result; TagData result;
result = this.get(id); result = this.get(id);
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public void setId(final String id, final TagData data) public void setId(final String id, final TagData data)
{ {
this.put(id, data); this.put(id, data);
} }
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2014 Christian Pierre MOMON * Copyright (C) 2006-2016 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -26,13 +26,13 @@ import java.util.Vector;
public class TagDataListByIndex extends Vector<TagData> implements TagData public class TagDataListByIndex extends Vector<TagData> implements TagData
{ {
private static final long serialVersionUID = 215545720925753884L; private static final long serialVersionUID = 215545720925753884L;
/** /**
* *
*/ */
public TagDataListByIndex() public TagDataListByIndex()
{ {
super(); super();
} }
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2014 Christian Pierre MOMON * Copyright (C) 2006-2016 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -23,308 +23,308 @@ package fr.devinsy.xidyn.data;
*/ */
public class TagDataManager public class TagDataManager
{ {
private TagDataListById idsDataById; private TagDataListById idsDataById;
/** /**
* *
*/ */
public TagDataManager() public TagDataManager()
{ {
this.idsDataById = new TagDataListById(); this.idsDataById = new TagDataListById();
} }
/** /**
* *
*/ */
public void appendAttribute(final String id, final int line, final String column, final String label, final String value) 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); 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) public void appendAttribute(final String id, final String label, final long value)
{ {
appendAttribute(id, label, String.valueOf(value)); appendAttribute(id, label, String.valueOf(value));
} }
/** /**
* *
*/ */
public void appendAttribute(final String id, final String label, final String value) public void appendAttribute(final String id, final String label, final String value)
{ {
SimpleTagData tag = this.getIdData(id); 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) public void appendContent(final String id, final int line, final long value)
{ {
appendContent(id, line, String.valueOf(value)); appendContent(id, line, String.valueOf(value));
} }
/** /**
* *
*/ */
public void appendContent(final String id, final int line, final String value) public void appendContent(final String id, final int line, final String value)
{ {
SimpleTagData tag = this.getIdData(id, line); 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) public void appendContent(final String id, final int line, final String column, final long value)
{ {
appendContent(id, line, column, String.valueOf(value)); appendContent(id, line, column, String.valueOf(value));
} }
/** /**
* *
*/ */
public void appendContent(final String id, final int line, final String column, final String value) public void appendContent(final String id, final int line, final String column, final String value)
{ {
SimpleTagData tag = this.getIdData(id, line, column); SimpleTagData tag = this.getIdData(id, line, column);
tag.appendContent(value); tag.appendContent(value);
} }
/** /**
* *
*/ */
public SimpleTagData getIdData(final String id) public SimpleTagData getIdData(final String id)
{ {
SimpleTagData result; SimpleTagData result;
// Be sure that IdData is existing and get item. // Be sure that IdData is existing and get item.
result = (SimpleTagData) this.idsDataById.getId(id); result = (SimpleTagData) this.idsDataById.getId(id);
if (result == null) if (result == null)
{ {
this.idsDataById.setId(id, new SimpleTagData()); 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) public SimpleTagData getIdData(final String id, final int line)
{ {
SimpleTagData result; SimpleTagData result;
// Be sure that IdsData are existing. // Be sure that IdsData are existing.
TagDataListByIndex tags = (TagDataListByIndex) this.idsDataById.getId(id); TagDataListByIndex tags = (TagDataListByIndex) this.idsDataById.getId(id);
if (tags == null) if (tags == null)
{ {
this.idsDataById.setId(id, new TagDataListByIndex()); this.idsDataById.setId(id, new TagDataListByIndex());
tags = (TagDataListByIndex) this.idsDataById.getId(id); tags = (TagDataListByIndex) this.idsDataById.getId(id);
} }
// Be sure that lines are existing. // Be sure that lines are existing.
int nbLines = tags.size(); int nbLines = tags.size();
for (int nLine = nbLines; nLine < line + 1; nLine++) for (int nLine = nbLines; nLine < line + 1; nLine++)
{ {
tags.add(nLine, new SimpleTagData()); tags.add(nLine, new SimpleTagData());
} }
// Get item. // Get item.
result = (SimpleTagData) tags.elementAt(line); result = (SimpleTagData) tags.elementAt(line);
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public SimpleTagData getIdData(final String id, final int line, final String column) public SimpleTagData getIdData(final String id, final int line, final String column)
{ {
SimpleTagData result; SimpleTagData result;
// Be sure that IdsData are existing. // Be sure that IdsData are existing.
TagDataListByIndex tags = (TagDataListByIndex) this.idsDataById.getId(id); TagDataListByIndex tags = (TagDataListByIndex) this.idsDataById.getId(id);
if (tags == null) if (tags == null)
{ {
this.idsDataById.setId(id, new TagDataListByIndex()); this.idsDataById.setId(id, new TagDataListByIndex());
tags = (TagDataListByIndex) this.idsDataById.getId(id); tags = (TagDataListByIndex) this.idsDataById.getId(id);
} }
// Be sure that lines are existing. // Be sure that lines are existing.
int nbLines = tags.size(); int nbLines = tags.size();
for (int nLine = nbLines; nLine < line + 1; nLine++) for (int nLine = nbLines; nLine < line + 1; nLine++)
{ {
tags.add(nLine, new TagDataListById()); tags.add(nLine, new TagDataListById());
} }
// Get item. // Get item.
TagDataListById lineData = (TagDataListById) tags.elementAt(line); TagDataListById lineData = (TagDataListById) tags.elementAt(line);
result = (SimpleTagData) lineData.get(column); result = (SimpleTagData) lineData.get(column);
if (result == null) if (result == null)
{ {
lineData.put(column, new SimpleTagData()); lineData.put(column, new SimpleTagData());
result = (SimpleTagData) lineData.get(column); result = (SimpleTagData) lineData.get(column);
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public TagDataListById getIdsDataById() public TagDataListById getIdsDataById()
{ {
TagDataListById result; 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) public void setAttribute(final String id, final int line, final String label, final long value)
{ {
setAttribute(id, line, label, String.valueOf(value)); setAttribute(id, line, label, String.valueOf(value));
} }
/** /**
* *
*/ */
public void setAttribute(final String id, final int line, final String label, final String value) public void setAttribute(final String id, final int line, final String label, final String value)
{ {
SimpleTagData tag = this.getIdData(id, line); 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) 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)); 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) 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); 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) public void setAttribute(final String id, final String label, final long value)
{ {
setAttribute(id, label, String.valueOf(value)); setAttribute(id, label, String.valueOf(value));
} }
/** /**
* *
*/ */
public void setAttribute(final String id, final String label, final String value) public void setAttribute(final String id, final String label, final String value)
{ {
SimpleTagData tag = this.getIdData(id); 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) public void setContent(final String id, final int line, final long value)
{ {
setContent(id, line, String.valueOf(value)); setContent(id, line, String.valueOf(value));
} }
/** /**
* *
*/ */
public void setContent(final String id, final int line, final String content) public void setContent(final String id, final int line, final String content)
{ {
SimpleTagData tag = this.getIdData(id, line); SimpleTagData tag = this.getIdData(id, line);
tag.setContent(content); tag.setContent(content);
} }
/** /**
* @TODO * @TODO
*/ */
public void setContent(final String id, final int line, final String subId, final int subLine, final String column, final String content) public void setContent(final String id, final int line, final String subId, final int subLine, final String column, final String content)
{ {
// IdData tag = this.getIdData (id, line, subId, subLine, column); // 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) public void setContent(final String id, final int line, final String column, final long value)
{ {
setContent(id, line, column, String.valueOf(value)); setContent(id, line, column, String.valueOf(value));
} }
/** /**
* *
*/ */
public void setContent(final String id, final int line, final String column, final String content) public void setContent(final String id, final int line, final String column, final String content)
{ {
SimpleTagData tag = this.getIdData(id, line, column); SimpleTagData tag = this.getIdData(id, line, column);
tag.setContent(content); tag.setContent(content);
} }
/** /**
* *
*/ */
public void setContent(final String id, final long value) public void setContent(final String id, final long value)
{ {
setContent(id, String.valueOf(value)); setContent(id, String.valueOf(value));
} }
/** /**
* *
*/ */
public void setContent(final String id, final String content) public void setContent(final String id, final String content)
{ {
SimpleTagData idData = this.getIdData(id); SimpleTagData idData = this.getIdData(id);
idData.setContent(content); idData.setContent(content);
} }
/** /**
* *
*/ */
public void setIterationStrategy(final String id, final SimpleTagData.IterationStrategy strategy) public void setIterationStrategy(final String id, final SimpleTagData.IterationStrategy strategy)
{ {
SimpleTagData tag = this.getIdData(id); SimpleTagData tag = this.getIdData(id);
tag.setIterationStrategy(strategy); tag.setIterationStrategy(strategy);
} }
} }

View file

@ -26,82 +26,82 @@ import fr.devinsy.xidyn.presenters.Presenter;
*/ */
public class Page extends TagDataManager public class Page extends TagDataManager
{ {
private Presenter presenter; private Presenter presenter;
private StringBuffer lastDynamize; private StringBuffer lastDynamize;
/** /**
* *
*/ */
public Page(final Presenter presenter) public Page(final Presenter presenter)
{ {
super(); super();
if (presenter == null) if (presenter == null)
{ {
throw new IllegalArgumentException("Null parameter."); throw new IllegalArgumentException("Null parameter.");
} }
else else
{ {
this.presenter = presenter; this.presenter = presenter;
this.lastDynamize = null; this.lastDynamize = null;
} }
} }
/** /**
* *
* @return * @return
* @throws Exception * @throws Exception
*/ */
public StringBuffer dynamize() throws Exception public StringBuffer dynamize() throws Exception
{ {
StringBuffer result; 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 * @return
*/ */
public boolean isComplete() public boolean isComplete()
{ {
boolean result; boolean result;
if (this.lastDynamize == null) if (this.lastDynamize == null)
{ {
result = false; result = false;
} }
else else
{ {
result = true; result = true;
} }
// //
return result; return result;
} }
/** /**
* @throws Exception * @throws Exception
*/ */
public StringBuffer lastVersion() throws Exception public StringBuffer lastVersion() throws Exception
{ {
StringBuffer result; StringBuffer result;
if ((this.lastDynamize == null) || (this.presenter.isOutdated())) if ((this.lastDynamize == null) || (this.presenter.isOutdated()))
{ {
dynamize(); dynamize();
} }
result = this.lastDynamize; result = this.lastDynamize;
// //
return result; return result;
} }
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -33,214 +33,214 @@ import fr.devinsy.xidyn.utils.cache.Cache;
*/ */
public class PageFactory public class PageFactory
{ {
/** /**
* http://thecodersbreakfast.net/index.php?post/2008/02/25/26-de-la-bonne- * http://thecodersbreakfast.net/index.php?post/2008/02/25/26-de-la-bonne-
* implementation-du-singleton-en-java * implementation-du-singleton-en-java
*
*/
private static class SingletonHolder
{
private final static PageFactory INSTANCE = new PageFactory();
}
private Cache<Page> cache;
/**
* *
*/ */
private static class SingletonHolder private PageFactory()
{ {
private final static PageFactory INSTANCE = new PageFactory(); this.cache = new Cache<Page>();
} }
private Cache<Page> cache; /**
/**
* *
*/ */
private PageFactory() public void clear()
{ {
this.cache = new Cache<Page>(); this.cache.clear();
} PresenterFactory.instance().clear();
}
/** /**
* *
* @param source * @param source
* @param parameters * @param parameters
* @return * @return
*/ */
public Page get(final Document source) public Page get(final Document source)
{ {
Page result; Page result;
result = new Page(PresenterFactory.instance().get(source)); result = new Page(PresenterFactory.instance().get(source));
// //
return result; return result;
} }
/** /**
* *
* @param source * @param source
* @param parameters * @param parameters
* @return * @return
* @throws Exception * @throws Exception
*/ */
public Page get(final Document source, final String... keys) public Page get(final Document source, final String... keys)
{ {
Page result; Page result;
String key = StringListUtils.toStringSeparatedBy(keys, "-").toString(); String key = StringListUtils.toStringSeparatedBy(keys, "-").toString();
result = this.cache.get(key); result = this.cache.get(key);
if (result == null) if (result == null)
{ {
result = get(source); result = get(source);
this.cache.put(key, result); this.cache.put(key, result);
} }
// //
return result; return result;
} }
/** /**
* *
* @param source * @param source
* @param parameters * @param parameters
* @return * @return
*/ */
public Page get(final File source) public Page get(final File source)
{ {
Page result; Page result;
result = new Page(PresenterFactory.instance().get(source)); result = new Page(PresenterFactory.instance().get(source));
// //
return result; return result;
} }
/** /**
* *
* @param source * @param source
* @param parameters * @param parameters
* @return * @return
*/ */
public Page get(final File source, final String... keys) public Page get(final File source, final String... keys)
{ {
Page result; Page result;
String key = StringListUtils.toStringSeparatedBy(keys, "-").toString(); String key = StringListUtils.toStringSeparatedBy(keys, "-").toString();
result = this.cache.get(key); result = this.cache.get(key);
if (result == null) if (result == null)
{ {
result = get(source); result = get(source);
this.cache.put(key, result); this.cache.put(key, result);
} }
// //
return result; return result;
} }
/** /**
* *
* @param source * @param source
* @param parameters * @param parameters
* @return * @return
*/ */
public Page get(final String source) public Page get(final String source)
{ {
Page result; Page result;
result = new Page(PresenterFactory.instance().get(source)); result = new Page(PresenterFactory.instance().get(source));
// //
return result; return result;
} }
/** /**
* *
* @param source * @param source
* @param parameters * @param parameters
* @return * @return
*/ */
public Page get(final String source, final String... keys) public Page get(final String source, final String... keys)
{ {
Page result; Page result;
String key = StringListUtils.toStringSeparatedBy(keys, "-").toString(); String key = StringListUtils.toStringSeparatedBy(keys, "-").toString();
result = this.cache.get(key); result = this.cache.get(key);
if (result == null) if (result == null)
{ {
result = get(source); result = get(source);
this.cache.put(key, result); this.cache.put(key, result);
} }
// //
return result; return result;
} }
/** /**
* *
* @param source * @param source
* @param parameters * @param parameters
* @return * @return
*/ */
public Page get(final URL source) public Page get(final URL source)
{ {
Page result; Page result;
result = new Page(PresenterFactory.instance().get(source)); result = new Page(PresenterFactory.instance().get(source));
// //
return result; return result;
} }
/** /**
* *
* @param source * @param source
* @param parameters * @param parameters
* @return * @return
*/ */
public Page get(final URL source, final String... keys) public Page get(final URL source, final String... keys)
{ {
Page result; Page result;
String key = StringListUtils.toStringSeparatedBy(keys, "-").toString(); String key = StringListUtils.toStringSeparatedBy(keys, "-").toString();
result = this.cache.get(key); result = this.cache.get(key);
if (result == null) if (result == null)
{ {
result = get(source); result = get(source);
this.cache.put(key, result); this.cache.put(key, result);
} }
// //
return result; return result;
} }
/** /**
* *
*/ * @return
public void clear() */
{ public int size()
this.cache.clear(); {
PresenterFactory.instance().clear(); int result;
}
/** result = this.cache.size();
*
* @return
*/
public int size()
{
int result;
result = this.cache.size(); //
return result;
}
// /**
return result; *
} * @return
*/
/** public static PageFactory instance()
* {
* @return return SingletonHolder.INSTANCE;
*/ }
public static PageFactory instance()
{
return SingletonHolder.INSTANCE;
}
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -32,168 +32,168 @@ import fr.devinsy.xidyn.utils.XidynUtils;
*/ */
public class DomPresenter implements Presenter public class DomPresenter implements Presenter
{ {
private static Logger logger = LoggerFactory.getLogger(DomPresenter.class); private static Logger logger = LoggerFactory.getLogger(DomPresenter.class);
private Document dom; private Document dom;
private boolean isOutdated; private boolean isOutdated;
private StringBuffer defaultHtmlTarget; private StringBuffer defaultHtmlTarget;
/** /**
* *
*/ */
public DomPresenter() public DomPresenter()
{ {
this.dom = null; this.dom = null;
this.isOutdated = false; this.isOutdated = false;
} }
/** /**
* *
*/ */
public DomPresenter(final Document doc) public DomPresenter(final Document doc)
{ {
setSource(doc); setSource(doc);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public StringBuffer dynamize() throws Exception public StringBuffer dynamize() throws Exception
{ {
StringBuffer result; StringBuffer result;
if ((this.isOutdated) || (this.defaultHtmlTarget == null)) if ((this.isOutdated) || (this.defaultHtmlTarget == null))
{ {
this.defaultHtmlTarget = dynamize(null); this.defaultHtmlTarget = dynamize(null);
this.isOutdated = false; this.isOutdated = false;
} }
result = this.defaultHtmlTarget; result = this.defaultHtmlTarget;
// //
return result; return result;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public StringBuffer dynamize(final TagDataManager data) throws Exception public StringBuffer dynamize(final TagDataManager data) throws Exception
{ {
StringBuffer result; StringBuffer result;
if (data == null) if (data == null)
{ {
result = dynamize(new TagDataManager()); result = dynamize(new TagDataManager());
} }
else if (this.dom == null) else if (this.dom == null)
{ {
String errorMessage = "source not defined"; String errorMessage = "source not defined";
logger.error(errorMessage); logger.error(errorMessage);
result = null; result = null;
throw new Exception(errorMessage); throw new Exception(errorMessage);
} }
else else
{ {
// Build the web page. // Build the web page.
StringWriter writer = new StringWriter(20000); StringWriter writer = new StringWriter(20000);
DomPresenterCore.dynamize(writer, this.dom, data); DomPresenterCore.dynamize(writer, this.dom, data);
result = writer.getBuffer(); result = writer.getBuffer();
this.isOutdated = false; this.isOutdated = false;
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public Document getDOM() public Document getDOM()
{ {
Document result; Document result;
result = this.dom; result = this.dom;
// //
return (result); return (result);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Object getSource() public Object getSource()
{ {
Object result; Object result;
result = this.dom; result = this.dom;
// //
return (result); return (result);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean isAvailable() public boolean isAvailable()
{ {
boolean result; boolean result;
if (this.dom == null) if (this.dom == null)
{ {
result = false; result = false;
} }
else else
{ {
result = true; result = true;
} }
// //
return result; return result;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean isOutdated() throws Exception public boolean isOutdated() throws Exception
{ {
boolean result; boolean result;
result = this.isOutdated; result = this.isOutdated;
// //
return result; return result;
} }
/** /**
* *
*/ */
public void setDOM(final Document doc) public void setDOM(final Document doc)
{ {
this.dom = doc; this.dom = doc;
this.isOutdated = true; this.isOutdated = true;
} }
/** /**
* *
*/ */
public void setSource(final Document doc) public void setSource(final Document doc)
{ {
this.dom = doc; this.dom = doc;
XidynUtils.addMetaTag(this.dom, "generator", "XIDYN"); XidynUtils.addMetaTag(this.dom, "generator", "XIDYN");
this.isOutdated = true; this.isOutdated = true;
} }
/** /**
* *
* @throws Exception * @throws Exception
*/ */
@Override @Override
public void update() throws Exception public void update() throws Exception
{ {
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -33,233 +33,233 @@ import fr.devinsy.xidyn.utils.XidynUtils;
*/ */
public class FilePresenter extends StringPresenter 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 File source;
private String sourceFilePathname; private String sourceFilePathname;
private long sourceTime; private long sourceTime;
/** /**
* *
*/ */
public FilePresenter() public FilePresenter()
{ {
setSource((String) null); setSource((String) null);
} }
/** /**
* *
*/ */
public FilePresenter(final File source) public FilePresenter(final File source)
{ {
setSource(source); setSource(source);
} }
/** /**
* *
*/ */
public FilePresenter(final String filePathname) public FilePresenter(final String filePathname)
{ {
setSource(filePathname); setSource(filePathname);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public StringBuffer dynamize() throws Exception public StringBuffer dynamize() throws Exception
{ {
StringBuffer result; StringBuffer result;
// //
update(); update();
// //
result = super.dynamize(); result = super.dynamize();
// //
return result; return result;
} }
/** /**
* No need to be synchronized. * No need to be synchronized.
* *
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public StringBuffer dynamize(final TagDataManager data) throws Exception public StringBuffer dynamize(final TagDataManager data) throws Exception
{ {
StringBuffer result; StringBuffer result;
logger.info("dynamize file [" + this.sourceFilePathname + "]"); logger.info("dynamize file [" + this.sourceFilePathname + "]");
// //
update(); update();
// Build the web page. // Build the web page.
result = super.dynamize(data); result = super.dynamize(data);
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public File getFile() public File getFile()
{ {
File result; File result;
result = this.source; result = this.source;
// //
return (result); return (result);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public String getSource() public String getSource()
{ {
String result; String result;
result = this.sourceFilePathname; result = this.sourceFilePathname;
// //
return (result); return (result);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean isAvailable() public boolean isAvailable()
{ {
boolean result; boolean result;
if ((this.source == null) || (!this.source.exists())) if ((this.source == null) || (!this.source.exists()))
{ {
result = false; result = false;
} }
else else
{ {
result = true; result = true;
} }
// //
return result; return result;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean isOutdated() throws Exception public boolean isOutdated() throws Exception
{ {
boolean result; boolean result;
// //
if (super.isOutdated()) if (super.isOutdated())
{ {
result = true; result = true;
} }
else if (this.sourceTime == this.source.lastModified()) else if (this.sourceTime == this.source.lastModified())
{ {
result = true; result = true;
} }
else else
{ {
result = false; result = false;
} }
// //
return result; return result;
} }
/** /**
* *
*/ */
public void setSource(final File source) public void setSource(final File source)
{ {
if (source == null) if (source == null)
{ {
super.setSource(null); super.setSource(null);
this.source = null; this.source = null;
this.sourceFilePathname = null; this.sourceFilePathname = null;
this.sourceTime = 0; this.sourceTime = 0;
setSource((String) null); setSource((String) null);
} }
else else
{ {
this.source = source; this.source = source;
this.sourceFilePathname = source.getAbsolutePath(); this.sourceFilePathname = source.getAbsolutePath();
this.sourceTime = 0; this.sourceTime = 0;
super.setSource(null); super.setSource(null);
} }
} }
/** /**
* @throws Exception * @throws Exception
* *
*/ */
@Override @Override
public void setSource(final String source) public void setSource(final String source)
{ {
// //
File file; File file;
if (source == null) if (source == null)
{ {
file = null; file = null;
} }
else if (source.matches("file://.+")) else if (source.matches("file://.+"))
{ {
try try
{ {
file = new File(new URI(source)); file = new File(new URI(source));
} }
catch (URISyntaxException exception) catch (URISyntaxException exception)
{ {
exception.printStackTrace(); exception.printStackTrace();
throw new IllegalArgumentException("Bad URI argument.", exception); throw new IllegalArgumentException("Bad URI argument.", exception);
} }
} }
else else
{ {
file = new File(source); file = new File(source);
} }
// //
setSource(file); setSource(file);
} }
/** /**
* @throws Exception * @throws Exception
*/ */
@Override @Override
public void update() throws Exception public void update() throws Exception
{ {
// //
if (this.source == null) if (this.source == null)
{ {
String errorMessage = "source not defined"; String errorMessage = "source not defined";
logger.error(errorMessage); logger.error(errorMessage);
throw new NullPointerException(errorMessage); throw new NullPointerException(errorMessage);
} }
else if (!this.source.exists()) else if (!this.source.exists())
{ {
String errorMessage = "source file defined but not found (" + this.sourceFilePathname + ")"; String errorMessage = "source file defined but not found (" + this.sourceFilePathname + ")";
logger.error(errorMessage); logger.error(errorMessage);
throw new Exception(errorMessage); throw new Exception(errorMessage);
} }
else else
{ {
long currentTime = this.source.lastModified(); long currentTime = this.source.lastModified();
if ((super.getSource() == null) || (this.sourceTime != currentTime)) if ((super.getSource() == null) || (this.sourceTime != currentTime))
{ {
super.setSource(XidynUtils.load(this.source)); super.setSource(XidynUtils.load(this.source));
this.sourceTime = currentTime; this.sourceTime = currentTime;
} }
} }
} }
} }

View file

@ -28,163 +28,163 @@ import org.slf4j.LoggerFactory;
*/ */
public class FilePresenters extends Vector<FilePresenter> public class FilePresenters extends Vector<FilePresenter>
{ {
private static final long serialVersionUID = 7058868685681354293L; private static final long serialVersionUID = 7058868685681354293L;
private static Logger logger = LoggerFactory.getLogger(FilePresenters.class); private static Logger logger = LoggerFactory.getLogger(FilePresenters.class);
/** /**
* *
*/ */
public FilePresenters() public FilePresenters()
{ {
super(); super();
} }
/** /**
* *
*/ */
public FilePresenters(final FilePresenters source) public FilePresenters(final FilePresenters source)
{ {
super(); super();
for (FilePresenter presenter : source) for (FilePresenter presenter : source)
{ {
this.add(presenter); this.add(presenter);
} }
} }
/** /**
* *
*/ */
public boolean exists(final String source) public boolean exists(final String source)
{ {
boolean result; boolean result;
if (this.getBySource(source) == null) if (this.getBySource(source) == null)
{ {
result = false; result = false;
} }
else else
{ {
result = true; result = true;
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public FilePresenter getByIndex(final int id) public FilePresenter getByIndex(final int id)
{ {
FilePresenter result; FilePresenter result;
result = this.get(id); result = this.get(id);
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public FilePresenter getBySource(final String source) public FilePresenter getBySource(final String source)
{ {
FilePresenter result; FilePresenter result;
if (source == null) if (source == null)
{ {
result = null; result = null;
} }
else else
{ {
result = null; result = null;
boolean ended = false; boolean ended = false;
int presenterIndex = 0; int presenterIndex = 0;
while (!ended) while (!ended)
{ {
if (presenterIndex < this.size()) if (presenterIndex < this.size())
{ {
FilePresenter presenter = this.get(presenterIndex); FilePresenter presenter = this.get(presenterIndex);
if (presenter.getSource().equals(source)) if (presenter.getSource().equals(source))
{ {
result = presenter; result = presenter;
ended = true; ended = true;
} }
else else
{ {
presenterIndex += 1; presenterIndex += 1;
} }
} }
else else
{ {
ended = true; ended = true;
result = null; result = null;
} }
} }
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public int getIndexOf(final String source) public int getIndexOf(final String source)
{ {
int result; int result;
if (source == null) if (source == null)
{ {
result = -1; result = -1;
} }
else else
{ {
result = -1; result = -1;
boolean ended = false; boolean ended = false;
int presenterIndex = 0; int presenterIndex = 0;
while (!ended) while (!ended)
{ {
if (presenterIndex < this.size()) if (presenterIndex < this.size())
{ {
FilePresenter presenter = this.get(presenterIndex); FilePresenter presenter = this.get(presenterIndex);
if (presenter.getSource().equals(source)) if (presenter.getSource().equals(source))
{ {
result = presenterIndex; result = presenterIndex;
ended = true; ended = true;
} }
else else
{ {
presenterIndex += 1; presenterIndex += 1;
} }
} }
else else
{ {
ended = true; ended = true;
result = -1; result = -1;
} }
} }
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
@Override @Override
public String toString() public String toString()
{ {
String result; String result;
result = ""; result = "";
// //
return (result); return (result);
} }
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -26,61 +26,61 @@ import org.slf4j.LoggerFactory;
*/ */
public class FilePresentersProxy 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 static FilePresentersProxy instance = null;
private FilePresenters presenters = null; private FilePresenters presenters = null;
/** /**
* *
*/ */
protected FilePresentersProxy() throws Exception protected FilePresentersProxy() throws Exception
{ {
this.presenters = new FilePresenters(); this.presenters = new FilePresenters();
} }
/** /**
* *
*/ */
public FilePresenter getBySource(final String source) throws Exception public FilePresenter getBySource(final String source) throws Exception
{ {
FilePresenter result; FilePresenter result;
if (source == null) if (source == null)
{ {
result = null; result = null;
} }
else else
{ {
result = this.presenters.getBySource(source); result = this.presenters.getBySource(source);
if (result == null) if (result == null)
{ {
result = new FilePresenter(source); result = new FilePresenter(source);
this.presenters.add(result); this.presenters.add(result);
} }
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public static FilePresentersProxy instance() throws Exception public static FilePresentersProxy instance() throws Exception
{ {
FilePresentersProxy result; FilePresentersProxy result;
if (FilePresentersProxy.instance == null) if (FilePresentersProxy.instance == null)
{ {
instance = new FilePresentersProxy(); instance = new FilePresentersProxy();
} }
result = instance; result = instance;
// //
return (result); return (result);
} }
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -30,226 +30,226 @@ import fr.devinsy.xidyn.data.TagDataManager;
*/ */
public class GenericPresenter implements Presenter 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) public GenericPresenter(final Document source)
{ {
if (source == null) if (source == null)
{ {
throw new NullPointerException("source is null"); throw new NullPointerException("source is null");
} }
else else
{ {
this.presenter = PresenterFactory.create(source); this.presenter = PresenterFactory.create(source);
} }
} }
/** /**
* *
*/ */
public GenericPresenter(final File source) public GenericPresenter(final File source)
{ {
if (source == null) if (source == null)
{ {
throw new NullPointerException("source is null"); throw new NullPointerException("source is null");
} }
else else
{ {
this.presenter = PresenterFactory.create(source); this.presenter = PresenterFactory.create(source);
} }
} }
/** /**
* *
*/ */
public GenericPresenter(final String source) public GenericPresenter(final String source)
{ {
if (source == null) if (source == null)
{ {
throw new NullPointerException("source is null"); throw new NullPointerException("source is null");
} }
else else
{ {
this.presenter = PresenterFactory.create(source); this.presenter = PresenterFactory.create(source);
} }
} }
/** /**
* *
*/ */
public GenericPresenter(final URL source) public GenericPresenter(final URL source)
{ {
if (source == null) if (source == null)
{ {
throw new NullPointerException("source is null"); throw new NullPointerException("source is null");
} }
else else
{ {
this.presenter = PresenterFactory.create(source); this.presenter = PresenterFactory.create(source);
} }
} }
/** /**
* *
*/ */
@Override @Override
public StringBuffer dynamize() throws Exception public StringBuffer dynamize() throws Exception
{ {
StringBuffer result; StringBuffer result;
result = this.presenter.dynamize(); result = this.presenter.dynamize();
// //
return result; return result;
} }
/** /**
* *
*/ */
@Override @Override
public StringBuffer dynamize(final TagDataManager datas) throws Exception public StringBuffer dynamize(final TagDataManager datas) throws Exception
{ {
StringBuffer result; StringBuffer result;
result = this.presenter.dynamize(datas); result = this.presenter.dynamize(datas);
// //
return result; return result;
} }
/** /**
* *
*/ */
@Override @Override
public Object getSource() public Object getSource()
{ {
Object result; Object result;
result = this.presenter.getSource(); result = this.presenter.getSource();
// //
return result; return result;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean isAvailable() public boolean isAvailable()
{ {
boolean result; boolean result;
result = this.presenter.isAvailable(); result = this.presenter.isAvailable();
// //
return result; return result;
} }
/** /**
* *
*/ */
@Override @Override
public boolean isOutdated() throws Exception public boolean isOutdated() throws Exception
{ {
boolean result; boolean result;
result = this.presenter.isOutdated(); result = this.presenter.isOutdated();
// //
return result; return result;
} }
/** /**
* *
* @param source * @param source
*/ */
public void setSource(final Document source) public void setSource(final Document source)
{ {
if (source == null) if (source == null)
{ {
throw new NullPointerException("source is null"); throw new NullPointerException("source is null");
} }
else else
{ {
this.presenter = PresenterFactory.create(source); this.presenter = PresenterFactory.create(source);
} }
} }
/** /**
* *
* @param source * @param source
*/ */
public void setSource(final File source) public void setSource(final File source)
{ {
if (source == null) if (source == null)
{ {
throw new NullPointerException("source is null"); throw new NullPointerException("source is null");
} }
else else
{ {
this.presenter = PresenterFactory.create(source); this.presenter = PresenterFactory.create(source);
} }
} }
/** /**
* *
* @param source * @param source
*/ */
public void setSource(final String source) public void setSource(final String source)
{ {
if (source == null) if (source == null)
{ {
throw new NullPointerException("source is null"); throw new NullPointerException("source is null");
} }
else else
{ {
this.presenter = PresenterFactory.create(source); this.presenter = PresenterFactory.create(source);
} }
} }
/** /**
* *
* @param source * @param source
*/ */
public void setSource(final URL source) public void setSource(final URL source)
{ {
if (source == null) if (source == null)
{ {
throw new NullPointerException("source is null"); throw new NullPointerException("source is null");
} }
else else
{ {
this.presenter = PresenterFactory.create(source); this.presenter = PresenterFactory.create(source);
} }
} }
/** /**
* *
*/ */
public String toString(final String language) throws Exception public String toString(final String language) throws Exception
{ {
String result; String result;
result = this.presenter.toString(); result = this.presenter.toString();
// //
return result; return result;
} }
/** /**
* *
*/ */
@Override @Override
public void update() throws Exception public void update() throws Exception
{ {
this.presenter.update(); this.presenter.update();
} }
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -30,43 +30,43 @@ import fr.devinsy.xidyn.data.TagDataManager;
*/ */
public interface Presenter public interface Presenter
{ {
/** /**
* *
* @param datas * @param datas
* @return * @return
* @throws Exception * @throws Exception
*/ */
public StringBuffer dynamize() throws Exception; public StringBuffer dynamize() throws Exception;
/** /**
* *
* @param datas * @param datas
* @return * @return
* @throws Exception * @throws Exception
*/ */
public StringBuffer dynamize(final TagDataManager datas) throws Exception; public StringBuffer dynamize(final TagDataManager datas) throws Exception;
/** /**
* *
* @return * @return
*/ */
public Object getSource(); public Object getSource();
/** /**
* This method check if the source exists and it is readable. * This method check if the source exists and it is readable.
* *
* @return * @return
*/ */
public boolean isAvailable(); public boolean isAvailable();
/** /**
* *
* @return * @return
*/ */
public boolean isOutdated() throws Exception; public boolean isOutdated() throws Exception;
/** /**
* *
*/ */
public void update() throws Exception; public void update() throws Exception;
} }

View file

@ -32,246 +32,246 @@ import fr.devinsy.xidyn.utils.cache.Cache;
*/ */
public class PresenterFactory public class PresenterFactory
{ {
/** /**
* http://thecodersbreakfast.net/index.php?post/2008/02/25/26-de-la-bonne- * http://thecodersbreakfast.net/index.php?post/2008/02/25/26-de-la-bonne-
* implementation-du-singleton-en-java * implementation-du-singleton-en-java
*/ */
private static class SingletonHolder private static class SingletonHolder
{ {
private final static PresenterFactory INSTANCE = new PresenterFactory(); 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<Presenter> cache; private Cache<Presenter> cache;
/** /**
* *
*/ */
private PresenterFactory() private PresenterFactory()
{ {
this.cache = new Cache<Presenter>(); this.cache = new Cache<Presenter>();
} }
/** /**
* *
*/ */
public void clear() public void clear()
{ {
this.cache.clear(); this.cache.clear();
} }
/** /**
* *
* @param source * @param source
* @return * @return
*/ */
public Presenter get(final Document source) public Presenter get(final Document source)
{ {
Presenter result; Presenter result;
result = this.cache.get(source); result = this.cache.get(source);
if (result == null) if (result == null)
{ {
result = create(source); result = create(source);
this.cache.put(source, result); this.cache.put(source, result);
} }
// //
return result; return result;
} }
/** /**
* *
* @param source * @param source
* @return * @return
*/ */
public Presenter get(final File source) public Presenter get(final File source)
{ {
Presenter result; Presenter result;
result = this.cache.get(source); result = this.cache.get(source);
if (result == null) if (result == null)
{ {
result = create(source); result = create(source);
this.cache.put(source, result); this.cache.put(source, result);
} }
// //
return result; return result;
} }
/** /**
* *
* @param source * @param source
* @return * @return
*/ */
public Presenter get(final String source) public Presenter get(final String source)
{ {
Presenter result; Presenter result;
result = this.cache.get(source); result = this.cache.get(source);
if (result == null) if (result == null)
{ {
result = create(source); result = create(source);
this.cache.put(source, result); this.cache.put(source, result);
} }
// //
return result; return result;
} }
/** /**
* *
* @param source * @param source
* @return * @return
*/ */
public Presenter get(final URL source) public Presenter get(final URL source)
{ {
Presenter result; Presenter result;
result = this.cache.get(source); result = this.cache.get(source);
if (result == null) if (result == null)
{ {
result = create(source); result = create(source);
this.cache.put(source, result); this.cache.put(source, result);
} }
// //
return result; return result;
} }
/** /**
* *
* @return * @return
*/ */
public int size() public int size()
{ {
int result; int result;
result = this.cache.size(); result = this.cache.size();
// //
return result; return result;
} }
/** /**
* *
* @param source * @param source
* @return * @return
*/ */
public static Presenter create(final Document source) public static Presenter create(final Document source)
{ {
Presenter result; Presenter result;
if (source == null) if (source == null)
{ {
result = null; result = null;
} }
else else
{ {
result = new DomPresenter(source); result = new DomPresenter(source);
} }
// //
return result; return result;
} }
/** /**
* *
* @param source * @param source
* @return * @return
*/ */
public static Presenter create(final File source) public static Presenter create(final File source)
{ {
Presenter result; Presenter result;
if (source == null) if (source == null)
{ {
result = null; result = null;
} }
else else
{ {
result = new FilePresenter(source); result = new FilePresenter(source);
} }
// //
return result; return result;
} }
/** /**
* *
* @param source * @param source
* @return * @return
*/ */
public static Presenter create(final String source) public static Presenter create(final String source)
{ {
Presenter result; Presenter result;
if (source == null) if (source == null)
{ {
result = null; result = null;
} }
else if (source.startsWith("file://")) else if (source.startsWith("file://"))
{ {
result = new FilePresenter(source); result = new FilePresenter(source);
} }
else if (source.matches(".+://.+")) else if (source.matches(".+://.+"))
{ {
result = new URLPresenter(source); result = new URLPresenter(source);
} }
else if (source.startsWith("/")) else if (source.startsWith("/"))
{ {
if (new File(source).exists()) if (new File(source).exists())
{ {
result = new FilePresenter(source); result = new FilePresenter(source);
} }
else else
{ {
result = new URLPresenter(source); result = new URLPresenter(source);
} }
} }
else else
{ {
result = new StringPresenter(source); result = new StringPresenter(source);
} }
// //
return result; return result;
} }
/** /**
* *
* @param source * @param source
* @return * @return
*/ */
public static Presenter create(final URL source) public static Presenter create(final URL source)
{ {
Presenter result; Presenter result;
if (source == null) if (source == null)
{ {
result = null; result = null;
} }
else else
{ {
result = new URLPresenter(source); result = new URLPresenter(source);
} }
// //
return result; return result;
} }
/** /**
* *
* @return * @return
*/ */
public static PresenterFactory instance() public static PresenterFactory instance()
{ {
return SingletonHolder.INSTANCE; return SingletonHolder.INSTANCE;
} }
} }

View file

@ -32,121 +32,121 @@ import fr.devinsy.xidyn.data.TagDataManager;
*/ */
public class PresenterUtils 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 doc
* @param data * @param data
* @return * @return
* @throws Exception * @throws Exception
*/ */
public static StringBuffer dynamize(final Document doc, final TagDataListById data) throws Exception public static StringBuffer dynamize(final Document doc, final TagDataListById data) throws Exception
{ {
StringBuffer result; StringBuffer result;
result = DomPresenterCore.dynamize(doc, data); result = DomPresenterCore.dynamize(doc, data);
// //
return result; return result;
} }
/** /**
* *
* @param doc * @param doc
* @param data * @param data
* @return * @return
* @throws Exception * @throws Exception
*/ */
public static StringBuffer dynamize(final Document doc, final TagDataManager data) throws Exception public static StringBuffer dynamize(final Document doc, final TagDataManager data) throws Exception
{ {
StringBuffer result; StringBuffer result;
result = DomPresenterCore.dynamize(doc, data); result = DomPresenterCore.dynamize(doc, data);
// //
return result; return result;
} }
/** /**
* Dynamize a file without data. * Dynamize a file without data.
*/ */
public static StringBuffer dynamize(final File source) throws Exception public static StringBuffer dynamize(final File source) throws Exception
{ {
StringBuffer result; 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. * Dynamize a file.
*/ */
public static StringBuffer dynamize(final File source, final TagDataManager datas) throws Exception public static StringBuffer dynamize(final File source, final TagDataManager datas) throws Exception
{ {
StringBuffer result; 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 * Dynamize a string with HTML in, or with file path name in, or with URL
* in. * in.
*/ */
public static StringBuffer dynamize(final String source, final TagDataManager datas) throws Exception public static StringBuffer dynamize(final String source, final TagDataManager datas) throws Exception
{ {
StringBuffer result; 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 * @param source
* @return * @return
*/ */
public static boolean hasHtmlTag(final String source) public static boolean hasHtmlTag(final String source)
{ {
boolean result; boolean result;
if (source == null) if (source == null)
{ {
result = false; result = false;
} }
else else
{ {
if (source.matches("<[hH][tT][mM][lL]>")) if (source.matches("<[hH][tT][mM][lL]>"))
{ {
result = true; result = true;
} }
else else
{ {
result = false; result = false;
} }
} }
// //
return result; return result;
} }
} }

View file

@ -32,204 +32,204 @@ import fr.devinsy.xidyn.utils.XidynUtils;
*/ */
public class StringPresenter implements Presenter 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 source;
private String doctype; private String doctype;
private Document dom; private Document dom;
/** /**
* *
*/ */
public StringPresenter() public StringPresenter()
{ {
setSource(""); setSource("");
} }
/** /**
* *
*/ */
public StringPresenter(final String html) public StringPresenter(final String html)
{ {
setSource(html); setSource(html);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public StringBuffer dynamize() throws Exception public StringBuffer dynamize() throws Exception
{ {
StringBuffer result; StringBuffer result;
result = new StringBuffer(this.source); result = new StringBuffer(this.source);
// //
return result; return result;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public StringBuffer dynamize(final TagDataManager data) throws Exception public StringBuffer dynamize(final TagDataManager data) throws Exception
{ {
StringBuffer result; StringBuffer result;
// Build the DOM. // Build the DOM.
if (this.dom == null) if (this.dom == null)
{ {
// Build the source HTML. // Build the source HTML.
String sourceHtml; String sourceHtml;
if (this.source == null) if (this.source == null)
{ {
String errorMessage = "source not defined"; String errorMessage = "source not defined";
logger.error(errorMessage); logger.error(errorMessage);
result = null; result = null;
throw new Exception(errorMessage); throw new Exception(errorMessage);
} }
else else
{ {
this.doctype = XidynUtils.extractDoctype(this.source); this.doctype = XidynUtils.extractDoctype(this.source);
if (this.doctype == null) if (this.doctype == null)
{ {
StringBuffer buffer = new StringBuffer(this.source.length() + 100); StringBuffer buffer = new StringBuffer(this.source.length() + 100);
buffer.append("<html><head></head><body>\n"); buffer.append("<html><head></head><body>\n");
buffer.append(this.source); buffer.append(this.source);
buffer.append("</body></html>"); buffer.append("</body></html>");
sourceHtml = buffer.toString(); sourceHtml = buffer.toString();
} }
else else
{ {
sourceHtml = this.source; sourceHtml = this.source;
} }
} }
// StringBufferInputStream is deprecated so we use another solution. // StringBufferInputStream is deprecated so we use another solution.
// (see // (see
// http://www.developpez.net/forums/archive/index.php/t-14101.html). // http://www.developpez.net/forums/archive/index.php/t-14101.html).
this.dom = XidynUtils.buildDom(sourceHtml); this.dom = XidynUtils.buildDom(sourceHtml);
XidynUtils.addMetaTag(this.dom, "generator", "XIDYN"); XidynUtils.addMetaTag(this.dom, "generator", "XIDYN");
} }
// //
if (data == null) if (data == null)
{ {
result = dynamize(); result = dynamize();
} }
else else
{ {
// //
StringWriter htmlCode = new StringWriter(XidynUtils.estimatedTargetLength(this.source.length())); StringWriter htmlCode = new StringWriter(XidynUtils.estimatedTargetLength(this.source.length()));
if ((this.doctype != null)) if ((this.doctype != null))
{ {
htmlCode.write(this.doctype); htmlCode.write(this.doctype);
} }
DomPresenterCore.dynamize(htmlCode, this.dom, data); DomPresenterCore.dynamize(htmlCode, this.dom, data);
StringBuffer htmlTarget = htmlCode.getBuffer(); StringBuffer htmlTarget = htmlCode.getBuffer();
// //
if (htmlTarget == null) if (htmlTarget == null)
{ {
result = null; result = null;
} }
else if (this.doctype != null) else if (this.doctype != null)
{ {
result = htmlTarget; result = htmlTarget;
} }
else else
{ {
String bodyContent = XidynUtils.extractBodyContent(htmlTarget); String bodyContent = XidynUtils.extractBodyContent(htmlTarget);
if (bodyContent == null) if (bodyContent == null)
{ {
result = null; result = null;
} }
else else
{ {
result = new StringBuffer(bodyContent); result = new StringBuffer(bodyContent);
} }
} }
} }
// //
return (result); return (result);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public String getSource() public String getSource()
{ {
String result; String result;
result = this.source; result = this.source;
// //
return (result); return (result);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean isAvailable() public boolean isAvailable()
{ {
boolean result; boolean result;
if (this.source == null) if (this.source == null)
{ {
result = false; result = false;
} }
else else
{ {
result = true; result = true;
} }
// //
return result; return result;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean isOutdated() throws Exception public boolean isOutdated() throws Exception
{ {
boolean result; boolean result;
if (this.dom == null) if (this.dom == null)
{ {
result = true; result = true;
} }
else else
{ {
result = false; result = false;
} }
// //
return result; return result;
} }
/** /**
* *
*/ */
public void setSource(final String html) public void setSource(final String html)
{ {
this.source = html; this.source = html;
this.doctype = null; this.doctype = null;
this.dom = null; this.dom = null;
} }
/** /**
* *
*/ */
@Override @Override
public void update() throws Exception public void update() throws Exception
{ {
// Nothing to do. // Nothing to do.
} }
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2014 Christian Pierre MOMON * Copyright (C) 2006-2016 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -29,323 +29,323 @@ import fr.devinsy.xidyn.data.TagDataManager;
*/ */
public class TranslatorPresenter implements Presenter public class TranslatorPresenter implements Presenter
{ {
private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TranslatorPresenter.class); private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TranslatorPresenter.class);
private String defaultSource; private String defaultSource;
private HashMap<String, Presenter> presenters; private HashMap<String, Presenter> presenters;
/** /**
* *
*/ */
public TranslatorPresenter(final String defaultSource) public TranslatorPresenter(final String defaultSource)
{ {
if (defaultSource == null) if (defaultSource == null)
{ {
throw new NullPointerException("defaultSource is null"); throw new NullPointerException("defaultSource is null");
} }
else else
{ {
this.defaultSource = defaultSource; this.defaultSource = defaultSource;
this.presenters = new HashMap<String, Presenter>(); this.presenters = new HashMap<String, Presenter>();
} }
} }
/** /**
* *
*/ */
@Override @Override
public StringBuffer dynamize() throws Exception public StringBuffer dynamize() throws Exception
{ {
StringBuffer result; StringBuffer result;
Presenter presenter = getPresenter((String) null); Presenter presenter = getPresenter((String) null);
if (presenter == null) if (presenter == null)
{ {
result = null; result = null;
} }
else else
{ {
result = presenter.dynamize(); result = presenter.dynamize();
} }
// //
return result; return result;
} }
/** /**
* *
*/ */
public StringBuffer dynamize(final Locale locale) throws Exception public StringBuffer dynamize(final Locale locale) throws Exception
{ {
StringBuffer result; StringBuffer result;
// //
String language; String language;
if (locale == null) if (locale == null)
{ {
language = null; language = null;
} }
else else
{ {
language = locale.getLanguage(); language = locale.getLanguage();
} }
// //
result = getPresenter(language).dynamize(); result = getPresenter(language).dynamize();
// //
return result; return result;
} }
/** /**
* *
*/ */
public StringBuffer dynamize(final String language) throws Exception public StringBuffer dynamize(final String language) throws Exception
{ {
StringBuffer result; StringBuffer result;
result = getPresenter(language).dynamize(); result = getPresenter(language).dynamize();
// //
return result; return result;
} }
/** /**
* *
*/ */
@Override @Override
public StringBuffer dynamize(final TagDataManager datas) throws Exception public StringBuffer dynamize(final TagDataManager datas) throws Exception
{ {
StringBuffer result; StringBuffer result;
Presenter presenter = getPresenter((String) null); Presenter presenter = getPresenter((String) null);
if (presenter == null) if (presenter == null)
{ {
result = null; result = null;
} }
else else
{ {
result = presenter.dynamize(datas); result = presenter.dynamize(datas);
} }
// //
return result; return result;
} }
/** /**
* *
*/ */
public StringBuffer dynamize(final TagDataManager datas, final Locale locale) throws Exception public StringBuffer dynamize(final TagDataManager datas, final Locale locale) throws Exception
{ {
StringBuffer result; StringBuffer result;
// //
String language; String language;
if (locale == null) if (locale == null)
{ {
language = null; language = null;
} }
else else
{ {
language = locale.getLanguage(); 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 public StringBuffer dynamize(final TagDataManager datas, final String language) throws Exception
{ {
StringBuffer result; StringBuffer result;
result = getPresenter(language).dynamize(datas); result = getPresenter(language).dynamize(datas);
// //
return result; return result;
} }
/** /**
* *
*/ */
public Presenter getPresenter(final Locale locale) throws Exception public Presenter getPresenter(final Locale locale) throws Exception
{ {
Presenter result; Presenter result;
// //
String language; String language;
if ((locale == null) || (locale.getLanguage().length() == 0)) if ((locale == null) || (locale.getLanguage().length() == 0))
{ {
language = null; language = null;
} }
else else
{ {
language = locale.getLanguage(); language = locale.getLanguage();
} }
// //
result = getPresenter(language); result = getPresenter(language);
// //
return result; return result;
} }
/** /**
* *
*/ */
public Presenter getPresenter(final String language) throws Exception public Presenter getPresenter(final String language) throws Exception
{ {
Presenter result; Presenter result;
// //
result = this.presenters.get(language); result = this.presenters.get(language);
// //
if (result == null) if (result == null)
{ {
// //
if (language == null) if (language == null)
{ {
// //
result = PresenterFactory.create(this.defaultSource); result = PresenterFactory.create(this.defaultSource);
if (result.isAvailable()) if (result.isAvailable())
{ {
this.presenters.put(language, result); this.presenters.put(language, result);
} }
else else
{ {
throw new Exception("Undefined default language file."); throw new Exception("Undefined default language file.");
} }
} }
else else
{ {
String adaptedSource = FileTools.addBeforeExtension(this.defaultSource, "-" + language); String adaptedSource = FileTools.addBeforeExtension(this.defaultSource, "-" + language);
result = PresenterFactory.create(adaptedSource); result = PresenterFactory.create(adaptedSource);
if (result.isAvailable()) if (result.isAvailable())
{ {
this.presenters.put(language, result); this.presenters.put(language, result);
} }
else else
{ {
adaptedSource = FileTools.addBeforeExtension(this.defaultSource, "_" + language); adaptedSource = FileTools.addBeforeExtension(this.defaultSource, "_" + language);
if (result.isAvailable()) if (result.isAvailable())
{ {
this.presenters.put(language, result); this.presenters.put(language, result);
} }
else else
{ {
result = getPresenter((String) null); result = getPresenter((String) null);
} }
} }
} }
} }
// //
return result; return result;
} }
/** /**
* *
*/ */
@Override @Override
public Object getSource() public Object getSource()
{ {
String result; String result;
result = this.defaultSource; result = this.defaultSource;
// //
return result; return result;
} }
/** /**
* *
*/ */
@Override @Override
public boolean isAvailable() public boolean isAvailable()
{ {
boolean result; boolean result;
try try
{ {
result = getPresenter((String) null).isAvailable(); result = getPresenter((String) null).isAvailable();
} }
catch (Exception exception) catch (Exception exception)
{ {
result = false; result = false;
} }
// //
return result; return result;
} }
/** /**
* *
*/ */
@Override @Override
public boolean isOutdated() throws Exception public boolean isOutdated() throws Exception
{ {
return false; return false;
} }
/** /**
* *
*/ */
public String toString(final Locale locale) throws Exception public String toString(final Locale locale) throws Exception
{ {
String result; String result;
// //
String language; String language;
if (locale == null) if (locale == null)
{ {
language = null; language = null;
} }
else else
{ {
language = locale.getLanguage(); language = locale.getLanguage();
} }
// //
result = toString(language); result = toString(language);
// //
return result; return result;
} }
/** /**
* *
*/ */
public String toString(final String language) throws Exception public String toString(final String language) throws Exception
{ {
String result; String result;
Presenter presenter = getPresenter(language); Presenter presenter = getPresenter(language);
if (presenter == null) if (presenter == null)
{ {
result = null; result = null;
} }
else else
{ {
result = presenter.toString(); result = presenter.toString();
} }
// //
return result; return result;
} }
@Override @Override
public void update() throws Exception public void update() throws Exception
{ {
} }
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -33,321 +33,321 @@ import fr.devinsy.xidyn.utils.XidynUtils;
*/ */
public class URLPresenter extends StringPresenter 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 String sourcePathname;
private URL source; private URL source;
private long sourceTime; private long sourceTime;
/** /**
* *
*/ */
public URLPresenter() public URLPresenter()
{ {
super(); super();
setSource((URL) null); setSource((URL) null);
} }
/** /**
* *
*/ */
public URLPresenter(final String source) public URLPresenter(final String source)
{ {
super(); super();
setSource(source); setSource(source);
} }
/** /**
* *
*/ */
public URLPresenter(final URL source) public URLPresenter(final URL source)
{ {
super(); super();
setSource(source); setSource(source);
} }
/** /**
* No need to be synchronized. * No need to be synchronized.
*/ */
@Override @Override
public StringBuffer dynamize() throws Exception public StringBuffer dynamize() throws Exception
{ {
StringBuffer result; StringBuffer result;
// //
update(); update();
// //
result = super.dynamize(); result = super.dynamize();
// //
return result; return result;
} }
/** /**
* No need to be synchronized. * No need to be synchronized.
*/ */
@Override @Override
public StringBuffer dynamize(final TagDataManager data) throws Exception public StringBuffer dynamize(final TagDataManager data) throws Exception
{ {
StringBuffer result; StringBuffer result;
logger.info("dynamize URL [" + this.sourcePathname + "]"); logger.info("dynamize URL [" + this.sourcePathname + "]");
// //
update(); update();
// Build the web page. // Build the web page.
result = super.dynamize(data); result = super.dynamize(data);
// //
return (result); return (result);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public String getSource() public String getSource()
{ {
String result; String result;
result = this.sourcePathname; result = this.sourcePathname;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public URL getURL() public URL getURL()
{ {
URL result; URL result;
result = this.source; result = this.source;
// //
return (result); return (result);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean isAvailable() public boolean isAvailable()
{ {
boolean result; boolean result;
if (this.source == null) if (this.source == null)
{ {
result = false; result = false;
} }
else if (this.sourcePathname.startsWith("/")) else if (this.sourcePathname.startsWith("/"))
{ {
/* /*
* In case of Jar resources, if resource does not exist then * 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 null. So, if we are here in the code then
* this.source is not null and so resource is available. * this.source is not null and so resource is available.
*/ */
result = true; result = true;
} }
else else
{ {
/* /*
* The source is an URL with protocol. Open a stream is the only way to test if the resource is available. * The source is an URL with protocol. Open a stream is the only way to test if the resource is available.
*/ */
try try
{ {
this.source.openStream(); this.source.openStream();
result = true; result = true;
} }
catch (final IOException exception) catch (final IOException exception)
{ {
/* /*
* On URL.openStream: * On URL.openStream:
* <ul> * <ul>
* <li>If host does not exist then a java.net.UnknownHostException is throwed.</li> * <li>If host does not exist then a java.net.UnknownHostException is throwed.</li>
* <li>If host exists but not the file does not exist then a java.io.FileNotFoundException is throwed.</li> * <li>If host exists but not the file does not exist then a java.io.FileNotFoundException is throwed.</li>
* </ul> * </ul>
* These exceptions are IOException. * These exceptions are IOException.
*/ */
result = false; result = false;
} }
} }
// //
return result; return result;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* @throws IOException * @throws IOException
*/ */
@Override @Override
public boolean isOutdated() throws Exception public boolean isOutdated() throws Exception
{ {
boolean result; boolean result;
// //
if (super.isOutdated()) if (super.isOutdated())
{ {
result = true; result = true;
} }
else if (this.sourceTime == this.source.openConnection().getLastModified()) else if (this.sourceTime == this.source.openConnection().getLastModified())
{ {
result = true; result = true;
} }
else else
{ {
result = false; result = false;
} }
// //
return result; return result;
} }
/** /**
* *
*/ */
@Override @Override
public void setSource(final String source) public void setSource(final String source)
{ {
// //
if (source == null) if (source == null)
{ {
this.source = null; this.source = null;
this.sourcePathname = null; this.sourcePathname = null;
this.sourceTime = 0; this.sourceTime = 0;
super.setSource(null); super.setSource(null);
} }
else else
{ {
// //
URL url; URL url;
if (source.matches(".+://.+")) if (source.matches(".+://.+"))
{ {
try try
{ {
url = new URL(source); url = new URL(source);
} }
catch (final MalformedURLException exception) catch (final MalformedURLException exception)
{ {
// TODO // TODO
logger.warn("UNKNOWN PROTOCOL [" + source + "]"); logger.warn("UNKNOWN PROTOCOL [" + source + "]");
url = null; url = null;
} }
} }
else else
{ {
url = URLPresenter.class.getResource(source); url = URLPresenter.class.getResource(source);
} }
// //
if (url == null) if (url == null)
{ {
this.source = null; this.source = null;
this.sourcePathname = source; this.sourcePathname = source;
this.sourceTime = 0; this.sourceTime = 0;
super.setSource(null); super.setSource(null);
} }
else else
{ {
this.source = url; this.source = url;
this.sourcePathname = source; this.sourcePathname = source;
this.sourceTime = 0; this.sourceTime = 0;
super.setSource(null); super.setSource(null);
} }
} }
} }
/** /**
* *
* @param source * @param source
*/ */
public void setSource(final URL source) public void setSource(final URL source)
{ {
if (source == null) if (source == null)
{ {
this.source = null; this.source = null;
this.sourcePathname = null; this.sourcePathname = null;
this.sourceTime = 0; this.sourceTime = 0;
super.setSource(null); super.setSource(null);
} }
else else
{ {
this.source = source; this.source = source;
this.sourcePathname = source.toString(); this.sourcePathname = source.toString();
this.sourceTime = 0; this.sourceTime = 0;
super.setSource(null); super.setSource(null);
} }
} }
/** /**
* *
*/ */
@Override @Override
public String toString() public String toString()
{ {
String result; String result;
try try
{ {
// //
update(); update();
// //
result = super.getSource(); result = super.getSource();
} }
catch (final Exception exception) catch (final Exception exception)
{ {
result = null; result = null;
} }
// //
return result; return result;
} }
/** /**
* No need to be synchronized. * No need to be synchronized.
* *
* @throws Exception * @throws Exception
*/ */
@Override @Override
public void update() throws Exception public void update() throws Exception
{ {
// //
if (this.source == null) if (this.source == null)
{ {
String errorMessage = "source not defined (" + this.sourcePathname + ")"; String errorMessage = "source not defined (" + this.sourcePathname + ")";
logger.error(errorMessage); logger.error(errorMessage);
throw new NullPointerException(errorMessage); throw new NullPointerException(errorMessage);
} }
else else
{ {
try try
{ {
long currentSourceTime = this.source.openConnection().getLastModified(); long currentSourceTime = this.source.openConnection().getLastModified();
if ((super.getSource() == null) || (this.sourceTime != currentSourceTime)) if ((super.getSource() == null) || (this.sourceTime != currentSourceTime))
{ {
super.setSource(XidynUtils.load(this.source)); super.setSource(XidynUtils.load(this.source));
this.sourceTime = currentSourceTime; this.sourceTime = currentSourceTime;
} }
} }
catch (final IOException exception) catch (final IOException exception)
{ {
/* On URL.openStream: /* On URL.openStream:
* <ul> * <ul>
* <li>If host does not exist then a java.net.UnknownHostException is throwed.</li> * <li>If host does not exist then a java.net.UnknownHostException is throwed.</li>
* <li>If host exists but not the file does not exist then a java.io.FileNotFoundException is throwed.</li> * <li>If host exists but not the file does not exist then a java.io.FileNotFoundException is throwed.</li>
* </ul> * </ul>
* These exceptions are IOException. * These exceptions are IOException.
*/ */
String errorMessage = "source file defined but not readable (" + this.source.toString() + ")"; String errorMessage = "source file defined but not readable (" + this.source.toString() + ")";
logger.error(errorMessage); logger.error(errorMessage);
throw new Exception(errorMessage); throw new Exception(errorMessage);
} }
} }
} }
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2014 Christian Pierre MOMON * Copyright (C) 2006-2016 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -33,157 +33,157 @@ import org.xml.sax.SAXParseException;
*/ */
public class ParserErrorHandler implements ErrorHandler public class ParserErrorHandler implements ErrorHandler
{ {
private Vector<String> messages; private Vector<String> messages;
private int fatalErrorsCount; private int fatalErrorsCount;
private int errorsCount; private int errorsCount;
private int warningCount; private int warningCount;
public ParserErrorHandler() public ParserErrorHandler()
{ {
this.fatalErrorsCount = 0; this.fatalErrorsCount = 0;
this.errorsCount = 0; this.errorsCount = 0;
this.warningCount = 0; this.warningCount = 0;
this.messages = new Vector<String>(); this.messages = new Vector<String>();
} }
/** /**
* *
*/ */
public int allErrorsCount() public int allErrorsCount()
{ {
int result; int result;
result = fatalErrorsCount() + errorsCount() + warningCount(); result = fatalErrorsCount() + errorsCount() + warningCount();
// //
return (result); return (result);
} }
/** /**
* Called by the XML parser to handle fatal errors. * Called by the XML parser to handle fatal errors.
* *
* @param ex * @param ex
* Parse Excpetion. Contains the warning text and the line * Parse Excpetion. Contains the warning text and the line
* number. * number.
*/ */
@Override @Override
public void error(final SAXParseException exception) public void error(final SAXParseException exception)
{ {
String message = "Error at line " + exception.getLineNumber() + " : " + exception.getMessage(); String message = "Error at line " + exception.getLineNumber() + " : " + exception.getMessage();
this.errorsCount += 1; this.errorsCount += 1;
this.messages.add(message); this.messages.add(message);
} }
/** /**
* *
*/ */
public int errorsCount() public int errorsCount()
{ {
int result; int result;
result = this.errorsCount; result = this.errorsCount;
// //
return (result); return (result);
} }
/** /**
* Called by the XML parser to handle fatal errors. * Called by the XML parser to handle fatal errors.
* *
* @param ex * @param ex
* Parse Excpetion. Contains the error text and the line number. * Parse Excpetion. Contains the error text and the line number.
* When a fatal parse error occurs, the parse does not return a * When a fatal parse error occurs, the parse does not return a
* document. * document.
*/ */
@Override @Override
public void fatalError(final SAXParseException exception) public void fatalError(final SAXParseException exception)
{ {
String message = "Fatal error at line " + exception.getLineNumber() + " : " + exception.getMessage(); String message = "Fatal error at line " + exception.getLineNumber() + " : " + exception.getMessage();
this.fatalErrorsCount += 1; this.fatalErrorsCount += 1;
this.messages.add(message); this.messages.add(message);
} }
/** /**
* *
*/ */
public int fatalErrorsCount() public int fatalErrorsCount()
{ {
int result; int result;
result = this.fatalErrorsCount; result = this.fatalErrorsCount;
// //
return (result); return (result);
} }
/** /**
* *
*/ */
public boolean hasError() public boolean hasError()
{ {
boolean result; boolean result;
if (allErrorsCount() == 0) if (allErrorsCount() == 0)
{ {
result = false; result = false;
} }
else else
{ {
result = true; result = true;
} }
// //
return (result); return (result);
} }
/** /**
* *
*/ */
@Override @Override
public String toString() public String toString()
{ {
StringBuffer result; StringBuffer result;
result = new StringBuffer(); result = new StringBuffer();
for (String message : this.messages) for (String message : this.messages)
{ {
result.append(message); result.append(message);
result.append('\n'); result.append('\n');
} }
// //
return (result.toString()); return (result.toString());
} }
/** /**
* Called by the XML parser to handle warnings. * Called by the XML parser to handle warnings.
* *
* @param ex * @param ex
* Parse Excpetion. Contains the warning text and the line * Parse Excpetion. Contains the warning text and the line
* number. * number.
*/ */
@Override @Override
public void warning(final SAXParseException exception) public void warning(final SAXParseException exception)
{ {
String message = "Warning at line " + exception.getLineNumber() + " : " + exception.getMessage(); String message = "Warning at line " + exception.getLineNumber() + " : " + exception.getMessage();
this.warningCount += 1; this.warningCount += 1;
this.messages.add(message); this.messages.add(message);
} }
/** /**
* *
*/ */
public int warningCount() public int warningCount()
{ {
int result; int result;
result = this.warningCount; result = this.warningCount;
// //
return (result); return (result);
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -28,147 +28,147 @@ import fr.devinsy.xidyn.utils.cache.CacheStrategy.Strategy;
*/ */
public class Cache<T> public class Cache<T>
{ {
private CacheStrategy strategy; private CacheStrategy strategy;
private Map<Object, CacheItem<T>> map; private Map<Object, CacheItem<T>> map;
/** /**
* *
*/ */
public Cache() public Cache()
{ {
this.strategy = new CacheStrategy(Strategy.NONE, 0); this.strategy = new CacheStrategy(Strategy.NONE, 0);
this.map = new HashMap<Object, CacheItem<T>>(); this.map = new HashMap<Object, CacheItem<T>>();
} }
/** /**
* *
*/ */
public Cache(final int initialCapacity) public Cache(final int initialCapacity)
{ {
this.strategy = new CacheStrategy(Strategy.NONE, 0); this.strategy = new CacheStrategy(Strategy.NONE, 0);
this.map = new HashMap<Object, CacheItem<T>>(initialCapacity); this.map = new HashMap<Object, CacheItem<T>>(initialCapacity);
} }
/** /**
* *
*/ */
public void clear() public void clear()
{ {
this.map.clear(); this.map.clear();
} }
/** /**
* *
* @param key * @param key
* @return * @return
* @throws Exception * @throws Exception
*/ */
public T get(final Object key) public T get(final Object key)
{ {
T result; T result;
CacheItem<T> item = this.map.get(key); CacheItem<T> item = this.map.get(key);
if (item == null) if (item == null)
{ {
result = null; result = null;
} }
else else
{ {
result = item.getValue(); result = item.getValue();
} }
// //
return result; return result;
} }
/** /**
* *
* @return * @return
*/ */
public boolean isEmpty() public boolean isEmpty()
{ {
boolean result; boolean result;
result = this.map.isEmpty(); result = this.map.isEmpty();
// //
return result; return result;
} }
/** /**
* *
*/ */
public void purge() public void purge()
{ {
switch (this.strategy.getStrategy()) switch (this.strategy.getStrategy())
{ {
case NONE: case NONE:
{ {
} }
break; break;
case SIZE: case SIZE:
{ {
if (this.map.size() > this.strategy.getParameter()) if (this.map.size() > this.strategy.getParameter())
{ {
// TODO // TODO
} }
} }
break; break;
case TIME: case TIME:
{ {
// TODO // TODO
} }
break; break;
} }
} }
/** /**
* *
* @param source * @param source
* @return * @return
*/ */
public T put(final Object key, final T source) public T put(final Object key, final T source)
{ {
T result; T result;
if (source != null) if (source != null)
{ {
CacheItem<T> item = this.map.get(key); CacheItem<T> item = this.map.get(key);
if (item == null) if (item == null)
{ {
purge(); purge();
item = new CacheItem<T>(source); item = new CacheItem<T>(source);
this.map.put(key, item); this.map.put(key, item);
} }
else else
{ {
item.setValue(source); item.setValue(source);
} }
} }
result = source; result = source;
// //
return result; return result;
} }
/** /**
* *
* @return * @return
*/ */
public int size() public int size()
{ {
int result; int result;
result = this.map.size(); result = this.map.size();
// //
return result; return result;
} }
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -25,103 +25,103 @@ import java.util.Date;
*/ */
public class CacheItem<T> public class CacheItem<T>
{ {
private T value; private T value;
private long creationDate; private long creationDate;
private long editionDate; private long editionDate;
private long accessDate; private long accessDate;
/** /**
* *
* @param source * @param source
*/ */
public CacheItem(final T source) public CacheItem(final T source)
{ {
this.value = source; this.value = source;
this.creationDate = time(); this.creationDate = time();
this.editionDate = this.creationDate; this.editionDate = this.creationDate;
this.accessDate = this.creationDate; this.accessDate = this.creationDate;
} }
/** /**
* *
* @return * @return
*/ */
public long accessDate() public long accessDate()
{ {
long result; long result;
result = this.accessDate; result = this.accessDate;
// //
return result; return result;
} }
/** /**
* *
* @return * @return
*/ */
public long creationDate() public long creationDate()
{ {
long result; long result;
result = this.creationDate; result = this.creationDate;
// //
return result; return result;
} }
/** /**
* *
* @return * @return
*/ */
public long editionDate() public long editionDate()
{ {
long result; long result;
result = this.editionDate; result = this.editionDate;
// //
return result; return result;
} }
/** /**
* *
* @return * @return
*/ */
public T getValue() public T getValue()
{ {
T result; T result;
result = this.value; result = this.value;
this.accessDate = time(); this.accessDate = time();
// //
return result; return result;
} }
/** /**
* *
* @param source * @param source
*/ */
public void setValue(final T source) public void setValue(final T source)
{ {
this.value = source; this.value = source;
this.editionDate = time(); this.editionDate = time();
} }
/** /**
* *
* @return * @return
*/ */
private static long time() private static long time()
{ {
long result; long result;
result = new Date().getTime(); result = new Date().getTime();
// //
return result; return result;
} }
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -23,57 +23,57 @@ package fr.devinsy.xidyn.utils.cache;
*/ */
public class CacheStrategy public class CacheStrategy
{ {
public enum Strategy public enum Strategy
{ {
NONE, NONE,
SIZE, SIZE,
TIME TIME
} }
private Strategy strategy; private Strategy strategy;
private long parameter; private long parameter;
/** /**
* *
* @param strategy * @param strategy
* @param parameter * @param parameter
*/ */
public CacheStrategy(final Strategy strategy, final long parameter) public CacheStrategy(final Strategy strategy, final long parameter)
{ {
if (strategy == null) if (strategy == null)
{ {
throw new IllegalArgumentException("Null strategy."); throw new IllegalArgumentException("Null strategy.");
} }
else if (parameter < 0) else if (parameter < 0)
{ {
throw new IllegalArgumentException("Negative parameter."); throw new IllegalArgumentException("Negative parameter.");
} }
else else
{ {
this.strategy = strategy; this.strategy = strategy;
this.parameter = parameter; this.parameter = parameter;
} }
} }
public long getParameter() public long getParameter()
{ {
return this.parameter; return this.parameter;
} }
public Strategy getStrategy() public Strategy getStrategy()
{ {
return this.strategy; return this.strategy;
} }
public void setParameter(final long parameter) public void setParameter(final long parameter)
{ {
this.parameter = parameter; this.parameter = parameter;
} }
public void setStrategy(final Strategy strategy) public void setStrategy(final Strategy strategy)
{ {
this.strategy = strategy; this.strategy = strategy;
} }
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2014 Christian Pierre MOMON * Copyright (C) 2006-2016 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -25,14 +25,14 @@ import java.util.Locale;
*/ */
public interface CharterView extends View public interface CharterView extends View
{ {
/** /**
* *
* @param userId * @param userId
* @param lang * @param lang
* @param content * @param content
* @return * @return
*/ */
public StringBuffer getHtml(final Long userId, final Locale language, final CharSequence content) throws Exception; public StringBuffer getHtml(final Long userId, final Locale language, final CharSequence content) throws Exception;
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2014 Christian Pierre MOMON * Copyright (C) 2006-2016 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -23,10 +23,10 @@ package fr.devinsy.xidyn.views;
*/ */
public interface View public interface View
{ {
/** /**
* *
*/ */
public StringBuffer getHtml() throws Exception; public StringBuffer getHtml() throws Exception;
} }

View file

@ -25,14 +25,14 @@ import fr.devinsy.xidyn.utils.XidynUtils;
*/ */
class Foo class Foo
{ {
/** /**
* @throws Exception * @throws Exception
* *
*/ */
public static void main(final String[] args) throws Exception public static void main(final String[] args) throws Exception
{ {
String source = "<div><h1>toto</h1><span id='titi'>blank</span></div>"; String source = "<div><h1>toto</h1><span id='titi'>blank</span></div>";
Document dom = XidynUtils.buildDom(source); Document dom = XidynUtils.buildDom(source);
} }
} }

View file

@ -29,233 +29,244 @@ import fr.devinsy.xidyn.presenters.StringPresenter;
*/ */
class XidynTest class XidynTest
{ {
public enum MONTHS public enum MONTHS
{ {
JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBRE, DECEMBRE JANUARY,
} FEBRUARY,
MARCH,
APRIL,
MAY,
JUNE,
JULY,
AUGUST,
SEPTEMBER,
OCTOBER,
NOVEMBRE,
DECEMBRE
}
static private Logger logger = LoggerFactory.getLogger(XidynTest.class); static private Logger logger = LoggerFactory.getLogger(XidynTest.class);
static static
{ {
// Initialize logger. // Initialize logger.
org.apache.log4j.BasicConfigurator.configure(); org.apache.log4j.BasicConfigurator.configure();
org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO); org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO);
} }
/** /**
* *
*/ */
public static String check(final String title, final StringBuffer source, final String model) public static String check(final String title, final StringBuffer source, final String model)
{ {
String result; String result;
if (source.indexOf(model) == -1) if (source.indexOf(model) == -1)
{ {
result = String.format("%-40s -> KO <-", title) + "\nGet:\n" + source + "\nWaiting:\n" + model; result = String.format("%-40s -> KO <-", title) + "\nGet:\n" + source + "\nWaiting:\n" + model;
} }
else else
{ {
result = String.format("%-40s [ OK ] ", title); result = String.format("%-40s [ OK ] ", title);
} }
// //
return (result); return (result);
}; };
/** /**
* *
*/ */
public static void main(final String[] args) public static void main(final String[] args)
{ {
System.out.println("Automatic test action for Xid!"); System.out.println("Automatic test action for Xid!");
TagDataManager datas; TagDataManager datas;
SimpleTagData tag; SimpleTagData tag;
String htmlSource; String htmlSource;
StringBuffer html; StringBuffer html;
// Populate attributes of Test 03. // Populate attributes of Test 03.
System.out.println("----------------------------"); System.out.println("----------------------------");
datas = new TagDataManager(); datas = new TagDataManager();
datas.setContent("name", "Superman"); datas.setContent("name", "Superman");
try try
{ {
html = StringPresenter.dynamize("<div id='name'>a name</div >", datas); html = StringPresenter.dynamize("<div id='name'>a name</div >", datas);
} }
catch (Exception exception) catch (Exception exception)
{ {
System.out.println(exception.getMessage()); System.out.println(exception.getMessage());
html = null; html = null;
} }
System.out.println(check("only content change", html, "<div id=\"name\">Superman</div>")); System.out.println(check("only content change", html, "<div id=\"name\">Superman</div>"));
// Populate attributes of Test 03. // Populate attributes of Test 03.
System.out.println("----------------------------"); System.out.println("----------------------------");
datas = new TagDataManager(); datas = new TagDataManager();
datas.setContent("lastname", "Spiderman"); datas.setContent("lastname", "Spiderman");
datas.appendAttribute("lastname", "style", "background: blue;"); datas.appendAttribute("lastname", "style", "background: blue;");
datas.appendAttribute("lastname", "style", "foreground: red;"); datas.appendAttribute("lastname", "style", "foreground: red;");
datas.setAttribute("lastname", "class", "nameClass"); datas.setAttribute("lastname", "class", "nameClass");
try try
{ {
html = StringPresenter.dynamize("<div id='lastname'>a last name</div >", datas); html = StringPresenter.dynamize("<div id='lastname'>a last name</div >", datas);
} }
catch (Exception exception) catch (Exception exception)
{ {
System.out.println(exception.getMessage()); System.out.println(exception.getMessage());
html = null; html = null;
} }
System.out.println(check("content and attributes", html, "<div id=\"lastname\" style=\"background: blue;foreground: red;\" class=\"nameClass\">Spiderman</div>")); System.out.println(check("content and attributes", html, "<div id=\"lastname\" style=\"background: blue;foreground: red;\" class=\"nameClass\">Spiderman</div>"));
// Populate attributes of Test 03. // Populate attributes of Test 03.
System.out.println("----------------------------"); System.out.println("----------------------------");
datas = new TagDataManager(); datas = new TagDataManager();
datas.setContent("words", 0, "alpha"); datas.setContent("words", 0, "alpha");
datas.setContent("words", 1, "bravo"); datas.setContent("words", 1, "bravo");
datas.setContent("words", 2, "charlie"); datas.setContent("words", 2, "charlie");
datas.setContent("words", 3, "delta"); datas.setContent("words", 3, "delta");
datas.setContent("words", 4, "echo"); datas.setContent("words", 4, "echo");
datas.setContent("words", 5, "fox"); datas.setContent("words", 5, "fox");
try try
{ {
html = StringPresenter.dynamize("<ul>\n <li id='words'>a word</li>\n</ul>", datas); html = StringPresenter.dynamize("<ul>\n <li id='words'>a word</li>\n</ul>", datas);
} }
catch (Exception exception) catch (Exception exception)
{ {
System.out.println(exception.getMessage()); System.out.println(exception.getMessage());
html = null; html = null;
} }
System.out.println(check("list assertion 1", html, "<li id=\"words_0\">alpha</li>")); System.out.println(check("list assertion 1", html, "<li id=\"words_0\">alpha</li>"));
System.out.println(check("list assertion 2", html, "<li id=\"words_1\">bravo</li>")); System.out.println(check("list assertion 2", html, "<li id=\"words_1\">bravo</li>"));
System.out.println(check("list assertion 3", html, "<li id=\"words_2\">charlie</li>")); System.out.println(check("list assertion 3", html, "<li id=\"words_2\">charlie</li>"));
System.out.println(check("list assertion 4", html, "<li id=\"words_3\">delta</li>")); System.out.println(check("list assertion 4", html, "<li id=\"words_3\">delta</li>"));
System.out.println(check("list assertion 5", html, "<li id=\"words_4\">echo</li>")); System.out.println(check("list assertion 5", html, "<li id=\"words_4\">echo</li>"));
System.out.println(check("list assertion 6", html, "<li id=\"words_5\">fox</li>")); System.out.println(check("list assertion 6", html, "<li id=\"words_5\">fox</li>"));
// Populate attributes of Test 03. // Populate attributes of Test 03.
System.out.println("----------------------------"); System.out.println("----------------------------");
datas = new TagDataManager(); datas = new TagDataManager();
datas.setContent("identity", 0, "nom", "Jemba"); datas.setContent("identity", 0, "nom", "Jemba");
datas.setContent("identity", 0, "prenom", "Epo"); datas.setContent("identity", 0, "prenom", "Epo");
datas.setContent("identity", 1, "nom", "Momon"); datas.setContent("identity", 1, "nom", "Momon");
datas.setContent("identity", 1, "prenom", "Christian"); datas.setContent("identity", 1, "prenom", "Christian");
datas.setContent("identity", 2, "nom", "Tronche"); datas.setContent("identity", 2, "nom", "Tronche");
datas.setContent("identity", 2, "prenom", "Christophe"); datas.setContent("identity", 2, "prenom", "Christophe");
StringBuffer source = new StringBuffer(); StringBuffer source = new StringBuffer();
source.append("<table>\n"); source.append("<table>\n");
source.append(" <tr id='identity'><td>noid</td><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>\n"); source.append(" <tr id='identity'><td>noid</td><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>\n");
source.append("</table>"); source.append("</table>");
htmlSource = source.toString(); htmlSource = source.toString();
try try
{ {
html = StringPresenter.dynamize(htmlSource, datas); html = StringPresenter.dynamize(htmlSource, datas);
} }
catch (Exception exception) catch (Exception exception)
{ {
System.out.println(exception.getMessage()); System.out.println(exception.getMessage());
html = null; html = null;
} }
System.out.println(check("table 1 assertion 1", html, "<tr id=\"identity_0\"><td>noid</td><td id=\"nom_0\">Jemba</td><td id=\"prenom_0\">Epo</td></tr>")); System.out.println(check("table 1 assertion 1", html, "<tr id=\"identity_0\"><td>noid</td><td id=\"nom_0\">Jemba</td><td id=\"prenom_0\">Epo</td></tr>"));
System.out.println(check("table 1 assertion 2", html, "<tr id=\"identity_1\"><td>noid</td><td id=\"nom_1\">Momon</td><td id=\"prenom_1\">Christian</td></tr>")); System.out.println(check("table 1 assertion 2", html, "<tr id=\"identity_1\"><td>noid</td><td id=\"nom_1\">Momon</td><td id=\"prenom_1\">Christian</td></tr>"));
System.out.println(check("table 1 assertion 3", html, "<tr id=\"identity_2\"><td>noid</td><td id=\"nom_2\">Tronche</td><td id=\"prenom_2\">Christophe</td></tr>")); System.out.println(check("table 1 assertion 3", html, "<tr id=\"identity_2\"><td>noid</td><td id=\"nom_2\">Tronche</td><td id=\"prenom_2\">Christophe</td></tr>"));
/* /*
* // Populate attributes of Test 03. System.out.println * // Populate attributes of Test 03. System.out.println
* ("----------------------------"); datas = new Data (); * ("----------------------------"); datas = new Data ();
* datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent * datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent
* ("identity", 0, "prenom", "Epo"); datas.setContent ("identity", 1, * ("identity", 0, "prenom", "Epo"); datas.setContent ("identity", 1,
* "nom", "Momon"); datas.setContent ("identity", 1, "prenom", * "nom", "Momon"); datas.setContent ("identity", 1, "prenom",
* "Christian"); datas.setContent ("identity", 2, "nom", "Tronche"); * "Christian"); datas.setContent ("identity", 2, "nom", "Tronche");
* datas.setContent ("identity", 2, "prenom", "Christophe"); * datas.setContent ("identity", 2, "prenom", "Christophe");
* datas.setIterationStrategy ("identity", * datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); * IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW);
* //datas.setIterationStrategy ("identity", * //datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID); * IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID);
* //datas.setIterationStrategy ("identity", * //datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID); * IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
* //datas.setIterationStrategy ("identity", * //datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ALL_ROWS); * IdsDataByIndex.IterationStrategy.ALL_ROWS);
* *
* *
* errorMessage = new StringBuffer (); source = new StringBuffer (); * errorMessage = new StringBuffer (); source = new StringBuffer ();
* source.append ("<table>\n"); source.append ( * source.append ("<table>\n"); source.append (
* " <tr id='identity'><td>noid</td><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>\n" * " <tr id='identity'><td>noid</td><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>\n"
* ); source.append ( * ); source.append (
* " <tr id='identity2'><td>noid</td><td id='nom2'>un nom</td><td id='prenom2'>un prenom</td></tr>\n" * " <tr id='identity2'><td>noid</td><td id='nom2'>un nom</td><td id='prenom2'>un prenom</td></tr>\n"
* ); source.append ( * ); source.append (
* " <tr><td>noid</td><td id='nom3'>un nom</td><td id='prenom3'>un prenom</td></tr>\n" * " <tr><td>noid</td><td id='nom3'>un nom</td><td id='prenom3'>un prenom</td></tr>\n"
* ); source.append ("</table>"); htmlSource = source.toString (); * ); source.append ("</table>"); htmlSource = source.toString ();
* *
* System.out.println ("datas = new Data ();"); System.out.println * System.out.println ("datas = new Data ();"); System.out.println
* ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");"); * ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");");
* System.out.println * System.out.println
* ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");"); * ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");");
* System.out.println * System.out.println
* ("datas.setContent (\"identity\", 1, \"nom\", \"Momon\");"); * ("datas.setContent (\"identity\", 1, \"nom\", \"Momon\");");
* System.out.println * System.out.println
* ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");"); * ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");");
* System.out.println * System.out.println
* ("datas.setContent (\"identity\", 2, \"nom\", \"Tronche\");"); * ("datas.setContent (\"identity\", 2, \"nom\", \"Tronche\");");
* System.out.println * System.out.println
* ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");"); * ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");");
* *
* System.out.println ("+"); System.out.println (htmlSource); * System.out.println ("+"); System.out.println (htmlSource);
* System.out.println ("=>"); * System.out.println ("=>");
* *
* *
* datas.setIterationStrategy ("identity", * datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); System.out.println * IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); System.out.println
* ("ONLY_FIRST_ROW:"); html = Presenter.dynamize (htmlSource, datas, "", * ("ONLY_FIRST_ROW:"); html = Presenter.dynamize (htmlSource, datas, "",
* errorMessage); System.out.println (html); * errorMessage); System.out.println (html);
* *
* datas.setIterationStrategy ("identity", * datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID); * IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID);
* System.out.println ("ONLY_ROWS_WITH_ID:"); html = Presenter.dynamize * System.out.println ("ONLY_ROWS_WITH_ID:"); html = Presenter.dynamize
* (htmlSource, datas, "", errorMessage); System.out.println (html); * (htmlSource, datas, "", errorMessage); System.out.println (html);
* *
* datas.setIterationStrategy ("identity", * datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID); * IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
* System.out.println ("ONLY_ROWS_WITHOUT_ID:"); html = Presenter.dynamize * System.out.println ("ONLY_ROWS_WITHOUT_ID:"); html = Presenter.dynamize
* (htmlSource, datas, "", errorMessage); System.out.println (html); * (htmlSource, datas, "", errorMessage); System.out.println (html);
* *
* datas.setIterationStrategy ("identity", * datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ALL_ROWS); System.out.println * IdsDataByIndex.IterationStrategy.ALL_ROWS); System.out.println
* ("ALL_ROWS:"); html = Presenter.dynamize (htmlSource, datas, "", * ("ALL_ROWS:"); html = Presenter.dynamize (htmlSource, datas, "",
* errorMessage); System.out.println (html); * errorMessage); System.out.println (html);
* *
* *
* *
* // Populate attributes of Test 03. System.out.println * // Populate attributes of Test 03. System.out.println
* ("----------------------------"); datas = new Data (); * ("----------------------------"); datas = new Data ();
* datas.setAttribute ("<div>", "class", "aDivClass"); * datas.setAttribute ("<div>", "class", "aDivClass");
* datas.setAttribute ("<div>", "style", "background-color: #000000;"); * datas.setAttribute ("<div>", "style", "background-color: #000000;");
* datas.setAttribute ("number", "style", "background-color: #0000FF;"); * datas.setAttribute ("number", "style", "background-color: #0000FF;");
* *
* errorMessage = new StringBuffer (); source = new StringBuffer (); * errorMessage = new StringBuffer (); source = new StringBuffer ();
* source.append ("<div>\n"); source.append (" <h1>one</h1>\n"); * source.append ("<div>\n"); source.append (" <h1>one</h1>\n");
* source.append ("</div>\n"); source.append ("<div id=\"number\">\n"); * source.append ("</div>\n"); source.append ("<div id=\"number\">\n");
* source.append (" <h1>three</h1>\n"); source.append ("</div>"); * source.append (" <h1>three</h1>\n"); source.append ("</div>");
* htmlSource = source.toString (); html = Presenter.dynamize (htmlSource, * htmlSource = source.toString (); html = Presenter.dynamize (htmlSource,
* datas, "", errorMessage); * datas, "", errorMessage);
* *
* System.out.println (htmlSource); System.out.println ("+"); * System.out.println (htmlSource); System.out.println ("+");
* System.out.println ("datas = new Data ();"); System.out.println * System.out.println ("datas = new Data ();"); System.out.println
* ("datas.setAttribute (\"<div>\", \"class\", \"aDivClass\");"); * ("datas.setAttribute (\"<div>\", \"class\", \"aDivClass\");");
* System.out.println ( * System.out.println (
* "datas.setAttribute (\"<div>\", \"style\", \"background-color: #000000;\");" * "datas.setAttribute (\"<div>\", \"style\", \"background-color: #000000;\");"
* ); System.out.println ( * ); System.out.println (
* "datas.setAttribute (\"number\", \"style\", \"background-color: #0000FF;\");" * "datas.setAttribute (\"number\", \"style\", \"background-color: #0000FF;\");"
* ); * );
* *
* System.out.println ("=>"); System.out.println (html); * System.out.println ("=>"); System.out.println (html);
*/ */
} }
} }

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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 = "aaaaa<body>hello</body>zzzzz";
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 = "aaaaa<body>hello</body>zzzzz";
String target = new StringPresenter(source).dynamize(null).toString();
Assertions.assertThat(target).isEqualTo(source);
}
/**
* @throws Exception
*
*/
@Test
public void testDynamize03() throws Exception
{
String source = "aaaaa<div>hello</div>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<div>hello</div>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<div>hello</div>zzzzz";
String target = PresenterUtils.dynamize(source, null).toString();
Assertions.assertThat(target).isEqualTo(source);
}
/**
* @throws Exception
*
*/
@Test
public void testStaticDynamize02() throws Exception
{
String source = "aaaaa<div>hello</div>zzzzz";
String target = PresenterUtils.dynamize(source, new TagDataManager()).toString();
Assertions.assertThat(target).isEqualTo(source);
}
}

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2014 Christian Pierre MOMON * Copyright (C) 2006-2016 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -18,11 +18,7 @@
*/ */
package fr.devinsy.xidyn.presenters; 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.fest.assertions.Assertions;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.data.TagDataManager;
@ -32,84 +28,33 @@ import fr.devinsy.xidyn.data.TagDataManager;
*/ */
public class DomPresenterTest public class DomPresenterTest
{ {
/**
*
*/
@Before
public void before()
{
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.ERROR);
}
/** /**
* @throws Exception * @throws Exception
* *
*/ */
@Test @Test
public void testDynamize01() throws Exception public void testStaticDynamize01() throws Exception
{ {
String source = "aaaaa<div>hello</div>zzzzz"; String source = "aaaaa<div>hello</div>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 * @throws Exception
* *
*/ */
@Test @Test
public void testDynamize02() throws Exception public void testStaticDynamize02() throws Exception
{ {
String source = "aaaaa<div>hello</div>zzzzz"; String source = "aaaaa<div>hello</div>zzzzz";
String target = new StringPresenter(source).dynamize(null).toString(); String target = PresenterUtils.dynamize(source, new TagDataManager()).toString();
Assertions.assertThat(target).isEqualTo(source); Assertions.assertThat(target).isEqualTo(source);
} }
/**
* @throws Exception
*
*/
@Test
public void testDynamize03() throws Exception
{
String source = "aaaaa<div>hello</div>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<div>hello</div>zzzzz";
String target = StringPresenter.dynamize(source, null).toString();
Assertions.assertThat(target).isEqualTo(source);
}
/**
* @throws Exception
*
*/
@Test
public void testStaticDynamize02() throws Exception
{
String source = "aaaaa<div>hello</div>zzzzz";
String target = StringPresenter.dynamize(source, new TagDataManager()).toString();
Assertions.assertThat(target).isEqualTo(source);
}
} }

View file

@ -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 <http://www.gnu.org/licenses/>
*/
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<div>hello</div>zzzzz";
String target = PresenterUtils.dynamize(source, null).toString();
Assertions.assertThat(target).isEqualTo(source);
}
/**
* @throws Exception
*
*/
@Test
public void testStaticDynamize02() throws Exception
{
String source = "aaaaa<div>hello</div>zzzzz";
String target = PresenterUtils.dynamize(source, new TagDataManager()).toString();
Assertions.assertThat(target).isEqualTo(source);
}
}

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2014 Christian Pierre MOMON * Copyright (C) 2006-2016 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -32,84 +32,55 @@ import fr.devinsy.xidyn.data.TagDataManager;
*/ */
public class StringPresenterTest public class StringPresenterTest
{ {
/** /**
* *
*/ */
@Before @Before
public void before() public void before()
{ {
BasicConfigurator.configure(); BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.ERROR); Logger.getRootLogger().setLevel(Level.ERROR);
} }
/** /**
* @throws Exception * @throws Exception
* *
*/ */
@Test @Test
public void testDynamize01() throws Exception public void testDynamize01() throws Exception
{ {
String source = "aaaaa<body>hello</body>zzzzz"; String source = "aaaaa<body>hello</body>zzzzz";
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 * @throws Exception
* *
*/ */
@Test @Test
public void testDynamize02() throws Exception public void testDynamize02() throws Exception
{ {
String source = "aaaaa<body>hello</body>zzzzz"; String source = "aaaaa<body>hello</body>zzzzz";
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 * @throws Exception
* *
*/ */
@Test @Test
public void testDynamize03() throws Exception public void testDynamize03() throws Exception
{ {
String source = "aaaaa<div>hello</div>zzzzz"; String source = "aaaaa<div>hello</div>zzzzz";
String target = new StringPresenter(source).dynamize(new TagDataManager()).toString(); 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<div>hello</div>zzzzz";
String target = StringPresenter.dynamize(source, null).toString();
Assertions.assertThat(target).isEqualTo(source);
}
/**
* @throws Exception
*
*/
@Test
public void testStaticDynamize02() throws Exception
{
String source = "aaaaa<div>hello</div>zzzzz";
String target = StringPresenter.dynamize(source, new TagDataManager()).toString();
Assertions.assertThat(target).isEqualTo(source);
}
Assertions.assertThat(target).isEqualTo(source);
}
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2014 Christian Pierre MOMON * Copyright (C) 2006-2016 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -30,151 +30,151 @@ import org.junit.Test;
*/ */
public class XidynUtilsTest public class XidynUtilsTest
{ {
/** /**
* *
*/ */
@Before @Before
public void before() public void before()
{ {
BasicConfigurator.configure(); BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.ERROR); Logger.getRootLogger().setLevel(Level.ERROR);
} }
/** /**
* *
*/ */
@Test @Test
public void testExtractBodyContent01() public void testExtractBodyContent01()
{ {
String source = "aaaaa<boDY>hello</Body>zzzzz"; String source = "aaaaa<boDY>hello</Body>zzzzz";
String target = XidynUtils.extractBodyContent(source); String target = XidynUtils.extractBodyContent(source);
Assertions.assertThat(target).isEqualTo("hello"); Assertions.assertThat(target).isEqualTo("hello");
} }
/** /**
* *
*/ */
@Test @Test
public void testExtractBodyContent02() public void testExtractBodyContent02()
{ {
String source = "aaaaaaa<boDY>hello</Bod>zzzzz"; String source = "aaaaaaa<boDY>hello</Bod>zzzzz";
String target = XidynUtils.extractBodyContent(source); String target = XidynUtils.extractBodyContent(source);
Assertions.assertThat(target).isEqualTo(""); Assertions.assertThat(target).isEqualTo("");
} }
/** /**
* *
*/ */
@Test @Test
public void testExtractBodyContent03() public void testExtractBodyContent03()
{ {
String source = "aaaaa<body></BodY>zzzzz"; String source = "aaaaa<body></BodY>zzzzz";
String target = XidynUtils.extractBodyContent(source); String target = XidynUtils.extractBodyContent(source);
Assertions.assertThat(target).isEqualTo(""); Assertions.assertThat(target).isEqualTo("");
} }
/** /**
* *
*/ */
@Test @Test
public void testExtractBodyContent04() public void testExtractBodyContent04()
{ {
String source = "aaaaa<boDY> hello </body>zzzzz"; String source = "aaaaa<boDY> hello </body>zzzzz";
String target = XidynUtils.extractBodyContent(source); String target = XidynUtils.extractBodyContent(source);
Assertions.assertThat(target).isEqualTo("hello"); Assertions.assertThat(target).isEqualTo("hello");
} }
/** /**
* *
*/ */
@Test @Test
public void testExtractBodyContent05() public void testExtractBodyContent05()
{ {
StringBuffer buffer = new StringBuffer(1000); StringBuffer buffer = new StringBuffer(1000);
buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").append("\n"); buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").append("\n");
buffer.append("<!DOCTYPE html>").append("\n"); buffer.append("<!DOCTYPE html>").append("\n");
buffer.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">").append("\n"); buffer.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">").append("\n");
buffer.append("<head>").append("\n"); buffer.append("<head>").append("\n");
buffer.append("<title>Kinsources</title>").append("\n"); buffer.append("<title>Kinsources</title>").append("\n");
buffer.append("<meta charset=\"UTF-8\" />").append("\n"); buffer.append("<meta charset=\"UTF-8\" />").append("\n");
buffer.append("<link rel=\"icon\" type=\"image/x-icon\" href=\"/favicon.ico\" />").append("\n"); buffer.append("<link rel=\"icon\" type=\"image/x-icon\" href=\"/favicon.ico\" />").append("\n");
buffer.append(" <link rel=\"stylesheet\" type=\"text/css\" href=\"kiwa.css\" />").append("\n"); buffer.append(" <link rel=\"stylesheet\" type=\"text/css\" href=\"kiwa.css\" />").append("\n");
buffer.append("<meta content=\"kinsources, puck, devinsy, gedcom\" name=\"keywords\" />").append("\n"); buffer.append("<meta content=\"kinsources, puck, devinsy, gedcom\" name=\"keywords\" />").append("\n");
buffer.append("</head>").append("\n"); buffer.append("</head>").append("\n");
buffer.append("<body>"); buffer.append("<body>");
buffer.append("WELCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOME"); buffer.append("WELCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOME");
buffer.append("</body>").append("\n"); buffer.append("</body>").append("\n");
buffer.append("</html>").append("\n"); buffer.append("</html>").append("\n");
String source = buffer.toString(); String source = buffer.toString();
// System.out.println("[" + source + "]"); // System.out.println("[" + source + "]");
String target = XidynUtils.extractBodyContent(source); String target = XidynUtils.extractBodyContent(source);
Assertions.assertThat(target).isEqualTo("WELCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOME"); Assertions.assertThat(target).isEqualTo("WELCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOME");
} }
/** /**
* *
*/ */
@Test @Test
public void testExtractDoctype01() public void testExtractDoctype01()
{ {
String source = "aaaaa<boDY>hello</Body>zzzzz"; String source = "aaaaa<boDY>hello</Body>zzzzz";
String target = XidynUtils.extractDoctype(source); String target = XidynUtils.extractDoctype(source);
Assertions.assertThat(target).isNull(); Assertions.assertThat(target).isNull();
} }
/** /**
* *
*/ */
@Test @Test
public void testExtractDoctype02() public void testExtractDoctype02()
{ {
String source = "<html xmlns='http://www.w3.org/1999/xhtml'>aaaaa<boDY>hello</Body>zzzzz"; String source = "<html xmlns='http://www.w3.org/1999/xhtml'>aaaaa<boDY>hello</Body>zzzzz";
String target = XidynUtils.extractDoctype(source); String target = XidynUtils.extractDoctype(source);
Assertions.assertThat(target).isEqualTo(""); Assertions.assertThat(target).isEqualTo("");
} }
/** /**
* *
*/ */
@Test @Test
public void testExtractDoctype03() public void testExtractDoctype03()
{ {
String source = "<!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'>aaaaa<boDY>hello</Body>zzzzz"; String source = "<!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'>aaaaa<boDY>hello</Body>zzzzz";
String target = XidynUtils.extractDoctype(source); String target = XidynUtils.extractDoctype(source);
Assertions.assertThat(target).isEqualTo("<!DOCTYPE html>"); Assertions.assertThat(target).isEqualTo("<!DOCTYPE html>");
} }
/** /**
* *
*/ */
@Test @Test
public void testExtractDoctype04() public void testExtractDoctype04()
{ {
String source = "<?xml version='1.0' encoding='UTF-8' ?><!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'>aaaaa<boDY>hello</Body>zzzzz"; String source = "<?xml version='1.0' encoding='UTF-8' ?><!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'>aaaaa<boDY>hello</Body>zzzzz";
String target = XidynUtils.extractDoctype(source); String target = XidynUtils.extractDoctype(source);
Assertions.assertThat(target).isEqualTo("<?xml version='1.0' encoding='UTF-8' ?><!DOCTYPE html>"); Assertions.assertThat(target).isEqualTo("<?xml version='1.0' encoding='UTF-8' ?><!DOCTYPE html>");
} }
/** /**
* *
*/ */
@Test @Test
public void testExtractDoctype05() public void testExtractDoctype05()
{ {
String source = "<?xml version='1.0' encoding='UTF-8' ?><!-- TOTOT --><!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'>aaaaa<boDY>hello</Body>zzzzz"; String source = "<?xml version='1.0' encoding='UTF-8' ?><!-- TOTOT --><!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'>aaaaa<boDY>hello</Body>zzzzz";
String target = XidynUtils.extractDoctype(source); String target = XidynUtils.extractDoctype(source);
Assertions.assertThat(target).isEqualTo("<?xml version='1.0' encoding='UTF-8' ?><!-- TOTOT --><!DOCTYPE html>"); Assertions.assertThat(target).isEqualTo("<?xml version='1.0' encoding='UTF-8' ?><!-- TOTOT --><!DOCTYPE html>");
} }
} }