[mapguide-commits] r4913 - in sandbox/maestro-2.5: Maestro
Maestro.Base/Editor Maestro.Editors/Generic
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Wed May 19 07:46:13 EDT 2010
Author: jng
Date: 2010-05-19 07:46:12 -0400 (Wed, 19 May 2010)
New Revision: 4913
Modified:
sandbox/maestro-2.5/Maestro.Base/Editor/XmlEditor.cs
sandbox/maestro-2.5/Maestro.Editors/Generic/XmlEditorCtrl.cs
sandbox/maestro-2.5/Maestro/Maestro.csproj
Log:
Make XML validation an externally pluggable function. As a result, the validate button is only enabled if a validation function has been specified.
Modified: sandbox/maestro-2.5/Maestro/Maestro.csproj
===================================================================
--- sandbox/maestro-2.5/Maestro/Maestro.csproj 2010-05-19 11:13:02 UTC (rev 4912)
+++ sandbox/maestro-2.5/Maestro/Maestro.csproj 2010-05-19 11:46:12 UTC (rev 4913)
@@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.30729</ProductVersion>
+ <ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E0C36475-2B70-4F6D-ACE0-8943167806DC}</ProjectGuid>
<OutputType>WinExe</OutputType>
@@ -54,78 +54,6 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\ApplicationDefinition-1.0.0.xsd">
- <Link>ApplicationDefinition-1.0.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\DrawingSource-1.0.0.xsd">
- <Link>DrawingSource-1.0.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\FeatureSource-1.0.0.xsd">
- <Link>FeatureSource-1.0.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\LayerDefinition-1.0.0.xsd">
- <Link>LayerDefinition-1.0.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\LayerDefinition-1.1.0.xsd">
- <Link>LayerDefinition-1.1.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\LayerDefinition-1.2.0.xsd">
- <Link>LayerDefinition-1.2.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\LayerDefinition-1.3.0.xsd">
- <Link>LayerDefinition-1.3.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\LoadProcedure-1.0.0.xsd">
- <Link>LoadProcedure-1.0.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\LoadProcedure-1.1.0.xsd">
- <Link>LoadProcedure-1.1.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\LoadProcedure-2.2.0.xsd">
- <Link>LoadProcedure-2.2.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\MapDefinition-1.0.0.xsd">
- <Link>MapDefinition-1.0.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\PlatformCommon-1.0.0.xsd">
- <Link>PlatformCommon-1.0.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\PrintLayout-1.0.0.xsd">
- <Link>PrintLayout-1.0.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\SymbolDefinition-1.0.0.xsd">
- <Link>SymbolDefinition-1.0.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\SymbolDefinition-1.1.0.xsd">
- <Link>SymbolDefinition-1.1.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\SymbolLibrary-1.0.0.xsd">
- <Link>SymbolLibrary-1.0.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\WebLayout-1.0.0.xsd">
- <Link>WebLayout-1.0.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
- <None Include="..\OSGeo.MapGuide.MaestroAPI\Schemas\WebLayout-1.1.0.xsd">
- <Link>WebLayout-1.1.0.xsd</Link>
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- </None>
<None Include="Maestro.sh">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Modified: sandbox/maestro-2.5/Maestro.Base/Editor/XmlEditor.cs
===================================================================
--- sandbox/maestro-2.5/Maestro.Base/Editor/XmlEditor.cs 2010-05-19 11:13:02 UTC (rev 4912)
+++ sandbox/maestro-2.5/Maestro.Base/Editor/XmlEditor.cs 2010-05-19 11:46:12 UTC (rev 4913)
@@ -28,6 +28,8 @@
using System.IO;
using OSGeo.MapGuide.MaestroAPI.Resource;
using ICSharpCode.Core;
+using OSGeo.MapGuide.MaestroAPI;
+using System.Xml;
namespace Maestro.Base.Editor
{
@@ -36,8 +38,52 @@
public XmlEditor()
{
InitializeComponent();
+ editor.Validator = new XmlValidationCallback(ValidateXml);
}
+ private void ValidateXml(out string[] errors, out string[] warnings)
+ {
+ errors = new string[0];
+ warnings = new string[0];
+
+ List<string> err = new List<string>();
+ List<string> warn = new List<string>();
+
+ var res = this.Resource;
+
+ //Test for well-formedness
+ try
+ {
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(editor.XmlContent);
+ }
+ catch (XmlException ex)
+ {
+ err.Add(ex.Message);
+ }
+
+ //If strongly-typed, test that this is serializable
+ if (res.IsStronglyTyped)
+ {
+ try
+ {
+ //Test by simply attempting to deserialize the current xml content
+ using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(editor.XmlContent)))
+ {
+ //Use original resource type to determine how to deserialize
+ var obj = ResourceTypeRegistry.Deserialize(res.ResourceType, ms);
+ }
+ }
+ catch (Exception ex)
+ {
+ err.Add(ex.Message);
+ }
+ }
+
+ errors = err.ToArray();
+ warnings = warn.ToArray();
+ }
+
protected override void Bind(OSGeo.MapGuide.MaestroAPI.Resource.IResource value)
{
//HACK: Scrub out junk <ExtendedData1> elements.
Modified: sandbox/maestro-2.5/Maestro.Editors/Generic/XmlEditorCtrl.cs
===================================================================
--- sandbox/maestro-2.5/Maestro.Editors/Generic/XmlEditorCtrl.cs 2010-05-19 11:13:02 UTC (rev 4912)
+++ sandbox/maestro-2.5/Maestro.Editors/Generic/XmlEditorCtrl.cs 2010-05-19 11:46:12 UTC (rev 4913)
@@ -31,6 +31,8 @@
namespace Maestro.Editors.Generic
{
+ public delegate void XmlValidationCallback(out string[] errors, out string[] warnings);
+
public partial class XmlEditorCtrl : UserControl
{
private bool _ready = false;
@@ -40,6 +42,8 @@
InitializeComponent();
}
+ public XmlValidationCallback Validator { get; set; }
+
public Color TextColor
{
get { return txtXmlContent.ForeColor; }
@@ -74,6 +78,7 @@
btnCut.Enabled = txtXmlContent.SelectionLength > 0;
btnCopy.Enabled = txtXmlContent.SelectionLength > 0;
btnPaste.Enabled = Clipboard.ContainsText();
+ btnValidate.Enabled = (this.Validator != null);
}
public string XmlContent
@@ -207,42 +212,18 @@
private void btnValidate_Click(object sender, EventArgs e)
{
- List<string> errors = new List<string>();
- List<string> warnings = new List<string>();
-
- // Set the validation settings.
- XmlReaderSettings settings = new XmlReaderSettings();
- settings.ValidationType = ValidationType.Schema;
- settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
- settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
- settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
- settings.ValidationEventHandler += (s, evt) =>
+ if (this.Validator != null)
{
- if (evt.Severity == XmlSeverityType.Error)
- errors.Add(evt.Message);
+ string[] errors;
+ string[] warnings;
+
+ this.Validator(out errors, out warnings);
+
+ if (errors.Length > 0 || warnings.Length > 0)
+ new XmlValidationResult(errors, warnings).Show();
else
- warnings.Add(evt.Message);
- };
-
- using(var ms = new MemoryStream(Encoding.UTF8.GetBytes(txtXmlContent.Text)))
- {
- using (var reader = XmlReader.Create(ms, settings))
- {
- try
- {
- while (reader.Read()) ;
- }
- catch (XmlException ex)
- {
- errors.Add(ex.Message);
- }
- }
+ MessageBox.Show(Properties.Resources.XmlDocIsValid);
}
-
- if (errors.Count > 0 || warnings.Count > 0)
- new XmlValidationResult(errors, warnings).Show();
- else
- MessageBox.Show(Properties.Resources.XmlDocIsValid);
}
private void btnFormat_Click(object sender, EventArgs e)
More information about the mapguide-commits
mailing list