Example #1
0
 public void CommonInit(IRuntimeServices rs, ExtendedProperties configuration)
 {
     this.rsvc        = rs;
     this.isCachingOn = configuration.GetBoolean("cache", false);
     this.modificationCheckInterval = configuration.GetLong("modificationCheckInterval", 0L);
     this.className = configuration.GetString("class");
 }
Example #2
0
        /// <summary> This initialization is used by all resource
        /// loaders and must be called to set up common
        /// properties shared by all resource loaders
        /// </summary>
        /// <param name="rs">
        /// </param>
        /// <param name="configuration">
        /// </param>
        public virtual void CommonInit(IRuntimeServices rs, ExtendedProperties configuration)
        {
            this.rsvc = rs;
            this.log  = rsvc.Log;

            /*
             *  these two properties are not required for all loaders.
             *  For example, for ClasspathLoader, what would cache mean?
             *  so adding default values which I think are the safest
             *
             *  don't cache, and modCheckInterval irrelevant...
             */

            try
            {
                isCachingOn = configuration.GetBoolean("cache", false);
            }
            catch (System.Exception e)
            {
                isCachingOn = false;
                string msg = "Exception parsing cache setting: " + configuration.GetString("cache");
                log.Error(msg, e);
                throw new VelocityException(msg, e);
            }
            try
            {
                modificationCheckInterval = configuration.GetLong("modificationCheckInterval", 0);
            }
            catch (System.Exception e)
            {
                modificationCheckInterval = 0;
                string msg = "Exception parsing modificationCheckInterval setting: " + configuration.GetString("modificationCheckInterval");
                log.Error(msg, e);
                throw new VelocityException(msg, e);
            }

            /*
             * this is a must!
             */
            className = typeof(ResourceCacheImpl).FullName;
            try
            {
                className = configuration.GetString("class", className);
            }
            catch (System.Exception e)
            {
                string msg = "Exception retrieving resource cache class name";
                log.Error(msg, e);
                throw new VelocityException(msg, e);
            }
        }
        /// <summary>
        /// This initialization is used by all resource
        /// loaders and must be called to set up common
        /// properties shared by all resource loaders
        /// </summary>
        public void CommonInit(IRuntimeServices rs, ExtendedProperties configuration)
        {
            runtimeServices = rs;

            // these two properties are not required for all loaders.
            // For example, for ClassPathLoader, what would cache mean?
            // so adding default values which I think are the safest

            // don't cache, and modCheckInterval irrelevant...

            isCachingOn = configuration.GetBoolean("cache", false);
            modificationCheckInterval = configuration.GetLong("modificationCheckInterval", 0);

            // this is a must!
            className = configuration.GetString("class");
        }
Example #4
0
        /// <summary> This initialization is used by all resource
        /// loaders and must be called to set up common
        /// properties shared by all resource loaders
        /// </summary>
        public virtual void  commonInit(RuntimeServices rs, ExtendedProperties configuration)
        {
            this.rsvc = rs;

            /*
             *  these two properties are not required for all loaders.
             *  For example, for ClasspathLoader, what would cache mean?
             *  so adding default values which I think are the safest
             *
             *  don't cache, and modCheckInterval irrelevant...
             */

            isCachingOn_Renamed_Field = configuration.GetBoolean("cache", false);
            modificationCheckInterval = configuration.GetLong("modificationCheckInterval", 0);

            /*
             * this is a must!
             */

            className = configuration.GetString("class");
        }
        /// <seealso cref="org.apache.velocity.runtime.resource.loader.ResourceLoader.Init(org.apache.commons.collections.ExtendedProperties)">
        /// </seealso>
        public override void Init(ExtendedProperties configuration)
        {
            if (log.TraceEnabled)
            {
                log.Trace("FileResourceLoader : initialization starting.");
            }

            ArrayList vectors = configuration.GetVector("path");

            foreach (var o in vectors)
            {
                paths.Add(o.ToString());
            }

            // unicode files may have a BOM marker at the start, but Java
            // has problems recognizing the UTF-8 bom. Enabling unicode will
            // recognize all unicode boms.
            unicode = configuration.GetBoolean("unicode", false);

            if (log.DebugEnabled)
            {
                log.Debug("Do unicode file recognition:  " + unicode);
            }

            if (log.DebugEnabled)
            {
                // trim spaces from all paths
                StringUtils.TrimStrings(paths);

                // this section lets tell people what paths we will be using
                int sz = paths.Count;
                for (int i = 0; i < sz; i++)
                {
                    log.Debug("FileResourceLoader : adding path '" + ((string)paths[i]) + "'");
                }
                log.Trace("FileResourceLoader : initialization complete.");
            }
        }
