What would you think of this code? (please note that this is my first time I get into FlexWiki sources, and my .net experience is very little as far as asp.net is involved...)


*** TopicResolver.aspx ***

<%@ Page language="c#" Codebehind="TopicResolver.aspx.cs" AutoEventWireup="false" Inherits="FlexWiki.Web.Default2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    <HEAD>
        <title id="title">TopicResolver</title>
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" content="_javascript_">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
        <%= InsertStylesheetReferences() %>
    </HEAD>
    <body class='Dialog'>
        <% Resolve(); %>
    </body>
</HTML>


*** TopicResolver.aspx.cs ***

public class TopicResolver : BasePage
{
    ContentBase _cb;

    protected void Resolve()
    {
        string input = Request.QueryString["input"];
        string nameSpace = Request.QueryString["nameSpace"];
        if (nameSpace == null)
            nameSpace = DefaultNamespace;

        _cb = TheFederation.ContentBaseForNamespace(nameSpace);

        XmlDocument doc = new XmlDocument();
        doc.LoadXml(input);
        ManageNodeRecursively(doc.DocumentElement);

        string output = doc.InnerXml;
        Response.Write(output);
    }

    void ManageNodeRecursively(XmlNode node)
    {
        // Manages the value of this node, if any.
        string txt = node.Value;
        string[] allTokens = txt.Split(new string[] { " ", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

        bool anyChangeMade = false;
        StringBuilder sb = new StringBuilder();

        foreach (string token in allTokens)
        {
            if (!_cb.TopicExistsLocally(token))
                sb.Append(token);
            else
            {
                sb.Append(TheLinkMaker.LinkToTopic(token));
                anyChangeMade = true;
            }
            sb.Append(' ');
        }

        if (anyChangeMade)
            node.Value = sb.ToString(0, sb.Length - 1);



        // Then manages its subnodes, if any.
        foreach (XmlNode subNode in node.ChildNodes)
            ManageNodeRecursively(subNode);
    }

}
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Flexwiki-users mailing list
Flexwiki-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flexwiki-users

Reply via email to