tomboy r2254 - in trunk: . Tomboy Tomboy/Synchronization



Author: sharm
Date: Mon Dec 15 17:42:46 2008
New Revision: 2254
URL: http://svn.gnome.org/viewvc/tomboy?rev=2254&view=rev

Log:
* tomboy/Tomboy/Utils.cs: Add some useful XmlWriterSettings static
  members.  The settings specify unix line endings, among other things.

* tomboy/Tomboy/NoteTag.cs: Note about why we're still using
  XmlTextWriter.

* tomboy/Tomboy/Note.cs:
* tomboy/Tomboy/Synchronization/TomboySyncClient.cs:
* tomboy/Tomboy/Synchronization/FileSystemSyncServer.cs: XmlTextWriter
  -> XmlWriter.

* tomboy/Tomboy/NoteBuffer.cs: When serializing the note buffer, make
  sure only unix line endings are used.  Fixes bug #559094.

Modified:
   trunk/ChangeLog
   trunk/Tomboy/Note.cs
   trunk/Tomboy/NoteBuffer.cs
   trunk/Tomboy/NoteTag.cs
   trunk/Tomboy/Synchronization/FileSystemSyncServer.cs
   trunk/Tomboy/Synchronization/TomboySyncClient.cs
   trunk/Tomboy/Utils.cs

