Skip to content
This repository has been archived by the owner on Nov 16, 2018. It is now read-only.

Commit

Permalink
Initial support and tests for MHTML
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas C. Zakas committed Nov 27, 2009
1 parent 48ff78e commit d25b6a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/net/nczonline/web/cssembed/CSSURLEmbedder.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class CSSURLEmbedder {
public static final int DATAURI_OPTION = 1;
public static final int MHTML_OPTION = 2;

private static String MHTML_SEPARATOR = "CSSEmbed_Image";
protected static String MHTML_SEPARATOR = "CSSEmbed_Image";

private static HashSet<String> imageTypes;
static {
Expand Down Expand Up @@ -100,7 +100,7 @@ public void setVerbose(boolean newVerbose){
// Determine if an option is set - Options support not yet complete
//--------------------------------------------------------------------------

public boolean hasOption(int option){
private boolean hasOption(int option){
return (options & option) > 0;
}

Expand Down
18 changes: 18 additions & 0 deletions tests/net/nczonline/web/cssembed/CSSURLEmbedderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ public void testAbsoluteLocalFile() throws IOException {
assertEquals("background: url(" + folderDataURI + ");", result);
}

@Test
public void testAbsoluteLocalFileWithMhtml() throws IOException {
String filename = CSSURLEmbedderTest.class.getResource("folder.png").getPath().replace("%20", " ");
String code = "background: url(folder.png);";
String mhtmlUrl = "http://www.example.com/dir/styles_ie.css";

StringWriter writer = new StringWriter();
embedder = new CSSURLEmbedder(new StringReader(code), CSSURLEmbedder.MHTML_OPTION, true);
embedder.setMhtmlUrl(mhtmlUrl);
embedder.embedImages(writer, filename.substring(0, filename.lastIndexOf("/")+1));

String result = writer.toString();
assertEquals("/*\nContent-Type: multipart/related; boundary=\"" + CSSURLEmbedder.MHTML_SEPARATOR +
"\"\n\n--" + CSSURLEmbedder.MHTML_SEPARATOR + "\nContent-Location:folder.png\n" +
"Content-Transfer-Encoding:base64\n\n" + folderDataURI.substring(folderDataURI.indexOf(",")+1) +
"\n*/\nbackground: url(mhtml:" + mhtmlUrl + "!folder.png);", result);
}

@Test
public void testAbsoluteLocalFileMultipleOneLine() throws IOException {
String filename = CSSURLEmbedderTest.class.getResource("folder.png").getPath().replace("%20", " ");
Expand Down

0 comments on commit d25b6a2

Please sign in to comment.