コード例 #1
0
ファイル: RuntimeInstance.cs プロジェクト: zyj0021/NVelocity
        /// <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]);
            }
        }
コード例 #2
0
ファイル: URLResourceLoader.cs プロジェクト: 15831944/tool
        /// <seealso cref="org.apache.velocity.runtime.resource.loader.ResourceLoader.Init(org.apache.commons.collections.ExtendedProperties)">
        /// </seealso>
        public override void Init(ExtendedProperties configuration)
        {
            log.Trace("URLResourceLoader : initialization starting.");

            roots = configuration.GetStringArray("root");
            if (log.DebugEnabled)
            {
                for (int i = 0; i < roots.Length; i++)
                {
                    log.Debug("URLResourceLoader : adding root '" + roots[i] + "'");
                }
            }

            timeout = configuration.GetInt("timeout", -1);
            if (timeout > 0)
            {
                try
                {
                    System.Type[] types = new System.Type[] { System.Type.GetType("System.Int32") };
                    System.Reflection.MethodInfo conn = typeof(System.Net.HttpWebRequest).GetMethod("setConnectTimeout", (types == null) ? new System.Type[0] : (System.Type[])types);
                    System.Reflection.MethodInfo read = typeof(System.Net.HttpWebRequest).GetMethod("setReadTimeout", (types == null) ? new System.Type[0] : (System.Type[])types);
                    timeoutMethods = new System.Reflection.MethodInfo[] { conn, read };
                    log.Debug("URLResourceLoader : timeout set to " + timeout);
                }
                catch (System.MethodAccessException nsme)
                {
                    log.Debug("URLResourceLoader : Java 1.5+ is required to customize timeout!", nsme);
                    timeout = -1;
                }
            }

            // Init the template paths map
            templateRoots = new System.Collections.Hashtable();

            log.Trace("URLResourceLoader : initialization complete.");
        }
コード例 #3
0
ファイル: RuntimeInstance.cs プロジェクト: minskowl/MY
        /// <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()
        {
            /*
             * Initialize the runtime directive table.
             * This will be used for creating parsers.
             */
            runtimeDirectives = new System.Collections.Hashtable();

            //UPGRADE_TODO: Format of property file may need to be changed. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1089"'
            ExtendedProperties directiveProperties = new ExtendedProperties();

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

            //	    ClassLoader classLoader = Runtime.class.getClassLoader();
            //	    //UPGRADE_ISSUE: Class 'java.lang.ClassLoader' was not converted. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1000_javalangClassLoader"'
            //	    //UPGRADE_ISSUE: Method 'java.lang.Class.getClassLoader' was not converted. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1000_javalangClassgetClassLoader"'
            //	    ClassLoader classLoader = this.GetType().getClassLoader();
            //
            //	    //UPGRADE_TODO: Method java.lang.ClassLoader.getResourceAsStream was not converted. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1095"'
            //	    System.IO.Stream inputStream = classLoader.getResourceAsStream(NVelocity.Runtime.RuntimeConstants_Fields.DEFAULT_RUNTIME_DIRECTIVES);
            //
            //	    if (inputStream == null)
            //	    throw new System.Exception("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!");
            //
            //	    //UPGRADE_ISSUE: Method 'java.util.Properties.load' was not converted. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1000_javautilPropertiesload_javaioInputStream"'
            //	    directiveProperties.load(inputStream);
            //
            try {
                ResourceLocator file = new ResourceLocator(RuntimeConstants_Fields.DEFAULT_RUNTIME_DIRECTIVES);
                directiveProperties.Load(file.OpenRead());
            } catch (System.Exception ex) {
                throw new System.Exception("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" + ex.Message);
            }


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

            //UPGRADE_TODO: method 'java.util.Enumeration.hasMoreElements' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationhasMoreElements"'
            while (directiveClasses.MoveNext())
            {
                //UPGRADE_TODO: method 'java.util.Enumeration.nextElement' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationnextElement"'
                System.String directiveClass = (System.String)directiveClasses.Current;
                loadDirective(directiveClass, "System");
            }

            /*
             *  now the user's directives
             */
            System.String[] userdirective = configuration.GetStringArray("userdirective");
            for (int i = 0; i < userdirective.Length; i++)
            {
                loadDirective(userdirective[i], "User");
            }
        }