/// <summary> /// Initializes a new instance of the <see cref="CSF.Zpt.Rendering.IRenderingSettings"/> class. /// </summary> /// <param name="addSourceFileAnnotation">Indicates whether or not source file annotation is to be added.</param> /// <param name="elementVisitors">The element visitors to use.</param> /// <param name="contextFactory">The rendering context factory.</param> /// <param name="outputEncoding">The desired output encoding.</param> /// <param name="omitXmlDeclaration">Whether or not to omit the XML declaration.</param> /// <param name="documentFactory">An optional non-default implementation of <see cref="ITemplateFileFactory"/> to use.</param> public RenderingSettings(IContextVisitor[] elementVisitors, IRenderingContextFactory contextFactory, bool addSourceFileAnnotation, System.Text.Encoding outputEncoding, bool omitXmlDeclaration, ITemplateFileFactory documentFactory) { if(elementVisitors == null) { throw new ArgumentNullException(nameof(elementVisitors)); } if(contextFactory == null) { throw new ArgumentNullException(nameof(contextFactory)); } if(outputEncoding == null) { throw new ArgumentNullException(nameof(outputEncoding)); } if(documentFactory == null) { throw new ArgumentNullException(nameof(documentFactory)); } _contextVisitors = elementVisitors; this.ContextFactory = contextFactory; this.AddSourceFileAnnotation = addSourceFileAnnotation; this.OutputEncoding = outputEncoding; this.OmitXmlDeclaration = omitXmlDeclaration; this.TemplateFileFactory = documentFactory; }
/// <summary> /// Initializes a new instance of the <see cref="CSF.Zpt.Rendering.DefaultRenderingSettings"/> class. /// </summary> /// <param name="documentFactory">Document factory.</param> /// <param name="elementVisitors">Element visitors.</param> /// <param name="contextFactory">Context factory.</param> /// <param name="addSourceFileAnnotation">If set to <c>true</c> add source file annotation.</param> /// <param name="outputEncoding">Output encoding.</param> /// <param name="omitXmlDeclaration">If set to <c>true</c> omit XML declaration.</param> protected DefaultRenderingSettings(ITemplateFileFactory documentFactory = null, IContextVisitor[] elementVisitors = null, IRenderingContextFactory contextFactory = null, bool addSourceFileAnnotation = DefaultAddAnnotation, Encoding outputEncoding = null, bool omitXmlDeclaration = DefaultOmitXmlDeclaration) { this.TemplateFileFactory = documentFactory?? new ZptDocumentFactory(); this.AddSourceFileAnnotation = addSourceFileAnnotation; this.OmitXmlDeclaration = omitXmlDeclaration; this.ContextVisitors = elementVisitors?? DefaultVisitors; this.ContextFactory = contextFactory?? DefaultContextFactory; this.OutputEncoding = outputEncoding?? DefaultEncoding; }
/** <summary> * For all subtrees that match the pattern, execute the visit action. * The implementation uses the root node of the pattern in combination * with visit(t, ttype, visitor) so nil-rooted patterns are not allowed. * Patterns with wildcard roots are also not allowed. * </summary> */ public virtual void Visit( object t, string pattern, IContextVisitor visitor ) { // Create a TreePattern from the pattern TreePatternLexer tokenizer = new TreePatternLexer( pattern ); TreePatternParser parser = new TreePatternParser( tokenizer, this, new TreePatternTreeAdaptor() ); TreePattern tpattern = (TreePattern)parser.Pattern(); // don't allow invalid patterns if ( tpattern == null || tpattern.IsNil || tpattern.GetType() == typeof( WildcardTreePattern ) ) { return; } IDictionary<string, object> labels = new Dictionary<string, object>(); // reused for each _parse int rootTokenType = tpattern.Type; Visit( t, rootTokenType, new VisitTreeWizardContextVisitor( this, visitor, labels, tpattern ) ); }
public VisitTreeWizardContextVisitor( TreeWizard outer, IContextVisitor visitor, IDictionary<string, object> labels, TreePattern tpattern ) { _outer = outer; _visitor = visitor; _labels = labels; _tpattern = tpattern; }
/** <summary>Do the recursive work for visit</summary> */ protected virtual void _Visit( object t, object parent, int childIndex, int ttype, IContextVisitor visitor ) { if ( t == null ) { return; } if ( adaptor.GetType( t ) == ttype ) { visitor.Visit( t, parent, childIndex, null ); } int n = adaptor.GetChildCount( t ); for ( int i = 0; i < n; i++ ) { object child = adaptor.GetChild( t, i ); _Visit( child, t, i, ttype, visitor ); } }
/** <summary> * Visit every ttype node in t, invoking the visitor. This is a quicker * version of the general visit(t, pattern) method. The labels arg * of the visitor action method is never set (it's null) since using * a token type rather than a pattern doesn't let us set a label. * </summary> */ public virtual void Visit( object t, int ttype, IContextVisitor visitor ) { _Visit( t, null, 0, ttype, visitor ); }
protected virtual void VisitCore(object t, object parent, int childIndex, int ttype, IContextVisitor visitor) { if (t != null) { if (this.adaptor.GetType(t) == ttype) { visitor.Visit(t, parent, childIndex, null); } int childCount = this.adaptor.GetChildCount(t); for (int i = 0; i < childCount; i++) { object child = this.adaptor.GetChild(t, i); this.VisitCore(child, t, i, ttype, visitor); } } }
public void Visit(object t, string pattern, IContextVisitor visitor) { TreePatternLexer tokenizer = new TreePatternLexer(pattern); TreePatternParser parser = new TreePatternParser(tokenizer, this, new TreePatternTreeAdaptor()); TreePattern tpattern = (TreePattern) parser.Pattern(); if (((tpattern != null) && !tpattern.IsNil) && (tpattern.GetType() != typeof(WildcardTreePattern))) { IDictionary<string, object> labels = new Dictionary<string, object>(); int type = tpattern.Type; this.Visit(t, type, new VisitTreeWizardContextVisitor(this, visitor, labels, tpattern)); } }
public void Visit(object t, int ttype, IContextVisitor visitor) { this.VisitCore(t, null, 0, ttype, visitor); }
/** <summary>Do the recursive work for visit</summary> */ protected virtual void VisitCore(object t, object parent, int childIndex, int ttype, IContextVisitor visitor) { if (t == null) { return; } if (adaptor.GetType(t) == ttype) { visitor.Visit(t, parent, childIndex, null); } int n = adaptor.GetChildCount(t); for (int i = 0; i < n; i++) { object child = adaptor.GetChild(t, i); VisitCore(child, t, i, ttype, visitor); } }
/** <summary> * Visit every ttype node in t, invoking the visitor. This is a quicker * version of the general visit(t, pattern) method. The labels arg * of the visitor action method is never set (it's null) since using * a token type rather than a pattern doesn't let us set a label. * </summary> */ public void Visit(object t, int ttype, IContextVisitor visitor) { VisitCore(t, null, 0, ttype, visitor); }
/** <summary> * Visit every ttype node in t, invoking the visitor. This is a quicker * version of the general visit(t, pattern) method. The labels arg * of the visitor action method is never set (it's null) since using * a token type rather than a pattern doesn't let us set a label. * </summary> */ public virtual void Visit(object t, int ttype, IContextVisitor visitor) { _Visit(t, null, 0, ttype, visitor); }