hydroponics 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog.markdown CHANGED
@@ -1,3 +1,9 @@
1
+ # Hydroponics 0.3.4
2
+
3
+ * Refactored templates into partials with a common layout in views/single
4
+ * now using ESAPI JavaScript XSS library
5
+ * Added ability to manually enter new row count in Dupe and ForeignDupe
6
+
1
7
  # hydroponics 0.3.3
2
8
 
3
9
  * Generalized the routes, so new actions can be added without changing them
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -0,0 +1,49 @@
1
+ <script type="text/javascript">
2
+ $(function(){
3
+ $("#slider div").slider({
4
+ slide: function(event, ui) {
5
+ $("#sliderct").val(ui.value);
6
+ },
7
+ change: function(event, ui) {
8
+ $("button").button("enable");
9
+ },
10
+ max: 25000,
11
+ value: j("<%= db[@table].count %>")
12
+ });
13
+
14
+ $("#sliderct").val(j("<%= db[@table].count %>"));
15
+ $("#sliderct").keyup(function() {
16
+ $("#slider div").slider("value", parseInt($("#sliderct").val()));
17
+ })
18
+
19
+ $("button").button();
20
+ $("button").button("enable");
21
+ $("button").click(function(){
22
+ $("#slider div").slider("disable");
23
+ $("button").button("disable");
24
+ $(".loader").show();
25
+ $.ajax({
26
+ type: "POST",
27
+ url: "/dupe/" + j("<%= @table %>"),
28
+ data: JSON.stringify({
29
+ count: parseInt($("#sliderct").val())
30
+ }),
31
+ success: function(data, status, xhr) {
32
+ $("#sliderct").val(j(data));
33
+ $("#slider div").slider("enable");
34
+ $(".loader").hide();
35
+ },
36
+ processData: false
37
+ });
38
+ });
39
+ });
40
+ </script>
41
+ <div class="dupecontainer">
42
+ <div class="dupe">
43
+ <h3>Dupe</h3>
44
+ <div id='slider'><div></div></div>
45
+ <div class="loader" style="display:none;"></div>
46
+ <div id='button'><button>Update</button></div>
47
+ <div class="count"><p><%= @table.to_s.gsub("_"," ") %>:</p> <input id='sliderct'></input></div>
48
+ </div>
49
+ </div>
@@ -0,0 +1,59 @@
1
+ <script type="text/javascript">
2
+ $(function(){
3
+ $("#slider div").slider({
4
+ slide: function(event, ui) {
5
+ $("#sliderct").val(ui.value);
6
+ },
7
+ change: function(event, ui) {
8
+ $("button").button("enable");
9
+ },
10
+ max: 25000,
11
+ value: j("<%= db[@table].count %>")
12
+ });
13
+
14
+
15
+ $("#sliderct").val(j("<%= db[@table].count %>"));
16
+ $("#sliderct").keyup(function() {
17
+ $("#slider div").slider("value", parseInt($("#sliderct").val()));
18
+ })
19
+
20
+ $("button").button();
21
+ $("button").button("enable");
22
+ $("button").click(function(){
23
+ $("#slider div").slider("disable");
24
+ $("button").button("disable");
25
+ $(".loader").show();
26
+
27
+ var postData = {
28
+ count: $("#slider div").slider("value"),
29
+ foreign_table: j("<%= params[:foreign_table] %>")
30
+ };
31
+ if($("#foreign_key").val() != "") {
32
+ postData.foreign_key = $("#foreign_key").val()
33
+ }
34
+
35
+ $.ajax({
36
+ type: "POST",
37
+ url: "/foreign_dupe/" + j("<%= @table %>"),
38
+ data: JSON.stringify(postData),
39
+ success: function(data, status, xhr) {
40
+ $("#sliderct").val(j(data));
41
+ $("#slider div").slider("enable");
42
+ $(".loader").hide();
43
+ },
44
+ processData: false
45
+ });
46
+ });
47
+ })
48
+ </script>
49
+
50
+ <div class="column dupecontainer span-10">
51
+ <div class="foreign-dupe">
52
+ <h3>Foreign Dupe</h3>
53
+ <div id='slider'><div></div></div>
54
+ <div class="loader" style="display:none;"></div>
55
+ <div id='button'><button>Update</button></div>
56
+ <input id='foreign_key'></input>
57
+ <div class="count"><p><%= @table.to_s.gsub("_"," ") %>:</p> <input id='sliderct'></input></div>
58
+ </div>
59
+ </div>
@@ -0,0 +1,31 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
4
+
5
+ <head>
6
+ <link href="../vendor/jquery-ui-1.8.5.custom/css/smoothness/jquery-ui-1.8.5.custom.css" media="screen" rel="stylesheet" type="text/css" />
7
+
8
+ <script type="text/javascript" src="../vendor/jquery-ui-1.8.5.custom/js/jquery-1.4.2.min.js"></script>
9
+ <script type="text/javascript" src="../vendor/jquery-ui-1.8.5.custom/js/jquery-ui-1.8.5.custom.min.js"></script>
10
+
11
+ <script type="text/javascript" src="../vendor/esapi4js/lib/log4js.js"></script>
12
+ <script type="text/javascript" src="../vendor/esapi4js/resources/i18n/ESAPI_Standard_en_US.properties.js"></script>
13
+ <script type="text/javascript" src="../vendor/esapi4js/esapi-compressed.js"></script>
14
+ <script type="text/javascript" src="../vendor/esapi4js/resources/Base.esapi.properties.js"></script>
15
+ <script type="text/javascript">
16
+ org.owasp.esapi.ESAPI.initialize();
17
+ var j = $ESAPI.encoder().encodeForJavaScript
18
+ </script>
19
+
20
+ <link href="../dupe.css" media="screen" rel="stylesheet" type="text/css" />
21
+
22
+ <title>Hydroponics <%= settings.version.split(".").collect(&:to_i).collect(&:to_s).join(".") %></title>
23
+ </head>
24
+
25
+ <body class="container">
26
+ <div class="header">
27
+ <h1>Hydroponics</h1>
28
+ </div>
29
+ <%= erb @action %>
30
+ </body>
31
+ </html>
data/config/hydro_app.rb CHANGED
@@ -29,7 +29,8 @@ class HydroApp < Sinatra::Base
29
29
  end
30
30
 
31
31
  get '/:action/:table' do |action, table|
32
+ @action = action.to_sym
32
33
  @table = table.to_sym
33
- erb :"#{action}/index"
34
+ erb :"single/index"
34
35
  end
35
36
  end
data/hydroponics.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hydroponics}
8
- s.version = "0.3.3"
8
+ s.version = "0.3.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tyler Boyd"]
12
- s.date = %q{2010-11-03}
12
+ s.date = %q{2010-11-15}
13
13
  s.default_executable = %q{hydro}
14
14
  s.description = %q{A user interface to seed or destroy large quantities of data in a Rails app.}
15
15
  s.email = %q{tboyd47@gmail.com}
@@ -29,8 +29,9 @@ Gem::Specification.new do |s|
29
29
  "VERSION",
30
30
  "app/actions/dupe.rb",
31
31
  "app/actions/foreigndupe.rb",
32
- "app/views/dupe/index.erb",
33
- "app/views/foreign_dupe/index.erb",
32
+ "app/views/dupe.erb",
33
+ "app/views/foreign_dupe.erb",
34
+ "app/views/single/index.erb",
34
35
  "bin/hydro",
35
36
  "config/hydro_app.rb",
36
37
  "hydroponics.gemspec",
@@ -42,9 +43,15 @@ Gem::Specification.new do |s|
42
43
  "spec/spec.opts",
43
44
  "spec/spec_helper.rb",
44
45
  "static/ajax-loader.gif",
46
+ "static/dupe.css",
45
47
  "static/dupe.js",
46
48
  "static/test/dupe_test.js",
47
49
  "static/test/index.html",
50
+ "static/vendor/esapi4js/esapi-compressed.js",
51
+ "static/vendor/esapi4js/lib/log4js-lib.js",
52
+ "static/vendor/esapi4js/lib/log4js.js",
53
+ "static/vendor/esapi4js/resources/Base.esapi.properties.js",
54
+ "static/vendor/esapi4js/resources/i18n/ESAPI_Standard_en_US.properties.js",
48
55
  "static/vendor/jquery-ui-1.8.5.custom/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png",
49
56
  "static/vendor/jquery-ui-1.8.5.custom/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png",
50
57
  "static/vendor/jquery-ui-1.8.5.custom/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png",
@@ -31,7 +31,7 @@ describe "HydroApp" do
31
31
 
32
32
  it "should show the table's count" do
33
33
  get '/dupe/users'
34
- last_response.body.include?("<span id='sliderct'>" + @db[:users].count.to_s).should be_true
34
+ last_response.body.include?(@db[:users].count.to_s).should be_true
35
35
  end
36
36
  end
37
37
 
