/// <summary> /// Try to find a template given a normalized path. /// </summary> /// <param name="String">a normalized path</param> /// <returns>InputStream input stream that will be parsed</returns> private Stream findTemplate(String path, String template) { try { ResourceLocator rl = new ResourceLocator(path, template) ; if (rl.Exists) { return(new BufferedStream(rl.OpenRead())); } else { return(null); } } catch (FileNotFoundException fnfe) { // log and convert to a general Velocity ResourceNotFoundException return(null); } }
/// <summary> /// Try to find a template given a normalized path. /// </summary> /// <param name="String">a normalized path</param> /// <returns>InputStream input stream that will be parsed</returns> private Stream findTemplate(String path, String template) { try { ResourceLocator rl = new ResourceLocator(path, template) ; if (rl.Exists) { return new BufferedStream(rl.OpenRead()); } else { return null; } } catch (FileNotFoundException fnfe) { // log and convert to a general Velocity ResourceNotFoundException return null; } }
/// <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"); } }
/// <summary> Initializes the Velocity Runtime with properties file. /// The properties file may be in the file system proper, /// or the properties file may be in the classpath. /// </summary> private void setDefaultProperties() { //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(); // // try { // //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_PROPERTIES); // FileInfo file = new FileInfo(NVelocity.Runtime.RuntimeConstants_Fields.DEFAULT_RUNTIME_PROPERTIES); // // configuration.Load(inputStream); // // info("Default Properties File: " + new System.IO.FileInfo(NVelocity.Runtime.RuntimeConstants_Fields.DEFAULT_RUNTIME_PROPERTIES).FullName); // } // catch (System.IO.IOException ioe) { // System.Console.Error.WriteLine("Cannot get Velocity Runtime default properties!"); // } // TODO - there might be a better way try { ResourceLocator file = new ResourceLocator(RuntimeConstants_Fields.DEFAULT_RUNTIME_PROPERTIES); configuration.Load(file.OpenRead()); info("Default Properties File: " + file.FullName); } catch (System.Exception ex) { debugOutput.WriteLine("Cannot get NVelocity Runtime default properties!\n" + ex.Message); debugOutput.Flush(); } }
/// <summary> /// Load a properties file from the classpath /// </summary> /// <param name="propertiesFile">the properties file to load.</param> /// <returns>a properties instance loaded with the properties from /// the file. If no file can be found it returns an empty instance. /// </returns> protected internal virtual ExtendedProperties loadFromClassPath(String propertiesFile) { ExtendedProperties properties = new ExtendedProperties(); try { // This is a hack for now to make sure that properties // files referenced in the filesystem work in // a JAR file. We have to deprecate the use // of $generator.templatePath in templates first // and this hack will allow those same templates // that use $generator.templatePath to work in // JAR files. if (propertiesFile.StartsWith("$generator")) { propertiesFile = propertiesFile.Substring("$generator.templatePath/".Length); } ResourceLocator rl = new ResourceLocator(propertiesFile); Stream inputStream = rl.OpenRead(); properties.Load(inputStream); } catch (System.IO.IOException) { // do nothing } return properties; }
/// <summary> Create a new generator object with default properties. /// * /// </summary> /// <returns>Generator generator used in the control context. /// /// </returns> /// <summary> Set the velocity engine. /// </summary> /// <summary> Create a new generator object with properties loaded from /// a file. If the file does not exist or any other exception /// occurs during the reading operation the default properties /// are used. /// * /// </summary> /// <param name="String">properties used to help populate the control context. /// </param> /// <returns>Generator generator used in the control context. /// /// </returns> public Generator(System.String propFile) { ResourceLocator rl = new ResourceLocator(propFile); if (rl.Exists) { Stream s = rl.OpenRead(); props.Load(rl.OpenRead()); s.Close(); } else { setDefaultProps(); } }
/// <summary> Set default properties. /// </summary> protected internal virtual void setDefaultProps() { try { ResourceLocator rl = new ResourceLocator(DEFAULT_TEXEN_PROPERTIES); if (rl.Exists) { Stream s = rl.OpenRead(); props.Load(rl.OpenRead()); s.Close(); } else { Log.WriteLine(LogPrefix + "PANIC: Could not locate default properties!"); } } catch (System.Exception) { Log.WriteLine(LogPrefix + "Cannot get default properties!"); } }