/// <seealso cref="org.apache.velocity.runtime.resource.loader.ResourceLoader.Init(org.apache.commons.collections.ExtendedProperties)">
        /// </seealso>
        public override void Init(ExtendedProperties configuration)
        {
            log.Trace("StringResourceLoader : initialization starting.");

            // Get the repository configuration Info
            string repoClass = configuration.GetString(REPOSITORY_CLASS, REPOSITORY_CLASS_DEFAULT);
            string repoName  = configuration.GetString(REPOSITORY_NAME, REPOSITORY_NAME_DEFAULT);
            bool   isStatic  = configuration.GetBoolean(REPOSITORY_STATIC, REPOSITORY_STATIC_DEFAULT);
            string encoding  = configuration.GetString(REPOSITORY_ENCODING);

            // look for an existing repository of that name and isStatic setting
            if (isStatic)
            {
                this.repository = GetRepository(repoName);
                if (repository != null && log.DebugEnabled)
                {
                    log.Debug("Loaded repository '" + repoName + "' from static repo store");
                }
            }
            else
            {
                this.repository = (IStringResourceRepository)rsvc.GetApplicationAttribute(repoName);
                if (repository != null && log.DebugEnabled)
                {
                    log.Debug("Loaded repository '" + repoName + "' from application attributes");
                }
            }

            if (this.repository == null)
            {
                // since there's no repository under the repo name, create a new one
                this.repository = CceateRepository(repoClass, encoding);

                // and store it according to the isStatic setting
                if (isStatic)
                {
                    SetRepository(repoName, this.repository);
                }
                else
                {
                    rsvc.SetApplicationAttribute(repoName, this.repository);
                }
            }
            else
            {
                // ok, we already have a repo
                // Warn them if they are trying to change the class of the repository
                if (!this.repository.GetType().FullName.Equals(repoClass))
                {
                    log.Debug("Cannot change class of string repository '" + repoName + "' from " + this.repository.GetType().FullName + " to " + repoClass + ". The change will be ignored.");
                }

                // allow them to change the default encoding of the repo
                if (encoding != null && !this.repository.Encoding.Equals(encoding))
                {
                    if (log.DebugEnabled)
                    {
                        log.Debug("Changing the default encoding of string repository '" + repoName + "' from " + this.repository.Encoding + " to " + encoding);
                    }
                    this.repository.Encoding = encoding;
                }
            }

            log.Trace("StringResourceLoader : initialization complete.");
        }
 public StringResourceService(IStringResourceRepository iStringResourceRepository)
 {
     this._iStringResourceRepository = iStringResourceRepository;
 }
 /// <summary> Sets the specified {@link StringResourceRepository} in static storage
 /// under the specified name.
 /// </summary>
 /// <since> 1.6
 /// </since>
 public static void SetRepository(string name, IStringResourceRepository repo)
 {
     STATIC_REPOSITORIES[name] = repo;
 }
Beispiel #4
0
 public StringResourceService(IStringResourceRepository stringResourcesRepository, IUnitOfWork unitOfWork)
 {
     this.stringResourcesRepository = stringResourcesRepository;
     this.unitOfWork = unitOfWork;
 }