I am facing a challenge with a complex, generated Javascript file (it is created by the GWT compiler) that requires programmatically making changes to and outputting a modified version of the file. The specific section in question contains:
function bookmark(){
// lots-o-javascript
var M=Vb+s+I+Wb;n.write(Xb+Yb+Zb+$b+_b+ac+bc+$b+_b+cc+dc+ec+M+fc+gc+hc+ic)
}
bookmark();
The unobfuscated content inside the function reads as follows:
var compiledScriptTag = '"<script src=\\"' + base + strongName + '.cache.js\\"><\/scr" + "ipt>"';
$doc_0.write('<scr' + 'ipt><!-' + '-\n' + 'blah blah blah' + 'document.write(' + compiledScriptTag + ');' + '\n-' + '-><\/scr' + 'ipt>');
My goal is to transform the above two lines within a Java servlet into the equivalent of:
eval('blah blah blah');
document.body.appendChild(document.createElement('script')).src=base + strongName + ".cache.js";
I am seeking advice on the best approach to parse and restructure this Javascript file. Would utilizing Rhino be a viable option for handling these changes and nested Javascript content being written using $doc.write? Any suggestions or insights would be greatly welcomed.