1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-23 21:17:58 +01:00

Fixed several xhtml processing bugs:

1) <br/> will no longer produce <br/><br/>. SMACK-93
2) XML entities inside of the xhtml bodies should now be properly escaped. SMACK-145
3) XHTML processing keeps track of depth. SMACK-65

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@4342 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Alex Wenckus 2006-07-10 18:15:26 +00:00 committed by alex
parent c49356052f
commit c4168bf3d7

View file

@ -22,6 +22,7 @@ package org.jivesoftware.smackx.provider;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.packet.XHTMLExtension;
import org.xmlpull.v1.XmlPullParser;
@ -50,25 +51,40 @@ public class XHTMLExtensionProvider implements PacketExtensionProvider {
throws Exception {
XHTMLExtension xhtmlExtension = new XHTMLExtension();
boolean done = false;
StringBuffer buffer = new StringBuffer();;
StringBuffer buffer = new StringBuffer();
int startDepth = parser.getDepth();
int depth = parser.getDepth();
String lastTag = "";
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("body"))
if (parser.getName().equals("body")) {
buffer = new StringBuffer();
depth = parser.getDepth();
}
lastTag = parser.getText();
buffer.append(parser.getText());
} else if (eventType == XmlPullParser.TEXT) {
if (buffer != null) buffer.append(parser.getText());
if (buffer != null) {
// We need to return valid XML so any inner text needs to be re-escaped
buffer.append(StringUtils.escapeForXML(parser.getText()));
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("body")) {
if (parser.getName().equals("body") || parser.getDepth() <= depth) {
buffer.append(parser.getText());
xhtmlExtension.addBody(buffer.toString());
}
else if (parser.getName().equals(xhtmlExtension.getElementName())) {
else if (parser.getName().equals(xhtmlExtension.getElementName())
|| parser.getDepth() <= startDepth) {
done = true;
}
else
buffer.append(parser.getText());
else {
// This is a check for tags that are both a start and end tag like <br/>
// So that they aren't doubled
if(!lastTag.equals(parser.getText())) {
buffer.append(parser.getText());
}
}
}
}