This repository has been archived by the owner on Nov 23, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ScriptsToConcat.java works with root relative URL's
Implemented nelsams fix in the ScriptsToConcat.java file and compiled it to a class file. This fixes the issue wher the build script couldn't handle root relative URL's in the script tags.
- Loading branch information
Thomas Kahn
committed
Aug 24, 2012
1 parent
700003f
commit 8b53c80
Showing
2 changed files
with
55 additions
and
52 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,55 @@ | ||
// HTML5 boilerplate scripts parser | ||
// Daniel Holth <dholth@fastmail.fm.com>, 2012 | ||
// Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
||
import java.io.FileReader; | ||
import java.io.IOException; | ||
|
||
import javax.swing.text.MutableAttributeSet; | ||
import javax.swing.text.html.HTML; | ||
import javax.swing.text.html.HTML.Tag; | ||
import javax.swing.text.html.HTMLEditorKit.ParserCallback; | ||
import javax.swing.text.html.parser.ParserDelegator; | ||
|
||
|
||
/** | ||
* Parse an HTML file, printing the src attribute of all scripts | ||
* between magic <!-- scripts concatenated --> and <!-- end scripts --> comments. | ||
*/ | ||
public class ScriptsToConcat extends ParserCallback { | ||
private boolean emitting = false; | ||
|
||
@Override | ||
public void handleComment(char[] arg0, int arg1) { | ||
String text = new String(arg0); | ||
if(text.startsWith(" scripts concatenated ")) { | ||
emitting = true; | ||
} else if (text.startsWith(" end scripts ") || | ||
text.startsWith(" end concatenated and minified scripts")) { | ||
emitting = false; | ||
} | ||
} | ||
|
||
@Override | ||
public void handleStartTag(Tag t, MutableAttributeSet a, int pos) { | ||
if(!emitting || t != HTML.Tag.SCRIPT) { | ||
return; | ||
} | ||
String scriptName = a.getAttribute(HTML.Attribute.SRC).toString(); | ||
if(scriptName != null) { | ||
System.out.println(scriptName); | ||
} | ||
} | ||
|
||
public static void main(String args[]) throws IOException { | ||
if(args.length != 1) { | ||
System.err.println("Accepts exactly one argument: the filename of an HTML document."); | ||
System.exit(1); | ||
} | ||
FileReader fr = new FileReader(args[0]); | ||
new ParserDelegator().parse(fr, new ScriptsToConcat(), true); | ||
} | ||
} | ||
// HTML5 boilerplate scripts parser | ||
// Daniel Holth <dholth@fastmail.fm.com>, 2012 | ||
// Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
||
import java.io.FileReader; | ||
import java.io.IOException; | ||
|
||
import javax.swing.text.MutableAttributeSet; | ||
import javax.swing.text.html.HTML; | ||
import javax.swing.text.html.HTML.Tag; | ||
import javax.swing.text.html.HTMLEditorKit.ParserCallback; | ||
import javax.swing.text.html.parser.ParserDelegator; | ||
|
||
|
||
/** | ||
* Parse an HTML file, printing the src attribute of all scripts | ||
* between magic <!-- scripts concatenated --> and <!-- end scripts --> comments. | ||
*/ | ||
public class ScriptsToConcat extends ParserCallback { | ||
private boolean emitting = false; | ||
|
||
@Override | ||
public void handleComment(char[] arg0, int arg1) { | ||
String text = new String(arg0); | ||
if(text.startsWith(" scripts concatenated ")) { | ||
emitting = true; | ||
} else if (text.startsWith(" end scripts ") || | ||
text.startsWith(" end concatenated and minified scripts")) { | ||
emitting = false; | ||
} | ||
} | ||
|
||
@Override | ||
public void handleStartTag(Tag t, MutableAttributeSet a, int pos) { | ||
if(!emitting || t != HTML.Tag.SCRIPT) { | ||
return; | ||
} | ||
String scriptName = a.getAttribute(HTML.Attribute.SRC).toString(); | ||
if(scriptName != null) { | ||
if(scriptName.startsWith("/")) { | ||
System.out.println(scriptName); | ||
} | ||
System.out.println(scriptName); | ||
} | ||
} | ||
|
||
public static void main(String args[]) throws IOException { | ||
if(args.length != 1) { | ||
System.err.println("Accepts exactly one argument: the filename of an HTML document."); | ||
System.exit(1); | ||
} | ||
FileReader fr = new FileReader(args[0]); | ||
new ParserDelegator().parse(fr, new ScriptsToConcat(), true); | ||
} | ||
} |