Compare commits

..

No commits in common. "1.17" and "master" have entirely different histories.
1.17 ... master

32 changed files with 408 additions and 1281 deletions

View file

@ -2,12 +2,6 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="lib" path="lib/servlet-api.jar"/>
<classpathentry kind="lib" path="lib/Logs/log4j-1.2.17-source.zip"/>
@ -15,11 +9,16 @@
<classpathentry kind="lib" path="lib/UnitTesting/hamcrest-core-1.3.jar" sourcepath="lib/UnitTesting/hamcrest-core-1.3-sources.jar"/>
<classpathentry kind="lib" path="lib/UnitTesting/fest-assert-1.4.jar"/>
<classpathentry kind="lib" path="lib/UnitTesting/fest-util-1.1.6.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/UnitTesting/junit-4.12.jar" sourcepath="lib/UnitTesting/junit-4.12-sources.jar"/>
<classpathentry kind="lib" path="lib/Logs/slf4j-api-1.7.25.jar" sourcepath="lib/Logs/slf4j-api-1.7.25-sources.jar"/>
<classpathentry kind="lib" path="lib/Logs/slf4j-log4j12-1.7.25.jar" sourcepath="lib/Logs/slf4j-log4j12-1.7.25-sources.jar"/>
<classpathentry kind="lib" path="lib/commons-text-1.9.jar" sourcepath="lib/commons-text-1.9-sources.jar"/>
<classpathentry kind="lib" path="lib/commons-lang3-3.13.0.jar" sourcepath="lib/commons-lang3-3.13.0-sources.jar"/>
<classpathentry kind="lib" path="lib/devinsy-strings-0.17.0.jar" sourcepath="lib/devinsy-strings-0.17.0-sources.zip"/>
<classpathentry kind="lib" path="lib/commons-lang3-3.7.jar" sourcepath="lib/commons-lang3-3.7-sources.jar"/>
<classpathentry kind="lib" path="lib/devinsy-strings-0.8.2.jar" sourcepath="lib/devinsy-strings-0.8.2-sources.zip"/>
<classpathentry kind="lib" path="lib/devinsy-utils-0.8.0.jar" sourcepath="lib/devinsy-utils-0.8.0-sources.zip"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>

View file

@ -11,20 +11,16 @@ 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=11
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
@ -32,20 +28,17 @@ org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_c
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_assignment=0
org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
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_logical_operator=16
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
@ -131,12 +124,11 @@ org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
@ -167,8 +159,6 @@ org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert
org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
@ -193,17 +183,13 @@ org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert
org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
@ -251,8 +237,6 @@ org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do no
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert
org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
@ -289,12 +273,9 @@ org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not inser
org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert
org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
@ -320,10 +301,6 @@ 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
org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true
org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true
org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true
org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true

View file

@ -3,5 +3,5 @@
<fixed facet="jst.java"/>
<fixed facet="jst.utility"/>
<installed facet="jst.utility" version="1.0"/>
<installed facet="jst.java" version="11"/>
<installed facet="jst.java" version="1.8"/>
</faceted-project>

View file

@ -1,22 +0,0 @@
# XIDYN
Xidyn provides an easy template solution.
## Author
Christian Pierre MOMON &lt;christian.momon@devinsy.fr&gt;
## License
This software is released under the GNU LGPL.
## Requirements
- Java 11
- Eclipse 4.16 (202006).
## Context
Several useful Java classes.
## Conclusion
Enjoy and use Xidyn. For questions, improvement, issues: christian.momon@devinsy.fr

View file

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Mon Nov 27 12:47:18 CET 2023
build.number=1
#Mon Oct 03 06:15:00 CEST 2016
build.number=0

View file

@ -1,3 +1,3 @@
product.name=xidyn
product.revision.major=1
product.revision.minor=17
product.revision.minor=8

View file

@ -1,6 +1,7 @@
This project is using the following libraries:
# Main requirements:
devinsy-utils GNU LGPL useful tools (StringList…)
commons-lang3 Apache 2
# Unit testing requirements:

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
lib/commons-lang3-3.7.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
lib/devinsy-utils-0.8.0.jar Normal file

Binary file not shown.

View file

