Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on JAXB #299

Merged
merged 1 commit into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions openhtmltopdf-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.w3c</groupId>
<artifactId>dom</artifactId>
<version>2.3.0-jaxb-1.0.6</version>
</dependency>

<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.logging.Level;
import javax.imageio.ImageIO;
import javax.xml.bind.DatatypeConverter;

/**
* Static utility methods for working with images. Meant to suggest "best practices" for the most straightforward
Expand Down Expand Up @@ -290,7 +290,7 @@ public static byte[] getEmbeddedBase64Image(String imageDataUri) {
int b64Index = imageDataUri.indexOf("base64,");
if (b64Index != -1) {
String b64encoded = imageDataUri.substring(b64Index + "base64,".length());
return DatatypeConverter.parseBase64Binary(b64encoded);
return Base64.getMimeDecoder().decode(b64encoded);
} else {
XRLog.load(Level.SEVERE, "Embedded XHTML images must be encoded in base 64.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.openhtmltopdf.util;

import java.awt.image.BufferedImage;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import org.junit.Test;
import org.junit.Assert;

public class ImageUtilTest {

@Test
public void testGetEmbeddedBase64Image() {
String onePixel = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAACXBIWXMAAC4jAAAuIwF4pT92AAAADElEQVQI12P4//8/AAX+Av7czFnnAAAAAElFTkSuQmCC";
byte[] result = ImageUtil.getEmbeddedBase64Image(onePixel);
Assert.assertThat(result, notNullValue());
}

@Test
public void testLoadEmbeddedBase64Image() {
String onePixel = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAACXBIWXMAAC4jAAAuIwF4pT92AAAADElEQVQI12P4//8/AAX+Av7czFnnAAAAAElFTkSuQmCC";
BufferedImage result = ImageUtil.loadEmbeddedBase64Image(onePixel);
Assert.assertThat(result.getHeight(), is(1));
Assert.assertThat(result.getWidth(), is(1));
}

}