From: <bo...@us...> - 2010-05-19 08:04:32
|
Revision: 392 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=392&view=rev Author: bodewig Date: 2010-05-19 08:04:25 +0000 (Wed, 19 May 2010) Log Message: ----------- documentation Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/builder/Input.java trunk/xmlunit/src/main/net-core/ISource.cs trunk/xmlunit/src/main/net-core/builder/Input.cs Added Paths: ----------- trunk/xmlunit/src/main/net-core/builder/AbstractTransformationBuilder.cs trunk/xmlunit/src/main/net-core/builder/ITransformationBuilderBase.cs trunk/xmlunit/src/main/net-core/builder/Transform.cs Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/builder/Input.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/builder/Input.java 2010-05-19 06:57:47 UTC (rev 391) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/builder/Input.java 2010-05-19 08:04:25 UTC (rev 392) @@ -32,9 +32,15 @@ import org.w3c.dom.Document; import org.w3c.dom.Node; +/** + * Fluent API to create Source instances. + */ public class Input { public static interface Builder { + /** + * build the actual Source instance. + */ Source build(); } @@ -49,10 +55,16 @@ } } + /** + * Build a Source from a DOM Document. + */ public static Builder fromDocument(Document d) { return new DOMBuilder(d); } + /** + * Build a Source from a DOM Node. + */ public static Builder fromNode(Node n) { return new DOMBuilder(n); } @@ -79,30 +91,51 @@ } } + /** + * Build a Source from a file. + */ public static Builder fromFile(File f) { return new StreamBuilder(f); } + /** + * Build a Source from a named file. + */ public static Builder fromFile(String name) { return new StreamBuilder(new File(name)); } + /** + * Build a Source from a stream. + */ public static Builder fromStream(InputStream s) { return new StreamBuilder(s); } + /** + * Build a Source from a reader. + */ public static Builder fromReader(Reader r) { return new StreamBuilder(r); } + /** + * Build a Source from a string. + */ public static Builder fromMemory(String s) { return fromReader(new StringReader(s)); } + /** + * Build a Source from an array of bytes. + */ public static Builder fromMemory(byte[] b) { return fromStream(new ByteArrayInputStream(b)); } + /** + * Build a Source from an URL. + */ public static Builder fromURL(URL url) { try { InputStream in = null; @@ -136,6 +169,10 @@ } } + /** + * Build a Source from an URI. + * @param uri must represent a valid URL + */ public static Builder fromURI(URI uri) { try { return fromURL(uri.toURL()); @@ -145,6 +182,10 @@ } } + /** + * Build a Source from an URI. + * @param uri must represent a valid URL + */ public static Builder fromURI(String uri) { try { return fromURI(new URI(uri)); @@ -158,6 +199,9 @@ TransformationBuilder usingFactory(TransformerFactory f); TransformationBuilder withOutputProperty(String name, String value); TransformationBuilder withParameter(String name, Object value); + /** + * Sets the stylesheet to use. + */ TransformationBuilder withStylesheet(Builder b); TransformationBuilder withStylesheet(Source s); TransformationBuilder withURIResolver(URIResolver r); @@ -202,10 +246,16 @@ } } + /** + * Build a Source by XSLT transforming a different Source. + */ public static TransformationBuilder byTransforming(Source s) { return new Transformation(s); } + /** + * Build a Source by XSLT transforming a different Source. + */ public static TransformationBuilder byTransforming(Builder b) { return byTransforming(b.build()); } Modified: trunk/xmlunit/src/main/net-core/ISource.cs =================================================================== --- trunk/xmlunit/src/main/net-core/ISource.cs 2010-05-19 06:57:47 UTC (rev 391) +++ trunk/xmlunit/src/main/net-core/ISource.cs 2010-05-19 08:04:25 UTC (rev 392) @@ -14,8 +14,18 @@ using System.Xml; namespace net.sf.xmlunit { + /// <summary> + /// Representation of the various ways to provide pieces of XML to + /// XMLUnit. + /// </summary> public interface ISource { + /// <summary> + /// Provides the content. + /// </summary> XmlReader Reader {get;} + /// <summary> + /// Some sort of Base-URI of this ISource. + /// </summary> string SystemId {get; set;} } } Added: trunk/xmlunit/src/main/net-core/builder/AbstractTransformationBuilder.cs =================================================================== --- trunk/xmlunit/src/main/net-core/builder/AbstractTransformationBuilder.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/builder/AbstractTransformationBuilder.cs 2010-05-19 08:04:25 UTC (rev 392) @@ -0,0 +1,72 @@ +/* + This file is licensed to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using System.Xml; +using net.sf.xmlunit.transform; + +namespace net.sf.xmlunit.builder { + + internal abstract class AbstractTransformationBuilder<T> + : ITransformationBuilderBase<T> + where T : class, ITransformationBuilderBase<T> { + private readonly Transformation t; + + protected AbstractTransformationBuilder(ISource s) { + t = new Transformation(s); + } + public T WithStylesheet(ISource s) { + t.Stylesheet = s; + return this as T; + } + public T WithExtensionObject(string namespaceUri, object extension) { + t.AddExtensionObject(namespaceUri, extension); + return this as T; + } + public T WithParameter(string name, string namespaceUri, + object parameter) { + t.AddParameter(name, namespaceUri, parameter); + return this as T; + } + public T WithXmlResolver(XmlResolver r) { + t.XmlResolver = r; + return this as T; + } + public T WithScripting() { + return WithScripting(true); + } + public T WithoutScripting() { + return WithScripting(false); + } + private T WithScripting(bool b) { + t.EnableScriptBlocks = b; + return this as T; + } + public T WithDocumentFunction() { + return WithDocumentFunction(true); + } + public T WithoutDocumentFunction() { + return WithDocumentFunction(false); + } + private T WithDocumentFunction(bool b) { + t.EnableDocumentFunction = b; + return this as T; + } + + protected Transformation Helper { + get { + return t; + } + } + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/main/net-core/builder/AbstractTransformationBuilder.cs ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/xmlunit/src/main/net-core/builder/ITransformationBuilderBase.cs =================================================================== --- trunk/xmlunit/src/main/net-core/builder/ITransformationBuilderBase.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/builder/ITransformationBuilderBase.cs 2010-05-19 08:04:25 UTC (rev 392) @@ -0,0 +1,30 @@ +/* + This file is licensed to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using System.Xml; + +namespace net.sf.xmlunit.builder { + + public interface ITransformationBuilderBase<T> + where T : ITransformationBuilderBase<T> { + T WithDocumentFunction(); + T WithExtensionObject(string namespaceUri, object extension); + T WithParameter(string name, string namespaceUri, object parameter); + T WithScripting(); + T WithStylesheet(ISource s); + T WithXmlResolver(XmlResolver r); + T WithoutDocumentFunction(); + T WithoutScripting(); + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/main/net-core/builder/ITransformationBuilderBase.cs ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/xmlunit/src/main/net-core/builder/Input.cs =================================================================== --- trunk/xmlunit/src/main/net-core/builder/Input.cs 2010-05-19 06:57:47 UTC (rev 391) +++ trunk/xmlunit/src/main/net-core/builder/Input.cs 2010-05-19 08:04:25 UTC (rev 392) @@ -18,8 +18,14 @@ using net.sf.xmlunit.input; namespace net.sf.xmlunit.builder { - public static class Input { + /// <summary> + /// Fluent API to create ISource instances. + /// </summary> + public sealed class Input { public interface IBuilder { + /// <summary> + /// build the actual ISource instance. + /// </summary> ISource Build(); } @@ -33,10 +39,16 @@ } } + /// <summary> + /// Build an ISource from a DOM Document. + /// </summary> public static IBuilder FromDocument(XmlDocument d) { return new DOMBuilder(d); } + /// <summary> + /// Build an ISource from a DOM Node. + /// </summary> public static IBuilder FromNode(XmlNode n) { return new DOMBuilder(n); } @@ -62,10 +74,16 @@ } } + /// <summary> + /// Build an ISource from a named file. + /// </summary> public static IBuilder FromFile(string name) { return new StreamBuilder(name); } + /// <summary> + /// Build an ISource from a stream. + /// </summary> public static IBuilder FromStream(Stream s) { StreamBuilder b = new StreamBuilder(s); if (s is FileStream) { @@ -75,6 +93,9 @@ return b; } + /// <summary> + /// Build an ISource from a reader. + /// </summary> public static IBuilder FromReader(TextReader r) { StreamBuilder b = new StreamBuilder(r); StreamReader s = r as StreamReader; @@ -86,18 +107,32 @@ return b; } + /// <summary> + /// Build an ISource from a string. + /// </summary> public static IBuilder FromMemory(string s) { return FromReader(new StringReader(s)); } + /// <summary> + /// Build an ISource from an array of bytes. + /// </summary> public static IBuilder FromMemory(byte[] b) { return FromStream(new MemoryStream(b)); } + /// <summary> + /// Build an ISource from an URI. + /// <param name="uri">must represent a valid URL</param> + /// </summary> public static IBuilder FromURI(string uri) { return new StreamBuilder(uri); } + /// <summary> + /// Build an ISource from an URI. + /// <param name="uri">must represent a valid URL</param> + /// </summary> public static IBuilder FromURI(System.Uri uri) { return new StreamBuilder(uri.AbsoluteUri); } @@ -111,6 +146,9 @@ object parameter); ITransformationBuilder WithScripting(); ITransformationBuilder WithStylesheet(ISource s); + /// <summary> + /// Sets the stylesheet to use. + /// </summary> ITransformationBuilder WithStylesheet(IBuilder b); ITransformationBuilder WithXmlResolver(XmlResolver r); ITransformationBuilder WithoutDocumentFunction(); @@ -182,9 +220,15 @@ } } + /// <summary> + /// Build an ISource by XSLT transforming a different ISource. + /// </summary> public static ITransformationBuilder ByTransforming(ISource s) { return new Transformation(s); } + /// <summary> + /// Build an ISource by XSLT transforming a different ISource. + /// </summary> public static ITransformationBuilder ByTransforming(IBuilder b) { return ByTransforming(b.Build()); } Added: trunk/xmlunit/src/main/net-core/builder/Transform.cs =================================================================== --- trunk/xmlunit/src/main/net-core/builder/Transform.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/builder/Transform.cs 2010-05-19 08:04:25 UTC (rev 392) @@ -0,0 +1,64 @@ +/* + This file is licensed to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using System.IO; +using System.Xml; + +namespace net.sf.xmlunit.builder { + + public sealed class Transform { + + public interface IBuilder : ITransformationBuilderBase<IBuilder> { + ITransformationResult Build(); + } + public interface ITransformationResult { + void To(Stream s); + void To(TextWriter t); + void To(XmlWriter x); + string ToString(); + XmlDocument ToDocument(); + } + + + internal class TransformationBuilder + : AbstractTransformationBuilder<IBuilder>, IBuilder, + ITransformationResult { + + internal TransformationBuilder(ISource s) : base(s) { + } + public ITransformationResult Build() { + return this; + } + public override string ToString() { + return Helper.TransformToString(); + } + public XmlDocument ToDocument() { + return Helper.TransformToDocument(); + } + public void To(Stream s) { + Helper.TransformTo(s); + } + public void To(TextWriter w) { + Helper.TransformTo(w); + } + public void To(XmlWriter w) { + Helper.TransformTo(w); + } + } + + public static IBuilder Source(ISource s) { + return new TransformationBuilder(s); + } + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/main/net-core/builder/Transform.cs ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |