Moved DOM code to utils class.

This commit is contained in:
Christian P. MOMON 2020-01-18 11:49:16 +01:00
parent ad51edcb07
commit 3ab9909181
2 changed files with 74 additions and 74 deletions

View file

@ -171,56 +171,6 @@ public class DomPresenterCore
return result; 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. * Merge attributes.
* *
@ -274,30 +224,6 @@ public class DomPresenterCore
return result; return result;
} }
/**
* Converts New Line characters to spaces. This is used when for example the
* text in a div tag goes over several lines.
*
* @param text
* String
* @return String
*/
private static String newLinesToSpaces(final String text)
{
StringBuffer result = new StringBuffer(text);
for (int i = 0; i < result.length(); i++)
{
if (result.charAt(i) == '\n')
{
result.setCharAt(i, ' ');
}
}
//
return (result.toString());
}
/** /**
* Process. * Process.
* *

View file

@ -518,6 +518,56 @@ public class XidynUtils
return result; 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;
}
/** /**
* Load. * Load.
* *
@ -661,6 +711,30 @@ public class XidynUtils
return result; return result;
} }
/**
* Converts New Line characters to spaces. This is used when for example the
* text in a div tag goes over several lines.
*
* @param text
* String
* @return String
*/
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. * Read.
* *