PageRenderTime 25ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/Ximura Communication/Commands/ContentCompiler/States/OutputTransformCCState.cs

https://github.com/mbmccormick/Ximura
C# | 96 lines | 65 code | 9 blank | 22 comment | 3 complexity | 3c4255f411769db002e3ba0095dc619c MD5 | raw file
  1. #region Copyright
  2. // *******************************************************************************
  3. // Copyright (c) 2000-2009 Paul Stancer.
  4. // All rights reserved. This program and the accompanying materials
  5. // are made available under the terms of the Eclipse Public License v1.0
  6. // which accompanies this distribution, and is available at
  7. // http://www.eclipse.org/legal/epl-v10.html
  8. //
  9. // Contributors:
  10. // Paul Stancer - initial implementation
  11. // *******************************************************************************
  12. #endregion
  13. #region using
  14. using System;
  15. using System.Runtime.Serialization;
  16. using System.IO;
  17. using System.ComponentModel;
  18. using Ximura;
  19. using CH = Ximura.Common;
  20. using Ximura.Framework;
  21. using Ximura.Framework;
  22. using Ximura.Communication;
  23. #endregion // using
  24. namespace Ximura.Communication
  25. {
  26. public class OutputTransformCCState : OutputBaseCCState
  27. {
  28. #region Constructors
  29. /// <summary>
  30. /// This is the default constructor.
  31. /// </summary>
  32. public OutputTransformCCState() : this(null) { }
  33. /// <summary>
  34. /// This is the component model constructor.
  35. /// </summary>
  36. /// <param name="container">The container</param>
  37. public OutputTransformCCState(IContainer container)
  38. : base(container)
  39. {
  40. }
  41. #endregion // Constructors
  42. #region OutputPrepare(ContentCompilerContext context)
  43. /// <summary>
  44. /// This method selects the appropriate node and creates a Body content.
  45. /// </summary>
  46. /// <param name="context">The current context.</param>
  47. public override void OutputPrepare(ContentCompilerContext context)
  48. {
  49. string stylesheetRef = null;
  50. try
  51. {
  52. if (context.Request.Data.OutputRawXML)
  53. {
  54. string data = context.ModelData.Payload.InnerXml; ;
  55. context.Response.Body = PrepareBody(context, data);
  56. context.Response.Body.ContentType = "application/xml; charset=utf-8";
  57. context.Response.Status = CH.HTTPCodes.OK_200;
  58. return;
  59. }
  60. //string stylesheetRef = context.Request.Data.ResponseStylesheet;
  61. stylesheetRef = context.Request.Settings.OutputColl[0].Output;
  62. Stylesheet stylesheet = context.StylesheetGet("name", stylesheetRef);
  63. if (stylesheet == null)
  64. throw new InvalidStylesheetCCException(string.Format("Stylesheet cannot be found: {0}", stylesheetRef));
  65. byte[] blob = stylesheet.Transform(context.ModelData);
  66. context.Response.Body = PrepareBody(context, blob);
  67. context.Response.Body.ContentType = context.Request.Settings.OutputColl[0].OutputMIMEType;
  68. context.Request.Data.ResponseHeaderAdd("ETag", PreparePageETag(context.ModelData));
  69. context.Request.Data.ResponseHeaderAdd("Cache-control", "must-revalidate");
  70. context.Response.Status = CH.HTTPCodes.OK_200;
  71. }
  72. catch (Exception ex)
  73. {
  74. context.Response.Body = null;
  75. context.Response.Status = CH.HTTPCodes.InternalServerError_500;
  76. context.Response.Substatus = ex.Message;
  77. }
  78. }
  79. #endregion // OutputPrepare(ContentCompilerContext context)
  80. private string PreparePageETag(Model data)
  81. {
  82. Guid ID = data.IDContent;
  83. Guid Version = data.IDVersion;
  84. return @"""" + Version.ToString("N").ToUpper() + @"""";
  85. }
  86. }
  87. }