/// <summary> 
		/// Initialize the template loader with a
		/// a resources class.
		/// </summary>
		public override void Init(ExtendedProperties configuration)
		{
			assemblyNames = configuration.GetVector("assembly");
			prefixes = configuration.GetVector("prefix");
			if (assemblyNames.Count != prefixes.Count)
			{
				throw new ResourceNotFoundException("Need to specify prefixes!");
			}
		}
Exemplo n.º 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>
		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");
		}
		/// <summary> 
		/// Initialize the template loader with a resources class.
		/// </summary>
		public override void Init(ExtendedProperties configuration)
		{
			object value = configuration["assembly"];
			if (value is string)
			{
				assemblyNames = new List<string> { (string)configuration["assembly"] };
			}
			else if (value is List<string>)
			{
				assemblyNames = configuration.GetStringList("assembly");
			}
			else
			{
				throw new VelocityException("Expected property 'assembly' to be of type string or List<string>.");
			}
		}
Exemplo n.º 4
0
		/// <summary>
		/// Initialize the template loader with a
		/// a resources class.
		/// </summary>
		public abstract void Init(ExtendedProperties configuration);
		/// <summary> Create an ExtendedProperties object that is a subset
		/// of this one. Take into account duplicate keys
		/// by using the setProperty() in ExtendedProperties.
		/// *
		/// </summary>
		/// <param name="prefix">prefix
		///
		/// </param>
		public ExtendedProperties Subset(String prefix)
		{
			ExtendedProperties c = new ExtendedProperties();
			bool validSubset = false;

			foreach(Object key in Keys)
			{
				if (key is String && ((String) key).StartsWith(prefix))
				{
					if (!validSubset)
						validSubset = true;

					String newKey;

					/*
					* Check to make sure that c.subset(prefix) doesn't
					* blow up when there is only a single property
					* with the key prefix. This is not a useful
					* subset but it is a valid subset.
					*/
					if (((String) key).Length == prefix.Length)
					{
						newKey = prefix;
					}
					else
					{
						newKey = ((String) key).Substring(prefix.Length + 1);
					}

					/*
						*  use addPropertyDirect() - this will plug the data as 
						*  is into the Map, but will also do the right thing
						*  re key accounting
						*/

					c.AddPropertyDirect(newKey, this[key]);
				}
			}

			if (validSubset)
			{
				return c;
			}
			else
			{
				return null;
			}
		}
		/// <summary> Combines an existing Hashtable with this Hashtable.
		/// *
		/// Warning: It will overwrite previous entries without warning.
		/// *
		/// </summary>
		/// <param name="c">ExtendedProperties
		///
		/// </param>
		public void Combine(ExtendedProperties c)
		{
			foreach(String key in c.Keys)
			{
				Object o = c[key];
				// if the value is a String, escape it so that if there are delimiters that the value is not converted to a list
				if (o is String)
				{
					o = ((String) o).Replace(",", @"\,");
				}

				SetProperty(key, o);
			}
		}
		/// <summary>
		/// Creates and loads the extended properties from the specified
		/// file.
		/// </summary>
		/// <param name="file">A String.</param>
		/// <param name="defaultFile">File to load defaults from.</param>
		/// <exception cref="IOException" />
		public ExtendedProperties(String file, String defaultFile)
		{
			this.file = file;

			basePath = new FileInfo(file).FullName;
			basePath = basePath.Substring(0, (basePath.LastIndexOf(fileSeparator) + 1) - (0));

			Load(new FileStream(file, FileMode.Open, FileAccess.Read));

			if (defaultFile != null)
			{
				defaults = new ExtendedProperties(defaultFile);
			}
		}
Exemplo n.º 8
0
		/// <summary>
		/// Add a property to the configuration. If it already
		/// exists then the value stated here will be added
		/// to the configuration entry.
		/// <remarks>
		/// For example, if
		/// <c>resource.loader = file</c>
		/// is already present in the configuration and you
		/// <c>addProperty("resource.loader", "classpath")</c>
		/// 
		/// Then you will end up with a <see cref="IList"/> like the
		/// following:
		/// 
		/// <c>["file", "classpath"]</c>
		/// </remarks>
		/// </summary>
		/// <param name="key">key</param>
		/// <param name="value">value</param>
		public void AddProperty(String key, Object value)
		{
			if (overridingProperties == null)
			{
				overridingProperties = new ExtendedProperties();
			}

			overridingProperties.AddProperty(key, value);
		}
