From edf79fd3eda36ded023f5ca04d74184c2d1a1e34 Mon Sep 17 00:00:00 2001 From: phasefx Date: Mon, 21 Jan 2008 15:18:47 +0000 Subject: [PATCH] some try/catch goodness for messagecatalog implementation, and throw exception on key not found git-svn-id: svn://svn.open-ils.org/ILS/trunk@8448 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../staff_client/chrome/content/main/bindings.xml | 198 ++++++++++++--------- 1 file changed, 113 insertions(+), 85 deletions(-) diff --git a/Open-ILS/xul/staff_client/chrome/content/main/bindings.xml b/Open-ILS/xul/staff_client/chrome/content/main/bindings.xml index 641514d5b0..ae708951d7 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/bindings.xml +++ b/Open-ILS/xul/staff_client/chrome/content/main/bindings.xml @@ -17,23 +17,38 @@ @@ -41,18 +56,23 @@ @@ -61,69 +81,74 @@ = 0) in_comment = true; - - if (in_comment && line.indexOf('*/') > 0) { - var comment_start = line.indexOf('/*'); - var comment_end = line.indexOf('*/'); - line = line.substring(0, comment_start) + line.substring(0, comment_end + 2); - in_comment = false; - } else if (in_comment) continue; - - // get rid of entire-line comments - if (line.indexOf('#') == 0) { - line = ''; - continue; - } - - // handle end-of-line comments - var end_comment = line.indexOf('//'); - if (end_comment >= 0) line = line.substring(0, end_comment); - - // and line concatenation - if (line.charAt(line.lenth - 1) == '\\') { - line = line.substring(0,line.lenth - 1); - continue; - } - - var eq_pos = line.indexOf('='); - if (eq_pos < 0) continue; - - var k = line.substring(0,eq_pos); - k = k.replace(/\s+/g,""); - - var v = line.substring(eq_pos + 1); - - var current_m = 0; - var cont = false; - do { - if (v.indexOf( "{" + current_m + "}" ) >= 0 ) { - var mes_bund = new RegExp( "\\\{" + current_m + "\\\}", 'g' ); - var sprintf_format = "%" + (current_m + 1) + "$s"; - - v = v.replace( mes_bund, sprintf_format ); - - cont = true; - current_m++; - } else { - cont = false; - } - } while ( cont == true ); - - props[k] = v; - line = ''; - } - - return props; + try { + var lines = str.split("\n"); + var props = {}; + var line = ''; + var in_comment = false; + + for (var l in lines) { + line += lines[l]; + + // handle multi-line comments + if (line.indexOf('/*') >= 0) in_comment = true; + + if (in_comment && line.indexOf('*/') > 0) { + var comment_start = line.indexOf('/*'); + var comment_end = line.indexOf('*/'); + line = line.substring(0, comment_start) + line.substring(0, comment_end + 2); + in_comment = false; + } else if (in_comment) continue; + + // get rid of entire-line comments + if (line.indexOf('#') == 0) { + line = ''; + continue; + } + + // handle end-of-line comments + var end_comment = line.indexOf('//'); + if (end_comment >= 0) line = line.substring(0, end_comment); + + // and line concatenation + if (line.charAt(line.lenth - 1) == '\\') { + line = line.substring(0,line.lenth - 1); + continue; + } + + var eq_pos = line.indexOf('='); + if (eq_pos < 0) continue; + + var k = line.substring(0,eq_pos); + k = k.replace(/\s+/g,""); + + var v = line.substring(eq_pos + 1); + + var current_m = 0; + var cont = false; + do { + if (v.indexOf( "{" + current_m + "}" ) >= 0 ) { + var mes_bund = new RegExp( "\\\{" + current_m + "\\\}", 'g' ); + var sprintf_format = "%" + (current_m + 1) + "$s"; + + v = v.replace( mes_bund, sprintf_format ); + + cont = true; + current_m++; + } else { + cont = false; + } + } while ( cont == true ); + + props[k] = v; + line = ''; + } + + return props; + } catch(E) { + alert('Error in props2object in messagecatalog in bindings.xml: ' + E); + throw(E); + } ]]> @@ -133,9 +158,11 @@ @@ -148,7 +175,8 @@