Author: bback
Date: 2006-03-10 16:38:22 +0000 (Fri, 10 Mar 2006)
New Revision: 8215
Modified:
trunk/apps/frost-0.7/source/frost/messages/MessageObject.java
trunk/apps/frost-0.7/source/frost/threads/MessageUploadThread.java
Log:
message saving moved to message object
Modified: trunk/apps/frost-0.7/source/frost/messages/MessageObject.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/messages/MessageObject.java
2006-03-10 16:34:26 UTC (rev 8214)
+++ trunk/apps/frost-0.7/source/frost/messages/MessageObject.java
2006-03-10 16:38:22 UTC (rev 8215)
@@ -81,10 +81,10 @@
public MessageObject(File file) throws MessageCreationException {
this();
if (file == null) {
- throw new MessageCreationException("Invalid input file for
MessageObject. Its value is null.");
+ throw new MessageCreationException("Invalid input file for
MessageObject. File is null.");
} else if (!file.exists()) {
throw new MessageCreationException(
- "Invalid input file '" +
file.getName() + "' for MessageObject. It doesn't exist.");
+ "Invalid input file '" +
file.getName() + "' for MessageObject. File doesn't exist.");
} else if (file.length() < 20) { // prolog+needed tags are always >
20, but we need to filter
// out
the messages containing "Empty", "Invalid", "Double", "Broken"
// (encrypted for someone else OR
completely invalid)
@@ -500,7 +500,7 @@
}
/**
- * Save the message to the specified file.
+ * Save this message to the specified file.
* Does not change the internal File pointer.
*/
public boolean saveToFile(File f) {
Modified: trunk/apps/frost-0.7/source/frost/threads/MessageUploadThread.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/threads/MessageUploadThread.java
2006-03-10 16:34:26 UTC (rev 8214)
+++ trunk/apps/frost-0.7/source/frost/threads/MessageUploadThread.java
2006-03-10 16:38:22 UTC (rev 8215)
@@ -25,8 +25,6 @@
import javax.swing.*;
-import org.w3c.dom.*;
-
import frost.*;
import frost.fcp.*;
import frost.fileTransfer.upload.*;
@@ -312,7 +310,7 @@
logger.info("TOFUP: Uploading message to board " +
board.getName());
// first save msg to be able to resend on crash
- if (!saveMessage(message, unsentMessageFile)) {
+ if (!message.saveToFile(unsentMessageFile)) {
logger.severe("This was a HARD error and the file to
upload is lost, please report to a dev!");
return false;
}
@@ -334,7 +332,7 @@
message.signMessage(identities.getMyId().getPrivKey());
// save msg with signature
- if (!saveMessage(message, unsentMessageFile)) {
+ if (!message.saveToFile(unsentMessageFile)) {
logger.severe("This was a HARD error and the file to upload is
lost, please report to a dev!");
return false;
}
@@ -358,7 +356,7 @@
}
message.setContent(encContent);
// save changed msg again, but to tmp upload file
- if (!saveMessage(message, uploadFile)) {
+ if (!message.saveToFile(uploadFile)) {
logger.severe("This was a HARD error and the file to upload is
lost, please report to a dev!");
return false;
}
@@ -409,32 +407,6 @@
}
/**
- * This method saves a message to disk in XML format (using a new name)
- * @param msg the MessageObject to save
- * @param file the file whose path will be used to save the message
- * @return true if successful. False otherwise.
- */
- private boolean saveMessage(MessageObject msg, File file) {
- File tmpFile = new File(file.getPath() + ".tmp");
- boolean success = false;
- try {
- Document doc = XMLTools.createDomDocument();
- doc.appendChild(msg.getXMLElement(doc));
- success = XMLTools.writeXmlFile(doc, tmpFile.getPath());
- } catch (Throwable ex) {
- logger.log(Level.SEVERE, "Exception thrown in
saveMessage()", ex);
- }
- if (success && tmpFile.length() > 0) {
- file.delete();
- tmpFile.renameTo(file);
- return true;
- } else {
- tmpFile.delete();
- return false;
- }
- }
-
- /**
* This inserts an attached SharedFileObject into freenet
* @param attachment the SharedFileObject to upload
* @return true if successful. False otherwise.
@@ -534,7 +506,7 @@
SharedFileObject attachment = (SharedFileObject) i.next();
if(uploadAttachment(attachment)) {
//If the attachment was successfully inserted, we update the
message on disk.
- saveMessage(msg, file);
+ msg.saveToFile(file);
} else {
success = false;
}