use of org.whole.lang.xml.model.IXmlEntity in project whole by wholeplatform.
the class XmlNormalizerVisitor method visit.
@Override
public void visit(Content entity) {
// recursively normalize nested composite entities
IEntityIterator<IEntity> iterator = IteratorFactory.childMatcherIterator().withPattern(EntityKinds.COMPOSITE);
iterator.reset(entity);
while (iterator.hasNext()) {
IEntity composite = iterator.next();
((IXmlEntity) composite).accept(this);
// move Content's children in place of Content entity
if (Matcher.match(Content, composite)) {
for (int i = composite.wSize() - 1; i >= 0; i--) {
IEntity child = composite.wGet(i);
composite.wRemove(i);
iterator.add(child);
}
iterator.remove();
}
}
for (int i = 0; i < entity.wSize(); i++) {
IContent child = (IContent) entity.wGet(i);
if (Matcher.matchImpl(XmlEntityDescriptorEnum.CharData, child)) {
IEntity nextChild;
if (i + 1 < entity.wSize() && Matcher.matchImpl(XmlEntityDescriptorEnum.CharData, nextChild = entity.wGet(i + 1))) {
StringBuilder sb = getStringBuilder();
sb.append(child.wStringValue());
do {
sb.append(nextChild.wStringValue());
entity.wRemove(i + 1);
} while (i + 1 < entity.wSize() && Matcher.matchImpl(XmlEntityDescriptorEnum.CharData, nextChild = entity.wGet(i + 1)));
child.wSetValue(sb.toString());
}
if (XmlUtils.isIgnorableWhitespace(child.wStringValue()))
entity.wRemove(i--);
}
child.accept(this);
}
}
Aggregations