Пример #1
0
        /// <summary>
        /// Initializes basic velocity properties. The main purpose of this method is to
        /// allow this logic to be overrided.
        /// </summary>
        /// <param name="props">The <see cref="ExtendedProperties"/> collection to populate.</param>
        protected virtual void InitializeVelocityProperties(ExtendedProperties props)
        {
            props.SetProperty(RuntimeConstants_Fields.RESOURCE_MANAGER_CLASS, "NVelocity.Runtime.Resource.ResourceManagerImpl\\,NVelocity");
            props.SetProperty(RuntimeConstants_Fields.FILE_RESOURCE_LOADER_PATH, ViewRootDir);

            // add support for global macros. they must be defined in "Views/macros".
            ArrayList     macros     = new ArrayList();
            DirectoryInfo macrosPath = new DirectoryInfo(Path.Combine(ViewRootDir, "macros"));

            if (macrosPath.Exists)
            {
                foreach (FileInfo file in macrosPath.GetFiles("*" + TemplateExtension))
                {
                    macros.Add("macros/" + file.Name);
                }
            }

            if (macros.Count > 0)
            {
                object m = props.GetProperty(RuntimeConstants_Fields.VM_LIBRARY);
                if (m is ICollection)
                {
                    macros.AddRange((ICollection)m);
                }
                else if (m is string)
                {
                    macros.Add(m);
                }

                props.AddProperty(RuntimeConstants_Fields.VM_LIBRARY, macros);
                props.AddProperty(RuntimeConstants_Fields.VM_LIBRARY_AUTORELOAD, true);
            }
        }
Пример #2
0
        private void VerifyProperties(ExtendedProperties props, String prefix)
        {
            Assert.IsTrue(props.Count == 5, "expected to have 5 properties, had " + props.Count);

            Assert.IsTrue(props.GetString(prefix + "key").Equals("value"),
                          "key was not correct: " + props.GetString(prefix + "key"));

            // make sure the comma escaping is working correctly
            Assert.IsTrue(props.GetString(prefix + "commas.excaped").Equals("Hi, what'up?"),
                          "commas.excaped was not correct: " + props.GetString(prefix + "commas.excaped"));

            // make sure that multiple tokens on a single line are parsed correctly
            Object o = props.GetProperty(prefix + "tokens_on_a_line");

            Assert.IsTrue((o is ArrayList), prefix + "tokens_on_a_line was expected to be an ArrayList");
            Assert.IsTrue(((ArrayList)o).Count == 2, prefix + "tokens_on_a_line was expected to be an ArrayList with 2 elements");

            // make sure that tokens specified on multiple lines get put together correctly
            o = props.GetProperty(prefix + "tokens_on_multiple_lines");
            Assert.IsTrue((o is ArrayList), prefix + "tokens_on_multiple_lines was expected to be an ArrayList");
            Assert.IsTrue(((ArrayList)o).Count == 2,
                          prefix + "tokens_on_multiple_lines was expected to be an ArrayList with 2 elements");
        }
