Browse files

added support for max URI length

new command-line flag:
  -u, --maxuri length
  • Loading branch information...
1 parent fe72468 commit 1a72cdae348d8919e6b03ac7123254f562d68705 phred committed Apr 8, 2011
Showing with 24 additions and 2 deletions.
  1. +13 −2 src/net/nczonline/web/cssembed/CSSEmbed.java
  2. +11 −0 src/net/nczonline/web/cssembed/CSSURLEmbedder.java
View
15 src/net/nczonline/web/cssembed/CSSEmbed.java
@@ -60,6 +60,7 @@ public static void main(String[] args) {
CmdLineParser.Option outputFilenameOpt = parser.addStringOption('o', "output");
CmdLineParser.Option mhtmlOpt = parser.addBooleanOption("mhtml");
CmdLineParser.Option mhtmlRootOpt = parser.addStringOption("mhtmlroot");
+ CmdLineParser.Option uriLengthOpt = parser.addIntegerOption('u', "maxuri");
try {
@@ -111,9 +112,17 @@ public static void main(String[] args) {
if (mhtml && mhtmlRoot == null){
throw new Exception("Must use --mhtmlroot when using --mhtml.");
}
+ int maxurilength = 0;
+ Integer uriOption = ((Integer) parser.getOptionValue(uriLengthOpt));
+ if (uriOption != null){
+ maxurilength = uriOption.intValue();
+ if (maxurilength < 0){
+ maxurilength = 0;
+ }
+ }
- CSSURLEmbedder embedder = new CSSURLEmbedder(in, options, verbose);
+ CSSURLEmbedder embedder = new CSSURLEmbedder(in, options, verbose, maxurilength);
embedder.setMHTMLRoot(mhtmlRoot);
//close in case writing to the same file
@@ -198,6 +207,8 @@ private static void usage() {
+ " --mhtmlroot <root> Use <root> as the MHTML root for the file.\n"
+ " -v, --verbose Display informational messages and warnings.\n"
+ " --root <root> Prepends <root> to all relative URLs.\n"
- + " -o <file> Place the output into <file>. Defaults to stdout.");
+ + " -o <file> Place the output into <file>. Defaults to stdout.\n"
+ + " -u, --maxuri length Maximum length of data URI to use.\n"
+ );
}
}
View
11 src/net/nczonline/web/cssembed/CSSURLEmbedder.java
@@ -60,6 +60,7 @@
private int options = 1;
private String mhtmlRoot = "";
private String outputFilename = "";
+ private int maxurilength;
//--------------------------------------------------------------------------
// Constructors
@@ -78,9 +79,14 @@ public CSSURLEmbedder(Reader in, boolean verbose) throws IOException {
}
public CSSURLEmbedder(Reader in, int options, boolean verbose) throws IOException {
+ this(in,1,verbose,0);
+ }
+
+ public CSSURLEmbedder(Reader in, int options, boolean verbose, int maxurilength) throws IOException {
this.code = readCode(in);
this.verbose = verbose;
this.options = options;
+ this.maxurilength = maxurilength;
}
//--------------------------------------------------------------------------
@@ -222,6 +228,11 @@ public void embedImages(Writer out, String root) throws IOException {
if (uriString.length() > 32768){
System.err.println("[WARNING] File " + newUrl + " creates a data URI larger than 32KB. IE8 can't display data URI images this large. Skipping.");
builder.append(url);
+ } else if (maxurilength > 0 && uriString.length() > maxurilength){
+ if (verbose) {
+ System.err.println("[INFO] File " + newUrl + " creates a data URI longer than " + maxurilength + " characters. Skipping.");
+ }
+ builder.append(url);
} else {
/*

0 comments on commit 1a72cda

Please sign in to comment.