Exemplo n.º 9
0
		/// <summary>
		/// CTOR that invokes an init(String), initializing
		/// the engine using the Properties specified
		/// </summary>
		/// <param name="p">name of properties to init with</param>
		public VelocityEngine(ExtendedProperties p)
		{
			runtimeInstance.Init(p);
		}
Exemplo n.º 10
0
		/// <summary>
		/// initialize the Velocity runtime engine, using default properties
		/// plus the properties in the passed in java.util.Properties object
		/// </summary>
		/// <param name="p"> Properties object containing initialization properties</param>
		public void Init(ExtendedProperties p)
		{
			runtimeInstance.Init(p);
		}
Exemplo n.º 11
0
		/// <summary>
		/// initialize the Velocity runtime engine, using default properties
		/// plus the properties in the passed in java.util.Properties object
		/// </summary>
		/// <param name="p">
		/// Proprties object containing initialization properties
		/// </param>
		public static void Init(ExtendedProperties p)
		{
			RuntimeSingleton.Init(p);
		}
Exemplo n.º 12
0
		/// <summary>
		/// Set an entire configuration at once. This is
		/// useful in cases where the parent application uses
		/// the ExtendedProperties class and the velocity configuration
		/// is a subset of the parent application's configuration.
		/// </summary>
		public static void SetExtendedProperties(ExtendedProperties value)
		{
			RuntimeSingleton.Configuration = value;
		}
Exemplo n.º 13
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]);
			}
		}
Exemplo n.º 14
0
		/// <summary>
		/// Initialize the Velocity Runtime with the name of
		/// ExtendedProperties object.
		/// </summary>
		/// <param name="configurationFile">Properties</param>
		public void Init(String configurationFile)
		{
			overridingProperties = new ExtendedProperties(configurationFile);
			Init();
		}
Exemplo n.º 15
0
		/// <summary>
		/// Initialize the Velocity Runtime with a Properties
		/// object.
		/// </summary>
		/// <param name="p">Properties</param>
		public void Init(ExtendedProperties p)
		{
			overridingProperties = ExtendedProperties.ConvertProperties(p);
			Init();
		}
Exemplo n.º 16
0
		/// <summary>
		/// Initialize the Velocity Runtime with an ExtendedProperties object.
		/// </summary>
		/// <param name="p">Properties</param>
		public static void Init(ExtendedProperties p)
		{
			ri.Init(p);
		}
		public override void Init(ExtendedProperties configuration)
		{
			runtimeServices.Info("FileResourceLoader : initialization starting.");

			paths = configuration.GetVector("path");
		}
Exemplo n.º 18
0
		/// <summary>
		/// Set an entire configuration at once. This is
		/// useful in cases where the parent application uses
		/// the ExtendedProperties class and the velocity configuration
		/// is a subset of the parent application's configuration.
		/// </summary>
		public void SetExtendedProperties(ExtendedProperties value)
		{
			runtimeInstance.Configuration = value;
		}
		/// <summary>
		/// Convert a standard properties class into a configuration class.
		/// </summary>
		/// <param name="p">properties object to convert into a ExtendedProperties object.</param>
		/// <returns>ExtendedProperties configuration created from the properties object.</returns>
		public static ExtendedProperties ConvertProperties(ExtendedProperties p)
		{
			ExtendedProperties c = new ExtendedProperties();

			foreach(String key in p.Keys)
			{
				Object value = p.GetProperty(key);

				// if the value is a String, escape it so that if there are delimiters that the value is not converted to a list
				if (value is String)
					value = value.ToString().Replace(",", @"\,");
				c.SetProperty(key, value);
			}

			return c;
		}
Exemplo n.º 20
0
		public RuntimeInstance()
		{
			// logSystem = new PrimordialLogSystem();
			configuration = new ExtendedProperties();

			// create a VM factory, resource manager
			// and introspector
			vmFactory = new VelocimacroFactory(this);

			// make a new introspector and initialize it
			introspector = new Introspector(this);

			// and a store for the application attributes
			applicationAttributes = new Hashtable();
		}