/* We need both elements and text content (but not comments etc);
* further, due to loose nesting of HTML, let's just do flat
* iteration in general, as we can still do sub-scoping for
* specific elements (tables etc)
*/
SMInputCursor bodyIt = parentIt.descendantMixedCursor();
StringBuffer text = null; // for collected 'loose' text
SMEvent evt;
while ((evt = bodyIt.getNext()) != null) {
// Let's weed out end elements right away...
if (evt == SMEvent.END_ELEMENT) {
continue;
}
// And straight text as well:
String inline;
if (evt == SMEvent.START_ELEMENT) {
String tag = bodyIt.getLocalName().toLowerCase();
if (processBlockElement(bodyIt, out, tag, text)) {
// true -> was succesfully handled
text = null;
continue;
}
/* Ok; not a block we recognized... but maybe a well-known
* inline element?
*/
inline = checkInlineMarkup(bodyIt, tag);
} else {
inline = bodyIt.getText();
}
if (inline != null) {
if (text == null) {
text = new StringBuffer(inline);