Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Message.java =================================================================== diff -u -r148812e61b3d92cfe06c5784af86e18d8765695d -r06fddd3d20bea904ede950bf0a3781fc5eb3fd64 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Message.java (.../Message.java) (revision 148812e61b3d92cfe06c5784af86e18d8765695d) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/Message.java (.../Message.java) (revision 06fddd3d20bea904ede950bf0a3781fc5eb3fd64) @@ -34,7 +34,7 @@ import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.log4j.Logger; -import org.lamsfoundation.lams.tool.forum.util.ForumToolContentHandler; +import org.lamsfoundation.lams.tool.forum.util.AttachmentComparator; /** * @author conradb @@ -70,7 +70,7 @@ private Set sessionClones; public Message() { - attachments = new TreeSet(); + attachments = new TreeSet(new AttachmentComparator()); sessionClones = new HashSet(); } @@ -110,7 +110,7 @@ // clone attachment if (attachments != null) { Iterator iter = attachments.iterator(); - Set set = new TreeSet(); + Set set = new TreeSet(new AttachmentComparator()); while (iter.hasNext()) { Attachment file = (Attachment) iter.next(); Attachment newFile = (Attachment) file.clone(); Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/AttachmentComparator.java =================================================================== diff -u --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/AttachmentComparator.java (revision 0) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/AttachmentComparator.java (revision 06fddd3d20bea904ede950bf0a3781fc5eb3fd64) @@ -0,0 +1,55 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ +package org.lamsfoundation.lams.tool.forum.util; + +import java.util.Comparator; + +import org.lamsfoundation.lams.tool.forum.persistence.Attachment; + + +/** + * Attachment comparator by unique id, hence should be the order saved in the database. + */ +public class AttachmentComparator implements Comparator { + + /** + * {@inheritDoc} + */ + public int compare(Attachment o1, Attachment o2) { + if (o1 != null && o2 != null) { + if ( o1.getUid() != null && o2.getUid() != null ) { + return (int) (o1.getUid() - o1.getUid()); + } else if ( o1.getUid() != null ) { + return (1); + } else { + return (-1); + } + } else if (o1 != null) { + return 1; + } else { + return -1; + } + } + +} \ No newline at end of file Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/AuthoringAction.java =================================================================== diff -u -r3323ab59f880fd09b8752ed7eeccf213d8f1e01f -r06fddd3d20bea904ede950bf0a3781fc5eb3fd64 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision 3323ab59f880fd09b8752ed7eeccf213d8f1e01f) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/AuthoringAction.java (.../AuthoringAction.java) (revision 06fddd3d20bea904ede950bf0a3781fc5eb3fd64) @@ -68,6 +68,7 @@ import org.lamsfoundation.lams.tool.forum.persistence.Message; import org.lamsfoundation.lams.tool.forum.persistence.PersistenceException; import org.lamsfoundation.lams.tool.forum.service.IForumService; +import org.lamsfoundation.lams.tool.forum.util.AttachmentComparator; import org.lamsfoundation.lams.tool.forum.util.ForumConstants; import org.lamsfoundation.lams.tool.forum.util.ForumWebUtils; import org.lamsfoundation.lams.tool.forum.util.MessageComparator; @@ -510,7 +511,7 @@ for (ForumToolSession toolSession : toolSessions) { Message newMsg = Message.newInstance(message); newMsg.setToolSession(toolSession); - newMsg.setAttachments(new TreeSet()); + newMsg.setAttachments(new TreeSet(new AttachmentComparator())); newMsg.setModifiedBy(null); newMsg.setCreatedBy(null); message.getSessionClones().add(newMsg);