break;
default:
throw new IllegalStateException(
"Unexpected target tag type: " + targetType);
} } catch (Exception e) {
throw new CreoleParseException(
"Tangled tag nesting. No matching open "
+ targetType + " tag for close of "
+ closeM + ". Last open tag is "
+ lastTag + '.', e);
}
if (lastTag.isAtomic())
throw new CreoleParseException(
"Close tag " + closeM
+ " attempted to close atomic tag "
+ lastTag + '.');
// Get this validation over with so rest of this block can
// assume lastTag is an instance of one of these types.
if (!(lastTag instanceof JcxSpanMarker)
&& !(lastTag instanceof JcxBlockMarker)
&& !(lastTag instanceof BlockMarker)
&& !(lastTag instanceof InlineMarker))
throw new RuntimeException(
"Unexpected class for TagMarker " + lastTag
+ ": " + lastTag.getClass().getName());
// At this point we have validated match with an opening tag.
if (lastTag instanceof JcxSpanMarker) {
prevJcxSpan = (JcxSpanMarker) lastTag;
typedStack = jcxSpanStack;
} else if (lastTag instanceof JcxBlockMarker) {
prevJcxBlock = (JcxBlockMarker) lastTag;
typedStack = jcxBlockStack;
} else if (lastTag instanceof BlockMarker) {
prevBlock = (BlockMarker) lastTag;
typedStack = blockStack;
} else if (lastTag instanceof InlineMarker) {
prevInline = (InlineMarker) lastTag;
typedStack = inlineStack;
}
if (typedStack.size() < 1 || typedStack.get(0) != lastTag)
throw new CreoleParseException(
"Closing tag " + lastTag
+ ", but it is not on the tail of the "
+ "type-specific tag stack: " + typedStack);
typedStack.remove(0);
stack.remove(0);
} else if (m instanceof Styler) {
Styler styler = (Styler) m;
TagType targetType = styler.getTargetType();
String[] classNames = styler.getClassNames();
// Get this validation over with so rest of this block can
// assume targetType is an instance of one of these types.
switch (targetType) {
case INLINE:
case BLOCK:
case JCXSPAN:
case JCXBLOCK:
break;
default:
throw new RuntimeException(
"Unexpected tag type value: " + targetType);
}
TagMarker targetTag = null;
switch (styler.getTargetDirection()) {
case PREVIOUS:
switch (targetType) {
case INLINE:
targetTag = prevInline;
break;
case BLOCK:
targetTag = prevBlock;
break;
case JCXSPAN:
targetTag = prevJcxSpan;
break;
case JCXBLOCK:
targetTag = prevJcxBlock;
break;
}
if (targetTag == null)
throw new CreoleParseException(
"No previous " + targetType
+ " tag for Styler " + styler);
break;
case CONTAINER:
switch (targetType) {
case INLINE:
typedStack = inlineStack;
break;
case BLOCK:
typedStack = blockStack;
break;
case JCXSPAN:
typedStack = jcxSpanStack;
break;
case JCXBLOCK:
typedStack = jcxBlockStack;
break;
}
if (typedStack.size() < 1)
throw new CreoleParseException(
"No parent " + targetType
+ " container for Styler " + styler);
targetTag = typedStack.get(0);
break;
case NEXT:
switch (targetType) {
case INLINE:
typedQueue = queuedInlineClassNames;
break;
case BLOCK:
typedQueue = queuedBlockClassNames;
break;
case JCXSPAN:
typedQueue = queuedJcxSpanClassNames;
break;
case JCXBLOCK:
typedQueue = queuedJcxBlockClassNames;
break;
}
typedQueue.addAll(Arrays.asList(classNames));
break;
default:
throw new RuntimeException("Unexpected direction value: "
+ styler.getTargetDirection());
}
if (targetTag != null) targetTag.addCssClasses(classNames);
} else if (m instanceof LinkMarker) {
linkM = (LinkMarker) m;
linkText = linkM.getLinkText();
String lookedUpLabel =
idToTextHMap.get(linkM.getLinkText().substring(1));
if (linkM.getLabel() == null)
linkM.setLabel((lookedUpLabel == null)
? linkM.getLinkText()
: lookedUpLabel);
if (lookedUpLabel == null)
linkM.wrapLabel(
"<span class=\"jcreole_orphanLink\">", "</span>");
} else if (m instanceof TocMarker) {
((TocMarker) m).setSectionHeadings(sections);
} else if (m instanceof BodyUpdaterMarker) {
;
} else if (m instanceof FootNoteRefMarker) {
;
} else if (m instanceof IndexedMarker) {
;
} else if (m instanceof DeferredUrlMarker) {
;
} else {
throw new CreoleParseException(
"Unexpected close marker class: "
+ m.getClass().getName());
}
if (m instanceof HeadingMarker) {
headingM = (HeadingMarker) m;
SectionHeading sh = headingM.getSectionHeading();
enumerationFormats =
headingM.updatedEnumerationFormats(enumerationFormats);
sh.setEnumerationFormats(enumerationFormats);
sections.add(sh);
int newLevel = sh.getLevel();
if (newLevel > headingLevel) {
headingLevel = newLevel;
} else if (newLevel < headingLevel) {
for (int i = headingLevel; i > newLevel; i--)
curSequences[i-1] = -1;
headingLevel = newLevel;
} else {
// No level change
// Intentionally empty
}
if (headingM.getFormatReset() != null)
curSequences[headingLevel-1] = -1;
curSequences[headingLevel-1] += 1;
sh.setSequences(curSequences);
}
}
if (stack.size() != 0)
throw new CreoleParseException(
"Unmatched tag(s) generated: " + stack);
if (jcxSpanStack.size() != 0)
throw new CreoleParseException(
"Unmatched JCX Span tag(s): " + jcxSpanStack);
if (blockStack.size() != 0)
throw new CreoleParseException(
"Unmatched Block tag(s): " + blockStack);
if (jcxBlockStack.size() != 0)
throw new CreoleParseException(
"Unmatched JCX Block tag(s): " + jcxBlockStack);
if (inlineStack.size() != 0)
throw new CreoleParseException(
"Unmatched Inline tag(s): " + inlineStack);
if (queuedJcxSpanClassNames.size() > 0)
throw new CreoleParseException(
"Unapplied Styler JCX class names: "
+ queuedJcxSpanClassNames);
if (queuedJcxBlockClassNames.size() > 0)
throw new CreoleParseException(
"Unapplied Styler JCX Block class names: "
+ queuedBlockClassNames);
if (queuedBlockClassNames.size() > 0)
throw new CreoleParseException(
"Unapplied Styler Block class names: "
+ queuedBlockClassNames);
if (queuedInlineClassNames.size() > 0)
throw new CreoleParseException(
"Unapplied Styler Inline class names: "
+ queuedInlineClassNames);
}