Ejemplo n.º 1
0
        /// <summary> This methods initializes all the directives
        /// that are used by the Velocity Runtime. The
        /// directives to be initialized are listed in
        /// the RUNTIME_DEFAULT_DIRECTIVES properties
        /// file.
        ///
        /// @throws Exception
        /// </summary>
        private void initializeDirectives()
        {
            initializeDirectiveManager();

            /*
             * Initialize the runtime directive table.
             * This will be used for creating parsers.
             */
            // runtimeDirectives = new Hashtable();

            ExtendedProperties directiveProperties = new ExtendedProperties();

            /*
             * Grab the properties file with the list of directives
             * that we should initialize.
             */

            try
            {
                directiveProperties.Load(
                    Assembly.GetExecutingAssembly().GetManifestResourceStream(RuntimeConstants.DEFAULT_RUNTIME_DIRECTIVES));
            }
            catch (System.Exception ex)
            {
                throw new System.Exception(
                          string.Format(
                              "Error loading directive.properties! Something is very wrong if these properties aren't being located. Either your Velocity distribution is incomplete or your Velocity jar file is corrupted!\n{0}",
                              ex.Message));
            }

            /*
             * Grab all the values of the properties. These
             * are all class names for example:
             *
             * NVelocity.Runtime.Directive.Foreach
             */
            IEnumerator directiveClasses = directiveProperties.Values.GetEnumerator();

            while (directiveClasses.MoveNext())
            {
                String directiveClass = (String)directiveClasses.Current;
                // loadDirective(directiveClass);
                directiveManager.Register(directiveClass);
            }

            /*
             *  now the user's directives
             */
            String[] userdirective = configuration.GetStringArray("userdirective");
            for (int i = 0; i < userdirective.Length; i++)
            {
                // loadDirective(userdirective[i]);
                directiveManager.Register(userdirective[i]);
            }
        }
        /// <summary>
        ///   Registers a directive type.
        /// </summary>
        /// <param name = "directiveTypeName">
        ///   Specifies the assembly qualified type name of the directive to register.
        /// </param>
        public void Register(string directiveTypeName)
        {
            var updatedDirective = AssemblyNameNeedsToBeFixed()
                                       ? UpdateAssemblyName(directiveTypeName)
                                       : directiveTypeName;

            _directiveManager.Register(updatedDirective);
        }