data/static/dupe.css ADDED
@@ -0,0 +1,57 @@
1
+ .container {width:950px;margin:0 auto;}
2
+ .dupe h3, .foreign-dupe h3 {
3
+ margin: 10px 5px 10px 18px;
4
+ color: #444;
5
+ float: left;
6
+ }
7
+ .dupe #slider {
8
+ float: left;
9
+ width: 352px;
10
+ margin: 16px 12px;
11
+ }
12
+ .foreign-dupe #slider {
13
+ float: left;
14
+ width: 252px;
15
+ margin: 16px 12px;
16
+ }
17
+ .dupecontainer {
18
+ height: 130px;
19
+ width: 501px;
20
+ }
21
+ .dupe, .foreign-dupe {
22
+ height: 106px;
23
+ width: 500px;
24
+ border: 1px #ddd solid;
25
+ }
26
+ #button {
27
+ float: right;
28
+ margin: 2px 12px;
29
+ }
30
+ #sliderct {
31
+ width: 50px;
32
+ float: left;
33
+ margin: 10px 5px;
34
+ }
35
+ h1, h3, p {
36
+ font-family: Verdana,Arial,sans-serif
37
+ }
38
+ p {
39
+ float: left;
40
+ font-size: 12px;
41
+ }
42
+ .count {
43
+ left: 18px;
44
+ position: relative;
45
+ top: 2px;
46
+ }
47
+ .loader {
48
+ background-image: url('../ajax-loader.gif');
49
+ width: 32px;
50
+ height: 16px;
51
+ margin-top: 16px;
52
+ float: left;
53
+ }
54
+ #foreign_key {
55
+ float: right;
56
+ margin-top: 12px;
57
+ }
data/static/dupe.js CHANGED
@@ -1,5 +1,4 @@
1
- var Dupe = function(slider, button, monitor) {
2
- this.slider = slider;
3
- this.button = button;
4
- this.monitor = monitor;
5
- };
1
+ function dupe() {
2
+ (function($){
3
+ })(jQuery);
4
+ }
@@ -0,0 +1,11 @@
1
+ var $namespace=function(d,g,b){var f=d.split(g||"."),h=b||window,e,a;for(e=0,a=f.length;e<a;e++){h=h[f[e]]=h[f[e]]||{}}return h};var $type=function(a,b){if(!a instanceof b){throw new SyntaxError()}};if(!$){var $=function(a){return document.getElementById(a)}}if(!Array.prototype.each){Array.prototype.each=function(a){if(typeof a!="function"){throw"Illegal Argument for Array.each"}for(var b=0;b<this.length;b++){a(this[b])}}}if(!Array.prototype.contains){Array.prototype.contains=function(b){var a=false;this.each(function(d){if((b.equals&&b.equals(d))||d==b){a=true;return}});return a}}if(!Array.prototype.containsKey){Array.prototype.containsKey=function(b){for(var a in this){if(a.toLowerCase()==b.toLowerCase()){return true}}return false}}if(!Array.prototype.getCaseInsensitive){Array.prototype.getCaseInsensitive=function(b){for(var a in this){if(a.toLowerCase()==b.toLowerCase()){return this[a]}}return null}}if(!String.prototype.charCodeAt){String.prototype.charCodeAt=function(a){var e=this.charAt(a);for(var b=0;b<65536;b++){var d=String.fromCharCode(b);if(d==e){return b}}return 0}}if(!String.prototype.endsWith){String.prototype.endsWith=function(a){return this.substr((this.length-a.length),a.length)==a}}if(!Exception){var Exception=function(a,b){this.cause=b;this.errorMessage=a};Exception.prototype=Error.prototype;Exception.prototype.getCause=function(){return this.cause};Exception.prototype.getMessage=function(){return this.message};Exception.prototype.getStackTrace=function(){if(this.callstack){return this.callstack}if(this.stack){var b=stack.split("\n");for(var d=0,a=b.length;d<a;d++){if(b[d].match(/^\s*[A-Za-z0-9\=+\$]+\(/)){this.callstack.push(b[d])}}this.callstack.shift();return this.callstack}else{if(window.opera&&this.message){var b=this.message.split("\n");for(var d=0,a=b.length;d<a;d++){if(b[d].match(/^\s*[A-Za-z0-9\=+\$]+\(/)){var f=b[d];if(b[d+1]){f+=" at "+b[d+1];d++}this.callstack.push(f)}}this.callstack.shift();return this.callstack}else{var g=arguments.callee.caller;while(g){var e=g.toString();var h=e.substring(e.indexOf("function")+8,e.indexOf("("))||"anonymous";this.callstack.push(h);g=g.caller}return this.callstack}}};Exception.prototype.printStackTrace=function(b){var a=this.getMessage()+"|||"+this.getStackTrace().join("|||");if(this.cause){if(this.cause.printStackTrace){a+="||||||Caused by "+this.cause.printStackTrace().replace("\n","|||")}}if(!b){return b.replace("|||","\n")}else{if(b.value){b.value=a.replace("|||","\n")}else{if(b.writeln){b.writeln(a.replace("|||","\n"))}else{if(b.innerHTML){b.innerHTML=a.replace("|||","<br/>")}else{if(b.innerText){b.innerText=a.replace("|||","<br/>")}else{if(b.append){b.append(a.replace("|||","\n"))}else{if(b instanceof Function){b(a.replace("|||","\n"))}}}}}}}}}if(!RuntimeException){var RuntimeException=Exception}if(!IllegalArgumentException){var IllegalArgumentException=Exception}if(!DateFormat){var DateFormat=function(d){var b=d;var a={longMonths:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],longDays:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],d:function(e){return(e.getDate()<10?"0":"")+e.getDate()},D:function(e){return a.shortDays[e.getDay()]},j:function(e){return e.getDate()},l:function(e){return a.longDays[e.getDay()]},N:function(e){return e.getDay()+1},S:function(e){return(e.getDate()%10==1&&e.getDate()!=11?"st":(e.getDate()%10==2&&e.getDate()!=12?"nd":(e.getDate()%10==3&&e.getDate()!=13?"rd":"th")))},w:function(e){return e.getDay()},z:function(e){return"Not Yet Supported"},W:function(e){return"Not Yet Supported"},F:function(e){return a.longMonths[e.getMonth()]},m:function(e){return(e.getMonth()<9?"0":"")+(e.getMonth()+1)},M:function(e){return a.shortMonths[e.getMonth()]},n:function(e){return e.getMonth()+1},t:function(e){return"Not Yet Supported"},L:function(e){return(((e.getFullYear()%4==0)&&(e.getFullYear()%100!=0))||(e.getFullYear()%400==0))?"1":"0"},o:function(e){return"Not Supported"},Y:function(e){return e.getFullYear()},y:function(e){return(""+e.getFullYear()).substr(2)},a:function(e){return e.getHours()<12?"am":"pm"},A:function(e){return e.getHours()<12?"AM":"PM"},B:function(e){return"Not Yet Supported"},g:function(e){return e.getHours()%12||12},G:function(e){return e.getHours()},h:function(e){return((e.getHours()%12||12)<10?"0":"")+(e.getHours()%12||12)},H:function(e){return(e.getHours()<10?"0":"")+e.getHours()},i:function(e){return(e.getMinutes()<10?"0":"")+e.getMinutes()},s:function(e){return(e.getSeconds()<10?"0":"")+e.getSeconds()},e:function(e){return"Not Yet Supported"},I:function(e){return"Not Supported"},O:function(e){return(-e.getTimezoneOffset()<0?"-":"+")+(Math.abs(e.getTimezoneOffset()/60)<10?"0":"")+(Math.abs(e.getTimezoneOffset()/60))+"00"},P:function(e){return(-e.getTimezoneOffset()<0?"-":"+")+(Math.abs(e.getTimezoneOffset()/60)<10?"0":"")+(Math.abs(e.getTimezoneOffset()/60))+":"+(Math.abs(e.getTimezoneOffset()%60)<10?"0":"")+(Math.abs(e.getTimezoneOffset()%60))
2
+ },T:function(g){var f=g.getMonth();g.setMonth(0);var e=g.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/,"$1");g.setMonth(f);return e},Z:function(e){return -e.getTimezoneOffset()*60},c:function(e){return e.format("Y-m-d")+"T"+e.format("H:i:sP")},r:function(e){return e.toString()},U:function(e){return e.getTime()/1000}};return{format:function(g){var e="";for(var f=0;f<b.length;f++){var h=b.charAt(f);if(a[h]){e+=a[h].call(g)}else{e+=h}}return e}}};DateFormat.getDateInstance=function(){return new DateFormat("M/d/y h:i a")}}$namespace("org.owasp.esapi");org.owasp.esapi.ESAPI=function(g){var b=g;if(!b){throw new RuntimeException("Configuration Error - Unable to load $ESAPI_Properties Object")}var a=null;var e=null;var d=null;var f=null;var h=null;return{properties:b,encoder:function(){if(!a){if(!b.encoder.Implementation){throw new RuntimeException("Configuration Error - $ESAPI.properties.encoder.Implementation object not found.")}a=new b.encoder.Implementation()}return a},logFactory:function(){if(!d){if(!b.logging.Implementation){throw new RuntimeException("Configuration Error - $ESAPI.properties.logging.Implementation object not found.")}d=new b.logging.Implementation()}return d},logger:function(i){return this.logFactory().getLogger(i)},locale:function(){return org.owasp.esapi.i18n.Locale.getLocale(b.localization.DefaultLocale)},resourceBundle:function(){if(!f){if(!b.localization.StandardResourceBundle){throw new RuntimeException("Configuration Error - $ESAPI.properties.localization.StandardResourceBundle not found.")}f=new org.owasp.esapi.i18n.ObjectResourceBundle(b.localization.StandardResourceBundle)}return f},validator:function(){if(!e){if(!b.validation.Implementation){throw new RuntimeException("Configuration Error - $ESAPI.properties.validation.Implementation object not found.")}e=new b.validation.Implementation()}return e},httpUtilities:function(){if(!h){h=new org.owasp.esapi.HTTPUtilities()}return h}}};var $ESAPI=null;org.owasp.esapi.ESAPI.initialize=function(){$ESAPI=new org.owasp.esapi.ESAPI(Base.esapi.properties)};$namespace("org.owasp.esapi");org.owasp.esapi.Encoder=function(){};$namespace("org.owasp.esapi");org.owasp.esapi.EncoderConstants={CHAR_LOWERS:["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],CHAR_UPPERS:["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],CHAR_DIGITS:["0","1","2","3","4","5","6","7","8","9"],CHAR_SPECIALS:["!","$","*","+","-",".","=","?","@","^","_","|","~"],CHAR_LETTERS:["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],CHAR_ALNUM:["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9"]};$namespace("org.owasp.esapi");org.owasp.esapi.EnterpriseSecurityException=function(b,a,e){var f=a;var d=new Exception(b,e);return{getMessage:d.getMessage,getUserMessage:d.getMessage,getLogMessage:function(){return f},getStackTrace:d.getStackTrace,printStackTrace:d.printStackTrace}};$namespace("org.owasp.esapi");org.owasp.esapi.HTTPUtilities=function(){var b=$ESAPI.logger("HTTPUtilities");var d=$ESAPI.resourceBundle();var a=org.owasp.esapi.Logger.EventType;return{addCookie:function(h){$type(h,org.owasp.esapi.net.Cookie);if(window.top.location.protocol!="http:"||window.top.location.protocol!="https:"){throw new RuntimeException(d.getString("HTTPUtilities.Cookie.Protocol",{protocol:window.top.location.protocol}))}var f=h.getName(),m=h.getValue(),k=h.getMaxAge(),i=h.getDomain(),p=h.getPath(),e=h.getSecure();var n=new org.owasp.esapi.ValidationErrorList();var l=$ESAPI.validator().getValidInput("cookie name",f,"HttpCookieName",50,false,n);var g=$ESAPI.validator().getValidInput("cookie value",m,"HttpCookieValue",5000,false,n);if(n.size()==0){var j=f+"="+escape(m);j+=k?";expires="+(new Date((new Date()).getTime()+(1000*k)).toGMTString()):"";j+=p?";path="+p:"";j+=i?";domain="+i:"";j+=e||$ESAPI.properties.httputilities.cookies.ForceSecure?";secure":"";document.cookie=j}else{b.warning(a.SECURITY_FAILURE,d.getString("HTTPUtilities.Cookie.UnsafeData",{name:f,value:m}))}},getCookie:function(j){var f=document.cookie.split("; ");for(var h=0,e=f.length;h<e;h++){var g=f[h].split("=");if(g[0]==escape(j)){return new org.owasp.esapi.net.Cookie(j,g[1]?unescape(g[1]):"")}}return null},killAllCookies:function(){var f=document.cookie.split("; ");for(var j=0,e=f.length;j<e;j++){var h=f[j].split("=");var g=unescape(h[0]);if(!this.killCookie(g)){throw new RuntimeException(d.getString("HTTPUtilities.Cookie.CantKill",{name:g}))}}},killCookie:function(e){var f=this.getCookie(e);if(f){f.setMaxAge(-10);this.addCookie(f);if(this.getCookie(e)){throw new RuntimeException(d.getString("HTTPUtilities.Cookie.CantKill",{name:e}))
3
+ }return true}return false},getRequestParameter:function(f){var e=window.top.location.search.substring(1);var g=e.indexOf(f);if(g<0){return null}g=g+f.length;var h=e.indexOf("&",g);if(h<0){h=e.length}return unescape(e.substring(g,h))}}};$namespace("org.owasp.esapi");org.owasp.esapi.IntrusionException=function(d,b,a){var e=new org.owasp.esapi.EnterpriseSecurityException(d,b,a);return{getMessage:e.getMessage,getUserMessage:e.getMessage,getLogMessage:e.getLogMessage,getStackTrace:e.getStackTrace,printStackTrace:e.printStackTrace}};$namespace("org.owasp.esapi");org.owasp.esapi.LogFactory=function(){return{getLogger:false}};$namespace("org.owasp.esapi");org.owasp.esapi.Logger=function(){return{setLevel:false,fatal:false,error:false,isErrorEnabled:false,warning:false,isWarningEnabled:false,info:false,isInfoEnabled:false,debug:false,isDebugEnabled:false,trace:false,isTraceEnabled:false}};org.owasp.esapi.Logger.EventType=function(d,b){var a=d;var e=b;return{isSuccess:function(){return e},toString:function(){return a}}};with(org.owasp.esapi.Logger){EventType.SECURITY_SUCCESS=new EventType("SECURITY SUCCESS",true);EventType.SECURITY_FAILURE=new EventType("SECURITY FAILURE",false);EventType.EVENT_SUCCESS=new EventType("EVENT SUCCESS",true);EventType.EVENT_FAILURE=new EventType("EVENT FAILURE",false);OFF=Number.MAX_VALUE;FATAL=1000;ERROR=800;WARNING=600;INFO=400;DEBUG=200;TRACE=100;ALL=Number.MIN_VALUE}$namespace("org.owasp.esapi");org.owasp.esapi.PreparedString=function(d,a,g){var f=[];var e=[];function b(k){var h=0,l=0;for(var j=0;j<k.length;j++){if(k.charAt(j)==g){l++;f.push(k.substr(h,j));h=j+1}}f.push(k.substr(h));e=new Array(l)}if(!g){g="?"}b(d);return{set:function(h,j,i){if(h<1||h>e.length){throw new IllegalArgumentException("Attempt to set parameter: "+h+" on a PreparedString with only "+e.length+" placeholders")}if(!i){i=a}e[h-1]=i.encode([],j)},toString:function(){for(var h=0;h<e.length;h++){if(e[h]==null){throw new RuntimeException("Attempt to render PreparedString without setting parameter "+(h+1))}}var j="",k=0;for(var l=0;l<f.length;l++){j+=f[l];if(k<e.length){j+=e[k++]}}return j}}};$namespace("org.owasp.esapi");org.owasp.esapi.ValidationErrorList=function(){var a=Array();return{addError:function(b,d){if(b==null){throw new RuntimeException("Context cannot be null: "+d.getLogMessage(),d)}if(d==null){throw new RuntimeException("Context ("+b+") - Error cannot be null")}if(a[b]){throw new RuntimeException("Context ("+b+") already exists. must be unique.")}a[b]=d},errors:function(){return a},isEmpty:function(){return a.length==0},size:function(){return a.length}}};$namespace("org.owasp.esapi");org.owasp.esapi.ValidationRule=function(){return{getValid:false,setAllowNull:false,getTypeName:false,setTypeName:false,setEncoder:false,assertValid:false,getSafe:false,isValid:false,whitelist:false}};$namespace("org.owasp.esapi");org.owasp.esapi.Validator=function(){return{addRule:false,getRule:false,getValidInput:false,isValidDate:false,getValidDate:false,isValidSafeHTML:false,getValidSafeHTML:false,isValidCreditCard:false,getValidCreditCard:false,isValidFilename:false,getValidFilename:false,isValidNumber:false,getValidNumber:false,isValidPrintable:false,getValidPrintable:false}};$namespace("org.owasp.esapi.codecs.Base64");org.owasp.esapi.codecs.Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(h){if(!h){return null}var e="";var d,b,a,m,l,k,j;var f=0;var g=org.owasp.esapi.codecs.UTF8.encode(h);while(f<g.length){d=g.charCodeAt(f++);b=g.charCodeAt(f++);a=g.charCodeAt(f++);m=d>>2;l=((d&3)<<4)|(b>>4);k=((b&15)<<2)|(a>>6);j=a&63;if(isNaN(b)){k=j=64}else{if(isNaN(a)){j=64}}e+=this._keyStr.charAt(m)+this._keyStr.charAt(l)+this._keyStr.charAt(k)+this._keyStr.charAt(j)}return e},decode:function(h){if(!h){return null}var e="";var d,b,a,m,l,k,j;var f=0;var g=h.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(f<g.length){m=this._keyStr.indexOf(g.charAt(f++));l=this._keyStr.indexOf(g.charAt(f++));k=this._keyStr.indexOf(g.charAt(f++));j=this._keyStr.indexOf(g.charAt(f++));d=(m<<2)|(l>>4);b=((l&15)<<4)|(k>>2);a=((k&3)<<6)|j;e+=String.fromCharCode(d);if(k!=64){e+=String.fromCharCode(b)}if(j!=64){e+=String.fromCharCode(a)}}e=org.owasp.esapi.codecs.UTF8.decode(e);return e}};$namespace("org.owasp.esapi.codecs");org.owasp.esapi.codecs.CSSCodec=function(){var a=new org.owasp.esapi.codecs.Codec();return{encode:a.encode,decode:a.decode,encodeCharacter:function(b,e){if(b.contains(e)){return e}var d=org.owasp.esapi.codecs.Codec.getHexForNonAlphanumeric(e);if(d==null){return e}return"\\"+d+" "},decodeCharacter:function(l){l.mark();var h=l.next();if(h==null){l.reset();return null}if(h!="\\"){l.reset();return null}var d=l.next();if(d==null){l.reset();return null}if(l.isHexDigit(d)){var b=d;for(var f=0;f<6;f++){var k=l.next();if(k==null||k.charCodeAt(0)==32){break}if(l.isHexDigit(k)){b+=k}else{input.pushback(k);break}}try{var j=parseInt(b,16);return String.fromCharCode(j)}catch(g){l.reset();return null}}return d
4
+ }}};$namespace("org.owasp.esapi.codecs");org.owasp.esapi.codecs.Codec=function(){return{encode:function(d,e){var a="";for(var b=0;b<e.length;b++){var f=e.charAt(b);a+=this.encodeCharacter(d,f)}return a},encodeCharacter:function(a,b){return b},decode:function(b){var a="";var d=new org.owasp.esapi.codecs.PushbackString(b);while(d.hasNext()){var e=this.decodeCharacter(d);if(e!=null){a+=e}else{a+=d.next()}}return a},decodeCharacter:function(a){return a.next()}}};org.owasp.esapi.codecs.Codec.getHexForNonAlphanumeric=function(a){if(a.charCodeAt(0)<256){return org.owasp.esapi.codecs.Codec.hex[a.charCodeAt(0)]}return a.charCodeAt(0).toString(16)};org.owasp.esapi.codecs.Codec.hex=[];for(var c=0;c<255;c++){if(c>=48&&c<=57||c>=65&&c<=90||c>=97&&c<=122){org.owasp.esapi.codecs.Codec.hex[c]=null}else{org.owasp.esapi.codecs.Codec.hex[c]=c.toString(16)}}var entityToCharacterMap=[];entityToCharacterMap["&quot"]="34";entityToCharacterMap["&amp"]="38";entityToCharacterMap["&lt"]="60";entityToCharacterMap["&gt"]="62";entityToCharacterMap["&nbsp"]="160";entityToCharacterMap["&iexcl"]="161";entityToCharacterMap["&cent"]="162";entityToCharacterMap["&pound"]="163";entityToCharacterMap["&curren"]="164";entityToCharacterMap["&yen"]="165";entityToCharacterMap["&brvbar"]="166";entityToCharacterMap["&sect"]="167";entityToCharacterMap["&uml"]="168";entityToCharacterMap["&copy"]="169";entityToCharacterMap["&ordf"]="170";entityToCharacterMap["&laquo"]="171";entityToCharacterMap["&not"]="172";entityToCharacterMap["&shy"]="173";entityToCharacterMap["&reg"]="174";entityToCharacterMap["&macr"]="175";entityToCharacterMap["&deg"]="176";entityToCharacterMap["&plusmn"]="177";entityToCharacterMap["&sup2"]="178";entityToCharacterMap["&sup3"]="179";entityToCharacterMap["&acute"]="180";entityToCharacterMap["&micro"]="181";entityToCharacterMap["&para"]="182";entityToCharacterMap["&middot"]="183";entityToCharacterMap["&cedil"]="184";entityToCharacterMap["&sup1"]="185";entityToCharacterMap["&ordm"]="186";entityToCharacterMap["&raquo"]="187";entityToCharacterMap["&frac14"]="188";entityToCharacterMap["&frac12"]="189";entityToCharacterMap["&frac34"]="190";entityToCharacterMap["&iquest"]="191";entityToCharacterMap["&Agrave"]="192";entityToCharacterMap["&Aacute"]="193";entityToCharacterMap["&Acirc"]="194";entityToCharacterMap["&Atilde"]="195";entityToCharacterMap["&Auml"]="196";entityToCharacterMap["&Aring"]="197";entityToCharacterMap["&AElig"]="198";entityToCharacterMap["&Ccedil"]="199";entityToCharacterMap["&Egrave"]="200";entityToCharacterMap["&Eacute"]="201";entityToCharacterMap["&Ecirc"]="202";entityToCharacterMap["&Euml"]="203";entityToCharacterMap["&Igrave"]="204";entityToCharacterMap["&Iacute"]="205";entityToCharacterMap["&Icirc"]="206";entityToCharacterMap["&Iuml"]="207";entityToCharacterMap["&ETH"]="208";entityToCharacterMap["&Ntilde"]="209";entityToCharacterMap["&Ograve"]="210";entityToCharacterMap["&Oacute"]="211";entityToCharacterMap["&Ocirc"]="212";entityToCharacterMap["&Otilde"]="213";entityToCharacterMap["&Ouml"]="214";entityToCharacterMap["&times"]="215";entityToCharacterMap["&Oslash"]="216";entityToCharacterMap["&Ugrave"]="217";entityToCharacterMap["&Uacute"]="218";entityToCharacterMap["&Ucirc"]="219";entityToCharacterMap["&Uuml"]="220";entityToCharacterMap["&Yacute"]="221";entityToCharacterMap["&THORN"]="222";entityToCharacterMap["&szlig"]="223";entityToCharacterMap["&agrave"]="224";entityToCharacterMap["&aacute"]="225";entityToCharacterMap["&acirc"]="226";entityToCharacterMap["&atilde"]="227";entityToCharacterMap["&auml"]="228";entityToCharacterMap["&aring"]="229";entityToCharacterMap["&aelig"]="230";entityToCharacterMap["&ccedil"]="231";entityToCharacterMap["&egrave"]="232";entityToCharacterMap["&eacute"]="233";entityToCharacterMap["&ecirc"]="234";entityToCharacterMap["&euml"]="235";entityToCharacterMap["&igrave"]="236";entityToCharacterMap["&iacute"]="237";entityToCharacterMap["&icirc"]="238";entityToCharacterMap["&iuml"]="239";entityToCharacterMap["&eth"]="240";entityToCharacterMap["&ntilde"]="241";entityToCharacterMap["&ograve"]="242";entityToCharacterMap["&oacute"]="243";entityToCharacterMap["&ocirc"]="244";entityToCharacterMap["&otilde"]="245";entityToCharacterMap["&ouml"]="246";entityToCharacterMap["&divide"]="247";entityToCharacterMap["&oslash"]="248";entityToCharacterMap["&ugrave"]="249";entityToCharacterMap["&uacute"]="250";entityToCharacterMap["&ucirc"]="251";entityToCharacterMap["&uuml"]="252";entityToCharacterMap["&yacute"]="253";entityToCharacterMap["&thorn"]="254";entityToCharacterMap["&yuml"]="255";entityToCharacterMap["&OElig"]="338";entityToCharacterMap["&oelig"]="339";entityToCharacterMap["&Scaron"]="352";entityToCharacterMap["&scaron"]="353";entityToCharacterMap["&Yuml"]="376";entityToCharacterMap["&fnof"]="402";entityToCharacterMap["&circ"]="710";entityToCharacterMap["&tilde"]="732";entityToCharacterMap["&Alpha"]="913";entityToCharacterMap["&Beta"]="914";entityToCharacterMap["&Gamma"]="915";entityToCharacterMap["&Delta"]="916";
5
+ entityToCharacterMap["&Epsilon"]="917";entityToCharacterMap["&Zeta"]="918";entityToCharacterMap["&Eta"]="919";entityToCharacterMap["&Theta"]="920";entityToCharacterMap["&Iota"]="921";entityToCharacterMap["&Kappa"]="922";entityToCharacterMap["&Lambda"]="923";entityToCharacterMap["&Mu"]="924";entityToCharacterMap["&Nu"]="925";entityToCharacterMap["&Xi"]="926";entityToCharacterMap["&Omicron"]="927";entityToCharacterMap["&Pi"]="928";entityToCharacterMap["&Rho"]="929";entityToCharacterMap["&Sigma"]="931";entityToCharacterMap["&Tau"]="932";entityToCharacterMap["&Upsilon"]="933";entityToCharacterMap["&Phi"]="934";entityToCharacterMap["&Chi"]="935";entityToCharacterMap["&Psi"]="936";entityToCharacterMap["&Omega"]="937";entityToCharacterMap["&alpha"]="945";entityToCharacterMap["&beta"]="946";entityToCharacterMap["&gamma"]="947";entityToCharacterMap["&delta"]="948";entityToCharacterMap["&epsilon"]="949";entityToCharacterMap["&zeta"]="950";entityToCharacterMap["&eta"]="951";entityToCharacterMap["&theta"]="952";entityToCharacterMap["&iota"]="953";entityToCharacterMap["&kappa"]="954";entityToCharacterMap["&lambda"]="955";entityToCharacterMap["&mu"]="956";entityToCharacterMap["&nu"]="957";entityToCharacterMap["&xi"]="958";entityToCharacterMap["&omicron"]="959";entityToCharacterMap["&pi"]="960";entityToCharacterMap["&rho"]="961";entityToCharacterMap["&sigmaf"]="962";entityToCharacterMap["&sigma"]="963";entityToCharacterMap["&tau"]="964";entityToCharacterMap["&upsilon"]="965";entityToCharacterMap["&phi"]="966";entityToCharacterMap["&chi"]="967";entityToCharacterMap["&psi"]="968";entityToCharacterMap["&omega"]="969";entityToCharacterMap["&thetasym"]="977";entityToCharacterMap["&upsih"]="978";entityToCharacterMap["&piv"]="982";entityToCharacterMap["&ensp"]="8194";entityToCharacterMap["&emsp"]="8195";entityToCharacterMap["&thinsp"]="8201";entityToCharacterMap["&zwnj"]="8204";entityToCharacterMap["&zwj"]="8205";entityToCharacterMap["&lrm"]="8206";entityToCharacterMap["&rlm"]="8207";entityToCharacterMap["&ndash"]="8211";entityToCharacterMap["&mdash"]="8212";entityToCharacterMap["&lsquo"]="8216";entityToCharacterMap["&rsquo"]="8217";entityToCharacterMap["&sbquo"]="8218";entityToCharacterMap["&ldquo"]="8220";entityToCharacterMap["&rdquo"]="8221";entityToCharacterMap["&bdquo"]="8222";entityToCharacterMap["&dagger"]="8224";entityToCharacterMap["&Dagger"]="8225";entityToCharacterMap["&bull"]="8226";entityToCharacterMap["&hellip"]="8230";entityToCharacterMap["&permil"]="8240";entityToCharacterMap["&prime"]="8242";entityToCharacterMap["&Prime"]="8243";entityToCharacterMap["&lsaquo"]="8249";entityToCharacterMap["&rsaquo"]="8250";entityToCharacterMap["&oline"]="8254";entityToCharacterMap["&frasl"]="8260";entityToCharacterMap["&euro"]="8364";entityToCharacterMap["&image"]="8365";entityToCharacterMap["&weierp"]="8472";entityToCharacterMap["&real"]="8476";entityToCharacterMap["&trade"]="8482";entityToCharacterMap["&alefsym"]="8501";entityToCharacterMap["&larr"]="8592";entityToCharacterMap["&uarr"]="8593";entityToCharacterMap["&rarr"]="8594";entityToCharacterMap["&darr"]="8595";entityToCharacterMap["&harr"]="8596";entityToCharacterMap["&crarr"]="8629";entityToCharacterMap["&lArr"]="8656";entityToCharacterMap["&uArr"]="8657";entityToCharacterMap["&rArr"]="8658";entityToCharacterMap["&dArr"]="8659";entityToCharacterMap["&hArr"]="8660";entityToCharacterMap["&forall"]="8704";entityToCharacterMap["&part"]="8706";entityToCharacterMap["&exist"]="8707";entityToCharacterMap["&empty"]="8709";entityToCharacterMap["&nabla"]="8711";entityToCharacterMap["&isin"]="8712";entityToCharacterMap["&notin"]="8713";entityToCharacterMap["&ni"]="8715";entityToCharacterMap["&prod"]="8719";entityToCharacterMap["&sum"]="8721";entityToCharacterMap["&minus"]="8722";entityToCharacterMap["&lowast"]="8727";entityToCharacterMap["&radic"]="8730";entityToCharacterMap["&prop"]="8733";entityToCharacterMap["&infin"]="8734";entityToCharacterMap["&ang"]="8736";entityToCharacterMap["&and"]="8743";entityToCharacterMap["&or"]="8744";entityToCharacterMap["&cap"]="8745";entityToCharacterMap["&cup"]="8746";entityToCharacterMap["&int"]="8747";entityToCharacterMap["&there4"]="8756";entityToCharacterMap["&sim"]="8764";entityToCharacterMap["&cong"]="8773";entityToCharacterMap["&asymp"]="8776";entityToCharacterMap["&ne"]="8800";entityToCharacterMap["&equiv"]="8801";entityToCharacterMap["&le"]="8804";entityToCharacterMap["&ge"]="8805";entityToCharacterMap["&sub"]="8834";entityToCharacterMap["&sup"]="8835";entityToCharacterMap["&nsub"]="8836";entityToCharacterMap["&sube"]="8838";entityToCharacterMap["&supe"]="8839";entityToCharacterMap["&oplus"]="8853";entityToCharacterMap["&otimes"]="8855";entityToCharacterMap["&perp"]="8869";entityToCharacterMap["&sdot"]="8901";entityToCharacterMap["&lceil"]="8968";entityToCharacterMap["&rceil"]="8969";entityToCharacterMap["&lfloor"]="8970";entityToCharacterMap["&rfloor"]="8971";entityToCharacterMap["&lang"]="9001";entityToCharacterMap["&rang"]="9002";entityToCharacterMap["&loz"]="9674";
6
+ entityToCharacterMap["&spades"]="9824";entityToCharacterMap["&clubs"]="9827";entityToCharacterMap["&hearts"]="9829";entityToCharacterMap["&diams"]="9830";var characterToEntityMap=[];for(var entity in entityToCharacterMap){characterToEntityMap[entityToCharacterMap[entity]]=entity}$namespace("org.owasp.esapi.codecs");org.owasp.esapi.codecs.HTMLEntityCodec=function(){var f=new org.owasp.esapi.codecs.Codec();var a=function(g){var h=g.peek();if(h==null){return null}if(h=="x"||h=="X"){g.next();return d(g)}return e(g)};var e=function(g){var h="";while(g.hasNext()){var j=g.peek();if(j.match(/[0-9]/)){h+=j;g.next()}else{if(j==";"){g.next();break}else{break}}}try{return parseInt(h)}catch(i){return null}};var d=function(g){var h="";while(g.hasNext()){var j=g.peek();if(j.match(/[0-9A-Fa-f]/)){h+=j;g.next()}else{if(j==";"){g.next();break}else{break}}}try{return parseInt(h,16)}catch(i){return null}};var b=function(h){var g="";while(h.hasNext()){var i=h.peek();if(i.match(/[A-Za-z]/)){g+=i;h.next();if(entityToCharacterMap.containsKey("&"+g)){if(h.peek(";")){h.next()}break}}else{if(i==";"){h.next()}else{break}}}return String.fromCharCode(entityToCharacterMap.getCaseInsensitive("&"+g))};return{encode:f.encode,decode:f.decode,encodeCharacter:function(h,k){if(h.contains(k)){return k}var i=org.owasp.esapi.codecs.Codec.getHexForNonAlphanumeric(k);if(i==null){return k}var j=k.charCodeAt(0);if((j<=31&&k!="\t"&&k!="\n"&&k!="\r")||(j>=127&&j<=159)||k==" "){return" "}var g=characterToEntityMap[j];if(g!=null){return g+";"}return"&#x"+i+";"},decodeCharacter:function(k){var g=k;g.mark();var i=g.next();if(i==null||i!="&"){g.reset();return null}var h=g.next();if(h==null){g.reset();return null}if(h=="#"){var j=a(g);if(j!=null){return j}}else{if(h.match(/[A-Za-z]/)){g.pushback(h);j=b(g);if(j!=null){return j}}}g.reset();return null}}};$namespace("org.owasp.esapi.codecs");org.owasp.esapi.codecs.JavascriptCodec=function(){var a=new org.owasp.esapi.codecs.Codec();return{encode:function(f,h){var d="";for(var b=0;b<h.length;b++){var g=h.charAt(b);if(f.contains(g)){d+=g}else{var i=org.owasp.esapi.codecs.Codec.getHexForNonAlphanumeric(g);if(i==null){d+=g}else{var e=g.charCodeAt(0).toString(16);if(g.charCodeAt(0)<256){var j="00".substr(e.length);d+="\\x"+j+e.toUpperCase()}else{j="0000".substr(e.length);d+="\\u"+j+e.toUpperCase()}}}}return d},decode:a.decode,decodeCharacter:function(p){p.mark();var k=p.next();if(k==null){p.reset();return null}if(k!="\\"){p.reset();return null}var b=p.next();if(b==null){p.reset();return null}if(b=="b"){return 8}else{if(b=="t"){return 9}else{if(b=="n"){return 10}else{if(b=="v"){return 11}else{if(b=="f"){return 12}else{if(b=="r"){return 13}else{if(b=='"'){return 34}else{if(b=="'"){return 39}else{if(b=="\\"){return 92}else{if(b.toLowerCase()=="x"){h="";for(var j=0;j<2;j++){var m=p.nextHex();if(m!=null){h+=m}else{input.reset();return null}}try{d=parseInt(h,16);return String.fromCharCode(d)}catch(l){p.reset();return null}}else{if(b.toLowerCase()=="u"){h="";for(j=0;j<4;j++){m=p.nextHex();if(m!=null){h+=m}else{input.reset();return null}}try{var d=parseInt(h,16);return String.fromCharCode(d)}catch(l){p.reset();return null}}else{if(p.isOctalDigit(b)){var h=b;var g=p.next();if(!p.isOctalDigit(g)){p.pushback(g)}else{h+=g;var f=p.next();if(!p.isOctalDigit(f)){p.pushback(f)}else{h+=f}}try{d=parseInt(h,8);return String.fromCharCode(d)}catch(l){p.reset();return null}}}}}}}}}}}}}return b}}};$namespace("org.owasp.esapi.codecs");org.owasp.esapi.codecs.PercentCodec=function(){var e=new org.owasp.esapi.codecs.Codec();var d="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";var b="-._~";var a=true;var g=d+(a?"":b);var f=function(h){var i="";if(h<-128||h>127){throw new IllegalArgumentException("b is not a byte (was "+h+")")}h&=255;if(h<16){i+="0"}return i+h.toString(16).toUpperCase()};return{encode:e.encode,decode:e.decode,encodeCharacter:function(k,l){if(g.indexOf(l)>-1){return l}var i=org.owasp.esapi.codecs.UTF8.encode(l);var j="";for(var h=0;h<i.length;h++){j+="%"+f(i.charCodeAt(h))}return j},decodeCharacter:function(q){q.mark();var l=q.next();if(l==null||l!="%"){q.reset();return null}var h="";for(var j=0;j<2;j++){var p=q.nextHex();if(p!=null){h+=p}}if(h.length==2){try{var m=parseInt(h,16);return String.fromCharCode(m)}catch(k){}}q.reset();return null}}};$namespace("org.owasp.esapi.codecs");org.owasp.esapi.codecs.PushbackString=function(b){var e=b,g="",a="",f=0,d=0;return{pushback:function(h){g=h},index:function(){return f},hasNext:function(){if(g!=null){return true}return !(e==null||e.length==0||f>=e.length)},next:function(){if(g!=null){var h=g;g=null;return h}if(e==null||e.length==0||f>=e.length){return null}return e.charAt(f++)},nextHex:function(){var h=this.next();if(this.isHexDigit(h)){return h}return null},nextOctal:function(){var h=this.next();if(this.isOctalDigit(h)){return h}return null},isHexDigit:function(h){return h!=null&&((h>="0"&&h<="9")||(h>="a"&&h<="f")||(h>="A"&&h<="F"))},isOctalDigit:function(h){return h!=null&&(h>="0"&&h<="7")
7
+ },peek:function(h){if(!h){if(g!=null){return g}if(e==null||e.length==0||f>=e.length){return null}return e.charAt(f)}else{if(g!=null&&g==h){return true}if(e==null||e.length==0||f>=e.length){return false}return e.charAt(f)==h}},mark:function(){a=g;d=f},reset:function(){g=a;f=d},remainder:function(){var h=e.substr(f);if(g!=null){h=g+h}return h}}};$namespace("org.owasp.esapi.codecs");org.owasp.esapi.codecs.UTF8={encode:function(d){var b=d.replace(/\r\n/g,"\n");var a="";for(var f=0;f<b.length;f++){var e=b.charCodeAt(f);if(e<128){a+=String.fromCharCode(e)}else{if((e>127)&&(e<2048)){a+=String.fromCharCode((e>>6)|192);a+=String.fromCharCode((e&63)|128)}else{a+=String.fromCharCode((e>>12)|224);a+=String.fromCharCode(((e>>6)&63)|128);a+=String.fromCharCode((e&63)|128)}}}return a},decode:function(d){var a="";var b=c=c1=c2=0;while(b<d.length){c=d.charCodeAt(b);if(c<128){a+=String.fromCharCode(c);b++}else{if((c>191)&&(c<224)){c2=d.charCodeAt(b+1);a+=String.fromCharCode(((c&31)<<6)|(c2&63));b+=2}else{c2=utftext.charCodeAt(b+1);c3=utftext.charCodeAt(b+2);string+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));b+=3}}}return a}};$namespace("org.owasp.esapi.i18n");org.owasp.esapi.i18n.ArrayResourceBundle=function(sName,oLocale,aMessages,oParent){with(org.owasp.esapi.i18n){var _super=new ResourceBundle(sName,oLocale,oParent)}var messages=aMessages;return{getParent:_super.getParent,getLocale:_super.getLocale,getName:_super.getName,getString:_super.getString,getMessage:function(sKey){return messages[sKey]}}};$namespace("org.owasp.esapi.i18n");org.owasp.esapi.i18n.Locale=function(f,d,a){var g=f,e=d,b=a;return{getLanguage:function(){return g},getCountry:function(){return e},getVariant:function(){return b},toString:function(){return g+(e?"-"+e+(b?"-"+b:""):"")}}};org.owasp.esapi.i18n.Locale.US=new org.owasp.esapi.i18n.Locale("en","US");org.owasp.esapi.i18n.Locale.GB=new org.owasp.esapi.i18n.Locale("en","GB");org.owasp.esapi.i18n.Locale.getLocale=function(b){var a=b.split("-");return new org.owasp.esapi.i18n.Locale(a[0],(a.length>1?a[1]:""),(a.length>2?a.length[2]:""))};org.owasp.esapi.i18n.Locale.getDefault=function(){var a=(navigator.language?navigator.language:(navigator.userLanguage?navigator.userLanguage:"en-US")).split("-");return new org.owasp.esapi.i18n.Locale(a[0],(a.length>1?a[1]:""),(a.length>2?a.length[2]:""))};$namespace("org.owasp.esapi.i18n");org.owasp.esapi.i18n.ObjectResourceBundle=function(e,d){var b=new org.owasp.esapi.i18n.ResourceBundle(e.name,org.owasp.esapi.i18n.Locale.getLocale(e.locale),d);var a=e.messages;return{getParent:b.getParent,getLocale:b.getLocale,getName:b.getName,getString:b.getString,getMessage:function(f){return a[f]}}};$namespace("org.owasp.esapi.i18n");org.owasp.esapi.i18n.ResourceBundle=function(g,e,b){var f=b;var a=e;var d=g;if(!d){throw new SyntaxError("Name required for implementations of org.owasp.esapi.i18n.ResourceBundle")}if(!a){throw new SyntaxError("Locale required for implementations of org.owasp.esapi.i18n.ResourceBundle")}return{getParent:function(){return f},getLocale:function(){return a},getName:function(){return d},getMessage:function(h){return h},getString:function(l,p){if(arguments.length<1){throw new IllegalArgumentException("No key passed to getString")}var m=this.getMessage(l);if(!m){if(f){return f.getString(l,p)}else{return l}}if(!m.match(/\{([A-Za-z]+)\}/)||!p){return m}var h="",n=0;while(true){var j=m.indexOf("{",n);var k=m.indexOf("}",j);if(j<0){h+=m.substr(n,m.length-n);break}if(j>=0&&k<-1){throw new SyntaxError("Invalid Message - Unclosed Context Reference: "+m)}h+=m.substring(n,j);var i=m.substring(j+1,k);if(p[i]){h+=p[i]}else{h+=m.substring(j,k+1)}n=k+1}return h}}};org.owasp.esapi.i18n.ResourceBundle.getResourceBundle=function(sResource,oLocale){var classname=sResource+"_"+oLocale.toString().replace("-","_");with(org.owasp.esapi.i18n){if(ResourceBundle[classname] instanceof Object){return ResourceBundle[classname]}else{return new ResourceBundle[classname]()}}};$namespace("org.owasp.esapi.net");org.owasp.esapi.net.Cookie=function(g,n){var b;var m;var h;var f;var l;var p;var a;var k;var d=$ESAPI.resourceBundle();var i=",; ";var e=function(u){for(var r=0,q=u.length;r<q;r++){var t=u.charCodeAt(r),s=u.charAt(r);if(t<32||t>=127||i.indexOf(s)!=-1){return false}}return true};if(!e(g)||g.toLowerCase()=="comment"||g.toLowerCase()=="discard"||g.toLowerCase()=="domain"||g.toLowerCase()=="expires"||g.toLowerCase()=="max-age"||g.toLowerCase()=="path"||g.toLowerCase()=="secure"||g.toLowerCase()=="version"||g.charAt(0)=="$"){var j=d.getString("Cookie.Name",{name:g});throw new IllegalArgumentException(j)}b=g;m=n;return{setComment:function(q){h=q},getComment:function(){return h},setDomain:function(q){f=q.toLowerCase()},getDomain:function(){return f},setMaxAge:function(q){l=q},getMaxAge:function(){return l},setPath:function(q){p=q},getPath:function(){return p},setSecure:function(q){a=q},getSecure:function(){return a},getName:function(){return b},setValue:function(q){m=q},getValue:function(){return m
8
+ },setVersion:function(q){if(q<0||q>1){throw new IllegalArgumentException(d.getString("Cookie.Version",{version:q}))}k=q},getVersion:function(){return k}}};$namespace("org.owasp.esapi.reference.encoding");org.owasp.esapi.reference.encoding.DefaultEncoder=function(a){var h=[],k=new org.owasp.esapi.codecs.HTMLEntityCodec(),f=new org.owasp.esapi.codecs.JavascriptCodec(),g=new org.owasp.esapi.codecs.CSSCodec(),b=new org.owasp.esapi.codecs.PercentCodec();if(!a){h.push(k);h.push(f);h.push(g);h.push(b)}else{h=a}var e=new Array(",",".","-","_"," ");var d=new Array(",",".","-","_");var j=new Array();var i=new Array(",",".","_");return{cananicalize:function(r,m){if(!r){return null}var l=r,p=null,s=1,n=0,q=false;while(!q){q=true;h.each(function(u){var t=l;l=u.decode(l);if(t!=l){if(p!=null&&p!=u){s++}p=u;if(q){n++}q=false}})}if(n>=2&&s>1){if(m){throw new org.owasp.esapi.IntrusionException("Input validation failure","Multiple ("+n+"x) and mixed encoding ("+s+"x) detected in "+r)}}else{if(n>=2){if(m){throw new org.owasp.esapi.IntrusionException("Input validation failure","Multiple ("+n+"x) encoding detected in "+r)}}else{if(s>1){if(m){throw new org.owasp.esapi.IntrusionException("Input validation failure","Mixed ("+s+"x) encoding detected in "+r)}}}}return l},normalize:function(l){return l.replace(/[^\x00-\x7F]/g,"")},encodeForHTML:function(l){return !l?null:k.encode(e,l)},decodeForHTML:function(l){return !l?null:k.decode(l)},encodeForHTMLAttribute:function(l){return !l?null:k.encode(d,l)},encodeForCSS:function(l){return !l?null:g.encode(j,l)},encodeForJavaScript:function(l){return !l?null:f.encode(i,l)},encodeForJavascript:this.encodeForJavaScript,encodeForURL:function(l){return !l?null:escape(l)},decodeFromURL:function(l){return !l?null:unescape(l)},encodeForBase64:function(l){return !l?null:org.owasp.esapi.codecs.Base64.encode(l)},decodeFromBase64:function(l){return !l?null:org.owasp.esapi.codecs.Base64.decode(l)}}};$namespace("org.owasp.esapi.reference.logging");org.owasp.esapi.reference.logging.Log4JSLogFactory=function(){var d=Array();var b=function(m){var f=null;var e=m?m:null;var k=Log4js.Level;var i=false,j=false,l=false,h=$ESAPI.encoder().encodeForHTML;f=Log4js.getLogger(e);var g=function(p){var n=org.owasp.esapi.Logger;switch(p){case n.OFF:return Log4js.Level.OFF;case n.FATAL:return Log4js.Level.FATAL;case n.ERROR:return Log4js.Level.ERROR;case n.WARNING:return Log4js.Level.WARN;case n.INFO:return Log4js.Level.INFO;case n.DEBUG:return Log4js.Level.DEBUG;case n.TRACE:return Log4js.Level.TRACE;case n.ALL:return Log4js.Level.ALL}};return{setLevel:function(n){try{f.setLevel(g(n))}catch(p){this.error(org.owasp.esapi.Logger.SECURITY_FAILURE,"",p)}},trace:function(p,n,q){this.log(k.TRACE,p,n,q)},debug:function(p,n,q){this.log(k.DEBUG,p,n,q)},info:function(p,n,q){this.log(k.INFO,p,n,q)},warning:function(p,n,q){this.log(k.WARN,p,n,q)},error:function(p,n,q){this.log(k.ERROR,p,n,q)},fatal:function(p,n,q){this.log(k.FATAL,p,n,q)},log:function(s,r,p,t){switch(s){case k.TRACE:if(!f.isTraceEnabled()){return}break;case k.DEBUG:if(!f.isDebugEnabled()){return}break;case k.INFO:if(!f.isInfoEnabled()){return}break;case k.WARNING:if(!f.isWarnEnabled()){return}break;case k.ERROR:if(!f.isErrorEnabled()){return}break;case k.FATAL:if(!f.isFatalEnabled()){return}break}if(!p){p=""}p="["+r.toString()+"] - "+p;var n=p.replace("\n","_").replace("\r","_");if(l){n=h(n);if(n!=p){n+=" [Encoded]"}}var q=(i?window.location.href:"")+(j?"/"+$ESAPI.properties.application.Name:"");f.log(s,(q!=""?"["+q+"] ":"")+n,t)},addAppender:function(n){f.addAppender(n)},isLogUrl:function(){return i},setLogUrl:function(n){i=n},isLogApplicationName:function(){return j},setLogApplicationName:function(n){j=n},isEncodingRequired:function(){return l},setEncodingRequired:function(n){l=n},setEncodingFunction:function(n){h=n},isDebugEnabled:function(){return f.isDebugEnabled()},isErrorEnabled:function(){return f.isErrorEnabled()},isFatalEnabled:function(){return f.isFatalEnabled()},isInfoEnabled:function(){return f.isInfoEnabled()},isTraceEnabled:function(){return f.isTraceEnabled()},isWarningEnabled:function(){return f.isWarnEnabled()}}};var a=function(f){var e=$ESAPI.properties.logging;if(e[f]){e=e[f]}return e};return{getLogger:function(g){var h=(typeof g=="string")?g:g.constructor.toString();var f=d[h];if(!f){f=new b(h);var e=a(g);f.setLevel(e.Level);f.setLogUrl(e.LogUrl);f.setLogApplicationName(e.LogApplicationName);f.setEncodingRequired(e.EncodingRequired);if(e.EncodingFunction){f.setEncodingFunction(e.EncodingFunction)}e.Appenders.each(function(i){if(e.Layout){i.setLayout(e.Layout)}f.addAppender(i)});d[h]=f}return f}}};$namespace("org.owasp.esapi.reference.validation");org.owasp.esapi.reference.validation.BaseValidationRule=function(f,h,a){var g=$ESAPI.logger("Validation");var b=org.owasp.esapi.Logger.EventType;var i=f;var j=h?h:$ESAPI.encoder();var l=false;var e=org.owasp.esapi.i18n.ResourceBundle;var k=a?a:$ESAPI.locale();var d;if($ESAPI.properties.validation.ResourceBundle){d=e.getResourceBundle($ESAPI.properties.validation.ResourceBundle,k)
9
+ }if(!d){d=$ESAPI.resourceBundle();g.info(b.EVENT_FAILURE,"No Validation ResourceBundle - Defaulting to "+d.getName()+"("+d.getLocale().toString()+")")}g.info(b.EVENT_SUCCESS,"Validation Rule Initialized with ResourceBundle: "+d.getName());return{setAllowNull:function(m){l=m},isAllowNull:function(){return l},getTypeName:function(){return i},setTypeName:function(m){i=m},setEncoder:function(m){j=m},getEncoder:function(){return j},assertValid:function(m,n){this.getValid(m,n)},getValid:function(m,p,r){var q=null;try{q=this.getValidInput(m,p)}catch(n){return this.sanitize(m,p)}return q},getValidInput:function(m,n){return n},getSafe:function(m,p){var q=null;try{q=this.getValidInput(m,p)}catch(n){return this.sanitize(m,p)}return q},sanitize:function(m,n){return n},isValid:function(m,p){var q=false;try{this.getValidInput(m,p);q=true}catch(n){return false}return q},whitelist:function(n,p){var q="";for(var m=0;m<n.length;m++){var r=n.charAt(m);if(p.contains(r)){q+=r}}return q},getUserMessage:function(p,m,n){return this.getMessage(p+".Usr",m+".Usr",n)},getLogMessage:function(p,m,n){return this.getMessage(p+".Log",m+".Log",n)},getMessage:function(p,m,n){return d.getString(p,n)?d.getString(p,n):d.getString(m,n)},validationException:function(p,m,q,n){throw new org.owasp.esapi.reference.validation.ValidationException(this.getUserMessage(p+"."+q,m+"."+q,n),this.getLogMessage(p+"."+q,m+"."+q,n),p)}}};$namespace("org.owasp.esapi.reference.validation");org.owasp.esapi.reference.validation.CreditCardValidationRule=function(b,f,a){var j=new org.owasp.esapi.reference.validation.BaseValidationRule(b,f,a);var h="CreditCard";var d=19;var g;var e=function(){var l=new RegExp($ESAPI.properties.validation.CreditCard);var k=new org.owasp.esapi.reference.validation.StringValidationRule("ccrule",j.getEncoder(),a,l);k.setMaxLength(d);k.setAllowNull(false);return k};ccRule=e();var i=function(k){var s="";var q;for(var n=0;o<k.length;n++){q=k.charAt(n);if(q.match(/[0-9]/)){s+=q}}var p=0,r=0,l=0,t=false;for(var m=s.length-1;m>=0;m--){r=parseInt(s.substring(m,n+1));if(t){l=r*2;if(l>9){l-=9}}else{l=r}p+=l;t=!t}return p%10==0};return{getMaxCardLength:function(){return d},setMaxCardLength:function(k){d=k},setAllowNull:j.setAllowNull,isAllowNull:j.isAllowNull,getTypeName:j.getTypeName,setTypeName:j.setTypeName,setEncoder:j.setEncoder,getEncoder:j.getEncoder,assertValid:j.assertValid,getValid:j.getValid,getValidInput:function(l,m){if(!m||m.trim()==""){if(this.isAllowNull()){return null}j.validationException(l,h,"Required",{context:l,input:m})}var k=g.getValid(l,m);if(!i(k)){j.validationException(l,h,"Invalid",{context:l,input:m})}return k},getSafe:j.getSafe,sanitize:function(k,l){return this.whitelist(l,org.owasp.esapi.EncoderConstants.CHAR_DIGITS)},isValid:j.isValid,whitelist:j.whitelist}};$namespace("org.owasp.esapi.reference.validation");org.owasp.esapi.reference.validation.DateValidationRule=function(a,d,b){var f=new org.owasp.esapi.reference.validation.BaseValidationRule(a,d,b);var h="Date";var g=DateFormat.getDateInstance();var e=function(j,k){if(!j||j.trim()==""){if(f.isAllowNull()){return null}f.validationException(j,h,"Required",{context:j,input:k,format:g})}var i=f.getEncoder().cananicalize(k);try{return g.parse(i)}catch(l){f.validationException(j,h,"Invalid",{context:j,input:k,format:g})}};return{setDateFormat:function(i){if(!i){throw new IllegalArgumentException("DateValidationRule.setDateFormat requires a non-null DateFormat")}g=i},setAllowNull:f.setAllowNull,isAllowNull:f.isAllowNull,getTypeName:f.getTypeName,setTypeName:f.setTypeName,setEncoder:f.setEncoder,getEncoder:f.getEncoder,assertValid:f.assertValid,getValid:f.getValid,getValidInput:function(i,j){return e(i,j)},getSafe:f.getSafe,sanitize:function(i,k){var j=new Date(0);try{j=e(i,k)}catch(l){}return j},isValid:f.isValid,whitelist:f.whitelist}};$namespace("org.owasp.esapi.reference.validation");org.owasp.esapi.reference.validation.DefaultValidator=function(e,b){var g=Array();var d=e?e:$ESAPI.encoder();var a=b?b:org.owasp.esapi.i18n.Locale.getDefault();var f=org.owasp.esapi.reference.validation;return{addRule:function(h){g[h.getName()]=h},getRule:function(h){return g[h]},isValidInput:function(h,k,m,j,i){try{this.getValidInput(h,k,m,j,i);return true}catch(l){return false}},getValidInput:function(i,q,h,l,k,r){var n=new org.owasp.esapi.reference.validation.StringValidationRule(h,d,a);var j=new RegExp($ESAPI.properties.validation[h]);if(j&&j instanceof RegExp){n.addWhitelistPattern(j)}else{throw new IllegalArgumentException("Invalid Type: "+h+" not found.")}n.setMaxLength(l);n.setAllowNull(k);try{return n.getValid(i,q)}catch(m){if(m instanceof j.ValidationErrorList&&r){r.addError(i,m)}throw m}},isValidDate:function(i,k,h,j){try{this.getValidDate(i,k,h,j);return true}catch(l){return false}},getValidDate:function(i,k,h,j,n){var l=new f.DateValidationRule(i,d,a);l.setAllowNull(j);l.setDateFormat(h);try{return l.getValid(i,k)}catch(m){if(m instanceof f.ValidationErrorList&&n){n.addError(i,m)
10
+ }throw m}},getValidCreditCard:function(h,j,i,m){var k=new f.CreditCardValidationRule(h,d,a);k.setAllowNull(i);try{return k.getValid(h,j)}catch(l){if(l instanceof f.ValidationErrorList&&m){m.addError(h,l)}throw l}},isValidCreditCard:function(h,j,i){try{this.getValidCreditCard(h,j,i);return true}catch(k){return false}},getValidNumber:function(i,k,j,n,p,m){var h=new f.NumberValidationRule(i,d,a,n,p);h.setAllowNull(j);try{return h.getValid(i,k)}catch(l){if(l instanceof f.ValidationErrorList&&m){m.addError(i,l)}throw l}},isValidNumber:function(h,j,i,l,m){try{this.getValidNumber(h,j,i,l,m);return true}catch(k){return false}},getValidInteger:function(i,k,j,n,p,m){var h=new f.IntegerValidationRule(i,d,a,n,p);h.setAllowNull(j);try{return h.getValid(i,k)}catch(l){if(l instanceof f.ValidationErrorList&&m){m.addError(i,l)}throw l}},isValidInteger:function(h,j,i,l,m){try{this.getValidInteger(h,j,i,l,m);return true}catch(k){return false}}}};$namespace("org.owasp.esapi.reference.validation");org.owasp.esapi.reference.validation.IntegerValidationRule=function(b,e,a,k,h){var j=new org.owasp.esapi.reference.validation.BaseValidationRule(b,e,a);var d="Integer";var i=k?k:Number.MIN_VALUE;var f=h?h:Number.MAX_VALUE;if(i>=f){throw new IllegalArgumentException("minValue must be less than maxValue")}var g=function(m,p){if(!p||p.trim()==""){if(j.allowNull()){return null}j.validationException(m,d,"Required",{context:m,input:p,minValue:i,maxValue:f})}var l=j.getEncoder().cananicalize(p);var q=parseInt(l);if(q=="NaN"){j.validationException(m,d,"NaN",{context:m,input:p,minValue:i,maxValue:f})}if(q<i){j.validationException(m,d,"MinValue",{context:m,input:p,minValue:i,maxValue:f})}if(q>f){j.validationException(m,d,"MaxValue",{context:m,input:p,minValue:i,maxValue:f})}return q};return{setMinValue:function(l){i=l},getMinValue:function(){return i},setMaxValue:function(l){f=l},getMaxValue:function(){return f},setAllowNull:j.setAllowNull,isAllowNull:j.isAllowNull,getTypeName:j.getTypeName,setTypeName:j.setTypeName,setEncoder:j.setEncoder,getEncoder:j.getEncoder,assertValid:j.assertValid,getValid:j.getValid,getValidInput:function(l,m){return g(l,m)},getSafe:j.getSafe,sanitize:function(l,m){var q=0;try{q=g(l,m)}catch(p){}return q},isValid:j.isValid,whitelist:j.whitelist}};$namespace("org.owasp.esapi.reference.validation");org.owasp.esapi.reference.validation.NumberValidationRule=function(b,f,a,h,e){var k=new org.owasp.esapi.reference.validation.BaseValidationRule(b,f,a);var d="Number";var j=h?h:Number.MIN_VALUE;var g=e?e:Number.MAX_VALUE;if(j>=g){throw new IllegalArgumentException("MinValue must be less that MaxValue")}var i=function(m,n){if(!n||n.trim()==""){if(k.isAllowNull()){return null}k.validationException(m,d,"Required",{context:m,input:n,minValue:j,maxValue:g})}var l=k.getEncoder().cananicalize(n);var p=0;try{p=parseFloat(l)}catch(q){k.validationException(m,d,"Invalid",{context:m,input:n,minValue:j,maxValue:g})}if(p=="NaN"){k.validationException(m,d,"NaN",{context:m,input:n,minValue:j,maxValue:g})}if(p<j){k.validationException(m,d,"MinValue",{context:m,input:n,minValue:j,maxValue:g})}if(p>g){k.validationException(m,d,"MaxValue",{context:m,input:n,minValue:j,maxValue:g})}return p};return{setMinValue:function(l){j=l},getMinValue:function(){return j},setMaxValue:function(l){g=l},getMaxValue:function(){return g},setAllowNull:k.setAllowNull,isAllowNull:k.isAllowNull,getTypeName:k.getTypeName,setTypeName:k.setTypeName,setEncoder:k.setEncoder,getEncoder:k.getEncoder,assertValid:k.assertValid,getValid:k.getValid,getValidInput:function(l,m){return i(l,m)},getSafe:k.getSafe,sanitize:function(l,m){var q=0;try{q=i(l,m)}catch(p){}return q},isValid:k.isValid,whitelist:k.whitelist}};$namespace("org.owasp.esapi.reference.validation");org.owasp.esapi.reference.validation.StringValidationRule=function(g,l,a,p){var q=new org.owasp.esapi.reference.validation.BaseValidationRule(g,l,a);var h="String";var n=Array();var f=Array();var e=0;var b=Number.MAX_VALUE;var m=true;if(p){if(p instanceof String){n.push(new RegExp(p))}else{if(p instanceof RegExp){n.push(p)}else{throw new IllegalArgumentException("sWhiteListPattern must be a string containing RegExp or a RegExp Object")}}}var k=function(r,t,s){n.each(function(u){if(t.match(u)){q.validationException(r,h,"Whitelist",{context:r,input:t,orig:s,pattern:u.toString(),minLength:e,maxLength:b,validateInputAndCanonical:m})}})};var j=function(r,t,s){f.each(function(u){if(t.match(u)){q.validationException(r,h,"Blacklist",{context:r,input:t,orig:s,pattern:u.toString(),minLength:e,maxLength:b,validateInputAndCanonical:m})}})};var d=function(r,t,s){if(t.length<e){q.validationException(r,h,"MinLength",{context:r,input:t,orig:s,minLength:e,maxLength:b,validateInputAndCanonical:m})}if(t.length>b){q.validationException(r,h,"MaxLength",{context:r,input:t,orig:s,minLength:e,maxLength:b,validateInputAndCanonical:m})}return t};var i=function(r,t,s){if(!t||t.trim()==""){if(q.isAllowNull()){return null}q.validationException(r,h,"Required",{context:r,input:t,orig:s,minLength:e,maxLength:b,validateInputAndCanonical:m})
11
+ }};return{addWhitelistPattern:function(r){if(r instanceof String){n.push(new RegExp(r))}else{if(r instanceof RegExp){n.push(r)}else{throw new IllegalArgumentException("p must be a string containing RegExp or a RegExp Object")}}},addBlacklistPattern:function(r){if(r instanceof String){f.push(new RegExp(r))}else{if(r instanceof RegExp){f.push(r)}else{throw new IllegalArgumentException("p must be a string containing RegExp or a RegExp Object")}}},setMinLength:function(r){e=r},getMinLength:function(){return e},setMaxLength:function(r){b=r},getMaxLength:function(){return b},setValidateInputAndCanonical:function(r){m=r},isValidateInputAndCanonical:function(){return m},setAllowNull:q.setAllowNull,isAllowNull:q.isAllowNull,getTypeName:q.getTypeName,setTypeName:q.setTypeName,setEncoder:q.setEncoder,getEncoder:q.getEncoder,assertValid:q.assertValid,getValid:q.getValid,getValidInput:function(s,t){var r=null;if(i(s,t)==null){return null}if(m){d(s,t);k(s,t);j(s,t)}r=this.getEncoder().cananicalize(t);if(i(s,r,t)==null){return null}d(s,r,t);k(s,r,t);j(s,r,t);return r},getSafe:q.getSafe,sanitize:function(r,s){return this.whitelist(s,org.owasp.esapi.EncoderConstants.CHAR_ALNUM)},isValid:q.isValid,whitelist:q.whitelist}};$namespace("org.owasp.esapi.reference.validation");org.owasp.esapi.reference.validation.ValidationException=function(d,b){var f,a;if(arguments[2]&&arguments[2] instanceof Exception){f=arguments[2];if(arguments[3]&&arguments[3] instanceof String){a=arguments[3]}}else{if(arguments[2]&&arguments[2] instanceof String){a=arguments[2]}}var e=new org.owasp.esapi.EnterpriseSecurityException(d,b,f);return{setContext:function(g){a=g},getContext:function(){return a},getMessage:e.getMessage,getUserMessage:e.getMessage,getLogMessage:e.getLogMessage,getStackTrace:e.getStackTrace,printStackTrace:e.printStackTrace}};
@@ -0,0 +1 @@
1
+ var Log4js={version:"1.0",applicationStartDate:new Date(),loggers:{},getLogger:function(categoryName){if(!(typeof categoryName=="string")){categoryName="[default]";}if(!Log4js.loggers[categoryName]){Log4js.loggers[categoryName]=new Log4js.Logger(categoryName);}return Log4js.loggers[categoryName];},getDefaultLogger:function(){return Log4js.getLogger("[default]");},attachEvent:function(element,name,observer){if(element.addEventListener){element.addEventListener(name,observer,false);}else if(element.attachEvent){element.attachEvent('on'+name,observer);}}};Log4js.extend=function(destination,source){for(property in source){destination[property]=source[property];}return destination;}Log4js.bind=function(fn,object){return function(){return fn.apply(object,arguments);};};Log4js.Level=function(level,levelStr){this.level=level;this.levelStr=levelStr;};Log4js.Level.prototype={toLevel:function(sArg,defaultLevel){if(sArg===null){return defaultLevel;}if(typeof sArg=="string"){var s=sArg.toUpperCase();if(s=="ALL"){return Log4js.Level.ALL;}if(s=="DEBUG"){return Log4js.Level.DEBUG;}if(s=="INFO"){return Log4js.Level.INFO;}if(s=="WARN"){return Log4js.Level.WARN;}if(s=="ERROR"){return Log4js.Level.ERROR;}if(s=="FATAL"){return Log4js.Level.FATAL;}if(s=="OFF"){return Log4js.Level.OFF;}if(s=="TRACE"){return Log4js.Level.TRACE;}return defaultLevel;}else if(typeof sArg=="number"){switch(sArg){case ALL_INT:return Log4js.Level.ALL;case DEBUG_INT:return Log4js.Level.DEBUG;case INFO_INT:return Log4js.Level.INFO;case WARN_INT:return Log4js.Level.WARN;case ERROR_INT:return Log4js.Level.ERROR;case FATAL_INT:return Log4js.Level.FATAL;case OFF_INT:return Log4js.Level.OFF;case TRACE_INT:return Log4js.Level.TRACE;default:return defaultLevel;}}else{return defaultLevel;}},toString:function(){return this.levelStr;},valueOf:function(){return this.level;}};Log4js.Level.OFF_INT=Number.MAX_VALUE;Log4js.Level.FATAL_INT=50000;Log4js.Level.ERROR_INT=40000;Log4js.Level.WARN_INT=30000;Log4js.Level.INFO_INT=20000;Log4js.Level.DEBUG_INT=10000;Log4js.Level.TRACE_INT=5000;Log4js.Level.ALL_INT=Number.MIN_VALUE;Log4js.Level.OFF=new Log4js.Level(Log4js.Level.OFF_INT,"OFF");Log4js.Level.FATAL=new Log4js.Level(Log4js.Level.FATAL_INT,"FATAL");Log4js.Level.ERROR=new Log4js.Level(Log4js.Level.ERROR_INT,"ERROR");Log4js.Level.WARN=new Log4js.Level(Log4js.Level.WARN_INT,"WARN");Log4js.Level.INFO=new Log4js.Level(Log4js.Level.INFO_INT,"INFO");Log4js.Level.DEBUG=new Log4js.Level(Log4js.Level.DEBUG_INT,"DEBUG");Log4js.Level.TRACE=new Log4js.Level(Log4js.Level.TRACE_INT,"TRACE");Log4js.Level.ALL=new Log4js.Level(Log4js.Level.ALL_INT,"ALL");Log4js.CustomEvent=function(){this.listeners=[];};Log4js.CustomEvent.prototype={addListener:function(method){this.listeners.push(method);},removeListener:function(method){var foundIndexes=this.findListenerIndexes(method);for(var i=0;i<foundIndexes.length;i++){this.listeners.splice(foundIndexes[i],1);}},dispatch:function(handler){for(var i=0;i<this.listeners.length;i++){try{this.listeners[i](handler);}catch(e){log4jsLogger.warn("Could not run the listener "+this.listeners[i]+". \n"+e);}}},findListenerIndexes:function(method){var indexes=[];for(var i=0;i<this.listeners.length;i++){if(this.listeners[i]==method){indexes.push(i);}}return indexes;}};Log4js.LoggingEvent=function(categoryName,level,message,exception,logger){this.startTime=new Date();this.categoryName=categoryName;this.message=message;this.exception=exception;this.level=level;this.logger=logger;};Log4js.LoggingEvent.prototype={getFormattedTimestamp:function(){if(this.logger){return this.logger.getFormattedTimestamp(this.startTime);}else{return this.startTime.toGMTString();}}};Log4js.Logger=function(name){this.loggingEvents=[];this.appenders=[];this.category=name||"";this.level=Log4js.Level.FATAL;this.dateformat=Log4js.DateFormatter.DEFAULT_DATE_FORMAT;this.dateformatter=new Log4js.DateFormatter();this.onlog=new Log4js.CustomEvent();this.onclear=new Log4js.CustomEvent();this.appenders.push(new Log4js.Appender(this));try{window.onerror=this.windowError.bind(this);}catch(e){}};Log4js.Logger.prototype={addAppender:function(appender){if(appender instanceof Log4js.Appender){appender.setLogger(this);this.appenders.push(appender);}else{throw "Not instance of an Appender: "+appender;}},setAppenders:function(appenders){for(var i=0;i<this.appenders.length;i++){this.appenders[i].doClear();}this.appenders=appenders;for(var j=0;j<this.appenders.length;j++){this.appenders[j].setLogger(this);}},setLevel:function(level){this.level=level;},log:function(logLevel,message,exception){var loggingEvent=new Log4js.LoggingEvent(this.category,logLevel,message,exception,this);this.loggingEvents.push(loggingEvent);this.onlog.dispatch(loggingEvent);},clear:function(){try{this.loggingEvents=[];this.onclear.dispatch();}catch(e){}},isTraceEnabled:function(){if(this.level.valueOf()<=Log4js.Level.TRACE.valueOf()){return true;}return false;},trace:function(message){if(this.isTraceEnabled()){this.log(Log4js.Level.TRACE,message,null);}},isDebugEnabled:function(){if(this.level.valueOf()<=Log4js.Level.DEBUG.valueOf()){return true;}return false;},debug:function(message){if(this.isDebugEnabled()){this.log(Log4js.Level.DEBUG,message,null);}},debug:function(message,throwable){if(this.isDebugEnabled()){this.log(Log4js.Level.DEBUG,message,throwable);}},isInfoEnabled:function(){if(this.level.valueOf()<=Log4js.Level.INFO.valueOf()){return true;}return false;},info:function(message){if(this.isInfoEnabled()){this.log(Log4js.Level.INFO,message,null);}},info:function(message,throwable){if(this.isInfoEnabled()){this.log(Log4js.Level.INFO,message,throwable);}},isWarnEnabled:function(){if(this.level.valueOf()<=Log4js.Level.WARN.valueOf()){return true;}return false;},warn:function(message){if(this.isWarnEnabled()){this.log(Log4js.Level.WARN,message,null);}},warn:function(message,throwable){if(this.isWarnEnabled()){this.log(Log4js.Level.WARN,message,throwable);}},isErrorEnabled:function(){if(this.level.valueOf()<=Log4js.Level.ERROR.valueOf()){return true;}return false;},error:function(message){if(this.isErrorEnabled()){this.log(Log4js.Level.ERROR,message,null);}},error:function(message,throwable){if(this.isErrorEnabled()){this.log(Log4js.Level.ERROR,message,throwable);}},isFatalEnabled:function(){if(this.level.valueOf()<=Log4js.Level.FATAL.valueOf()){return true;}return false;},fatal:function(message){if(this.isFatalEnabled()){this.log(Log4js.Level.FATAL,message,null);}},fatal:function(message,throwable){if(this.isFatalEnabled()){this.log(Log4js.Level.FATAL,message,throwable);}},windowError:function(msg,url,line){var message="Error in ("+(url||window.location)+") on line "+line+" with message ("+msg+")";this.log(Log4js.Level.FATAL,message,null);},setDateFormat:function(format){this.dateformat=format;},getFormattedTimestamp:function(date){return this.dateformatter.formatDate(date,this.dateformat);}};Log4js.Appender=function(){this.logger=null;};Log4js.Appender.prototype={doAppend:function(loggingEvent){return;},doClear:function(){return;},setLayout:function(layout){this.layout=layout;},setLogger:function(logger){logger.onlog.addListener(Log4js.bind(this.doAppend,this));logger.onclear.addListener(Log4js.bind(this.doClear,this));this.logger=logger;}};Log4js.Layout=function(){return;};Log4js.Layout.prototype={format:function(loggingEvent){return "";},getContentType:function(){return "text/plain";},getHeader:function(){return null;},getFooter:function(){return null;},getSeparator:function(){return "";}};Log4js.ConsoleAppender=function(isInline){this.layout=new Log4js.PatternLayout(Log4js.PatternLayout.TTCC_CONVERSION_PATTERN);this.inline=isInline;this.accesskey="d";this.tagPattern=null;this.commandHistory=[];this.commandIndex=0;this.popupBlocker=false;this.outputElement=null;this.docReference=null;this.winReference=null;if(this.inline){Log4js.attachEvent(window,'load',Log4js.bind(this.initialize,this));}};Log4js.ConsoleAppender.prototype=Log4js.extend(new Log4js.Appender(),{setAccessKey:function(key){this.accesskey=key;},initialize:function(){if(!this.inline){var doc=null;var win=null;window.top.consoleWindow=window.open("",this.logger.category,"left=0,top=0,width=700,height=700,scrollbars=no,status=no,resizable=yes;toolbar=no");window.top.consoleWindow.opener=self;win=window.top.consoleWindow;if(!win){this.popupBlocker=true;alert("Popup window manager blocking the Log4js popup window to bedisplayed.\n\n"+"Please disabled this to properly see logged events.");}else{doc=win.document;doc.open();doc.write("<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN ");doc.write(" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>\n\n");doc.write("<html><head><title>Log4js - "+this.logger.category+"</title>\n");doc.write("</head><body style=\"background-color:darkgray\"></body>\n");win.blur();win.focus();}this.docReference=doc;this.winReference=win;}else{this.docReference=document;this.winReference=window;}this.outputCount=0;this.tagPattern=".*";this.logElement=this.docReference.createElement('div');this.docReference.body.appendChild(this.logElement);this.logElement.style.display='none';this.logElement.style.position="absolute";this.logElement.style.left='0px';this.logElement.style.width='100%';this.logElement.style.textAlign="left";this.logElement.style.fontFamily="lucida console";this.logElement.style.fontSize="100%";this.logElement.style.backgroundColor='darkgray';this.logElement.style.opacity=0.9;this.logElement.style.zIndex=2000;this.toolbarElement=this.docReference.createElement('div');this.logElement.appendChild(this.toolbarElement);this.toolbarElement.style.padding="0 0 0 2px";this.buttonsContainerElement=this.docReference.createElement('span');this.toolbarElement.appendChild(this.buttonsContainerElement);if(this.inline){var closeButton=this.docReference.createElement('button');closeButton.style.cssFloat="right";closeButton.style.styleFloat="right";closeButton.style.color="black";closeButton.innerHTML="close";closeButton.onclick=Log4js.bind(this.toggle,this);this.buttonsContainerElement.appendChild(closeButton);}var clearButton=this.docReference.createElement('button');clearButton.style.cssFloat="right";clearButton.style.styleFloat="right";clearButton.style.color="black";clearButton.innerHTML="clear";clearButton.onclick=Log4js.bind(this.logger.clear,this.logger);this.buttonsContainerElement.appendChild(clearButton);this.tagFilterContainerElement=this.docReference.createElement('span');this.toolbarElement.appendChild(this.tagFilterContainerElement);this.tagFilterContainerElement.style.cssFloat='left';this.tagFilterContainerElement.appendChild(this.docReference.createTextNode("Log4js - "+this.logger.category));this.tagFilterContainerElement.appendChild(this.docReference.createTextNode(" | Level Filter: "));this.tagFilterElement=this.docReference.createElement('input');this.tagFilterContainerElement.appendChild(this.tagFilterElement);this.tagFilterElement.style.width='200px';this.tagFilterElement.value=this.tagPattern;this.tagFilterElement.setAttribute('autocomplete','off');Log4js.attachEvent(this.tagFilterElement,'keyup',Log4js.bind(this.updateTags,this));Log4js.attachEvent(this.tagFilterElement,'click',Log4js.bind(function(){this.tagFilterElement.select();},this));this.outputElement=this.docReference.createElement('div');this.logElement.appendChild(this.outputElement);this.outputElement.style.overflow="auto";this.outputElement.style.clear="both";this.outputElement.style.height=(this.inline)?("200px"):("650px");this.outputElement.style.width="100%";this.outputElement.style.backgroundColor='black';this.inputContainerElement=this.docReference.createElement('div');this.inputContainerElement.style.width="100%";this.logElement.appendChild(this.inputContainerElement);this.inputElement=this.docReference.createElement('input');this.inputContainerElement.appendChild(this.inputElement);this.inputElement.style.width='100%';this.inputElement.style.borderWidth='0px';this.inputElement.style.margin='0px';this.inputElement.style.padding='0px';this.inputElement.value='Type command here';this.inputElement.setAttribute('autocomplete','off');Log4js.attachEvent(this.inputElement,'keyup',Log4js.bind(this.handleInput,this));Log4js.attachEvent(this.inputElement,'click',Log4js.bind(function(){this.inputElement.select();},this));if(this.inline){window.setInterval(Log4js.bind(this.repositionWindow,this),500);this.repositionWindow();var accessElement=this.docReference.createElement('button');accessElement.style.position="absolute";accessElement.style.top="-100px";accessElement.accessKey=this.accesskey;accessElement.onclick=Log4js.bind(this.toggle,this);this.docReference.body.appendChild(accessElement);}else{this.show();}},toggle:function(){if(this.logElement.style.display=='none'){this.show();return true;}else{this.hide();return false;}},show:function(){this.logElement.style.display='';this.outputElement.scrollTop=this.outputElement.scrollHeight;this.inputElement.select();},hide:function(){this.logElement.style.display='none';},output:function(message,style){var shouldScroll=(this.outputElement.scrollTop+(2*this.outputElement.clientHeight))>=this.outputElement.scrollHeight;this.outputCount++;style=(style?style+=';':'');style+='padding:1px;margin:0 0 5px 0';if(this.outputCount%2===0){style+=";background-color:#101010";}message=message||"undefined";message=message.toString();this.outputElement.innerHTML+="<pre style='"+style+"'>"+message+"</pre>";if(shouldScroll){this.outputElement.scrollTop=this.outputElement.scrollHeight;}},updateTags:function(){var pattern=this.tagFilterElement.value;if(this.tagPattern==pattern){return;}try{new RegExp(pattern);}catch(e){return;}this.tagPattern=pattern;this.outputElement.innerHTML="";this.outputCount=0;for(var i=0;i<this.logger.loggingEvents.length;i++){this.doAppend(this.logger.loggingEvents[i]);}},repositionWindow:function(){var offset=window.pageYOffset||this.docReference.documentElement.scrollTop||this.docReference.body.scrollTop;var pageHeight=self.innerHeight||this.docReference.documentElement.clientHeight||this.docReference.body.clientHeight;this.logElement.style.top=(offset+pageHeight-this.logElement.offsetHeight)+"px";},doAppend:function(loggingEvent){if(this.popupBlocker){return;}if((!this.inline)&&(!this.winReference||this.winReference.closed)){this.initialize();}if(this.tagPattern!==null&&loggingEvent.level.toString().search(new RegExp(this.tagPattern,'igm'))==-1){return;}var style='';if(loggingEvent.level.toString().search(/ERROR/)!=-1){style+='color:red';}else if(loggingEvent.level.toString().search(/FATAL/)!=-1){style+='color:red';}else if(loggingEvent.level.toString().search(/WARN/)!=-1){style+='color:orange';}else if(loggingEvent.level.toString().search(/DEBUG/)!=-1){style+='color:green';}else if(loggingEvent.level.toString().search(/INFO/)!=-1){style+='color:white';}else{style+='color:yellow';}this.output(this.layout.format(loggingEvent),style);},doClear:function(){this.outputElement.innerHTML="";},handleInput:function(e){if(e.keyCode==13){var command=this.inputElement.value;switch(command){case "clear":this.logger.clear();break;default:var consoleOutput="";try{consoleOutput=eval(this.inputElement.value);}catch(e){this.logger.error("Problem parsing input <"+command+">"+e.message);break;}this.logger.trace(consoleOutput);break;}if(this.inputElement.value!==""&&this.inputElement.value!==this.commandHistory[0]){this.commandHistory.unshift(this.inputElement.value);}this.commandIndex=0;this.inputElement.value="";}else if(e.keyCode==38&&this.commandHistory.length>0){this.inputElement.value=this.commandHistory[this.commandIndex];if(this.commandIndex<this.commandHistory.length-1){this.commandIndex+=1;}}else if(e.keyCode==40&&this.commandHistory.length>0){if(this.commandIndex>0){this.commandIndex-=1;}this.inputElement.value=this.commandHistory[this.commandIndex];}else{this.commandIndex=0;}},toString:function(){return "Log4js.ConsoleAppender[inline="+this.inline+"]";}});Log4js.MetatagAppender=function(){this.currentLine=0;};Log4js.MetatagAppender.prototype=Log4js.extend(new Log4js.Appender(),{doAppend:function(loggingEvent){var now=new Date();var lines=loggingEvent.message.split("\n");var headTag=document.getElementsByTagName("head")[0];for(var i=1;i<=lines.length;i++){var value=lines[i-1];if(i==1){value=loggingEvent.level.toString()+": "+value;}else{value="> "+value;}var metaTag=document.createElement("meta");metaTag.setAttribute("name","X-log4js:"+this.currentLine);metaTag.setAttribute("content",value);headTag.appendChild(metaTag);this.currentLine+=1;}},toString:function(){return "Log4js.MetatagAppender";}});Log4js.AjaxAppender=function(loggingUrl){this.isInProgress=false;this.loggingUrl=loggingUrl||"logging.log4js";this.threshold=1;this.timeout=2000;this.loggingEventMap=new Log4js.FifoBuffer();this.layout=new Log4js.XMLLayout();this.httpRequest=null;};Log4js.AjaxAppender.prototype=Log4js.extend(new Log4js.Appender(),{doAppend:function(loggingEvent){log4jsLogger.trace("> AjaxAppender.append");if(this.loggingEventMap.length()<=this.threshold||this.isInProgress===true){this.loggingEventMap.push(loggingEvent);}if(this.loggingEventMap.length()>=this.threshold&&this.isInProgress===false){this.send();}log4jsLogger.trace("< AjaxAppender.append");},doClear:function(){log4jsLogger.trace("> AjaxAppender.doClear");if(this.loggingEventMap.length()>0){this.send();}log4jsLogger.trace("< AjaxAppender.doClear");},setThreshold:function(threshold){log4jsLogger.trace("> AjaxAppender.setThreshold: "+threshold);this.threshold=threshold;log4jsLogger.trace("< AjaxAppender.setThreshold");},setTimeout:function(milliseconds){this.timeout=milliseconds;},send:function(){if(this.loggingEventMap.length()>0){log4jsLogger.trace("> AjaxAppender.send");this.isInProgress=true;var a=[];for(var i=0;i<this.loggingEventMap.length()&&i<this.threshold;i++){a.push(this.layout.format(this.loggingEventMap.pull()));}var content=this.layout.getHeader();content+=a.join(this.layout.getSeparator());content+=this.layout.getFooter();var appender=this;if(this.httpRequest===null){this.httpRequest=this.getXmlHttpRequest();}this.httpRequest.onreadystatechange=function(){appender.onReadyStateChanged.call(appender);};this.httpRequest.open("POST",this.loggingUrl,true);this.httpRequest.setRequestHeader("Content-type",this.layout.getContentType());this.httpRequest.setRequestHeader("REFERER",location.href);this.httpRequest.setRequestHeader("Content-length",content.length);this.httpRequest.setRequestHeader("Connection","close");this.httpRequest.send(content);appender=this;try{window.setTimeout(function(){log4jsLogger.trace("> AjaxAppender.timeout");appender.httpRequest.onreadystatechange=function(){return;};appender.httpRequest.abort();appender.isInProgress=false;if(appender.loggingEventMap.length()>0){appender.send();}log4jsLogger.trace("< AjaxAppender.timeout");},this.timeout);}catch(e){log4jsLogger.fatal(e);}log4jsLogger.trace("> AjaxAppender.send");}},onReadyStateChanged:function(){log4jsLogger.trace("> AjaxAppender.onReadyStateChanged");var req=this.httpRequest;if(this.httpRequest.readyState!=4){log4jsLogger.trace("< AjaxAppender.onReadyStateChanged: readyState "+req.readyState+" != 4");return;}var success=((typeof req.status==="undefined")||req.status===0||(req.status>=200&&req.status<300));if(success){log4jsLogger.trace(" AjaxAppender.onReadyStateChanged: success");this.isInProgress=false;}else{var msg=" AjaxAppender.onReadyStateChanged: XMLHttpRequest request to URL "+this.loggingUrl+" returned status code "+this.httpRequest.status;log4jsLogger.error(msg);}log4jsLogger.trace("< AjaxAppender.onReadyStateChanged: readyState == 4");},getXmlHttpRequest:function(){log4jsLogger.trace("> AjaxAppender.getXmlHttpRequest");var httpRequest=false;try{if(window.XMLHttpRequest){httpRequest=new XMLHttpRequest();if(httpRequest.overrideMimeType){httpRequest.overrideMimeType(this.layout.getContentType());}}else if(window.ActiveXObject){try{httpRequest=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){httpRequest=new ActiveXObject("Microsoft.XMLHTTP");}}}catch(e){httpRequest=false;}if(!httpRequest){log4jsLogger.fatal("Unfortunatelly your browser does not support AjaxAppender for log4js!");}log4jsLogger.trace("< AjaxAppender.getXmlHttpRequest");return httpRequest;},toString:function(){return "Log4js.AjaxAppender[loggingUrl="+this.loggingUrl+", threshold="+this.threshold+"]";}});Log4js.FileAppender=function(file){this.layout=new Log4js.SimpleLayout();this.isIE='undefined';this.file=file||"log4js.log";try{this.fso=new ActiveXObject("Scripting.FileSystemObject");this.isIE=true;}catch(e){try{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");this.fso=Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);this.isIE=false;}catch(e){log4jsLogger.error(e);}}};Log4js.FileAppender.prototype=Log4js.extend(new Log4js.Appender(),{doAppend:function(loggingEvent){try{var fileHandle=null;if(this.isIE==='undefined'){log4jsLogger.error("Unsupported ")}else if(this.isIE){fileHandle=this.fso.OpenTextFile(this.file,8,true);fileHandle.WriteLine(this.layout.format(loggingEvent));fileHandle.close();}else{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");this.fso.initWithPath(this.file);if(!this.fso.exists()){this.fso.create(0x00,0600);}fileHandle=Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);fileHandle.init(this.fso,0x04|0x08|0x10,064,0);var line=this.layout.format(loggingEvent);fileHandle.write(line,line.length);fileHandle.close();}}catch(e){log4jsLogger.error(e);}},doClear:function(){try{if(this.isIE){var fileHandle=this.fso.GetFile(this.file);fileHandle.Delete();}else{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");this.fso.initWithPath(this.file);if(this.fso.exists()){this.fso.remove(false);}}}catch(e){log4jsLogger.error(e);}},toString:function(){return "Log4js.FileAppender[file="+this.file+"]";}});Log4js.WindowsEventAppender=function(){this.layout=new Log4js.SimpleLayout();try{this.shell=new ActiveXObject("WScript.Shell");}catch(e){log4jsLogger.error(e);}};Log4js.WindowsEventAppender.prototype=Log4js.extend(new Log4js.Appender(),{doAppend:function(loggingEvent){var winLevel=4;switch(loggingEvent.level){case Log4js.Level.FATAL:winLevel=1;break;case Log4js.Level.ERROR:winLevel=1;break;case Log4js.Level.WARN:winLevel=2;break;default:winLevel=4;break;}try{this.shell.LogEvent(winLevel,this.level.format(loggingEvent));}catch(e){log4jsLogger.error(e);}},toString:function(){return "Log4js.WindowsEventAppender";}});Log4js.JSAlertAppender=function(){this.layout=new Log4js.SimpleLayout();};Log4js.JSAlertAppender.prototype=Log4js.extend(new Log4js.Appender(),{doAppend:function(loggingEvent){alert(this.layout.getHeader()+this.layout.format(loggingEvent)+this.layout.getFooter());},toString:function(){return "Log4js.JSAlertAppender";}});Log4js.MozillaJSConsoleAppender=function(){this.layout=new Log4js.SimpleLayout();try{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");this.jsConsole=Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);this.scriptError=Components.classes["@mozilla.org/scripterror;1"].createInstance(Components.interfaces.nsIScriptError);}catch(e){log4jsLogger.error(e);}};Log4js.MozillaJSConsoleAppender.prototype=Log4js.extend(new Log4js.Appender(),{doAppend:function(loggingEvent){try{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");this.scriptError.init(this.layout.format(loggingEvent),null,null,null,null,this.getFlag(loggingEvent),loggingEvent.categoryName);this.jsConsole.logMessage(this.scriptError);}catch(e){log4jsLogger.error(e);}},toString:function(){return "Log4js.MozillaJSConsoleAppender";},getFlag:function(loggingEvent){var retval;switch(loggingEvent.level){case Log4js.Level.FATAL:retval=2;break;case Log4js.Level.ERROR:retval=0;break;case Log4js.Level.WARN:retval=1;break;default:retval=1;break;}return retval;}});Log4js.OperaJSConsoleAppender=function(){this.layout=new Log4js.SimpleLayout();};Log4js.OperaJSConsoleAppender.prototype=Log4js.extend(new Log4js.Appender(),{doAppend:function(loggingEvent){opera.postError(this.layout.format(loggingEvent));},toString:function(){return "Log4js.OperaJSConsoleAppender";}});Log4js.SafariJSConsoleAppender=function(){this.layout=new Log4js.SimpleLayout();};Log4js.SafariJSConsoleAppender.prototype=Log4js.extend(new Log4js.Appender(),{doAppend:function(loggingEvent){window.console.log(this.layout.format(loggingEvent));},toString:function(){return "Log4js.SafariJSConsoleAppender";}});Log4js.BrowserConsoleAppender=function(){this.consoleDelegate=null;if(window.console){this.consoleDelegate=new Log4js.SafariJSConsoleAppender();}else if(window.opera){this.consoleDelegate=new Log4js.OperaJSConsoleAppender();}else if(netscape){this.consoleDelegate=new Log4js.MozJSConsoleAppender();}else{log4jsLogger.error("Unsupported Browser");}};Log4js.BrowserConsoleAppender.prototype=Log4js.extend(new Log4js.Appender(),{doAppend:function(loggingEvent){this.consoleDelegate.doAppend(loggingEvent);},doClear:function(){this.consoleDelegate.doClear();},setLayout:function(layout){this.consoleDelegate.setLayout(layout);},toString:function(){return "Log4js.BrowserConsoleAppender: "+this.consoleDelegate.toString();}});Log4js.SimpleLayout=function(){this.LINE_SEP="\n";this.LINE_SEP_LEN=1;};Log4js.SimpleLayout.prototype=Log4js.extend(new Log4js.Layout(),{format:function(loggingEvent){return loggingEvent.level.toString()+" - "+loggingEvent.message+this.LINE_SEP;},getContentType:function(){return "text/plain";},getHeader:function(){return "";},getFooter:function(){return "";}});Log4js.BasicLayout=function(){this.LINE_SEP="\n";};Log4js.BasicLayout.prototype=Log4js.extend(new Log4js.Layout(),{format:function(loggingEvent){return loggingEvent.categoryName+"~"+loggingEvent.startTime.toLocaleString()+" ["+loggingEvent.level.toString()+"] "+loggingEvent.message+this.LINE_SEP;},getContentType:function(){return "text/plain";},getHeader:function(){return "";},getFooter:function(){return "";}});Log4js.HtmlLayout=function(){return;};Log4js.HtmlLayout.prototype=Log4js.extend(new Log4js.Layout(),{format:function(loggingEvent){return "<div style=\""+this.getStyle(loggingEvent)+"\">"+loggingEvent.getFormattedTimestamp()+" - "+loggingEvent.level.toString()+" - "+loggingEvent.message+"</div>\n";},getContentType:function(){return "text/html";},getHeader:function(){return "<html><head><title>log4js</head><body>";},getFooter:function(){return "</body></html>";},getStyle:function(loggingEvent){var style;if(loggingEvent.level.toString().search(/ERROR/)!=-1){style='color:red';}else if(loggingEvent.level.toString().search(/FATAL/)!=-1){style='color:red';}else if(loggingEvent.level.toString().search(/WARN/)!=-1){style='color:orange';}else if(loggingEvent.level.toString().search(/DEBUG/)!=-1){style='color:green';}else if(loggingEvent.level.toString().search(/INFO/)!=-1){style='color:white';}else{style='color:yellow';}return style;}});Log4js.XMLLayout=function(){return;};Log4js.XMLLayout.prototype=Log4js.extend(new Log4js.Layout(),{format:function(loggingEvent){var useragent="unknown";try{useragent=navigator.userAgent;}catch(e){useragent="unknown";}var referer="unknown";try{referer=location.href;}catch(e){referer="unknown";}var content="<log4js:event logger=\"";content+=loggingEvent.categoryName+"\" level=\"";content+=loggingEvent.level.toString()+"\" useragent=\"";content+=useragent+"\" referer=\"";content+=referer.replace(/&/g,"&amp;")+"\" timestamp=\"";content+=loggingEvent.getFormattedTimestamp()+"\">\n";content+="\t<log4js:message><![CDATA["+this.escapeCdata(loggingEvent.message)+"]]></log4js:message>\n";if(loggingEvent.exception){content+=this.formatException(loggingEvent.exception);}content+="</log4js:event>\n";return content;},getContentType:function(){return "text/xml";},getHeader:function(){return "<log4js:eventSet version=\""+Log4js.version+"\" xmlns:log4js=\"http://log4js.berlios.de/2007/log4js/\">\n";},getFooter:function(){return "</log4js:eventSet>\n";},getSeparator:function(){return "\n";},formatException:function(ex){if(ex){var exStr="\t<log4js:throwable>";if(ex.message){exStr+="\t\t<log4js:message><![CDATA["+this.escapeCdata(ex.message)+"]]></log4js:message>\n";}if(ex.description){exStr+="\t\t<log4js:description><![CDATA["+this.escapeCdata(ex.description)+"]]></log4js:description>\n";}exStr+="\t\t<log4js:stacktrace>";exStr+="\t\t\t<log4js:location fileName=\""+ex.fileName+"\" lineNumber=\""+ex.lineNumber+"\" />";exStr+="\t\t</log4js:stacktrace>";exStr="\t</log4js:throwable>";return exStr;}return null;},escapeCdata:function(str){return str.replace(/\]\]>/,"]]>]]&gt;<![CDATA[");}});Log4js.JSONLayout=function(){this.df=new Log4js.DateFormatter();};Log4js.JSONLayout.prototype=Log4js.extend(new Log4js.Layout(),{format:function(loggingEvent){var useragent="unknown";try{useragent=navigator.userAgent;}catch(e){useragent="unknown";}var referer="unknown";try{referer=location.href;}catch(e){referer="unknown";}var jsonString="{\n \"LoggingEvent\": {\n";jsonString+="\t\"logger\": \""+loggingEvent.categoryName+"\",\n";jsonString+="\t\"level\": \""+loggingEvent.level.toString()+"\",\n";jsonString+="\t\"message\": \""+loggingEvent.message+"\",\n";jsonString+="\t\"referer\": \""+referer+"\",\n";jsonString+="\t\"useragent\": \""+useragent+"\",\n";jsonString+="\t\"timestamp\": \""+this.df.formatDate(loggingEvent.startTime,"yyyy-MM-ddThh:mm:ssZ")+"\",\n";jsonString+="\t\"exception\": \""+loggingEvent.exception+"\"\n";jsonString+="}}";return jsonString;},getContentType:function(){return "text/json";},getHeader:function(){return "{\"Log4js\": [\n";},getFooter:function(){return "\n]}";},getSeparator:function(){return ",\n";}});Log4js.PatternLayout=function(pattern){if(pattern){this.pattern=pattern;}else{this.pattern=Log4js.PatternLayout.DEFAULT_CONVERSION_PATTERN;}};Log4js.PatternLayout.TTCC_CONVERSION_PATTERN="%r %p %c - %m%n";Log4js.PatternLayout.DEFAULT_CONVERSION_PATTERN="%m%n";Log4js.PatternLayout.ISO8601_DATEFORMAT="yyyy-MM-dd HH:mm:ss,SSS";Log4js.PatternLayout.DATETIME_DATEFORMAT="dd MMM YYYY HH:mm:ss,SSS";Log4js.PatternLayout.ABSOLUTETIME_DATEFORMAT="HH:mm:ss,SSS";Log4js.PatternLayout.prototype=Log4js.extend(new Log4js.Layout(),{getContentType:function(){return "text/plain";},getHeader:function(){return null;},getFooter:function(){return null;},format:function(loggingEvent){var regex= /%(-?[0-9]+)?(\.?[0-9]+)?([cdmnpr%])(\{([^\}]+)\})?|([^%]+)/;var formattedString="";var result;var searchString=this.pattern;while((result=regex.exec(searchString))){var matchedString=result[0];var padding=result[1];var truncation=result[2];var conversionCharacter=result[3];var specifier=result[5];var text=result[6];if(text){formattedString+=""+text;}else{var replacement="";switch(conversionCharacter){case "c":var loggerName=loggingEvent.categoryName;if(specifier){var precision=parseInt(specifier,10);var loggerNameBits=loggingEvent.categoryName.split(".");if(precision>=loggerNameBits.length){replacement=loggerName;}else{replacement=loggerNameBits.slice(loggerNameBits.length-precision).join(".");}}else{replacement=loggerName;}break;case "d":var dateFormat=Log4js.PatternLayout.ISO8601_DATEFORMAT;if(specifier){dateFormat=specifier;if(dateFormat=="ISO8601"){dateFormat=Log4js.PatternLayout.ISO8601_DATEFORMAT;}else if(dateFormat=="ABSOLUTE"){dateFormat=Log4js.PatternLayout.ABSOLUTETIME_DATEFORMAT;}else if(dateFormat=="DATE"){dateFormat=Log4js.PatternLayout.DATETIME_DATEFORMAT;}}replacement=(new Log4js.SimpleDateFormat(dateFormat)).format(loggingEvent.startTime);break;case "m":replacement=loggingEvent.message;break;case "n":replacement="\n";break;case "p":replacement=loggingEvent.level.toString();break;case "r":replacement=""+loggingEvent.startTime.toLocaleTimeString();break;case "%":replacement="%";break;default:replacement=matchedString;break;}var len;if(truncation){len=parseInt(truncation.substr(1),10);replacement=replacement.substring(0,len);}if(padding){if(padding.charAt(0)=="-"){len=parseInt(padding.substr(1),10);while(replacement.length<len){replacement+=" ";}}else{len=parseInt(padding,10);while(replacement.length<len){replacement=" "+replacement;}}}formattedString+=replacement;}searchString=searchString.substr(result.index+result[0].length);}return formattedString;}});if(!Array.prototype.push){Array.prototype.push=function(){var startLength=this.length;for(var i=0;i<arguments.length;i++){this[startLength+i]=arguments[i];}return this.length;};}Log4js.FifoBuffer=function(){this.array=new Array();};Log4js.FifoBuffer.prototype={push:function(obj){this.array[this.array.length]=obj;return this.array.length;},pull:function(){if(this.array.length>0){var firstItem=this.array[0];for(var i=0;i<this.array.length-1;i++){this.array[i]=this.array[i+1];}this.array.length=this.array.length-1;return firstItem;}return null;},length:function(){return this.array.length;}};Log4js.DateFormatter=function(){return;};Log4js.DateFormatter.DEFAULT_DATE_FORMAT="yyyy-MM-ddThh:mm:ssO";Log4js.DateFormatter.prototype={formatDate:function(vDate,vFormat){var vDay=this.addZero(vDate.getDate());var vMonth=this.addZero(vDate.getMonth()+1);var vYearLong=this.addZero(vDate.getFullYear());var vYearShort=this.addZero(vDate.getFullYear().toString().substring(3,4));var vYear=(vFormat.indexOf("yyyy")>-1?vYearLong:vYearShort);var vHour=this.addZero(vDate.getHours());var vMinute=this.addZero(vDate.getMinutes());var vSecond=this.addZero(vDate.getSeconds());var vTimeZone=this.O(vDate);var vDateString=vFormat.replace(/dd/g,vDay).replace(/MM/g,vMonth).replace(/y{1,4}/g,vYear);vDateString=vDateString.replace(/hh/g,vHour).replace(/mm/g,vMinute).replace(/ss/g,vSecond);vDateString=vDateString.replace(/O/g,vTimeZone);return vDateString;},addZero:function(vNumber){return((vNumber<10)?"0":"")+vNumber;},O:function(date){var os=Math.abs(date.getTimezoneOffset());var h=String(Math.floor(os/60));var m=String(os%60);h.length==1?h="0"+h:1;m.length==1?m="0"+m:1;return date.getTimezoneOffset()<0?"+"+h+m:"-"+h+m;}};var log4jsLogger=Log4js.getLogger("Log4js");log4jsLogger.addAppender(new Log4js.ConsoleAppender());log4jsLogger.setLevel(Log4js.Level.ALL);
@@ -0,0 +1,2501 @@
1
+ /*
2
+ * Licensed under the Apache License, Version 2.0 (the "License");
3
+ * you may not use this file except in compliance with the License.
4
+ * You may obtain a copy of the License at
5
+ *
6
+ * http://www.apache.org/licenses/LICENSE-2.0
7
+ *
8
+ * Unless required by applicable law or agreed to in writing, software
9
+ * distributed under the License is distributed on an "AS IS" BASIS,
10
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ * See the License for the specific language governing permissions and
12
+ * limitations under the License.
13
+ */
14
+
15
+ /*jsl:option explicit*/
16
+
17
+ /**
18
+ * @fileoverview log4js is a library to log in JavaScript in similar manner
19
+ * than in log4j for Java. The API should be nearly the same.
20
+ *
21
+ * This file contains all log4js code and is the only file required for logging.
22
+ *
23
+ * <h3>Example:</h3>
24
+ * <pre>
25
+ * var log = new Log4js.getLogger("some-category-name"); //create logger instance
26
+ * log.setLevel(Log4js.Level.TRACE); //set the Level
27
+ * log.addAppender(new ConsoleAppender(log, false)); // console that launches in new window
28
+
29
+ * // if multiple appenders are set all will log
30
+ * log.addAppender(new ConsoleAppender(log, true)); // console that is in-line in the page
31
+ * log.addAppender(new FileAppender("C:\\somefile.log")); // file appender logs to C:\\somefile.log
32
+ *
33
+ * ...
34
+ *
35
+ * //call the log
36
+ * log.trace("trace me" );
37
+ * </pre>
38
+ *
39
+ * @version 0.3
40
+ * @author Stephan Strittmatter - http://jroller.com/page/stritti
41
+ * @author Seth Chisamore - http://www.chisamore.com
42
+ * @since 2005-05-20
43
+ * Website: http://log4js.berlios.de
44
+ */
45
+ var Log4js = {
46
+
47
+ /**
48
+ * Current version of log4js.
49
+ * @static
50
+ * @final
51
+ */
52
+ version: "1.0",
53
+
54
+ /**
55
+ * Date of logger initialized.
56
+ * @static
57
+ * @final
58
+ */
59
+ applicationStartDate: new Date(),
60
+
61
+ /**
62
+ * Hashtable of loggers.
63
+ * @static
64
+ * @final
65
+ * @private
66
+ */
67
+ loggers: {},
68
+
69
+ /**
70
+ * Get a logger instance. Instance is cached on categoryName level.
71
+ * @param {String} categoryName name of category to log to.
72
+ * @return {Logger} instance of logger for the category
73
+ * @static
74
+ */
75
+ getLogger: function(categoryName) {
76
+
77
+ // Use default logger if categoryName is not specified or invalid
78
+ if (!(typeof categoryName == "string")) {
79
+ categoryName = "[default]";
80
+ }
81
+
82
+ if (!Log4js.loggers[categoryName]) {
83
+ // Create the logger for this name if it doesn't already exist
84
+ Log4js.loggers[categoryName] = new Log4js.Logger(categoryName);
85
+ }
86
+
87
+ return Log4js.loggers[categoryName];
88
+ },
89
+
90
+ /**
91
+ * Get the default logger instance.
92
+ * @return {Logger} instance of default logger
93
+ * @static
94
+ */
95
+ getDefaultLogger: function() {
96
+ return Log4js.getLogger("[default]");
97
+ },
98
+
99
+ /**
100
+ * Atatch an observer function to an elements event browser independent.
101
+ *
102
+ * @param element element to attach event
103
+ * @param name name of event
104
+ * @param observer observer method to be called
105
+ * @private
106
+ */
107
+ attachEvent: function (element, name, observer) {
108
+ if (element.addEventListener) { //DOM event model
109
+ element.addEventListener(name, observer, false);
110
+ } else if (element.attachEvent) { //M$ event model
111
+ element.attachEvent('on' + name, observer);
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Load a JS-script dynamically.
117
+ * @param {String} src
118
+ */
119
+ /* $import: function (src) {
120
+ var documentScripts = document.getElementsByTagName("script");
121
+
122
+ for (index = 0; index < documentScripts.length; ++index)
123
+ {
124
+ var documentScript = documentScripts[index];
125
+ if (documentScript.src == src) {
126
+ return false;
127
+ }
128
+ }
129
+
130
+ var script = document.createElement('script');
131
+ script.type = 'text/javascript';
132
+ script.src = src;
133
+ document.getElementsByTagName('head')[0].appendChild(script);
134
+
135
+ return true;
136
+ }
137
+ */
138
+ };
139
+
140
+ /**
141
+ * Internal object extension (OO) methods.
142
+ *
143
+ * @private
144
+ * @ignore
145
+ */
146
+ Log4js.extend = function(destination, source) {
147
+ for (property in source) {
148
+ destination[property] = source[property];
149
+ }
150
+ return destination;
151
+ }
152
+
153
+ /**
154
+ * Functions taken from Prototype library,
155
+ * didn't want to require for just few functions.
156
+ * More info at {@link http://prototype.conio.net/}
157
+ * @private
158
+ */
159
+ Log4js.bind = function(fn, object) {
160
+ return function() {
161
+ return fn.apply(object, arguments);
162
+ };
163
+ };
164
+
165
+ /**
166
+ * Log4js.Level Enumeration. Do not use directly. Use static objects instead.
167
+ * @constructor
168
+ * @param {Number} level number of level
169
+ * @param {String} levelString String representation of level
170
+ * @private
171
+ */
172
+ Log4js.Level = function(level, levelStr) {
173
+ this.level = level;
174
+ this.levelStr = levelStr;
175
+ };
176
+
177
+ Log4js.Level.prototype = {
178
+ /**
179
+ * converts given String to corresponding Level
180
+ * @param {String} sArg String value of Level
181
+ * @param {Log4js.Level} defaultLevel default Level, if no String representation
182
+ * @return Level object
183
+ * @type Log4js.Level
184
+ */
185
+ toLevel: function(sArg, defaultLevel) {
186
+
187
+ if(sArg === null) {
188
+ return defaultLevel;
189
+ }
190
+
191
+ if(typeof sArg == "string") {
192
+ var s = sArg.toUpperCase();
193
+ if(s == "ALL") {return Log4js.Level.ALL;}
194
+ if(s == "DEBUG") {return Log4js.Level.DEBUG;}
195
+ if(s == "INFO") {return Log4js.Level.INFO;}
196
+ if(s == "WARN") {return Log4js.Level.WARN;}
197
+ if(s == "ERROR") {return Log4js.Level.ERROR;}
198
+ if(s == "FATAL") {return Log4js.Level.FATAL;}
199
+ if(s == "OFF") {return Log4js.Level.OFF;}
200
+ if(s == "TRACE") {return Log4js.Level.TRACE;}
201
+ return defaultLevel;
202
+ } else if(typeof sArg == "number") {
203
+ switch(sArg) {
204
+ case ALL_INT: return Log4js.Level.ALL;
205
+ case DEBUG_INT: return Log4js.Level.DEBUG;
206
+ case INFO_INT: return Log4js.Level.INFO;
207
+ case WARN_INT: return Log4js.Level.WARN;
208
+ case ERROR_INT: return Log4js.Level.ERROR;
209
+ case FATAL_INT: return Log4js.Level.FATAL;
210
+ case OFF_INT: return Log4js.Level.OFF;
211
+ case TRACE_INT: return Log4js.Level.TRACE;
212
+ default: return defaultLevel;
213
+ }
214
+ } else {
215
+ return defaultLevel;
216
+ }
217
+ },
218
+ /**
219
+ * @return converted Level to String
220
+ * @type String
221
+ */
222
+ toString: function() {
223
+ return this.levelStr;
224
+ },
225
+ /**
226
+ * @return internal Number value of Level
227
+ * @type Number
228
+ */
229
+ valueOf: function() {
230
+ return this.level;
231
+ }
232
+ };
233
+
234
+ // Static variables
235
+ /**
236
+ * @private
237
+ */
238
+ Log4js.Level.OFF_INT = Number.MAX_VALUE;
239
+ /**
240
+ * @private
241
+ */
242
+ Log4js.Level.FATAL_INT = 50000;
243
+ /**
244
+ * @private
245
+ */
246
+ Log4js.Level.ERROR_INT = 40000;
247
+ /**
248
+ * @private
249
+ */
250
+ Log4js.Level.WARN_INT = 30000;
251
+ /**
252
+ * @private
253
+ */
254
+ Log4js.Level.INFO_INT = 20000;
255
+ /**
256
+ * @private
257
+ */
258
+ Log4js.Level.DEBUG_INT = 10000;
259
+ /**
260
+ * @private
261
+ */
262
+ Log4js.Level.TRACE_INT = 5000;
263
+ /**
264
+ * @private
265
+ */
266
+ Log4js.Level.ALL_INT = Number.MIN_VALUE;
267
+
268
+ /**
269
+ * Logging Level OFF - all disabled
270
+ * @type Log4js.Level
271
+ * @static
272
+ */
273
+ Log4js.Level.OFF = new Log4js.Level(Log4js.Level.OFF_INT, "OFF");
274
+ /**
275
+ * Logging Level Fatal
276
+ * @type Log4js.Level
277
+ * @static
278
+ */
279
+ Log4js.Level.FATAL = new Log4js.Level(Log4js.Level.FATAL_INT, "FATAL");
280
+ /**
281
+ * Logging Level Error
282
+ * @type Log4js.Level
283
+ * @static
284
+ */
285
+ Log4js.Level.ERROR = new Log4js.Level(Log4js.Level.ERROR_INT, "ERROR");
286
+ /**
287
+ * Logging Level Warn
288
+ * @type Log4js.Level
289
+ * @static
290
+ */
291
+ Log4js.Level.WARN = new Log4js.Level(Log4js.Level.WARN_INT, "WARN");
292
+ /**
293
+ * Logging Level Info
294
+ * @type Log4js.Level
295
+ * @static
296
+ */
297
+ Log4js.Level.INFO = new Log4js.Level(Log4js.Level.INFO_INT, "INFO");
298
+ /**
299
+ * Logging Level Debug
300
+ * @type Log4js.Level
301
+ * @static
302
+ */
303
+ Log4js.Level.DEBUG = new Log4js.Level(Log4js.Level.DEBUG_INT, "DEBUG");
304
+ /**
305
+ * Logging Level Trace
306
+ * @type Log4js.Level
307
+ * @static
308
+ */
309
+ Log4js.Level.TRACE = new Log4js.Level(Log4js.Level.TRACE_INT, "TRACE");
310
+ /**
311
+ * Logging Level All - All traces are enabled
312
+ * @type Log4js.Level
313
+ * @static
314
+ */
315
+ Log4js.Level.ALL = new Log4js.Level(Log4js.Level.ALL_INT, "ALL");
316
+
317
+ /**
318
+ * Log4js CustomEvent
319
+ * @constructor
320
+ * @author Corey Johnson - original code in Lumberjack (http://gleepglop.com/javascripts/logger/)
321
+ * @author Seth Chisamore - adapted for Log4js
322
+ * @private
323
+ */
324
+ Log4js.CustomEvent = function() {
325
+ this.listeners = [];
326
+ };
327
+
328
+ Log4js.CustomEvent.prototype = {
329
+
330
+ /**
331
+ * @param method method to be added
332
+ */
333
+ addListener : function(method) {
334
+ this.listeners.push(method);
335
+ },
336
+
337
+ /**
338
+ * @param method method to be removed
339
+ */
340
+ removeListener : function(method) {
341
+ var foundIndexes = this.findListenerIndexes(method);
342
+
343
+ for(var i = 0; i < foundIndexes.length; i++) {
344
+ this.listeners.splice(foundIndexes[i], 1);
345
+ }
346
+ },
347
+
348
+ /**
349
+ * @param handler
350
+ */
351
+ dispatch : function(handler) {
352
+ for(var i = 0; i < this.listeners.length; i++) {
353
+ try {
354
+ this.listeners[i](handler);
355
+ }
356
+ catch (e) {
357
+ log4jsLogger.warn("Could not run the listener " + this.listeners[i] + ". \n" + e);
358
+ }
359
+ }
360
+ },
361
+
362
+ /**
363
+ * @private
364
+ * @param method
365
+ */
366
+ findListenerIndexes : function(method) {
367
+ var indexes = [];
368
+ for(var i = 0; i < this.listeners.length; i++) {
369
+ if (this.listeners[i] == method) {
370
+ indexes.push(i);
371
+ }
372
+ }
373
+
374
+ return indexes;
375
+ }
376
+ };
377
+
378
+ /**
379
+ * Models a logging event.
380
+ * @constructor
381
+ * @param {String} categoryName name of category
382
+ * @param {Log4js.Level} level level of message
383
+ * @param {String} message message to log
384
+ * @param {Log4js.Logger} logger the associated logger
385
+ * @author Seth Chisamore
386
+ */
387
+ Log4js.LoggingEvent = function(categoryName, level, message, exception, logger) {
388
+ /**
389
+ * the timestamp of the Logging Event
390
+ * @type Date
391
+ * @private
392
+ */
393
+ this.startTime = new Date();
394
+ /**
395
+ * category of event
396
+ * @type String
397
+ * @private
398
+ */
399
+ this.categoryName = categoryName;
400
+ /**
401
+ * the logging message
402
+ * @type String
403
+ * @private
404
+ */
405
+ this.message = message;
406
+ /**
407
+ * the logging exception
408
+ * @type Exception
409
+ * @private
410
+ */
411
+ this.exception = exception;
412
+ /**
413
+ * level of log
414
+ * @type Log4js.Level
415
+ * @private
416
+ */
417
+ this.level = level;
418
+ /**
419
+ * reference to logger
420
+ * @type Log4js.Logger
421
+ * @private
422
+ */
423
+ this.logger = logger;
424
+ };
425
+
426
+ Log4js.LoggingEvent.prototype = {
427
+ /**
428
+ * get the timestamp formatted as String.
429
+ * @return {String} formatted timestamp
430
+ * @see Log4js#setDateFormat()
431
+ */
432
+ getFormattedTimestamp: function() {
433
+ if(this.logger) {
434
+ return this.logger.getFormattedTimestamp(this.startTime);
435
+ } else {
436
+ return this.startTime.toGMTString();
437
+ }
438
+ }
439
+ };
440
+
441
+ /**
442
+ * Logger to log messages to the defined appender.</p>
443
+ * Default appender is Appender, which is ignoring all messages. Please
444
+ * use setAppender() to set a specific appender (e.g. WindowAppender).
445
+ * use {@see Log4js#getLogger(String)} to get an instance.
446
+ * @constructor
447
+ * @param name name of category to log to
448
+ * @author Stephan Strittmatter
449
+ */
450
+ Log4js.Logger = function(name) {
451
+ this.loggingEvents = [];
452
+ this.appenders = [];
453
+ /** category of logger */
454
+ this.category = name || "";
455
+ /** level to be logged */
456
+ this.level = Log4js.Level.FATAL;
457
+
458
+ this.dateformat = Log4js.DateFormatter.DEFAULT_DATE_FORMAT;
459
+ this.dateformatter = new Log4js.DateFormatter();
460
+
461
+ this.onlog = new Log4js.CustomEvent();
462
+ this.onclear = new Log4js.CustomEvent();
463
+
464
+ /** appender to write in */
465
+ this.appenders.push(new Log4js.Appender(this));
466
+
467
+ // if multiple log objects are instantiated this will only log to the log
468
+ // object that is declared last can't seem to get the attachEvent method to
469
+ // work correctly
470
+ try {
471
+ window.onerror = this.windowError.bind(this);
472
+ } catch (e) {
473
+ //log4jsLogger.fatal(e);
474
+ }
475
+ };
476
+
477
+ Log4js.Logger.prototype = {
478
+
479
+ /**
480
+ * add additional appender. DefaultAppender always is there.
481
+ * @param appender additional wanted appender
482
+ */
483
+ addAppender: function(appender) {
484
+ if (appender instanceof Log4js.Appender) {
485
+ appender.setLogger(this);
486
+ this.appenders.push(appender);
487
+ } else {
488
+ throw "Not instance of an Appender: " + appender;
489
+ }
490
+ },
491
+
492
+ /**
493
+ * set Array of appenders. Previous Appenders are cleared and removed.
494
+ * @param {Array} appenders Array of Appenders
495
+ */
496
+ setAppenders: function(appenders) {
497
+ //clear first all existing appenders
498
+ for(var i = 0; i < this.appenders.length; i++) {
499
+ this.appenders[i].doClear();
500
+ }
501
+
502
+ this.appenders = appenders;
503
+
504
+ for(var j = 0; j < this.appenders.length; j++) {
505
+ this.appenders[j].setLogger(this);
506
+ }
507
+ },
508
+
509
+ /**
510
+ * Set the Loglevel default is LogLEvel.TRACE
511
+ * @param level wanted logging level
512
+ */
513
+ setLevel: function(level) {
514
+ this.level = level;
515
+ },
516
+
517
+ /**
518
+ * main log method logging to all available appenders
519
+ * @private
520
+ */
521
+ log: function(logLevel, message, exception) {
522
+ var loggingEvent = new Log4js.LoggingEvent(this.category, logLevel,
523
+ message, exception, this);
524
+ this.loggingEvents.push(loggingEvent);
525
+ this.onlog.dispatch(loggingEvent);
526
+ },
527
+
528
+ /** clear logging */
529
+ clear : function () {
530
+ try{
531
+ this.loggingEvents = [];
532
+ this.onclear.dispatch();
533
+ } catch(e){}
534
+ },
535
+ /** checks if Level Trace is enabled */
536
+ isTraceEnabled: function() {
537
+ if (this.level.valueOf() <= Log4js.Level.TRACE.valueOf()) {
538
+ return true;
539
+ }
540
+ return false;
541
+ },
542
+ /**
543
+ * Trace messages
544
+ * @param message {Object} message to be logged
545
+ */
546
+ trace: function(message) {
547
+ if (this.isTraceEnabled()) {
548
+ this.log(Log4js.Level.TRACE, message, null);
549
+ }
550
+ },
551
+ /** checks if Level Debug is enabled */
552
+ isDebugEnabled: function() {
553
+ if (this.level.valueOf() <= Log4js.Level.DEBUG.valueOf()) {
554
+ return true;
555
+ }
556
+ return false;
557
+ },
558
+ /**
559
+ * Debug messages
560
+ * @param message {Object} message to be logged
561
+ */
562
+ debug: function(message) {
563
+ if (this.isDebugEnabled()) {
564
+ this.log(Log4js.Level.DEBUG, message, null);
565
+ }
566
+ },
567
+ /**
568
+ * Debug messages
569
+ * @param {Object} message message to be logged
570
+ * @param {Throwable} throwable
571
+ */
572
+ debug: function(message, throwable) {
573
+ if (this.isDebugEnabled()) {
574
+ this.log(Log4js.Level.DEBUG, message, throwable);
575
+ }
576
+ },
577
+ /** checks if Level Info is enabled */
578
+ isInfoEnabled: function() {
579
+ if (this.level.valueOf() <= Log4js.Level.INFO.valueOf()) {
580
+ return true;
581
+ }
582
+ return false;
583
+ },
584
+ /**
585
+ * logging info messages
586
+ * @param {Object} message message to be logged
587
+ */
588
+ info: function(message) {
589
+ if (this.isInfoEnabled()) {
590
+ this.log(Log4js.Level.INFO, message, null);
591
+ }
592
+ },
593
+ /**
594
+ * logging info messages
595
+ * @param {Object} message message to be logged
596
+ * @param {Throwable} throwable
597
+ */
598
+ info: function(message, throwable) {
599
+ if (this.isInfoEnabled()) {
600
+ this.log(Log4js.Level.INFO, message, throwable);
601
+ }
602
+ },
603
+ /** checks if Level Warn is enabled */
604
+ isWarnEnabled: function() {
605
+ if (this.level.valueOf() <= Log4js.Level.WARN.valueOf()) {
606
+ return true;
607
+ }
608
+ return false;
609
+ },
610
+
611
+ /** logging warn messages */
612
+ warn: function(message) {
613
+ if (this.isWarnEnabled()) {
614
+ this.log(Log4js.Level.WARN, message, null);
615
+ }
616
+ },
617
+ /** logging warn messages */
618
+ warn: function(message, throwable) {
619
+ if (this.isWarnEnabled()) {
620
+ this.log(Log4js.Level.WARN, message, throwable);
621
+ }
622
+ },
623
+ /** checks if Level Error is enabled */
624
+ isErrorEnabled: function() {
625
+ if (this.level.valueOf() <= Log4js.Level.ERROR.valueOf()) {
626
+ return true;
627
+ }
628
+ return false;
629
+ },
630
+ /** logging error messages */
631
+ error: function(message) {
632
+ if (this.isErrorEnabled()) {
633
+ this.log(Log4js.Level.ERROR, message, null);
634
+ }
635
+ },
636
+ /** logging error messages */
637
+ error: function(message, throwable) {
638
+ if (this.isErrorEnabled()) {
639
+ this.log(Log4js.Level.ERROR, message, throwable);
640
+ }
641
+ },
642
+ /** checks if Level Fatal is enabled */
643
+ isFatalEnabled: function() {
644
+ if (this.level.valueOf() <= Log4js.Level.FATAL.valueOf()) {
645
+ return true;
646
+ }
647
+ return false;
648
+ },
649
+ /** logging fatal messages */
650
+ fatal: function(message) {
651
+ if (this.isFatalEnabled()) {
652
+ this.log(Log4js.Level.FATAL, message, null);
653
+ }
654
+ },
655
+ /** logging fatal messages */
656
+ fatal: function(message, throwable) {
657
+ if (this.isFatalEnabled()) {
658
+ this.log(Log4js.Level.FATAL, message, throwable);
659
+ }
660
+ },
661
+ /**
662
+ * Capture main window errors and log as fatal.
663
+ * @private
664
+ */
665
+ windowError: function(msg, url, line){
666
+ var message = "Error in (" + (url || window.location) + ") on line "+ line +" with message (" + msg + ")";
667
+ this.log(Log4js.Level.FATAL, message, null);
668
+ },
669
+
670
+ /**
671
+ * Set the date format of logger. Following switches are supported:
672
+ * <ul>
673
+ * <li>yyyy - The year</li>
674
+ * <li>MM - the month</li>
675
+ * <li>dd - the day of month<li>
676
+ * <li>hh - the hour<li>
677
+ * <li>mm - minutes</li>
678
+ * <li>O - timezone offset</li>
679
+ * </ul>
680
+ * @param {String} format format String for the date
681
+ * @see #getTimestamp
682
+ */
683
+ setDateFormat: function(format) {
684
+ this.dateformat = format;
685
+ },
686
+
687
+ /**
688
+ * Generates a timestamp using the format set in {Log4js.setDateFormat}.
689
+ * @param {Date} date the date to format
690
+ * @see #setDateFormat
691
+ * @return A formatted timestamp with the current date and time.
692
+ */
693
+ getFormattedTimestamp: function(date) {
694
+ return this.dateformatter.formatDate(date, this.dateformat);
695
+ }
696
+ };
697
+
698
+ /**
699
+ * Abstract base class for other appenders.
700
+ * It is doing nothing.
701
+ *
702
+ * @constructor
703
+ * @param {Log4js.Logger} logger log4js instance this appender is attached to
704
+ * @author Stephan Strittmatter
705
+ */
706
+ Log4js.Appender = function () {
707
+ /**
708
+ * Reference to calling logger
709
+ * @type Log4js.Logger
710
+ * @private
711
+ */
712
+ this.logger = null;
713
+ };
714
+
715
+ Log4js.Appender.prototype = {
716
+ /**
717
+ * appends the given loggingEvent appender specific
718
+ * @param {Log4js.LoggingEvent} loggingEvent loggingEvent to append
719
+ */
720
+ doAppend: function(loggingEvent) {
721
+ return;
722
+ },
723
+ /**
724
+ * clears the Appender
725
+ */
726
+ doClear: function() {
727
+ return;
728
+ },
729
+
730
+ /**
731
+ * Set the Layout for this appender.
732
+ * @param {Log4js.Layout} layout Layout for formatting loggingEvent
733
+ */
734
+ setLayout: function(layout){
735
+ this.layout = layout;
736
+ },
737
+ /**
738
+ * Set reference to the logger.
739
+ * @param {Log4js.Logger} the invoking logger
740
+ */
741
+ setLogger: function(logger){
742
+ // add listener to the logger methods
743
+ logger.onlog.addListener(Log4js.bind(this.doAppend, this));
744
+ logger.onclear.addListener(Log4js.bind(this.doClear, this));
745
+
746
+ this.logger = logger;
747
+ }
748
+ };
749
+
750
+ /**
751
+ * Interface for Layouts.
752
+ * Use this Layout as "interface" for other Layouts. It is doing nothing.
753
+ *
754
+ * @constructor
755
+ * @author Stephan Strittmatter
756
+ */
757
+ Log4js.Layout = function(){return;};
758
+ Log4js.Layout.prototype = {
759
+ /**
760
+ * Implement this method to create your own layout format.
761
+ * @param {Log4js.LoggingEvent} loggingEvent loggingEvent to format
762
+ * @return formatted String
763
+ * @type String
764
+ */
765
+ format: function(loggingEvent) {
766
+ return "";
767
+ },
768
+ /**
769
+ * Returns the content type output by this layout.
770
+ * @return The base class returns "text/plain".
771
+ * @type String
772
+ */
773
+ getContentType: function() {
774
+ return "text/plain";
775
+ },
776
+ /**
777
+ * @return Returns the header for the layout format. The base class returns null.
778
+ * @type String
779
+ */
780
+ getHeader: function() {
781
+ return null;
782
+ },
783
+ /**
784
+ * @return Returns the footer for the layout format. The base class returns null.
785
+ * @type String
786
+ */
787
+ getFooter: function() {
788
+ return null;
789
+ },
790
+
791
+ /**
792
+ * @return Separator between events
793
+ * @type String
794
+ */
795
+ getSeparator: function() {
796
+ return "";
797
+ }
798
+ };
799
+
800
+ /**
801
+ * Console Appender writes the logs to a console. If "inline" is
802
+ * set to "false" the console launches in another window otherwise
803
+ * the window is inline on the page and toggled on and off with "Alt-D".
804
+ * Note: At FireFox &gb; 2.0 the keystroke is little different now: "SHIFT+ALT+D".
805
+ *
806
+ * @constructor
807
+ * @extends Log4js.Appender
808
+ * @param {boolean} isInline boolean value that indicates whether the console be placed inline, default is to launch in new window
809
+ *
810
+ * @author Corey Johnson - original console code in Lumberjack (http://gleepglop.com/javascripts/logger/)
811
+ * @author Seth Chisamore - adapted for use as a log4js appender
812
+ */
813
+ Log4js.ConsoleAppender = function(isInline) {
814
+
815
+ /**
816
+ * @type Log4js.Layout
817
+ * @private
818
+ */
819
+ this.layout = new Log4js.PatternLayout(Log4js.PatternLayout.TTCC_CONVERSION_PATTERN);
820
+ /**
821
+ * @type boolean
822
+ * @private
823
+ */
824
+ this.inline = isInline;
825
+
826
+ /**
827
+ * @type String
828
+ * @private
829
+ */
830
+ this.accesskey = "d";
831
+
832
+ /**
833
+ * @private
834
+ */
835
+ this.tagPattern = null;
836
+
837
+ this.commandHistory = [];
838
+ this.commandIndex = 0;
839
+
840
+ /**
841
+ * true if popup is blocked.
842
+ */
843
+ this.popupBlocker = false;
844
+
845
+ /**
846
+ * current output div-element.
847
+ */
848
+ this.outputElement = null;
849
+
850
+ this.docReference = null;
851
+ this.winReference = null;
852
+
853
+ if(this.inline) {
854
+ Log4js.attachEvent(window, 'load', Log4js.bind(this.initialize, this));
855
+ }
856
+ };
857
+
858
+ Log4js.ConsoleAppender.prototype = Log4js.extend(new Log4js.Appender(), {
859
+
860
+ /**
861
+ * Set the access key to show/hide the inline console (default &quote;d&quote;)
862
+ * @param key access key to show/hide the inline console
863
+ */
864
+ setAccessKey : function(key) {
865
+ this.accesskey = key;
866
+ },
867
+
868
+ /**
869
+ * @private
870
+ */
871
+ initialize : function() {
872
+
873
+ if(!this.inline) {
874
+ var doc = null;
875
+ var win = null;
876
+ window.top.consoleWindow = window.open("", this.logger.category,
877
+ "left=0,top=0,width=700,height=700,scrollbars=no,status=no,resizable=yes;toolbar=no");
878
+ window.top.consoleWindow.opener = self;
879
+ win = window.top.consoleWindow;
880
+
881
+ if (!win) {
882
+ this.popupBlocker=true;
883
+ alert("Popup window manager blocking the Log4js popup window to bedisplayed.\n\n"
884
+ + "Please disabled this to properly see logged events.");
885
+ } else {
886
+
887
+ doc = win.document;
888
+ doc.open();
889
+ doc.write("<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN ");
890
+ doc.write(" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>\n\n");
891
+ doc.write("<html><head><title>Log4js - " + this.logger.category + "</title>\n");
892
+ doc.write("</head><body style=\"background-color:darkgray\"></body>\n");
893
+ win.blur();
894
+ win.focus();
895
+ }
896
+
897
+ this.docReference = doc;
898
+ this.winReference = win;
899
+ } else {
900
+ this.docReference = document;
901
+ this.winReference = window;
902
+ }
903
+
904
+ this.outputCount = 0;
905
+ this.tagPattern = ".*";
906
+
907
+ // I hate writing javascript in HTML... but what's a better alternative
908
+ this.logElement = this.docReference.createElement('div');
909
+ this.docReference.body.appendChild(this.logElement);
910
+ this.logElement.style.display = 'none';
911
+
912
+ this.logElement.style.position = "absolute";
913
+ this.logElement.style.left = '0px';
914
+ this.logElement.style.width = '100%';
915
+
916
+ this.logElement.style.textAlign = "left";
917
+ this.logElement.style.fontFamily = "lucida console";
918
+ this.logElement.style.fontSize = "100%";
919
+ this.logElement.style.backgroundColor = 'darkgray';
920
+ this.logElement.style.opacity = 0.9;
921
+ this.logElement.style.zIndex = 2000;
922
+
923
+ // Add toolbarElement
924
+ this.toolbarElement = this.docReference.createElement('div');
925
+ this.logElement.appendChild(this.toolbarElement);
926
+ this.toolbarElement.style.padding = "0 0 0 2px";
927
+
928
+ // Add buttons
929
+ this.buttonsContainerElement = this.docReference.createElement('span');
930
+ this.toolbarElement.appendChild(this.buttonsContainerElement);
931
+
932
+ if(this.inline) {
933
+ var closeButton = this.docReference.createElement('button');
934
+ closeButton.style.cssFloat = "right";
935
+ closeButton.style.styleFloat = "right"; // IE dom bug...doesn't understand cssFloat
936
+ closeButton.style.color = "black";
937
+ closeButton.innerHTML = "close";
938
+ closeButton.onclick = Log4js.bind(this.toggle, this);
939
+ this.buttonsContainerElement.appendChild(closeButton);
940
+ }
941
+
942
+ var clearButton = this.docReference.createElement('button');
943
+ clearButton.style.cssFloat = "right";
944
+ clearButton.style.styleFloat = "right"; // IE dom bug...doesn't understand cssFloat
945
+ clearButton.style.color = "black";
946
+ clearButton.innerHTML = "clear";
947
+ clearButton.onclick = Log4js.bind(this.logger.clear, this.logger);
948
+ this.buttonsContainerElement.appendChild(clearButton);
949
+
950
+
951
+ //Add CategoryName and Level Filter
952
+ this.tagFilterContainerElement = this.docReference.createElement('span');
953
+ this.toolbarElement.appendChild(this.tagFilterContainerElement);
954
+ this.tagFilterContainerElement.style.cssFloat = 'left';
955
+
956
+ this.tagFilterContainerElement.appendChild(this.docReference.createTextNode("Log4js - " + this.logger.category));
957
+ this.tagFilterContainerElement.appendChild(this.docReference.createTextNode(" | Level Filter: "));
958
+
959
+ this.tagFilterElement = this.docReference.createElement('input');
960
+ this.tagFilterContainerElement.appendChild(this.tagFilterElement);
961
+ this.tagFilterElement.style.width = '200px';
962
+ this.tagFilterElement.value = this.tagPattern;
963
+ this.tagFilterElement.setAttribute('autocomplete', 'off'); // So Firefox doesn't flip out
964
+
965
+ Log4js.attachEvent(this.tagFilterElement, 'keyup', Log4js.bind(this.updateTags, this));
966
+ Log4js.attachEvent(this.tagFilterElement, 'click', Log4js.bind( function() {this.tagFilterElement.select();}, this));
967
+
968
+ // Add outputElement
969
+ this.outputElement = this.docReference.createElement('div');
970
+ this.logElement.appendChild(this.outputElement);
971
+ this.outputElement.style.overflow = "auto";
972
+ this.outputElement.style.clear = "both";
973
+ this.outputElement.style.height = (this.inline) ? ("200px"):("650px");
974
+ this.outputElement.style.width = "100%";
975
+ this.outputElement.style.backgroundColor = 'black';
976
+
977
+ this.inputContainerElement = this.docReference.createElement('div');
978
+ this.inputContainerElement.style.width = "100%";
979
+ this.logElement.appendChild(this.inputContainerElement);
980
+
981
+ this.inputElement = this.docReference.createElement('input');
982
+ this.inputContainerElement.appendChild(this.inputElement);
983
+ this.inputElement.style.width = '100%';
984
+ this.inputElement.style.borderWidth = '0px'; // Inputs with 100% width always seem to be too large (I HATE THEM) they only work if the border, margin and padding are 0
985
+ this.inputElement.style.margin = '0px';
986
+ this.inputElement.style.padding = '0px';
987
+ this.inputElement.value = 'Type command here';
988
+ this.inputElement.setAttribute('autocomplete', 'off'); // So Firefox doesn't flip out
989
+
990
+ Log4js.attachEvent(this.inputElement, 'keyup', Log4js.bind(this.handleInput, this));
991
+ Log4js.attachEvent(this.inputElement, 'click', Log4js.bind( function() {this.inputElement.select();}, this));
992
+
993
+ if(this.inline){
994
+ window.setInterval(Log4js.bind(this.repositionWindow, this), 500);
995
+ this.repositionWindow();
996
+ // Allow acess key link
997
+ var accessElement = this.docReference.createElement('button');
998
+ accessElement.style.position = "absolute";
999
+ accessElement.style.top = "-100px";
1000
+ accessElement.accessKey = this.accesskey;
1001
+ accessElement.onclick = Log4js.bind(this.toggle, this);
1002
+ this.docReference.body.appendChild(accessElement);
1003
+ } else {
1004
+ this.show();
1005
+ }
1006
+ },
1007
+ /**
1008
+ * shows/hide an element
1009
+ * @private
1010
+ * @return true if shown
1011
+ */
1012
+ toggle : function() {
1013
+ if (this.logElement.style.display == 'none') {
1014
+ this.show();
1015
+ return true;
1016
+ } else {
1017
+ this.hide();
1018
+ return false;
1019
+ }
1020
+ },
1021
+ /**
1022
+ * @private
1023
+ */
1024
+ show : function() {
1025
+ this.logElement.style.display = '';
1026
+ this.outputElement.scrollTop = this.outputElement.scrollHeight; // Scroll to bottom when toggled
1027
+ this.inputElement.select();
1028
+ },
1029
+ /**
1030
+ * @private
1031
+ */
1032
+ hide : function() {
1033
+ this.logElement.style.display = 'none';
1034
+ },
1035
+ /**
1036
+ * @private
1037
+ * @param message
1038
+ * @style
1039
+ */
1040
+ output : function(message, style) {
1041
+
1042
+ // If we are at the bottom of the window, then keep scrolling with the output
1043
+ var shouldScroll = (this.outputElement.scrollTop + (2 * this.outputElement.clientHeight)) >= this.outputElement.scrollHeight;
1044
+
1045
+ this.outputCount++;
1046
+ style = (style ? style += ';' : '');
1047
+ style += 'padding:1px;margin:0 0 5px 0';
1048
+
1049
+ if (this.outputCount % 2 === 0) {
1050
+ style += ";background-color:#101010";
1051
+ }
1052
+
1053
+ message = message || "undefined";
1054
+ message = message.toString();
1055
+
1056
+ this.outputElement.innerHTML += "<pre style='" + style + "'>" + message + "</pre>";
1057
+
1058
+ if (shouldScroll) {
1059
+ this.outputElement.scrollTop = this.outputElement.scrollHeight;
1060
+ }
1061
+ },
1062
+
1063
+ /**
1064
+ * @private
1065
+ */
1066
+ updateTags : function() {
1067
+
1068
+ var pattern = this.tagFilterElement.value;
1069
+
1070
+ if (this.tagPattern == pattern) {
1071
+ return;
1072
+ }
1073
+
1074
+ try {
1075
+ new RegExp(pattern);
1076
+ } catch (e) {
1077
+ return;
1078
+ }
1079
+
1080
+ this.tagPattern = pattern;
1081
+
1082
+ this.outputElement.innerHTML = "";
1083
+
1084
+ // Go through each log entry again
1085
+ this.outputCount = 0;
1086
+ for (var i = 0; i < this.logger.loggingEvents.length; i++) {
1087
+ this.doAppend(this.logger.loggingEvents[i]);
1088
+ }
1089
+ },
1090
+
1091
+ /**
1092
+ * @private
1093
+ */
1094
+ repositionWindow : function() {
1095
+ var offset = window.pageYOffset || this.docReference.documentElement.scrollTop || this.docReference.body.scrollTop;
1096
+ var pageHeight = self.innerHeight || this.docReference.documentElement.clientHeight || this.docReference.body.clientHeight;
1097
+ this.logElement.style.top = (offset + pageHeight - this.logElement.offsetHeight) + "px";
1098
+ },
1099
+
1100
+ /**
1101
+ * @param loggingEvent event to be logged
1102
+ * @see Log4js.Appender#doAppend
1103
+ */
1104
+ doAppend : function(loggingEvent) {
1105
+
1106
+ if(this.popupBlocker) {
1107
+ //popup blocked, we return in this case
1108
+ return;
1109
+ }
1110
+
1111
+ if ((!this.inline) && (!this.winReference || this.winReference.closed)) {
1112
+ this.initialize();
1113
+ }
1114
+
1115
+ if (this.tagPattern !== null &&
1116
+ loggingEvent.level.toString().search(new RegExp(this.tagPattern, 'igm')) == -1) {
1117
+ return;
1118
+ }
1119
+
1120
+ var style = '';
1121
+
1122
+ if (loggingEvent.level.toString().search(/ERROR/) != -1) {
1123
+ style += 'color:red';
1124
+ } else if (loggingEvent.level.toString().search(/FATAL/) != -1) {
1125
+ style += 'color:red';
1126
+ } else if (loggingEvent.level.toString().search(/WARN/) != -1) {
1127
+ style += 'color:orange';
1128
+ } else if (loggingEvent.level.toString().search(/DEBUG/) != -1) {
1129
+ style += 'color:green';
1130
+ } else if (loggingEvent.level.toString().search(/INFO/) != -1) {
1131
+ style += 'color:white';
1132
+ } else {
1133
+ style += 'color:yellow';
1134
+ }
1135
+
1136
+ this.output(this.layout.format(loggingEvent), style);
1137
+ },
1138
+
1139
+ /**
1140
+ * @see Log4js.Appender#doClear
1141
+ */
1142
+ doClear : function() {
1143
+ this.outputElement.innerHTML = "";
1144
+ },
1145
+ /**
1146
+ * @private
1147
+ * @param e
1148
+ */
1149
+ handleInput : function(e) {
1150
+ if (e.keyCode == 13 ) {
1151
+ var command = this.inputElement.value;
1152
+
1153
+ switch(command) {
1154
+ case "clear":
1155
+ this.logger.clear();
1156
+ break;
1157
+
1158
+ default:
1159
+ var consoleOutput = "";
1160
+
1161
+ try {
1162
+ consoleOutput = eval(this.inputElement.value);
1163
+ } catch (e) {
1164
+ this.logger.error("Problem parsing input <" + command + ">" + e.message);
1165
+ break;
1166
+ }
1167
+
1168
+ this.logger.trace(consoleOutput);
1169
+ break;
1170
+ }
1171
+
1172
+ if (this.inputElement.value !== "" && this.inputElement.value !== this.commandHistory[0]) {
1173
+ this.commandHistory.unshift(this.inputElement.value);
1174
+ }
1175
+
1176
+ this.commandIndex = 0;
1177
+ this.inputElement.value = "";
1178
+ } else if (e.keyCode == 38 && this.commandHistory.length > 0) {
1179
+ this.inputElement.value = this.commandHistory[this.commandIndex];
1180
+
1181
+ if (this.commandIndex < this.commandHistory.length - 1) {
1182
+ this.commandIndex += 1;
1183
+ }
1184
+ } else if (e.keyCode == 40 && this.commandHistory.length > 0) {
1185
+ if (this.commandIndex > 0) {
1186
+ this.commandIndex -= 1;
1187
+ }
1188
+
1189
+ this.inputElement.value = this.commandHistory[this.commandIndex];
1190
+ } else {
1191
+ this.commandIndex = 0;
1192
+ }
1193
+ },
1194
+
1195
+ /**
1196
+ * toString
1197
+ */
1198
+ toString: function() {
1199
+ return "Log4js.ConsoleAppender[inline=" + this.inline + "]";
1200
+ }
1201
+ });
1202
+
1203
+ /**
1204
+ * Metatag Appender writing the logs to meta tags
1205
+ *
1206
+ * @extends Log4js.Appender
1207
+ * @constructor
1208
+ * @param logger log4js instance this appender is attached to
1209
+ * @author Stephan Strittmatter
1210
+ */
1211
+ Log4js.MetatagAppender = function() {
1212
+ this.currentLine = 0;
1213
+ };
1214
+ Log4js.MetatagAppender.prototype = Log4js.extend(new Log4js.Appender(), {
1215
+ /**
1216
+ * @param loggingEvent event to be logged
1217
+ * @see Log4js.Appender#doAppend
1218
+ */
1219
+ doAppend: function(loggingEvent) {
1220
+ var now = new Date();
1221
+ var lines = loggingEvent.message.split("\n");
1222
+ var headTag = document.getElementsByTagName("head")[0];
1223
+
1224
+ for (var i = 1; i <= lines.length; i++) {
1225
+ var value = lines[i - 1];
1226
+ if (i == 1) {
1227
+ value = loggingEvent.level.toString() + ": " + value;
1228
+ } else {
1229
+ value = "> " + value;
1230
+ }
1231
+
1232
+ var metaTag = document.createElement("meta");
1233
+ metaTag.setAttribute("name", "X-log4js:" + this.currentLine);
1234
+ metaTag.setAttribute("content", value);
1235
+ headTag.appendChild(metaTag);
1236
+ this.currentLine += 1;
1237
+ }
1238
+ },
1239
+
1240
+ /**
1241
+ * toString
1242
+ */
1243
+ toString: function() {
1244
+ return "Log4js.MetatagAppender";
1245
+ }
1246
+ });
1247
+
1248
+ /**
1249
+ * AJAX Appender sending {@link Log4js.LoggingEvent}s asynchron via
1250
+ * <code>XMLHttpRequest</code> to server.<br />
1251
+ * The {@link Log4js.LoggingEvent} is POSTed as response content and is
1252
+ * formatted by the accociated layout. Default layout is {@link Log4js.XMLLayout}.
1253
+ * The <code>threshold</code> defines when the logs
1254
+ * should be send to the server. By default every event is sent on its
1255
+ * own (threshold=1). If it is set to 10, then the events are send in groups of
1256
+ * 10 events.
1257
+ *
1258
+ * @extends Log4js.Appender
1259
+ * @constructor
1260
+ * @param {Log4js.Logger} logger log4js instance this appender is attached to
1261
+ * @param {String} loggingUrl url where appender will post log messages to
1262
+ * @author Stephan Strittmatter
1263
+ */
1264
+ Log4js.AjaxAppender = function(loggingUrl) {
1265
+
1266
+ /**
1267
+ * is still esnding data to server
1268
+ * @type boolean
1269
+ * @private
1270
+ */
1271
+ this.isInProgress = false;
1272
+
1273
+ /**
1274
+ * @type String
1275
+ * @private
1276
+ */
1277
+ this.loggingUrl = loggingUrl || "logging.log4js";
1278
+
1279
+ /**
1280
+ * @type Integer
1281
+ * @private
1282
+ */
1283
+ this.threshold = 1;
1284
+
1285
+ /**
1286
+ * timeout when request is aborted.
1287
+ * @private
1288
+ */
1289
+ this.timeout = 2000;
1290
+
1291
+ /**
1292
+ * List of LoggingEvents which should be send after threshold is reached.
1293
+ * @type Map
1294
+ * @private
1295
+ */
1296
+ this.loggingEventMap = new Log4js.FifoBuffer();
1297
+
1298
+ /**
1299
+ * @type Log4js.Layout
1300
+ * @private
1301
+ */
1302
+ this.layout = new Log4js.XMLLayout();
1303
+ /**
1304
+ * @type XMLHttpRequest
1305
+ * @private
1306
+ */
1307
+ this.httpRequest = null;
1308
+ };
1309
+
1310
+ Log4js.AjaxAppender.prototype = Log4js.extend(new Log4js.Appender(), {
1311
+ /**
1312
+ * sends the logs to the server
1313
+ * @param loggingEvent event to be logged
1314
+ * @see Log4js.Appender#doAppend
1315
+ */
1316
+ doAppend: function(loggingEvent) {
1317
+ log4jsLogger.trace("> AjaxAppender.append");
1318
+
1319
+ if (this.loggingEventMap.length() <= this.threshold || this.isInProgress === true) {
1320
+ this.loggingEventMap.push(loggingEvent);
1321
+ }
1322
+
1323
+ if(this.loggingEventMap.length() >= this.threshold && this.isInProgress === false) {
1324
+ //if threshold is reached send the events and reset current threshold
1325
+ this.send();
1326
+ }
1327
+
1328
+ log4jsLogger.trace("< AjaxAppender.append");
1329
+ },
1330
+
1331
+ /** @see Appender#doClear */
1332
+ doClear: function() {
1333
+ log4jsLogger.trace("> AjaxAppender.doClear" );
1334
+ if(this.loggingEventMap.length() > 0) {
1335
+ this.send();
1336
+ }
1337
+ log4jsLogger.trace("< AjaxAppender.doClear" );
1338
+ },
1339
+
1340
+ /**
1341
+ * Set the threshold when logs have to be send. Default threshold is 1.
1342
+ * @praram {int} threshold new threshold
1343
+ */
1344
+ setThreshold: function(threshold) {
1345
+ log4jsLogger.trace("> AjaxAppender.setThreshold: " + threshold );
1346
+ this.threshold = threshold;
1347
+ log4jsLogger.trace("< AjaxAppender.setThreshold" );
1348
+ },
1349
+
1350
+ /**
1351
+ * Set the timeout in milli seconds until sending request is aborted.
1352
+ * Default is 2000 ms.
1353
+ * @param {int} milliseconds the new timeout
1354
+ */
1355
+ setTimeout: function(milliseconds) {
1356
+ this.timeout = milliseconds;
1357
+ },
1358
+
1359
+ /**
1360
+ * send the request.
1361
+ */
1362
+ send: function() {
1363
+ if(this.loggingEventMap.length() >0) {
1364
+
1365
+ log4jsLogger.trace("> AjaxAppender.send");
1366
+
1367
+
1368
+ this.isInProgress = true;
1369
+ var a = [];
1370
+
1371
+ for(var i = 0; i < this.loggingEventMap.length() && i < this.threshold; i++) {
1372
+ a.push(this.layout.format(this.loggingEventMap.pull()));
1373
+ }
1374
+
1375
+ var content = this.layout.getHeader();
1376
+ content += a.join(this.layout.getSeparator());
1377
+ content += this.layout.getFooter();
1378
+
1379
+ var appender = this;
1380
+ if(this.httpRequest === null){
1381
+ this.httpRequest = this.getXmlHttpRequest();
1382
+ }
1383
+ this.httpRequest.onreadystatechange = function() {
1384
+ appender.onReadyStateChanged.call(appender);
1385
+ };
1386
+
1387
+ this.httpRequest.open("POST", this.loggingUrl, true);
1388
+ // set the request headers.
1389
+ //this.httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
1390
+ this.httpRequest.setRequestHeader("Content-type", this.layout.getContentType());
1391
+ //REFERER will be the top-level
1392
+ // URI which may differ from the location of the error if
1393
+ // it occurs in an included .js file
1394
+ this.httpRequest.setRequestHeader("REFERER", location.href);
1395
+ this.httpRequest.setRequestHeader("Content-length", content.length);
1396
+ this.httpRequest.setRequestHeader("Connection", "close");
1397
+ this.httpRequest.send( content );
1398
+
1399
+ appender = this;
1400
+
1401
+ try {
1402
+ window.setTimeout(function(){
1403
+ log4jsLogger.trace("> AjaxAppender.timeout");
1404
+ appender.httpRequest.onreadystatechange = function(){return;};
1405
+ appender.httpRequest.abort();
1406
+ //this.httpRequest = null;
1407
+ appender.isInProgress = false;
1408
+
1409
+ if(appender.loggingEventMap.length() > 0) {
1410
+ appender.send();
1411
+ }
1412
+ log4jsLogger.trace("< AjaxAppender.timeout");
1413
+ }, this.timeout);
1414
+ } catch (e) {
1415
+ log4jsLogger.fatal(e);
1416
+ }
1417
+ log4jsLogger.trace("> AjaxAppender.send");
1418
+ }
1419
+ },
1420
+
1421
+ /**
1422
+ * @private
1423
+ */
1424
+ onReadyStateChanged: function() {
1425
+ log4jsLogger.trace("> AjaxAppender.onReadyStateChanged");
1426
+ var req = this.httpRequest;
1427
+ if (this.httpRequest.readyState != 4) {
1428
+ log4jsLogger.trace("< AjaxAppender.onReadyStateChanged: readyState " + req.readyState + " != 4");
1429
+ return;
1430
+ }
1431
+
1432
+ var success = ((typeof req.status === "undefined") || req.status === 0 || (req.status >= 200 && req.status < 300));
1433
+
1434
+ if (success) {
1435
+ log4jsLogger.trace(" AjaxAppender.onReadyStateChanged: success");
1436
+
1437
+ //ready sending data
1438
+ this.isInProgress = false;
1439
+
1440
+ } else {
1441
+ var msg = " AjaxAppender.onReadyStateChanged: XMLHttpRequest request to URL " + this.loggingUrl + " returned status code " + this.httpRequest.status;
1442
+ log4jsLogger.error(msg);
1443
+ }
1444
+
1445
+ log4jsLogger.trace("< AjaxAppender.onReadyStateChanged: readyState == 4");
1446
+ },
1447
+ /**
1448
+ * Get the XMLHttpRequest object independent of browser.
1449
+ * @private
1450
+ */
1451
+ getXmlHttpRequest: function() {
1452
+ log4jsLogger.trace("> AjaxAppender.getXmlHttpRequest");
1453
+
1454
+ var httpRequest = false;
1455
+
1456
+ try {
1457
+ if (window.XMLHttpRequest) { // Mozilla, Safari, IE7...
1458
+ httpRequest = new XMLHttpRequest();
1459
+ if (httpRequest.overrideMimeType) {
1460
+ httpRequest.overrideMimeType(this.layout.getContentType());
1461
+ }
1462
+ } else if (window.ActiveXObject) { // IE
1463
+ try {
1464
+ httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
1465
+ } catch (e) {
1466
+ httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
1467
+ }
1468
+ }
1469
+ } catch (e) {
1470
+ httpRequest = false;
1471
+ }
1472
+
1473
+ if (!httpRequest) {
1474
+ log4jsLogger.fatal("Unfortunatelly your browser does not support AjaxAppender for log4js!");
1475
+ }
1476
+
1477
+ log4jsLogger.trace("< AjaxAppender.getXmlHttpRequest");
1478
+ return httpRequest;
1479
+ },
1480
+
1481
+ /**
1482
+ * toString
1483
+ */
1484
+ toString: function() {
1485
+ return "Log4js.AjaxAppender[loggingUrl=" + this.loggingUrl + ", threshold=" + this.threshold + "]";
1486
+ }
1487
+ });
1488
+
1489
+ /**
1490
+ * File Appender writing the logs to a text file.
1491
+ * PLEASE NOTE - Only works in IE and Mozilla
1492
+ * use ActiveX to write file on IE
1493
+ * use XPCom components to write file on Mozilla
1494
+ *
1495
+ * @extends Log4js.Appender
1496
+ * @constructor
1497
+ * @param logger log4js instance this appender is attached to
1498
+ * @param file file log messages will be written to
1499
+ * @author Seth Chisamore
1500
+ * @author Nicolas Justin njustin@idealx.com
1501
+ * @author Gregory Kokanosky gkokanosky@idealx.com
1502
+ */
1503
+ Log4js.FileAppender = function(file) {
1504
+
1505
+ this.layout = new Log4js.SimpleLayout();
1506
+ this.isIE = 'undefined';
1507
+
1508
+ this.file = file || "log4js.log";
1509
+
1510
+ try{
1511
+ this.fso = new ActiveXObject("Scripting.FileSystemObject");
1512
+ this.isIE = true;
1513
+ } catch(e){
1514
+ try {
1515
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1516
+ this.fso = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
1517
+ this.isIE = false; //mozilla & co
1518
+ } catch (e) {
1519
+ log4jsLogger.error(e);
1520
+ }
1521
+ }
1522
+ };
1523
+
1524
+ Log4js.FileAppender.prototype = Log4js.extend(new Log4js.Appender(), {
1525
+ /**
1526
+ * @param loggingEvent event to be logged
1527
+ * @see Log4js.Appender#doAppend
1528
+ */
1529
+ doAppend: function(loggingEvent) {
1530
+ try {
1531
+ var fileHandle = null;
1532
+
1533
+ if( this.isIE === 'undefined') {
1534
+ log4jsLogger.error("Unsupported ")
1535
+ }
1536
+ else if( this.isIE ){
1537
+ // try opening existing file, create if needed
1538
+ fileHandle = this.fso.OpenTextFile(this.file, 8, true);
1539
+ // write out our data
1540
+ fileHandle.WriteLine(this.layout.format(loggingEvent));
1541
+ fileHandle.close();
1542
+ } else {
1543
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1544
+ this.fso.initWithPath(this.file);
1545
+ if(!this.fso.exists()) {
1546
+ //create file if needed
1547
+ this.fso.create(0x00, 0600);
1548
+ }
1549
+
1550
+ fileHandle = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
1551
+ fileHandle.init( this.fso, 0x04 | 0x08 | 0x10, 064, 0);
1552
+ var line = this.layout.format(loggingEvent);
1553
+ fileHandle.write(line, line.length); //write data
1554
+ fileHandle.close();
1555
+ }
1556
+ } catch (e) {
1557
+ log4jsLogger.error(e);
1558
+ }
1559
+ },
1560
+ /*
1561
+ * @see Log4js.Appender#doClear
1562
+ */
1563
+ doClear: function() {
1564
+ try {
1565
+ if( this.isIE ){
1566
+ var fileHandle = this.fso.GetFile(this.file);
1567
+ fileHandle.Delete();
1568
+ } else {
1569
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1570
+ this.fso.initWithPath(this.file);
1571
+ if(this.fso.exists()) {
1572
+ this.fso.remove(false);
1573
+ }
1574
+ }
1575
+ } catch (e) {
1576
+ log4jsLogger.error(e);
1577
+ }
1578
+ },
1579
+
1580
+ /**
1581
+ * toString
1582
+ */
1583
+ toString: function() {
1584
+ return "Log4js.FileAppender[file=" + this.file + "]";
1585
+ }
1586
+ });
1587
+
1588
+ /**
1589
+ * Windows Event Appender writes the logs to the Windows Event log.
1590
+ * PLEASE NOTE - Only works in IE..uses ActiveX to write to Windows Event log
1591
+ *
1592
+ * @extends Log4js.Appender
1593
+ * @constructor
1594
+ * @param logger log4js instance this appender is attached to
1595
+ * @author Seth Chisamore
1596
+ */
1597
+ Log4js.WindowsEventAppender = function() {
1598
+
1599
+ this.layout = new Log4js.SimpleLayout();
1600
+
1601
+ try {
1602
+ this.shell = new ActiveXObject("WScript.Shell");
1603
+ } catch(e) {
1604
+ log4jsLogger.error(e);
1605
+ }
1606
+ };
1607
+
1608
+ Log4js.WindowsEventAppender.prototype = Log4js.extend(new Log4js.Appender(), {
1609
+ /**
1610
+ * @param loggingEvent event to be logged
1611
+ * @see Log4js.Appender#doAppend
1612
+ */
1613
+ doAppend: function(loggingEvent) {
1614
+ var winLevel = 4;
1615
+
1616
+ // Map log level to windows event log level.
1617
+ // Windows events: - SUCCESS: 0, ERROR: 1, WARNING: 2, INFORMATION: 4, AUDIT_SUCCESS: 8, AUDIT_FAILURE: 16
1618
+ switch (loggingEvent.level) {
1619
+ case Log4js.Level.FATAL:
1620
+ winLevel = 1;
1621
+ break;
1622
+ case Log4js.Level.ERROR:
1623
+ winLevel = 1;
1624
+ break;
1625
+ case Log4js.Level.WARN:
1626
+ winLevel = 2;
1627
+ break;
1628
+ default:
1629
+ winLevel = 4;
1630
+ break;
1631
+ }
1632
+
1633
+ try {
1634
+ this.shell.LogEvent(winLevel, this.level.format(loggingEvent));
1635
+ } catch(e) {
1636
+ log4jsLogger.error(e);
1637
+ }
1638
+ },
1639
+
1640
+ /**
1641
+ * toString
1642
+ */
1643
+ toString: function() {
1644
+ return "Log4js.WindowsEventAppender";
1645
+ }
1646
+ });
1647
+
1648
+ /**
1649
+ * JS Alert Appender writes the logs to the JavaScript alert dialog box
1650
+ * @constructor
1651
+ * @extends Log4js.Appender
1652
+ * @param logger log4js instance this appender is attached to
1653
+ * @author S&eacute;bastien LECACHEUR
1654
+ */
1655
+ Log4js.JSAlertAppender = function() {
1656
+
1657
+ this.layout = new Log4js.SimpleLayout();
1658
+ };
1659
+
1660
+ Log4js.JSAlertAppender.prototype = Log4js.extend(new Log4js.Appender(), {
1661
+ /**
1662
+ * @see Log4js.Appender#doAppend
1663
+ */
1664
+ doAppend: function(loggingEvent) {
1665
+ alert(this.layout.getHeader() + this.layout.format(loggingEvent) + this.layout.getFooter());
1666
+ },
1667
+
1668
+ /**
1669
+ * toString
1670
+ */
1671
+ toString: function() {
1672
+ return "Log4js.JSAlertAppender";
1673
+ }
1674
+ });
1675
+
1676
+ /**
1677
+ * Appender writes the logs to the JavaScript console of Mozilla browser
1678
+ * More infos: http://kb.mozillazine.org/index.php?title=JavaScript_Console&redirect=no
1679
+ * PLEASE NOTE - Only works in Mozilla browser
1680
+ * @constructor
1681
+ * @extends Log4js.Appender
1682
+ * @param logger log4js instance this appender is attached to
1683
+ * @author Stephan Strittmatter
1684
+ */
1685
+ Log4js.MozillaJSConsoleAppender = function() {
1686
+ this.layout = new Log4js.SimpleLayout();
1687
+ try {
1688
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1689
+ this.jsConsole = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
1690
+ this.scriptError = Components.classes["@mozilla.org/scripterror;1"].createInstance(Components.interfaces.nsIScriptError);
1691
+ } catch (e) {
1692
+ log4jsLogger.error(e);
1693
+ }
1694
+ };
1695
+
1696
+ Log4js.MozillaJSConsoleAppender.prototype = Log4js.extend(new Log4js.Appender(), {
1697
+ /**
1698
+ * @see Log4js.Appender#doAppend
1699
+ */
1700
+ doAppend: function(loggingEvent) {
1701
+ try {
1702
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1703
+ this.scriptError.init(this.layout.format(loggingEvent), null, null, null, null, this.getFlag(loggingEvent), loggingEvent.categoryName);
1704
+ this.jsConsole.logMessage(this.scriptError);
1705
+ } catch (e) {
1706
+ log4jsLogger.error(e);
1707
+ }
1708
+ },
1709
+
1710
+ /**
1711
+ * toString
1712
+ */
1713
+ toString: function() {
1714
+ return "Log4js.MozillaJSConsoleAppender";
1715
+ },
1716
+
1717
+ /**
1718
+ * Map Log4js.Level to jsConsole Flags:
1719
+ * <ul>
1720
+ * <li>nsIScriptError.errorFlag (0) = Level.Error</li>
1721
+ * <li>nsIScriptError.warningFlag (1)= Log4js.Level.WARN</li>
1722
+ * <li>nsIScriptError.exceptionFlag (2) = Log4js.Level.FATAL</li>
1723
+ * <li>nsIScriptError.strictFlag (4) = unused</li>
1724
+ * </ul>
1725
+ * @private
1726
+ */
1727
+ getFlag: function(loggingEvent)
1728
+ {
1729
+ var retval;
1730
+ switch (loggingEvent.level) {
1731
+ case Log4js.Level.FATAL:
1732
+ retval = 2;//nsIScriptError.exceptionFlag = 2
1733
+ break;
1734
+ case Log4js.Level.ERROR:
1735
+ retval = 0;//nsIScriptError.errorFlag
1736
+ break;
1737
+ case Log4js.Level.WARN:
1738
+ retval = 1;//nsIScriptError.warningFlag = 1
1739
+ break;
1740
+ default:
1741
+ retval = 1;//nsIScriptError.warningFlag = 1
1742
+ break;
1743
+ }
1744
+
1745
+ return retval;
1746
+ }
1747
+ });
1748
+
1749
+ /**
1750
+ * Appender writes the logs to the JavaScript console of Opera browser
1751
+ * PLEASE NOTE - Only works in Opera browser
1752
+ * @constructor
1753
+ * @extends Log4js.Appender
1754
+ * @param logger log4js instance this appender is attached to
1755
+ * @author Stephan Strittmatter
1756
+ */
1757
+ Log4js.OperaJSConsoleAppender = function() {
1758
+ this.layout = new Log4js.SimpleLayout();
1759
+ };
1760
+
1761
+ Log4js.OperaJSConsoleAppender.prototype = Log4js.extend(new Log4js.Appender(), {
1762
+ /**
1763
+ * @see Log4js.Appender#doAppend
1764
+ */
1765
+ doAppend: function(loggingEvent) {
1766
+ opera.postError(this.layout.format(loggingEvent));
1767
+ },
1768
+
1769
+ /**
1770
+ * toString
1771
+ */
1772
+ toString: function() {
1773
+ return "Log4js.OperaJSConsoleAppender";
1774
+ }
1775
+ });
1776
+
1777
+ /**
1778
+ * Appender writes the logs to the JavaScript console of Safari browser
1779
+ * PLEASE NOTE - Only works in Safari browser
1780
+ * @constructor
1781
+ * @extends Log4js.Appender
1782
+ * @param logger log4js instance this appender is attached to
1783
+ * @author Stephan Strittmatter
1784
+ */
1785
+ Log4js.SafariJSConsoleAppender = function() {
1786
+ this.layout = new Log4js.SimpleLayout();
1787
+ };
1788
+
1789
+ Log4js.SafariJSConsoleAppender.prototype = Log4js.extend(new Log4js.Appender(), {
1790
+ /**
1791
+ * @see Log4js.Appender#doAppend
1792
+ */
1793
+ doAppend: function(loggingEvent) {
1794
+ window.console.log(this.layout.format(loggingEvent));
1795
+ },
1796
+
1797
+ /**
1798
+ * toString
1799
+ */
1800
+ toString: function() {
1801
+ return "Log4js.SafariJSConsoleAppender";
1802
+ }
1803
+ });
1804
+
1805
+ /**
1806
+ * JavaScript Console Appender which is browser independent.
1807
+ * It checks internally for the current browser and adds delegate to
1808
+ * specific JavaScript Console Appender of the browser.
1809
+ *
1810
+ * @author Stephan Strittmatter
1811
+ * @since 1.0
1812
+ */
1813
+ Log4js.BrowserConsoleAppender = function() {
1814
+ /**
1815
+ * Delegate for browser specific implementation
1816
+ * @type Log4js.Appender
1817
+ * @private
1818
+ */
1819
+ this.consoleDelegate = null;
1820
+
1821
+ if (window.console) {
1822
+ this.consoleDelegate = new Log4js.SafariJSConsoleAppender();
1823
+ }
1824
+ else if (window.opera) {
1825
+ this.consoleDelegate = new Log4js.OperaJSConsoleAppender();
1826
+ }
1827
+ else if(netscape) {
1828
+ this.consoleDelegate = new Log4js.MozJSConsoleAppender();
1829
+ }
1830
+ else {
1831
+ //@todo
1832
+ log4jsLogger.error("Unsupported Browser");
1833
+ }
1834
+ };
1835
+
1836
+ Log4js.BrowserConsoleAppender.prototype = Log4js.extend(new Log4js.Appender(), {
1837
+ /**
1838
+ * @see Log4js.Appender#doAppend
1839
+ */
1840
+ doAppend: function(loggingEvent) {
1841
+ this.consoleDelegate.doAppend(loggingEvent);
1842
+ },
1843
+ /**
1844
+ * @see Log4js.Appender#doClear
1845
+ */
1846
+ doClear: function() {
1847
+ this.consoleDelegate.doClear();
1848
+ },
1849
+ /**
1850
+ * @see Log4js.Appender#setLayout
1851
+ */
1852
+ setLayout: function(layout){
1853
+ this.consoleDelegate.setLayout(layout);
1854
+ },
1855
+
1856
+ /**
1857
+ * toString
1858
+ */
1859
+ toString: function() {
1860
+ return "Log4js.BrowserConsoleAppender: " + this.consoleDelegate.toString();
1861
+ }
1862
+ });
1863
+
1864
+ /**
1865
+ * SimpleLayout consists of the level of the log statement, followed by " - "
1866
+ * and then the log message itself. For example,
1867
+ * <code>DEBUG - Hello world</code>
1868
+ *
1869
+ * @constructor
1870
+ * @extends Log4js.Layout
1871
+ * @extends Layout
1872
+ * @author Stephan Strittmatter
1873
+ */
1874
+ Log4js.SimpleLayout = function() {
1875
+ this.LINE_SEP = "\n";
1876
+ this.LINE_SEP_LEN = 1;
1877
+ };
1878
+
1879
+ Log4js.SimpleLayout.prototype = Log4js.extend(new Log4js.Layout(), {
1880
+ /**
1881
+ * Implement this method to create your own layout format.
1882
+ * @param {Log4js.LoggingEvent} loggingEvent loggingEvent to format
1883
+ * @return formatted String
1884
+ * @type String
1885
+ */
1886
+ format: function(loggingEvent) {
1887
+ return loggingEvent.level.toString() + " - " + loggingEvent.message + this.LINE_SEP;
1888
+ },
1889
+ /**
1890
+ * Returns the content type output by this layout.
1891
+ * @return The base class returns "text/plain".
1892
+ * @type String
1893
+ */
1894
+ getContentType: function() {
1895
+ return "text/plain";
1896
+ },
1897
+ /**
1898
+ * @return Returns the header for the layout format. The base class returns null.
1899
+ * @type String
1900
+ */
1901
+ getHeader: function() {
1902
+ return "";
1903
+ },
1904
+ /**
1905
+ * @return Returns the footer for the layout format. The base class returns null.
1906
+ * @type String
1907
+ */
1908
+ getFooter: function() {
1909
+ return "";
1910
+ }
1911
+ });
1912
+
1913
+ /**
1914
+ * BasicLayout is a simple layout for storing the loggs. The loggs are stored
1915
+ * in following format:
1916
+ * <pre>
1917
+ * categoryName~startTime [logLevel] message\n
1918
+ * </pre>
1919
+ *
1920
+ * @constructor
1921
+ * @extends Log4js.Layout
1922
+ * @author Stephan Strittmatter
1923
+ */
1924
+ Log4js.BasicLayout = function() {
1925
+ this.LINE_SEP = "\n";
1926
+ };
1927
+
1928
+ Log4js.BasicLayout.prototype = Log4js.extend(new Log4js.Layout(), {
1929
+ /**
1930
+ * Implement this method to create your own layout format.
1931
+ * @param {Log4js.LoggingEvent} loggingEvent loggingEvent to format
1932
+ * @return formatted String
1933
+ * @type String
1934
+ */
1935
+ format: function(loggingEvent) {
1936
+ return loggingEvent.categoryName + "~" + loggingEvent.startTime.toLocaleString() + " [" + loggingEvent.level.toString() + "] " + loggingEvent.message + this.LINE_SEP;
1937
+ },
1938
+ /**
1939
+ * Returns the content type output by this layout.
1940
+ * @return The base class returns "text/plain".
1941
+ * @type String
1942
+ */
1943
+ getContentType: function() {
1944
+ return "text/plain";
1945
+ },
1946
+ /**
1947
+ * @return Returns the header for the layout format. The base class returns null.
1948
+ * @type String
1949
+ */
1950
+ getHeader: function() {
1951
+ return "";
1952
+ },
1953
+ /**
1954
+ * @return Returns the footer for the layout format. The base class returns null.
1955
+ * @type String
1956
+ */
1957
+ getFooter: function() {
1958
+ return "";
1959
+ }
1960
+ });
1961
+
1962
+ /**
1963
+ * HtmlLayout write the logs in Html format.
1964
+ *
1965
+ * @constructor
1966
+ * @extends Log4js.Layout
1967
+ * @author Stephan Strittmatter
1968
+ */
1969
+ Log4js.HtmlLayout = function() {return;};
1970
+
1971
+ Log4js.HtmlLayout.prototype = Log4js.extend(new Log4js.Layout(), {
1972
+ /**
1973
+ * Implement this method to create your own layout format.
1974
+ * @param {Log4js.LoggingEvent} loggingEvent loggingEvent to format
1975
+ * @return formatted String
1976
+ * @type String
1977
+ */
1978
+ format: function(loggingEvent) {
1979
+ return "<div style=\"" + this.getStyle(loggingEvent) + "\">" + loggingEvent.getFormattedTimestamp() + " - " + loggingEvent.level.toString() + " - " + loggingEvent.message + "</div>\n";
1980
+ },
1981
+ /**
1982
+ * Returns the content type output by this layout.
1983
+ * @return The base class returns "text/html".
1984
+ * @type String
1985
+ */
1986
+ getContentType: function() {
1987
+ return "text/html";
1988
+ },
1989
+ /**
1990
+ * @return Returns the header for the layout format. The base class returns null.
1991
+ * @type String
1992
+ */
1993
+ getHeader: function() {
1994
+ return "<html><head><title>log4js</head><body>";
1995
+ },
1996
+ /**
1997
+ * @return Returns the footer for the layout format. The base class returns null.
1998
+ * @type String
1999
+ */
2000
+ getFooter: function() {
2001
+ return "</body></html>";
2002
+ },
2003
+
2004
+ getStyle: function(loggingEvent)
2005
+ {
2006
+ var style;
2007
+ if (loggingEvent.level.toString().search(/ERROR/) != -1) {
2008
+ style = 'color:red';
2009
+ } else if (loggingEvent.level.toString().search(/FATAL/) != -1) {
2010
+ style = 'color:red';
2011
+ } else if (loggingEvent.level.toString().search(/WARN/) != -1) {
2012
+ style = 'color:orange';
2013
+ } else if (loggingEvent.level.toString().search(/DEBUG/) != -1) {
2014
+ style = 'color:green';
2015
+ } else if (loggingEvent.level.toString().search(/INFO/) != -1) {
2016
+ style = 'color:white';
2017
+ } else {
2018
+ style = 'color:yellow';
2019
+ }
2020
+ return style;
2021
+ }
2022
+ });
2023
+
2024
+ /**
2025
+ * XMLLayout write the logs in XML format.
2026
+ * Layout is simmilar to log4j's XMLLayout:
2027
+ * <pre>
2028
+ * <log4js:event category="category" level="Level" client="Client" referer="ref" timestam="Date">
2029
+ * <log4js:message>Logged message</log4js:message>
2030
+ * </log4js:event>
2031
+ * </pre>
2032
+ * @constructor
2033
+ * @extends Layout
2034
+ * @author Stephan Strittmatter
2035
+ */
2036
+ Log4js.XMLLayout = function(){return;};
2037
+ Log4js.XMLLayout.prototype = Log4js.extend(new Log4js.Layout(), {
2038
+ /**
2039
+ * Implement this method to create your own layout format.
2040
+ * @param {Log4js.LoggingEvent} loggingEvent loggingEvent to format
2041
+ * @return formatted String
2042
+ * @type String
2043
+ */
2044
+ format: function(loggingEvent) {
2045
+ var useragent = "unknown";
2046
+ try {
2047
+ useragent = navigator.userAgent;
2048
+ } catch(e){
2049
+ useragent = "unknown";
2050
+ }
2051
+
2052
+ var referer = "unknown";
2053
+ try {
2054
+ referer = location.href;
2055
+ } catch(e){
2056
+ referer = "unknown";
2057
+ }
2058
+
2059
+ var content = "<log4js:event logger=\"";
2060
+ content += loggingEvent.categoryName + "\" level=\"";
2061
+ content += loggingEvent.level.toString() + "\" useragent=\"";
2062
+ content += useragent + "\" referer=\"";
2063
+ content += referer.replace(/&/g, "&amp;") + "\" timestamp=\"";
2064
+ content += loggingEvent.getFormattedTimestamp() + "\">\n";
2065
+ content += "\t<log4js:message><![CDATA[" + this.escapeCdata(loggingEvent.message) + "]]></log4js:message>\n";
2066
+
2067
+ if (loggingEvent.exception) {
2068
+ content += this.formatException(loggingEvent.exception) ;
2069
+ }
2070
+ content += "</log4js:event>\n";
2071
+
2072
+ return content;
2073
+ },
2074
+ /**
2075
+ * Returns the content type output by this layout.
2076
+ * @return The base class returns "text/xml".
2077
+ * @type String
2078
+ */
2079
+ getContentType: function() {
2080
+ return "text/xml";
2081
+ },
2082
+ /**
2083
+ * @return Returns the header for the layout format. The base class returns null.
2084
+ * @type String
2085
+ */
2086
+ getHeader: function() {
2087
+ return "<log4js:eventSet version=\"" + Log4js.version +
2088
+ "\" xmlns:log4js=\"http://log4js.berlios.de/2007/log4js/\">\n";
2089
+ },
2090
+ /**
2091
+ * @return Returns the footer for the layout format. The base class returns null.
2092
+ * @type String
2093
+ */
2094
+ getFooter: function() {
2095
+ return "</log4js:eventSet>\n";
2096
+ },
2097
+
2098
+ getSeparator: function() {
2099
+ return "\n";
2100
+ },
2101
+
2102
+ /**
2103
+ * better readable formatted Exceptions.
2104
+ * @param ex {Exception} the exception to be formatted.
2105
+ * @return {String} the formatted String representation of the exception.
2106
+ * @private
2107
+ */
2108
+ formatException: function(ex) {
2109
+ if (ex) {
2110
+ var exStr = "\t<log4js:throwable>";
2111
+ if (ex.message) {
2112
+ exStr += "\t\t<log4js:message><![CDATA[" + this.escapeCdata(ex.message) + "]]></log4js:message>\n";
2113
+ }
2114
+ if (ex.description) {
2115
+ exStr += "\t\t<log4js:description><![CDATA[" + this.escapeCdata(ex.description) + "]]></log4js:description>\n";
2116
+ }
2117
+
2118
+ exStr += "\t\t<log4js:stacktrace>";
2119
+ exStr += "\t\t\t<log4js:location fileName=\""+ex.fileName+"\" lineNumber=\""+ex.lineNumber+"\" />";
2120
+ exStr += "\t\t</log4js:stacktrace>";
2121
+ exStr = "\t</log4js:throwable>";
2122
+ return exStr;
2123
+ }
2124
+ return null;
2125
+ },
2126
+ /**
2127
+ * Escape Cdata messages
2128
+ * @param str {String} message to escape
2129
+ * @return {String} the escaped message
2130
+ * @private
2131
+ */
2132
+ escapeCdata: function(str) {
2133
+ return str.replace(/\]\]>/, "]]>]]&gt;<![CDATA[");
2134
+ }
2135
+ });
2136
+
2137
+ /**
2138
+ * JSONLayout write the logs in JSON format.
2139
+ * JSON library is required to use this Layout. See also {@link http://www.json.org}
2140
+ * @constructor
2141
+ * @extends Log4js.Layout
2142
+ * @author Stephan Strittmatter
2143
+ */
2144
+ Log4js.JSONLayout = function() {
2145
+ this.df = new Log4js.DateFormatter();
2146
+ };
2147
+ Log4js.JSONLayout.prototype = Log4js.extend(new Log4js.Layout(), {
2148
+ /**
2149
+ * Implement this method to create your own layout format.
2150
+ * @param {Log4js.LoggingEvent} loggingEvent loggingEvent to format
2151
+ * @return formatted String
2152
+ * @type String
2153
+ */
2154
+ format: function(loggingEvent) {
2155
+
2156
+ var useragent = "unknown";
2157
+ try {
2158
+ useragent = navigator.userAgent;
2159
+ } catch(e){
2160
+ useragent = "unknown";
2161
+ }
2162
+
2163
+ var referer = "unknown";
2164
+ try {
2165
+ referer = location.href;
2166
+ } catch(e){
2167
+ referer = "unknown";
2168
+ }
2169
+
2170
+ var jsonString = "{\n \"LoggingEvent\": {\n";
2171
+
2172
+ jsonString += "\t\"logger\": \"" + loggingEvent.categoryName + "\",\n";
2173
+ jsonString += "\t\"level\": \"" + loggingEvent.level.toString() + "\",\n";
2174
+ jsonString += "\t\"message\": \"" + loggingEvent.message + "\",\n";
2175
+ jsonString += "\t\"referer\": \"" + referer + "\",\n";
2176
+ jsonString += "\t\"useragent\": \"" + useragent + "\",\n";
2177
+ jsonString += "\t\"timestamp\": \"" + this.df.formatDate(loggingEvent.startTime, "yyyy-MM-ddThh:mm:ssZ") + "\",\n";
2178
+ jsonString += "\t\"exception\": \"" + loggingEvent.exception + "\"\n";
2179
+ jsonString += "}}";
2180
+
2181
+ return jsonString;
2182
+ },
2183
+ /**
2184
+ * Returns the content type output by this layout.
2185
+ * @return The base class returns "text/xml".
2186
+ * @type String
2187
+ */
2188
+ getContentType: function() {
2189
+ return "text/json";
2190
+ },
2191
+ /**
2192
+ * @return Returns the header for the layout format. The base class returns null.
2193
+ * @type String
2194
+ */
2195
+ getHeader: function() {
2196
+ return "{\"Log4js\": [\n";
2197
+ },
2198
+ /**
2199
+ * @return Returns the footer for the layout format. The base class returns null.
2200
+ * @type String
2201
+ */
2202
+ getFooter: function() {
2203
+ return "\n]}";
2204
+ },
2205
+
2206
+ getSeparator: function() {
2207
+ return ",\n";
2208
+ }
2209
+ });
2210
+
2211
+ /**
2212
+ * PatternLayout
2213
+ */
2214
+ Log4js.PatternLayout = function(pattern) {
2215
+ if (pattern) {
2216
+ this.pattern = pattern;
2217
+ } else {
2218
+ this.pattern = Log4js.PatternLayout.DEFAULT_CONVERSION_PATTERN;
2219
+ }
2220
+ };
2221
+
2222
+ Log4js.PatternLayout.TTCC_CONVERSION_PATTERN = "%r %p %c - %m%n";
2223
+ Log4js.PatternLayout.DEFAULT_CONVERSION_PATTERN = "%m%n";
2224
+ Log4js.PatternLayout.ISO8601_DATEFORMAT = "yyyy-MM-dd HH:mm:ss,SSS";
2225
+ Log4js.PatternLayout.DATETIME_DATEFORMAT = "dd MMM YYYY HH:mm:ss,SSS";
2226
+ Log4js.PatternLayout.ABSOLUTETIME_DATEFORMAT = "HH:mm:ss,SSS";
2227
+
2228
+ Log4js.PatternLayout.prototype = Log4js.extend(new Log4js.Layout(), {
2229
+ /**
2230
+ * Returns the content type output by this layout.
2231
+ * @return "text/plain".
2232
+ * @type String
2233
+ */
2234
+ getContentType: function() {
2235
+ return "text/plain";
2236
+ },
2237
+ /**
2238
+ * @return Returns the header for the layout format.
2239
+ * @type String
2240
+ */
2241
+ getHeader: function() {
2242
+ return null;
2243
+ },
2244
+ /**
2245
+ * @return Returns the footer for the layout format.
2246
+ * @type String
2247
+ */
2248
+ getFooter: function() {
2249
+ return null;
2250
+ },
2251
+
2252
+ format: function(loggingEvent) {
2253
+ var regex = /%(-?[0-9]+)?(\.?[0-9]+)?([cdmnpr%])(\{([^\}]+)\})?|([^%]+)/;
2254
+ var formattedString = "";
2255
+ var result;
2256
+ var searchString = this.pattern;
2257
+
2258
+ // Cannot use regex global flag since it doesn't work in IE5
2259
+ while ((result = regex.exec(searchString))) {
2260
+ var matchedString = result[0];
2261
+ var padding = result[1];
2262
+ var truncation = result[2];
2263
+ var conversionCharacter = result[3];
2264
+ var specifier = result[5];
2265
+ var text = result[6];
2266
+
2267
+ // Check if the pattern matched was just normal text
2268
+ if (text) {
2269
+ formattedString += "" + text;
2270
+ } else {
2271
+ // Create a raw replacement string based on the conversion
2272
+ // character and specifier
2273
+ var replacement = "";
2274
+ switch(conversionCharacter) {
2275
+ case "c":
2276
+ var loggerName = loggingEvent.categoryName;
2277
+ if (specifier) {
2278
+ var precision = parseInt(specifier, 10);
2279
+ var loggerNameBits = loggingEvent.categoryName.split(".");
2280
+ if (precision >= loggerNameBits.length) {
2281
+ replacement = loggerName;
2282
+ } else {
2283
+ replacement = loggerNameBits.slice(loggerNameBits.length - precision).join(".");
2284
+ }
2285
+ } else {
2286
+ replacement = loggerName;
2287
+ }
2288
+ break;
2289
+ case "d":
2290
+ var dateFormat = Log4js.PatternLayout.ISO8601_DATEFORMAT;
2291
+ if (specifier) {
2292
+ dateFormat = specifier;
2293
+ // Pick up special cases
2294
+ if (dateFormat == "ISO8601") {
2295
+ dateFormat = Log4js.PatternLayout.ISO8601_DATEFORMAT;
2296
+ } else if (dateFormat == "ABSOLUTE") {
2297
+ dateFormat = Log4js.PatternLayout.ABSOLUTETIME_DATEFORMAT;
2298
+ } else if (dateFormat == "DATE") {
2299
+ dateFormat = Log4js.PatternLayout.DATETIME_DATEFORMAT;
2300
+ }
2301
+ }
2302
+ // Format the date
2303
+ replacement = (new Log4js.SimpleDateFormat(dateFormat)).format(loggingEvent.startTime);
2304
+ break;
2305
+ case "m":
2306
+ replacement = loggingEvent.message;
2307
+ break;
2308
+ case "n":
2309
+ replacement = "\n";
2310
+ break;
2311
+ case "p":
2312
+ replacement = loggingEvent.level.toString();
2313
+ break;
2314
+ case "r":
2315
+ replacement = "" + loggingEvent.startTime.toLocaleTimeString(); //TODO: .getDifference(Log4js.applicationStartDate);
2316
+ break;
2317
+ case "%":
2318
+ replacement = "%";
2319
+ break;
2320
+ default:
2321
+ replacement = matchedString;
2322
+ break;
2323
+ }
2324
+ // Format the replacement according to any padding or
2325
+ // truncation specified
2326
+
2327
+ var len;
2328
+
2329
+ // First, truncation
2330
+ if (truncation) {
2331
+ len = parseInt(truncation.substr(1), 10);
2332
+ replacement = replacement.substring(0, len);
2333
+ }
2334
+ // Next, padding
2335
+ if (padding) {
2336
+ if (padding.charAt(0) == "-") {
2337
+ len = parseInt(padding.substr(1), 10);
2338
+ // Right pad with spaces
2339
+ while (replacement.length < len) {
2340
+ replacement += " ";
2341
+ }
2342
+ } else {
2343
+ len = parseInt(padding, 10);
2344
+ // Left pad with spaces
2345
+ while (replacement.length < len) {
2346
+ replacement = " " + replacement;
2347
+ }
2348
+ }
2349
+ }
2350
+ formattedString += replacement;
2351
+ }
2352
+ searchString = searchString.substr(result.index + result[0].length);
2353
+ }
2354
+ return formattedString;
2355
+ }
2356
+ });
2357
+
2358
+ /**
2359
+ * @private
2360
+ * @ignore
2361
+ */
2362
+ if (!Array.prototype.push) {
2363
+ /**
2364
+ * Functions taken from Prototype library, didn't want to require for just few
2365
+ * functions.
2366
+ * More info at {@link http://
2367
+ * prototype.conio.net/}
2368
+ * @private
2369
+ */
2370
+ Array.prototype.push = function() {
2371
+ var startLength = this.length;
2372
+ for (var i = 0; i < arguments.length; i++) {
2373
+ this[startLength + i] = arguments[i];
2374
+ }
2375
+ return this.length;
2376
+ };
2377
+ }
2378
+
2379
+ /**
2380
+ * FIFO buffer
2381
+ * @private
2382
+ */
2383
+ Log4js.FifoBuffer = function()
2384
+ {
2385
+ this.array = new Array();
2386
+ };
2387
+
2388
+ Log4js.FifoBuffer.prototype = {
2389
+
2390
+ /**
2391
+ * @param {Object} obj any object added to buffer
2392
+ */
2393
+ push : function(obj) {
2394
+ this.array[this.array.length] = obj;
2395
+ return this.array.length;
2396
+ },
2397
+
2398
+ /**
2399
+ * @return first putted in Object
2400
+ */
2401
+ pull : function() {
2402
+ if (this.array.length > 0) {
2403
+ var firstItem = this.array[0];
2404
+ for (var i = 0; i < this.array.length - 1; i++) {
2405
+ this.array[i] = this.array[i + 1];
2406
+ }
2407
+ this.array.length = this.array.length - 1;
2408
+ return firstItem;
2409
+ }
2410
+ return null;
2411
+ },
2412
+
2413
+ length : function() {
2414
+ return this.array.length;
2415
+ }
2416
+ };
2417
+
2418
+
2419
+
2420
+ /**
2421
+ * Date Formatter
2422
+ * addZero() and formatDate() are courtesy of Mike Golding:
2423
+ * http://www.mikezilla.com/exp0015.html
2424
+ * @private
2425
+ */
2426
+ Log4js.DateFormatter = function() {
2427
+ return;
2428
+ };
2429
+ /**
2430
+ * default format of date (ISO-8601)
2431
+ * @static
2432
+ * @final
2433
+ */
2434
+ Log4js.DateFormatter.DEFAULT_DATE_FORMAT = "yyyy-MM-ddThh:mm:ssO";
2435
+
2436
+
2437
+ Log4js.DateFormatter.prototype = {
2438
+ /**
2439
+ * Formats the given date by the given pattern.<br />
2440
+ * Following switches are supported:
2441
+ * <ul>
2442
+ * <li>yyyy: The year</li>
2443
+ * <li>MM: the month</li>
2444
+ * <li>dd: the day of month<li>
2445
+ * <li>hh: the hour<li>
2446
+ * <li>mm: minutes</li>
2447
+ * <li>O: timezone offset</li>
2448
+ * </ul>
2449
+ * @param {Date} vDate the date to format
2450
+ * @param {String} vFormat the format pattern
2451
+ * @return {String} formatted date string
2452
+ * @static
2453
+ */
2454
+ formatDate : function(vDate, vFormat) {
2455
+ var vDay = this.addZero(vDate.getDate());
2456
+ var vMonth = this.addZero(vDate.getMonth()+1);
2457
+ var vYearLong = this.addZero(vDate.getFullYear());
2458
+ var vYearShort = this.addZero(vDate.getFullYear().toString().substring(3,4));
2459
+ var vYear = (vFormat.indexOf("yyyy")>-1?vYearLong:vYearShort);
2460
+ var vHour = this.addZero(vDate.getHours());
2461
+ var vMinute = this.addZero(vDate.getMinutes());
2462
+ var vSecond = this.addZero(vDate.getSeconds());
2463
+ var vTimeZone = this.O(vDate);
2464
+ var vDateString = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear);
2465
+ vDateString = vDateString.replace(/hh/g, vHour).replace(/mm/g, vMinute).replace(/ss/g, vSecond);
2466
+ vDateString = vDateString.replace(/O/g, vTimeZone);
2467
+ return vDateString;
2468
+ },
2469
+
2470
+ /**
2471
+ * @private
2472
+ * @static
2473
+ */
2474
+ addZero : function(vNumber) {
2475
+ return ((vNumber < 10) ? "0" : "") + vNumber;
2476
+ },
2477
+
2478
+ /**
2479
+ * Formates the TimeOffest
2480
+ * Thanks to http://www.svendtofte.com/code/date_format/
2481
+ * @private
2482
+ */
2483
+ O : function (date) {
2484
+ // Difference to Greenwich time (GMT) in hours
2485
+ var os = Math.abs(date.getTimezoneOffset());
2486
+ var h = String(Math.floor(os/60));
2487
+ var m = String(os%60);
2488
+ h.length == 1? h = "0"+h:1;
2489
+ m.length == 1? m = "0"+m:1;
2490
+ return date.getTimezoneOffset() < 0 ? "+"+h+m : "-"+h+m;
2491
+ }
2492
+ };
2493
+
2494
+
2495
+ /**
2496
+ * internal Logger to be used
2497
+ * @private
2498
+ */
2499
+ var log4jsLogger = Log4js.getLogger("Log4js");
2500
+ log4jsLogger.addAppender(new Log4js.ConsoleAppender());
2501
+ log4jsLogger.setLevel(Log4js.Level.ALL);