@ -1,29 +0,0 @@
/*
* Copyright (C) 2006-2017,2020 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.data;
/**
* The Enum DisplayMode.
*/
public enum DisplayMode
{
REPLACE,
APPEND,
IGNORE
};

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2006-2017,2020 Christian Pierre MOMON
* Copyright (C) 2006-2017 Christian Pierre MOMON
*
* This file is part of Xidyn.
*
@ -20,9 +20,6 @@ package fr.devinsy.xidyn.data;
import java.io.Serializable;
import fr.devinsy.strings.StringsUtils;
import fr.devinsy.xidyn.utils.XidynUtils;
/**
* The Class SimpleTagData.
*
@ -39,8 +36,6 @@ import fr.devinsy.xidyn.utils.XidynUtils;
*/
public class SimpleTagData implements Serializable, TagData
{
private static final long serialVersionUID = 8976245034682639923L;
public enum IterationStrategy
{
ONLY_FIRST_ROW,
@ -50,10 +45,19 @@ public class SimpleTagData implements Serializable, TagData
ALL_ROWS
}
public enum MODE
{
REPLACE,
APPEND,
IGNORE
}
private static final long serialVersionUID = 8976245034682639923L;;
private IterationStrategy iterationStrategy;
private TagAttributes attributes;
private boolean excludeSection;
private DisplayMode displayMode = DisplayMode.REPLACE;
private MODE displayMode = MODE.REPLACE;
private String content;
/**
@ -61,7 +65,11 @@ public class SimpleTagData implements Serializable, TagData
*/
public SimpleTagData()
{
this(null);
this.attributes = null;
this.excludeSection = false;
this.displayMode = MODE.REPLACE;
this.content = null;
this.iterationStrategy = IterationStrategy.ALL_ROWS;
}
/**
@ -72,26 +80,13 @@ public class SimpleTagData implements Serializable, TagData
*/
public SimpleTagData(final String text)
{
this.attributes = new TagAttributes();
this.attributes = null;
this.excludeSection = false;
this.displayMode = DisplayMode.REPLACE;
this.displayMode = MODE.REPLACE;
this.content = text;
this.iterationStrategy = IterationStrategy.ALL_ROWS;
}
/**
* Append attribute.
*
* @param label
* the label
* @param value
* the value
*/
public void appendAttribute(final String label, final String value)
{
this.attributes.appendAttribute(label, value);
}
/**
* Append content.
*
@ -119,20 +114,40 @@ public class SimpleTagData implements Serializable, TagData
{
TagAttributes result;
if (this.attributes == null)
{
this.attributes = new TagAttributes();
}
result = this.attributes;
//
return result;
}
/**
* Display.
*
* @return the string
*/
public String display()
{
String result;
result = this.content;
//
return result;
}
/**
* Display mode.
*
* @return the mode
*/
public DisplayMode displayMode()
public MODE displayMode()
{
DisplayMode result;
MODE result;
result = this.displayMode;
@ -154,88 +169,6 @@ public class SimpleTagData implements Serializable, TagData
return result;
}
/**
* Gets the attribute.
*
* @param label
* the label
* @return the attribute
*/
public TagAttribute getAttribute(final String label)
{
TagAttribute result;
result = this.attributes.getAttribute(label);
//
return result;
}
/**
* Gets the attribute mode.
*
* @param label
* the label
* @return the attribute mode
*/
public DisplayMode getAttributeMode(final String label)
{
DisplayMode result;
TagAttribute attribute = this.attributes.get(label);
if (attribute == null)
{
result = null;
}
else
{
result = attribute.getMode();
}
//
return result;
}
/**
* Gets the attribute value.
*
* @param label
* the label
* @return the attribute value
*/
public String getAttributeValue(final String label)
{
String result;
TagAttribute attribute = this.attributes.get(label);
if (attribute == null)
{
result = null;
}
else
{
result = attribute.getValue();
}
//
return result;
}
/**
* Display.
*
* @return the string
*/
public String getContent()
{
String result;
result = this.content;
//
return result;
}
/**
* Iteration strategy.
*
@ -251,78 +184,6 @@ public class SimpleTagData implements Serializable, TagData
return result;
}
/**
* Sets the attribute.
*
* @param label
* the label
* @param value
* the value
*/
public void setAttribute(final String label, final String value)
{
if (this.attributes.containsKey(label))
{
this.attributes.get(label).setValue(value);
}
else
{
if (StringsUtils.containsAnyIgnoreCase(label, "style", "class"))
{
this.attributes.put(label, new TagAttribute(label, value, DisplayMode.APPEND));
}
else
{
this.attributes.put(label, new TagAttribute(label, value));
}
}
}
/**
* Sets the attribute.
*
* @param label
* the label
* @param value
* the value
* @param mode
* the mode
*/
public void setAttribute(final String label, final String value, final DisplayMode mode)
{
if (this.attributes.containsKey(label))
{
TagAttribute attribute = this.attributes.get(label);
attribute.setValue(value);
attribute.setMode(mode);
}
else
{
this.attributes.put(label, new TagAttribute(label, value, mode));
}
}
/**
* Sets the attribute mode.
*
* @param label
* the label
* @param mode
* the mode
*/
public void setAttributeMode(final String label, final DisplayMode mode)
{
if (this.attributes.containsKey(label))
{
this.attributes.get(label).setMode(mode);
}
else
{
TagAttribute tag = new TagAttribute(label, null, mode);
this.attributes.put(label, tag);
}
}
/**
* Sets the content.
*
@ -340,35 +201,11 @@ public class SimpleTagData implements Serializable, TagData
* @param displayMode
* the new display mode
*/
public void setDisplayMode(final DisplayMode displayMode)
public void setDisplayMode(final MODE displayMode)
{
this.displayMode = displayMode;
}
/**
* Sets the escaped attribute.
*
* @param label
* the label
* @param value
* the value
*/
public void setEscapedAttribute(final String label, final String value)
{
setAttribute(label, XidynUtils.escapeXmlBlank(value));
}
/**
* Sets the escaped content.
*
* @param text
* the new escaped content
*/
public void setEscapedContent(final String text)
{
setContent(XidynUtils.escapeXmlBlank(text));
}
/**
* Sets the exclude section.
*

View file

@ -1,113 +0,0 @@
/*
* Copyright (C) 2020 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.data;
/**
* The Class TagAttribute.
*/
public class TagAttribute
{
private DisplayMode mode;
private String label;
private String value;
/**
* Instantiates a new tag attribute.
*
* @param value
* the value
*/
public TagAttribute(final String label, final String value)
{
this(label, value, DisplayMode.REPLACE);
}
/**
* Instantiates a new tag attribute.
*
* @param label
* the label
* @param value
* the value
* @param mode
* the mode
*/
public TagAttribute(final String label, final String value, final DisplayMode mode)
{
this.mode = mode;
this.label = label;
this.value = value;
}
/**
* Append value.
*
* @param value
* the value
*/
public void appendValue(final String value)
{
if (this.value == null)
{
this.value = value;
}
else
{
this.value = this.value + " " + value;
}
}
public String getLabel()
{
return this.label;
}
public DisplayMode getMode()
{
return this.mode;
}
public String getValue()
{
return this.value;
}
/**
* Sets the mode.
*
* @param mode
* the new mode
*/
public void setMode(final DisplayMode mode)
{
if (mode == null)
{
throw new IllegalArgumentException("Null parameter.");
}
else
{
this.mode = mode;
}
}
public void setValue(final String value)
{
this.value = value;
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2006-2017,2020 Christian Pierre MOMON
* Copyright (C) 2006-2017 Christian Pierre MOMON
*
* This file is part of Xidyn.
*
@ -19,7 +19,6 @@
package fr.devinsy.xidyn.data;
import java.util.HashMap;
import java.util.Iterator;
/**
* The Class TagAttributes.
@ -27,7 +26,8 @@ import java.util.Iterator;
* Note: no more AttrValue as in Brill, because the exception of style is
* managed in the attribute merging on the "style" string detection.
*/
public class TagAttributes extends HashMap<String, TagAttribute> implements Iterable<TagAttribute>
public class TagAttributes extends HashMap<String, String>
{
private static final long serialVersionUID = 2802739066295665336L;
@ -62,11 +62,11 @@ public class TagAttributes extends HashMap<String, TagAttribute> implements Iter
{
if (this.containsKey(label))
{
this.get(label).appendValue(value);
this.put(label, this.get(label) + " " + value);
}
else
{
this.put(label, new TagAttribute(label, value));
this.put(label, value);
}
}
@ -77,9 +77,9 @@ public class TagAttributes extends HashMap<String, TagAttribute> implements Iter
* the label
* @return the attribute
*/
public TagAttribute getAttribute(final String label)
public String getAttribute(final String label)
{
TagAttribute result;
String result;
if (this.containsKey(label))
{
@ -95,18 +95,15 @@ public class TagAttributes extends HashMap<String, TagAttribute> implements Iter
}
/**
* Iterator.
* Sets the attribute.
*
* @return the iterator
* @param label
* the label
* @param value
* the value
*/
@Override
public Iterator<TagAttribute> iterator()
public void setAttribute(final String label, final String value)
{
Iterator<TagAttribute> result;
result = this.values().iterator();
//
return result;
this.put(label, value);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2006-2017,2020 Christian Pierre MOMON
* Copyright (C) 2006-2017 Christian Pierre MOMON
*
* This file is part of Xidyn.
*
@ -74,82 +74,6 @@ public class TagDataManager
tags.add(tag);
}
/**
* Append attribute.
*
* @param id
* the id
* @param line
* the line
* @param label
* the label
* @param value
* the value
*/
public void appendAttribute(final String id, final int line, final String label, final long value)
{
appendAttribute(id, line, label, String.valueOf(value));
}
/**
* Append attribute.
*
* @param id
* the id
* @param line
* the line
* @param label
* the label
* @param value
* the value
*/
public void appendAttribute(final String id, final int line, final String label, final String value)
{
SimpleTagData tag = this.getIdData(id, line);
tag.attributes().appendAttribute(label, value);
}
/**
* Append attribute.
*
* @param id
* the id
* @param line
* the line
* @param column
* the column
* @param label
* the label
* @param value
* the value
*/
public void appendAttribute(final String id, final int line, final String column, final String label, final long value)
{
appendAttribute(id, line, column, label, String.valueOf(value));
}
/**
* Append attribute.
*
* @param id
* the id
* @param line
* the line
* @param column
* the column
* @param label
* the label
* @param value
* the value
*/
public void appendAttribute(final String id, final int line, final String column, final String label, final String value)
{
SimpleTagData tag = this.getIdData(id, line, column);
tag.attributes().appendAttribute(label, value);
}
/**
* Append attribute.
*
@ -250,19 +174,6 @@ public class TagDataManager
tag.appendContent(value);
}
/**
* Append content.
*
* @param id
* the id
* @param value
* the value
*/
public void appendContent(final String id, final long value)
{
appendContent(id, String.valueOf(value));
}
/**
* Append content.
*
@ -293,8 +204,9 @@ public class TagDataManager
if (result == null)
{
result = new SimpleTagData();
this.idsDataById.setId(id, result);
this.idsDataById.setId(id, new SimpleTagData());
result = (SimpleTagData) this.idsDataById.getId(id);
}
//
@ -318,8 +230,9 @@ public class TagDataManager
TagDataListByIndex tags = (TagDataListByIndex) this.idsDataById.getId(id);
if (tags == null)
{
tags = new TagDataListByIndex();
this.idsDataById.setId(id, tags);
this.idsDataById.setId(id, new TagDataListByIndex());
tags = (TagDataListByIndex) this.idsDataById.getId(id);
}
// Be sure that lines are existing.
@ -355,8 +268,9 @@ public class TagDataManager
TagDataListByIndex tags = (TagDataListByIndex) this.idsDataById.getId(id);
if (tags == null)
{
tags = new TagDataListByIndex();
this.idsDataById.setId(id, tags);
this.idsDataById.setId(id, new TagDataListByIndex());
tags = (TagDataListByIndex) this.idsDataById.getId(id);
}
// Be sure that lines are existing.
@ -373,8 +287,9 @@ public class TagDataManager
if (result == null)
{
result = new SimpleTagData();
lineData.put(column, result);
lineData.put(column, new SimpleTagData());
result = (SimpleTagData) lineData.get(column);
}
//
@ -382,11 +297,11 @@ public class TagDataManager
}
/**
* Gets the root ids data.
*
* @return the root
* Gets the ids data by id.
*
* @return the ids data by id
*/
public TagDataListById getRoot()
public TagDataListById getIdsDataById()
{
TagDataListById result;
@ -428,7 +343,7 @@ public class TagDataManager
{
SimpleTagData tag = this.getIdData(id);
tag.setAttribute("class", DomPresenterCore.NODISPLAY_CLASS);
tag.attributes().setAttribute("class", DomPresenterCore.NODISPLAY_CLASS);
}
/**
@ -464,7 +379,7 @@ public class TagDataManager
{
SimpleTagData tag = this.getIdData(id, line);
tag.setAttribute(label, value);
tag.attributes().setAttribute(label, value);
}
/**
@ -504,7 +419,7 @@ public class TagDataManager
{
SimpleTagData tag = this.getIdData(id, line, column);
tag.setAttribute(label, value);
tag.attributes().setAttribute(label, value);
}
/**
@ -536,7 +451,7 @@ public class TagDataManager
{
SimpleTagData tag = this.getIdData(id);
tag.setAttribute(label, value);
tag.attributes().setAttribute(label, value);
}
/**
@ -659,114 +574,6 @@ public class TagDataManager
idData.setContent(content);
}
/**
* Sets the escaped attribute.
*
* @param id
* the id
* @param line
* the line
* @param label
* the label
* @param value
* the value
*/
public void setEscapedAttribute(final String id, final int line, final String label, final String value)
{
SimpleTagData tag = this.getIdData(id, line);
tag.setEscapedAttribute(label, value);
}
/**
* Sets the escaped attribute.
*
* @param id
* the id
* @param line
* the line
* @param column
* the column
* @param label
* the label
* @param value
* the value
*/
public void setEscapedAttribute(final String id, final int line, final String column, final String label, final String value)
{
SimpleTagData tag = this.getIdData(id, line, column);
tag.setEscapedAttribute(label, value);
}
/**
* Sets the escaped attribute.
*
* @param id
* the id
* @param label
* the label
* @param value
* the value
*/
public void setEscapedAttribute(final String id, final String label, final String value)
{
SimpleTagData tag = this.getIdData(id);
tag.setEscapedAttribute(label, value);
}
/**
* Sets the escaped content.
*
* @param id
* the id
* @param line
* the line
* @param content
* the content
*/
public void setEscapedContent(final String id, final int line, final String content)
{
SimpleTagData tag = this.getIdData(id, line);
tag.setEscapedContent(content);
}
/**
* Sets the escaped content.
*
* @param id
* the id
* @param line
* the line
* @param column
* the column
* @param content
* the content
*/
public void setEscapedContent(final String id, final int line, final String column, final String content)
{
SimpleTagData tag = this.getIdData(id, line, column);
tag.setEscapedContent(content);
}
/**
* Sets the escaped content.
*
* @param id
* the id
* @param content
* the content
*/
public void setEscapedContent(final String id, final String content)
{
SimpleTagData idData = this.getIdData(id);
idData.setEscapedContent(content);
}
/**
* Sets the iteration strategy.
*

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2006-2018,2020 Christian Pierre MOMON
* Copyright (C) 2006-2018 Christian Pierre MOMON
*
* This file is part of Xidyn.
*
@ -59,7 +59,7 @@ class XidynDemo
String htmlSource = "<div id='pseudo'>a pseudo</div >";
TagDataManager data = new TagDataManager();
data.setContent("pseudo", "Superman");
data.setContent("name", "Superman");
String htmlTarget = PresenterUtils.dynamize(htmlSource, data).toString();
@ -73,8 +73,7 @@ class XidynDemo
}
catch (Exception exception)
{
System.out.println("Demo failed: " + exception.getMessage());
exception.printStackTrace();
System.out.println(exception.getMessage());
}
}
@ -107,8 +106,7 @@ class XidynDemo
}
catch (Exception exception)
{
System.out.println("Demo failed: " + exception.getMessage());
exception.printStackTrace();
System.out.println(exception.getMessage());
}
}
@ -149,8 +147,7 @@ class XidynDemo
}
catch (Exception exception)
{
System.out.println("Demo failed: " + exception.getMessage());
exception.printStackTrace();
System.out.println(exception.getMessage());
}
}
@ -192,8 +189,7 @@ class XidynDemo
}
catch (Exception exception)
{
System.out.println("Demo failed: " + exception.getMessage());
exception.printStackTrace();
System.out.println(exception.getMessage());
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2006-2018,2020 Christian Pierre MOMON
* Copyright (C) 2006-2018 Christian Pierre MOMON
*
* This file is part of Xidyn.
*
@ -34,9 +34,7 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.DisplayMode;
import fr.devinsy.xidyn.data.SimpleTagData;
import fr.devinsy.xidyn.data.TagAttribute;
import fr.devinsy.xidyn.data.TagAttributes;
import fr.devinsy.xidyn.data.TagData;
import fr.devinsy.xidyn.data.TagDataListById;
@ -92,7 +90,7 @@ public class DomPresenterCore
*/
public static void dynamize(final Appendable result, final Document doc, final TagDataManager data) throws XidynException
{
dynamize(result, doc, data.getRoot());
dynamize(result, doc, data.getIdsDataById());
}
/**
@ -133,7 +131,7 @@ public class DomPresenterCore
{
StringBuffer result;
result = dynamize(doc, data.getRoot());
result = dynamize(doc, data.getIdsDataById());
//
return result;
@ -173,6 +171,133 @@ public class DomPresenterCore
return result;
}
/**
* Get the text for an element. Converts new lines to spaces.
*
* @param node
* the node
* @return the element text
*/
private static String getElementText(final Node node)
{
String result;
NodeList children = node.getChildNodes();
if ((children == null) || (children.getLength() == 0))
{
result = "";
}
else
{
boolean ended = false;
result = ""; // Grrrr, Java ...
int childCounter = 0;
int childCount = children.getLength();
while (!ended)
{
if (childCounter >= childCount)
{
ended = true;
result = "";
}
else
{
Node child = children.item(childCounter);
if (child.getNodeType() == Node.TEXT_NODE)
{
// STU (+=, newLines...)
result = newLinesToSpaces(child.getNodeValue());
ended = true;
}
else
{
childCounter += 1;
}
}
}
}
//
return result;
}
/**
* Merge attributes.
*
* @param target
* the target
* @param source
* the source
* @return the tag attributes
*/
private static TagAttributes mergeAttributes(final TagAttributes target, final TagAttributes source)
{
TagAttributes result;
//
if (target == null)
{
result = source;
}
else if (source == null)
{
result = target;
}
else
{
result = new TagAttributes(target);
Iterator<Map.Entry<String, String>> iterator = source.entrySet().iterator();
while (iterator.hasNext())
{
Map.Entry<String, String> attribute = iterator.next();
String currentValue = target.get(attribute.getKey());
if (currentValue == null)
{
result.put(attribute.getKey(), attribute.getValue());
}
else if (attribute.getKey().equals("style"))
{
result.put(attribute.getKey(), currentValue + attribute.getValue());
}
else
{
result.put(attribute.getKey(), attribute.getValue());
}
}
}
//
return result;
}
/**
* Converts New Line characters to spaces. This is used when for example the
* text in a div tag goes over several lines.
*
* @param text
* String
* @return String
*/
private static String newLinesToSpaces(final String text)
{
StringBuffer result = new StringBuffer(text);
for (int i = 0; i < result.length(); i++)
{
if (result.charAt(i) == '\n')
{
result.setCharAt(i, ' ');
}
}
//
return (result.toString());
}
/**
* Process.
*
@ -322,6 +447,42 @@ public class DomPresenterCore
logger.debug("process - ended");
}
/**
* Process attributes.
*
* @param attrs
* the attrs
* @return the string buffer
*/
private static StringBuffer processAttributes(final NamedNodeMap attrs)
{
StringBuffer result;
result = processAttributes(attrs, null, null, "");
//
return result;
}
/**
* Process attributes.
*
* @param attrs
* the attrs
* @param dataAttributes
* the data attributes
* @return the string buffer
*/
private static StringBuffer processAttributes(final NamedNodeMap attrs, final TagAttributes dataAttributes)
{
StringBuffer result;
result = processAttributes(attrs, dataAttributes, "");
//
return result;
}
/**
* Process attributes.
*
@ -351,26 +512,26 @@ public class DomPresenterCore
// Put model attributes in the merged attributes list.
if (dataAttributes != null)
{
for (TagAttribute attribute : dataAttributes)
Iterator<Map.Entry<String, String>> iterator = dataAttributes.entrySet().iterator();
while (iterator.hasNext())
{
if (mergedAttributes.containsKey(attribute.getLabel()))
Map.Entry<String, String> attribute = iterator.next();
if (mergedAttributes.containsKey(attribute.getKey()))
{
if (attribute.getMode() == DisplayMode.APPEND)
if (attribute.getKey().equalsIgnoreCase("style"))
{
mergedAttributes.put(attribute.getLabel(), mergedAttributes.get(attribute.getLabel()) + " " + attribute.getValue());
}
else if (attribute.getMode() == DisplayMode.REPLACE)
{
mergedAttributes.put(attribute.getLabel(), attribute.getValue());
mergedAttributes.put(attribute.getKey(), mergedAttributes.get(attribute.getKey()) + attribute.getValue());
}
else
{
// Keep the already merged value.
mergedAttributes.put(attribute.getKey(), attribute.getValue());
}
}
else
{
mergedAttributes.put(attribute.getLabel(), attribute.getValue());
mergedAttributes.put(attribute.getKey(), attribute.getValue());
}
}
}
@ -395,6 +556,46 @@ public class DomPresenterCore
return result;
}
/**
* Process attributes.
*
* @param attrs
* the attrs
* @param dataAttributes
* the data attributes
* @param namedDataAttributes
* the named data attributes
* @param suffix
* the suffix
* @return the string buffer
*/
private static StringBuffer processAttributes(final NamedNodeMap attrs, final TagAttributes dataAttributes, final TagAttributes namedDataAttributes, final String suffix)
{
StringBuffer result;
result = processAttributes(attrs, mergeAttributes(dataAttributes, namedDataAttributes), suffix);
//
return result;
}
/**
* Process children.
*
* @param result
* the result
* @param node
* the node
* @param datas
* the datas
* @throws IOException
* the exception
*/
private static void processChildren(final Appendable result, final Node node, final TagDataListById datas) throws IOException
{
processChildren(result, node, datas, "");
}
/**
* Process children.
*
@ -537,6 +738,23 @@ public class DomPresenterCore
}
}
/**
* TODO remove?.
*
* @param result
* the result
* @param node
* the node
* @param datas
* the datas
* @throws IOException
* the exception
*/
private static void processElementBasically(final Appendable result, final Node node, final TagDataListById datas) throws IOException
{
processElementBasically(result, node, datas, "");
}
/**
* Process element basically.
*
@ -583,6 +801,28 @@ public class DomPresenterCore
logger.debug("processElementBasically - ended");
}
/**
* Processes a node that has dynamic content. Calls the appropriate code
* generator method, depending on the tag.
*
* @param result
* the result
* @param node
* Current node.
* @param attrs
* The tag attributes.
* @param idAttr
* The ID.
* @param datas
* the datas
* @throws IOException
* the exception
*/
private static void processElementWithId(final Appendable result, final Node node, final NamedNodeMap attrs, final Node idAttr, final TagDataListById datas) throws IOException
{
processElementWithId(result, node, attrs, idAttr, datas, "");
}
/**
* Processes a node that has dynamic content. Calls the appropriate code
* generator method, depending on the tag.
@ -621,7 +861,7 @@ public class DomPresenterCore
{
SimpleTagData data = (SimpleTagData) dataCore;
String theClass = data.getAttributeValue("class");
String theClass = data.attributes().getAttribute("class");
if ((theClass == null) || (!theClass.equals(NODISPLAY_CLASS)))
{
@ -632,7 +872,7 @@ public class DomPresenterCore
// Build attributes.
result.append(processAttributes(attrs, data.attributes(), suffix));
if (((node.getChildNodes() == null) || (node.getChildNodes().getLength() == 0)) && ((data == null) || (data.getContent() == null)))
if (((node.getChildNodes() == null) || (node.getChildNodes().getLength() == 0)) && ((data == null) || (data.display() == null)))
{
// Close the tag.
result.append(" />");
@ -641,14 +881,16 @@ public class DomPresenterCore
{
result.append('>');
// CHANGED, cpm:
// Insert data.
if ((data == null) || (data.getContent() == null))
if ((data == null) || (data.display() == null))
{
processChildren(result, node, datas, suffix);
}
else
{
result.append(data.getContent());
result.append(data.display());
}
// Close the tag.
@ -662,20 +904,20 @@ public class DomPresenterCore
{
TagDataListByIndex tags = (TagDataListByIndex) dataCore;
int lineCount = tags.size();
for (int lineIndex = 0; lineIndex < lineCount; lineIndex++)
int nbLines = tags.size();
for (int nLine = 0; nLine < nbLines; nLine++)
{
if (tags.elementAt(lineIndex) instanceof SimpleTagData)
if (tags.elementAt(nLine) instanceof SimpleTagData)
{
SimpleTagData data = (SimpleTagData) tags.elementAt(lineIndex);
SimpleTagData data = (SimpleTagData) tags.elementAt(nLine);
// Open the tag.
result.append("<");
result.append(node.getNodeName());
result.append(processAttributes(attrs, data.attributes(), Integer.toString(lineIndex)));
result.append(processAttributes(attrs, data.attributes(), Integer.toString(nLine)));
if (((node.getChildNodes() == null) || (node.getChildNodes().getLength() == 0)) && ((data == null) || (data.getContent() == null)))
if (((node.getChildNodes() == null) || (node.getChildNodes().getLength() == 0)) && ((data == null) || (data.display() == null)))
{
// Close the tag.
result.append(" />\n");
@ -687,13 +929,13 @@ public class DomPresenterCore
// CHANGED, cpm
// Insert data.
if ((data == null) || (data.getContent() == null))
if ((data == null) || (data.display() == null))
{
processChildren(result, node, datas, suffix);
}
else
{
result.append(data.getContent());
result.append(data.display());
}
// Close the tag.
@ -705,9 +947,9 @@ public class DomPresenterCore
else
{
// Manage a Hashmap.
TagDataListById data = (TagDataListById) tags.elementAt(lineIndex);
TagDataListById data = (TagDataListById) tags.elementAt(nLine);
processElementWithId(result, node, attrs, idAttr, data, Integer.toString(lineIndex));
processElementWithId(result, node, attrs, idAttr, data, Integer.toString(nLine));
result.append('\n');
}
}

View file

@ -27,7 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import fr.devinsy.xidyn.utils.XidynUtils;
import fr.devinsy.util.FileTools;
import fr.devinsy.xidyn.utils.cache.Cache;
/**
@ -35,6 +35,8 @@ import fr.devinsy.xidyn.utils.cache.Cache;
*/
public class PresenterFactory
{
private static Logger logger = LoggerFactory.getLogger(PresenterFactory.class);
/**
* http://thecodersbreakfast.net/index.php?post/2008/02/25/26-de-la-bonne-
* implementation-du-singleton-en-java
@ -44,8 +46,6 @@ public class PresenterFactory
private final static PresenterFactory INSTANCE = new PresenterFactory();
}
private static Logger logger = LoggerFactory.getLogger(PresenterFactory.class);
private Cache<Presenter> cache;
/**
@ -110,7 +110,7 @@ public class PresenterFactory
}
else
{
String localizedSource = XidynUtils.insertBeforeExtension(source.toString(), "-" + locale.getLanguage());
String localizedSource = FileTools.addBeforeExtension(source.toString(), "-" + locale.getLanguage());
result = this.cache.get(localizedSource);
@ -200,7 +200,7 @@ public class PresenterFactory
}
else
{
File localizedSource = new File(XidynUtils.insertBeforeExtension(source.getAbsolutePath(), "-" + locale.getLanguage()));
File localizedSource = new File(FileTools.addBeforeExtension(source.getAbsolutePath(), "-" + locale.getLanguage()));
result = this.cache.get(localizedSource);
@ -271,7 +271,7 @@ public class PresenterFactory
{
URL localizedSource;
localizedSource = new URL(XidynUtils.insertBeforeExtension(source.getPath(), "-" + locale.getLanguage()));
localizedSource = new URL(FileTools.addBeforeExtension(source.getPath(), "-" + locale.getLanguage()));
result = this.cache.get(localizedSource);
@ -383,7 +383,7 @@ public class PresenterFactory
}
else
{
String localizedSource = XidynUtils.insertBeforeExtension(source.toString(), "-" + locale.getLanguage());
String localizedSource = FileTools.addBeforeExtension(source.toString(), "-" + locale.getLanguage());
result = create(localizedSource);
@ -468,7 +468,7 @@ public class PresenterFactory
}
else
{
File localizedSource = new File(XidynUtils.insertBeforeExtension(source.getAbsolutePath(), "-" + locale.getLanguage()));
File localizedSource = new File(FileTools.addBeforeExtension(source.getAbsolutePath(), "-" + locale.getLanguage()));
result = create(localizedSource);
@ -531,7 +531,7 @@ public class PresenterFactory
}
else
{
URL localizedSource = new URL(XidynUtils.insertBeforeExtension(source.getPath(), "-" + locale.getLanguage()));
URL localizedSource = new URL(FileTools.addBeforeExtension(source.getPath(), "-" + locale.getLanguage()));
result = create(localizedSource);

View file

@ -22,9 +22,9 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import fr.devinsy.util.FileTools;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.utils.XidynUtils;
/**
* The Class TranslatorPresenter.
@ -270,7 +270,7 @@ public class TranslatorPresenter implements Presenter
}
else
{
String adaptedSource = XidynUtils.insertBeforeExtension(this.defaultSource, "-" + language);
String adaptedSource = FileTools.addBeforeExtension(this.defaultSource, "-" + language);
result = PresenterFactory.create(adaptedSource);
if (result.isAvailable())
@ -279,7 +279,7 @@ public class TranslatorPresenter implements Presenter
}
else
{
adaptedSource = XidynUtils.insertBeforeExtension(this.defaultSource, "_" + language);
adaptedSource = FileTools.addBeforeExtension(this.defaultSource, "_" + language);
if (result.isAvailable())
{

View file

@ -109,7 +109,7 @@ public class URLPresenter extends StringPresenter
{
StringBuffer result;
logger.debug("dynamize URL [{}]", this.sourcePathname);
logger.info("dynamize URL [" + this.sourcePathname + "]");
//
update();

View file

@ -34,8 +34,6 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.validation.Schema;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
@ -133,8 +131,7 @@ public class XidynUtils
if (errorHandler.hasError())
{
// Most time, error is (with StringPresenter):
// "Error at line 1 : Document root element "html", must match
// DOCTYPE root
// "Error at line 1 : Document root element "html", must match DOCTYPE root
// "null".
// Error at line 1 : Document is invalid: no grammar found.
// We ignore it. STU
@ -213,8 +210,7 @@ public class XidynUtils
if (errorHandler.hasError())
{
// Most time, error is (with StringPresenter):
// "Error at line 1 : Document root element "html", must match
// DOCTYPE root
// "Error at line 1 : Document root element "html", must match DOCTYPE root
// "null".
// Error at line 1 : Document is invalid: no grammar found.
// We ignore it. STU
@ -247,30 +243,6 @@ public class XidynUtils
return result;
}
/**
* Escape xml blank.
*
* @param source
* the source
* @return the string
*/
public static String escapeXmlBlank(final String source)
{
String result;
if (StringUtils.isBlank(source))
{
result = "";
}
else
{
result = StringEscapeUtils.escapeXml11(source);
}
//
return result;
}
/**
* Good estimation of the target length able to optimize performance.
*
@ -343,12 +315,11 @@ public class XidynUtils
/**
* This method extracts the string before the <i>html</i> tag.
*
* A possible way is to use pattern searching for
* <i>$(.*)&lt;html&gt;.*^</i>. But if there is no <i>html</i> tag, all the
* source is read for nothing.
* A possible way is to use pattern searching for <i>$(.*)&lt;html&gt;.*^</i>.
* But if there is no <i>html</i> tag, all the source is read for nothing.
*
* A best way is to analyze each &lt; while it is a XML tag or a DOCTYPE tag
* or the &lt;HTML&gt; tag.
* A best way is to analyze each &lt; while it is a XML tag or a DOCTYPE tag or
* the &lt;HTML&gt; tag.
*
* Uses cases:
*
@ -359,8 +330,8 @@ public class XidynUtils
*
* @param source
* the source
* @return the string before the <i>html</i> tag or null if no <i>html</i>
* tag found. So, "" if there is a <i>html</i> tag without doctype.
* @return the string before the <i>html</i> tag or null if no <i>html</i> tag
* found. So, "" if there is a <i>html</i> tag without doctype.
*/
public static String extractDoctype(final String source)
{
@ -547,95 +518,6 @@ public class XidynUtils
return result;
}
/**
* Get the text for an element. Converts new lines to spaces.
*
* @param node
* the node
* @return the element text
*/
public static String getElementText(final Node node)
{
String result;
NodeList children = node.getChildNodes();
if ((children == null) || (children.getLength() == 0))
{
result = "";
}
else
{
boolean ended = false;
result = ""; // Grrrr, Java ...
int childCounter = 0;
int childCount = children.getLength();
while (!ended)
{
if (childCounter >= childCount)
{
ended = true;
result = "";
}
else
{
Node child = children.item(childCounter);
if (child.getNodeType() == Node.TEXT_NODE)
{
// STU (+=, newLines...)
result = newLinesToSpaces(child.getNodeValue());
ended = true;
}
else
{
childCounter += 1;
}
}
}
}
//
return result;
}
/**
* Insert before extension.
*
* @param fileName
* the file name
* @param addition
* the addition
* @return the string
*/
public static String insertBeforeExtension(final String fileName, final String addition)
{
String result;
if (fileName == null)
{
result = null;
}
else if (addition == null)
{
result = fileName;
}
else
{
int separatorIndex = fileName.lastIndexOf('.');
if (separatorIndex > 0)
{
result = fileName.substring(0, separatorIndex) + addition + fileName.substring(separatorIndex);
}
else
{
result = fileName + addition;
}
}
//
return result;
}
/**
* Load.
*
@ -779,30 +661,6 @@ public class XidynUtils
return result;
}
/**
* Converts New Line characters to spaces. This is used when for example the
* text in a div tag goes over several lines.
*
* @param text
* String
* @return String
*/
public static String newLinesToSpaces(final String text)
{
StringBuffer result = new StringBuffer(text);
for (int letterIndex = 0; letterIndex < result.length(); letterIndex++)
{
if (result.charAt(letterIndex) == '\n')
{
result.setCharAt(letterIndex, ' ');
}
}
//
return (result.toString());
}
/**
* Read.
*
@ -856,8 +714,8 @@ public class XidynUtils
}
/**
* Any ampersand lt;, ampersand gt; and ampersand amp; sequences in text
* nodes get read in as symbols. This method converts them back to entities.
* Any ampersand lt;, ampersand gt; and ampersand amp; sequences in text nodes
* get read in as symbols. This method converts them back to entities.
*
* @param source
* String that is to have the entities restored..

View file

@ -1,279 +0,0 @@
/*
* Copyright (C) 2020 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.data;
import org.fest.assertions.Assertions;
import org.junit.Test;
import fr.devinsy.xidyn.presenters.PresenterUtils;
/**
* The Class TagDataManagerTest.
*/
public class TagDataManagerTest
{
/**
* Test 01.
*
* @throws Exception
* the exception
*/
@Test
public void test01() throws Exception
{
String source = "<ul><li id='line'>line 1</li></ul>";
TagDataManager data = new TagDataManager();
data.setContent("line", 0, "Alpha");
data.appendAttribute("line", 0, "style", "background: red;");
data.setContent("line", 1, "Bravo");
data.appendAttribute("line", 1, "style", "background: blue;");
String target = PresenterUtils.dynamize(source, data).toString();
String goal = "<ul><li style=\"background: red;\" id=\"line_0\">Alpha</li>\n<li style=\"background: blue;\" id=\"line_1\">Bravo</li>\n</ul>";
Assertions.assertThat(target).isEqualTo(goal);
}
@Test
public void test02() throws Exception
{
String source = "<table><tr id='line'><td id='col1'>id</td><td id='name'>name</td></tr></table>";
TagDataManager data = new TagDataManager();
data.setContent("line", 0, "col1", "Alpha");
data.appendAttribute("line", 0, "col1", "style", "background: red;");
data.setContent("line", 1, "Bravo");
data.appendAttribute("line", 1, "style", "background: blue;");
String target = PresenterUtils.dynamize(source, null).toString();
Assertions.assertThat(target).isEqualTo(source);
}
/**
* Test 03.
*
* @throws Exception
* the exception
*/
@Test
public void test03a() throws Exception
{
String source = "<span id='foo' class='bare'>FOOO</span>";
TagDataManager data = new TagDataManager();
data.setAttribute("foo", "class", "goodClass");
String target = PresenterUtils.dynamize(source, data).toString();
String goal = "<span id=\"foo\" class=\"bare goodClass\">FOOO</span>";
Assertions.assertThat(target).isEqualTo(goal);
}
/**
* Test 04.
*
* @throws Exception
* the exception
*/
@Test
public void test03b() throws Exception
{
String source = "<span id='foo' class='bare'>FOOO</span>";
TagDataManager data = new TagDataManager();
data.setAttribute("foo", "class", "goodClass");
data.getIdData("foo").setAttributeMode("class", DisplayMode.APPEND);
String target = PresenterUtils.dynamize(source, data).toString();
String goal = "<span id=\"foo\" class=\"bare goodClass\">FOOO</span>";
Assertions.assertThat(target).isEqualTo(goal);
}
/**
* Test 05.
*
* @throws Exception
* the exception
*/
@Test
public void test03c() throws Exception
{
String source = "<span id='foo' class='bare'>FOOO</span>";
TagDataManager data = new TagDataManager();
data.setAttribute("foo", "class", "goodClass");
data.getIdData("foo").setAttributeMode("class", DisplayMode.REPLACE);
String target = PresenterUtils.dynamize(source, data).toString();
String goal = "<span id=\"foo\" class=\"goodClass\">FOOO</span>";
Assertions.assertThat(target).isEqualTo(goal);
}
/**
* Test 06.
*
* @throws Exception
* the exception
*/
@Test
public void test06a() throws Exception
{
String source = "<span id='foo' style='width: 100px;'>FOOO</span>";
TagDataManager data = new TagDataManager();
data.setAttribute("foo", "style", "goodStyle;");
String target = PresenterUtils.dynamize(source, data).toString();
String goal = "<span style=\"width: 100px; goodStyle;\" id=\"foo\">FOOO</span>";
Assertions.assertThat(target).isEqualTo(goal);
}
@Test
public void test06b() throws Exception
{
String source = "<span id='foo' style='width: 100px;'>FOOO</span>";
TagDataManager data = new TagDataManager();
data.setAttribute("foo", "style", "goodStyle;");
data.getIdData("foo").setAttributeMode("style", DisplayMode.APPEND);
String target = PresenterUtils.dynamize(source, data).toString();
String goal = "<span style=\"width: 100px; goodStyle;\" id=\"foo\">FOOO</span>";
Assertions.assertThat(target).isEqualTo(goal);
}
/**
* Test 06 c.
*
* @throws Exception
* the exception
*/
@Test
public void test06c() throws Exception
{
String source = "<span id='foo' style='width: 100px;'>FOOO</span>";
TagDataManager data = new TagDataManager();
data.setAttribute("foo", "style", "goodStyle;");
data.getIdData("foo").setAttributeMode("style", DisplayMode.REPLACE);
String target = PresenterUtils.dynamize(source, data).toString();
String goal = "<span style=\"goodStyle;\" id=\"foo\">FOOO</span>";
Assertions.assertThat(target).isEqualTo(goal);
}
/**
* Test 9a.
*
* @throws Exception
* the exception
*/
@Test
public void test09a() throws Exception
{
String source = "<span id='foo' name='bare'>FOOO</span>";
TagDataManager data = new TagDataManager();
data.setAttribute("foo", "name", "good;");
String target = PresenterUtils.dynamize(source, data).toString();
String goal = "<span name=\"good;\" id=\"foo\">FOOO</span>";
Assertions.assertThat(target).isEqualTo(goal);
}
/**
* Test 9 b.
*
* @throws Exception
* the exception
*/
@Test
public void test09b() throws Exception
{
String source = "<span id='foo' name='bare'>FOOO</span>";
TagDataManager data = new TagDataManager();
data.setAttribute("foo", "name", "good;");
data.getIdData("foo").setAttributeMode("name", DisplayMode.REPLACE);
String target = PresenterUtils.dynamize(source, data).toString();
String goal = "<span name=\"good;\" id=\"foo\">FOOO</span>";
Assertions.assertThat(target).isEqualTo(goal);
}
/**
* Test 9 c.
*
* @throws Exception
* the exception
*/
@Test
public void test09c() throws Exception
{
String source = "<span id='foo' name='bare'>FOOO</span>";
TagDataManager data = new TagDataManager();
data.setAttribute("foo", "name", "good;");
data.getIdData("foo").setAttributeMode("name", DisplayMode.APPEND);
String target = PresenterUtils.dynamize(source, data).toString();
String goal = "<span name=\"bare good;\" id=\"foo\">FOOO</span>";
Assertions.assertThat(target).isEqualTo(goal);
}
/**
* Test set escaped content.
*
* @throws Exception
* the exception
*/
@Test
public void testSetEscapedContent01() throws Exception
{
String source = "<span id='foo'>n/a</span>";
TagDataManager data = new TagDataManager();
data.setEscapedContent("foo", "<b>foo</b>");
String target = PresenterUtils.dynamize(source, data).toString();
String goal = "<span id=\"foo\">&lt;b&gt;foo&lt;/b&gt;</span>";
Assertions.assertThat(target).isEqualTo(goal);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2006-2023 Christian Pierre MOMON <christian@momon.org>
* Copyright (C) 2006-2017 Christian Pierre MOMON
*
* This file is part of Xidyn.
*
@ -21,7 +21,7 @@ package fr.devinsy.xidyn.utils;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Assert;
import org.fest.assertions.Assertions;
import org.junit.Before;
import org.junit.Test;
@ -49,7 +49,7 @@ public class XidynUtilsTest
String source = "aaaaa<boDY>hello</Body>zzzzz";
String target = XidynUtils.extractBodyContent(source);
Assert.assertEquals(target, "hello");
Assertions.assertThat(target).isEqualTo("hello");
}
/**
@ -61,7 +61,7 @@ public class XidynUtilsTest
String source = "aaaaaaa<boDY>hello</Bod>zzzzz";
String target = XidynUtils.extractBodyContent(source);
Assert.assertEquals(target, "");
Assertions.assertThat(target).isEqualTo("");
}
/**
@ -73,7 +73,7 @@ public class XidynUtilsTest
String source = "aaaaa<body></BodY>zzzzz";
String target = XidynUtils.extractBodyContent(source);
Assert.assertEquals(target, "");
Assertions.assertThat(target).isEqualTo("");
}
/**
@ -85,7 +85,7 @@ public class XidynUtilsTest
String source = "aaaaa<boDY> hello </body>zzzzz";
String target = XidynUtils.extractBodyContent(source);
Assert.assertEquals(target, "hello");
Assertions.assertThat(target).isEqualTo("hello");
}
/**
@ -114,7 +114,7 @@ public class XidynUtilsTest
// System.out.println("[" + source + "]");
String target = XidynUtils.extractBodyContent(source);
Assert.assertEquals(target, "WELCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOME");
Assertions.assertThat(target).isEqualTo("WELCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOME");
}
/**
@ -126,7 +126,7 @@ public class XidynUtilsTest
String source = "aaaaa<boDY>hello</Body>zzzzz";
String target = XidynUtils.extractDoctype(source);
Assert.assertNull(target);
Assertions.assertThat(target).isNull();
}
/**
@ -138,7 +138,7 @@ public class XidynUtilsTest
String source = "<html xmlns='http://www.w3.org/1999/xhtml'>aaaaa<boDY>hello</Body>zzzzz";
String target = XidynUtils.extractDoctype(source);
Assert.assertEquals(target, "");
Assertions.assertThat(target).isEqualTo("");
}
/**
@ -150,7 +150,7 @@ public class XidynUtilsTest
String source = "<!DOCTYPE html><html xmlns='http://www.w3.org/1999/xhtml'>aaaaa<boDY>hello</Body>zzzzz";
String target = XidynUtils.extractDoctype(source);
Assert.assertEquals(target, "<!DOCTYPE html>");
Assertions.assertThat(target).isEqualTo("<!DOCTYPE html>");
}
/**
@ -162,7 +162,7 @@ public class XidynUtilsTest
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);
Assert.assertEquals(target, "<?xml version='1.0' encoding='UTF-8' ?><!DOCTYPE html>");
Assertions.assertThat(target).isEqualTo("<?xml version='1.0' encoding='UTF-8' ?><!DOCTYPE html>");
}
/**
@ -174,150 +174,6 @@ public class XidynUtilsTest
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);
Assert.assertEquals(target, "<?xml version='1.0' encoding='UTF-8' ?><!-- TOTOT --><!DOCTYPE html>");
}
/**
* Test insert before extension 01.
*/
@Test
public void testInsertBeforeExtension01()
{
String source = null;
String target = XidynUtils.insertBeforeExtension(source, null);
Assert.assertNull(target);
}
/**
* Test insert before extension 02.
*/
@Test
public void testInsertBeforeExtension02()
{
String source = null;
String target = XidynUtils.insertBeforeExtension(source, "");
Assert.assertNull(target);
}
/**
* Test insert before extension 03.
*/
@Test
public void testInsertBeforeExtension03()
{
String source = null;
String target = XidynUtils.insertBeforeExtension(source, "-fr");
Assert.assertNull(target);
}
/**
* Test insert before extension 05.
*/
@Test
public void testInsertBeforeExtension05()
{
String source = "";
String target = XidynUtils.insertBeforeExtension(source, null);
Assert.assertEquals(target, "");
}
/**
* Test insert before extension 06.
*/
@Test
public void testInsertBeforeExtension06()
{
String source = "";
String target = XidynUtils.insertBeforeExtension(source, "");
Assert.assertEquals(target, "");
}
/**
* Test insert before extension 07.
*/
@Test
public void testInsertBeforeExtension07()
{
String source = "";
String target = XidynUtils.insertBeforeExtension(source, "-fr");
Assert.assertEquals(target, "-fr");
}
/**
* Test insert before extension 08.
*/
@Test
public void testInsertBeforeExtension08()
{
String source = "foo";
String target = XidynUtils.insertBeforeExtension(source, null);
Assert.assertEquals(target, "foo");
}
/**
* Test insert before extension 09.
*/
@Test
public void testInsertBeforeExtension09()
{
String source = "foo";
String target = XidynUtils.insertBeforeExtension(source, "");
Assert.assertEquals(target, "foo");
}
/**
* Test insert before extension 10.
*/
@Test
public void testInsertBeforeExtension10()
{
String source = "foo";
String target = XidynUtils.insertBeforeExtension(source, "-fr");
Assert.assertEquals(target, "foo-fr");
}
/**
* Test insert before extension 11.
*/
@Test
public void testInsertBeforeExtension11()
{
String source = "foo.txt";
String target = XidynUtils.insertBeforeExtension(source, null);
Assert.assertEquals(target, "foo.txt");
}
/**
* Test insert before extension 12.
*/
@Test
public void testInsertBeforeExtension12()
{
String source = "foo.txt";
String target = XidynUtils.insertBeforeExtension(source, "");
Assert.assertEquals(target, "foo.txt");
}
/**
* Test insert before extension 13.
*/
@Test
public void testInsertBeforeExtension13()
{
String source = "foo.txt";
String target = XidynUtils.insertBeforeExtension(source, "-fr");
Assert.assertEquals(target, "foo-fr.txt");
Assertions.assertThat(target).isEqualTo("<?xml version='1.0' encoding='UTF-8' ?><!-- TOTOT --><!DOCTYPE html>");
}
}