* </p>
*/
private static class WhitespaceAnalyser implements Analyser {
// javadoc inherited
public boolean hasVisualEffect(final Element element) {
final PropertyValues propertyValues =
element.getStyles().getPropertyValues();
boolean important = true;
final StyleValue whitespaceValue = propertyValues.getComputedValue(
StylePropertyDetails.WHITE_SPACE);
// if no value is set, it is not important
if (whitespaceValue == null) {
important = false;
}
// if it is the same as the parent value, then it is not important,
// as it is an inherited property
if (important) {
final Element parent = getParent(element);
if (parent != null) {
final Styles parentStyles = parent.getStyles();
if (parentStyles != null) {
final StyleValue parentValue =
parentStyles.getPropertyValues().getComputedValue(
StylePropertyDetails.WHITE_SPACE);
if (whitespaceValue.equals(parentValue)) {
important = false;
}
}
} else {
important =
!whitespaceValue.equals(WhiteSpaceKeywords.NORMAL);
}
}
// check if there is an element we can apply this on
if (important) {
important = false;
for (Node child = element.getHead();
child != null && !important;
child = child.getNext()) {
if (child instanceof Text) {
final Text text = (Text) child;
important = text.getLength() > 0;
} else {
final Element childElement = (Element) child;
final Styles childStyles = childElement.getStyles();
if (childStyles != null) {
final PropertyValues childValues =
childStyles.getPropertyValues();
final StyleValue childValue =
childValues.getComputedValue(
StylePropertyDetails.WHITE_SPACE);
important = childValue == null;
} else {
important = true;
}