// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) deadcode 
// Source File Name:   DocLocale.java

package com.sun.tools.javadoc;

import java.text.BreakIterator;
import java.text.Collator;
import java.util.Locale;

// Referenced classes of package com.sun.tools.javadoc:
//            DocEnv, DocImpl

class DocLocale
{

    private boolean htmlSentenceTerminatorFound(String s, int i)
    {
        for(int j = 0; j < sentenceTerminators.length; j++)
        {
            String s1 = sentenceTerminators[j];
            if(s.regionMatches(true, i, s1, 0, s1.length()))
                return true;
        }

        return false;
    }

    private Locale getLocale()
    {
        Object obj = null;
        if(localeName.length() > 0)
        {
            int i = localeName.indexOf('_');
            byte byte0 = -1;
            String s = null;
            String s1 = null;
            String s2 = null;
            if(i == 2)
            {
                s = localeName.substring(0, i);
                int j = localeName.indexOf('_', i + 1);
                if(j > 0)
                {
                    if(j != i + 3 || localeName.length() <= j + 1)
                    {
                        docenv.error(null, "main.malformed_locale_name", localeName);
                        return null;
                    }
                    s1 = localeName.substring(i + 1, j);
                    s2 = localeName.substring(j + 1);
                } else
                if(localeName.length() == i + 3)
                {
                    s1 = localeName.substring(i + 1);
                } else
                {
                    docenv.error(null, "main.malformed_locale_name", localeName);
                    return null;
                }
            } else
            if(i == -1 && localeName.length() == 2)
            {
                s = localeName;
            } else
            {
                docenv.error(null, "main.malformed_locale_name", localeName);
                return null;
            }
            Locale locale1 = searchLocale(s, s1, s2);
            if(locale1 == null)
            {
                docenv.error(null, "main.illegal_locale_name", localeName);
                return null;
            } else
            {
                return locale1;
            }
        } else
        {
            return Locale.getDefault();
        }
    }

    DocLocale(DocEnv docenv1, String s, boolean flag)
    {
        useBreakIterator = false;
        printedLongBreakIteratorWarning = false;
        docenv = docenv1;
        localeName = s;
        useBreakIterator = flag;
        if(locale == null)
            docenv1.exit();
        else
            Locale.setDefault(locale);
        collator = Collator.getInstance(locale);
        sentenceBreaker = BreakIterator.getSentenceInstance(locale);
    }

    private String englishLanguageFirstSentence(String s)
    {
        if(s == null)
            return null;
        int i = s.length();
        boolean flag = false;
        for(int j = 0; j < i; j++)
            switch(s.charAt(j))
            {
            case 46: // '.'
                flag = true;
                break;

            case 9: // '\t'
            case 10: // '\n'
            case 12: // '\f'
            case 13: // '\r'
            case 32: // ' '
                if(flag)
                    return s.substring(0, j);
                break;

            case 60: // '<'
                if(j > 0 && htmlSentenceTerminatorFound(s, j))
                    return s.substring(0, j);
                break;

            default:
                flag = false;
                break;
            }

        return s;
    }

    String localeSpecificFirstSentence(DocImpl docimpl, String s)
    {
        if(s == null || s.length() == 0)
            return "";
        int i = s.indexOf("-->");
        if(s.trim().startsWith("<!--") && i != -1)
            return localeSpecificFirstSentence(docimpl, s.substring(i + 3, s.length()));
        sentenceBreaker.setText(s.replace('\n', ' '));
        int j = sentenceBreaker.first();
        int k = sentenceBreaker.next();
        String s1 = s.substring(j, k);
        if(locale.getLanguage().equals("en") && !useBreakIterator)
        {
            String s2 = englishLanguageFirstSentence(s);
            if(!s1.trim().equals(s2.trim()))
                if(!printedLongBreakIteratorWarning)
                {
                    docenv.warning(docimpl, "javadoc.BreakIterator_Error_Long_0");
                    docenv.notice("javadoc.BreakIterator_Error_Long_1", s2);
                    docenv.notice("javadoc.BreakIterator_Error_Long_2");
                    docenv.notice("javadoc.BreakIterator_Error_Long_3");
                    docenv.notice("javadoc.BreakIterator_Error_Long_4", s1);
                    docenv.notice("javadoc.BreakIterator_Error_Long_5");
                    docenv.notice("javadoc.BreakIterator_Error_Long_6");
                    printedLongBreakIteratorWarning = true;
                } else
                {
                    docenv.warning(docimpl, "javadoc.BreakIterator_Error_Short_0");
                    docenv.notice("javadoc.BreakIterator_Error_Short_1", s2);
                    docenv.notice("javadoc.BreakIterator_Error_Short_2");
                    docenv.notice("javadoc.BreakIterator_Error_Short_3", s1);
                }
            return s2;
        } else
        {
            return s1;
        }
    }

    private Locale searchLocale(String s, String s1, String s2)
    {
        Locale alocale[] = Locale.getAvailableLocales();
        for(int i = 0; i < alocale.length; i++)
            if(alocale[i].getLanguage().equals(s) && (s1 == null || alocale[i].getCountry().equals(s1)) && (s2 == null || alocale[i].getVariant().equals(s2)))
                return alocale[i];

        return null;
    }

    final String localeName;
    final Locale locale = getLocale();
    final Collator collator;
    private final DocEnv docenv;
    private final BreakIterator sentenceBreaker;
    private boolean useBreakIterator;
    private boolean printedLongBreakIteratorWarning;
    static final String sentenceTerminators[] = {
        "<p>", "</p>", "<h1>", "<h2>", "<h3>", "<h4>", "<h5>", "<h6>", "</h1>", "</h2>", 
        "</h3>", "</h4>", "</h5>", "</h6>", "<hr>", "<pre>", "</pre>"
    };

}
