Esempio n. 1
0
        /**
         * Create a MessageBundle by merging child messages into the parent.
         *
         * @param parent The base bundle.
         * @param child The bundle containing overriding messages.
         */
        public MessageBundle(MessageBundle parent, MessageBundle child)
        {
            Dictionary <String, String> merged = new Dictionary <string, string>();
            String dir = null;

            if (parent != null)
            {
                foreach (var item in parent.messages)
                {
                    merged[item.Key] = item.Value;
                }
                dir = parent.languageDirection;
            }
            if (child != null)
            {
                foreach (var item in child.messages)
                {
                    merged[item.Key] = item.Value;
                }
                dir = child.languageDirection;
            }
            messages          = merged;
            jsonString        = new JsonObject(messages).ToString();
            languageDirection = dir;
        }
Esempio n. 2
0
        /**
         * @param element
         * @param specUrl The url that the spec is loaded from. messages is assumed
         *     to be relative to this path.
         * @throws SpecParserException If language_direction is not valid
         */
        public LocaleSpec(XmlElement element, Uri specUrl)
        {
            language          = XmlUtil.getAttribute(element, "lang", "all").ToLower();
            country           = XmlUtil.getAttribute(element, "country", "ALL").ToUpper();
            languageDirection = XmlUtil.getAttribute(element, "language_direction", "ltr");
            if (!("ltr".Equals(languageDirection) ||
                  "rtl".Equals(languageDirection)))
            {
                throw new SpecParserException(
                          "Locale@language_direction must be ltr or rtl");
            }
            String messages = XmlUtil.getAttribute(element, "messages");

            if (messages == null)
            {
                this.messages = Uri.parse("");
            }
            else
            {
                try
                {
                    URI thisuri = new URI(messages, UriKind.RelativeOrAbsolute);
                    if (thisuri.IsAbsoluteUri)
                    {
                        this.messages = specUrl.resolve(Uri.parse(messages));
                    }
                    else
                    {
                        this.messages = specUrl.resolve(Uri.parse(specUrl.toJavaUri(), thisuri));
                    }
                    //this.messages = Uri.parse(messages);
                }
                catch (Exception)
                {
                    throw new SpecParserException("Locale@messages url is invalid.");
                }
            }
            messageBundle = new MessageBundle(element);
        }
Esempio n. 3
0
 /**
 * Create a MessageBundle by merging child messages into the parent.
 *
 * @param parent The base bundle.
 * @param child The bundle containing overriding messages.
 */
 public MessageBundle(MessageBundle parent, MessageBundle child)
 {
     Dictionary<String, String> merged = new Dictionary<string,string>();
     String dir = null;
     if (parent != null)
     {
         foreach (var item in parent.messages)
         {
             merged[item.Key] = item.Value;
         }
         dir = parent.languageDirection;
     }
     if (child != null)
     {
         foreach (var item in child.messages)
         {
             merged[item.Key] = item.Value;
         }
         dir = child.languageDirection;
     }
     messages = merged;
     jsonString = new JsonObject(messages).ToString();
     languageDirection = dir;
 }
Esempio n. 4
0
 /**
  * @param element
  * @param specUrl The url that the spec is loaded from. messages is assumed
  *     to be relative to this path.
  * @throws SpecParserException If language_direction is not valid
  */
 public LocaleSpec(XmlElement element, Uri specUrl)
 {
     language = XmlUtil.getAttribute(element, "lang", "all").ToLower();
     country = XmlUtil.getAttribute(element, "country", "ALL").ToUpper();
     languageDirection = XmlUtil.getAttribute(element, "language_direction", "ltr");
     if (!("ltr".Equals(languageDirection) ||
           "rtl".Equals(languageDirection)))
     {
         throw new SpecParserException(
             "Locale@language_direction must be ltr or rtl");
     }
     String messages = XmlUtil.getAttribute(element, "messages");
     if (messages == null)
     {
         this.messages = Uri.parse("");
     }
     else
     {
         try
         {
             URI thisuri = new URI(messages, UriKind.RelativeOrAbsolute);
             if (thisuri.IsAbsoluteUri)
             {
                 this.messages = specUrl.resolve(Uri.parse(messages));
             }
             else
             {
                 this.messages = specUrl.resolve(Uri.parse(specUrl.toJavaUri(),thisuri));
             }
             //this.messages = Uri.parse(messages);
         }
         catch (Exception)
         {
             throw new SpecParserException("Locale@messages url is invalid.");
         }
     }
     messageBundle = new MessageBundle(element);
 }
        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;
        }