Esempio n. 1
0
        /// <summary>
        /// Initializes Velocity.
        /// </summary>
        /// <param name="config">servlet configuration parameters
        /// </param>
        protected override void InitVelocity()
        {
            // Try reading Velocity configuration
            try {
                ExtendedProperties p = base.LoadConfiguration();
                Velocity.ExtendedProperties = ExtendedProperties.ConvertProperties(p);
            } catch (System.Exception e) {
                Velocity.Error("Unable to read Velocity configuration file: " + e);
                Velocity.Info("Using default Velocity configuration.");
            }

            // load resources with webapp resource loader
            WebappLoaderAppContext wlac = new WebappLoaderAppContext(this.context);

            Velocity.SetApplicationAttribute("NVelocity.Http.Resource.Loader.WebappLoader", wlac);
            Velocity.SetProperty("resource.loader", "webapp");
            Velocity.SetProperty("webapp.resource.loader.class", @"NVelocity.Http.Resource.Loader.WebappLoader\,NVelocity.Http");

            // now all is ready - init Velocity
            try {
                Velocity.Init();
            } catch (System.Exception e) {
                Velocity.Error("VELOCITY PANIC : unable to init() : " + e);
                throw new HttpException("VELOCITY PANIC : unable to init()", e);
            }
        }
Esempio n. 2
0
        protected virtual void LoadToolbox()
        {
            // setup the toolbox if there is one
            String key = System.Configuration.ConfigurationSettings.AppSettings[INIT_TOOLBOX_KEY];

            if (key != null)
            {
                Stream fs = null;

                try {
                    // little fix up
                    if (!key.StartsWith("/"))
                    {
                        key = "/" + key;
                    }

                    // get the bits
                    FileInfo file = new FileInfo(HttpContext.Current.Request.PhysicalApplicationPath + key);
                    fs = file.OpenRead();

                    if (fs != null)
                    {
                        Velocity.Info("Using toolbox configuration file '" + key + "'");

                        toolboxManager = new ServletToolboxManager(HttpContext.Current);
                        toolboxManager.load(fs);

                        Velocity.Info("Toolbox setup complete.");
                    }
                } catch (System.Exception e) {
                    Velocity.Error("Problem reading toolbox file properties file '" + key + "' : " + e);
                } finally {
                    try {
                        if (fs != null)
                        {
                            fs.Close();
                        }
                    } catch (System.Exception) {}
                }
            }
            else
            {
                Velocity.Info("No toolbox entry in configuration.");
            }
        }