Example #6
0
 /// <summary>
 /// Boolean property accessor method to hide the configuration implementation.
 /// </summary>
 /// <param name="key">property key</param>
 /// <param name="def">default value if property not found</param>
 /// <returns>boolean  value of key or default value</returns>
 public bool GetBoolean(String key, bool def)
 {
     return(configuration.GetBoolean(key, def));
 }
        /// <seealso cref="org.apache.velocity.runtime.resource.loader.ResourceLoader.Init(org.apache.commons.collections.ExtendedProperties)">
        /// </seealso>
        public override void Init(ExtendedProperties configuration)
        {
            log.Trace("StringResourceLoader : initialization starting.");

            // Get the repository configuration Info
            string repoClass = configuration.GetString(REPOSITORY_CLASS, REPOSITORY_CLASS_DEFAULT);
            string repoName  = configuration.GetString(REPOSITORY_NAME, REPOSITORY_NAME_DEFAULT);
            bool   isStatic  = configuration.GetBoolean(REPOSITORY_STATIC, REPOSITORY_STATIC_DEFAULT);
            string encoding  = configuration.GetString(REPOSITORY_ENCODING);

            // look for an existing repository of that name and isStatic setting
            if (isStatic)
            {
                this.repository = GetRepository(repoName);
                if (repository != null && log.DebugEnabled)
                {
                    log.Debug("Loaded repository '" + repoName + "' from static repo store");
                }
            }
            else
            {
                this.repository = (IStringResourceRepository)rsvc.GetApplicationAttribute(repoName);
                if (repository != null && log.DebugEnabled)
                {
                    log.Debug("Loaded repository '" + repoName + "' from application attributes");
                }
            }

            if (this.repository == null)
            {
                // since there's no repository under the repo name, create a new one
                this.repository = CceateRepository(repoClass, encoding);

                // and store it according to the isStatic setting
                if (isStatic)
                {
                    SetRepository(repoName, this.repository);
                }
                else
                {
                    rsvc.SetApplicationAttribute(repoName, this.repository);
                }
            }
            else
            {
                // ok, we already have a repo
                // Warn them if they are trying to change the class of the repository
                if (!this.repository.GetType().FullName.Equals(repoClass))
                {
                    log.Debug("Cannot change class of string repository '" + repoName + "' from " + this.repository.GetType().FullName + " to " + repoClass + ". The change will be ignored.");
                }

                // allow them to change the default encoding of the repo
                if (encoding != null && !this.repository.Encoding.Equals(encoding))
                {
                    if (log.DebugEnabled)
                    {
                        log.Debug("Changing the default encoding of string repository '" + repoName + "' from " + this.repository.Encoding + " to " + encoding);
                    }
                    this.repository.Encoding = encoding;
                }
            }

            log.Trace("StringResourceLoader : initialization complete.");
        }
Example #8
0
 /// <summary> Boolean property accessor method to hide the configuration implementation.
 ///
 /// </summary>
 /// <param name="String">key  property key
 /// </param>
 /// <param name="boolean">default default value if property not found
 /// </param>
 /// <returns>boolean  value of key or default value
 ///
 /// </returns>
 public virtual bool getBoolean(System.String key, bool def)
 {
     return(configuration.GetBoolean(key, def));
 }
Example #9
0
        public virtual void  Test_run()
        {
            System.IO.StreamWriter result = null;
            ExtendedProperties     c      = null;

            try {
                assureResultsDirectoryExists(RESULTS_DIR);
                c      = new ExtendedProperties(TEST_CONFIG);
                result = new System.IO.StreamWriter(getFileName(RESULTS_DIR, "output", "res"));
            } catch (System.Exception e) {
                throw new System.Exception("Cannot setup CommonsExtPropTestCase!", e);
            }

            message(result, "Testing order of keys ...");
            showIterator(result, c.Keys);

            message(result, "Testing retrieval of CSV values ...");
            showVector(result, c.GetVector("resource.loader"));

            message(result, "Testing subset(prefix).getKeys() ...");
            ExtendedProperties subset = c.Subset("file.resource.loader");

            showIterator(result, subset.Keys);

            message(result, "Testing getVector(prefix) ...");
            showVector(result, subset.GetVector("path"));

            message(result, "Testing getString(key) ...");
            result.Write(c.GetString("config.string.value"));
            result.Write("\n\n");

            message(result, "Testing getBoolean(key) ...");
            //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Boolean.toString' may return a different value. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1043"'
            result.Write(c.GetBoolean("config.boolean.value").ToString());
            result.Write("\n\n");

            message(result, "Testing getByte(key) ...");
            result.Write(c.GetByte("config.byte.value").ToString());
            result.Write("\n\n");

            message(result, "Testing getShort(key) ...");
            result.Write(c.GetShort("config.short.value").ToString());
            result.Write("\n\n");

            message(result, "Testing getInt(key) ...");
            result.Write(c.GetInt("config.int.value").ToString());
            result.Write("\n\n");

            message(result, "Testing getLong(key) ...");
            result.Write(c.GetLong("config.long.value").ToString());
            result.Write("\n\n");

            message(result, "Testing getFloat(key) ...");
            result.Write(c.GetFloat("config.float.value").ToString());
            result.Write("\n\n");

            message(result, "Testing getDouble(key) ...");
            result.Write(c.GetDouble("config.double.value").ToString());
            result.Write("\n\n");

            message(result, "Testing escaped-comma scalar...");
            result.Write(c.GetString("escape.comma1"));
            result.Write("\n\n");

            message(result, "Testing escaped-comma vector...");
            showVector(result, c.GetVector("escape.comma2"));
            result.Write("\n\n");

            result.Flush();
            result.Close();

            if (!isMatch(RESULTS_DIR, COMPARE_DIR, "output", "res", "cmp"))
            {
                Assertion.Fail("Output incorrect.");
            }
        }