Modified: trunk/Tomboy/Note.cs
==============================================================================
--- trunk/Tomboy/Note.cs	(original)
+++ trunk/Tomboy/Note.cs	Mon Dec 15 17:42:46 2008
@@ -1228,7 +1228,7 @@
 		public static string WriteString(NoteData note)
 		{
 			StringWriter str = new StringWriter ();
-			XmlTextWriter xml = new XmlTextWriter (str);
+			XmlWriter xml = XmlWriter.Create (str, XmlEncoder.DocumentSettings);
 			Instance.Write (xml, note);
 			xml.Close ();
 			str.Flush();
@@ -1244,7 +1244,7 @@
 		{
 			string tmp_file = write_file + ".tmp";
 
-			XmlTextWriter xml = new XmlTextWriter (tmp_file, System.Text.Encoding.UTF8);
+			XmlWriter xml = XmlWriter.Create (tmp_file, XmlEncoder.DocumentSettings);
 			Write (xml, note);
 			xml.Close ();
 
@@ -1274,15 +1274,13 @@
 
 		public void WriteFile (TextWriter writer, NoteData note)
 		{
-			XmlTextWriter xml = new XmlTextWriter (writer);
+			XmlWriter xml = XmlWriter.Create (writer, XmlEncoder.DocumentSettings);
 			Write (xml, note);
 			xml.Close ();
 		}
 
-		void Write (XmlTextWriter xml, NoteData note)
+		void Write (XmlWriter xml, NoteData note)
 		{
-			xml.Formatting = Formatting.Indented;
-
 			xml.WriteStartDocument ();
 			xml.WriteStartElement (null, "note", "http://beatniksoftware.com/tomboy";);
 			xml.WriteAttributeString(null,

Modified: trunk/Tomboy/NoteBuffer.cs
==============================================================================
--- trunk/Tomboy/NoteBuffer.cs	(original)
+++ trunk/Tomboy/NoteBuffer.cs	Mon Dec 15 17:42:46 2008
@@ -1140,7 +1140,16 @@
 			Serialize (buffer, start, end, xml);
 
 			xml.Close ();
-			return stream.ToString ();
+			string serializedBuffer = stream.ToString ();
+			
+			// We cannot use newer XmlWriter with XmlWriterSettings
+			// to control the newline character, because XmlWriter
+			// doesn't like elements with ":" in the name.  The
+			// point here is to write these files identically on
+			// all platforms, to make synchronization work better.
+			if (Environment.NewLine != "\n")
+				serializedBuffer = serializedBuffer.Replace (Environment.NewLine, "\n");
+			return serializedBuffer;
 		}
 
 		static void WriteTag (Gtk.TextTag tag, XmlTextWriter xml, bool start)

Modified: trunk/Tomboy/NoteTag.cs
==============================================================================
--- trunk/Tomboy/NoteTag.cs	(original)
+++ trunk/Tomboy/NoteTag.cs	Mon Dec 15 17:42:46 2008
@@ -160,6 +160,10 @@
 			end.ForwardToTagToggle (this);
 		}
 
+		// XmlTextWriter is required, because an XmlWriter created with
+		// XmlWriter.Create considers ":" to be an invalid character
+		// for an element name.
+		// http://bugzilla.gnome.org/show_bug.cgi?id=559094
 		public virtual void Write (XmlTextWriter xml, bool start)
 		{
 			if (CanSerialize) {

Modified: trunk/Tomboy/Synchronization/FileSystemSyncServer.cs
==============================================================================
--- trunk/Tomboy/Synchronization/FileSystemSyncServer.cs	(original)
+++ trunk/Tomboy/Synchronization/FileSystemSyncServer.cs	Mon Dec 15 17:42:46 2008
@@ -237,10 +237,8 @@
 				}
 
 				// Write out the new manifest file
-				XmlTextWriter xml = new XmlTextWriter (manifestFilePath, System.Text.Encoding.UTF8);
+				XmlWriter xml = XmlWriter.Create (manifestFilePath, XmlEncoder.DocumentSettings);
 				try {
-					xml.Formatting = Formatting.Indented;
-
 					xml.WriteStartDocument ();
 					xml.WriteStartElement (null, "sync", null);
 					xml.WriteAttributeString ("revision", newRevision.ToString ());
@@ -496,10 +494,8 @@
 
 		private void UpdateLockFile (SyncLockInfo syncLockInfo)
 		{
-			XmlTextWriter xml = new XmlTextWriter (lockPath, System.Text.Encoding.UTF8);
+			XmlWriter xml = XmlWriter.Create (lockPath, XmlEncoder.DocumentSettings);
 			try {
-				xml.Formatting = Formatting.Indented;
-
 				xml.WriteStartDocument ();
 				xml.WriteStartElement (null, "lock", null);
 

Modified: trunk/Tomboy/Synchronization/TomboySyncClient.cs
==============================================================================
--- trunk/Tomboy/Synchronization/TomboySyncClient.cs	(original)
+++ trunk/Tomboy/Synchronization/TomboySyncClient.cs	Mon Dec 15 17:42:46 2008
@@ -138,11 +138,9 @@
 		private void Write (string manifestPath)
 		{
 			// TODO: Handle file permission errors
-			XmlTextWriter xml = new XmlTextWriter (manifestPath, System.Text.Encoding.UTF8);
+			XmlWriter xml = XmlWriter.Create (manifestPath, XmlEncoder.DocumentSettings);
 
 			try {
-				xml.Formatting = Formatting.Indented;
-
 				xml.WriteStartDocument ();
 				xml.WriteStartElement (null, "manifest", "http://beatniksoftware.com/tomboy";);
 

Modified: trunk/Tomboy/Utils.cs
==============================================================================
--- trunk/Tomboy/Utils.cs	(original)
+++ trunk/Tomboy/Utils.cs	Mon Dec 15 17:42:46 2008
@@ -527,9 +527,20 @@
 		static StringBuilder builder;
 		static StringWriter writer;
 		static XmlTextWriter xml;
+		static XmlWriterSettings documentSettings;
+		static XmlWriterSettings fragmentSettings;
 
 		static XmlEncoder ()
 		{
+			documentSettings = new XmlWriterSettings ();
+			documentSettings.NewLineChars = "\n";
+			documentSettings.Indent = true;
+
+			fragmentSettings = new XmlWriterSettings ();
+			fragmentSettings.NewLineChars = "\n";
+			fragmentSettings.Indent = true;
+			fragmentSettings.ConformanceLevel = ConformanceLevel.Fragment;
+
 			builder = new StringBuilder ();
 			writer = new StringWriter (builder);
 			xml = new XmlTextWriter (writer);
@@ -543,6 +554,16 @@
 			builder.Length = 0;
 			return val;
 		}
+
+		public static XmlWriterSettings DocumentSettings
+		{
+			get { return documentSettings; }
+		}
+
+		public static XmlWriterSettings FragmentSettings
+		{
+			get { return fragmentSettings; }
+		}
 	}
 
 	// Strip xml tags



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]