Ejemplo n.º 1
0
 public static HyphenationTreeCache GetHyphenationTreeCache()
 {
     if (hTreeCache == null)
     {
         hTreeCache = new HyphenationTreeCache();
     }
     return(hTreeCache);
 }
Ejemplo n.º 2
0
        /// <summary>Returns a hyphenation tree for a given language and country.</summary>
        /// <remarks>Returns a hyphenation tree for a given language and country. The hyphenation trees are cached.</remarks>
        /// <param name="lang">the language</param>
        /// <param name="country">the country (may be null or "none")</param>
        /// <param name="hyphPathNames">the map with user-configured hyphenation pattern file names</param>
        /// <returns>the hyphenation tree</returns>
        public static HyphenationTree GetHyphenationTree2(String lang, String country, IDictionary <String, String>
                                                          hyphPathNames)
        {
            String llccKey             = HyphenationTreeCache.ConstructLlccKey(lang, country);
            HyphenationTreeCache cache = GetHyphenationTreeCache();
            HyphenationTree      hTree;

            // first try to find it in the cache
            hTree = GetHyphenationTreeCache().GetHyphenationTree(lang, country);
            if (hTree != null)
            {
                return(hTree);
            }
            String key = HyphenationTreeCache.ConstructUserKey(lang, country, hyphPathNames);

            if (key == null)
            {
                key = llccKey;
            }
            if (additionalHyphenationFileDirectories != null)
            {
                foreach (String dir in additionalHyphenationFileDirectories)
                {
                    hTree = GetHyphenationTree(dir, key);
                    if (hTree != null)
                    {
                        break;
                    }
                }
            }
            if (hTree == null)
            {
                // get from the default directory
                Stream defaultHyphenationResourceStream = ResourceUtil.GetResourceStream(HyphenationConstants.HYPHENATION_DEFAULT_RESOURCE
                                                                                         + key + ".xml");
                if (defaultHyphenationResourceStream != null)
                {
                    hTree = GetHyphenationTree(defaultHyphenationResourceStream, key);
                }
            }
            // put it into the pattern cache
            if (hTree != null)
            {
                cache.Cache(llccKey, hTree);
            }
            return(hTree);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a hyphenation tree for a given language and country,
        /// with fallback from (lang,country) to (lang).
        /// </summary>
        /// <remarks>
        /// Returns a hyphenation tree for a given language and country,
        /// with fallback from (lang,country) to (lang).
        /// The hyphenation trees are cached.
        /// </remarks>
        /// <param name="lang">the language</param>
        /// <param name="country">the country (may be null or "none")</param>
        /// <param name="hyphPathNames">the map with user-configured hyphenation pattern file names</param>
        /// <returns>the hyphenation tree</returns>
        public static HyphenationTree GetHyphenationTree(String lang, String country, IDictionary <String, String>
                                                         hyphPathNames)
        {
            String llccKey             = HyphenationTreeCache.ConstructLlccKey(lang, country);
            HyphenationTreeCache cache = GetHyphenationTreeCache();

            // If this hyphenation tree has been registered as missing, return immediately
            if (cache.IsMissing(llccKey))
            {
                return(null);
            }
            HyphenationTree hTree = GetHyphenationTree2(lang, country, hyphPathNames);

            // fallback to lang only
            if (hTree == null && country != null && !country.Equals("none"))
            {
                String llKey = HyphenationTreeCache.ConstructLlccKey(lang, null);
                if (!cache.IsMissing(llKey))
                {
                    hTree = GetHyphenationTree2(lang, null, hyphPathNames);
                    if (hTree != null && log.IsDebugEnabled)
                    {
                        log.Debug("Couldn't find hyphenation pattern " + "for lang=\"" + lang + "\",country=\"" + country + "\"."
                                  + " Using general language pattern " + "for lang=\"" + lang + "\" instead.");
                    }
                    if (hTree == null)
                    {
                        // no fallback; register as missing
                        cache.NoteMissing(llKey);
                    }
                    else
                    {
                        // also register for (lang,country)
                        cache.Cache(llccKey, hTree);
                    }
                }
            }
            if (hTree == null)
            {
                // (lang,country) and (lang) tried; register as missing
                cache.NoteMissing(llccKey);
                log.Error("Couldn't find hyphenation pattern " + "for lang=\"" + lang + "\"" + (country != null && !country
                                                                                                .Equals("none") ? ",country=\"" + country + "\"" : "") + ".");
            }
            return(hTree);
        }
Ejemplo n.º 4
0
 /// <summary>Clears the default hyphenation tree cache.</summary>
 /// <remarks>Clears the default hyphenation tree cache. This method can be used if the underlying data files are changed at runtime.
 ///     </remarks>
 public static void ClearHyphenationTreeCache()
 {
     lock (staticLock) {
         hTreeCache = new HyphenationTreeCache();
     }
 }