Upgraded lib, added setEscapedContent methods and tests.
This commit is contained in:
parent
33a35fcf96
commit
1dfc9f0eb2
10 changed files with 114 additions and 11 deletions
|
@ -18,8 +18,9 @@
|
|||
<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-lang3-3.7.jar" sourcepath="lib/commons-lang3-3.7-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/devinsy-utils-0.8.0.jar" sourcepath="lib/devinsy-utils-0.8.0-sources.zip"/>
|
||||
<classpathentry kind="lib" path="lib/devinsy-strings-0.11.0.jar" sourcepath="lib/devinsy-strings-0.11.0-sources.zip"/>
|
||||
<classpathentry kind="lib" path="lib/commons-lang3-3.11.jar" sourcepath="lib/commons-lang3-3.11-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-text-1.9.jar" sourcepath="lib/commons-text-1.9-sources.jar"/>
|
||||
<classpathentry kind="output" path="build/classes"/>
|
||||
</classpath>
|
||||
|
|
BIN
lib/commons-lang3-3.11-sources.jar
Normal file
BIN
lib/commons-lang3-3.11-sources.jar
Normal file
Binary file not shown.
BIN
lib/commons-lang3-3.11.jar
Normal file
BIN
lib/commons-lang3-3.11.jar
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
lib/commons-text-1.9-sources.jar
Normal file
BIN
lib/commons-text-1.9-sources.jar
Normal file
Binary file not shown.
BIN
lib/commons-text-1.9.jar
Normal file
BIN
lib/commons-text-1.9.jar
Normal file
Binary file not shown.
|
@ -19,6 +19,7 @@
|
|||
package fr.devinsy.xidyn.data;
|
||||
|
||||
import fr.devinsy.xidyn.presenters.DomPresenterCore;
|
||||
import fr.devinsy.xidyn.utils.XidynUtils;
|
||||
|
||||
/**
|
||||
* The Class TagDataManager.
|
||||
|
@ -659,6 +660,57 @@ public class TagDataManager
|
|||
idData.setContent(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.setContent(XidynUtils.escapeXmlBlank(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.setContent(XidynUtils.escapeXmlBlank(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.setContent(XidynUtils.escapeXmlBlank(content));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the iteration strategy.
|
||||
*
|
||||
|
|
|
@ -34,6 +34,8 @@ 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;
|
||||
|
@ -131,7 +133,8 @@ 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
|
||||
|
@ -210,7 +213,8 @@ 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
|
||||
|
@ -243,6 +247,30 @@ 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.
|
||||
*
|
||||
|
@ -315,11 +343,12 @@ public class XidynUtils
|
|||
/**
|
||||
* This method extracts the string before the <i>html</i> tag.
|
||||
*
|
||||
* A possible way is to use pattern searching for <i>$(.*)<html>.*^</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>$(.*)<html>.*^</i>. But if there is no <i>html</i> tag, all the
|
||||
* source is read for nothing.
|
||||
*
|
||||
* A best way is to analyze each < while it is a XML tag or a DOCTYPE tag or
|
||||
* the <HTML> tag.
|
||||
* A best way is to analyze each < while it is a XML tag or a DOCTYPE tag
|
||||
* or the <HTML> tag.
|
||||
*
|
||||
* Uses cases:
|
||||
*
|
||||
|
@ -330,8 +359,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)
|
||||
{
|
||||
|
@ -788,8 +817,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..
|
||||
|
|
|
@ -255,4 +255,25 @@ public class TagDataManagerTest
|
|||
|
||||
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\"><b>foo</b></span>";
|
||||
|
||||
Assertions.assertThat(target).isEqualTo(goal);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue