fixes to extraction of scripts from HTML
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3044 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
80c067d476
commit
9160a2f565
|
@ -67,7 +67,6 @@ public class HTMLCallback extends HTMLEditorKit.ParserCallback {
|
||||||
System.out.println(new String(data));
|
System.out.println(new String(data));
|
||||||
try {
|
try {
|
||||||
out2.write(data);
|
out2.write(data);
|
||||||
out2.write("\n");
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Error writing to second file");
|
System.out.println("Error writing to second file");
|
||||||
}
|
}
|
||||||
|
@ -167,6 +166,9 @@ public class HTMLCallback extends HTMLEditorKit.ParserCallback {
|
||||||
if(attr.substring(0,2).equals("on")) {
|
if(attr.substring(0,2).equals("on")) {
|
||||||
out.write(varName + "." + attr + " = function " + attr + "_" + varName + "(event) {" + value + "};\n");
|
out.write(varName + "." + attr + " = function " + attr + "_" + varName + "(event) {" + value + "};\n");
|
||||||
out2.write("\n\n" + varName2 + "." + attr + "(null);\n\n");
|
out2.write("\n\n" + varName2 + "." + attr + "(null);\n\n");
|
||||||
|
} else if (value.startsWith("javascript:") || value.startsWith("javaScript:")) {
|
||||||
|
out.write("var " + varName + attr + " = " + value.substring(11) + "\n");
|
||||||
|
out.write(varName + ".setAttribute('" + attr + "', " + varName + attr + ");\n");
|
||||||
} else {
|
} else {
|
||||||
out.write(varName + ".setAttribute('" + attr + "', '" + value + "');\n");
|
out.write(varName + ".setAttribute('" + attr + "', '" + value + "');\n");
|
||||||
}
|
}
|
||||||
|
@ -191,6 +193,11 @@ public class HTMLCallback extends HTMLEditorKit.ParserCallback {
|
||||||
public void handleEndTag(HTML.Tag t, int pos) {
|
public void handleEndTag(HTML.Tag t, int pos) {
|
||||||
if(t.toString().toUpperCase().equals("SCRIPT")) {
|
if(t.toString().toUpperCase().equals("SCRIPT")) {
|
||||||
System.out.println("Exiting Script");
|
System.out.println("Exiting Script");
|
||||||
|
try {
|
||||||
|
out2.write("\n\n");
|
||||||
|
} catch (IOException e) {
|
||||||
|
|
||||||
|
}
|
||||||
script = false;
|
script = false;
|
||||||
}
|
}
|
||||||
System.out.println("End" + t);
|
System.out.println("End" + t);
|
||||||
|
@ -199,7 +206,22 @@ public class HTMLCallback extends HTMLEditorKit.ParserCallback {
|
||||||
|
|
||||||
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
|
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
|
||||||
System.out.println("Simple" + t);
|
System.out.println("Simple" + t);
|
||||||
createElement(t,a);
|
if (script) {
|
||||||
|
try {
|
||||||
|
out2.write("<" + t);
|
||||||
|
Enumeration names = a.getAttributeNames();
|
||||||
|
while (names.hasMoreElements()) {
|
||||||
|
Object name = names.nextElement();
|
||||||
|
Object val = a.getAttribute(name);
|
||||||
|
out2.write(" " + name + "='" + val + "'");
|
||||||
|
}
|
||||||
|
out2.write("></" + t + ">");
|
||||||
|
} catch (IOException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
createElement(t,a);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleError(String errorMsg, int pos) {
|
public void handleError(String errorMsg, int pos) {
|
||||||
|
|
|
@ -50,7 +50,10 @@ public class WebUtil {
|
||||||
public static SourceFileModule extractScriptFromHTML(URL url, Generator generator) {
|
public static SourceFileModule extractScriptFromHTML(URL url, Generator generator) {
|
||||||
try {
|
try {
|
||||||
String urlFile = url.getFile();
|
String urlFile = url.getFile();
|
||||||
String urlName = urlFile.substring(urlFile.lastIndexOf('/'));
|
String urlName =
|
||||||
|
urlFile.lastIndexOf('/')>0?
|
||||||
|
urlFile.substring(urlFile.lastIndexOf('/')):
|
||||||
|
url.getHost() + ".html";
|
||||||
File F = new File(outputDir + urlName);
|
File F = new File(outputDir + urlName);
|
||||||
Trace.println("making driver at " + F + " " + outputDir);
|
Trace.println("making driver at " + F + " " + outputDir);
|
||||||
if (F.exists()) F.delete();
|
if (F.exists()) F.delete();
|
||||||
|
|
Loading…
Reference in New Issue