/// <summary>
        /// Initializes a new instance of the <see cref="CSF.Zpt.Rendering.RenderingContext"/> class.
        /// </summary>
        /// <param name="metalContext">The METAL context.</param>
        /// <param name="talContext">The TAL context.</param>
        /// <param name="element">The ZPT element for which this context is created.</param>
        /// <param name="options">The rendering options.</param>
        /// <param name="sourceAnnotationRoot">The source annotation root path.</param>
        public RenderingContext(IModel metalContext,
                            IModel talContext,
                            IZptElement element,
                            IRenderingSettings options,
                            string sourceAnnotationRoot = null)
        {
            if(metalContext == null)
              {
            throw new ArgumentNullException(nameof(metalContext));
              }
              if(talContext == null)
              {
            throw new ArgumentNullException(nameof(talContext));
              }
              if(element == null)
              {
            throw new ArgumentNullException(nameof(element));
              }
              if(options == null)
              {
            throw new ArgumentNullException(nameof(options));
              }

              _metalContext = metalContext;
              _talContext = talContext;
              _element = element;
              _renderingOptions = options;
              _sourceAnnotationRoot = sourceAnnotationRoot;

              _originalAttributes = _element.GetAttributes();
        }
Exemple #2
0
        /// <summary>
        /// Renders the current document, returning an <see cref="IZptElement"/> representing the rendered result.
        /// </summary>
        /// <returns>The result of the rendering process.</returns>
        /// <param name="model">An object to which the ZPT document is to be applied.</param>
        /// <param name="element">The original element to be rendered.</param>
        /// <param name="options">The rendering options to use.  If <c>null</c> then default options are used.</param>
        /// <param name="contextConfigurator">An optional action to perform upon the root <see cref="IModelValueContainer"/>, to configure it.</param>
        public IZptElement RenderElement(object model,
                                     IZptElement element,
                                     IRenderingSettings options,
                                     Action<IModelValueContainer> contextConfigurator)
        {
            if(options == null)
              {
            throw new ArgumentNullException(nameof(options));
              }
              if(element == null)
              {
            throw new ArgumentNullException(nameof(element));
              }

              var output = element;
              var context = options.CreateRootContext(output, model);

              ZptConstants.TraceSource.TraceInformation(Resources.LogMessageFormats.RenderingDocument,
                                                (output.SourceFile != null)? output.SourceFile.FullName : "<unknown>",
                                                nameof(ZptDocument),
                                                nameof(RenderElement));

              if(contextConfigurator != null)
              {
            contextConfigurator(context);
              }

              try
              {
            foreach(var visitor in options.ContextVisitors)
            {
              var contexts = visitor.VisitContext(context);

              if(contexts.Count() != 1)
              {
            string message = String.Format(Resources.ExceptionMessages.WrongCountOfReturnedContexts,
                                           typeof(IContextVisitor).Name,
                                           typeof(RenderingContext).Name);
            throw new RenderingException(message);
              }

              context = contexts.Single();
            }
              }
              catch(Exception ex)
              {
            ZptConstants.TraceSource.TraceEvent(System.Diagnostics.TraceEventType.Error,
                                            3,
                                            Resources.LogMessageFormats.UnexpectedRenderingException,
                                            nameof(ZptDocument),
                                            nameof(RenderElement),
                                            ex.ToString());
            throw;
              }

              return context.Element;
        }
 /// <summary>
 /// Renders a single ZPT document and returns a response.
 /// </summary>
 /// <param name="doc">The document to render.</param>
 /// <param name="outputStream">The output stream.</param>
 /// <param name="options">Rendering options.</param>
 /// <param name="contextConfigurator">Context configurator.</param>
 /// <param name="outputInfo">Output info.</param>
 protected override IBatchRenderingDocumentResponse Render(IZptDocument doc,
                                                       Stream outputStream,
                                                       IRenderingSettings options,
                                                       Action<IModelValueContainer> contextConfigurator,
                                                       string outputInfo)
 {
     try
       {
     return base.Render(doc, outputStream, options, contextConfigurator, outputInfo);
       }
       catch(ZptException ex)
       {
     return new BatchRenderingDocumentResponse(doc.GetSourceInfo(), ex);
       }
 }
