RSS design implemented; XML output optimised; encoding bugs fixed

main
Inga 🏳‍🌈 14 years ago
parent b638da72a0
commit 88a8debd30
  1. 1
      IISMainHandler/IISMainHandler.csproj
  2. 7
      IISMainHandler/TemplateEngine.cs
  3. 12
      IISMainHandler/WebContext.cs
  4. 7
      IISMainHandler/designs/Classic.cs
  5. 4
      IISMainHandler/designs/IDesign.cs
  6. 7
      IISMainHandler/designs/Lite.cs
  7. 7
      IISMainHandler/designs/Raw.cs
  8. 24
      IISMainHandler/designs/Rss.cs
  9. 4
      IISMainHandler/handlers/AbstractGetHandler.cs
  10. 4
      IISMainHandler/handlers/request/AbstractPostHandler.cs

@ -144,6 +144,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="designs\Rss.cs" />
<Compile Include="handlers\request\avatars\AddHandler.cs" />
<Compile Include="handlers\request\avatars\RemoveHandler.cs" />
<Compile Include="handlers\request\avatars\SetAsDefaultHandler.cs" />

@ -5,6 +5,7 @@ using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Xsl;
using System.IO;
namespace FLocal.IISHandler {
class TemplateEngine {
@ -32,14 +33,12 @@ namespace FLocal.IISHandler {
}
public static string Compile(string templateName, XDocument data) {
StringBuilder builder = new StringBuilder();
using(XmlWriter writer = XmlWriter.Create(builder, new XmlWriterSettings { Indent = false })) {
public static void WriteCompiled(string templateName, XDocument data, Encoding encoding, TextWriter outStream) {
using(XmlWriter writer = XmlWriter.Create(outStream, new XmlWriterSettings { Indent = false, Encoding = encoding })) {
using(XmlReader reader = data.CreateReader()) {
TemplateCacher.instance.getCompiledTransform(templateName).Transform(reader, writer);
}
}
return builder.ToString();
}
}

@ -13,6 +13,8 @@ using System.IO;
namespace FLocal.IISHandler {
class WebContext : Common.UserContext {
private static readonly Encoding OutputEncoding = Encoding.GetEncoding(1251);
public readonly HttpContext httpcontext;
public HttpRequest httprequest {
@ -115,6 +117,9 @@ namespace FLocal.IISHandler {
case 447:
this.design = new designs.Lite();
break;
case 449:
this.design = new designs.Rss();
break;
case 443:
default:
this.design = new designs.Classic();
@ -122,9 +127,10 @@ namespace FLocal.IISHandler {
}
}
public string Transform(string templateName, System.Xml.Linq.XDocument data) {
//TODO: this should work according to design!
return TemplateEngine.Compile(this.design.GetFSName(templateName), data);
public void WriteTransformResult(string templateName, System.Xml.Linq.XDocument data) {
this.httpresponse.ContentType = this.design.ContentType;
this.httpresponse.ContentEncoding = OutputEncoding;
TemplateEngine.WriteCompiled(this.design.GetFSName(templateName), data, OutputEncoding, this.httpresponse.Output);
}
public XElement exportSession() {

@ -16,5 +16,12 @@ namespace FLocal.IISHandler.designs {
Replace("</f:src><f:alt>", "\" alt=\"").
Replace("</f:alt></f:img>", "\"/>");
}
public string ContentType {
get {
return "text/html";
}
}
}
}

@ -8,5 +8,9 @@ namespace FLocal.IISHandler.designs {
string GetFSName(string template);
string ContentType {
get;
}
}
}

@ -16,5 +16,12 @@ namespace FLocal.IISHandler.designs {
Replace("</f:src><f:alt>", "\">").
Replace("</f:alt></f:img>", "</a>");
}
public string ContentType {
get {
return "text/html";
}
}
}
}

@ -13,5 +13,12 @@ namespace FLocal.IISHandler.designs {
string FLocal.Common.IOutputParams.preprocessBodyIntermediate(string bodyIntermediate) {
return bodyIntermediate;
}
public string ContentType {
get {
return "application/xml";
}
}
}
}

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLocal.IISHandler.designs {
class Rss : IDesign {
public string GetFSName(string template) {
return System.IO.Path.Combine("Rss", template);
}
string FLocal.Common.IOutputParams.preprocessBodyIntermediate(string bodyIntermediate) {
return bodyIntermediate;
}
public string ContentType {
get {
return "application/rss+xml";
}
}
}
}

@ -41,14 +41,14 @@ namespace FLocal.IISHandler.handlers {
public void Handle(WebContext context) {
try {
context.httpresponse.Write(context.Transform(this.templateName, this.getData(context)));
context.WriteTransformResult(this.templateName, this.getData(context));
} catch(RedirectException) {
throw;
} catch(WrongUrlException) {
throw;
} catch(Exception e) {
context.LogError(e);
context.httpresponse.Write(context.Transform("Exception.xslt", new XDocument(new XElement("root", this.getCommonData(context), e.ToXml()))));
context.WriteTransformResult("Exception.xslt", new XDocument(new XElement("root", this.getCommonData(context), e.ToXml())));
}
}

@ -56,14 +56,14 @@ namespace FLocal.IISHandler.handlers.request {
if(this.shouldBeGuest && context.session != null) throw new FLocalException("Should be guest");
if(this.shouldBeLoggedIn && context.session == null) throw new FLocalException("Should be anonymous");
context.httpresponse.Write(context.Transform(this.templateName, this.getData(context)));
context.WriteTransformResult(this.templateName, this.getData(context));
} catch(RedirectException) {
throw;
} catch(WrongUrlException) {
throw;
} catch(Exception e) {
context.LogError(e);
context.httpresponse.Write(context.Transform("Exception.xslt", new XDocument(new XElement("root", this.getCommonData(context), e.ToXml()))));
context.WriteTransformResult("Exception.xslt", new XDocument(new XElement("root", this.getCommonData(context), e.ToXml())));
}
}

Loading…
Cancel
Save