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
org.eclipse.jdt.core.codeComplete.argumentPrefixes=
org.eclipse.jdt.core.codeComplete.argumentSuffixes=
org.eclipse.jdt.core.codeComplete.fieldPrefixes=
org.eclipse.jdt.core.codeComplete.fieldSuffixes=
org.eclipse.jdt.core.codeComplete.localPrefixes=
org.eclipse.jdt.core.codeComplete.localSuffixes=
org.eclipse.jdt.core.codeComplete.staticFieldPrefixes=
org.eclipse.jdt.core.codeComplete.staticFieldSuffixes=
org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes=
org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes=
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
@ -21,7 +31,7 @@ org.eclipse.jdt.core.formatter.alignment_for_assignment=0
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=49
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
@ -60,7 +70,7 @@ org.eclipse.jdt.core.formatter.brace_position_for_switch=next_line
org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=next_line
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
org.eclipse.jdt.core.formatter.comment.format_block_comments=true
org.eclipse.jdt.core.formatter.comment.format_block_comments=false
org.eclipse.jdt.core.formatter.comment.format_header=false
org.eclipse.jdt.core.formatter.comment.format_html=true
org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
@ -85,12 +95,12 @@ org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_de
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=false
org.eclipse.jdt.core.formatter.indent_empty_lines=false
org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true
org.eclipse.jdt.core.formatter.indentation.size=4
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
@ -287,7 +297,7 @@ org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
org.eclipse.jdt.core.formatter.tabulation.char=tab
org.eclipse.jdt.core.formatter.tabulation.char=space
org.eclipse.jdt.core.formatter.tabulation.size=4
org.eclipse.jdt.core.formatter.use_on_off_tags=false
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false

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
formatter_profile=_Devinsy
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_Xidyn
formatter_settings_version=12
org.eclipse.jdt.ui.exception.name=exception
org.eclipse.jdt.ui.gettersetter.use.is=true
org.eclipse.jdt.ui.keywordthis=false
org.eclipse.jdt.ui.overrideannotation=true
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true
sp_cleanup.add_missing_deprecated_annotations=true
sp_cleanup.add_missing_methods=false
sp_cleanup.add_missing_nls_tags=false
sp_cleanup.add_missing_override_annotations=true
sp_cleanup.add_missing_override_annotations_interface_methods=true
sp_cleanup.add_serial_version_id=false
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=false
sp_cleanup.always_use_this_for_non_static_field_access=true
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.correct_indentation=true
sp_cleanup.format_source_code=true
sp_cleanup.format_source_code_changes_only=false
sp_cleanup.make_local_variable_final=false
sp_cleanup.make_parameters_final=true
sp_cleanup.make_private_fields_final=false
sp_cleanup.make_type_abstract_if_missing_method=false
sp_cleanup.make_variable_declarations_final=true
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=true
sp_cleanup.on_save_use_additional_actions=true
sp_cleanup.organize_imports=true
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=true
sp_cleanup.remove_trailing_whitespaces=false
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
sp_cleanup.remove_unnecessary_casts=true
sp_cleanup.remove_unnecessary_nls_tags=true
sp_cleanup.remove_unused_imports=true
sp_cleanup.remove_unused_local_variables=false
sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=false
sp_cleanup.remove_unused_private_methods=true
sp_cleanup.remove_unused_private_types=true
sp_cleanup.sort_members=true
sp_cleanup.sort_members_all=false
sp_cleanup.use_blocks=true
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_parentheses_in_expressions=false
sp_cleanup.use_this_for_non_static_field_access=true
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=false
sp_cleanup.use_this_for_non_static_method_access=false
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true

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

