Return-Path: X-Original-To: apmail-ambari-commits-archive@www.apache.org Delivered-To: apmail-ambari-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 29F6F195EB for ; Mon, 11 Apr 2016 16:14:16 +0000 (UTC) Received: (qmail 98479 invoked by uid 500); 11 Apr 2016 16:14:16 -0000 Delivered-To: apmail-ambari-commits-archive@ambari.apache.org Received: (qmail 98391 invoked by uid 500); 11 Apr 2016 16:14:16 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 98098 invoked by uid 99); 11 Apr 2016 16:14:15 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Apr 2016 16:14:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BCCE3E78B2; Mon, 11 Apr 2016 16:14:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: oleewere@apache.org To: commits@ambari.apache.org Date: Mon, 11 Apr 2016 16:14:24 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [10/51] [partial] ambari git commit: AMBARI-15679. Initial commit for LogSearch module (oleewre) http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/examples/browser/jquery.tmpl.js ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/examples/browser/jquery.tmpl.js b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/examples/browser/jquery.tmpl.js new file mode 100644 index 0000000..f731a32 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/examples/browser/jquery.tmpl.js @@ -0,0 +1,131 @@ +/* + * jQuery Templating Plugin + * NOTE: Created for demonstration purposes. + * Copyright 2010, John Resig + * Dual licensed under the MIT or GPL Version 2 licenses. + */ +(function(jQuery){ + // Override the DOM manipulation function + var oldManip = jQuery.fn.domManip; + + jQuery.fn.extend({ + render: function( data ) { + return this.map(function(i, tmpl){ + return jQuery.render( tmpl, data ); + }); + }, + + // This will allow us to do: .append( "template", dataObject ) + domManip: function( args ) { + // This appears to be a bug in the appendTo, etc. implementation + // it should be doing .call() instead of .apply(). See #6227 + if ( args.length > 1 && args[0].nodeType ) { + arguments[0] = [ jQuery.makeArray(args) ]; + } + + if ( args.length === 2 && typeof args[0] === "string" && typeof args[1] !== "string" ) { + arguments[0] = [ jQuery.render( args[0], args[1] ) ]; + } + + return oldManip.apply( this, arguments ); + } + }); + + jQuery.extend({ + render: function( tmpl, data ) { + var fn; + + // Use a pre-defined template, if available + if ( jQuery.templates[ tmpl ] ) { + fn = jQuery.templates[ tmpl ]; + + // We're pulling from a script node + } else if ( tmpl.nodeType ) { + var node = tmpl, elemData = jQuery.data( node ); + fn = elemData.tmpl || jQuery.tmpl( node.innerHTML ); + } + + fn = fn || jQuery.tmpl( tmpl ); + + // We assume that if the template string is being passed directly + // in the user doesn't want it cached. They can stick it in + // jQuery.templates to cache it. + + if ( jQuery.isArray( data ) ) { + return jQuery.map( data, function( data, i ) { + return fn.call( data, jQuery, data, i ); + }); + + } else { + return fn.call( data, jQuery, data, 0 ); + } + }, + + // You can stick pre-built template functions here + templates: {}, + + /* + * For example, someone could do: + * jQuery.templates.foo = jQuery.tmpl("some long templating string"); + * $("#test").append("foo", data); + */ + + tmplcmd: { + each: { + _default: [ null, "$i" ], + prefix: "jQuery.each($1,function($2){with(this){", + suffix: "}});" + }, + "if": { + prefix: "if($1){", + suffix: "}" + }, + "else": { + prefix: "}else{" + }, + html: { + prefix: "_.push(typeof $1==='function'?$1.call(this):$1);" + }, + "=": { + _default: [ "this" ], + prefix: "_.push($.encode(typeof $1==='function'?$1.call(this):$1));" + } + }, + + encode: function( text ) { + return text != null ? document.createTextNode( text.toString() ).nodeValue : ""; + }, + + tmpl: function(str, data, i) { + // Generate a reusable function that will serve as a template + // generator (and which will be cached). + var fn = new Function("jQuery","$data","$i", + "var $=jQuery,_=[];_.data=$data;_.index=$i;" + + + // Introduce the data as local variables using with(){} + "with($data){_.push('" + + + // Convert the template into pure JavaScript + str + .replace(/[\r\t\n]/g, " ") + .replace(/\${([^}]*)}/g, "{{= $1}}") + .replace(/{{(\/?)(\w+|.)(?:\((.*?)\))?(?: (.*?))?}}/g, function(all, slash, type, fnargs, args) { + var tmpl = jQuery.tmplcmd[ type ]; + + if ( !tmpl ) { + throw "Template not found: " + type; + } + + var def = tmpl._default; + + return "');" + tmpl[slash ? "suffix" : "prefix"] + .split("$1").join(args || (def?def[0]:null)) + .split("$2").join(fnargs || (def?def[1]:null)) + "_.push('"; + }) + + "');}return $(_.join('')).get();"); + + // Provide some basic currying to the user + return data ? fn.call( this, jQuery, data, i ) : fn; + } + }); +})(jQuery); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/HijriCalendar.js ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/HijriCalendar.js b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/HijriCalendar.js new file mode 100644 index 0000000..461833b --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/HijriCalendar.js @@ -0,0 +1,70 @@ + // Adapted to Script from System.Globalization.HijriCalendar + ticks1970: 62135596800000, + // number of days leading up to each month + monthDays: [0, 30, 59, 89, 118, 148, 177, 207, 236, 266, 295, 325, 355], + minDate: -42521673600000, + maxDate: 253402300799999, + // The number of days to add or subtract from the calendar to accommodate the variances + // in the start and the end of Ramadan and to accommodate the date difference between + // countries/regions. May be dynamically adjusted based on user preference, but should + // remain in the range of -2 to 2, inclusive. + hijriAdjustment: %HIJRIADJUSTMENT%, + toGregorian: function(hyear, hmonth, hday) { + var daysSinceJan0101 = this.daysToYear(hyear) + this.monthDays[hmonth] + hday - 1 - this.hijriAdjustment; + // 86400000 = ticks per day + var gdate = new Date(daysSinceJan0101 * 86400000 - this.ticks1970); + // adjust for timezone, because we are interested in the gregorian date for the same timezone + // but ticks in javascript is always from GMT, unlike the server were ticks counts from the base + // date in the current timezone. + gdate.setMinutes(gdate.getMinutes() + gdate.getTimezoneOffset()); + return gdate; + }, + fromGregorian: function(gdate) { + if ((gdate < this.minDate) || (gdate > this.maxDate)) return null; + var ticks = this.ticks1970 + (gdate-0) - gdate.getTimezoneOffset() * 60000, + daysSinceJan0101 = Math.floor(ticks / 86400000) + 1 + this.hijriAdjustment; + // very particular formula determined by someone smart, adapted from the server-side implementation. + // it approximates the hijri year. + var hday, hmonth, hyear = Math.floor(((daysSinceJan0101 - 227013) * 30) / 10631) + 1, + absDays = this.daysToYear(hyear), + daysInYear = this.isLeapYear(hyear) ? 355 : 354; + // hyear is just approximate, it may need adjustment up or down by 1. + if (daysSinceJan0101 < absDays) { + hyear--; + absDays -= daysInYear; + } + else if (daysSinceJan0101 === absDays) { + hyear--; + absDays = this.daysToYear(hyear); + } + else { + if (daysSinceJan0101 > (absDays + daysInYear)) { + absDays += daysInYear; + hyear++; + } + } + // determine month by looking at how many days into the hyear we are + // monthDays contains the number of days up to each month. + hmonth = 0; + var daysIntoYear = daysSinceJan0101 - absDays; + while (hmonth <= 11 && daysIntoYear > this.monthDays[hmonth]) { + hmonth++; + } + hmonth--; + hday = daysIntoYear - this.monthDays[hmonth]; + return [hyear, hmonth, hday]; + }, + daysToYear: function(year) { + // calculates how many days since Jan 1, 0001 + var yearsToYear30 = Math.floor((year - 1) / 30) * 30, + yearsInto30 = year - yearsToYear30 - 1, + days = Math.floor((yearsToYear30 * 10631) / 30) + 227013; + while (yearsInto30 > 0) { + days += (this.isLeapYear(yearsInto30) ? 355 : 354); + yearsInto30--; + } + return days; + }, + isLeapYear: function(year) { + return ((((year * 11) + 14) % 30) < 11); + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/Program.cs ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/Program.cs b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/Program.cs new file mode 100644 index 0000000..890fbb9 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/Program.cs @@ -0,0 +1,672 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using System.Globalization; +using System.Web.Script.Serialization; +using System.Collections.Specialized; +using System.Collections; +using System.Text.RegularExpressions; +using System.Reflection; +using System.Diagnostics; +using Globalization; + +namespace Globalization { + public class GlobalizationInfo { + public string name = ""; + public string englishName; + public string nativeName; + public string language; + public bool isRTL; + public NumberFormatInfo numberFormat; + public Dictionary calendars; + private CultureInfo culture; + public static Dictionary BasisGlobInfo; + + + private static string[] _numberNegativePatterns = "(n)|-n|- n|n-|n -".Split('|'); + private static string[] _currencyNegativePatterns = "($n)|-$n|$-n|$n-|(n$)|-n$|n-$|n$-|-n $|-$ n|n $-|$ n-|$ -n|n- $|($ n)|(n $)".Split('|'); + private static string[] _percentNegativePatterns = "-n %|-n%|-%n|%-n|%n-|n-%|n%-|-% n|n %-|% n-|% -n|n- %".Split('|'); + private static string[] _currencyPositivePatterns = "$n|n$|$ n|n $".Split('|'); + private static string[] _percentPositivePatterns = "n %|n%|%n|% n".Split('|'); + + public static GlobalizationInfo GetGlobInfo(CultureInfo culture) { + var info = new GlobalizationInfo { + culture = culture, + language = (culture == CultureInfo.InvariantCulture || culture.IsNeutralCulture) ? culture.Name : culture.Parent.Name, + name = String.IsNullOrEmpty(culture.Name) ? "invariant" : culture.Name, + englishName = String.IsNullOrEmpty(culture.Name) ? "invariant" : culture.EnglishName, + nativeName = String.IsNullOrEmpty(culture.Name) ? "invariant" : culture.NativeName, + isRTL = culture.TextInfo.IsRightToLeft, + numberFormat = GetNumberFormatInfo(culture), + calendars = GetCalendars(culture) + }; + return info; + } + + public static Dictionary GetCalendars(CultureInfo culture) { + var calendars = new Dictionary(); + bool foundStandard = false; + var gregorianType = typeof(GregorianCalendar); + var defaultCalendar = culture.DateTimeFormat.Calendar; + var defaultCalendarType = defaultCalendar.GetType(); + GregorianCalendarTypes? gregorianCalendarType = null; + if (defaultCalendarType == gregorianType) { + gregorianCalendarType = ((GregorianCalendar)defaultCalendar).CalendarType; + } + var optionalCalendars = culture.OptionalCalendars; + foreach (var calendar in optionalCalendars) { + var type = calendar.GetType(); + string name; + bool isStandard = false; + if (type == gregorianType) { + var calendarType = ((GregorianCalendar)calendar).CalendarType; + if (calendarType == GregorianCalendarTypes.USEnglish) { + // we include the Gregorian_USEnglish culture as part of the built-in 'en' culture + // because it is so common -- it is an optional calendar of every single english + // speaking culture. So, skip it when found for any other culture. + continue; + } + else if (culture == CultureInfo.InvariantCulture) { + // invariant has one calendar, Gregorian_Localized, which is identical + // to Gregorian_USEnglish. + name = " Gregorian_USEnglish"; + } + else { + name = "Gregorian_" + calendarType.ToString(); + } + if (!foundStandard && gregorianCalendarType.HasValue && gregorianCalendarType == gregorianCalendarType.Value) { + isStandard = true; + foundStandard = true; + } + } + else { + name = type.Name.Replace("Calendar", ""); + if (!foundStandard) { + isStandard = true; + foundStandard = true; + } + } + string key = name; + if (isStandard) { + key = "standard"; + } + if (culture != CultureInfo.InvariantCulture) { + culture.DateTimeFormat.Calendar = calendar; + } + var calendarInfo = GetDateTimeFormatInfo(culture, name); + calendars.Add(key, calendarInfo); + } + if (!foundStandard) { + throw new ApplicationException("Could not locate the standard calendar type for culture '" + culture.Name + "'."); + } + return calendars; + } + + public static GlobalizationInfo.NumberFormatInfo GetNumberFormatInfo(CultureInfo culture) { + var nf = culture.NumberFormat; + return new GlobalizationInfo.NumberFormatInfo { + decimals = nf.NumberDecimalDigits, + decimalSeparator = nf.NumberDecimalSeparator, + groupSeparator = nf.NumberGroupSeparator, + groupSizes = nf.NumberGroupSizes, + NaN = nf.NaNSymbol, + negative = nf.NegativeSign, + negativeInfinity = nf.NegativeInfinitySymbol, + positive = nf.PositiveSign, + positiveInfinity = nf.PositiveInfinitySymbol, + pattern = new string[] { GetFromStringList(_numberNegativePatterns, nf.NumberNegativePattern) }, + currency = new GlobalizationInfo.NumberFormatInfo.NumberClassFormatInfo { + decimals = nf.CurrencyDecimalDigits, + decimalSeparator = nf.CurrencyDecimalSeparator, + groupSeparator = nf.CurrencyGroupSeparator, + groupSizes = nf.CurrencyGroupSizes, + pattern = new string[] { + GetFromStringList(_currencyNegativePatterns, nf.CurrencyNegativePattern), + GetFromStringList(_currencyPositivePatterns, nf.CurrencyPositivePattern) + }, + symbol = nf.CurrencySymbol + }, + percent = new GlobalizationInfo.NumberFormatInfo.NumberClassFormatInfo { + decimals = nf.PercentDecimalDigits, + decimalSeparator = nf.PercentDecimalSeparator, + groupSeparator = nf.PercentGroupSeparator, + groupSizes = nf.PercentGroupSizes, + pattern = new string[] { + GetFromStringList(_percentNegativePatterns, nf.PercentNegativePattern), + GetFromStringList(_percentPositivePatterns, nf.PercentPositivePattern) + }, + symbol = nf.PercentSymbol + } + }; + } + + public static string[] GetAMPMDesignators(CultureInfo culture, string ampm) { + return String.IsNullOrEmpty(ampm) ? null : new string[] { ampm, culture.TextInfo.ToLower(ampm), culture.TextInfo.ToUpper(ampm) }; + } + + public static GlobalizationInfo.DateFormatInfo GetDateTimeFormatInfo(CultureInfo culture, string calendarName) { + var df = culture.DateTimeFormat; + var info = new GlobalizationInfo.DateFormatInfo { + name = calendarName, + months = new DateFormatInfo.MonthInfo { names = df.MonthNames, namesAbbr = df.AbbreviatedMonthNames }, + monthsGenitive = new DateFormatInfo.MonthInfo { names = df.MonthGenitiveNames, namesAbbr = df.AbbreviatedMonthGenitiveNames }, + firstDay = (int) df.FirstDayOfWeek, + dateSeparator = df.DateSeparator, + timeSeparator = df.TimeSeparator, + days = new DateFormatInfo.DayInfo { names = df.DayNames, namesAbbr = df.AbbreviatedDayNames, namesShort = df.ShortestDayNames }, + eras = GetEraInfo(culture), + twoDigitYearMax = df.Calendar.TwoDigitYearMax, + patterns = GetPatterns(df) + }; + info.AM = GetAMPMDesignators(culture, df.AMDesignator); + info.PM = GetAMPMDesignators(culture, df.PMDesignator); + if (df.Calendar != null) { + var type = df.Calendar.GetType(); + if (type == typeof(HijriCalendar)) { + string convert; + using (var sr = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Generator.HijriCalendar.js"))) { + convert = sr.ReadToEnd(); + } + int adjustment = ((HijriCalendar)df.Calendar).HijriAdjustment; + convert = convert.Replace("%HIJRIADJUSTMENT%", adjustment.ToString(CultureInfo.InvariantCulture)); + info.convertScriptBlock = convert; + } + else if (type == typeof(UmAlQuraCalendar)) { + using (var sr = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Generator.UmAlQuraCalendar.js"))) { + info.convertScriptBlock = sr.ReadToEnd(); + } + } + } + return info; + } + + private static GlobalizationInfo.DateFormatInfo.EraInfo[] GetEraInfo(CultureInfo culture) { + Calendar cal = culture.DateTimeFormat.Calendar; + List eras = null; + if (cal != null) { + eras = new List(); + foreach (var eraNum in cal.Eras) { + eras.Add(GetEraInfo(culture, eraNum)); + } + } + return eras == null ? null : eras.ToArray(); + } + + private static GlobalizationInfo.DateFormatInfo.EraInfo GetEraInfo(CultureInfo culture, int eraNum) { + var era = new GlobalizationInfo.DateFormatInfo.EraInfo { + name = culture.DateTimeFormat.GetEraName(eraNum), + offset = 0, + start = null + }; + var calendar = culture.DateTimeFormat.Calendar; + + Type type = calendar.GetType(); + if (type != typeof(GregorianCalendar)) { + if (type == typeof(TaiwanCalendar)) { + era.offset = 0x777; + } + else if (type == typeof(KoreanCalendar)) { + era.offset = -2333; + } + else if (type == typeof(ThaiBuddhistCalendar)) { + era.offset = -543; + } + else if (type == typeof(JapaneseCalendar)) { + switch (eraNum) { + case 1: + era.start = 0xdf9984200L; + era.offset = 0x7c4; + break; + case 2: + era.start = -1357603200000L; + era.offset = 0x785; + break; + case 3: + era.start = -1812153600000L; + era.offset = 0x777; + break; + case 4: + era.start = null; + era.offset = 0x74b; + break; + default: + throw new InvalidOperationException("Invalid era number for JapaneseCalendar: " + eraNum.ToString()); + } + } + } + return era; + } + + private static Dictionary GetPatterns(DateTimeFormatInfo df) { + var patterns = new Dictionary { + { "d", df.ShortDatePattern }, + { "D", df.LongDatePattern }, + { "t", df.ShortTimePattern }, + { "T", df.LongTimePattern }, + { "f", df.LongDatePattern + " " + df.ShortTimePattern }, + { "F", df.FullDateTimePattern }, + { "M", df.MonthDayPattern }, + { "S", df.SortableDateTimePattern }, + { "Y", df.YearMonthPattern } + }; + return patterns; + } + + private static bool ArrayEquality(Array arr1, Array arr2) { + if (arr1.Length == arr2.Length) { + for (int i = 0; i < arr1.Length; i++) { + if (!arr1.GetValue(i).Equals(arr2.GetValue(i))) { + return false; + } + } + return true; + } + return false; + } + + private static bool ListEquality(IList arr1, IList arr2) { + if (arr1.Count == arr2.Count) { + for (int i = 0; i < arr1.Count; i++) { + var val1 = arr1[i]; + var val2 = arr2[i]; + if (val1 == null || !val1.Equals(val2)) { + if (val1 is IList && val2 is IList) { + if (!ListEquality(val1 as IList, val2 as IList)) { + return false; + } + } + else if (val1 is Dictionary && val2 is Dictionary) { + var diff = DiffGlobInfos((Dictionary)val1, (Dictionary)val2); + if (diff.Count > 0) { + return false; + } + } + else { + return false; + } + } + } + return true; + } + return false; + } + + private static string GetFromStringList(string[] list, int value) { + return value < list.Length ? list[value] : null; + } + + public Dictionary ToDictionary(bool diffCalendars) { + var jss = new JavaScriptSerializer(); + var str = jss.Serialize(this); + var dictionary = jss.Deserialize>(str); + var cals = (Dictionary) dictionary["calendars"]; + Dictionary basisStandardCal = null; + if (GlobalizationInfo.BasisGlobInfo != null) { + basisStandardCal = (Dictionary)((Dictionary)GlobalizationInfo.BasisGlobInfo["calendars"])["standard"]; + foreach (var pair in this.calendars) { + var cal = (Dictionary)cals[pair.Key]; + if (diffCalendars) { + // make each calendar a diff from the standard basis calendar + cals[pair.Key] = cal = DiffGlobInfos(basisStandardCal, cal); + } + // apply convert script if it exists + if (!String.IsNullOrEmpty(pair.Value.convertScriptBlock)) { + cal["convert"] = pair.Value.convertScriptBlock; + } + // remove redundant monthsGenitive array if it is equivilent to months + Dictionary months = cal.ContainsKey("months") ? (Dictionary)cal["months"] : null; + Dictionary monthsGenitive = cal.ContainsKey("monthsGenitive") ? (Dictionary)cal["monthsGenitive"] : null; + Dictionary diff = (months != null && monthsGenitive != null) ? DiffGlobInfos(months, monthsGenitive) : null; + if (diff != null && diff.Count == 0) { + // the genitive months are the same as months, so remove it since it's optional + cal.Remove("monthsGenitive"); + } + } + } + return dictionary; + } + + public static string GenerateJavaScript(string extend, string global, CultureInfo culture, string name, Dictionary dictionary, StringBuilder aggregateScript) { + string cultureFragment = ToJavaScript(extend, culture, dictionary, 1, false); + + if (aggregateScript != null) { + aggregateScript.AppendFormat(CultureInfo.InvariantCulture, @" +Globalize.addCultureInfo( ""{0}"", ""default"", {{ +{1} +}}); +", name, cultureFragment, extend); + } + + return string.Format(CultureInfo.InvariantCulture, @"/* + * Globalize Culture {0} + * + * http://github.com/jquery/globalize + * + * Copyright Software Freedom Conservancy, Inc. + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * This file was generated by the Globalize Culture Generator + * Translation: bugs found in this file need to be fixed in the generator + */ + +(function( window, undefined ) {{ + +var Globalize; + +if ( typeof require !== ""undefined"" && + typeof exports !== ""undefined"" && + typeof module !== ""undefined"" ) {{ + // Assume CommonJS + Globalize = require( ""globalize"" ); +}} else {{ + // Global variable + Globalize = window.Globalize; +}} + +Globalize.addCultureInfo( ""{0}"", ""default"", {{ +{1} +}}); + +}}( this )); +", name, cultureFragment); + } + + private static string Serialize(object value) { + // no need to escape single quotes + return _jss.Serialize(value).Replace("\\u0027", "'") + // Unsafe Characters + // There are characters that are handled inconsistently in browsers, and so must be escaped when placed in strings. + // http://www.jslint.com/lint.html#unsafe + .Replace("\xad", "\\xad") + .Replace("\u070f", "\\u070f") + .Replace("\u200c", "\\u200c") + .Replace("\u200d", "\\u200d") + .Replace("\u200f", "\\u200f") + .Replace("\u202f", "\\u202f"); + } + + private static string ToJavaScript(string extend, CultureInfo culture, Dictionary dictionary, int level, bool isCalendars) { + StringBuilder sb = new StringBuilder(); + string padding = _padding.Substring(0, level); + bool first = true; + foreach (var pair in dictionary) { + if (!first) { + sb.Append(",\n"); + } + first = false; + if (pair.Value is Dictionary) { + sb.AppendFormat("{0}{1}: {{\n{2}\n{0}}}", padding, pair.Key, ToJavaScript(extend, culture, (Dictionary)pair.Value, level + 1, pair.Key.Equals("calendars"))); + } + else if (pair.Key.Equals("convert")) { + sb.AppendFormat("{0}convert: {{\n{1}\n{0}}}", padding, pair.Value); + } + else if (pair.Key.Equals("groupSeparator")) { + sb.AppendFormat("{0}\",\": {1}", padding, Serialize(pair.Value)); + } + else if (pair.Key.Equals("decimalSeparator")) { + sb.AppendFormat("{0}\".\": {1}", padding, Serialize(pair.Value)); + } + else if (pair.Key.Equals("positive")) { + sb.AppendFormat("{0}\"+\": {1}", padding, Serialize(pair.Value)); + } + else if (pair.Key.Equals("negative")) { + sb.AppendFormat("{0}\"-\": {1}", padding, Serialize(pair.Value)); + } + else if (pair.Key.Equals("dateSeparator")) { + sb.AppendFormat("{0}\"/\": {1}", padding, Serialize(pair.Value)); + } + else if (pair.Key.Equals("timeSeparator")) { + sb.AppendFormat("{0}\":\": {1}", padding, Serialize(pair.Value)); + } + else if (pair.Key.Equals("NaN")) { + sb.AppendFormat("{0}\"NaN\": {1}", padding, Serialize(pair.Value)); + } + else { + sb.AppendFormat("{0}{1}: {2}", padding, pair.Key, Serialize(pair.Value)); + } + } + return sb.ToString(); + } + + private static JavaScriptSerializer _jss = new JavaScriptSerializer(); + private static string _padding = " "; + + private static Dictionary ToDictionary(IEnumerable> pairs) { + var d = new Dictionary(); + foreach (var pair in pairs) { + d.Add(pair.Key, pair.Value); + } + return d; + } + + public static Dictionary DiffGlobInfos(Dictionary glob1, Dictionary glob2) { + var unique = new Dictionary(); + var comparer = new KeyValueComparer(); + + var diff = ToDictionary(glob2.Except(glob1, comparer)); + foreach (var pair in glob2) { + if (diff.ContainsKey(pair.Key) && pair.Value != null) { + if (pair.Value is Dictionary) { + var subdiff = glob1.ContainsKey(pair.Key) ? DiffGlobInfos((Dictionary)glob1[pair.Key], (Dictionary)pair.Value) : (Dictionary)pair.Value; + if (subdiff.Count > 0) { + //Debug.WriteLine("Replacing\n {0}\nwith\n {1}", _jss.Serialize(diff[pair.Key]), _jss.Serialize(subdiff)); + diff[pair.Key] = subdiff; + } + else { + //Debug.WriteLine("\nRemoving {0}\n", _jss.Serialize(pair.Key)); + diff.Remove(pair.Key); + } + } + else if (pair.Value is IList) { + if (glob1.ContainsKey(pair.Key) && ListEquality((IList)pair.Value, (IList)glob1[pair.Key])) { + diff.Remove(pair.Key); + } + } + } + } + + return diff; + } + + public class KeyValueComparer : IEqualityComparer> { + public bool Equals(KeyValuePair x, KeyValuePair y) { + if (x.Key.Equals(y.Key)) { + if ((x.Value == null && y.Value == null) || (x.Value != null && x.Value.Equals(y.Value))) { + return true; + } + else if (x.Value is ArrayList && y.Value is ArrayList) { + return ListEquality((IList)x.Value, (IList)y.Value); + } + else if (x.Value is Array && y.Value is Array) { + return ArrayEquality(x.Value as Array, y.Value as Array); + } + else if (x.Value is Dictionary && y.Value is Dictionary) { + var diff = DiffGlobInfos((Dictionary)x.Value, (Dictionary)y.Value); + if (diff.Count == 0) { + return true; + } + //else { + // Debug.WriteLine(" Dictionaries diff:\n {0}\n {1}", _jss.Serialize(x.Value), _jss.Serialize(y.Value)); + //} + } + } + //Debug.WriteLine(" Diff found: {0}={1}, {2}={3}", x.Key, x.Value, y.Key, y.Value); + return false; + } + + public int GetHashCode(KeyValuePair obj) { + return obj.GetHashCode(); + } + } + + public class NumberFormatInfo { + public string[] pattern; + public int decimals; + public string groupSeparator; + public string decimalSeparator; + public int[] groupSizes; + public string NaN; + public string negative; + public string negativeInfinity; + public string positive; + public string positiveInfinity; + public NumberClassFormatInfo percent; + public NumberClassFormatInfo currency; + + public class NumberClassFormatInfo { + public string[] pattern; + public int decimals; + public int[] groupSizes; + public string groupSeparator; + public string decimalSeparator; + public string symbol; + } + } + + public class DateFormatInfo { + public string name; + public string dateSeparator; + public string timeSeparator; + public int firstDay; + public DayInfo days; + public MonthInfo months; + public MonthInfo monthsGenitive; + public string[] AM; + public string[] PM; + public EraInfo[] eras; + public int twoDigitYearMax; + public Dictionary patterns; + internal string convertScriptBlock; + + public class EraInfo { + public string name; + public long? start; + public long offset; + } + + public class MonthInfo { + public string[] names; + public string[] namesAbbr; + } + + public class DayInfo { + public string[] names; + public string[] namesAbbr; + public string[] namesShort; + } + } + + } + + public class Program { + + private static void WriteCulture(string outputdir, string fileName, string extend, string global, CultureInfo culture, StringBuilder aggregateScript) { + var globInfo = GlobalizationInfo.GetGlobInfo(culture); + var diff = (String.IsNullOrEmpty(extend) || culture == CultureInfo.InvariantCulture || culture.Name.Equals("en")) ? globInfo.ToDictionary(false) : GlobalizationInfo.DiffGlobInfos(GlobalizationInfo.BasisGlobInfo, globInfo.ToDictionary(true)); + + // Fix for Issue #31 - en-US 'englishName' is wrong + // Special case diff of englishName for en-US. The generator diff seemingly finds both "en" and "en-US" to + // have englishName "English (United States)" but globalize.js (correctly) has the neutral "English" for "en"/"default" + if (culture.Name.Equals("en-US")) { + diff.Add("name", globInfo.name); + diff.Add("englishName", globInfo.englishName); + } + + var script = GlobalizationInfo.GenerateJavaScript(extend, global, culture, culture.Name, diff, aggregateScript); + var filePath = Path.Combine(outputdir, String.Format(fileName, (String.IsNullOrEmpty(culture.Name) ? "invariant" : culture.Name))); + + File.WriteAllText(filePath, script); + Console.WriteLine(filePath); + } + + [STAThread] + static void Main(string[] args) { + string outputdir = "lib\\cultures"; + string extend = "extend"; + string global = "Globalization"; + string fileName = "globalize.culture.{0}.js"; + string aggregateFileName = "globalize.cultures.js"; + foreach (string param in string.Join(" ", args).SplitCommandLine()) { + if (param.StartsWith("/o:")) { + outputdir = param.Substring("/o:".Length); + } + else if (param == "/?") { + Console.Write(@" +Usage:glob-generator [] + +options: + + /o: The directory to put the culture scripts into. The directory will be + created if it does not exist. Existing scripts there will be + overwritten if necessary. + default: ""lib\cultures"" + +"); + return; + } + } + Directory.CreateDirectory(outputdir); + GlobalizationInfo.BasisGlobInfo = GlobalizationInfo.GetGlobInfo(CultureInfo.CreateSpecificCulture("en")).ToDictionary(false); + + StringBuilder aggregateScript = new StringBuilder(); + +/* + +Globalize.addCultureInfo( ""{0}"", ""default"", {{ +{1} +}}); + +}}( this )); +" +*/ + + aggregateScript.Append( + @"/* + * Globalize Cultures + * + * http://github.com/jquery/globalize + * + * Copyright Software Freedom Conservancy, Inc. + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * This file was generated by the Globalize Culture Generator + * Translation: bugs found in this file need to be fixed in the generator + */ + +(function( window, undefined ) { + +var Globalize; + +if ( typeof require !== ""undefined"" && + typeof exports !== ""undefined"" && + typeof module !== ""undefined"" ) { + // Assume CommonJS + Globalize = require( ""globalize"" ); +} else { + // Global variable + Globalize = window.Globalize; +} +"); + + int count = 0; + foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures)) { + if (!String.IsNullOrEmpty(culture.Name) && culture != CultureInfo.InvariantCulture && culture.Name != "en") { + WriteCulture(outputdir, fileName, extend, global, culture, aggregateScript); + count++; + } + } + + aggregateScript.Append("\r\n}( this ));\r\n"); + string aggregateScriptString = aggregateScript.ToString(); + string aggregatePath = Path.Combine(outputdir, aggregateFileName); + File.WriteAllText(aggregatePath, aggregateScriptString); + Console.WriteLine(aggregatePath); + + Console.WriteLine("Done! Generated scripts for a total of {0} cultures, and 1 aggregate script.", count); + } + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/Properties/AssemblyInfo.cs ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/Properties/AssemblyInfo.cs b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..36a678f --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("GlobalizationCultures")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("jQuery")] +[assembly: AssemblyProduct("GlobalizeCultureGenerator")] +[assembly: AssemblyCopyright("Copyright Software Freedom Conservancy, Inc.")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d485ddf1-b620-429a-bc9e-619e9aa5edc4")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/StringExt.cs ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/StringExt.cs b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/StringExt.cs new file mode 100644 index 0000000..4fa450b --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/StringExt.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Globalization; + +namespace Globalization { + public static class StringExtensions { + public static IEnumerable Split(this string str, Func controller) { + int nextPiece = 0; + + for (int c = 0; c < str.Length; c++) { + if (controller(str[c])) { + yield return str.Substring(nextPiece, c - nextPiece); + nextPiece = c + 1; + } + } + + yield return str.Substring(nextPiece); + } + + public static string TrimMatchingQuotes(this string input, char quote) { + if ((input.Length >= 2) && + (input[0] == quote) && (input[input.Length - 1] == quote)) + return input.Substring(1, input.Length - 2); + + return input; + } + + public static IEnumerable SplitCommandLine(this string commandLine) { + bool inQuotes = false; + + return commandLine.Split(c => { + if (c == '\"') + inQuotes = !inQuotes; + + return !inQuotes && c == ' '; + }).Select(arg => arg.Trim().TrimMatchingQuotes('\"')) + .Where(arg => !string.IsNullOrEmpty(arg)); + } + + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/UmAlQuraCalendar.js ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/UmAlQuraCalendar.js b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/UmAlQuraCalendar.js new file mode 100644 index 0000000..7dc25ee --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/UmAlQuraCalendar.js @@ -0,0 +1,190 @@ + _yearInfo: [ + // MonthLengthFlags, Gregorian Date + [746, -2198707200000], + [1769, -2168121600000], + [3794, -2137449600000], + [3748, -2106777600000], + [3402, -2076192000000], + [2710, -2045606400000], + [1334, -2015020800000], + [2741, -1984435200000], + [3498, -1953763200000], + [2980, -1923091200000], + [2889, -1892505600000], + [2707, -1861920000000], + [1323, -1831334400000], + [2647, -1800748800000], + [1206, -1770076800000], + [2741, -1739491200000], + [1450, -1708819200000], + [3413, -1678233600000], + [3370, -1647561600000], + [2646, -1616976000000], + [1198, -1586390400000], + [2397, -1555804800000], + [748, -1525132800000], + [1749, -1494547200000], + [1706, -1463875200000], + [1365, -1433289600000], + [1195, -1402704000000], + [2395, -1372118400000], + [698, -1341446400000], + [1397, -1310860800000], + [2994, -1280188800000], + [1892, -1249516800000], + [1865, -1218931200000], + [1621, -1188345600000], + [683, -1157760000000], + [1371, -1127174400000], + [2778, -1096502400000], + [1748, -1065830400000], + [3785, -1035244800000], + [3474, -1004572800000], + [3365, -973987200000], + [2637, -943401600000], + [685, -912816000000], + [1389, -882230400000], + [2922, -851558400000], + [2898, -820886400000], + [2725, -790300800000], + [2635, -759715200000], + [1175, -729129600000], + [2359, -698544000000], + [694, -667872000000], + [1397, -637286400000], + [3434, -606614400000], + [3410, -575942400000], + [2710, -545356800000], + [2349, -514771200000], + [605, -484185600000], + [1245, -453600000000], + [2778, -422928000000], + [1492, -392256000000], + [3497, -361670400000], + [3410, -330998400000], + [2730, -300412800000], + [1238, -269827200000], + [2486, -239241600000], + [884, -208569600000], + [1897, -177984000000], + [1874, -147312000000], + [1701, -116726400000], + [1355, -86140800000], + [2731, -55555200000], + [1370, -24883200000], + [2773, 5702400000], + [3538, 36374400000], + [3492, 67046400000], + [3401, 97632000000], + [2709, 128217600000], + [1325, 158803200000], + [2653, 189388800000], + [1370, 220060800000], + [2773, 250646400000], + [1706, 281318400000], + [1685, 311904000000], + [1323, 342489600000], + [2647, 373075200000], + [1198, 403747200000], + [2422, 434332800000], + [1388, 465004800000], + [2901, 495590400000], + [2730, 526262400000], + [2645, 556848000000], + [1197, 587433600000], + [2397, 618019200000], + [730, 648691200000], + [1497, 679276800000], + [3506, 709948800000], + [2980, 740620800000], + [2890, 771206400000], + [2645, 801792000000], + [693, 832377600000], + [1397, 862963200000], + [2922, 893635200000], + [3026, 924307200000], + [3012, 954979200000], + [2953, 985564800000], + [2709, 1016150400000], + [1325, 1046736000000], + [1453, 1077321600000], + [2922, 1107993600000], + [1748, 1138665600000], + [3529, 1169251200000], + [3474, 1199923200000], + [2726, 1230508800000], + [2390, 1261094400000], + [686, 1291680000000], + [1389, 1322265600000], + [874, 1352937600000], + [2901, 1383523200000], + [2730, 1414195200000], + [2381, 1444780800000], + [1181, 1475366400000], + [2397, 1505952000000], + [698, 1536624000000], + [1461, 1567209600000], + [1450, 1597881600000], + [3413, 1628467200000], + [2714, 1659139200000], + [2350, 1689724800000], + [622, 1720310400000], + [1373, 1750896000000], + [2778, 1781568000000], + [1748, 1812240000000], + [1701, 1842825600000], + [0, 1873411200000] + ], + minDate: -2198707200000, + maxDate: 1873411199999, + toGregorian: function(hyear, hmonth, hday) { + var days = hday - 1, + gyear = hyear - 1318; + if (gyear < 0 || gyear >= this._yearInfo.length) return null; + var info = this._yearInfo[gyear], + gdate = new Date(info[1]), + monthLength = info[0]; + // Date's ticks in javascript are always from the GMT time, + // but we are interested in the gregorian date in the same timezone, + // not what the gregorian date was at GMT time, so we adjust for the offset. + gdate.setMinutes(gdate.getMinutes() + gdate.getTimezoneOffset()); + for (var i = 0; i < hmonth; i++) { + days += 29 + (monthLength & 1); + monthLength = monthLength >> 1; + } + gdate.setDate(gdate.getDate() + days); + return gdate; + }, + fromGregorian: function(gdate) { + // Date's ticks in javascript are always from the GMT time, + // but we are interested in the hijri date in the same timezone, + // not what the hijri date was at GMT time, so we adjust for the offset. + var ticks = gdate - gdate.getTimezoneOffset() * 60000; + if (ticks < this.minDate || ticks > this.maxDate) return null; + var hyear = 0, + hmonth = 1; + // find the earliest gregorian date in the array that is greater than or equal to the given date + while (ticks > this._yearInfo[++hyear][1]) { } + if (ticks !== this._yearInfo[hyear][1]) { + hyear--; + } + var info = this._yearInfo[hyear], + // how many days has it been since the date we found in the array? + // 86400000 = ticks per day + days = Math.floor((ticks - info[1]) / 86400000), + monthLength = info[0]; + hyear += 1318; // the Nth array entry corresponds to hijri year 1318+N + // now increment day/month based on the total days, considering + // how many days are in each month. We cannot run past the year + // mark since we would have found a different array entry in that case. + var daysInMonth = 29 + (monthLength & 1); + while (days >= daysInMonth) { + days -= daysInMonth; + monthLength = monthLength >> 1; + daysInMonth = 29 + (monthLength & 1); + hmonth++; + } + // remaining days is less than is in one month, thus is the day of the month we landed on + // hmonth-1 because in javascript months are zero based, stay consistent with that. + return [hyear, hmonth - 1, days + 1]; + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/generator.csproj ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/generator.csproj b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/generator.csproj new file mode 100644 index 0000000..3c9f503 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/generator/generator.csproj @@ -0,0 +1,61 @@ + + + + Debug + x86 + {6EBDAB07-7C5E-4CF5-91CA-368ED36D6600} + Exe + false + generator + v4.0 + + + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + x86 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + x86 + + + Generator + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/39c85bb8/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/grunt.js ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/grunt.js b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/grunt.js new file mode 100644 index 0000000..4e82c73 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/bower/globalize/grunt.js @@ -0,0 +1,36 @@ +module.exports = function( grunt ) { + +grunt.initConfig({ + pkg: "", + meta: { + banner: "/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - " + + "<%= grunt.template.today('isoDate') %>\n" + + "<%= pkg.homepage ? '* ' + pkg.homepage + '\n' : '' %>" + + "* Copyright <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>;" + + " Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %> */" + }, + lint: { + files: [ "lib/globalize.js", "lib/cultures/*.js", "test/*.js" ] + }, + qunit: { + files: [ "test/*.html" ] + }, + watch: { + files: [ "", "test/*.html" ], + tasks: "lint qunit" + }, + jshint: { + options: { + eqnull: true + } + }, + min: { + "dist/globalize.min.js": [ "", "lib/globalize.js" ] + } +}); + +// Default task. +grunt.registerTask( "default", "lint qunit" ); + +} +