Exemple #4
0
        /// <summary>
        /// Parse and render the documents found using the given batch rendering options.
        /// </summary>
        /// <param name="settings">Rendering settings.</param>
        /// <param name="batchOptions">Batch rendering options, indicating the source and destination files.</param>
        public virtual IBatchRenderingResponse Render(IBatchRenderingOptions batchOptions,
                                                  IRenderingSettings settings)
        {
            ValidateBatchOptions(batchOptions);

              var jobs = GetRenderingJobs(batchOptions, batchOptions.RenderingMode);

              List<IBatchRenderingDocumentResponse> documents = new List<IBatchRenderingDocumentResponse>();

              foreach(var job in jobs)
              {
            var contextConfigurator = GetContextConfigurator(job);

            var docResponse = Render(job, settings, batchOptions, contextConfigurator);
            documents.Add(docResponse);
              }

              return new BatchRenderingResponse(documents);
        }
Exemple #5
0
        /// <summary>
        /// Renders a single rendering job and returns a response.
        /// </summary>
        /// <param name="job">The job to render.</param>
        /// <param name="options">Rendering options.</param>
        /// <param name="batchOptions">Batch rendering options.</param>
        /// <param name="contextConfigurator">Context configurator.</param>
        protected virtual IBatchRenderingDocumentResponse Render(IRenderingJob job,
                                                             IRenderingSettings options,
                                                             IBatchRenderingOptions batchOptions,
                                                             Action<IModelValueContainer> contextConfigurator)
        {
            var doc = GetDocument(job);
              var outputInfo = GetOutputInfo(job, batchOptions);

              using(var outputStream = GetOutputStream(job, batchOptions))
              {
            return Render(doc, outputStream, options, contextConfigurator, outputInfo);
              }
        }
 protected override string Render(IZptDocument document, IRenderingSettings options)
 {
     return document.Render(_model, options);
 }
Exemple #7
0
        public void Setup()
        {
            _defaultSettings = RenderingSettings.Default;

              _rootElement = Mock.Of<IZptElement>();
              _renderedElement = Mock.Of<IZptElement>();
              _elementRenderer = new Mock<IElementRenderer>();

              _sut = new Mock<ZptDocument>(_elementRenderer.Object) { CallBase = true };

              _sut.Protected().Setup<IRenderingSettings>("GetDefaultOptions").Returns(_defaultSettings);
              _sut.Protected().Setup<IZptElement>("GetRootElement").Returns(_rootElement);
        }
 public IRenderingContext Create(IZptElement element, IRenderingSettings options, object model)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Initializes the <see cref="CSF.Zpt.Rendering.RenderingSettings"/> class.
 /// </summary>
 static RenderingSettings()
 {
     DEFAULT = RenderingSettingsFactory.GetDefaultSettings();
 }
Exemple #10
0
        /// <summary>
        /// Renders the document to an <c>HtmlAgilityPack.HtmlDocument</c> instance.
        /// </summary>
        /// <returns>The rendered HTML document.</returns>
        /// <param name="model">An object for which the ZPT document is to be applied.</param>
        /// <param name="options">The rendering options to use.  If <c>null</c> then default options are used.</param>
        /// <param name="contextConfigurator">An optional action to perform upon the root <see cref="IModelValueContainer"/>, to configure it.</param>
        public HtmlDocument RenderHtml(object model,
                                   IRenderingSettings options = null,
                                   Action<IModelValueContainer> contextConfigurator = null)
        {
            var element = RenderElement(model, options, contextConfigurator);

              var output = new HtmlDocument();
              output.LoadHtml(element.ToString());

              return output;
        }
