Fix SVG export tests...

This commit is contained in:
Paulo Gustavo Veiga 2013-03-10 19:45:21 -03:00
parent 202c3f28a3
commit b6ee7e61b8
2 changed files with 25 additions and 25 deletions

View File

@ -105,8 +105,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version> <version>2.3.2</version>
<configuration> <configuration>
<source>1.6</source> <source>1.7</source>
<target>1.6</target> <target>1.7</target>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
</configuration> </configuration>
</plugin> </plugin>

View File

@ -140,9 +140,7 @@ public class ExporterFactory {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
final DocumentBuilder documentBuilder = factory.newDocumentBuilder(); final DocumentBuilder documentBuilder = factory.newDocumentBuilder();
if (!svgXml.trim().startsWith("<svg xmlns=\"http://www.w3.org/2000/svg\"")) { if (!svgXml.contains("xmlns:xlink=\"http://www.w3.org/1999/xlink\"")) {
svgXml = svgXml.replaceFirst("<svg ", "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" ");
} else {
svgXml = svgXml.replaceFirst("<svg ", "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" "); svgXml = svgXml.replaceFirst("<svg ", "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" ");
} }
@ -222,30 +220,32 @@ public class ExporterFactory {
Element elem = (Element) node; Element elem = (Element) node;
// Cook image href ... // If the image is a external URL, embeed it...
String imgUrl = elem.getAttribute("href"); String imgUrl = elem.getAttribute("href");
elem.removeAttribute("href"); if (!imgUrl.startsWith("image/png;base64") ||!imgUrl.startsWith("data:image/png;base64") ) {
elem.removeAttribute("href");
if (imgUrl == null || imgUrl.isEmpty()) { if (imgUrl == null || imgUrl.isEmpty()) {
imgUrl = elem.getAttribute("xlink:href"); // Do not support namespaces ... imgUrl = elem.getAttribute("xlink:href"); // Do not support namespaces ...
elem.removeAttribute("xlink:href"); elem.removeAttribute("xlink:href");
} }
FileInputStream fis = null; FileInputStream fis = null;
// Obtains file name ... // Obtains file name ...
try { try {
final File iconFile = iconFile(imgUrl); final File iconFile = iconFile(imgUrl);
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
fis = new FileInputStream(iconFile); fis = new FileInputStream(iconFile);
BASE64Encoder encoder = new BASE64Encoder(); BASE64Encoder encoder = new BASE64Encoder();
encoder.encode(fis, bos); encoder.encode(fis, bos);
elem.setAttribute("xlink:href", "data:image/png;base64," + bos.toString("8859_1")); elem.setAttribute("xlink:href", "data:image/png;base64," + bos.toString("8859_1"));
elem.appendChild(document.createTextNode(" ")); elem.appendChild(document.createTextNode(" "));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
close(fis); close(fis);
}
} }
} }
} }