View file

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

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.
*
@ -34,161 +34,167 @@ import java.io.Serializable;
*/
public class SimpleTagData implements Serializable, TagData
{
public enum IterationStrategy
{
ONLY_FIRST_ROW, ONLY_FIRST_TWO_ROWS, ONLY_ROWS_WITH_ID, ONLY_ROWS_WITHOUT_ID, ALL_ROWS
}
public enum IterationStrategy
{
ONLY_FIRST_ROW,
ONLY_FIRST_TWO_ROWS,
ONLY_ROWS_WITH_ID,
ONLY_ROWS_WITHOUT_ID,
ALL_ROWS
}
public enum MODE
{
REPLACE, APPEND, IGNORE
}
public enum MODE
{
REPLACE,
APPEND,
IGNORE
}
private static final long serialVersionUID = 8976245034682639923L;;
private static final long serialVersionUID = 8976245034682639923L;;
private IterationStrategy iterationStrategy;
private TagAttributes attributes;
private boolean excludeSection;
private MODE displayMode = MODE.REPLACE;
private String content;
private IterationStrategy iterationStrategy;
private TagAttributes attributes;
private boolean excludeSection;
private MODE displayMode = MODE.REPLACE;
private String content;
/**
/**
*
*/
public SimpleTagData()
{
this.attributes = null;
this.excludeSection = false;
this.displayMode = MODE.REPLACE;
this.content = null;
this.iterationStrategy = IterationStrategy.ALL_ROWS;
}
public SimpleTagData()
{
this.attributes = null;
this.excludeSection = false;
this.displayMode = MODE.REPLACE;
this.content = null;
this.iterationStrategy = IterationStrategy.ALL_ROWS;
}
/**
/**
*
*/
public SimpleTagData(final String text)
{
this.attributes = null;
this.excludeSection = false;
this.displayMode = MODE.REPLACE;
this.content = text;
this.iterationStrategy = IterationStrategy.ALL_ROWS;
}
public SimpleTagData(final String text)
{
this.attributes = null;
this.excludeSection = false;
this.displayMode = MODE.REPLACE;
this.content = text;
this.iterationStrategy = IterationStrategy.ALL_ROWS;
}
/**
/**
*
*/
public void appendContent(final String text)
{
if (this.content == null)
{
this.content = text;
}
else
{
this.content += text;
}
}
public void appendContent(final String text)
{
if (this.content == null)
{
this.content = text;
}
else
{
this.content += text;
}
}
/**
/**
*
*/
public TagAttributes attributes()
{
TagAttributes result;
public TagAttributes attributes()
{
TagAttributes result;
if (this.attributes == null)
{
this.attributes = new TagAttributes();
}
if (this.attributes == null)
{
this.attributes = new TagAttributes();
}
result = this.attributes;
result = this.attributes;
//
return (result);
}
//
return (result);
}
/**
/**
*
*/
public String display()
{
String result;
public String display()
{
String result;
result = this.content;
result = this.content;
//
return (result);
}
//
return (result);
}
/**
/**
*
*/
public MODE displayMode()
{
MODE result;
public MODE displayMode()
{
MODE result;
result = this.displayMode;
result = this.displayMode;
return (result);
}
return (result);
}
/**
/**
*
*/
public boolean excludeSection()
{
boolean result;
public boolean excludeSection()
{
boolean result;
result = this.excludeSection;
result = this.excludeSection;
//
return (result);
}
//
return (result);
}
/**
/**
*
*/
public IterationStrategy iterationStrategy()
{
IterationStrategy result;
public IterationStrategy iterationStrategy()
{
IterationStrategy result;
result = this.iterationStrategy;
result = this.iterationStrategy;
//
return (result);
}
//
return (result);
}
/**
/**
*
*/
public void setContent(final String text)
{
this.content = text;
}
public void setContent(final String text)
{
this.content = text;
}
/**
/**
*
*/
public void setDisplayMode(final MODE displayMode)
{
this.displayMode = displayMode;
}
public void setDisplayMode(final MODE displayMode)
{
this.displayMode = displayMode;
}
/**
/**
*
*/
public void setExcludeSection(final boolean excludeSection)
{
this.excludeSection = excludeSection;
}
public void setExcludeSection(final boolean excludeSection)
{
this.excludeSection = excludeSection;
}
/**
/**
*
*/
public void setIterationStrategy(final IterationStrategy strategy)
{
this.iterationStrategy = strategy;
}
public void setIterationStrategy(final IterationStrategy strategy)
{
this.iterationStrategy = strategy;
}
}

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

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.
*

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.
*
@ -26,35 +26,35 @@ import java.util.HashMap;
public class TagDataListById extends HashMap<String, TagData> implements TagData
{
private static final long serialVersionUID = -5787252043825503554L;
private static final long serialVersionUID = -5787252043825503554L;
/**
/**
*
*/
public TagDataListById()
{
super();
}
public TagDataListById()
{
super();
}
/**
/**
*
*/
public TagData getId(final String id)
{
TagData result;
public TagData getId(final String id)
{
TagData result;
result = this.get(id);
result = this.get(id);
//
return (result);
}
//
return (result);
}
/**
/**
*
*/
public void setId(final String id, final TagData data)
{
this.put(id, data);
}
public void setId(final String id, final TagData data)
{
this.put(id, data);
}
}

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.
*
@ -26,13 +26,13 @@ import java.util.Vector;
public class TagDataListByIndex extends Vector<TagData> implements TagData
{
private static final long serialVersionUID = 215545720925753884L;
private static final long serialVersionUID = 215545720925753884L;
/**
/**
*
*/
public TagDataListByIndex()
{
super();
}
public TagDataListByIndex()
{
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.
*
@ -23,308 +23,308 @@ package fr.devinsy.xidyn.data;
*/
public class TagDataManager
{
private TagDataListById idsDataById;
private TagDataListById idsDataById;
/**
/**
*
*/
public TagDataManager()
{
this.idsDataById = new TagDataListById();
}
public TagDataManager()
{
this.idsDataById = new TagDataListById();
}
/**
/**
*
*/
public void appendAttribute(final String id, final int line, final String column, final String label, final String value)
{
SimpleTagData tag = this.getIdData(id, line, column);
public void appendAttribute(final String id, final int line, final String column, final String label, final String value)
{
SimpleTagData tag = this.getIdData(id, line, column);
tag.attributes().appendAttribute(label, value);
}
tag.attributes().appendAttribute(label, value);
}
/**
/**
*
*/
public void appendAttribute(final String id, final String label, final long value)
{
appendAttribute(id, label, String.valueOf(value));
}
public void appendAttribute(final String id, final String label, final long value)
{
appendAttribute(id, label, String.valueOf(value));
}
/**
/**
*
*/
public void appendAttribute(final String id, final String label, final String value)
{
SimpleTagData tag = this.getIdData(id);
public void appendAttribute(final String id, final String label, final String value)
{
SimpleTagData tag = this.getIdData(id);
tag.attributes().appendAttribute(label, value);
}
tag.attributes().appendAttribute(label, value);
}
/**
/**
*
*/
public void appendContent(final String id, final int line, final long value)
{
appendContent(id, line, String.valueOf(value));
}
public void appendContent(final String id, final int line, final long value)
{
appendContent(id, line, String.valueOf(value));
}
/**
/**
*
*/
public void appendContent(final String id, final int line, final String value)
{
SimpleTagData tag = this.getIdData(id, line);
public void appendContent(final String id, final int line, final String value)
{
SimpleTagData tag = this.getIdData(id, line);
tag.appendContent(value);
}
tag.appendContent(value);
}
/**
/**
*
*/
public void appendContent(final String id, final int line, final String column, final long value)
{
appendContent(id, line, column, String.valueOf(value));
}
public void appendContent(final String id, final int line, final String column, final long value)
{
appendContent(id, line, column, String.valueOf(value));
}
/**
/**
*
*/
public void appendContent(final String id, final int line, final String column, final String value)
{
SimpleTagData tag = this.getIdData(id, line, column);
public void appendContent(final String id, final int line, final String column, final String value)
{
SimpleTagData tag = this.getIdData(id, line, column);
tag.appendContent(value);
}
tag.appendContent(value);
}
/**
/**
*
*/
public SimpleTagData getIdData(final String id)
{
SimpleTagData result;
public SimpleTagData getIdData(final String id)
{
SimpleTagData result;
// Be sure that IdData is existing and get item.
result = (SimpleTagData) this.idsDataById.getId(id);
// Be sure that IdData is existing and get item.
result = (SimpleTagData) this.idsDataById.getId(id);
if (result == null)
{
this.idsDataById.setId(id, new SimpleTagData());
if (result == null)
{
this.idsDataById.setId(id, new SimpleTagData());
result = (SimpleTagData) this.idsDataById.getId(id);
}
result = (SimpleTagData) this.idsDataById.getId(id);
}
//
return (result);
}
//
return (result);
}
/**
/**
*
*/
public SimpleTagData getIdData(final String id, final int line)
{
SimpleTagData result;
public SimpleTagData getIdData(final String id, final int line)
{
SimpleTagData result;
// Be sure that IdsData are existing.
TagDataListByIndex tags = (TagDataListByIndex) this.idsDataById.getId(id);
if (tags == null)
{
this.idsDataById.setId(id, new TagDataListByIndex());
// Be sure that IdsData are existing.
TagDataListByIndex tags = (TagDataListByIndex) this.idsDataById.getId(id);
if (tags == null)
{
this.idsDataById.setId(id, new TagDataListByIndex());
tags = (TagDataListByIndex) this.idsDataById.getId(id);
}
tags = (TagDataListByIndex) this.idsDataById.getId(id);
}
// Be sure that lines are existing.
int nbLines = tags.size();
for (int nLine = nbLines; nLine < line + 1; nLine++)
{
tags.add(nLine, new SimpleTagData());
}
// Be sure that lines are existing.
int nbLines = tags.size();
for (int nLine = nbLines; nLine < line + 1; nLine++)
{
tags.add(nLine, new SimpleTagData());
}
// Get item.
result = (SimpleTagData) tags.elementAt(line);
// Get item.
result = (SimpleTagData) tags.elementAt(line);
//
return (result);
}
//
return (result);
}
/**
/**
*
*/
public SimpleTagData getIdData(final String id, final int line, final String column)
{
SimpleTagData result;
public SimpleTagData getIdData(final String id, final int line, final String column)
{
SimpleTagData result;
// Be sure that IdsData are existing.
TagDataListByIndex tags = (TagDataListByIndex) this.idsDataById.getId(id);
if (tags == null)
{
this.idsDataById.setId(id, new TagDataListByIndex());
// Be sure that IdsData are existing.
TagDataListByIndex tags = (TagDataListByIndex) this.idsDataById.getId(id);
if (tags == null)
{
this.idsDataById.setId(id, new TagDataListByIndex());
tags = (TagDataListByIndex) this.idsDataById.getId(id);
}
tags = (TagDataListByIndex) this.idsDataById.getId(id);
}
// Be sure that lines are existing.
int nbLines = tags.size();
for (int nLine = nbLines; nLine < line + 1; nLine++)
{
tags.add(nLine, new TagDataListById());
}
// Be sure that lines are existing.
int nbLines = tags.size();
for (int nLine = nbLines; nLine < line + 1; nLine++)
{
tags.add(nLine, new TagDataListById());
}
// Get item.
TagDataListById lineData = (TagDataListById) tags.elementAt(line);
// Get item.
TagDataListById lineData = (TagDataListById) tags.elementAt(line);
result = (SimpleTagData) lineData.get(column);
result = (SimpleTagData) lineData.get(column);
if (result == null)
{
lineData.put(column, new SimpleTagData());
if (result == null)
{
lineData.put(column, new SimpleTagData());
result = (SimpleTagData) lineData.get(column);
}
result = (SimpleTagData) lineData.get(column);
}
//
return (result);
}
//
return (result);
}
/**
/**
*
*/
public TagDataListById getIdsDataById()
{
TagDataListById result;
public TagDataListById getIdsDataById()
{
TagDataListById result;
result = this.idsDataById;
result = this.idsDataById;
//
return (result);
}
//
return (result);
}
/**
/**
*
*/
public void setAttribute(final String id, final int line, final String label, final long value)
{
setAttribute(id, line, label, String.valueOf(value));
}
public void setAttribute(final String id, final int line, final String label, final long value)
{
setAttribute(id, line, label, String.valueOf(value));
}
/**
/**
*
*/
public void setAttribute(final String id, final int line, final String label, final String value)
{
SimpleTagData tag = this.getIdData(id, line);
public void setAttribute(final String id, final int line, final String label, final String value)
{
SimpleTagData tag = this.getIdData(id, line);
tag.attributes().setAttribute(label, value);
}
tag.attributes().setAttribute(label, value);
}
/**
/**
*
*/
public void setAttribute(final String id, final int line, final String column, final String label, final long value)
{
setAttribute(id, line, column, label, String.valueOf(value));
}
public void setAttribute(final String id, final int line, final String column, final String label, final long value)
{
setAttribute(id, line, column, label, String.valueOf(value));
}
/**
/**
*
*/
public void setAttribute(final String id, final int line, final String column, final String label, final String value)
{
SimpleTagData tag = this.getIdData(id, line, column);
public void setAttribute(final String id, final int line, final String column, final String label, final String value)
{
SimpleTagData tag = this.getIdData(id, line, column);
tag.attributes().setAttribute(label, value);
}
tag.attributes().setAttribute(label, value);
}
/**
/**
*
*/
public void setAttribute(final String id, final String label, final long value)
{
setAttribute(id, label, String.valueOf(value));
}
public void setAttribute(final String id, final String label, final long value)
{
setAttribute(id, label, String.valueOf(value));
}
/**
/**
*
*/
public void setAttribute(final String id, final String label, final String value)
{
SimpleTagData tag = this.getIdData(id);
public void setAttribute(final String id, final String label, final String value)
{
SimpleTagData tag = this.getIdData(id);
tag.attributes().setAttribute(label, value);
}
tag.attributes().setAttribute(label, value);
}
/**
/**
*
*/
public void setContent(final String id, final int line, final long value)
{
setContent(id, line, String.valueOf(value));
}
public void setContent(final String id, final int line, final long value)
{
setContent(id, line, String.valueOf(value));
}
/**
/**
*
*/
public void setContent(final String id, final int line, final String content)
{
SimpleTagData tag = this.getIdData(id, line);
public void setContent(final String id, final int line, final String content)
{
SimpleTagData tag = this.getIdData(id, line);
tag.setContent(content);
}
tag.setContent(content);
}
/**
* @TODO
*/
public void setContent(final String id, final int line, final String subId, final int subLine, final String column, final String content)
{
// IdData tag = this.getIdData (id, line, subId, subLine, column);
/**
* @TODO
*/
public void setContent(final String id, final int line, final String subId, final int subLine, final String column, final String content)
{
// IdData tag = this.getIdData (id, line, subId, subLine, column);
// tag.setContent (content);
}
// tag.setContent (content);
}
/**
/**
*
*/
public void setContent(final String id, final int line, final String column, final long value)
{
setContent(id, line, column, String.valueOf(value));
}
public void setContent(final String id, final int line, final String column, final long value)
{
setContent(id, line, column, String.valueOf(value));
}
/**
/**
*
*/
public void setContent(final String id, final int line, final String column, final String content)
{
SimpleTagData tag = this.getIdData(id, line, column);
public void setContent(final String id, final int line, final String column, final String content)
{
SimpleTagData tag = this.getIdData(id, line, column);
tag.setContent(content);
}
tag.setContent(content);
}
/**
/**
*
*/
public void setContent(final String id, final long value)
{
setContent(id, String.valueOf(value));
}
public void setContent(final String id, final long value)
{
setContent(id, String.valueOf(value));
}
/**
/**
*
*/
public void setContent(final String id, final String content)
{
SimpleTagData idData = this.getIdData(id);
public void setContent(final String id, final String content)
{
SimpleTagData idData = this.getIdData(id);
idData.setContent(content);
}
idData.setContent(content);
}
/**
/**
*
*/
public void setIterationStrategy(final String id, final SimpleTagData.IterationStrategy strategy)
{
SimpleTagData tag = this.getIdData(id);
public void setIterationStrategy(final String id, final SimpleTagData.IterationStrategy strategy)
{
SimpleTagData tag = this.getIdData(id);
tag.setIterationStrategy(strategy);
}
tag.setIterationStrategy(strategy);
}
}

View file

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

View file

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

View file

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

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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

View file

@ -33,321 +33,321 @@ import fr.devinsy.xidyn.utils.XidynUtils;
*/
public class URLPresenter extends StringPresenter
{
private static Logger logger = LoggerFactory.getLogger(URLPresenter.class);
private static Logger logger = LoggerFactory.getLogger(URLPresenter.class);
private String sourcePathname;
private URL source;
private long sourceTime;
private String sourcePathname;
private URL source;
private long sourceTime;
/**
/**
*
*/
public URLPresenter()
{
super();
setSource((URL) null);
}
public URLPresenter()
{
super();
setSource((URL) null);
}
/**
/**
*
*/
public URLPresenter(final String source)
{
super();
setSource(source);
}
public URLPresenter(final String source)
{
super();
setSource(source);
}
/**
/**
*
*/
public URLPresenter(final URL source)
{
super();
setSource(source);
}
public URLPresenter(final URL source)
{
super();
setSource(source);
}
/**
* No need to be synchronized.
*/
@Override
public StringBuffer dynamize() throws Exception
{
StringBuffer result;
/**
* No need to be synchronized.
*/
@Override
public StringBuffer dynamize() throws Exception
{
StringBuffer result;
//
update();
//
update();
//
result = super.dynamize();
//
result = super.dynamize();
//
return result;
}
//
return result;
}
/**
* No need to be synchronized.
*/
@Override
public StringBuffer dynamize(final TagDataManager data) throws Exception
{
StringBuffer result;
/**
* No need to be synchronized.
*/
@Override
public StringBuffer dynamize(final TagDataManager data) throws Exception
{
StringBuffer result;
logger.info("dynamize URL [" + this.sourcePathname + "]");
logger.info("dynamize URL [" + this.sourcePathname + "]");
//
update();
//
update();
// Build the web page.
result = super.dynamize(data);
// Build the web page.
result = super.dynamize(data);
//
return (result);
}
//
return (result);
}
/**
* {@inheritDoc}
*/
@Override
public String getSource()
{
String result;
/**
* {@inheritDoc}
*/
@Override
public String getSource()
{
String result;
result = this.sourcePathname;
result = this.sourcePathname;
//
return (result);
}
//
return (result);
}
/**
/**
*
*/
public URL getURL()
{
URL result;
public URL getURL()
{
URL result;
result = this.source;
result = this.source;
//
return (result);
}
//
return (result);
}
/**
* {@inheritDoc}
*/
@Override
public boolean isAvailable()
{
boolean result;
/**
* {@inheritDoc}
*/
@Override
public boolean isAvailable()
{
boolean result;
if (this.source == null)
{
result = false;
}
else if (this.sourcePathname.startsWith("/"))
{
/*
* In case of Jar resources, if resource does not exist then
* this.source is null. So, if we are here in the code then
* this.source is not null and so resource is available.
*/
result = true;
}
else
{
/*
* The source is an URL with protocol. Open a stream is the only way to test if the resource is available.
*/
try
{
this.source.openStream();
result = true;
}
catch (final IOException exception)
{
/*
* On URL.openStream:
* <ul>
* <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>
* </ul>
* These exceptions are IOException.
*/
result = false;
}
}
if (this.source == null)
{
result = false;
}
else if (this.sourcePathname.startsWith("/"))
{
/*
* In case of Jar resources, if resource does not exist then
* this.source is null. So, if we are here in the code then
* this.source is not null and so resource is available.
*/
result = true;
}
else
{
/*
* The source is an URL with protocol. Open a stream is the only way to test if the resource is available.
*/
try
{
this.source.openStream();
result = true;
}
catch (final IOException exception)
{
/*
* On URL.openStream:
* <ul>
* <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>
* </ul>
* These exceptions are IOException.
*/
result = false;
}
}
//
return result;
}
//
return result;
}
/**
* {@inheritDoc}
*
* @throws IOException
*/
@Override
public boolean isOutdated() throws Exception
{
boolean result;
/**
* {@inheritDoc}
*
* @throws IOException
*/
@Override
public boolean isOutdated() throws Exception
{
boolean result;
//
if (super.isOutdated())
{
result = true;
}
else if (this.sourceTime == this.source.openConnection().getLastModified())
{
result = true;
}
else
{
result = false;
}
//
if (super.isOutdated())
{
result = true;
}
else if (this.sourceTime == this.source.openConnection().getLastModified())
{
result = true;
}
else
{
result = false;
}
//
return result;
}
//
return result;
}
/**
/**
*
*/
@Override
public void setSource(final String source)
{
//
if (source == null)
{
this.source = null;
this.sourcePathname = null;
this.sourceTime = 0;
super.setSource(null);
}
else
{
//
URL url;
if (source.matches(".+://.+"))
{
try
{
url = new URL(source);
}
catch (final MalformedURLException exception)
{
// TODO
logger.warn("UNKNOWN PROTOCOL [" + source + "]");
url = null;
}
}
else
{
url = URLPresenter.class.getResource(source);
}
@Override
public void setSource(final String source)
{
//
if (source == null)
{
this.source = null;
this.sourcePathname = null;
this.sourceTime = 0;
super.setSource(null);
}
else
{
//
URL url;
if (source.matches(".+://.+"))
{
try
{
url = new URL(source);
}
catch (final MalformedURLException exception)
{
// TODO
logger.warn("UNKNOWN PROTOCOL [" + source + "]");
url = null;
}
}
else
{
url = URLPresenter.class.getResource(source);
}
//
if (url == null)
{
this.source = null;
this.sourcePathname = source;
this.sourceTime = 0;
super.setSource(null);
}
else
{
this.source = url;
this.sourcePathname = source;
this.sourceTime = 0;
super.setSource(null);
}
}
}
//
if (url == null)
{
this.source = null;
this.sourcePathname = source;
this.sourceTime = 0;
super.setSource(null);
}
else
{
this.source = url;
this.sourcePathname = source;
this.sourceTime = 0;
super.setSource(null);
}
}
}
/**
*
* @param source
*/
public void setSource(final URL source)
{
if (source == null)
{
this.source = null;
this.sourcePathname = null;
this.sourceTime = 0;
super.setSource(null);
}
else
{
this.source = source;
this.sourcePathname = source.toString();
this.sourceTime = 0;
super.setSource(null);
}
}
/**
*
* @param source
*/
public void setSource(final URL source)
{
if (source == null)
{
this.source = null;
this.sourcePathname = null;
this.sourceTime = 0;
super.setSource(null);
}
else
{
this.source = source;
this.sourcePathname = source.toString();
this.sourceTime = 0;
super.setSource(null);
}
}
/**
/**
*
*/
@Override
public String toString()
{
String result;
@Override
public String toString()
{
String result;
try
{
//
update();
try
{
//
update();
//
result = super.getSource();
}
catch (final Exception exception)
{
result = null;
}
//
result = super.getSource();
}
catch (final Exception exception)
{
result = null;
}
//
return result;
}
//
return result;
}
/**
* No need to be synchronized.
*
* @throws Exception
*/
@Override
public void update() throws Exception
{
//
if (this.source == null)
{
String errorMessage = "source not defined (" + this.sourcePathname + ")";
logger.error(errorMessage);
throw new NullPointerException(errorMessage);
}
else
{
try
{
long currentSourceTime = this.source.openConnection().getLastModified();
if ((super.getSource() == null) || (this.sourceTime != currentSourceTime))
{
super.setSource(XidynUtils.load(this.source));
this.sourceTime = currentSourceTime;
}
}
catch (final IOException exception)
{
/* On URL.openStream:
* <ul>
* <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>
* </ul>
* These exceptions are IOException.
*/
String errorMessage = "source file defined but not readable (" + this.source.toString() + ")";
logger.error(errorMessage);
throw new Exception(errorMessage);
}
}
}
/**
* No need to be synchronized.
*
* @throws Exception
*/
@Override
public void update() throws Exception
{
//
if (this.source == null)
{
String errorMessage = "source not defined (" + this.sourcePathname + ")";
logger.error(errorMessage);
throw new NullPointerException(errorMessage);
}
else
{
try
{
long currentSourceTime = this.source.openConnection().getLastModified();
if ((super.getSource() == null) || (this.sourceTime != currentSourceTime))
{
super.setSource(XidynUtils.load(this.source));
this.sourceTime = currentSourceTime;
}
}
catch (final IOException exception)
{
/* On URL.openStream:
* <ul>
* <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>
* </ul>
* These exceptions are IOException.
*/
String errorMessage = "source file defined but not readable (" + this.source.toString() + ")";
logger.error(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.
*
@ -33,157 +33,157 @@ import org.xml.sax.SAXParseException;
*/
public class ParserErrorHandler implements ErrorHandler
{
private Vector<String> messages;
private int fatalErrorsCount;
private int errorsCount;
private int warningCount;
private Vector<String> messages;
private int fatalErrorsCount;
private int errorsCount;
private int warningCount;
public ParserErrorHandler()
{
this.fatalErrorsCount = 0;
this.errorsCount = 0;
this.warningCount = 0;
this.messages = new Vector<String>();
}
public ParserErrorHandler()
{
this.fatalErrorsCount = 0;
this.errorsCount = 0;
this.warningCount = 0;
this.messages = new Vector<String>();
}
/**
/**
*
*/
public int allErrorsCount()
{
int result;
public int allErrorsCount()
{
int result;
result = fatalErrorsCount() + errorsCount() + warningCount();
result = fatalErrorsCount() + errorsCount() + warningCount();
//
return (result);
}
//
return (result);
}
/**
* Called by the XML parser to handle fatal errors.
*
* @param ex
* Parse Excpetion. Contains the warning text and the line
* number.
*/
@Override
public void error(final SAXParseException exception)
{
String message = "Error at line " + exception.getLineNumber() + " : " + exception.getMessage();
/**
* Called by the XML parser to handle fatal errors.
*
* @param ex
* Parse Excpetion. Contains the warning text and the line
* number.
*/
@Override
public void error(final SAXParseException exception)
{
String message = "Error at line " + exception.getLineNumber() + " : " + exception.getMessage();
this.errorsCount += 1;
this.messages.add(message);
}
this.errorsCount += 1;
this.messages.add(message);
}
/**
/**
*
*/
public int errorsCount()
{
int result;
public int errorsCount()
{
int result;
result = this.errorsCount;
result = this.errorsCount;
//
return (result);
}
//
return (result);
}
/**
* Called by the XML parser to handle fatal errors.
*
* @param ex
* Parse Excpetion. Contains the error text and the line number.
* When a fatal parse error occurs, the parse does not return a
* document.
*/
@Override
public void fatalError(final SAXParseException exception)
{
String message = "Fatal error at line " + exception.getLineNumber() + " : " + exception.getMessage();
/**
* Called by the XML parser to handle fatal errors.
*
* @param ex
* Parse Excpetion. Contains the error text and the line number.
* When a fatal parse error occurs, the parse does not return a
* document.
*/
@Override
public void fatalError(final SAXParseException exception)
{
String message = "Fatal error at line " + exception.getLineNumber() + " : " + exception.getMessage();
this.fatalErrorsCount += 1;
this.messages.add(message);
}
this.fatalErrorsCount += 1;
this.messages.add(message);
}
/**
/**
*
*/
public int fatalErrorsCount()
{
int result;
public int fatalErrorsCount()
{
int result;
result = this.fatalErrorsCount;
result = this.fatalErrorsCount;
//
return (result);
}
//
return (result);
}
/**
/**
*
*/
public boolean hasError()
{
boolean result;
public boolean hasError()
{
boolean result;
if (allErrorsCount() == 0)
{
result = false;
}
else
{
result = true;
}
if (allErrorsCount() == 0)
{
result = false;
}
else
{
result = true;
}
//
return (result);
}
//
return (result);
}
/**
/**
*
*/
@Override
public String toString()
{
StringBuffer result;
@Override
public String toString()
{
StringBuffer result;
result = new StringBuffer();
result = new StringBuffer();
for (String message : this.messages)
{
result.append(message);
result.append('\n');
}
for (String message : this.messages)
{
result.append(message);
result.append('\n');
}
//
return (result.toString());
}
//
return (result.toString());
}
/**
* Called by the XML parser to handle warnings.
*
* @param ex
* Parse Excpetion. Contains the warning text and the line
* number.
*/
@Override
public void warning(final SAXParseException exception)
{
String message = "Warning at line " + exception.getLineNumber() + " : " + exception.getMessage();
/**
* Called by the XML parser to handle warnings.
*
* @param ex
* Parse Excpetion. Contains the warning text and the line
* number.
*/
@Override
public void warning(final SAXParseException exception)
{
String message = "Warning at line " + exception.getLineNumber() + " : " + exception.getMessage();
this.warningCount += 1;
this.messages.add(message);
}
this.warningCount += 1;
this.messages.add(message);
}
/**
/**
*
*/
public int warningCount()
{
int result;
public int warningCount()
{
int result;
result = this.warningCount;
result = this.warningCount;
//
return (result);
}
//
return (result);
}
}

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

View file

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

View file

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

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.
*
@ -25,14 +25,14 @@ import java.util.Locale;
*/
public interface CharterView extends View
{
/**
*
* @param userId
* @param lang
* @param content
* @return
*/
public StringBuffer getHtml(final Long userId, final Locale language, final CharSequence content) throws Exception;
/**
*
* @param userId
* @param lang
* @param content
* @return
*/
public StringBuffer getHtml(final Long userId, final Locale language, final CharSequence content) throws Exception;
}
// ////////////////////////////////////////////////////////////////////////

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.
*
@ -23,10 +23,10 @@ package fr.devinsy.xidyn.views;
*/
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
{
/**
* @throws Exception
*
*/
public static void main(final String[] args) throws Exception
{
String source = "<div><h1>toto</h1><span id='titi'>blank</span></div>";
/**
* @throws Exception
*
*/
public static void main(final String[] args) throws Exception
{
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
{
public enum MONTHS
{
JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBRE, DECEMBRE
}
public enum MONTHS
{
JANUARY,
FEBRUARY,
MARCH,
APRIL,
MAY,
JUNE,
JULY,
AUGUST,
SEPTEMBER,
OCTOBER,
NOVEMBRE,
DECEMBRE
}
static private Logger logger = LoggerFactory.getLogger(XidynTest.class);
static
{
// Initialize logger.
org.apache.log4j.BasicConfigurator.configure();
org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO);
}
static private Logger logger = LoggerFactory.getLogger(XidynTest.class);
static
{
// Initialize logger.
org.apache.log4j.BasicConfigurator.configure();
org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO);
}
/**
/**
*
*/
public static String check(final String title, final StringBuffer source, final String model)
{
String result;
public static String check(final String title, final StringBuffer source, final String model)
{
String result;
if (source.indexOf(model) == -1)
{
result = String.format("%-40s -> KO <-", title) + "\nGet:\n" + source + "\nWaiting:\n" + model;
if (source.indexOf(model) == -1)
{
result = String.format("%-40s -> KO <-", title) + "\nGet:\n" + source + "\nWaiting:\n" + model;
}
else
{
result = String.format("%-40s [ OK ] ", title);
}
}
else
{
result = String.format("%-40s [ OK ] ", title);
}
//
return (result);
};
//
return (result);
};
/**
/**
*
*/
public static void main(final String[] args)
{
System.out.println("Automatic test action for Xid!");
public static void main(final String[] args)
{
System.out.println("Automatic test action for Xid!");
TagDataManager datas;
SimpleTagData tag;
TagDataManager datas;
SimpleTagData tag;
String htmlSource;
StringBuffer html;
String htmlSource;
StringBuffer html;
// Populate attributes of Test 03.
System.out.println("----------------------------");
datas = new TagDataManager();
datas.setContent("name", "Superman");
try
{
html = StringPresenter.dynamize("<div id='name'>a name</div >", datas);
}
catch (Exception exception)
{
System.out.println(exception.getMessage());
html = null;
}
// Populate attributes of Test 03.
System.out.println("----------------------------");
datas = new TagDataManager();
datas.setContent("name", "Superman");
try
{
html = StringPresenter.dynamize("<div id='name'>a name</div >", datas);
}
catch (Exception exception)
{
System.out.println(exception.getMessage());
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.
System.out.println("----------------------------");
datas = new TagDataManager();
datas.setContent("lastname", "Spiderman");
datas.appendAttribute("lastname", "style", "background: blue;");
datas.appendAttribute("lastname", "style", "foreground: red;");
datas.setAttribute("lastname", "class", "nameClass");
// Populate attributes of Test 03.
System.out.println("----------------------------");
datas = new TagDataManager();
datas.setContent("lastname", "Spiderman");
datas.appendAttribute("lastname", "style", "background: blue;");
datas.appendAttribute("lastname", "style", "foreground: red;");
datas.setAttribute("lastname", "class", "nameClass");
try
{
html = StringPresenter.dynamize("<div id='lastname'>a last name</div >", datas);
}
catch (Exception exception)
{
System.out.println(exception.getMessage());
html = null;
}
System.out.println(check("content and attributes", html, "<div id=\"lastname\" style=\"background: blue;foreground: red;\" class=\"nameClass\">Spiderman</div>"));
try
{
html = StringPresenter.dynamize("<div id='lastname'>a last name</div >", datas);
}
catch (Exception exception)
{
System.out.println(exception.getMessage());
html = null;
}
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.
System.out.println("----------------------------");
datas = new TagDataManager();
datas.setContent("words", 0, "alpha");
datas.setContent("words", 1, "bravo");
datas.setContent("words", 2, "charlie");
datas.setContent("words", 3, "delta");
datas.setContent("words", 4, "echo");
datas.setContent("words", 5, "fox");
// Populate attributes of Test 03.
System.out.println("----------------------------");
datas = new TagDataManager();
datas.setContent("words", 0, "alpha");
datas.setContent("words", 1, "bravo");
datas.setContent("words", 2, "charlie");
datas.setContent("words", 3, "delta");
datas.setContent("words", 4, "echo");
datas.setContent("words", 5, "fox");
try
{
html = StringPresenter.dynamize("<ul>\n <li id='words'>a word</li>\n</ul>", datas);
}
catch (Exception exception)
{
System.out.println(exception.getMessage());
html = null;
}
try
{
html = StringPresenter.dynamize("<ul>\n <li id='words'>a word</li>\n</ul>", datas);
}
catch (Exception exception)
{
System.out.println(exception.getMessage());
html = null;
}
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 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 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 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 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 5", html, "<li id=\"words_4\">echo</li>"));
System.out.println(check("list assertion 6", html, "<li id=\"words_5\">fox</li>"));
// Populate attributes of Test 03.
System.out.println("----------------------------");
datas = new TagDataManager();
datas.setContent("identity", 0, "nom", "Jemba");
datas.setContent("identity", 0, "prenom", "Epo");
datas.setContent("identity", 1, "nom", "Momon");
datas.setContent("identity", 1, "prenom", "Christian");
datas.setContent("identity", 2, "nom", "Tronche");
datas.setContent("identity", 2, "prenom", "Christophe");
// Populate attributes of Test 03.
System.out.println("----------------------------");
datas = new TagDataManager();
datas.setContent("identity", 0, "nom", "Jemba");
datas.setContent("identity", 0, "prenom", "Epo");
datas.setContent("identity", 1, "nom", "Momon");
datas.setContent("identity", 1, "prenom", "Christian");
datas.setContent("identity", 2, "nom", "Tronche");
datas.setContent("identity", 2, "prenom", "Christophe");
StringBuffer source = new StringBuffer();
source.append("<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("</table>");
htmlSource = source.toString();
try
{
html = StringPresenter.dynamize(htmlSource, datas);
}
catch (Exception exception)
{
System.out.println(exception.getMessage());
html = null;
}
StringBuffer source = new StringBuffer();
source.append("<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("</table>");
htmlSource = source.toString();
try
{
html = StringPresenter.dynamize(htmlSource, datas);
}
catch (Exception exception)
{
System.out.println(exception.getMessage());
html = null;
}
System.out.println(check("table 1 assertion 1", html, "<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 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 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 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
* ("----------------------------"); datas = new Data ();
* datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent
* ("identity", 0, "prenom", "Epo"); datas.setContent ("identity", 1,
* "nom", "Momon"); datas.setContent ("identity", 1, "prenom",
* "Christian"); datas.setContent ("identity", 2, "nom", "Tronche");
* datas.setContent ("identity", 2, "prenom", "Christophe");
* datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW);
* //datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID);
* //datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
* //datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ALL_ROWS);
*
*
* errorMessage = new StringBuffer (); source = new StringBuffer ();
* source.append ("<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='identity2'><td>noid</td><td id='nom2'>un nom</td><td id='prenom2'>un prenom</td></tr>\n"
* ); source.append (
* " <tr><td>noid</td><td id='nom3'>un nom</td><td id='prenom3'>un prenom</td></tr>\n"
* ); source.append ("</table>"); htmlSource = source.toString ();
*
* System.out.println ("datas = new Data ();"); System.out.println
* ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");");
* System.out.println
* ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");");
* System.out.println
* ("datas.setContent (\"identity\", 1, \"nom\", \"Momon\");");
* System.out.println
* ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");");
* System.out.println
* ("datas.setContent (\"identity\", 2, \"nom\", \"Tronche\");");
* System.out.println
* ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");");
*
* System.out.println ("+"); System.out.println (htmlSource);
* System.out.println ("=>");
*
*
* datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); System.out.println
* ("ONLY_FIRST_ROW:"); html = Presenter.dynamize (htmlSource, datas, "",
* errorMessage); System.out.println (html);
*
* datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID);
* System.out.println ("ONLY_ROWS_WITH_ID:"); html = Presenter.dynamize
* (htmlSource, datas, "", errorMessage); System.out.println (html);
*
* datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
* System.out.println ("ONLY_ROWS_WITHOUT_ID:"); html = Presenter.dynamize
* (htmlSource, datas, "", errorMessage); System.out.println (html);
*
* datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ALL_ROWS); System.out.println
* ("ALL_ROWS:"); html = Presenter.dynamize (htmlSource, datas, "",
* errorMessage); System.out.println (html);
*
*
*
* // Populate attributes of Test 03. System.out.println
* ("----------------------------"); datas = new Data ();
* datas.setAttribute ("<div>", "class", "aDivClass");
* datas.setAttribute ("<div>", "style", "background-color: #000000;");
* datas.setAttribute ("number", "style", "background-color: #0000FF;");
*
* errorMessage = new StringBuffer (); source = new StringBuffer ();
* source.append ("<div>\n"); source.append (" <h1>one</h1>\n");
* source.append ("</div>\n"); source.append ("<div id=\"number\">\n");
* source.append (" <h1>three</h1>\n"); source.append ("</div>");
* htmlSource = source.toString (); html = Presenter.dynamize (htmlSource,
* datas, "", errorMessage);
*
* System.out.println (htmlSource); System.out.println ("+");
* System.out.println ("datas = new Data ();"); System.out.println
* ("datas.setAttribute (\"<div>\", \"class\", \"aDivClass\");");
* System.out.println (
* "datas.setAttribute (\"<div>\", \"style\", \"background-color: #000000;\");"
* ); System.out.println (
* "datas.setAttribute (\"number\", \"style\", \"background-color: #0000FF;\");"
* );
*
* System.out.println ("=>"); System.out.println (html);
*/
}
/*
* // Populate attributes of Test 03. System.out.println
* ("----------------------------"); datas = new Data ();
* datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent
* ("identity", 0, "prenom", "Epo"); datas.setContent ("identity", 1,
* "nom", "Momon"); datas.setContent ("identity", 1, "prenom",
* "Christian"); datas.setContent ("identity", 2, "nom", "Tronche");
* datas.setContent ("identity", 2, "prenom", "Christophe");
* datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW);
* //datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID);
* //datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
* //datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ALL_ROWS);
*
*
* errorMessage = new StringBuffer (); source = new StringBuffer ();
* source.append ("<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='identity2'><td>noid</td><td id='nom2'>un nom</td><td id='prenom2'>un prenom</td></tr>\n"
* ); source.append (
* " <tr><td>noid</td><td id='nom3'>un nom</td><td id='prenom3'>un prenom</td></tr>\n"
* ); source.append ("</table>"); htmlSource = source.toString ();
*
* System.out.println ("datas = new Data ();"); System.out.println
* ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");");
* System.out.println
* ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");");
* System.out.println
* ("datas.setContent (\"identity\", 1, \"nom\", \"Momon\");");
* System.out.println
* ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");");
* System.out.println
* ("datas.setContent (\"identity\", 2, \"nom\", \"Tronche\");");
* System.out.println
* ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");");
*
* System.out.println ("+"); System.out.println (htmlSource);
* System.out.println ("=>");
*
*
* datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); System.out.println
* ("ONLY_FIRST_ROW:"); html = Presenter.dynamize (htmlSource, datas, "",
* errorMessage); System.out.println (html);
*
* datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID);
* System.out.println ("ONLY_ROWS_WITH_ID:"); html = Presenter.dynamize
* (htmlSource, datas, "", errorMessage); System.out.println (html);
*
* datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
* System.out.println ("ONLY_ROWS_WITHOUT_ID:"); html = Presenter.dynamize
* (htmlSource, datas, "", errorMessage); System.out.println (html);
*
* datas.setIterationStrategy ("identity",
* IdsDataByIndex.IterationStrategy.ALL_ROWS); System.out.println
* ("ALL_ROWS:"); html = Presenter.dynamize (htmlSource, datas, "",
* errorMessage); System.out.println (html);
*
*
*
* // Populate attributes of Test 03. System.out.println
* ("----------------------------"); datas = new Data ();
* datas.setAttribute ("<div>", "class", "aDivClass");
* datas.setAttribute ("<div>", "style", "background-color: #000000;");
* datas.setAttribute ("number", "style", "background-color: #0000FF;");
*
* errorMessage = new StringBuffer (); source = new StringBuffer ();
* source.append ("<div>\n"); source.append (" <h1>one</h1>\n");
* source.append ("</div>\n"); source.append ("<div id=\"number\">\n");
* source.append (" <h1>three</h1>\n"); source.append ("</div>");
* htmlSource = source.toString (); html = Presenter.dynamize (htmlSource,
* datas, "", errorMessage);
*
* System.out.println (htmlSource); System.out.println ("+");
* System.out.println ("datas = new Data ();"); System.out.println
* ("datas.setAttribute (\"<div>\", \"class\", \"aDivClass\");");
* System.out.println (
* "datas.setAttribute (\"<div>\", \"style\", \"background-color: #000000;\");"
* ); System.out.println (
* "datas.setAttribute (\"number\", \"style\", \"background-color: #0000FF;\");"
* );
*
* 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.
*
@ -18,11 +18,7 @@
*/
package fr.devinsy.xidyn.presenters;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.fest.assertions.Assertions;
import org.junit.Before;
import org.junit.Test;
import fr.devinsy.xidyn.data.TagDataManager;
@ -32,84 +28,33 @@ import fr.devinsy.xidyn.data.TagDataManager;
*/
public class DomPresenterTest
{
/**
*
*/
@Before
public void before()
{
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.ERROR);
}
/**
* @throws Exception
*
*/
@Test
public void testDynamize01() throws Exception
{
String source = "aaaaa<div>hello</div>zzzzz";
/**
* @throws Exception
*
*/
@Test
public void testStaticDynamize01() throws Exception
{
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
*
*/
@Test
public void testDynamize02() throws Exception
{
String source = "aaaaa<div>hello</div>zzzzz";
/**
* @throws Exception
*
*/
@Test
public void testStaticDynamize02() throws Exception
{
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);
}
/**
* @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);
}
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.
*
@ -32,84 +32,55 @@ import fr.devinsy.xidyn.data.TagDataManager;
*/
public class StringPresenterTest
{
/**
/**
*
*/
@Before
public void before()
{
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.ERROR);
}
@Before
public void before()
{
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.ERROR);
}
/**
* @throws Exception
*
*/
@Test
public void testDynamize01() throws Exception
{
String source = "aaaaa<body>hello</body>zzzzz";
/**
* @throws Exception
*
*/
@Test
public void testDynamize01() throws Exception
{
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
*
*/
@Test
public void testDynamize02() throws Exception
{
String source = "aaaaa<body>hello</body>zzzzz";
/**
* @throws Exception
*
*/
@Test
public void testDynamize02() throws Exception
{
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
*
*/
@Test
public void testDynamize03() throws Exception
{
String source = "aaaaa<div>hello</div>zzzzz";
/**
* @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);
}
String target = new StringPresenter(source).dynamize(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.
*
@ -30,151 +30,151 @@ import org.junit.Test;
*/
public class XidynUtilsTest
{
/**
/**
*
*/
@Before
public void before()
{
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.ERROR);
}
@Before
public void before()
{
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.ERROR);
}
/**
/**
*
*/
@Test
public void testExtractBodyContent01()
{
String source = "aaaaa<boDY>hello</Body>zzzzz";
@Test
public void testExtractBodyContent01()
{
String source = "aaaaa<boDY>hello</Body>zzzzz";
String target = XidynUtils.extractBodyContent(source);
Assertions.assertThat(target).isEqualTo("hello");
}
String target = XidynUtils.extractBodyContent(source);
Assertions.assertThat(target).isEqualTo("hello");
}
/**
/**
*
*/
@Test
public void testExtractBodyContent02()
{
String source = "aaaaaaa<boDY>hello</Bod>zzzzz";
@Test
public void testExtractBodyContent02()
{
String source = "aaaaaaa<boDY>hello</Bod>zzzzz";
String target = XidynUtils.extractBodyContent(source);
Assertions.assertThat(target).isEqualTo("");
}
String target = XidynUtils.extractBodyContent(source);
Assertions.assertThat(target).isEqualTo("");
}
/**
/**
*
*/
@Test
public void testExtractBodyContent03()
{
String source = "aaaaa<body></BodY>zzzzz";
@Test
public void testExtractBodyContent03()
{
String source = "aaaaa<body></BodY>zzzzz";
String target = XidynUtils.extractBodyContent(source);
Assertions.assertThat(target).isEqualTo("");
}
String target = XidynUtils.extractBodyContent(source);
Assertions.assertThat(target).isEqualTo("");
}
/**
/**
*
*/
@Test
public void testExtractBodyContent04()
{
String source = "aaaaa<boDY> hello </body>zzzzz";
@Test
public void testExtractBodyContent04()
{
String source = "aaaaa<boDY> hello </body>zzzzz";
String target = XidynUtils.extractBodyContent(source);
Assertions.assertThat(target).isEqualTo("hello");
}
String target = XidynUtils.extractBodyContent(source);
Assertions.assertThat(target).isEqualTo("hello");
}
/**
/**
*
*/
@Test
public void testExtractBodyContent05()
{
StringBuffer buffer = new StringBuffer(1000);
buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").append("\n");
buffer.append("<!DOCTYPE html>").append("\n");
buffer.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">").append("\n");
buffer.append("<head>").append("\n");
buffer.append("<title>Kinsources</title>").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=\"stylesheet\" type=\"text/css\" href=\"kiwa.css\" />").append("\n");
buffer.append("<meta content=\"kinsources, puck, devinsy, gedcom\" name=\"keywords\" />").append("\n");
buffer.append("</head>").append("\n");
buffer.append("<body>");
buffer.append("WELCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOME");
buffer.append("</body>").append("\n");
buffer.append("</html>").append("\n");
@Test
public void testExtractBodyContent05()
{
StringBuffer buffer = new StringBuffer(1000);
buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").append("\n");
buffer.append("<!DOCTYPE html>").append("\n");
buffer.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">").append("\n");
buffer.append("<head>").append("\n");
buffer.append("<title>Kinsources</title>").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=\"stylesheet\" type=\"text/css\" href=\"kiwa.css\" />").append("\n");
buffer.append("<meta content=\"kinsources, puck, devinsy, gedcom\" name=\"keywords\" />").append("\n");
buffer.append("</head>").append("\n");
buffer.append("<body>");
buffer.append("WELCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOME");
buffer.append("</body>").append("\n");
buffer.append("</html>").append("\n");
String source = buffer.toString();
String source = buffer.toString();
// System.out.println("[" + source + "]");
String target = XidynUtils.extractBodyContent(source);
Assertions.assertThat(target).isEqualTo("WELCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOME");
}
// System.out.println("[" + source + "]");
String target = XidynUtils.extractBodyContent(source);
Assertions.assertThat(target).isEqualTo("WELCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOME");
}
/**
/**
*
*/
@Test
public void testExtractDoctype01()
{
String source = "aaaaa<boDY>hello</Body>zzzzz";
@Test
public void testExtractDoctype01()
{
String source = "aaaaa<boDY>hello</Body>zzzzz";
String target = XidynUtils.extractDoctype(source);
Assertions.assertThat(target).isNull();
}
String target = XidynUtils.extractDoctype(source);
Assertions.assertThat(target).isNull();
}
/**
/**
*
*/
@Test
public void testExtractDoctype02()
{
String source = "<html xmlns='http://www.w3.org/1999/xhtml'>aaaaa<boDY>hello</Body>zzzzz";
@Test
public void testExtractDoctype02()
{
String source = "<html xmlns='http://www.w3.org/1999/xhtml'>aaaaa<boDY>hello</Body>zzzzz";
String target = XidynUtils.extractDoctype(source);
Assertions.assertThat(target).isEqualTo("");
}
String target = XidynUtils.extractDoctype(source);
Assertions.assertThat(target).isEqualTo("");
}
/**
/**
*
*/
@Test
public void testExtractDoctype03()
{
String source = "<!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'>aaaaa<boDY>hello</Body>zzzzz";
@Test
public void testExtractDoctype03()
{
String source = "<!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'>aaaaa<boDY>hello</Body>zzzzz";
String target = XidynUtils.extractDoctype(source);
Assertions.assertThat(target).isEqualTo("<!DOCTYPE html>");
}
String target = XidynUtils.extractDoctype(source);
Assertions.assertThat(target).isEqualTo("<!DOCTYPE html>");
}
/**
/**
*
*/
@Test
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";
@Test
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 target = XidynUtils.extractDoctype(source);
Assertions.assertThat(target).isEqualTo("<?xml version='1.0' encoding='UTF-8' ?><!DOCTYPE html>");
}
String target = XidynUtils.extractDoctype(source);
Assertions.assertThat(target).isEqualTo("<?xml version='1.0' encoding='UTF-8' ?><!DOCTYPE html>");
}
/**
/**
*
*/
@Test
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";
@Test
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 target = XidynUtils.extractDoctype(source);
Assertions.assertThat(target).isEqualTo("<?xml version='1.0' encoding='UTF-8' ?><!-- TOTOT --><!DOCTYPE html>");
}
String target = XidynUtils.extractDoctype(source);
Assertions.assertThat(target).isEqualTo("<?xml version='1.0' encoding='UTF-8' ?><!-- TOTOT --><!DOCTYPE html>");
}
}