812 var xmlString = xhr.responseText; |
812 var xmlString = xhr.responseText; |
813 |
813 |
814 // do some cheating here |
814 // do some cheating here |
815 xmlString = xmlString.replace(/<\s*true\s*\/>/gi, "<string>true</string>"); |
815 xmlString = xmlString.replace(/<\s*true\s*\/>/gi, "<string>true</string>"); |
816 xmlString = xmlString.replace(/<\s*false\s*\/>/gi, "<string>false</string>"); |
816 xmlString = xmlString.replace(/<\s*false\s*\/>/gi, "<string>false</string>"); |
817 |
817 xmlString = xmlString.replace(/[\n\r]/gi, ""); |
818 /* |
|
819 * DomParser Logic |
|
820 var appXml = new DOMParser(); |
|
821 var xmlobject = appXml.parseFromString(xmlString, "text/xml"); |
|
822 */ |
|
823 |
|
824 // return the JSON Object |
818 // return the JSON Object |
825 NOKIA.helper.validate(xml2json.parser(xmlString)); |
819 NOKIA.helper.validate(xmlString); |
826 } |
820 } |
827 |
821 |
828 }, |
822 }, |
829 |
823 |
830 getIconCallback : function(flag, xhr) |
824 getIconCallback : function(flag, xhr) |
844 }, |
838 }, |
845 |
839 |
846 |
840 |
847 validate : function(xmlObject) |
841 validate : function(xmlObject) |
848 { |
842 { |
849 window.xmlObject = xmlObject; |
843 var values = xmlObject.match(/.*<plist.*?(<dict.*?>\s*(<key[^>]*?>[^<]*?<\/key>\s*<string[^>]*?>[^<]*?<\/string>)*\s*<\/dict>)\s*<\/plist>/)[1]; |
850 |
844 if(values == null || values == undefined) |
851 // <plist> |
|
852 if(typeof xmlObject.plist != 'object' || xmlObject.plist == 'undefined') |
|
853 { |
845 { |
854 NOKIA.helper.error('Corrupted Info.plist file'); |
846 NOKIA.helper.error('Corrupted Info.plist file'); |
855 return false; |
847 return false; |
856 } |
848 } |
857 // <dict> |
849 values = values.replace(/<dict.*?(<key.*?>\s*.*\s*<\/string>)\s*<\/dict>/, "{ $1 }"); |
858 xmlObject = xmlObject.plist; |
850 values = values.replace(/\s*<key.*?>\s*(.*?)\s*<\/key>\s*<string.*?>\s*(.*?)\s*<\/string>\s*/g, "\"$1\" : \"$2\", "); |
859 if(typeof xmlObject.dict != 'object' || xmlObject.dict == 'undefined') |
851 try { |
860 { |
852 NOKIA.emulator.plist = JSON.parse(values); |
|
853 } catch (exception) { |
861 NOKIA.helper.error('Corrupted Info.plist file'); |
854 NOKIA.helper.error('Corrupted Info.plist file'); |
862 return false; |
855 return false; |
863 } |
|
864 |
|
865 // <key> |
|
866 xmlObject = xmlObject.dict; |
|
867 if(typeof xmlObject.key != 'object' || xmlObject.key == 'undefined') |
|
868 { |
|
869 NOKIA.helper.error('Corrupted Info.plist file'); |
|
870 return false; |
|
871 } |
|
872 |
|
873 // <string> |
|
874 if(typeof xmlObject.string != 'object' || xmlObject.string == 'undefined') |
|
875 { |
|
876 NOKIA.helper.error('Corrupted Info.plist file'); |
|
877 return false; |
|
878 } |
|
879 |
|
880 // num of <key> = num of <string> |
|
881 if(xmlObject.key.length != xmlObject.string.length) |
|
882 { |
|
883 NOKIA.helper.error('Corrupted Info.plist file'); |
|
884 return false; |
|
885 } |
|
886 |
|
887 for(var val in xmlObject.key) |
|
888 { |
|
889 if(NOKIA.emulator.plist[xmlObject.key[val]] != 'undefined'){ |
|
890 NOKIA.emulator.plist[xmlObject.key[val]] = xmlObject.string[val].toString(); |
|
891 } |
|
892 } |
856 } |
893 |
857 |
894 try { |
858 try { |
895 if(typeof NOKIA.emulator.plist.DisplayName != 'undefined'){ |
859 if(typeof NOKIA.emulator.plist.DisplayName != 'undefined'){ |
896 document.title = NOKIA.emulator.plist.DisplayName + ' - ' + document.title; |
860 document.title = NOKIA.emulator.plist.DisplayName + ' - ' + document.title; |