Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Standardize some variable naming

Clean up tests a bit
  • Loading branch information...
commit 5139afb6a600150b21ee745aead083e05561f7cc 1 parent 5670dd1
@tivac tivac authored
View
37 src/net/nczonline/web/cssembed/CSSURLEmbedder.java
@@ -64,8 +64,8 @@
private int options = 1;
private String mhtmlRoot = "";
private String outputFilename = "";
- private int maxUriLength = DEFAULT_MAX_URI_LENGTH; //IE8 only allows dataURIs up to 32KB
- private int maximagesize;
+ private int maxUriLengthh = DEFAULT_MAX_URI_LENGTH; //IE8 only allows dataURIs up to 32KB
+ private int maxImageSize;
//--------------------------------------------------------------------------
// Constructors
@@ -80,26 +80,23 @@ public CSSURLEmbedder(Reader in, int options) throws IOException {
}
public CSSURLEmbedder(Reader in, boolean verbose) throws IOException {
- this(in,1,verbose);
+ this(in, 1, verbose);
}
public CSSURLEmbedder(Reader in, int options, boolean verbose) throws IOException {
- this(in,options,verbose,0,0);
+ this(in, options, verbose, 0);
}
- public CSSURLEmbedder(Reader in, int options, boolean verbose, int maxurilength, int maximagesize) throws IOException {
- this.code = readCode(in);
- this.verbose = verbose;
- this.options = options;
- this.maxurilength = maxurilength;
- this.maximagesize = maximagesize;
+ public CSSURLEmbedder(Reader in, int options, boolean verbose, int maxUriLengthh) throws IOException {
+ this(in, options, verbose, maxUriLengthh, 0);
}
-
- public CSSURLEmbedder(Reader in, int options, boolean verbose, int maxUriLength) throws IOException {
+
+ public CSSURLEmbedder(Reader in, int options, boolean verbose, int maxUriLengthh, int maxImageSize) throws IOException {
this.code = readCode(in);
this.verbose = verbose;
this.options = options;
- this.maxUriLength = maxUriLength;
+ this.maxUriLengthh = maxUriLengthh;
+ this.maxImageSize = maxImageSize;
}
//--------------------------------------------------------------------------
@@ -166,8 +163,6 @@ public void embedImages(Writer out, String root) throws IOException {
StringBuilder builder = new StringBuilder();
StringBuilder mhtmlHeader = new StringBuilder();
HashMap<String,Integer> foundMedia = new HashMap<String,Integer>();
- int conversions = 0;
-
String line;
int lineNum = 1;
int conversions = 0;
@@ -240,14 +235,14 @@ public void embedImages(Writer out, String root) throws IOException {
if (uriString.startsWith("data:")){
- if (maxUriLength > 0 && uriString.length() > maxUriLength) {
+ if (maxUriLengthh > 0 && uriString.length() > maxUriLengthh) {
if (verbose){
- System.err.println("[WARNING] File " + newUrl + " creates a data URI larger than " + maxUriLength + " bytes. Skipping.");
+ System.err.println("[WARNING] File " + newUrl + " creates a data URI larger than " + maxUriLengthh + " bytes. Skipping.");
}
builder.append(url);
- } else if (maxurilength > 0 && uriString.length() > maxurilength){
+ } else if (maxUriLengthh > 0 && uriString.length() > maxUriLengthh){
if (verbose) {
- System.err.println("[INFO] File " + newUrl + " creates a data URI longer than " + maxurilength + " characters. Skipping.");
+ System.err.println("[INFO] File " + newUrl + " creates a data URI longer than " + maxUriLengthh + " characters. Skipping.");
}
builder.append(url);
} else {
@@ -358,9 +353,9 @@ private String getImageURIString(String url, String originalUrl) throws IOExcept
}
//check file size if we've been asked to
- if(this.maximagesize > 0 && file.length() > this.maximagesize) {
+ if(this.maxImageSize > 0 && file.length() > this.maxImageSize) {
if(verbose) {
- System.err.println("[INFO] File " + originalUrl + " is larger than " + this.maximagesize + " bytes. Skipping.");
+ System.err.println("[INFO] File " + originalUrl + " is larger than " + this.maxImageSize + " bytes. Skipping.");
}
writer.write(originalUrl);
View
30 tests/net/nczonline/web/cssembed/CSSURLEmbedderTest.java
@@ -141,38 +141,12 @@ public void testAbsoluteLocalFileWithMissingFilesEnabled() throws IOException {
}
@Test
- public void testAbsoluteLocalFileUnderMaxSize() throws IOException {
- String filename = CSSURLEmbedderTest.class.getResource("folder.png").getPath().replace("%20", " ");
- String code = "background: url(folder.png);";
-
- StringWriter writer = new StringWriter();
- embedder = new CSSURLEmbedder(new StringReader(code), CSSURLEmbedder.DATAURI_OPTION, true, 1000);
- embedder.embedImages(writer, filename.substring(0, filename.lastIndexOf("/")+1));
-
- String result = writer.toString();
- assertEquals("background: url(" + folderDataURI + ");", result);
- }
-
- @Test
- public void testAbsoluteLocalFileOverMaxSize() throws IOException {
- String filename = CSSURLEmbedderTest.class.getResource("folder.png").getPath().replace("%20", " ");
- String code = "background: url(folder.png);";
-
- StringWriter writer = new StringWriter();
- embedder = new CSSURLEmbedder(new StringReader(code), CSSURLEmbedder.DATAURI_OPTION, true, 200);
- embedder.embedImages(writer, filename.substring(0, filename.lastIndexOf("/")+1));
-
- String result = writer.toString();
- assertEquals(code, result);
- }
-
- @Test
public void testAbsoluteLocalFileUnderMaxLength() throws IOException {
String filename = CSSURLEmbedderTest.class.getResource("folder.png").getPath().replace("%20", " ");
String code = "background: url(folder.png);";
StringWriter writer = new StringWriter();
- embedder = new CSSURLEmbedder(new StringReader(code), CSSURLEmbedder.DATAURI_OPTION, true, 1000, 0);
+ embedder = new CSSURLEmbedder(new StringReader(code), CSSURLEmbedder.DATAURI_OPTION, true, 1000);
embedder.embedImages(writer, filename.substring(0, filename.lastIndexOf("/")+1));
String result = writer.toString();
@@ -185,7 +159,7 @@ public void testAbsoluteLocalFileOverMaxLength() throws IOException {
String code = "background: url(folder.png);";
StringWriter writer = new StringWriter();
- embedder = new CSSURLEmbedder(new StringReader(code), CSSURLEmbedder.DATAURI_OPTION, true, 200, 0);
+ embedder = new CSSURLEmbedder(new StringReader(code), CSSURLEmbedder.DATAURI_OPTION, true, 200);
embedder.embedImages(writer, filename.substring(0, filename.lastIndexOf("/")+1));
String result = writer.toString();
Please sign in to comment.
Something went wrong with that request. Please try again.