Пример #3
0
        public void Test_ExtendedProperties()
        {
            FileInfo     file = new FileInfo("test1.properties");
            StreamWriter sw   = file.CreateText();

            sw.WriteLine("# lines starting with # are comments.  Blank lines are ignored");
            sw.WriteLine("");
            sw.WriteLine("# This is the simplest property");
            sw.WriteLine("key = value");
            sw.WriteLine("");
            sw.WriteLine("# A long property may be separated on multiple lines");
            sw.WriteLine("longvalue = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \\");
            sw.WriteLine("            aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            sw.WriteLine("");
            sw.WriteLine("# This is a property with many tokens");
            sw.WriteLine("tokens_on_a_line = first token, second token");
            sw.WriteLine("");
            sw.WriteLine("# This sequence generates exactly the same result");
            sw.WriteLine("tokens_on_multiple_lines = first token");
            sw.WriteLine("tokens_on_multiple_lines = second token");
            sw.WriteLine("");
            sw.WriteLine("# commas may be escaped in tokens");
            sw.WriteLine("commas.excaped = Hi\\, what'up?");
            sw.Flush();
            sw.Close();

            StreamReader sr = file.OpenText();
            String       s  = sr.ReadToEnd();

            sr.Close();

            // TODO: could build string, then write, then read and compare.
            ExtendedProperties props = new ExtendedProperties(file.FullName);

            Assertion.Assert("expected to have 5 properties, had " + props.Count.ToString(), props.Count == 5);

            Assertion.Assert("key was not correct: " + props.GetString("key"), props.GetString("key").Equals("value"));
            Assertion.Assert("commas.excaped was not correct: " + props.GetString("commas.excaped"), props.GetString("commas.excaped").Equals("Hi, what'up?"));

            Object o = props.GetProperty("tokens_on_a_line");

            Assertion.Assert("tokens_on_a_line was expected to be an ArrayList", (o is ArrayList));
            Assertion.Assert("tokens_on_a_line was expected to be an ArrayList with 2 elements", ((ArrayList)o).Count == 2);

            StringWriter writer = new StringWriter();

            props.Save(writer, "header");
        }
Пример #4
0
        /// <summary> </summary>
        public static ExtendedProperties setMacros(ExtendedProperties props)
        {
            ArrayList macroList = new ArrayList();

            macroList.Add("macros.vm");
            object libPropValue = props.GetProperty(RuntimeConstants.VM_LIBRARY);

            if (libPropValue is ICollection)
            {
                macroList.AddRange((ICollection)libPropValue);
            }
            else if (libPropValue is string)
            {
                macroList.Add(libPropValue);
            }
            props.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, HttpContext.Current.Server.MapPath("~/Views/macros/"));

            props.AddProperty(RuntimeConstants.VM_LIBRARY, macroList);
            props.AddProperty(RuntimeConstants.VM_LIBRARY_AUTORELOAD, true);
            return(props);
        }
Пример #5
0
        private void LoadMacros(ExtendedProperties props)
        {
            var macros = ViewSourceLoader.ListViews("macros", this.ViewFileExtension, this.JSGeneratorFileExtension);

            var macroList = new ArrayList(macros);

            if (macroList.Count > 0)
            {
                var libPropValue = props.GetProperty(RuntimeConstants.VM_LIBRARY);

                if (libPropValue is ICollection)
                {
                    macroList.AddRange((ICollection)libPropValue);
                }
                else if (libPropValue is string)
                {
                    macroList.Add(libPropValue);
                }

                props.AddProperty(RuntimeConstants.VM_LIBRARY, macroList);
            }

            props.AddProperty(RuntimeConstants.VM_LIBRARY_AUTORELOAD, true);
        }
Пример #6
0
 /// <summary>
 /// Allows an external caller to get a property.
 /// <remarks>
 /// The calling routine is required to know the type, as this routine
 /// will return an Object, as that is what properties can be.
 /// </remarks>
 /// </summary>
 /// <param name="key">property to return</param>
 public Object GetProperty(String key)
 {
     return(configuration.GetProperty(key));
 }
Пример #7
0
        private void VerifyProperties(ExtendedProperties props, String prefix)
        {
            Assert.IsTrue(props.Count == 5, "expected to have 5 properties, had " + props.Count);

            Assert.IsTrue(props.GetString(prefix + "key").Equals("value"),
                          "key was not correct: " + props.GetString(prefix + "key"));

            // make sure the comma escaping is working correctly
            Assert.IsTrue(props.GetString(prefix + "commas.excaped").Equals("Hi, what'up?"),
                          "commas.excaped was not correct: " + props.GetString(prefix + "commas.excaped"));

            // make sure that multiple tokens on a single line are parsed correctly
            Object o = props.GetProperty(prefix + "tokens_on_a_line");
            Assert.IsTrue((o is ArrayList), prefix + "tokens_on_a_line was expected to be an ArrayList");
            Assert.IsTrue(((ArrayList) o).Count == 2, prefix + "tokens_on_a_line was expected to be an ArrayList with 2 elements");

            // make sure that tokens specified on multiple lines get put together correctly
            o = props.GetProperty(prefix + "tokens_on_multiple_lines");
            Assert.IsTrue((o is ArrayList), prefix + "tokens_on_multiple_lines was expected to be an ArrayList");
            Assert.IsTrue(((ArrayList) o).Count == 2,
                          prefix + "tokens_on_multiple_lines was expected to be an ArrayList with 2 elements");
        }
Пример #8
0
 /// <summary>  Allows an external caller to get a property.  The calling
 /// routine is required to know the type, as this routine
 /// will return an Object, as that is what properties can be.
 /// *
 /// </summary>
 /// <param name="key">property to return
 ///
 /// </param>
 public virtual System.Object getProperty(System.String key)
 {
     return(configuration.GetProperty(key));
 }