/* Important: A OwnMessageList contains a single reference for each message. A MessageList however contains a message reference
* for each board a message is posted to. If this function is changed to be able to encode non-own MessageLists then you need
* to ensure that each message is only listed once, the for(each MessageReference) will return duplicates if a message is posted
* to multiple boards.*/
for(final MessageList.MessageReference ref : list) {
final OwnMessage message = messageManager.getOwnMessage(ref.getMessageID());
// Duplicate checks to prevent severe breakage, also done in message list constructor.
if(message.getAuthor() != list.getAuthor())
throw new RuntimeException("Message author does not match message list author");
if(message.wasInserted() == false)
throw new RuntimeException("Trying to convert a MessageList to XML which contains a not inserted message.");
final Element messageElement = xmlDoc.createElement("Message");
// ID
messageElement.setAttribute("ID", message.getID());
// URI
messageElement.setAttribute("FreenetURI", message.getFreenetURI().toString());
// Date
synchronized(mDateFormat) {
messageElement.setAttribute("Date", mDateFormat.format(message.getDate()));
}
// Boards
for(final Board board : message.getBoards()) {
final Element boardTag = xmlDoc.createElement("Board");
boardTag.setAttribute("Name", board.getName());
messageElement.appendChild(boardTag);
}