#region License
/**
* Ingenious MVC : An MVC framework for .NET 2.0
* Copyright (C) 2006, JDP Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: - Kent Boogaart (kentcb@internode.on.net)
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Xsl;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace Ingenious.Mvc.Build{
/// <summary>
/// Implements a task to transform user documentation files into HTML.
/// </summary>
/// <remarks>
/// This task is needed mainly because the community XSLT task doesn't support passing in an XmlReader instance into the transform.
/// Without this I cannot load XSLT documents that have embedded DTDs.
/// </remarks>
public sealed class UserDocTransformTask : Task
{
private ITaskItem _input;
private ITaskItem _xslt;
private string _output;
[Required]
public ITaskItem Input
{
get
{
return _input;
}
set
{
_input = value;
}
}
[Required]
public ITaskItem Xslt
{
get
{
return _xslt;
}
set
{
_xslt = value;
}
}
[Required]
public string Output
{
get
{
return _output;
}
set
{
_output = value;
}
}
public override bool Execute()
{
//these settings are the key - they allow DTD in the loaded documents
XmlReaderSettings settings = new XmlReaderSettings();
settings.ProhibitDtd = false;
using (XmlReader inputDocument = XmlReader.Create(_input.ItemSpec, settings))
using (XmlWriter outputWriter = XmlWriter.Create(_output))
using (XmlReader xslDocument = XmlReader.Create(_xslt.ItemSpec, settings))
{
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(xslDocument, new XsltSettings(true, true), new XmlUrlResolver());
XsltArgumentList arguments = new XsltArgumentList();
//specify a stylesheet to use
arguments.AddParam("html.stylesheet", string.Empty, "Styles.css");
//do the transform
transform.Transform(inputDocument, arguments, outputWriter);
}
return true;
}
}
}
|