Esempio n. 1
0
        public static void SaveFormatted(AddinDescription adesc)
        {
            XmlDocument  doc       = adesc.SaveToXml();
            XmlFormatter formatter = new XmlFormatter();

            TextStylePolicy     textPolicy = new TextStylePolicy(80, 4, false, false, true, EolMarker.Unix);
            XmlFormattingPolicy xmlPolicy  = new XmlFormattingPolicy();

            XmlFormatingSettings f = new XmlFormatingSettings();

            f.ScopeXPath.Add("*/*");
            f.EmptyLinesBeforeStart = 1;
            f.EmptyLinesAfterEnd    = 1;
            xmlPolicy.Formats.Add(f);

            f = new XmlFormatingSettings();
            f.ScopeXPath.Add("Addin");
            f.AttributesInNewLine = true;
            f.AlignAttributes     = true;
            f.AttributesInNewLine = false;
            xmlPolicy.Formats.Add(f);

            string xml = formatter.FormatXml(textPolicy, xmlPolicy, doc.OuterXml);

            File.WriteAllText(adesc.FileName, xml);
        }
		public static string FormatXml (TextStylePolicy textPolicy, XmlFormattingPolicy formattingPolicy, string input)
		{
			XmlDocument doc;
			try {
				doc = new XmlDocument ();
				doc.LoadXml (input);
			} catch (XmlException ex) {
				// handle xml files without root element (https://bugzilla.xamarin.com/show_bug.cgi?id=4748)
				if (ex.Message == "Root element is missing.")
					return input;
				MonoDevelop.Core.LoggingService.LogWarning ("Error formatting XML file", ex);
				IdeApp.Workbench.StatusBar.ShowError ("Error formatting file: " + ex.Message);
				return input;
			} catch (Exception ex) {
				// Ignore malformed xml
				MonoDevelop.Core.LoggingService.LogWarning ("Error formatting XML file", ex);
				IdeApp.Workbench.StatusBar.ShowError ("Error formatting file: " + ex.Message);
				return input;
			}
			
			var sw = new StringWriter ();
			var xmlWriter = new XmlFormatterWriter (sw);
			xmlWriter.WriteNode (doc, formattingPolicy, textPolicy);
			xmlWriter.Flush ();
			return sw.ToString ();
		}
Esempio n. 3
0
        public static string SaveFormattedXml(PolicyContainer policies, AddinDescription adesc)
        {
            XmlDocument doc = adesc.SaveToXml();

            TextStylePolicy     textPolicy = policies.Get <TextStylePolicy> (DesktopService.GetMimeTypeInheritanceChain("application/x-addin+xml"));
            XmlFormattingPolicy xmlPolicy  = policies.Get <XmlFormattingPolicy> (DesktopService.GetMimeTypeInheritanceChain("application/x-addin+xml"));

            return(XmlFormatter.FormatXml(textPolicy, xmlPolicy, doc.OuterXml));
        }
		public void SetFormat (XmlFormattingPolicy policy)
		{
			this.policy = policy;
			Update ();
			TreeIter it;
			if (store.GetIterFirst (out it))
				listView.Selection.SelectIter (it);
			if (policy.Formats.Count == 0) {
				boxScopes.Hide ();
				buttonAdvanced.Show ();
			} else {
				boxScopes.Show ();
				buttonAdvanced.Hide ();
			}
		}
Esempio n. 5
0
		public string FormatXml (TextStylePolicy textPolicy, XmlFormattingPolicy formattingPolicy, string input)
		{
			XmlDocument doc;
			try {
				doc = new XmlDocument ();
				doc.LoadXml (input);
			} catch {
				// Ignore malformed xml
				return input;
			}
			
			StringWriter sw = new StringWriter ();
			XmlFormatterWriter xmlWriter = new XmlFormatterWriter (sw);
			xmlWriter.WriteNode (doc, formattingPolicy, textPolicy);
			xmlWriter.Flush ();
			return sw.ToString ();
		}
Esempio n. 6
0
		public static string FormatXml (TextStylePolicy textPolicy, XmlFormattingPolicy formattingPolicy, string input)
		{
			XmlDocument doc;
			try {
				doc = new XmlDocument ();
				doc.LoadXml (input);
			} catch (Exception ex) {
				// Ignore malformed xml
				MonoDevelop.Core.LoggingService.LogWarning ("Error formatting XML file", ex);
				return null;
			}
			
			var sw = new StringWriter ();
			var xmlWriter = new XmlFormatterWriter (sw);
			xmlWriter.WriteNode (doc, formattingPolicy, textPolicy);
			xmlWriter.Flush ();
			return sw.ToString ();
		}
		public void WriteNode (XmlNode node, XmlFormattingPolicy formattingPolicy, TextStylePolicy textPolicy)
		{
			this.TextPolicy = textPolicy;
			formatMap.Clear ();
			defaultFormatSettings = formattingPolicy.DefaultFormat;
			foreach (XmlFormattingSettings format in formattingPolicy.Formats) {
				foreach (string xpath in format.ScopeXPath) {
					foreach (XmlNode n in node.SelectNodes (xpath))
						formatMap [n] = format;
				}
			}
			WriteNode (node);
		}
Esempio n. 8
0
 public void Init()
 {
     textPolicy = new TextStylePolicy();
     xmlPolicy  = new XmlFormattingPolicy();
 }
		public static void SaveFormatted (AddinDescription adesc)
		{
			XmlDocument doc = adesc.SaveToXml ();
			XmlFormatter formatter = new XmlFormatter ();
			
			TextStylePolicy textPolicy = new TextStylePolicy (80, 4, false, false, true, EolMarker.Unix);
			XmlFormattingPolicy xmlPolicy = new XmlFormattingPolicy ();
			
			XmlFormatingSettings f = new XmlFormatingSettings ();
			f.ScopeXPath.Add ("*/*");
			f.EmptyLinesBeforeStart = 1;
			f.EmptyLinesAfterEnd = 1;
			xmlPolicy.Formats.Add (f);
			
			f = new XmlFormatingSettings ();
			f.ScopeXPath.Add ("Addin");
			f.AttributesInNewLine = true;
			f.AlignAttributes = true;
			f.AttributesInNewLine = false;
			xmlPolicy.Formats.Add (f);
				
			string xml = formatter.FormatXml (textPolicy, xmlPolicy, doc.OuterXml);
			File.WriteAllText (adesc.FileName, xml);
		}
		public void Init ()
		{
			textPolicy = new TextStylePolicy ();
			xmlPolicy = new XmlFormattingPolicy ();
		}
Esempio n. 11
0
 public void Init()
 {
     textPolicy = new TextStylePolicy().WithEolMarker(EolMarker.Unix);
     xmlPolicy  = new XmlFormattingPolicy();
 }