Пример #1
0
        /// <summary>
        /// nxslt main entry point.
        /// </summary>
        /// <param name="args">Command line args</param>
        public static int Main(string[] args)
        {
            NXsltMain nxsltMain = new NXsltMain();

            nxsltMain.setReporter(new Reporter());
            try
            {
                NXsltArgumentsParser clParser = new NXsltArgumentsParser();
                nxsltMain.options = clParser.ParseArguments(args);
                //Ok, then let's process it
                return(nxsltMain.Process());
            }
            catch (NXsltCommandLineParsingException clpe)
            {
                //There was an exception while parsing command line
                nxsltMain.reporter.ReportCommandLineParsingError(Reporter.GetFullMessage(clpe));
                return(RETURN_CODE_ERROR);
            }
            catch (NXsltException ne)
            {
                nxsltMain.reporter.ReportError(Reporter.GetFullMessage(ne));
                return(RETURN_CODE_ERROR);
            }
            catch (Exception e)
            {
                //Some other exception
                nxsltMain.reporter.ReportError(NXsltStrings.Error, Reporter.GetFullMessage(e));
                return(RETURN_CODE_ERROR);
            }
        }// Main() method
Пример #2
0
 /// <summary>
 /// nxslt main entry point.
 /// </summary>
 /// <param name="args">Command line args</param>
 public static int Main(string[] args)
 {
     NXsltMain nxsltMain = new NXsltMain();
     nxsltMain.setReporter(new Reporter());
     try
     {                                
         NXsltArgumentsParser clParser = new NXsltArgumentsParser();
         nxsltMain.options = clParser.ParseArguments(args);                
         //Ok, then let's process it
         return nxsltMain.Process();
     }
     catch (NXsltCommandLineParsingException clpe)
     {
         //There was an exception while parsing command line
         nxsltMain.reporter.ReportCommandLineParsingError(Reporter.GetFullMessage(clpe));
         return RETURN_CODE_ERROR;
     }
     catch (NXsltException ne)
     {
         nxsltMain.reporter.ReportError(Reporter.GetFullMessage(ne));
         return RETURN_CODE_ERROR;
     }
     catch (Exception e)
     {
         //Some other exception
         nxsltMain.reporter.ReportError(NXsltStrings.Error, Reporter.GetFullMessage(e));
         return RETURN_CODE_ERROR;
     }
 }// Main() method
Пример #3
0
        public override bool  Execute()
        {            
            TaskReporter reporter = new TaskReporter(this);
            int rc = NXsltMain.RETURN_CODE_OK;
            try
            {
                try
                {
                    NXsltMain nxslt = new NXsltMain();
                    nxslt.setReporter(reporter);

                    if (xsltParameters != null)
                    {                        
                        if (nxsltOptions.XslArgList == null)
                        {
                            nxsltOptions.XslArgList = new XsltArgumentList();
                        }
                        ParseParameters();                                                
                    }

                    if (xsltExtensions != null)
                    {
                        if (nxsltOptions.XslArgList == null)
                        {
                            nxsltOptions.XslArgList = new XsltArgumentList();
                        }

                        ParseExtensions();                                                
                    }

                    nxslt.options = nxsltOptions;
                    if (style != null)
                    {
                        nxslt.options.Stylesheet = style;
                    }                                                           
                                        
                    if (inFiles == null || inFiles.Length == 0)
                    {
                        throw new NxsltTaskException("No source files indicated; use 'in' or <infiles>.");
                    }

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

                    foreach (ITaskItem file in inFiles)
                    {
                        Log.LogMessage(MessageImportance.Normal, "Transforming " + file.ItemSpec);
                        nxslt.options.Source = file.ItemSpec;
                        if (outFile != null)
                        {
                            nxslt.options.OutFile = outFile;
                        }
                        else
                        {
                            string destFile = Path.GetFileNameWithoutExtension(file.ItemSpec) + "." + extension;                            
                            nxslt.options.OutFile = Path.Combine(destDir, destFile);
                        }
                        rc = nxslt.Process();
                        if (rc != NXsltMain.RETURN_CODE_OK)
                        {
                            throw new NxsltTaskException(
                                string.Format(CultureInfo.InvariantCulture,
                                "nxslt task failed.", rc));
                        }
                    }
                }
                catch (NXsltCommandLineParsingException clpe)
                {
                    //There was an exception while parsing command line
                    reporter.ReportCommandLineParsingError(Reporter.GetFullMessage(clpe));
                    throw new NxsltTaskException(
                            "nxslt task failed to parse parameters.", clpe);
                }
                catch (NXsltException ne)
                {
                    reporter.ReportError(Reporter.GetFullMessage(ne));
                    throw new NxsltTaskException(
                            "nxslt task failed.", ne);
                }
            }
            catch (Exception e)
            {                
                reporter.ReportError(NXsltStrings.Error, Reporter.GetFullMessage(e));
                return false;
            }
            return true;
        }
Пример #4
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);
            }           
        }