}
public void processContent(MarkupParser parser, String markupContent, boolean asDocument) {
ContentState state = createState();
state.setMarkupContent(markupContent);
LocationTrackingReader reader = new LocationTrackingReader(new StringReader(markupContent));
String line;
Block currentBlock = null;
DocumentBuilder builder = parser.getBuilder();
builder.setLocator(state);
try {
if (asDocument) {
builder.beginDocument();
}
try {
while ((line = reader.readLine()) != null) {
state.setLineNumber(reader.getLineNumber()+1);
state.setLineOffset(reader.getLineOffset());
state.setLineCharacterOffset(0);
state.setLineSegmentEndOffset(0);
state.setLineLength(line.length());
int lineOffset = 0;
for (;;) {
if (currentBlock == null) {
currentBlock = startBlock(line,lineOffset);
if (currentBlock == null) {
break;
}
currentBlock.setState(state);
currentBlock.setParser(parser);
}
lineOffset = currentBlock.processLineContent(line,lineOffset);
if (currentBlock.isClosed()) {
currentBlock = null;
}
if (lineOffset < line.length() && lineOffset >= 0) {
if (currentBlock != null) {
throw new IllegalStateException("if a block does not fully process a line then it must be closed");
}
} else {
break;
}
}
}
state.setLineNumber(reader.getLineNumber()+1);
state.setLineOffset(reader.getLineOffset());
state.setLineCharacterOffset(0);
state.setLineLength(0);
} catch (IOException e) {
throw new IllegalStateException(e);