Esempio n. 1
0
 /**
 * Constructs a message bundle from input xml (fetched from an external file).
 *
 * @param locale The LocaleSpec element that this bundle was constructed from.
 * @param xml The content of the remote file.
 * @throws SpecParserException if parsing fails.
 */
 public MessageBundle(LocaleSpec locale, String xml)
 {
     XmlElement doc;
     try
     {
         doc = XmlUtil.Parse(xml);
     }
     catch (XmlException e)
     {
         throw new SpecParserException("Malformed XML in file " + locale.getMessages()
                                       + ": " + e.Message);
     }
     messages = parseMessages(doc);
     jsonString = new JsonObject(messages).ToString();
     languageDirection = locale.getLanguageDirection();
 }
Esempio n. 2
0
        /**
         * Constructs a message bundle from input xml (fetched from an external file).
         *
         * @param locale The LocaleSpec element that this bundle was constructed from.
         * @param xml The content of the remote file.
         * @throws SpecParserException if parsing fails.
         */
        public MessageBundle(LocaleSpec locale, String xml)
        {
            XmlElement doc;

            try
            {
                doc = XmlUtil.Parse(xml);
            }
            catch (XmlException e)
            {
                throw new SpecParserException("Malformed XML in file " + locale.getMessages()
                                              + ": " + e.Message);
            }
            messages          = parseMessages(doc);
            jsonString        = new JsonObject(messages).ToString();
            languageDirection = locale.getLanguageDirection();
        }
Esempio n. 3
0
        /**
         * Attempts to retrieve a valid LocaleSpec for the given Locale.
         * First tries to find an exact language / country match.
         * Then tries to find a match for language / all.
         * Then tries to find a match for all / all.
         * Finally gives up.
         * @param locale
         * @return The locale spec, if there is a matching one, or null.
         */
        public LocaleSpec getLocale(Locale locale)
        {
            if (locales.Count == 0)
            {
                return(null);
            }
            LocaleSpec localeSpec = null;

            if (!locales.TryGetValue(locale, out localeSpec))
            {
                locale = new Locale(locale.getLanguage(), "ALL");
                if (!locales.TryGetValue(locale, out localeSpec))
                {
                    locales.TryGetValue(GadgetSpec.DEFAULT_LOCALE, out localeSpec);
                }
            }

            return(localeSpec);
        }
    /**
 * Retrieve the MessageBundle for the given LocaleSpec from the network or cache.
 */
    protected abstract MessageBundle fetchBundle(LocaleSpec locale, bool ignoreCache);
        protected MessageBundle fetchBundle(LocaleSpec locale, bool ignoreCache)
        {
            Uri url = locale.getMessages();
            sRequest request = new sRequest(url).setIgnoreCache(ignoreCache);
            // Since we don't allow any variance in cache time, we should just force the cache time
            // globally. This ensures propagation to shared caches when this is set.
            request.setCacheTtl((int)(refresh / 1000));

            sResponse response = fetcher.fetch(request);
            if (response.getHttpStatusCode() != (int)HttpStatusCode.OK)
            {
                throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
                                          "Unable to retrieve message bundle xml. HTTP error " +
                                          response.getHttpStatusCode());
            }

            MessageBundle bundle = new MessageBundle(locale, response.responseString);
            return bundle;
        }
Esempio n. 6
0
        public void visit(XmlElement element)
        {
            LocaleSpec locale = new LocaleSpec(element, _base);

            localeMap[new Locale(locale.getLanguage(), locale.getCountry())] = locale;
        }
Esempio n. 7
0
 public void visit(XmlElement element)
 {
     LocaleSpec locale = new LocaleSpec(element, _base);
     localeMap[new Locale(locale.getLanguage(), locale.getCountry())] = locale;
 }