I have a complex, generated Javascript file (it's generated by the GWT compiler), and I need to be able to programmatically make changes to this and output a 'cleaned' version of the file. In particular, I have:
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();
Un-obfuscated, the inside of the function looks like:
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>');
So what I need to do is in a Java servlet, transform the above two lines into the equivalent of:
eval('blah blah blah');
document.body.appendChild(document.createElement('script')).src=base + strongName + ".cache.js";
What are my best options to parse and re-arrange this Javascript file? Should I look into Rhino, would it be able to give handles to these (as well as the nested Javascript which is being written using $doc.write)? Any ideas would be appreciated.