From c75ee591401cbcbf32ea7839e5beaef7d67b8706 Mon Sep 17 00:00:00 2001 From: erezmazor Date: Sat, 11 Jul 2009 20:25:38 +0000 Subject: [PATCH] - Added custom namespace definition for (spring-template-1.2.xsd) the associated entry in NamespaceParserRegistry - Added documentation for the spring template nvelocity implementation --- Spring.Net.2008.sln | 24 ++ doc/reference/src/index.xml | 15 +- doc/reference/src/templating.xml | 223 ++++++++++++++++++ .../Factory/Xml/NamespaceParserRegistry.cs | 1 + .../Spring.Template.Velocity.2008.csproj | 5 + .../Config/TemplateNamespaceParser.cs | 192 +++++++++++++++ .../Template/Config/spring-template-1.2.xsd | 117 +++++++++ .../VelocityEngineFactoryObjectTests.cs | 13 + .../VelocityEngineFactoryObjectTests.xml | 10 +- 9 files changed, 596 insertions(+), 4 deletions(-) create mode 100644 doc/reference/src/templating.xml create mode 100644 src/Spring/Spring.Template.Velocity/Template/Config/TemplateNamespaceParser.cs create mode 100644 src/Spring/Spring.Template.Velocity/Template/Config/spring-template-1.2.xsd diff --git a/Spring.Net.2008.sln b/Spring.Net.2008.sln index e5dc5b7b..982b141c 100644 --- a/Spring.Net.2008.sln +++ b/Spring.Net.2008.sln @@ -63,6 +63,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Data.NHibernate21.Te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Data.NHibernate21.2008", "src\Spring\Spring.Data.NHibernate21\Spring.Data.NHibernate21.2008.csproj", "{E57B4652-0231-49CB-B058-87E10EFE540D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Template.Velocity.2008", "src\Spring\Spring.Template.Velocity\Spring.Template.Velocity.2008.csproj", "{BF3AB954-8375-407C-9E98-4C51D8072784}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Template.Velocity.Tests", "test\Spring\Spring.Template.Velocity.Tests\Spring.Template.Velocity.Tests.csproj", "{10405837-CB67-40D8-9326-84C9383983E2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|.NET = Debug|.NET @@ -377,6 +381,26 @@ Global {E57B4652-0231-49CB-B058-87E10EFE540D}.Release|Any CPU.Build.0 = Release|Any CPU {E57B4652-0231-49CB-B058-87E10EFE540D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {E57B4652-0231-49CB-B058-87E10EFE540D}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {BF3AB954-8375-407C-9E98-4C51D8072784}.Debug|.NET.ActiveCfg = Debug|Any CPU + {BF3AB954-8375-407C-9E98-4C51D8072784}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BF3AB954-8375-407C-9E98-4C51D8072784}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BF3AB954-8375-407C-9E98-4C51D8072784}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {BF3AB954-8375-407C-9E98-4C51D8072784}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {BF3AB954-8375-407C-9E98-4C51D8072784}.Release|.NET.ActiveCfg = Release|Any CPU + {BF3AB954-8375-407C-9E98-4C51D8072784}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BF3AB954-8375-407C-9E98-4C51D8072784}.Release|Any CPU.Build.0 = Release|Any CPU + {BF3AB954-8375-407C-9E98-4C51D8072784}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {BF3AB954-8375-407C-9E98-4C51D8072784}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {10405837-CB67-40D8-9326-84C9383983E2}.Debug|.NET.ActiveCfg = Debug|Any CPU + {10405837-CB67-40D8-9326-84C9383983E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {10405837-CB67-40D8-9326-84C9383983E2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {10405837-CB67-40D8-9326-84C9383983E2}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {10405837-CB67-40D8-9326-84C9383983E2}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {10405837-CB67-40D8-9326-84C9383983E2}.Release|.NET.ActiveCfg = Release|Any CPU + {10405837-CB67-40D8-9326-84C9383983E2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {10405837-CB67-40D8-9326-84C9383983E2}.Release|Any CPU.Build.0 = Release|Any CPU + {10405837-CB67-40D8-9326-84C9383983E2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {10405837-CB67-40D8-9326-84C9383983E2}.Release|Mixed Platforms.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/doc/reference/src/index.xml b/doc/reference/src/index.xml index c6370f6c..5610d79d 100644 --- a/doc/reference/src/index.xml +++ b/doc/reference/src/index.xml @@ -1,4 +1,4 @@ - + @@ -17,6 +17,7 @@ + @@ -62,7 +63,7 @@ The Spring.NET Framework Reference Documentation Version 1.2.1 - Last Updated April xx, 2009 (Latest documentation) + Last Updated July xx, 2009 (Latest documentation) Mark @@ -104,6 +105,10 @@ Choy Rim + + Erez + Mazor + The Spring Java Team @@ -328,11 +333,17 @@ + + + + + &messaging; &msmq; &scheduling; + &templating; VS.NET Integration diff --git a/doc/reference/src/templating.xml b/doc/reference/src/templating.xml new file mode 100644 index 00000000..5fc77f98 --- /dev/null +++ b/doc/reference/src/templating.xml @@ -0,0 +1,223 @@ + + + + Template Engine Support + +
+ Introduction + + The Spring Framework features integration classes for templating + engine support. Currently, Spring supports the NVelocity + templating engine. +
+ +
+ Dependencies + + The Spring NVelocity support depends on the Castle project's + NVelocity implementation which is provided in the lib directory of the + spring release. +
+ +
+ Using the NVelocity Factory Object + + The NVelocity template engine is set up using a + IFactoryObject with optional configuration parameters + to define where templates reside, define logging and more. + +
+ Simple file based template engine definition + + A simple definition of the template engine: + + <!-- Simple no arg file based configuration use's NVeclocity default file resource loader --> +<object id="velocityEngine" type="Spring.Template.Velocity.VelocityEngineFactoryObject, Spring.Template.Velocity" /> + + The velocity engine could then be used to load and merge a local + template using a simple relative path: + + StringWriter stringWriter = new StringWriter(); +Hashtable modelTable = new Hashtable(); +modelTable.Add("var1", TEST_VALUE); +VelocityContext velocityContext = new VelocityContext(modelTable); +velocityEngine.MergeTemplate("Template/Velocity/MyTemplate.vm", Encoding.UTF8.WebName, velocityContext, stringWriter); +string mergedContent = stringWriter.ToString(); +
+ +
+ Assembly based template loading + + When templates are packaged in an assembly, NVelocity's assembly + resource loader can be used to define where templates reside: + + <!-- Assembly based template loading with NVelocity assembly resource loader --> +<object id="assemblyBasedVelocityEngine" type="Spring.Template.Velocity.VelocityEngineFactoryObject, Spring.Template.Velocity"> + <property name="VelocityProperties"> + <dictionary key-type="string" value-type="object"> + <entry key="resource.loader" value="assembly"/> + <entry key="assembly.resource.loader.class" value="NVelocity.Runtime.Resource.Loader.AssemblyResourceLoader"/> + <entry key="assembly.resource.loader.assembly" value="MyAssembly"/> + </dictionary> + </property> +</object> + + Using the example above the template would be loaded using a + namespace syntax for the template resource: + + velocityEngine.MergeTemplate("MyAssembly.MyNamespace.MyTemplate.vm", Encoding.UTF8.WebName, velocityContext, stringWriter); + + Using the custom namespace the same definition could be + simplified: + + <template:nvelocity id="velocityEngine" > + <template:resource-loader> + <template:assembly name="MyAssembly" /> + </template:resource-loader> +</template:nvelocity> +
+ +
+ Using Spring's <literal>IResourceLoader</literal> to load + templates + + In some cases Spring's resource abstraction can be beneficial to + load templates from a variety of resources. A spring resource loader + extension to the NVelocity resource loader implementation is provided + for this use case. + + <object id="velocityEngine" type="Spring.Template.Velocity.VelocityEngineFactoryObject, Spring.Template.Velocity" > + <property name="ResourceLoaderPath" value="file://MyTemplateFolder/AnotherFolder/" /> +</object> + + + Or with multiple locations + + <object id="velocityEngine" type="Spring.Template.Velocity.VelocityEngineFactoryObject, Spring.Template.Velocity" > + <property name="ResourceLoaderPaths" > + <list> + <value>file://MyTemplateFolder/</value> + <value>file://MyOtherTemplateFolder/</value> + </list> + </property> +</object> + + + By default spring will attempt to load resources using file + based template loading (useful for detection of template changes at + runtime). If this is not desirable you set the + preferFileSystemAccess property of the factory + object to false + (prefer-file-system-access="false" for custom + namespace use) + + + Using the example above when resource loader paths are defined + templates can be loaded using their name: + + string mergedTemplate = VelocityEngineUtils.MergeTemplateIntostring(velocityEngine, "MyTemplate.vm", Encoding.UTF8.WebName, model); +
+ +
+ Using a custom configuration file + + If so desired one could provide a custom configuration resource to + customize the NVelocity configuration: + + <object id="velocityEngine" type="Spring.Template.Velocity.VelocityEngineFactoryObject, Spring.Template.Velocity" > + <property name="ConfigLocation " value="file://Template/Velocity/config.properties" /> +</object> + + + + You can override specific properties by providing the VelocityProperties property to the NVelocity factory object (shown above) + + +
+ +
+ + + Logging + + + + By default Spring will override NVelocity's default + ILogSystem implementation with its own + CommonsLoggingLogSystem implementation. If this is + not desirable, you can specify the following property of the NVelocity + factory object: + + + + <object id="velocityEngine" type="Spring.Template.Velocity.VelocityEngineFactoryObject, Spring.Template.Velocity" > + <property name="OverrideLogging" value="false" /> +</object> + + or + + <template:nvelocity id="velocityEngine" override-logging="false" /> + + + + + + You can override specific NVelocity properties locally by + providing a dictionary as the VelocityProperties + property of the NVelocity factory object (shown above) + + + +
+
+ +
+ Merging a template + + Spring provides the VelocityEngineUtils utility + for merging templates using an engine instance: + + string mergedTemplate = VelocityEngineUtils.MergeTemplateIntostring(velocityEngine, "MyTemplate.vm", Encoding.UTF8.WebName, model); +
+ +
+ Namespace + + For convinience in defining NVelocity engine instances a custom + namespace is provided, for example the resource loader definition could be + done this way: + + +<objects xmlns="http://www.springframework.net" xmlns:template="http://www.springframework.net/template"> + +<template:nvelocity id="customNamespaceVelocityTemplate" > + <template:resource-loader> + <template:file path="Template/Velocity/" /> + </template:resource-loader> +</template:nvelocity> + +</objects> +
+
diff --git a/src/Spring/Spring.Core/Objects/Factory/Xml/NamespaceParserRegistry.cs b/src/Spring/Spring.Core/Objects/Factory/Xml/NamespaceParserRegistry.cs index 863b5a1a..74fa07ac 100644 --- a/src/Spring/Spring.Core/Objects/Factory/Xml/NamespaceParserRegistry.cs +++ b/src/Spring/Spring.Core/Objects/Factory/Xml/NamespaceParserRegistry.cs @@ -102,6 +102,7 @@ namespace Spring.Objects.Factory.Xml wellknownNamespaceParserTypeNames["http://www.springframework.net/nms"] = "Spring.Messaging.Nms.Config.NmsNamespaceParser, Spring.Messaging.Nms"; wellknownNamespaceParserTypeNames["http://www.springframework.net/ems"] = "Spring.Messaging.Ems.Config.EmsNamespaceParser, Spring.Messaging.Ems"; wellknownNamespaceParserTypeNames["http://www.springframework.net/validation"] = "Spring.Validation.Config.ValidationNamespaceParser, Spring.Core"; + wellknownNamespaceParserTypeNames["http://www.springframework.net/template"] = "Spring.Template.Config.TemplateNamespaceParser, Spring.Template.Velocity"; Reset(); } diff --git a/src/Spring/Spring.Template.Velocity/Spring.Template.Velocity.2008.csproj b/src/Spring/Spring.Template.Velocity/Spring.Template.Velocity.2008.csproj index 316884ec..82731207 100644 --- a/src/Spring/Spring.Template.Velocity/Spring.Template.Velocity.2008.csproj +++ b/src/Spring/Spring.Template.Velocity/Spring.Template.Velocity.2008.csproj @@ -58,6 +58,7 @@ ..\..\..\lib\Net\2.0\NVelocity.dll + @@ -66,6 +67,7 @@ + @@ -99,6 +101,9 @@ false + + + @@ -39,5 +46,4 @@ - \ No newline at end of file