# HG changeset patch # User Eugene Ostroukhov # Date 1270858059 25200 # Node ID 60453502674ed83433800e0b1f75fe34183a15e7 # Parent a908b05787d14a96cfbc96bb5c52d98a69cf5d9f Bug 2446 - Use different JSON diff -r a908b05787d1 -r 60453502674e org.symbian.tools.wrttools.previewer/preview/script/nokia.js --- a/org.symbian.tools.wrttools.previewer/preview/script/nokia.js Fri Apr 09 11:42:56 2010 -0700 +++ b/org.symbian.tools.wrttools.previewer/preview/script/nokia.js Fri Apr 09 17:07:39 2010 -0700 @@ -814,15 +814,9 @@ // do some cheating here xmlString = xmlString.replace(/<\s*true\s*\/>/gi, "true"); xmlString = xmlString.replace(/<\s*false\s*\/>/gi, "false"); - - /* - * DomParser Logic - var appXml = new DOMParser(); - var xmlobject = appXml.parseFromString(xmlString, "text/xml"); - */ - + xmlString = xmlString.replace(/[\n\r]/gi, ""); // return the JSON Object - NOKIA.helper.validate(xml2json.parser(xmlString)); + NOKIA.helper.validate(xmlString); } }, @@ -846,51 +840,21 @@ validate : function(xmlObject) { - window.xmlObject = xmlObject; - - // - if(typeof xmlObject.plist != 'object' || xmlObject.plist == 'undefined') - { - NOKIA.helper.error('Corrupted Info.plist file'); - return false; - } - // - xmlObject = xmlObject.plist; - if(typeof xmlObject.dict != 'object' || xmlObject.dict == 'undefined') + var values = xmlObject.match(/.*\s*(]*?>[^<]*?<\/key>\s*]*?>[^<]*?<\/string>)*\s*<\/dict>)\s*<\/plist>/)[1]; + if(values == null || values == undefined) { NOKIA.helper.error('Corrupted Info.plist file'); return false; } - - // - xmlObject = xmlObject.dict; - if(typeof xmlObject.key != 'object' || xmlObject.key == 'undefined') - { - NOKIA.helper.error('Corrupted Info.plist file'); - return false; - } - - // - if(typeof xmlObject.string != 'object' || xmlObject.string == 'undefined') - { + values = values.replace(/\s*.*\s*<\/string>)\s*<\/dict>/, "{ $1 }"); + values = values.replace(/\s*\s*(.*?)\s*<\/key>\s*\s*(.*?)\s*<\/string>\s*/g, "\"$1\" : \"$2\", "); + try { + NOKIA.emulator.plist = JSON.parse(values); + } catch (exception) { NOKIA.helper.error('Corrupted Info.plist file'); return false; } - // num of = num of - if(xmlObject.key.length != xmlObject.string.length) - { - NOKIA.helper.error('Corrupted Info.plist file'); - return false; - } - - for(var val in xmlObject.key) - { - if(NOKIA.emulator.plist[xmlObject.key[val]] != 'undefined'){ - NOKIA.emulator.plist[xmlObject.key[val]] = xmlObject.string[val].toString(); - } - } - try { if(typeof NOKIA.emulator.plist.DisplayName != 'undefined'){ document.title = NOKIA.emulator.plist.DisplayName + ' - ' + document.title; diff -r a908b05787d1 -r 60453502674e org.symbian.tools.wrttools.previewer/preview/script/xml2json.js --- a/org.symbian.tools.wrttools.previewer/preview/script/xml2json.js Fri Apr 09 11:42:56 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,172 +0,0 @@ -/* -xml2json v 1.1 -copyright 2005-2007 Thomas Frank - -This program is free software under the terms of the -GNU General Public License version 2 as published by the Free -Software Foundation. It is distributed without any warranty. -*/ - -var xml2json={ - parser:function(xmlcode,ignoretags,debug){ - if(!ignoretags){ignoretags=""}; - xmlcode=xmlcode.replace(/\s*\/>/g,'/>'); - xmlcode=xmlcode.replace(/<\?[^>]*>/g,"").replace(/<\![^>]*>/g,""); - if (!ignoretags.sort){ignoretags=ignoretags.split(",")}; - var x=this.no_fast_endings(xmlcode); - x=this.attris_to_tags(x); - x=escape(x); - x=x.split("%3C").join("<").split("%3E").join(">").split("%3D").join("=").split("%22").join("\""); - for (var i=0;i","g"),"*$**"+ignoretags[i]+"**$*"); - x=x.replace(new RegExp("","g"),"*$***"+ignoretags[i]+"**$*") - }; - x=''+x+''; - this.xmlobject={}; - var y=this.xml_to_object(x).jsontagwrapper; - if(debug){y=this.show_json_structure(y,debug)}; - return y - }, - xml_to_object:function(xmlcode){ - var x=xmlcode.replace(/<\//g,"�"); - x=x.split("<"); - var y=[]; - var level=0; - var opentags=[]; - for (var i=1;i")[0]; - opentags.push(tagname); - level++ - y.push(level+"<"+x[i].split("�")[0]); - while(x[i].indexOf("�"+opentags[opentags.length-1]+">")>=0){level--;opentags.pop()} - }; - var oldniva=-1; - var objname="this.xmlobject"; - for (var i=0;i")[0]; - tagnamn=tagnamn.toLowerCase(); - var rest=y[i].split(">")[1]; - if(niva<=oldniva){ - var tabort=oldniva-niva+1; - for (var j=0;j") - } - } - else {rest="{}"}; - if(rest.charAt(0)=="'"){rest='unescape('+rest+')'}; - if (already && !eval(objname+".sort")){preeval+=objname+"=["+objname+"];\n"}; - var before="=";after=""; - if (already){before=".push(";after=")"}; - var toeval=preeval+objname+before+rest+after; - eval(toeval); - if(eval(objname+".sort")){objname+="["+eval(objname+".length-1")+"]"}; - oldniva=niva - }; - return this.xmlobject - }, - show_json_structure:function(obj,debug,l){ - var x=''; - if (obj.sort){x+="[\n"} else {x+="{\n"}; - for (var i in obj){ - if (!obj.sort){x+=i+":"}; - if (typeof obj[i] == "object"){ - x+=this.show_json_structure(obj[i],false,1) - } - else { - if(typeof obj[i]=="function"){ - var v=obj[i]+""; - //v=v.replace(/\t/g,""); - x+=v - } - else if(typeof obj[i]!="string"){x+=obj[i]+",\n"} - else {x+="'"+obj[i].replace(/\'/g,"\\'").replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r")+"',\n"} - } - }; - if (obj.sort){x+="],\n"} else {x+="},\n"}; - if (!l){ - x=x.substring(0,x.lastIndexOf(",")); - x=x.replace(new RegExp(",\n}","g"),"\n}"); - x=x.replace(new RegExp(",\n]","g"),"\n]"); - var y=x.split("\n");x=""; - var lvl=0; - for (var i=0;i=0 || y[i].indexOf("]")>=0){lvl--}; - tabs="";for(var j=0;j=0 || y[i].indexOf("[")>=0){lvl++} - }; - if(debug=="html"){ - x=x.replace(//g,">"); - x=x.replace(/\n/g,"
").replace(/\t/g,"    ") - }; - if (debug=="compact"){x=x.replace(/\n/g,"").replace(/\t/g,"")} - }; - return x - }, - no_fast_endings:function(x){ - x=x.split("/>"); - for (var i=1;i"+x[i] - } ; - x=x.join(""); - return x - }, - attris_to_tags: function(x){ - var d=' ="\''.split(""); - x=x.split(">"); - for (var i=0;i"); - x=x.replace(/ ([^=]*)=([^ |>]*)/g,"><$1>$2"/g,">").replace(/" -