Commit df106421 authored by Dave Cridland's avatar Dave Cridland Committed by akrherz

OF-1271 Copy elements correctly

Adding elements and attributes to the new element doesn't work, since reparenting the old elements generates an exception. This exception wasn't logged.

* Exception logged
* id attribute copied, if present.
* Elements copied deeply/properly.

Test stanza:

```
<message xmlns="jabber:client" to="blah@conference.cridland.im" type="groupchat" id="5260">
<body>This is a message with a label.</body>
<custom xmlns='tmp:custom'/>
<custom-attr xmlns='tmp:custom2' attr='value'/>
<custom-child xmlns='tmp:custom3'>
<child>element</child>
</custom-child>
<custom-text xmlns='tmp:custom4'>Text here</custom-text>
</message>
```
parent eefa0f1d
...@@ -26,6 +26,8 @@ import org.dom4j.Namespace; ...@@ -26,6 +26,8 @@ import org.dom4j.Namespace;
import org.dom4j.io.SAXReader; import org.dom4j.io.SAXReader;
import org.jivesoftware.openfire.user.UserNotFoundException; import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.XMPPDateTimeFormat; import org.jivesoftware.util.XMPPDateTimeFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
...@@ -42,6 +44,7 @@ import java.util.ListIterator; ...@@ -42,6 +44,7 @@ import java.util.ListIterator;
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public final class MUCRoomHistory { public final class MUCRoomHistory {
private static final Logger Log = LoggerFactory.getLogger(MUCRoomHistory.class);
private MUCRoom room; private MUCRoom room;
...@@ -168,15 +171,21 @@ public final class MUCRoomHistory { ...@@ -168,15 +171,21 @@ public final class MUCRoomHistory {
continue; continue;
} }
Element added = message.addChildElement(child.getName(), child.getNamespaceURI()); Element added = message.addChildElement(child.getName(), child.getNamespaceURI());
if (!child.getText().isEmpty()) {
added.setText(child.getText());
}
for (Attribute attr : (List<Attribute>)child.attributes()) { for (Attribute attr : (List<Attribute>)child.attributes()) {
added.add(attr); added.addAttribute(attr.getQName(), attr.getValue());
} }
for (Element el : (List<Element>)child.elements()) { for (Element el : (List<Element>)child.elements()) {
added.add(el); added.add(el.createCopy());
}
} }
if (element.attribute("id") != null) {
message.setID(element.attributeValue("id"));
} }
} catch (Exception ex) { } catch (Exception ex) {
// log.error("Failed to parse payload XML", ex); Log.error("Failed to parse payload XML", ex);
} }
} }
message.setSubject(subject); message.setSubject(subject);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment