if (WodHtmlUtils.isWOTag(chuckWord)) {
tagName = chuckWord;
}
}
FuzzyXMLElementImpl lastOpenElement = (FuzzyXMLElementImpl) _stack.pop();
String lowercaseLastOpenElementName = lastOpenElement.getName().toLowerCase();
String lowercaseCloseTagName = tagName.toLowerCase();
boolean closeTagMatches = lowercaseLastOpenElementName.equals(lowercaseCloseTagName);
// System.out.println("FuzzyXMLParser.handleCloseTag: lastOpen = " +
// lowercaseLastOpenElementName + ", close = " + lowercaseCloseTagName);
if (!closeTagMatches) {
closeAutocloseTags();
// Allow </wo> to close </wo:if>
boolean looseNamespace = false;
int colonIndex = lowercaseLastOpenElementName.indexOf(':');
if (colonIndex != -1) {
String elementNamespace = lowercaseLastOpenElementName.substring(0, colonIndex);
if (lowercaseCloseTagName.equals(elementNamespace) && _looseNamespaces.contains(elementNamespace)) {
tagName = lastOpenElement.getName();
lowercaseCloseTagName = lowercaseLastOpenElementName;
looseNamespace = true;
}
}
if (!looseNamespace) {
boolean looseTag = false;
if (_looseTags.contains(lowercaseLastOpenElementName)) {
looseTag = true;
}
if (looseTag) {
while (lowercaseLastOpenElementName != null && !lowercaseLastOpenElementName.equals(lowercaseCloseTagName) && _looseTags.contains(lowercaseLastOpenElementName)) {
int lastOpenElementEndOffset = end;
// int lastOpenElementEndOffset = lastOpenElement.getOffset() +
// lastOpenElement.getLength();
_stack.push(lastOpenElement);
handleCloseTag(lastOpenElementEndOffset, lastOpenElementEndOffset, "/" + lastOpenElement.getName(), false);
/*
* FuzzyXMLElement looseElement = lastOpenElement;
* FuzzyXMLNode[] looseElementChildren =
* lastOpenElement.getChildren();
* FuzzyXMLElement looseElementParent = (FuzzyXMLElement)
* lastOpenElement.getParentNode();
* for (FuzzyXMLNode looseElementChild : looseElementChildren) {
* looseElement.removeChild(looseElementChild);
* looseElementParent.insertAfter(looseElementChild, looseElement);
* //((AbstractFuzzyXMLNode)
* looseElementChild).setOffset(looseElementChild.getOffset() + 1);
* }
*/
if (_stack.size() == 0) {
lastOpenElement = null;
lowercaseLastOpenElementName = null;
}
else {
lastOpenElement = (FuzzyXMLElementImpl) _stack.pop();
lowercaseLastOpenElementName = lastOpenElement.getName().toLowerCase();
}
}
}
else {
FuzzyXMLElement matchingOpenElement = null;
for (FuzzyXMLElement nonCloseElement : _nonCloseElements) {
if (nonCloseElement.getName().equalsIgnoreCase(lowercaseCloseTagName)) {
matchingOpenElement = nonCloseElement;
}
}
if (matchingOpenElement == null) {
if (showMismatchError) {
fireErrorEvent(offset, end - offset, Messages.getMessage("error.noStartTag", tagName), null);
}
_stack.push(lastOpenElement);
return;
}
// System.out.println("FuzzyXMLParser.handleCloseTag: mismatched close "
// + lastOpenElement.getName());
if (showMismatchError) {
// fireErrorEvent(offset, end - offset, "Found </" + tagName +
// "> before </" + lastOpenElement.getName() + ">", null);
fireErrorEvent(lastOpenElement.getOffset(), lastOpenElement.getLength(), "Missing </" + lastOpenElement.getName() + "> tag", null);
}
_stack.push(lastOpenElement);
handleCloseTag(offset, offset, "/" + lastOpenElement.getName(), false);
lastOpenElement = (FuzzyXMLElementImpl) _stack.pop();
lowercaseLastOpenElementName = lastOpenElement.getName().toLowerCase();
}
/*
* boolean matchesOpenElement = false;
* if (looseTag) {
* for (FuzzyXMLElement nonCloseElement : nonCloseElements) {
* if
* (nonCloseElement.getName().equalsIgnoreCase(lowercaseCloseTagName)) {
* matchesOpenElement = true;
* }
* }
* if (matchesOpenElement) {
* nonCloseElements.remove(lastOpenElement);
* }
* }
*
* if (lastOpenElement.getParentNode() != null) {
* ((FuzzyXMLElementImpl)
* lastOpenElement.getParentNode()).appendChildWithNoCheck
* (lastOpenElement);
* FuzzyXMLNode[] nodes = lastOpenElement.getChildren();
* for (int i = 0; i < nodes.length; i++) {
* ((AbstractFuzzyXMLNode)
* nodes[i]).setParentNode(lastOpenElement.getParentNode());
* lastOpenElement.removeChild(nodes[i]);
* ((FuzzyXMLElementImpl)
* lastOpenElement.getParentNode()).appendChildWithNoCheck(nodes[i]);
* }
* }
* else {
* //System.out.println(tagName + "�̊J�n�^�O��������܂���B");
* fireErrorEvent(offset, end - offset,
* Messages.getMessage("error.noStartTag", tagName), null);
* }
* if (matchesOpenElement) {
* handleCloseTag(offset, end, text);
* }
* // stack.push(element);
* return;
*/
}
}
if (lastOpenElement != null) {
// ��^�O�̏ꍇ�͋�̃e�L�X�g�m�[�h��lj����Ă���
if (lastOpenElement.getChildren().length == 0) {
// MS: Hopefully this doesn't break things ... Sure wish I could read
// Japanese to know what the original author said about this :)
// lastOpenElement.appendChild(new FuzzyXMLTextImpl(getParent(), "",
// offset, 0));
}
lastOpenElement.setLength(end - lastOpenElement.getOffset());
if (closeTagMatches) {
lastOpenElement.setCloseTagOffset(offset);
lastOpenElement.setCloseTagLength(end - offset - 2);
lastOpenElement.setCloseNameOffset(text.indexOf(tagName));
}
_nonCloseElements.remove(lastOpenElement);
if (lastOpenElement.getParentNode() == null) {
_roots.add(lastOpenElement);
for (FuzzyXMLElement error : _nonCloseElements) {
// System.out.println(error.getName() + "�͕��Ă��܂���B");
if (showMismatchError) {
fireErrorEvent(error.getOffset(), error.getLength(), Messages.getMessage("error.noCloseTag", error.getName()), error);
}
}
}
else {
((FuzzyXMLElementImpl) lastOpenElement.getParentNode()).appendChildWithNoCheck(lastOpenElement);
}
}
}