Exemple #11
0
 /// <summary>
 /// Renders the document to an <c>HtmlAgilityPack.HtmlDocument</c> instance.
 /// </summary>
 /// <returns>The rendered HTML document.</returns>
 /// <param name="options">The rendering options to use.  If <c>null</c> then default options are used.</param>
 /// <param name="contextConfigurator">An optional action to perform upon the root <see cref="IModelValueContainer"/>, to configure it.</param>
 public HtmlDocument RenderHtml(IRenderingSettings options = null,
                            Action<IModelValueContainer> contextConfigurator = null)
 {
     return RenderHtml(null, options, contextConfigurator);
 }
        /// <summary>
        /// Renders an element to the given <c>System.IO.TextWriter</c>.
        /// </summary>
        /// <param name="writer">The text writer to render to.</param>
        /// <param name="element">The element to render.</param>
        /// <param name="options">The rendering options to use.  If <c>null</c> then default options are used.</param>
        protected override void Render(TextWriter writer,
                                   IZptElement element,
                                   IRenderingSettings options)
        {
            if(writer == null)
              {
            throw new ArgumentNullException(nameof(writer));
              }
              if(element == null)
              {
            throw new ArgumentNullException(nameof(element));
              }

              var xmlElement = ConvertElement<ZptXmlLinqElement>(element);

              var settings = new XmlWriterSettings();
              settings.Indent = true;
              settings.Encoding = options.OutputEncoding;
              settings.OmitXmlDeclaration = options.OmitXmlDeclaration;

              using(var xmlWriter = XmlTextWriter.Create(writer, settings))
              {
            xmlElement.Node.Document.Save(xmlWriter);
              }
        }
        /// <summary>
        /// Renders the document to an <c>System.Xml.XmlDocument</c> instance.
        /// </summary>
        /// <returns>The rendered XML document.</returns>
        /// <param name="model">An object for which the ZPT document is to be applied.</param>
        /// <param name="options">The rendering options to use.  If <c>null</c> then default options are used.</param>
        /// <param name="contextConfigurator">An optional action to perform upon the root <see cref="IModelValueContainer"/>, to configure it.</param>
        public XDocument RenderXml(object model,
                                 IRenderingSettings options = null,
                                 Action<IModelValueContainer> contextConfigurator = null)
        {
            var element = RenderElement(model, options, contextConfigurator);

              var output = XDocument.Parse(element.ToString());

              return output;
        }
        /// <summary>
        /// Create a context instance.
        /// </summary>
        public virtual IRenderingContext Create(IZptElement element, IRenderingSettings options, object model)
        {
            if(element == null)
              {
            throw new ArgumentNullException(nameof(element));
              }
              if(options == null)
              {
            throw new ArgumentNullException(nameof(options));
              }

              NamedObjectWrapper
            metalKeywordOptions = new NamedObjectWrapper(MetalKeywordOptions),
            talKeywordOptions = new NamedObjectWrapper(TalKeywordOptions);

              IModel
            metalModel = new TalesModel(this.EvaluatorRegistry, metalKeywordOptions, modelObject: model),
            talModel = new TalesModel(this.EvaluatorRegistry, talKeywordOptions, modelObject: model);

              PopulateMetalModel(metalModel);
              PopulateTalModel(talModel);

              return new RenderingContext(metalModel, talModel, element, options, this.RootDocumentPath);
        }
 /// <summary>
 /// Create a context instance.
 /// </summary>
 public virtual IRenderingContext Create(IZptElement element, IRenderingSettings options)
 {
     return Create(element, options, null);
 }
Exemple #16
0
        /// <summary>
        /// Renders a single ZPT document and returns a response.
        /// </summary>
        /// <param name="doc">The document to render.</param>
        /// <param name="outputStream">The output stream.</param>
        /// <param name="options">Rendering options.</param>
        /// <param name="contextConfigurator">Context configurator.</param>
        /// <param name="outputInfo">Output info.</param>
        protected virtual IBatchRenderingDocumentResponse Render(IZptDocument doc,
                                                             Stream outputStream,
                                                             IRenderingSettings options,
                                                             Action<IModelValueContainer> contextConfigurator,
                                                             string outputInfo)
        {
            using(var writer = new StreamWriter(outputStream, options.OutputEncoding))
              {
            doc.Render(writer,
                   options: options,
                   contextConfigurator: contextConfigurator);
              }

              return new BatchRenderingDocumentResponse(doc.GetSourceInfo(), outputInfo);
        }
Exemple #17
0
        /// <summary>
        /// Renders an element to the given <c>System.IO.TextWriter</c>.
        /// </summary>
        /// <param name="writer">The text writer to render to.</param>
        /// <param name="element">The element to render.</param>
        /// <param name="options">The rendering options to use.  If <c>null</c> then default options are used.</param>
        protected override void Render(TextWriter writer,
                                   IZptElement element,
                                   IRenderingSettings options)
        {
            if(writer == null)
              {
            throw new ArgumentNullException(nameof(writer));
              }
              if(element == null)
              {
            throw new ArgumentNullException(nameof(element));
              }

              var htmlElement = ConvertElement<ZptHtmlElement>(element);
              htmlElement.Node.WriteTo(writer);
        }
 protected virtual string Render(IZptDocument document, IRenderingSettings options)
 {
     return document.Render(options);
 }