Пример #1
0
        protected override void ExecuteTask()
        {            
            if (inFiles.BaseDirectory == null)
            {
                inFiles.BaseDirectory = new DirectoryInfo(Project.BaseDirectory);
            }

            TaskReporter reporter = new TaskReporter(this);
            int rc = NXsltMain.RETURN_CODE_OK;
            try
            {
                NXsltMain nxslt = new NXsltMain();
                nxslt.setReporter(reporter);
                if (xsltParameters.Count > 0)
                {
                    if (nxsltOptions.XslArgList == null)
                    {
                        nxsltOptions.XslArgList = new XsltArgumentList();
                    }
                    foreach (XsltParameter param in xsltParameters)
                    {
                        if (param.IfDefined && !param.UnlessDefined)
                        {
                            nxsltOptions.XslArgList.AddParam(param.ParameterName,
                                param.NamespaceUri, param.Value);
                        }
                    }
                }
                if (xsltExtensions.Count > 0)
                {
                    if (nxsltOptions.XslArgList == null)
                    {
                        nxsltOptions.XslArgList = new XsltArgumentList();
                    }
                    foreach (XsltExtensionObject ext in xsltExtensions)
                    {
                        if (ext.IfDefined && !ext.UnlessDefined)
                        {
                            object extInstance = ext.CreateInstance();
                            nxsltOptions.XslArgList.AddExtensionObject(
                                ext.NamespaceUri, extInstance);
                        }
                    }
                }
                nxslt.options = nxsltOptions;
                if (style != null)
                {
                    nxslt.options.Stylesheet = style.AbsoluteUri;
                }

                StringCollection srcFiles = null;
                if (inFile != null)
                {
                    srcFiles = new StringCollection();
                    srcFiles.Add(inFile.AbsoluteUri);
                }
                else if (InFiles.FileNames.Count > 0)
                {

                    if (outFile != null)
                    {
                        throw new BuildException("The 'out' attribute cannot be used when <infiles> is specified.",
                            Location);
                    }
                    srcFiles = inFiles.FileNames;
                }

                if (srcFiles == null || srcFiles.Count == 0)
                {
                    throw new BuildException("No source files indicated; use 'in' or <infiles>.",
                        Location);
                }

                if (outFile == null && destDir == null)
                {
                    throw new BuildException("'out' and 'destdir' cannot be both omitted.", Location);
                }

                foreach (string file in srcFiles)
                {
                    Log(Level.Info, "Transforming " + file);
                    nxslt.options.Source = file;
                    if (outFile != null)
                    {
                        nxslt.options.OutFile = outFile.FullName;
                    }
                    else
                    {                        
                        string destFile =  Path.GetFileNameWithoutExtension(file) + "." + extension;                        
                        nxslt.options.OutFile = Path.Combine(destDir.FullName, destFile);
                    }                     
                    rc = nxslt.Process();
                    if (rc != NXsltMain.RETURN_CODE_OK)
                    {
                        throw new BuildException(
                            string.Format(CultureInfo.InvariantCulture,
                            "nxslt task failed.", rc), Location);
                    }
                }
            }
            catch (NXsltCommandLineParsingException clpe)
            {
                //There was an exception while parsing command line
                reporter.ReportCommandLineParsingError(Reporter.GetFullMessage(clpe));
                throw new BuildException(
                        "nxslt task failed to parse parameters.", Location, clpe);
            }
            catch (NXsltException ne)
            {
                reporter.ReportError(Reporter.GetFullMessage(ne));
                throw new BuildException(
                        "nxslt task failed.", Location, ne);
            }
            catch (BuildException)
            {
                throw;
            }
            catch (Exception e)
            {
                //Some other exception
                reporter.ReportError(NXsltStrings.Error, Reporter.GetFullMessage(e));
                throw new BuildException(
                        "nxslt task failed.", Location, e);
            }           
        }       
Пример #2
0
        protected override void ExecuteTask()
        {
            if (inFiles.BaseDirectory == null)
            {
                inFiles.BaseDirectory = new DirectoryInfo(Project.BaseDirectory);
            }

            TaskReporter reporter = new TaskReporter(this);
            int          rc       = NXsltMain.RETURN_CODE_OK;

            try
            {
                NXsltMain nxslt = new NXsltMain();
                nxslt.setReporter(reporter);
                if (xsltParameters.Count > 0)
                {
                    if (nxsltOptions.XslArgList == null)
                    {
                        nxsltOptions.XslArgList = new XsltArgumentList();
                    }
                    foreach (XsltParameter param in xsltParameters)
                    {
                        if (param.IfDefined && !param.UnlessDefined)
                        {
                            nxsltOptions.XslArgList.AddParam(param.ParameterName,
                                                             param.NamespaceUri, param.Value);
                        }
                    }
                }
                if (xsltExtensions.Count > 0)
                {
                    if (nxsltOptions.XslArgList == null)
                    {
                        nxsltOptions.XslArgList = new XsltArgumentList();
                    }
                    foreach (XsltExtensionObject ext in xsltExtensions)
                    {
                        if (ext.IfDefined && !ext.UnlessDefined)
                        {
                            object extInstance = ext.CreateInstance();
                            nxsltOptions.XslArgList.AddExtensionObject(
                                ext.NamespaceUri, extInstance);
                        }
                    }
                }
                nxslt.options = nxsltOptions;
                if (style != null)
                {
                    nxslt.options.Stylesheet = style.AbsoluteUri;
                }

                StringCollection srcFiles = null;
                if (inFile != null)
                {
                    srcFiles = new StringCollection();
                    srcFiles.Add(inFile.AbsoluteUri);
                }
                else if (InFiles.FileNames.Count > 0)
                {
                    if (outFile != null)
                    {
                        throw new BuildException("The 'out' attribute cannot be used when <infiles> is specified.",
                                                 Location);
                    }
                    srcFiles = inFiles.FileNames;
                }

                if (srcFiles == null || srcFiles.Count == 0)
                {
                    throw new BuildException("No source files indicated; use 'in' or <infiles>.",
                                             Location);
                }

                if (outFile == null && destDir == null)
                {
                    throw new BuildException("'out' and 'destdir' cannot be both omitted.", Location);
                }

                foreach (string file in srcFiles)
                {
                    Log(Level.Info, "Transforming " + file);
                    nxslt.options.Source = file;
                    if (outFile != null)
                    {
                        nxslt.options.OutFile = outFile.FullName;
                    }
                    else
                    {
                        string destFile = Path.GetFileNameWithoutExtension(file) + "." + extension;
                        nxslt.options.OutFile = Path.Combine(destDir.FullName, destFile);
                    }
                    rc = nxslt.Process();
                    if (rc != NXsltMain.RETURN_CODE_OK)
                    {
                        throw new BuildException(
                                  string.Format(CultureInfo.InvariantCulture,
                                                "nxslt task failed.", rc), Location);
                    }
                }
            }
            catch (NXsltCommandLineParsingException clpe)
            {
                //There was an exception while parsing command line
                reporter.ReportCommandLineParsingError(Reporter.GetFullMessage(clpe));
                throw new BuildException(
                          "nxslt task failed to parse parameters.", Location, clpe);
            }
            catch (NXsltException ne)
            {
                reporter.ReportError(Reporter.GetFullMessage(ne));
                throw new BuildException(
                          "nxslt task failed.", Location, ne);
            }
            catch (BuildException)
            {
                throw;
            }
            catch (Exception e)
            {
                //Some other exception
                reporter.ReportError(NXsltStrings.Error, Reporter.GetFullMessage(e));
                throw new BuildException(
                          "nxslt task failed.", Location, e);
            }
        }