Ejemplo n.º 1
0
        public static void UpdateFromBundle(String bundleName, DataInfo info)
        {
            ResourceBundle r      = ResourceBundle.GetBundle(bundleName, Locale.Current);
            String         prefix = info.GetDataClassName();

            DataField[] fs = info.GetFields();
            for (int i = 0; i < fs.Length; i++)
            {
                try
                {
                    fs[i].SetFieldTitle(r.GetString(prefix + "." + fs[i].GetFieldName()));
                }
                catch (MissingResourceException)
                {
                    Console.WriteLine("Missing Resource " + prefix + "." + fs[i].GetFieldName());
                }
                catch (Exception e)
                {
                    Console.WriteLine("Resource not found for : " + prefix + "." + fs[i].GetFieldName() + "\n" + e);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Format the given message to XML.
        /// <para>
        /// This method can be overridden in a subclass.
        /// It is recommended to use the <seealso cref="Formatter#formatMessage"/>
        /// convenience method to localize and format the message field.
        ///
        /// </para>
        /// </summary>
        /// <param name="record"> the log record to be formatted. </param>
        /// <returns> a formatted log record </returns>
        public override String Format(LogRecord record)
        {
            StringBuilder sb = new StringBuilder(500);

            sb.Append("<record>\n");

            sb.Append("  <date>");
            AppendISO8601(sb, record.Millis);
            sb.Append("</date>\n");

            sb.Append("  <millis>");
            sb.Append(record.Millis);
            sb.Append("</millis>\n");

            sb.Append("  <sequence>");
            sb.Append(record.SequenceNumber);
            sb.Append("</sequence>\n");

            String name = record.LoggerName;

            if (name != null)
            {
                sb.Append("  <logger>");
                Escape(sb, name);
                sb.Append("</logger>\n");
            }

            sb.Append("  <level>");
            Escape(sb, record.Level.ToString());
            sb.Append("</level>\n");

            if (record.SourceClassName != null)
            {
                sb.Append("  <class>");
                Escape(sb, record.SourceClassName);
                sb.Append("</class>\n");
            }

            if (record.SourceMethodName != null)
            {
                sb.Append("  <method>");
                Escape(sb, record.SourceMethodName);
                sb.Append("</method>\n");
            }

            sb.Append("  <thread>");
            sb.Append(record.ThreadID);
            sb.Append("</thread>\n");

            if (record.Message != null)
            {
                // Format the message string and its accompanying parameters.
                String message = formatMessage(record);
                sb.Append("  <message>");
                Escape(sb, message);
                sb.Append("</message>");
                sb.Append("\n");
            }

            // If the message is being localized, output the key, resource
            // bundle name, and params.
            ResourceBundle bundle = record.ResourceBundle;

            try
            {
                if (bundle != null && bundle.GetString(record.Message) != null)
                {
                    sb.Append("  <key>");
                    Escape(sb, record.Message);
                    sb.Append("</key>\n");
                    sb.Append("  <catalog>");
                    Escape(sb, record.ResourceBundleName);
                    sb.Append("</catalog>\n");
                }
            }
            catch (Exception)
            {
                // The message is not in the catalog.  Drop through.
            }

            Object[] parameters = record.Parameters;
            //  Check to see if the parameter was not a messagetext format
            //  or was not null or empty
            if (parameters != null && parameters.Length != 0 && record.Message.IndexOf("{") == -1)
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    sb.Append("  <param>");
                    try
                    {
                        Escape(sb, parameters[i].ToString());
                    }
                    catch (Exception)
                    {
                        sb.Append("???");
                    }
                    sb.Append("</param>\n");
                }
            }

            if (record.Thrown != null)
            {
                // Report on the state of the throwable.
                Throwable th = record.Thrown;
                sb.Append("  <exception>\n");
                sb.Append("    <message>");
                Escape(sb, th.ToString());
                sb.Append("</message>\n");
                StackTraceElement[] trace = th.StackTrace;
                for (int i = 0; i < trace.Length; i++)
                {
                    StackTraceElement frame = trace[i];
                    sb.Append("    <frame>\n");
                    sb.Append("      <class>");
                    Escape(sb, frame.ClassName);
                    sb.Append("</class>\n");
                    sb.Append("      <method>");
                    Escape(sb, frame.MethodName);
                    sb.Append("</method>\n");
                    // Check for a line number.
                    if (frame.LineNumber >= 0)
                    {
                        sb.Append("      <line>");
                        sb.Append(frame.LineNumber);
                        sb.Append("</line>\n");
                    }
                    sb.Append("    </frame>\n");
                }
                sb.Append("  </exception>\n");
            }

            sb.Append("</record>\n");
            return(sb.ToString());
        }
Ejemplo n.º 3
0
 public RequiredPrivilegesException(ResourceBundle bundle) : base(bundle.GetString("Default.RequiredPrivilegesException"))
 {
 }
Ejemplo n.º 4
0
        private void InitializeData(Locale desiredLocale)
        {
            Locale = desiredLocale;

            // Copy values of a cached instance if any.
            SoftReference <DateFormatSymbols> @ref = CachedInstances[Locale];
            DateFormatSymbols dfs;

            if (@ref != null && (dfs = @ref.get()) != null)
            {
                CopyMembers(dfs, this);
                return;
            }

            // Initialize the fields from the ResourceBundle for locale.
            LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(typeof(DateFormatSymbolsProvider), Locale);

            // Avoid any potential recursions
            if (!(adapter is ResourceBundleBasedAdapter))
            {
                adapter = LocaleProviderAdapter.ResourceBundleBased;
            }
            ResourceBundle resource = ((ResourceBundleBasedAdapter)adapter).LocaleData.getDateFormatData(Locale);

            // JRE and CLDR use different keys
            // JRE: Eras, short.Eras and narrow.Eras
            // CLDR: long.Eras, Eras and narrow.Eras
            if (resource.ContainsKey("Eras"))
            {
                Eras_Renamed = resource.GetStringArray("Eras");
            }
            else if (resource.ContainsKey("long.Eras"))
            {
                Eras_Renamed = resource.GetStringArray("long.Eras");
            }
            else if (resource.ContainsKey("short.Eras"))
            {
                Eras_Renamed = resource.GetStringArray("short.Eras");
            }
            Months_Renamed      = resource.GetStringArray("MonthNames");
            ShortMonths_Renamed = resource.GetStringArray("MonthAbbreviations");
            Ampms = resource.GetStringArray("AmPmMarkers");
            LocalPatternChars_Renamed = resource.GetString("DateTimePatternChars");

            // Day of week names are stored in a 1-based array.
            Weekdays_Renamed      = ToOneBasedArray(resource.GetStringArray("DayNames"));
            ShortWeekdays_Renamed = ToOneBasedArray(resource.GetStringArray("DayAbbreviations"));

            // Put a clone in the cache
            @ref = new SoftReference <>((DateFormatSymbols)this.Clone());
            SoftReference <DateFormatSymbols> x = CachedInstances.PutIfAbsent(Locale, @ref);

            if (x != null)
            {
                DateFormatSymbols y = x.get();
                if (y == null)
                {
                    // Replace the empty SoftReference with ref.
                    CachedInstances[Locale] = @ref;
                }
            }
        }
Ejemplo n.º 5
0
 //public override string GetLocalizedMessage()
 public string GetLocalizedMessage()
 {
     return(bundle.GetString(key.ToString()));
 }
Ejemplo n.º 6
0
 public BusinessException(string message, Object[] parameters, ResourceBundle bundle) : base(
         bundle.GetString(message, parameters))
 {
 }
Ejemplo n.º 7
0
 public BusinessException(string message, ResourceBundle bundle) : base(
         bundle.GetString(message))
 {
 }