diff options
author | Simon Pepping <spepping@apache.org> | 2010-10-06 07:07:38 +0000 |
---|---|---|
committer | Simon Pepping <spepping@apache.org> | 2010-10-06 07:07:38 +0000 |
commit | 04701709af5735bf1ecf236efef93999c2ffe834 (patch) | |
tree | 2c47b28176dc80445e0153382de454fe90d6b510 /src | |
parent | a6e8eea8153df672e94a9e4e7d2398b45a29b0bc (diff) | |
download | xmlgraphics-fop-04701709af5735bf1ecf236efef93999c2ffe834.tar.gz xmlgraphics-fop-04701709af5735bf1ecf236efef93999c2ffe834.zip |
Making fallback from (lang,country) to (lang) consistent
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1004907 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/java/org/apache/fop/hyphenation/Hyphenator.java | 91 |
1 files changed, 61 insertions, 30 deletions
diff --git a/src/java/org/apache/fop/hyphenation/Hyphenator.java b/src/java/org/apache/fop/hyphenation/Hyphenator.java index a556fd7fe..7f37b5e28 100644 --- a/src/java/org/apache/fop/hyphenation/Hyphenator.java +++ b/src/java/org/apache/fop/hyphenation/Hyphenator.java @@ -76,8 +76,9 @@ public final class Hyphenator { } /** - * Returns a hyphenation tree for a given language and country. The hyphenation trees are - * cached. + * Returns a hyphenation tree for a given language and country, + * with fallback from (lang,country) to (lang). + * The hyphenation trees are cached. * @param lang the language * @param country the country (may be null or "none") * @param resolver resolver to find the hyphenation files @@ -89,11 +90,62 @@ public final class Hyphenator { String llccKey = HyphenationTreeCache.constructLlccKey(lang, country); HyphenationTreeCache cache = getHyphenationTreeCache(); - // See if there was an error finding this hyphenation tree before + // If this hyphenation tree has been registered as missing, return immediately if (cache.isMissing(llccKey)) { return null; } + HyphenationTree hTree = getHyphenationTree2(lang, country, resolver, hyphPatNames); + + // 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, resolver, hyphPatNames); + 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; + } + + /** + * Returns a hyphenation tree for a given language and country + * The hyphenation trees are cached. + * @param lang the language + * @param country the country (may be null or "none") + * @param resolver resolver to find the hyphenation files + * @param hyphPatNames the map with user-configured hyphenation pattern file names + * @return the hyphenation tree + */ + private static HyphenationTree getHyphenationTree2(String lang, + String country, HyphenationTreeResolver resolver, Map hyphPatNames) { + String llccKey = HyphenationTreeCache.constructLlccKey(lang, country); + HyphenationTreeCache cache = getHyphenationTreeCache(); + HyphenationTree hTree; // first try to find it in the cache hTree = getHyphenationTreeCache().getHyphenationTree(lang, country); @@ -105,6 +157,7 @@ public final class Hyphenator { if (key == null) { key = llccKey; } + if (resolver != null) { hTree = getUserHyphenationTree(key, resolver); } @@ -115,10 +168,8 @@ public final class Hyphenator { // put it into the pattern cache if (hTree != null) { cache.cache(llccKey, hTree); - } else { - log.error("Couldn't find hyphenation pattern " + llccKey); - cache.noteMissing(llccKey); } + return hTree; } @@ -173,31 +224,11 @@ public final class Hyphenator { try { is = getResourceStream(key); if (is == null) { - if (key.length() == 5) { - String lang = key.substring(0, 2); - is = getResourceStream(lang); - if (is != null) { - if (log.isDebugEnabled()) { - log.debug("Couldn't find hyphenation pattern '" - + key - + "'. Using general language pattern '" - + lang - + "' instead."); - } - } else { - if (log.isDebugEnabled()) { - log.debug("Couldn't find precompiled hyphenation pattern " - + lang + " in resources."); - } - return null; - } - } else { - if (log.isDebugEnabled()) { - log.debug("Couldn't find precompiled hyphenation pattern " - + key + " in resources"); - } - return null; + if (log.isDebugEnabled()) { + log.debug("Couldn't find precompiled hyphenation pattern " + + key + " in resources"); } + return null; } hTree = readHyphenationTree(is); } finally { |